Skip to content

Commit 8257124

Browse files
Romain GuyAndroid (Google) Code Review
authored andcommitted
Merge "Draw stroked rectangle as meshes instead of textures Bug #7233734" into jb-mr1-dev
2 parents ec9b13d + cf8675e commit 8257124

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)