Skip to content

Commit cf8675e

Browse files
author
Romain Guy
committed
Draw stroked rectangle as meshes instead of textures
Bug #7233734 Stroked rectangles were rendered using software generated textures which would lead to slightly misaligned results. Instead, let's use the new convex path rendering code that will do the right thing (and save a lot of bandwidth.) Change-Id: Ib95ff581e56c1ecead97e4919298e6fd146ca167
1 parent 0944d62 commit cf8675e

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

graphics/java/android/graphics/drawable/GradientDrawable.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,10 @@ of the fill (if any) without worrying about blending artifacts.
513513
canvas.drawRoundRect(mRect, rad, rad, mStrokePaint);
514514
}
515515
} else {
516-
canvas.drawRect(mRect, mFillPaint);
516+
if (mFillPaint.getColor() != 0 || mColorFilter != null ||
517+
mFillPaint.getShader() != null) {
518+
canvas.drawRect(mRect, mFillPaint);
519+
}
517520
if (haveStroke) {
518521
canvas.drawRect(mRect, mStrokePaint);
519522
}
@@ -1251,6 +1254,11 @@ private GradientDrawable(GradientState state) {
12511254
private void initializeWithState(GradientState state) {
12521255
if (state.mHasSolidColor) {
12531256
mFillPaint.setColor(state.mSolidColor);
1257+
} else if (state.mColors == null) {
1258+
// If we don't have a solid color and we don't have a gradient,
1259+
// the app is stroking the shape, set the color to the default
1260+
// value of state.mSolidColor
1261+
mFillPaint.setColor(0);
12541262
}
12551263
mPadding = state.mPadding;
12561264
if (state.mStrokeWidth >= 0) {

libs/hwui/OpenGLRenderer.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,16 +2440,33 @@ status_t OpenGLRenderer::drawArc(float left, float top, float right, float botto
24402440
return drawShape(left, top, texture, paint);
24412441
}
24422442

2443+
// See SkPaintDefaults.h
2444+
#define SkPaintDefaults_MiterLimit SkIntToScalar(4)
2445+
24432446
status_t OpenGLRenderer::drawRect(float left, float top, float right, float bottom, SkPaint* p) {
24442447
if (mSnapshot->isIgnored() || quickRejectPreStroke(left, top, right, bottom, p)) {
24452448
return DrawGlInfo::kStatusDone;
24462449
}
24472450

2448-
// only fill style is supported by drawConvexPath, since others have to handle joins
24492451
if (p->getStyle() != SkPaint::kFill_Style) {
2450-
mCaches.activeTexture(0);
2451-
const PathTexture* texture = mCaches.rectShapeCache.getRect(right - left, bottom - top, p);
2452-
return drawShape(left, top, texture, p);
2452+
// only fill style is supported by drawConvexPath, since others have to handle joins
2453+
if (p->getPathEffect() != 0 || p->getStrokeJoin() != SkPaint::kMiter_Join ||
2454+
p->getStrokeMiter() != SkPaintDefaults_MiterLimit) {
2455+
mCaches.activeTexture(0);
2456+
const PathTexture* texture =
2457+
mCaches.rectShapeCache.getRect(right - left, bottom - top, p);
2458+
return drawShape(left, top, texture, p);
2459+
}
2460+
2461+
SkPath path;
2462+
SkRect rect = SkRect::MakeLTRB(left, top, right, bottom);
2463+
if (p->getStyle() == SkPaint::kStrokeAndFill_Style) {
2464+
rect.outset(p->getStrokeWidth() / 2, p->getStrokeWidth() / 2);
2465+
}
2466+
path.addRect(rect);
2467+
drawConvexPath(path, p);
2468+
2469+
return DrawGlInfo::kStatusDrew;
24532470
}
24542471

24552472
if (p->isAntiAlias() && !mSnapshot->transform->isSimple()) {

0 commit comments

Comments
 (0)