Skip to content

Commit 34c55d3

Browse files
Romain GuyAndroid (Google) Code Review
authored andcommitted
Merge "Only recreate path textures when necessary"
2 parents 5d3bc7d + 4bcb746 commit 34c55d3

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)