summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Romain Guy <romainguy@google.com> 2012-02-23 17:08:38 -0800
committer Romain Guy <romainguy@google.com> 2012-02-23 17:08:38 -0800
commit4bcb7467a174ed03a67b0c62950c555813ddf00d (patch)
tree496ee923124a889d0a103fcc8dddba74515c2f81
parentcfef12374c15b11b3c2a1041582be9728152e15d (diff)
Only recreate path textures when necessary
When a drawPath command is recorded in a display list, a copy of the source path is made to preserve against possible modifications of the said source path. Copies are discarded when a display list is cleared, which usually happens on invalidate(). This means that even if a path is never modified, the texture generated to draw it on screen is destroyed every time an invalidate() is issued. This change fixes this problem by introducing a reference to the source path in the copy. If both the copy and the source path have the same genID, they are the same path and can share the same texture. Change-Id: I34849311c183e06336a1391d2d1568a087f973f6
-rw-r--r--libs/hwui/DisplayListRenderer.h1
-rw-r--r--libs/hwui/PathCache.cpp5
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/PathsCacheActivity.java31
3 files changed, 24 insertions, 13 deletions
diff --git a/libs/hwui/DisplayListRenderer.h b/libs/hwui/DisplayListRenderer.h
index 90a714526623..4a299c6eb47a 100644
--- a/libs/hwui/DisplayListRenderer.h
+++ b/libs/hwui/DisplayListRenderer.h
@@ -462,6 +462,7 @@ private:
SkPath* pathCopy = mPathMap.valueFor(path);
if (pathCopy == NULL || pathCopy->getGenerationID() != path->getGenerationID()) {
pathCopy = new SkPath(*path);
+ pathCopy->setSourcePath(path);
// replaceValueFor() performs an add if the entry doesn't exist
mPathMap.replaceValueFor(path, pathCopy);
mPaths.add(pathCopy);
diff --git a/libs/hwui/PathCache.cpp b/libs/hwui/PathCache.cpp
index e09c24381d9d..e363b73498df 100644
--- a/libs/hwui/PathCache.cpp
+++ b/libs/hwui/PathCache.cpp
@@ -83,6 +83,11 @@ void PathCache::clearGarbage() {
}
PathTexture* PathCache::get(SkPath* path, SkPaint* paint) {
+ const SkPath* sourcePath = path->getSourcePath();
+ if (sourcePath && sourcePath->getGenerationID() == path->getGenerationID()) {
+ path = const_cast<SkPath*>(sourcePath);
+ }
+
PathCacheEntry entry(path, paint);
PathTexture* texture = mCache.get(entry);
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/PathsCacheActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/PathsCacheActivity.java
index b8ad823bf73a..9ab2a860f7cc 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/PathsCacheActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/PathsCacheActivity.java
@@ -92,19 +92,24 @@ public class PathsCacheActivity extends Activity {
canvas.restore();
-// Path path = makePath();
-// int r = mRandom.nextInt(10);
-// if (r == 5 || r == 3) {
-// mPathList.add(path);
-// } else if (r == 9) {
-// mPathList.clear();
-// }
-//
-// canvas.save();
-// canvas.translate(550.0f + mRandom.nextInt(50), 60.0f + mRandom.nextInt(50));
-// canvas.drawPath(path, mMediumPaint);
-// canvas.restore();
-//
+ for (int i = 0; i < mRandom.nextInt(20); i++) {
+ Path path = makePath();
+ int r = mRandom.nextInt(10);
+ if (r == 5 || r == 3) {
+ mPathList.add(path);
+ }
+
+ canvas.save();
+ canvas.translate(450.0f + mRandom.nextInt(200), mRandom.nextInt(200));
+ canvas.drawPath(path, mMediumPaint);
+ canvas.restore();
+ }
+
+ int r = mRandom.nextInt(100);
+ if (r == 50) {
+ mPathList.clear();
+ }
+
invalidate();
}
}