summaryrefslogtreecommitdiffstats
path: root/libs/hwui/PathCache.cpp
diff options
context:
space:
mode:
authorDerek Sollenberger <djsollen@google.com>2015-02-12 14:10:21 -0500
committerDerek Sollenberger <djsollen@google.com>2015-03-13 08:05:55 -0400
commitee248599d49a15fc207c5aeb0b90ec263cc1d600 (patch)
treeabb62a362ef1962a3097a586b638c1d7efc93a31 /libs/hwui/PathCache.cpp
parent247dc6e125783b31f5c9a2cbccb34bd2ac575e6d (diff)
downloadframeworks_base-ee248599d49a15fc207c5aeb0b90ec263cc1d600.zip
frameworks_base-ee248599d49a15fc207c5aeb0b90ec263cc1d600.tar.gz
frameworks_base-ee248599d49a15fc207c5aeb0b90ec263cc1d600.tar.bz2
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
Diffstat (limited to 'libs/hwui/PathCache.cpp')
-rw-r--r--libs/hwui/PathCache.cpp61
1 files changed, 13 insertions, 48 deletions
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 @@ void PathCache::PathProcessor::onProcess(const sp<Task<SkBitmap*> >& task) {
// 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 @@ void PathCache::clearGarbage() {
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 @@ void PathCache::clearGarbage() {
}
}
-/**
- * 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 @@ PathTexture* PathCache::get(const SkPath* path, const SkPaint* paint) {
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 @@ void PathCache::precache(const SkPath* path, const SkPaint* paint) {
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) {