Skip to content

Commit 2aa50b6

Browse files
ChrisCraikAndroid (Google) Code Review
authored andcommitted
Merge "HW Acceleration support for stroked arcs with BUTT caps" into jb-mr1-dev
2 parents 3f840c8 + 780c128 commit 2aa50b6

File tree

3 files changed

+300
-47
lines changed

3 files changed

+300
-47
lines changed

libs/hwui/OpenGLRenderer.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,17 +2427,39 @@ status_t OpenGLRenderer::drawOval(float left, float top, float right, float bott
24272427
}
24282428

24292429
status_t OpenGLRenderer::drawArc(float left, float top, float right, float bottom,
2430-
float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) {
2431-
if (mSnapshot->isIgnored()) return DrawGlInfo::kStatusDone;
2430+
float startAngle, float sweepAngle, bool useCenter, SkPaint* p) {
2431+
if (mSnapshot->isIgnored() || quickRejectPreStroke(left, top, right, bottom, p)) {
2432+
return DrawGlInfo::kStatusDone;
2433+
}
24322434

24332435
if (fabs(sweepAngle) >= 360.0f) {
2434-
return drawOval(left, top, right, bottom, paint);
2436+
return drawOval(left, top, right, bottom, p);
24352437
}
24362438

2437-
mCaches.activeTexture(0);
2438-
const PathTexture* texture = mCaches.arcShapeCache.getArc(right - left, bottom - top,
2439-
startAngle, sweepAngle, useCenter, paint);
2440-
return drawShape(left, top, texture, paint);
2439+
// TODO: support fills (accounting for concavity if useCenter && sweepAngle > 180)
2440+
if (p->getStyle() != SkPaint::kStroke_Style || p->getPathEffect() != 0 || p->getStrokeCap() != SkPaint::kButt_Cap) {
2441+
mCaches.activeTexture(0);
2442+
const PathTexture* texture = mCaches.arcShapeCache.getArc(right - left, bottom - top,
2443+
startAngle, sweepAngle, useCenter, p);
2444+
return drawShape(left, top, texture, p);
2445+
}
2446+
2447+
SkRect rect = SkRect::MakeLTRB(left, top, right, bottom);
2448+
if (p->getStyle() == SkPaint::kStrokeAndFill_Style) {
2449+
rect.outset(p->getStrokeWidth() / 2, p->getStrokeWidth() / 2);
2450+
}
2451+
2452+
SkPath path;
2453+
if (useCenter) {
2454+
path.moveTo(rect.centerX(), rect.centerY());
2455+
}
2456+
path.arcTo(rect, startAngle, sweepAngle, !useCenter);
2457+
if (useCenter) {
2458+
path.close();
2459+
}
2460+
drawConvexPath(path, p);
2461+
2462+
return DrawGlInfo::kStatusDrew;
24412463
}
24422464

24432465
// See SkPaintDefaults.h

0 commit comments

Comments
 (0)