Add support for arcs.
Change-Id: I96c057ff4eb1b464b03f132da0b85333777bee4f
diff --git a/libs/hwui/Caches.h b/libs/hwui/Caches.h
index 3bac422..0a9335f 100644
--- a/libs/hwui/Caches.h
+++ b/libs/hwui/Caches.h
@@ -164,6 +164,7 @@
CircleShapeCache circleShapeCache;
OvalShapeCache ovalShapeCache;
RectShapeCache rectShapeCache;
+ ArcShapeCache arcShapeCache;
PatchCache patchCache;
TextDropShadowCache dropShadowCache;
FboCache fboCache;
diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp
index 8714997..200e248 100644
--- a/libs/hwui/DisplayListRenderer.cpp
+++ b/libs/hwui/DisplayListRenderer.cpp
@@ -108,6 +108,7 @@
"DrawRoundRect",
"DrawCircle",
"DrawOval",
+ "DrawArc",
"DrawPath",
"DrawLines",
"DrawText",
@@ -363,6 +364,11 @@
renderer.drawOval(getFloat(), getFloat(), getFloat(), getFloat(), getPaint());
}
break;
+ case DrawArc: {
+ renderer.drawArc(getFloat(), getFloat(), getFloat(), getFloat(),
+ getFloat(), getFloat(), getInt() == 1, getPaint());
+ }
+ break;
case DrawPath: {
renderer.drawPath(getPath(), getPaint());
}
@@ -675,6 +681,15 @@
addPaint(paint);
}
+void DisplayListRenderer::drawArc(float left, float top, float right, float bottom,
+ float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) {
+ addOp(DisplayList::DrawOval);
+ addBounds(left, top, right, bottom);
+ addPoint(startAngle, sweepAngle);
+ addInt(useCenter ? 1 : 0);
+ addPaint(paint);
+}
+
void DisplayListRenderer::drawPath(SkPath* path, SkPaint* paint) {
addOp(DisplayList::DrawPath);
addPath(path);
diff --git a/libs/hwui/DisplayListRenderer.h b/libs/hwui/DisplayListRenderer.h
index 8183e25..35bb163 100644
--- a/libs/hwui/DisplayListRenderer.h
+++ b/libs/hwui/DisplayListRenderer.h
@@ -114,6 +114,7 @@
DrawRoundRect,
DrawCircle,
DrawOval,
+ DrawArc,
DrawPath,
DrawLines,
DrawText,
@@ -281,6 +282,8 @@
float rx, float ry, SkPaint* paint);
void drawCircle(float x, float y, float radius, SkPaint* paint);
void drawOval(float left, float top, float right, float bottom, SkPaint* paint);
+ void drawArc(float left, float top, float right, float bottom,
+ float startAngle, float sweepAngle, bool useCenter, SkPaint* paint);
void drawPath(SkPath* path, SkPaint* paint);
void drawLines(float* points, int count, SkPaint* paint);
void drawText(const char* text, int bytesCount, int count, float x, float y, SkPaint* paint);
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 99c0600..2467d8e 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -1396,6 +1396,21 @@
drawShape(left, top, texture, paint);
}
+void OpenGLRenderer::drawArc(float left, float top, float right, float bottom,
+ float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) {
+ if (mSnapshot->isIgnored()) return;
+
+ if (fabs(sweepAngle) >= 360.0f) {
+ drawOval(left, top, right, bottom, paint);
+ return;
+ }
+
+ glActiveTexture(gTextureUnits[0]);
+ const PathTexture* texture = mCaches.arcShapeCache.getArc(right - left, bottom - top,
+ startAngle, sweepAngle, useCenter, paint);
+ drawShape(left, top, texture, paint);
+}
+
void OpenGLRenderer::drawRectAsShape(float left, float top, float right, float bottom,
SkPaint* paint) {
if (mSnapshot->isIgnored()) return;
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index 30cf102..eec3750 100644
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -113,6 +113,8 @@
float rx, float ry, SkPaint* paint);
virtual void drawCircle(float x, float y, float radius, SkPaint* paint);
virtual void drawOval(float left, float top, float right, float bottom, SkPaint* paint);
+ virtual void drawArc(float left, float top, float right, float bottom,
+ float startAngle, float sweepAngle, bool useCenter, SkPaint* paint);
virtual void drawPath(SkPath* path, SkPaint* paint);
virtual void drawLines(float* points, int count, SkPaint* paint);
virtual void drawText(const char* text, int bytesCount, int count, float x, float y,
diff --git a/libs/hwui/ShapeCache.cpp b/libs/hwui/ShapeCache.cpp
index da86075..0d7cd9c 100644
--- a/libs/hwui/ShapeCache.cpp
+++ b/libs/hwui/ShapeCache.cpp
@@ -114,5 +114,36 @@
return texture;
}
+///////////////////////////////////////////////////////////////////////////////
+// Arcs
+///////////////////////////////////////////////////////////////////////////////
+
+ArcShapeCache::ArcShapeCache(): ShapeCache<ArcShapeCacheEntry>(
+ "arc", PROPERTY_SHAPE_CACHE_SIZE, DEFAULT_SHAPE_CACHE_SIZE) {
+}
+
+PathTexture* ArcShapeCache::getArc(float width, float height,
+ float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) {
+ ArcShapeCacheEntry entry(width, height, startAngle, sweepAngle, useCenter, paint);
+ PathTexture* texture = get(entry);
+
+ if (!texture) {
+ SkPath path;
+ SkRect r;
+ r.set(0.0f, 0.0f, width, height);
+ if (useCenter) {
+ path.moveTo(r.centerX(), r.centerY());
+ }
+ path.arcTo(r, startAngle, sweepAngle, !useCenter);
+ if (useCenter) {
+ path.close();
+ }
+
+ texture = addTexture(entry, &path, paint);
+ }
+
+ return texture;
+}
+
}; // namespace uirenderer
}; // namespace android
diff --git a/libs/hwui/ShapeCache.h b/libs/hwui/ShapeCache.h
index a4aff9d..e535466 100644
--- a/libs/hwui/ShapeCache.h
+++ b/libs/hwui/ShapeCache.h
@@ -281,6 +281,58 @@
uint32_t mHeight;
}; // RectShapeCacheEntry
+struct ArcShapeCacheEntry: public ShapeCacheEntry {
+ ArcShapeCacheEntry(float width, float height, float startAngle, float sweepAngle,
+ bool useCenter, SkPaint* paint):
+ ShapeCacheEntry(ShapeCacheEntry::kShapeArc, paint) {
+ mWidth = *(uint32_t*) &width;
+ mHeight = *(uint32_t*) &height;
+ mStartAngle = *(uint32_t*) &startAngle;
+ mSweepAngle = *(uint32_t*) &sweepAngle;
+ mUseCenter = useCenter ? 1 : 0;
+ }
+
+ ArcShapeCacheEntry(): ShapeCacheEntry() {
+ mWidth = 0;
+ mHeight = 0;
+ mStartAngle = 0;
+ mSweepAngle = 0;
+ mUseCenter = 0;
+ }
+
+ ArcShapeCacheEntry(const ArcShapeCacheEntry& entry):
+ ShapeCacheEntry(entry) {
+ mWidth = entry.mWidth;
+ mHeight = entry.mHeight;
+ mStartAngle = entry.mStartAngle;
+ mSweepAngle = entry.mSweepAngle;
+ mUseCenter = entry.mUseCenter;
+ }
+
+ bool lessThan(const ShapeCacheEntry& r) const {
+ const ArcShapeCacheEntry& rhs = (const ArcShapeCacheEntry&) r;
+ LTE_INT(mWidth) {
+ LTE_INT(mHeight) {
+ LTE_INT(mStartAngle) {
+ LTE_INT(mSweepAngle) {
+ LTE_INT(mUseCenter) {
+ return false;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+private:
+ uint32_t mWidth;
+ uint32_t mHeight;
+ uint32_t mStartAngle;
+ uint32_t mSweepAngle;
+ uint32_t mUseCenter;
+}; // ArcShapeCacheEntry
+
/**
* A simple LRU shape cache. The cache has a maximum size expressed in bytes.
* Any texture added to the cache causing the cache to grow beyond the maximum
@@ -370,6 +422,14 @@
PathTexture* getRect(float width, float height, SkPaint* paint);
}; // class RectShapeCache
+class ArcShapeCache: public ShapeCache<ArcShapeCacheEntry> {
+public:
+ ArcShapeCache();
+
+ PathTexture* getArc(float width, float height, float startAngle, float sweepAngle,
+ bool useCenter, SkPaint* paint);
+}; // class ArcShapeCache
+
///////////////////////////////////////////////////////////////////////////////
// Constructors/destructor
///////////////////////////////////////////////////////////////////////////////