diff options
author | Chet Haase <chet@google.com> | 2010-10-25 15:47:32 -0700 |
---|---|---|
committer | Chet Haase <chet@google.com> | 2010-10-26 06:54:55 -0700 |
commit | d98aa2de9ab18e09c2be1997f41212740f51f6e6 (patch) | |
tree | 04bf505226c6a38fde7a466e28154e006e806f30 /libs/hwui/DisplayListRenderer.h | |
parent | 9bb127869666be6507fb5c4b37b7d1965c7e5fa6 (diff) | |
download | frameworks_base-d98aa2de9ab18e09c2be1997f41212740f51f6e6.zip frameworks_base-d98aa2de9ab18e09c2be1997f41212740f51f6e6.tar.gz frameworks_base-d98aa2de9ab18e09c2be1997f41212740f51f6e6.tar.bz2 |
DisplayList optimizations and fixes.
We now use a copy of SkPaint objects to avoid having it changed from under us.
We reuse copies that have not changed. We also copy the SkMatrix every time to
avoid the same problem.
Change-Id: If3fd80698f2d43ea16d23302063e0fd8d0549027
Diffstat (limited to 'libs/hwui/DisplayListRenderer.h')
-rw-r--r-- | libs/hwui/DisplayListRenderer.h | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/libs/hwui/DisplayListRenderer.h b/libs/hwui/DisplayListRenderer.h index c8cd801..ce4cfc5 100644 --- a/libs/hwui/DisplayListRenderer.h +++ b/libs/hwui/DisplayListRenderer.h @@ -182,10 +182,11 @@ private: PathHeap* mPathHeap; Vector<SkBitmap*> mBitmapResources; - Vector<SkMatrix*> mMatrixResources; - Vector<SkPaint*> mPaintResources; Vector<SkiaShader*> mShaderResources; + Vector<SkPaint*> mPaints; + Vector<SkMatrix*> mMatrices; + mutable SkFlattenableReadBuffer mReader; SkRefCntPlayback mRCPlayback; @@ -263,16 +264,16 @@ public: return mBitmapResources; } - const Vector<SkMatrix*>& getMatrixResources() const { - return mMatrixResources; + const Vector<SkiaShader*>& getShaderResources() const { + return mShaderResources; } - const Vector<SkPaint*>& getPaintResources() const { - return mPaintResources; + const Vector<SkPaint*>& getPaints() const { + return mPaints; } - const Vector<SkiaShader*>& getShaderResources() const { - return mShaderResources; + const Vector<SkMatrix*>& getMatrices() const { + return mMatrices; } private: @@ -334,20 +335,30 @@ private: } inline void addPaint(SkPaint* paint) { - addInt((int)paint); - mPaintResources.add(paint); - Caches& caches = Caches::getInstance(); - caches.resourceCache.incrementRefcount(paint); + if (paint == NULL) { + addInt((int)NULL); + return; + } + SkPaint *paintCopy = mPaintMap.valueFor(paint); + if (paintCopy == NULL || paintCopy->getGenerationID() != paint->getGenerationID()) { + paintCopy = new SkPaint(*paint); + mPaintMap.add(paint, paintCopy); + mPaints.add(paintCopy); + } + addInt((int)paintCopy); } inline void addMatrix(SkMatrix* matrix) { - addInt((int)matrix); - mMatrixResources.add(matrix); - Caches& caches = Caches::getInstance(); - caches.resourceCache.incrementRefcount(matrix); + // Copying the matrix is cheap and prevents against the user changing the original + // matrix before the operation that uses it + addInt((int) new SkMatrix(*matrix)); } inline void addBitmap(SkBitmap* bitmap) { + // Note that this assumes the bitmap is immutable. There are cases this won't handle + // correctly, such as creating the bitmap from scratch, drawing with it, changing its + // contents, and drawing again. The only fix would be to always copy it the first time, + // which doesn't seem worth the extra cycles for this unlikely case. addInt((int)bitmap); mBitmapResources.add(bitmap); Caches& caches = Caches::getInstance(); @@ -364,10 +375,12 @@ private: SkChunkAlloc mHeap; Vector<SkBitmap*> mBitmapResources; - Vector<SkMatrix*> mMatrixResources; - Vector<SkPaint*> mPaintResources; Vector<SkiaShader*> mShaderResources; + Vector<SkPaint*> mPaints; + DefaultKeyedVector<SkPaint *, SkPaint *> mPaintMap; + Vector<SkMatrix*> mMatrices; + PathHeap* mPathHeap; SkWriter32 mWriter; |