summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/hwui/Caches.h3
-rw-r--r--libs/hwui/DisplayListRenderer.cpp28
-rw-r--r--libs/hwui/DisplayListRenderer.h5
-rw-r--r--libs/hwui/OpenGLRenderer.cpp63
-rw-r--r--libs/hwui/OpenGLRenderer.h6
-rw-r--r--libs/hwui/ShapeCache.cpp77
-rw-r--r--libs/hwui/ShapeCache.h140
7 files changed, 306 insertions, 16 deletions
diff --git a/libs/hwui/Caches.h b/libs/hwui/Caches.h
index 24585d5a14e9..0a9335f23288 100644
--- a/libs/hwui/Caches.h
+++ b/libs/hwui/Caches.h
@@ -162,6 +162,9 @@ public:
PathCache pathCache;
RoundRectShapeCache roundRectShapeCache;
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 58ef7b3a1689..ffd3be470fe6 100644
--- a/libs/hwui/DisplayListRenderer.cpp
+++ b/libs/hwui/DisplayListRenderer.cpp
@@ -107,6 +107,8 @@ const char* DisplayList::OP_NAMES[] = {
"DrawRect",
"DrawRoundRect",
"DrawCircle",
+ "DrawOval",
+ "DrawArc",
"DrawPath",
"DrawLines",
"DrawText",
@@ -323,6 +325,7 @@ void DisplayList::replay(OpenGLRenderer& renderer, uint32_t level) {
renderer.drawBitmapMesh(bitmap, meshWidth, meshHeight, vertices, colors, getPaint());
}
+ break;
case DrawPatch: {
int32_t* xDivs = NULL;
int32_t* yDivs = NULL;
@@ -358,6 +361,15 @@ void DisplayList::replay(OpenGLRenderer& renderer, uint32_t level) {
renderer.drawCircle(getFloat(), getFloat(), getFloat(), getPaint());
}
break;
+ case DrawOval: {
+ 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());
}
@@ -663,6 +675,22 @@ void DisplayListRenderer::drawCircle(float x, float y, float radius, SkPaint* pa
addPaint(paint);
}
+void DisplayListRenderer::drawOval(float left, float top, float right, float bottom,
+ SkPaint* paint) {
+ addOp(DisplayList::DrawOval);
+ addBounds(left, top, right, bottom);
+ 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 68e4359ee90c..35bb163f9c62 100644
--- a/libs/hwui/DisplayListRenderer.h
+++ b/libs/hwui/DisplayListRenderer.h
@@ -113,6 +113,8 @@ public:
DrawRect,
DrawRoundRect,
DrawCircle,
+ DrawOval,
+ DrawArc,
DrawPath,
DrawLines,
DrawText,
@@ -279,6 +281,9 @@ public:
void drawRoundRect(float left, float top, float right, float bottom,
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 9aa3e7cffc61..e8dc9f6cfd86 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -1094,10 +1094,10 @@ void OpenGLRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHei
SkXfermode::Mode mode;
getAlphaAndMode(paint, &alpha, &mode);
- // TODO: Support the colors array
const uint32_t count = meshWidth * meshHeight * 6;
- TextureVertex mesh[count];
+ // TODO: Support the colors array
+ TextureVertex mesh[count];
TextureVertex* vertex = mesh;
for (int32_t y = 0; y < meshHeight; y++) {
for (int32_t x = 0; x < meshWidth; x++) {
@@ -1360,39 +1360,72 @@ void OpenGLRenderer::drawColor(int color, SkXfermode::Mode mode) {
drawColorRect(clip.left, clip.top, clip.right, clip.bottom, color, mode, true);
}
+void OpenGLRenderer::drawShape(float left, float top, const PathTexture* texture, SkPaint* paint) {
+ if (!texture) return;
+ const AutoTexture autoCleanup(texture);
+
+ const float x = left + texture->left - texture->offset;
+ const float y = top + texture->top - texture->offset;
+
+ drawPathTexture(texture, x, y, paint);
+}
+
void OpenGLRenderer::drawRoundRect(float left, float top, float right, float bottom,
float rx, float ry, SkPaint* paint) {
if (mSnapshot->isIgnored()) return;
glActiveTexture(gTextureUnits[0]);
-
const PathTexture* texture = mCaches.roundRectShapeCache.getRoundRect(
right - left, bottom - top, rx, ry, paint);
- if (!texture) return;
- const AutoTexture autoCleanup(texture);
+ drawShape(left, top, texture, paint);
+}
- const float x = left + texture->left - texture->offset;
- const float y = top + texture->top - texture->offset;
+void OpenGLRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) {
+ if (mSnapshot->isIgnored()) return;
- drawPathTexture(texture, x, y, paint);
+ glActiveTexture(gTextureUnits[0]);
+ const PathTexture* texture = mCaches.circleShapeCache.getCircle(radius, paint);
+ drawShape(x - radius, y - radius, texture, paint);
}
-void OpenGLRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) {
+void OpenGLRenderer::drawOval(float left, float top, float right, float bottom, SkPaint* paint) {
if (mSnapshot->isIgnored()) return;
glActiveTexture(gTextureUnits[0]);
+ const PathTexture* texture = mCaches.ovalShapeCache.getOval(right - left, bottom - top, paint);
+ drawShape(left, top, texture, paint);
+}
- const PathTexture* texture = mCaches.circleShapeCache.getCircle(radius, paint);
- if (!texture) return;
- const AutoTexture autoCleanup(texture);
+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);
+}
- const float left = (x - radius) + texture->left - texture->offset;
- const float top = (y - radius) + texture->top - texture->offset;
+void OpenGLRenderer::drawRectAsShape(float left, float top, float right, float bottom,
+ SkPaint* paint) {
+ if (mSnapshot->isIgnored()) return;
- drawPathTexture(texture, left, top, paint);
+ glActiveTexture(gTextureUnits[0]);
+ const PathTexture* texture = mCaches.rectShapeCache.getRect(right - left, bottom - top, paint);
+ drawShape(left, top, texture, paint);
}
void OpenGLRenderer::drawRect(float left, float top, float right, float bottom, SkPaint* p) {
+ if (p->getStyle() != SkPaint::kFill_Style) {
+ drawRectAsShape(left, top, right, bottom, p);
+ return;
+ }
+
if (quickReject(left, top, right, bottom)) {
return;
}
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index 42e93adfef22..eec37501784d 100644
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -112,6 +112,9 @@ public:
virtual void drawRoundRect(float left, float top, float right, float bottom,
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,
@@ -277,6 +280,9 @@ private:
void drawColorRect(float left, float top, float right, float bottom,
int color, SkXfermode::Mode mode, bool ignoreTransform = false);
+ void drawShape(float left, float top, const PathTexture* texture, SkPaint* paint);
+ void drawRectAsShape(float left, float top, float right, float bottom, SkPaint* p);
+
/**
* Draws a textured rectangle with the specified texture. The specified coordinates
* are transformed by the current snapshot's transform matrix.
diff --git a/libs/hwui/ShapeCache.cpp b/libs/hwui/ShapeCache.cpp
index b78eecba5215..0d7cd9cb9a72 100644
--- a/libs/hwui/ShapeCache.cpp
+++ b/libs/hwui/ShapeCache.cpp
@@ -68,5 +68,82 @@ PathTexture* CircleShapeCache::getCircle(float radius, SkPaint* paint) {
return texture;
}
+///////////////////////////////////////////////////////////////////////////////
+// Ovals
+///////////////////////////////////////////////////////////////////////////////
+
+OvalShapeCache::OvalShapeCache(): ShapeCache<OvalShapeCacheEntry>(
+ "oval", PROPERTY_SHAPE_CACHE_SIZE, DEFAULT_SHAPE_CACHE_SIZE) {
+}
+
+PathTexture* OvalShapeCache::getOval(float width, float height, SkPaint* paint) {
+ OvalShapeCacheEntry entry(width, height, paint);
+ PathTexture* texture = get(entry);
+
+ if (!texture) {
+ SkPath path;
+ SkRect r;
+ r.set(0.0f, 0.0f, width, height);
+ path.addOval(r, SkPath::kCW_Direction);
+
+ texture = addTexture(entry, &path, paint);
+ }
+
+ return texture;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// Rects
+///////////////////////////////////////////////////////////////////////////////
+
+RectShapeCache::RectShapeCache(): ShapeCache<RectShapeCacheEntry>(
+ "rect", PROPERTY_SHAPE_CACHE_SIZE, DEFAULT_SHAPE_CACHE_SIZE) {
+}
+
+PathTexture* RectShapeCache::getRect(float width, float height, SkPaint* paint) {
+ RectShapeCacheEntry entry(width, height, paint);
+ PathTexture* texture = get(entry);
+
+ if (!texture) {
+ SkPath path;
+ path.addRect(0.0f, 0.0f, width, height, SkPath::kCW_Direction);
+
+ texture = addTexture(entry, &path, paint);
+ }
+
+ 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 c62793180838..e53546605f13 100644
--- a/libs/hwui/ShapeCache.h
+++ b/libs/hwui/ShapeCache.h
@@ -76,6 +76,7 @@ struct PathTexture: public Texture {
struct ShapeCacheEntry {
enum ShapeType {
kShapeNone,
+ kShapeRect,
kShapeRoundRect,
kShapeCircle,
kShapeOval,
@@ -216,6 +217,122 @@ private:
uint32_t mRadius;
}; // CircleShapeCacheEntry
+struct OvalShapeCacheEntry: public ShapeCacheEntry {
+ OvalShapeCacheEntry(float width, float height, SkPaint* paint):
+ ShapeCacheEntry(ShapeCacheEntry::kShapeOval, paint) {
+ mWidth = *(uint32_t*) &width;
+ mHeight = *(uint32_t*) &height;
+ }
+
+ OvalShapeCacheEntry(): ShapeCacheEntry() {
+ mWidth = mHeight = 0;
+ }
+
+ OvalShapeCacheEntry(const OvalShapeCacheEntry& entry):
+ ShapeCacheEntry(entry) {
+ mWidth = entry.mWidth;
+ mHeight = entry.mHeight;
+ }
+
+ bool lessThan(const ShapeCacheEntry& r) const {
+ const OvalShapeCacheEntry& rhs = (const OvalShapeCacheEntry&) r;
+ LTE_INT(mWidth) {
+ LTE_INT(mHeight) {
+ return false;
+ }
+ }
+ return false;
+ }
+
+private:
+ uint32_t mWidth;
+ uint32_t mHeight;
+}; // OvalShapeCacheEntry
+
+struct RectShapeCacheEntry: public ShapeCacheEntry {
+ RectShapeCacheEntry(float width, float height, SkPaint* paint):
+ ShapeCacheEntry(ShapeCacheEntry::kShapeRect, paint) {
+ mWidth = *(uint32_t*) &width;
+ mHeight = *(uint32_t*) &height;
+ }
+
+ RectShapeCacheEntry(): ShapeCacheEntry() {
+ mWidth = mHeight = 0;
+ }
+
+ RectShapeCacheEntry(const RectShapeCacheEntry& entry):
+ ShapeCacheEntry(entry) {
+ mWidth = entry.mWidth;
+ mHeight = entry.mHeight;
+ }
+
+ bool lessThan(const ShapeCacheEntry& r) const {
+ const RectShapeCacheEntry& rhs = (const RectShapeCacheEntry&) r;
+ LTE_INT(mWidth) {
+ LTE_INT(mHeight) {
+ return false;
+ }
+ }
+ return false;
+ }
+
+private:
+ uint32_t mWidth;
+ 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
@@ -289,8 +406,29 @@ public:
CircleShapeCache();
PathTexture* getCircle(float radius, SkPaint* paint);
-}; // class RoundRectShapeCache
+}; // class CircleShapeCache
+
+class OvalShapeCache: public ShapeCache<OvalShapeCacheEntry> {
+public:
+ OvalShapeCache();
+
+ PathTexture* getOval(float width, float height, SkPaint* paint);
+}; // class OvalShapeCache
+
+class RectShapeCache: public ShapeCache<RectShapeCacheEntry> {
+public:
+ RectShapeCache();
+
+ 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