Skip to content

Commit 4bcb746

Browse files
author
Romain Guy
committed
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
1 parent cfef123 commit 4bcb746

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

libs/hwui/DisplayListRenderer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ class DisplayListRenderer: public OpenGLRenderer {
462462
SkPath* pathCopy = mPathMap.valueFor(path);
463463
if (pathCopy == NULL || pathCopy->getGenerationID() != path->getGenerationID()) {
464464
pathCopy = new SkPath(*path);
465+
pathCopy->setSourcePath(path);
465466
// replaceValueFor() performs an add if the entry doesn't exist
466467
mPathMap.replaceValueFor(path, pathCopy);
467468
mPaths.add(pathCopy);

libs/hwui/PathCache.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ void PathCache::clearGarbage() {
8383
}
8484

8585
PathTexture* PathCache::get(SkPath* path, SkPaint* paint) {
86+
const SkPath* sourcePath = path->getSourcePath();
87+
if (sourcePath && sourcePath->getGenerationID() == path->getGenerationID()) {
88+
path = const_cast<SkPath*>(sourcePath);
89+
}
90+
8691
PathCacheEntry entry(path, paint);
8792
PathTexture* texture = mCache.get(entry);
8893

tests/HwAccelerationTest/src/com/android/test/hwui/PathsCacheActivity.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,24 @@ protected void onDraw(Canvas canvas) {
9292

9393
canvas.restore();
9494

95-
// Path path = makePath();
96-
// int r = mRandom.nextInt(10);
97-
// if (r == 5 || r == 3) {
98-
// mPathList.add(path);
99-
// } else if (r == 9) {
100-
// mPathList.clear();
101-
// }
102-
//
103-
// canvas.save();
104-
// canvas.translate(550.0f + mRandom.nextInt(50), 60.0f + mRandom.nextInt(50));
105-
// canvas.drawPath(path, mMediumPaint);
106-
// canvas.restore();
107-
//
95+
for (int i = 0; i < mRandom.nextInt(20); i++) {
96+
Path path = makePath();
97+
int r = mRandom.nextInt(10);
98+
if (r == 5 || r == 3) {
99+
mPathList.add(path);
100+
}
101+
102+
canvas.save();
103+
canvas.translate(450.0f + mRandom.nextInt(200), mRandom.nextInt(200));
104+
canvas.drawPath(path, mMediumPaint);
105+
canvas.restore();
106+
}
107+
108+
int r = mRandom.nextInt(100);
109+
if (r == 50) {
110+
mPathList.clear();
111+
}
112+
108113
invalidate();
109114
}
110115
}

0 commit comments

Comments
 (0)