Refactor DisplayList path caching.
This removes dependence on SkPath ptrs that HWUI does not control
the lifecycle of. This clears up some errors where the paths are
not generated from Java, but rather the Skia test suites.
Cherry-pick of a change that originally landed in master-skia and is
dependent on a skia merge (ag/655422).
Change-Id: I41b9797a2b0af5d6b4ea51891565469d4f1d832d
diff --git a/libs/hwui/PathCache.cpp b/libs/hwui/PathCache.cpp
index e2caf8b..5b2e5e2 100644
--- a/libs/hwui/PathCache.cpp
+++ b/libs/hwui/PathCache.cpp
@@ -362,22 +362,9 @@
// Paths
///////////////////////////////////////////////////////////////////////////////
-void PathCache::remove(Vector<PathDescription>& pathsToRemove, const path_pair_t& pair) {
- LruCache<PathDescription, PathTexture*>::Iterator i(mCache);
-
- while (i.next()) {
- const PathDescription& key = i.key();
- if (key.type == kShapePath &&
- (key.shape.path.mPath == pair.getFirst() ||
- key.shape.path.mPath == pair.getSecond())) {
- pathsToRemove.push(key);
- }
- }
-}
-
-void PathCache::removeDeferred(SkPath* path) {
+void PathCache::removeDeferred(const SkPath* path) {
Mutex::Autolock l(mLock);
- mGarbage.push(path_pair_t(path, const_cast<SkPath*>(path->getSourcePath())));
+ mGarbage.push(path->getGenerationID());
}
void PathCache::clearGarbage() {
@@ -387,9 +374,15 @@
Mutex::Autolock l(mLock);
size_t count = mGarbage.size();
for (size_t i = 0; i < count; i++) {
- const path_pair_t& pair = mGarbage.itemAt(i);
- remove(pathsToRemove, pair);
- delete pair.getFirst();
+ const uint32_t generationID = mGarbage.itemAt(i);
+
+ LruCache<PathDescription, PathTexture*>::Iterator iter(mCache);
+ while (iter.next()) {
+ const PathDescription& key = iter.key();
+ if (key.type == kShapePath && key.shape.path.mGenerationID == generationID) {
+ pathsToRemove.push(key);
+ }
+ }
}
mGarbage.clear();
}
@@ -399,27 +392,9 @@
}
}
-/**
- * To properly handle path mutations at draw time we always make a copy
- * of paths objects when recording display lists. The source path points
- * to the path we originally copied the path from. This ensures we use
- * the original path as a cache key the first time a path is inserted
- * in the cache. The source path is also used to reclaim garbage when a
- * Dalvik Path object is collected.
- */
-static const SkPath* getSourcePath(const SkPath* path) {
- const SkPath* sourcePath = path->getSourcePath();
- if (sourcePath && sourcePath->getGenerationID() == path->getGenerationID()) {
- return const_cast<SkPath*>(sourcePath);
- }
- return path;
-}
-
PathTexture* PathCache::get(const SkPath* path, const SkPaint* paint) {
- path = getSourcePath(path);
-
PathDescription entry(kShapePath, paint);
- entry.shape.path.mPath = path;
+ entry.shape.path.mGenerationID = path->getGenerationID();
PathTexture* texture = mCache.get(entry);
@@ -442,11 +417,6 @@
texture = nullptr;
mCache.remove(entry);
}
- } else if (path->getGenerationID() != texture->generation) {
- // The size of the path might have changed so we first
- // remove the entry from the cache
- mCache.remove(entry);
- texture = addTexture(entry, path, paint);
}
}
@@ -458,19 +428,14 @@
return;
}
- path = getSourcePath(path);
-
PathDescription entry(kShapePath, paint);
- entry.shape.path.mPath = path;
+ entry.shape.path.mGenerationID = path->getGenerationID();
PathTexture* texture = mCache.get(entry);
bool generate = false;
if (!texture) {
generate = true;
- } else if (path->getGenerationID() != texture->generation) {
- mCache.remove(entry);
- generate = true;
}
if (generate) {