diff options
Diffstat (limited to 'libs')
-rw-r--r-- | libs/hwui/Android.common.mk | 2 | ||||
-rw-r--r-- | libs/hwui/AssetAtlas.cpp | 22 | ||||
-rw-r--r-- | libs/hwui/AssetAtlas.h | 62 | ||||
-rw-r--r-- | libs/hwui/Caches.cpp | 1 | ||||
-rw-r--r-- | libs/hwui/Canvas.h | 7 | ||||
-rw-r--r-- | libs/hwui/CanvasState.h | 11 | ||||
-rw-r--r-- | libs/hwui/DisplayList.h | 4 | ||||
-rw-r--r-- | libs/hwui/DisplayListCanvas.cpp (renamed from libs/hwui/DisplayListRenderer.cpp) | 143 | ||||
-rw-r--r-- | libs/hwui/DisplayListCanvas.h (renamed from libs/hwui/DisplayListRenderer.h) | 20 | ||||
-rw-r--r-- | libs/hwui/DisplayListOp.h | 2 | ||||
-rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 4 | ||||
-rw-r--r-- | libs/hwui/PathCache.cpp | 4 | ||||
-rw-r--r-- | libs/hwui/RenderNode.h | 4 | ||||
-rw-r--r-- | libs/hwui/ResourceCache.cpp | 6 | ||||
-rw-r--r-- | libs/hwui/ResourceCache.h | 10 | ||||
-rw-r--r-- | libs/hwui/SkiaCanvas.cpp | 28 | ||||
-rw-r--r-- | libs/hwui/TessellationCache.cpp | 9 | ||||
-rw-r--r-- | libs/hwui/renderthread/RenderProxy.cpp | 4 | ||||
-rw-r--r-- | libs/hwui/renderthread/RenderProxy.h | 2 | ||||
-rw-r--r-- | libs/hwui/tests/main.cpp | 24 | ||||
-rw-r--r-- | libs/hwui/thread/TaskProcessor.h | 16 |
21 files changed, 194 insertions, 191 deletions
diff --git a/libs/hwui/Android.common.mk b/libs/hwui/Android.common.mk index ecb625b..5fca8ec 100644 --- a/libs/hwui/Android.common.mk +++ b/libs/hwui/Android.common.mk @@ -37,7 +37,7 @@ LOCAL_SRC_FILES := \ DeferredDisplayList.cpp \ DeferredLayerUpdater.cpp \ DisplayList.cpp \ - DisplayListRenderer.cpp \ + DisplayListCanvas.cpp \ Dither.cpp \ DrawProfiler.cpp \ Extensions.cpp \ diff --git a/libs/hwui/AssetAtlas.cpp b/libs/hwui/AssetAtlas.cpp index 882826e..4d2e3a0 100644 --- a/libs/hwui/AssetAtlas.cpp +++ b/libs/hwui/AssetAtlas.cpp @@ -82,12 +82,12 @@ void AssetAtlas::updateTextureId() { /////////////////////////////////////////////////////////////////////////////// AssetAtlas::Entry* AssetAtlas::getEntry(const SkBitmap* bitmap) const { - ssize_t index = mEntries.indexOfKey(bitmap->pixelRef()); + ssize_t index = mEntries.indexOfKey(bitmap); return index >= 0 ? mEntries.valueAt(index) : nullptr; } Texture* AssetAtlas::getEntryTexture(const SkBitmap* bitmap) const { - ssize_t index = mEntries.indexOfKey(bitmap->pixelRef()); + ssize_t index = mEntries.indexOfKey(bitmap); return index >= 0 ? mEntries.valueAt(index)->texture : nullptr; } @@ -120,7 +120,7 @@ void AssetAtlas::createEntries(Caches& caches, int64_t* map, int count) { const float height = float(mTexture->height); for (int i = 0; i < count; ) { - SkPixelRef* pixelRef = reinterpret_cast<SkPixelRef*>(map[i++]); + SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(map[i++]); // NOTE: We're converting from 64 bit signed values to 32 bit // signed values. This is guaranteed to be safe because the "x" // and "y" coordinate values are guaranteed to be representable @@ -131,21 +131,21 @@ void AssetAtlas::createEntries(Caches& caches, int64_t* map, int count) { bool rotated = map[i++] > 0; // Bitmaps should never be null, we're just extra paranoid - if (!pixelRef) continue; + if (!bitmap) continue; const UvMapper mapper( - x / width, (x + pixelRef->info().width()) / width, - y / height, (y + pixelRef->info().height()) / height); + x / width, (x + bitmap->width()) / width, + y / height, (y + bitmap->height()) / height); Texture* texture = new DelegateTexture(caches, mTexture); - texture->blend = !SkAlphaTypeIsOpaque(pixelRef->info().alphaType()); - texture->width = pixelRef->info().width(); - texture->height = pixelRef->info().height(); + texture->blend = !bitmap->isOpaque(); + texture->width = bitmap->width(); + texture->height = bitmap->height(); - Entry* entry = new Entry(pixelRef, x, y, rotated, texture, mapper, *this); + Entry* entry = new Entry(bitmap, x, y, rotated, texture, mapper, *this); texture->uvMapper = &entry->uvMapper; - mEntries.add(entry->pixelRef, entry); + mEntries.add(entry->bitmap, entry); } } diff --git a/libs/hwui/AssetAtlas.h b/libs/hwui/AssetAtlas.h index 17c5281..1772eff 100644 --- a/libs/hwui/AssetAtlas.h +++ b/libs/hwui/AssetAtlas.h @@ -48,8 +48,24 @@ public: * Entry representing the position and rotation of a * bitmap inside the atlas. */ - class Entry { - public: + struct Entry { + /** + * The bitmap that generated this atlas entry. + */ + SkBitmap* bitmap; + + /** + * Location of the bitmap inside the atlas, in pixels. + */ + int x; + int y; + + /** + * If set, the bitmap is rotated 90 degrees (clockwise) + * inside the atlas. + */ + bool rotated; + /* * A "virtual texture" object that represents the texture * this entry belongs to. This texture should never be @@ -64,6 +80,11 @@ public: const UvMapper uvMapper; /** + * Atlas this entry belongs to. + */ + const AssetAtlas& atlas; + + /** * Unique identifier used to merge bitmaps and 9-patches stored * in the atlas. */ @@ -72,37 +93,10 @@ public: } private: - /** - * The pixel ref that generated this atlas entry. - */ - SkPixelRef* pixelRef; - - /** - * Location of the bitmap inside the atlas, in pixels. - */ - int x; - int y; - - /** - * If set, the bitmap is rotated 90 degrees (clockwise) - * inside the atlas. - */ - bool rotated; - - /** - * Atlas this entry belongs to. - */ - const AssetAtlas& atlas; - - Entry(SkPixelRef* pixelRef, int x, int y, bool rotated, - Texture* texture, const UvMapper& mapper, const AssetAtlas& atlas) - : texture(texture) - , uvMapper(mapper) - , pixelRef(pixelRef) - , x(x) - , y(y) - , rotated(rotated) - , atlas(atlas) { + Entry(SkBitmap* bitmap, int x, int y, bool rotated, + Texture* texture, const UvMapper& mapper, const AssetAtlas& atlas): + bitmap(bitmap), x(x), y(y), rotated(rotated), + texture(texture), uvMapper(mapper), atlas(atlas) { } ~Entry() { @@ -184,7 +178,7 @@ private: const bool mBlendKey; const bool mOpaqueKey; - KeyedVector<const SkPixelRef*, Entry*> mEntries; + KeyedVector<const SkBitmap*, Entry*> mEntries; }; // class AssetAtlas }; // namespace uirenderer diff --git a/libs/hwui/Caches.cpp b/libs/hwui/Caches.cpp index e5489a8..fd5a2ce 100644 --- a/libs/hwui/Caches.cpp +++ b/libs/hwui/Caches.cpp @@ -18,7 +18,6 @@ #include "Caches.h" -#include "DisplayListRenderer.h" #include "GammaFontRenderer.h" #include "LayerRenderer.h" #include "Properties.h" diff --git a/libs/hwui/Canvas.h b/libs/hwui/Canvas.h index aa24673..7ad0683 100644 --- a/libs/hwui/Canvas.h +++ b/libs/hwui/Canvas.h @@ -29,7 +29,7 @@ class ANDROID_API Canvas { public: virtual ~Canvas() {}; - static Canvas* create_canvas(const SkBitmap& bitmap); + static Canvas* create_canvas(SkBitmap* bitmap); /** * Create a new Canvas object which delegates to an SkCanvas. @@ -52,7 +52,7 @@ public: */ virtual SkCanvas* asSkCanvas() = 0; - virtual void setBitmap(const SkBitmap& bitmap) = 0; + virtual void setBitmap(SkBitmap* bitmap, bool copyState) = 0; virtual bool isOpaque() = 0; virtual int width() = 0; @@ -87,8 +87,7 @@ public: virtual bool quickRejectRect(float left, float top, float right, float bottom) const = 0; virtual bool quickRejectPath(const SkPath& path) const = 0; - virtual bool clipRect(float left, float top, float right, float bottom, - SkRegion::Op op = SkRegion::kIntersect_Op) = 0; + virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op) = 0; virtual bool clipPath(const SkPath* path, SkRegion::Op op) = 0; virtual bool clipRegion(const SkRegion* region, SkRegion::Op op) = 0; diff --git a/libs/hwui/CanvasState.h b/libs/hwui/CanvasState.h index 4db5ed2..8e4a4d3 100644 --- a/libs/hwui/CanvasState.h +++ b/libs/hwui/CanvasState.h @@ -62,12 +62,13 @@ public: * Renderer interface. Drawing and recording classes that include a CanvasState will have * different use cases: * - * Drawing subclasses (i.e. OpenGLRenderer) can query attributes (such as transform) or hook into - * changes (e.g. save/restore) with minimal surface area for manipulating the stack itself. + * Drawing code maintaining canvas state (i.e. OpenGLRenderer) can query attributes (such as + * transform) or hook into changes (e.g. save/restore) with minimal surface area for manipulating + * the stack itself. * - * Recording subclasses (i.e. DisplayListRenderer) can both record and pass through state operations - * to CanvasState, so that not only will querying operations work (getClip/Matrix), but so - * that quickRejection can also be used. + * Recording code maintaining canvas state (i.e. DisplayListCanvas) can both record and pass + * through state operations to CanvasState, so that not only will querying operations work + * (getClip/Matrix), but so that quickRejection can also be used. */ class ANDROID_API CanvasState { diff --git a/libs/hwui/DisplayList.h b/libs/hwui/DisplayList.h index 3178584..7fbda1f 100644 --- a/libs/hwui/DisplayList.h +++ b/libs/hwui/DisplayList.h @@ -53,7 +53,7 @@ namespace uirenderer { class DeferredDisplayList; class DisplayListOp; -class DisplayListRenderer; +class DisplayListCanvas; class OpenGLRenderer; class Rect; class Layer; @@ -109,7 +109,7 @@ struct ReplayStateStruct : public PlaybackStateStruct { * Data structure that holds the list of commands used in display list stream */ class DisplayListData { - friend class DisplayListRenderer; + friend class DisplayListCanvas; public: struct Chunk { // range of included ops in DLD::displayListOps diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListCanvas.cpp index 4d596fe..6b86030 100644 --- a/libs/hwui/DisplayListRenderer.cpp +++ b/libs/hwui/DisplayListCanvas.cpp @@ -14,25 +14,24 @@ * limitations under the License. */ -#define LOG_TAG "OpenGLRenderer" - -#include <SkCamera.h> -#include <SkCanvas.h> - -#include <private/hwui/DrawGlInfo.h> +#include "DisplayListCanvas.h" #include "ResourceCache.h" #include "DeferredDisplayList.h" #include "DeferredLayerUpdater.h" #include "DisplayListOp.h" -#include "DisplayListRenderer.h" #include "RenderNode.h" #include "utils/PaintUtils.h" +#include <SkCamera.h> +#include <SkCanvas.h> + +#include <private/hwui/DrawGlInfo.h> + namespace android { namespace uirenderer { -DisplayListRenderer::DisplayListRenderer() +DisplayListCanvas::DisplayListCanvas() : mState(*this) , mResourceCache(ResourceCache::getInstance()) , mDisplayListData(nullptr) @@ -44,16 +43,16 @@ DisplayListRenderer::DisplayListRenderer() , mRestoreSaveCount(-1) { } -DisplayListRenderer::~DisplayListRenderer() { +DisplayListCanvas::~DisplayListCanvas() { LOG_ALWAYS_FATAL_IF(mDisplayListData, - "Destroyed a DisplayListRenderer during a record!"); + "Destroyed a DisplayListCanvas during a record!"); } /////////////////////////////////////////////////////////////////////////////// // Operations /////////////////////////////////////////////////////////////////////////////// -DisplayListData* DisplayListRenderer::finishRecording() { +DisplayListData* DisplayListCanvas::finishRecording() { mPaintMap.clear(); mRegionMap.clear(); mPathMap.clear(); @@ -63,7 +62,7 @@ DisplayListData* DisplayListRenderer::finishRecording() { return data; } -void DisplayListRenderer::prepareDirty(float left, float top, +void DisplayListCanvas::prepareDirty(float left, float top, float right, float bottom) { LOG_ALWAYS_FATAL_IF(mDisplayListData, @@ -77,25 +76,25 @@ void DisplayListRenderer::prepareDirty(float left, float top, mRestoreSaveCount = -1; } -bool DisplayListRenderer::finish() { +bool DisplayListCanvas::finish() { flushRestoreToCount(); flushTranslate(); return false; } -void DisplayListRenderer::interrupt() { +void DisplayListCanvas::interrupt() { } -void DisplayListRenderer::resume() { +void DisplayListCanvas::resume() { } -void DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) { +void DisplayListCanvas::callDrawGLFunction(Functor *functor, Rect& dirty) { // Ignore dirty during recording, it matters only when we replay addDrawOp(new (alloc()) DrawFunctorOp(functor)); mDisplayListData->functors.add(functor); } -SkCanvas* DisplayListRenderer::asSkCanvas() { +SkCanvas* DisplayListCanvas::asSkCanvas() { LOG_ALWAYS_FATAL_IF(!mDisplayListData, "attempting to get an SkCanvas when we are not recording!"); if (!mSkiaCanvasProxy) { @@ -104,12 +103,12 @@ SkCanvas* DisplayListRenderer::asSkCanvas() { return mSkiaCanvasProxy.get(); } -int DisplayListRenderer::save(SkCanvas::SaveFlags flags) { +int DisplayListCanvas::save(SkCanvas::SaveFlags flags) { addStateOp(new (alloc()) SaveOp((int) flags)); return mState.save((int) flags); } -void DisplayListRenderer::restore() { +void DisplayListCanvas::restore() { if (mRestoreSaveCount < 0) { restoreToCount(getSaveCount() - 1); return; @@ -120,13 +119,13 @@ void DisplayListRenderer::restore() { mState.restore(); } -void DisplayListRenderer::restoreToCount(int saveCount) { +void DisplayListCanvas::restoreToCount(int saveCount) { mRestoreSaveCount = saveCount; flushTranslate(); mState.restoreToCount(saveCount); } -int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom, +int DisplayListCanvas::saveLayer(float left, float top, float right, float bottom, const SkPaint* paint, SkCanvas::SaveFlags flags) { // force matrix/clip isolation for layer flags |= SkCanvas::kClip_SaveFlag | SkCanvas::kMatrix_SaveFlag; @@ -136,7 +135,7 @@ int DisplayListRenderer::saveLayer(float left, float top, float right, float bot return mState.save((int) flags); } -void DisplayListRenderer::translate(float dx, float dy) { +void DisplayListCanvas::translate(float dx, float dy) { mHasDeferredTranslate = true; mTranslateX += dx; mTranslateY += dy; @@ -144,66 +143,66 @@ void DisplayListRenderer::translate(float dx, float dy) { mState.translate(dx, dy, 0.0f); } -void DisplayListRenderer::rotate(float degrees) { +void DisplayListCanvas::rotate(float degrees) { addStateOp(new (alloc()) RotateOp(degrees)); mState.rotate(degrees); } -void DisplayListRenderer::scale(float sx, float sy) { +void DisplayListCanvas::scale(float sx, float sy) { addStateOp(new (alloc()) ScaleOp(sx, sy)); mState.scale(sx, sy); } -void DisplayListRenderer::skew(float sx, float sy) { +void DisplayListCanvas::skew(float sx, float sy) { addStateOp(new (alloc()) SkewOp(sx, sy)); mState.skew(sx, sy); } -void DisplayListRenderer::setMatrix(const SkMatrix& matrix) { +void DisplayListCanvas::setMatrix(const SkMatrix& matrix) { addStateOp(new (alloc()) SetMatrixOp(matrix)); mState.setMatrix(matrix); } -void DisplayListRenderer::concat(const SkMatrix& matrix) { +void DisplayListCanvas::concat(const SkMatrix& matrix) { addStateOp(new (alloc()) ConcatMatrixOp(matrix)); mState.concatMatrix(matrix); } -bool DisplayListRenderer::getClipBounds(SkRect* outRect) const { +bool DisplayListCanvas::getClipBounds(SkRect* outRect) const { Rect bounds = mState.getLocalClipBounds(); *outRect = SkRect::MakeLTRB(bounds.left, bounds.top, bounds.right, bounds.bottom); return !(outRect->isEmpty()); } -bool DisplayListRenderer::quickRejectRect(float left, float top, float right, float bottom) const { +bool DisplayListCanvas::quickRejectRect(float left, float top, float right, float bottom) const { return mState.quickRejectConservative(left, top, right, bottom); } -bool DisplayListRenderer::quickRejectPath(const SkPath& path) const { +bool DisplayListCanvas::quickRejectPath(const SkPath& path) const { SkRect bounds = path.getBounds(); return mState.quickRejectConservative(bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); } -bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom, +bool DisplayListCanvas::clipRect(float left, float top, float right, float bottom, SkRegion::Op op) { addStateOp(new (alloc()) ClipRectOp(left, top, right, bottom, op)); return mState.clipRect(left, top, right, bottom, op); } -bool DisplayListRenderer::clipPath(const SkPath* path, SkRegion::Op op) { +bool DisplayListCanvas::clipPath(const SkPath* path, SkRegion::Op op) { path = refPath(path); addStateOp(new (alloc()) ClipPathOp(path, op)); return mState.clipPath(path, op); } -bool DisplayListRenderer::clipRegion(const SkRegion* region, SkRegion::Op op) { +bool DisplayListCanvas::clipRegion(const SkRegion* region, SkRegion::Op op) { region = refRegion(region); addStateOp(new (alloc()) ClipRegionOp(region, op)); return mState.clipRegion(region, op); } -void DisplayListRenderer::drawRenderNode(RenderNode* renderNode, Rect& dirty, int32_t flags) { +void DisplayListCanvas::drawRenderNode(RenderNode* renderNode, Rect& dirty, int32_t flags) { LOG_ALWAYS_FATAL_IF(!renderNode, "missing rendernode"); // dirty is an out parameter and should not be recorded, @@ -212,21 +211,21 @@ void DisplayListRenderer::drawRenderNode(RenderNode* renderNode, Rect& dirty, in addRenderNodeOp(op); } -void DisplayListRenderer::drawLayer(DeferredLayerUpdater* layerHandle, float x, float y) { +void DisplayListCanvas::drawLayer(DeferredLayerUpdater* layerHandle, float x, float y) { // We ref the DeferredLayerUpdater due to its thread-safe ref-counting // semantics. mDisplayListData->ref(layerHandle); addDrawOp(new (alloc()) DrawLayerOp(layerHandle->backingLayer(), x, y)); } -void DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, const SkPaint* paint) { - bitmap = refBitmap(*bitmap); +void DisplayListCanvas::drawBitmap(const SkBitmap* bitmap, const SkPaint* paint) { + bitmap = refBitmap(bitmap); paint = refPaint(paint); addDrawOp(new (alloc()) DrawBitmapOp(bitmap, paint)); } -void DisplayListRenderer::drawBitmap(const SkBitmap& bitmap, float left, float top, +void DisplayListCanvas::drawBitmap(const SkBitmap& bitmap, float left, float top, const SkPaint* paint) { save(SkCanvas::kMatrix_SaveFlag); translate(left, top); @@ -234,7 +233,7 @@ void DisplayListRenderer::drawBitmap(const SkBitmap& bitmap, float left, float t restore(); } -void DisplayListRenderer::drawBitmap(const SkBitmap& bitmap, const SkMatrix& matrix, +void DisplayListCanvas::drawBitmap(const SkBitmap& bitmap, const SkMatrix& matrix, const SkPaint* paint) { if (matrix.isIdentity()) { drawBitmap(&bitmap, paint); @@ -254,7 +253,7 @@ void DisplayListRenderer::drawBitmap(const SkBitmap& bitmap, const SkMatrix& mat } } -void DisplayListRenderer::drawBitmap(const SkBitmap& bitmap, float srcLeft, float srcTop, +void DisplayListCanvas::drawBitmap(const SkBitmap& bitmap, float srcLeft, float srcTop, float srcRight, float srcBottom, float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint) { if (srcLeft == 0 && srcTop == 0 @@ -286,7 +285,7 @@ void DisplayListRenderer::drawBitmap(const SkBitmap& bitmap, float srcLeft, floa dstRight = srcRight - srcLeft; dstBottom = srcBottom - srcTop; - addDrawOp(new (alloc()) DrawBitmapRectOp(refBitmap(bitmap), + addDrawOp(new (alloc()) DrawBitmapRectOp(refBitmap(&bitmap), srcLeft, srcTop, srcRight, srcBottom, dstLeft, dstTop, dstRight, dstBottom, paint)); restore(); @@ -294,37 +293,37 @@ void DisplayListRenderer::drawBitmap(const SkBitmap& bitmap, float srcLeft, floa } } - addDrawOp(new (alloc()) DrawBitmapRectOp(refBitmap(bitmap), + addDrawOp(new (alloc()) DrawBitmapRectOp(refBitmap(&bitmap), srcLeft, srcTop, srcRight, srcBottom, dstLeft, dstTop, dstRight, dstBottom, paint)); } } -void DisplayListRenderer::drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight, +void DisplayListCanvas::drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight, const float* vertices, const int* colors, const SkPaint* paint) { int vertexCount = (meshWidth + 1) * (meshHeight + 1); vertices = refBuffer<float>(vertices, vertexCount * 2); // 2 floats per vertex paint = refPaint(paint); colors = refBuffer<int>(colors, vertexCount); // 1 color per vertex - addDrawOp(new (alloc()) DrawBitmapMeshOp(refBitmap(bitmap), meshWidth, meshHeight, + addDrawOp(new (alloc()) DrawBitmapMeshOp(refBitmap(&bitmap), meshWidth, meshHeight, vertices, colors, paint)); } -void DisplayListRenderer::drawPatch(const SkBitmap& bitmap, const Res_png_9patch* patch, +void DisplayListCanvas::drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch, float left, float top, float right, float bottom, const SkPaint* paint) { - const SkBitmap* bitmapPtr = refBitmap(bitmap); + bitmap = refBitmap(bitmap); patch = refPatch(patch); paint = refPaint(paint); - addDrawOp(new (alloc()) DrawPatchOp(bitmapPtr, patch, left, top, right, bottom, paint)); + addDrawOp(new (alloc()) DrawPatchOp(bitmap, patch, left, top, right, bottom, paint)); } -void DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) { +void DisplayListCanvas::drawColor(int color, SkXfermode::Mode mode) { addDrawOp(new (alloc()) DrawColorOp(color, mode)); } -void DisplayListRenderer::drawPaint(const SkPaint& paint) { +void DisplayListCanvas::drawPaint(const SkPaint& paint) { SkRect bounds; if (getClipBounds(&bounds)) { drawRect(bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom, paint); @@ -332,17 +331,17 @@ void DisplayListRenderer::drawPaint(const SkPaint& paint) { } -void DisplayListRenderer::drawRect(float left, float top, float right, float bottom, +void DisplayListCanvas::drawRect(float left, float top, float right, float bottom, const SkPaint& paint) { addDrawOp(new (alloc()) DrawRectOp(left, top, right, bottom, refPaint(&paint))); } -void DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom, +void DisplayListCanvas::drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, const SkPaint& paint) { addDrawOp(new (alloc()) DrawRoundRectOp(left, top, right, bottom, rx, ry, refPaint(&paint))); } -void DisplayListRenderer::drawRoundRect( +void DisplayListCanvas::drawRoundRect( CanvasPropertyPrimitive* left, CanvasPropertyPrimitive* top, CanvasPropertyPrimitive* right, CanvasPropertyPrimitive* bottom, CanvasPropertyPrimitive* rx, CanvasPropertyPrimitive* ry, @@ -358,11 +357,11 @@ void DisplayListRenderer::drawRoundRect( &right->value, &bottom->value, &rx->value, &ry->value, &paint->value)); } -void DisplayListRenderer::drawCircle(float x, float y, float radius, const SkPaint& paint) { +void DisplayListCanvas::drawCircle(float x, float y, float radius, const SkPaint& paint) { addDrawOp(new (alloc()) DrawCircleOp(x, y, radius, refPaint(&paint))); } -void DisplayListRenderer::drawCircle(CanvasPropertyPrimitive* x, CanvasPropertyPrimitive* y, +void DisplayListCanvas::drawCircle(CanvasPropertyPrimitive* x, CanvasPropertyPrimitive* y, CanvasPropertyPrimitive* radius, CanvasPropertyPaint* paint) { mDisplayListData->ref(x); mDisplayListData->ref(y); @@ -372,12 +371,12 @@ void DisplayListRenderer::drawCircle(CanvasPropertyPrimitive* x, CanvasPropertyP &radius->value, &paint->value)); } -void DisplayListRenderer::drawOval(float left, float top, float right, float bottom, +void DisplayListCanvas::drawOval(float left, float top, float right, float bottom, const SkPaint& paint) { addDrawOp(new (alloc()) DrawOvalOp(left, top, right, bottom, refPaint(&paint))); } -void DisplayListRenderer::drawArc(float left, float top, float right, float bottom, +void DisplayListCanvas::drawArc(float left, float top, float right, float bottom, float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) { if (fabs(sweepAngle) >= 360.0f) { drawOval(left, top, right, bottom, paint); @@ -387,23 +386,23 @@ void DisplayListRenderer::drawArc(float left, float top, float right, float bott } } -void DisplayListRenderer::drawPath(const SkPath& path, const SkPaint& paint) { +void DisplayListCanvas::drawPath(const SkPath& path, const SkPaint& paint) { addDrawOp(new (alloc()) DrawPathOp(refPath(&path), refPaint(&paint))); } -void DisplayListRenderer::drawLines(const float* points, int count, const SkPaint& paint) { +void DisplayListCanvas::drawLines(const float* points, int count, const SkPaint& paint) { points = refBuffer<float>(points, count); addDrawOp(new (alloc()) DrawLinesOp(points, count, refPaint(&paint))); } -void DisplayListRenderer::drawPoints(const float* points, int count, const SkPaint& paint) { +void DisplayListCanvas::drawPoints(const float* points, int count, const SkPaint& paint) { points = refBuffer<float>(points, count); addDrawOp(new (alloc()) DrawPointsOp(points, count, refPaint(&paint))); } -void DisplayListRenderer::drawTextOnPath(const uint16_t* glyphs, int count, +void DisplayListCanvas::drawTextOnPath(const uint16_t* glyphs, int count, const SkPath& path, float hOffset, float vOffset, const SkPaint& paint) { if (!glyphs || count <= 0) return; @@ -414,7 +413,7 @@ void DisplayListRenderer::drawTextOnPath(const uint16_t* glyphs, int count, addDrawOp(op); } -void DisplayListRenderer::drawPosText(const uint16_t* text, const float* positions, +void DisplayListCanvas::drawPosText(const uint16_t* text, const float* positions, int count, int posCount, const SkPaint& paint) { if (!text || count <= 0) return; @@ -436,7 +435,7 @@ static void simplifyPaint(int color, SkPaint* paint) { paint->setLooper(nullptr); } -void DisplayListRenderer::drawText(const uint16_t* glyphs, const float* positions, +void DisplayListCanvas::drawText(const uint16_t* glyphs, const float* positions, int count, const SkPaint& paint, float x, float y, float boundsLeft, float boundsTop, float boundsRight, float boundsBottom, float totalAdvance) { @@ -475,7 +474,7 @@ void DisplayListRenderer::drawText(const uint16_t* glyphs, const float* position } } -void DisplayListRenderer::drawRects(const float* rects, int count, const SkPaint* paint) { +void DisplayListCanvas::drawRects(const float* rects, int count, const SkPaint* paint) { if (count <= 0) return; rects = refBuffer<float>(rects, count); @@ -483,24 +482,24 @@ void DisplayListRenderer::drawRects(const float* rects, int count, const SkPaint addDrawOp(new (alloc()) DrawRectsOp(rects, count, paint)); } -void DisplayListRenderer::setDrawFilter(SkDrawFilter* filter) { +void DisplayListCanvas::setDrawFilter(SkDrawFilter* filter) { mDrawFilter.reset(SkSafeRef(filter)); } -void DisplayListRenderer::insertReorderBarrier(bool enableReorder) { +void DisplayListCanvas::insertReorderBarrier(bool enableReorder) { flushRestoreToCount(); flushTranslate(); mDeferredBarrierType = enableReorder ? kBarrier_OutOfOrder : kBarrier_InOrder; } -void DisplayListRenderer::flushRestoreToCount() { +void DisplayListCanvas::flushRestoreToCount() { if (mRestoreSaveCount >= 0) { addOpAndUpdateChunk(new (alloc()) RestoreToCountOp(mRestoreSaveCount)); mRestoreSaveCount = -1; } } -void DisplayListRenderer::flushTranslate() { +void DisplayListCanvas::flushTranslate() { if (mHasDeferredTranslate) { if (mTranslateX != 0.0f || mTranslateY != 0.0f) { addOpAndUpdateChunk(new (alloc()) TranslateOp(mTranslateX, mTranslateY)); @@ -510,7 +509,7 @@ void DisplayListRenderer::flushTranslate() { } } -size_t DisplayListRenderer::addOpAndUpdateChunk(DisplayListOp* op) { +size_t DisplayListCanvas::addOpAndUpdateChunk(DisplayListOp* op) { int insertIndex = mDisplayListData->displayListOps.add(op); if (mDeferredBarrierType != kBarrier_None) { // op is first in new chunk @@ -530,17 +529,17 @@ size_t DisplayListRenderer::addOpAndUpdateChunk(DisplayListOp* op) { return insertIndex; } -size_t DisplayListRenderer::flushAndAddOp(DisplayListOp* op) { +size_t DisplayListCanvas::flushAndAddOp(DisplayListOp* op) { flushRestoreToCount(); flushTranslate(); return addOpAndUpdateChunk(op); } -size_t DisplayListRenderer::addStateOp(StateOp* op) { +size_t DisplayListCanvas::addStateOp(StateOp* op) { return flushAndAddOp(op); } -size_t DisplayListRenderer::addDrawOp(DrawOp* op) { +size_t DisplayListCanvas::addDrawOp(DrawOp* op) { Rect localBounds; if (op->getLocalBounds(localBounds)) { bool rejected = quickRejectRect(localBounds.left, localBounds.top, @@ -552,7 +551,7 @@ size_t DisplayListRenderer::addDrawOp(DrawOp* op) { return flushAndAddOp(op); } -size_t DisplayListRenderer::addRenderNodeOp(DrawRenderNodeOp* op) { +size_t DisplayListCanvas::addRenderNodeOp(DrawRenderNodeOp* op) { int opIndex = addDrawOp(op); int childIndex = mDisplayListData->addChild(op); diff --git a/libs/hwui/DisplayListRenderer.h b/libs/hwui/DisplayListCanvas.h index 44cf546..a9ac57d 100644 --- a/libs/hwui/DisplayListRenderer.h +++ b/libs/hwui/DisplayListCanvas.h @@ -52,9 +52,7 @@ namespace uirenderer { class DeferredDisplayList; class DeferredLayerUpdater; -class DisplayListRenderer; class DisplayListOp; -class DisplayListRenderer; class DrawOp; class RenderNode; class StateOp; @@ -62,10 +60,10 @@ class StateOp; /** * Records drawing commands in a display list for later playback into an OpenGLRenderer. */ -class ANDROID_API DisplayListRenderer: public Canvas, public CanvasStateClient { +class ANDROID_API DisplayListCanvas: public Canvas, public CanvasStateClient { public: - DisplayListRenderer(); - virtual ~DisplayListRenderer(); + DisplayListCanvas(); + virtual ~DisplayListCanvas(); void insertReorderBarrier(bool enableReorder); @@ -100,7 +98,7 @@ public: // Bitmap-based void drawBitmap(const SkBitmap* bitmap, const SkPaint* paint); // TODO: move drawPatch() to Canvas.h - void drawPatch(const SkBitmap& bitmap, const Res_png_9patch* patch, + void drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch, float left, float top, float right, float bottom, const SkPaint* paint); // Shapes @@ -138,8 +136,8 @@ public: // ---------------------------------------------------------------------------- virtual SkCanvas* asSkCanvas() override; - virtual void setBitmap(const SkBitmap& bitmap) override { - LOG_ALWAYS_FATAL("DisplayListRenderer is not backed by a bitmap."); + virtual void setBitmap(SkBitmap* bitmap, bool copyState) override { + LOG_ALWAYS_FATAL("DisplayListCanvas is not backed by a bitmap."); } virtual bool isOpaque() override { return false; } @@ -216,7 +214,7 @@ public: virtual void drawVertices(SkCanvas::VertexMode vertexMode, int vertexCount, const float* verts, const float* tex, const int* colors, const uint16_t* indices, int indexCount, const SkPaint& paint) override - { /* DisplayListRenderer does not support drawVertices(); ignore */ } + { /* DisplayListCanvas does not support drawVertices(); ignore */ } // Bitmap-based virtual void drawBitmap(const SkBitmap& bitmap, float left, float top, const SkPaint* paint) override; @@ -347,7 +345,7 @@ private: return cachedRegion; } - inline const SkBitmap* refBitmap(const SkBitmap& bitmap) { + inline const SkBitmap* refBitmap(const 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, @@ -382,7 +380,7 @@ private: friend class RenderNode; -}; // class DisplayListRenderer +}; // class DisplayListCanvas }; // namespace uirenderer }; // namespace android diff --git a/libs/hwui/DisplayListOp.h b/libs/hwui/DisplayListOp.h index 1963475..b5801fc 100644 --- a/libs/hwui/DisplayListOp.h +++ b/libs/hwui/DisplayListOp.h @@ -20,7 +20,7 @@ #include "OpenGLRenderer.h" #include "AssetAtlas.h" #include "DeferredDisplayList.h" -#include "DisplayListRenderer.h" +#include "DisplayListCanvas.h" #include "GammaFontRenderer.h" #include "Patch.h" #include "RenderNode.h" diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index aa722d0..30935d5 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -17,7 +17,6 @@ #include "OpenGLRenderer.h" #include "DeferredDisplayList.h" -#include "DisplayListRenderer.h" #include "GammaFontRenderer.h" #include "Glop.h" #include "GlopBuilder.h" @@ -1009,12 +1008,13 @@ void OpenGLRenderer::composeLayerRegion(Layer* layer, const Rect& rect) { TextureVertex::set(mesh++, r->left, r->bottom, u1, v2); TextureVertex::set(mesh++, r->right, r->bottom, u2, v2); } + Rect modelRect = Rect(rect.getWidth(), rect.getHeight()); Glop glop; GlopBuilder(mRenderState, mCaches, &glop) .setMeshTexturedIndexedQuads(&quadVertices[0], count * 6) .setFillLayer(layer->getTexture(), layer->getColorFilter(), getLayerAlpha(layer), layer->getMode(), Blend::ModeOrderSwap::NoSwap) .setTransform(currentSnapshot()->getOrthoMatrix(), *currentTransform(), false) - .setModelViewOffsetRectSnap(0, 0, rect) + .setModelViewOffsetRectSnap(rect.left, rect.top, modelRect) .setRoundRectClipState(currentSnapshot()->roundRectClipState) .build(); DRAW_DOUBLE_STENCIL_IF(!layer->hasDrawnSinceUpdate, renderGlop(glop)); diff --git a/libs/hwui/PathCache.cpp b/libs/hwui/PathCache.cpp index 2703072..bdb44a6 100644 --- a/libs/hwui/PathCache.cpp +++ b/libs/hwui/PathCache.cpp @@ -446,9 +446,7 @@ void PathCache::precache(const SkPath* path, const SkPaint* paint) { if (mProcessor == nullptr) { mProcessor = new PathProcessor(Caches::getInstance()); } - if (!mProcessor->add(task)) { - mProcessor->process(task); - } + mProcessor->add(task); } } diff --git a/libs/hwui/RenderNode.h b/libs/hwui/RenderNode.h index bbe53ff..d0d81d9 100644 --- a/libs/hwui/RenderNode.h +++ b/libs/hwui/RenderNode.h @@ -47,7 +47,7 @@ namespace android { namespace uirenderer { class DisplayListOp; -class DisplayListRenderer; +class DisplayListCanvas; class OpenGLRenderer; class Rect; class Layer; @@ -64,7 +64,7 @@ class TreeInfo; * Primary class for storing recorded canvas commands, as well as per-View/ViewGroup display properties. * * Recording of canvas commands is somewhat similar to SkPicture, except the canvas-recording - * functionality is split between DisplayListRenderer (which manages the recording), DisplayListData + * functionality is split between DisplayListCanvas (which manages the recording), DisplayListData * (which holds the actual data), and DisplayList (which holds properties and performs playback onto * a renderer). * diff --git a/libs/hwui/ResourceCache.cpp b/libs/hwui/ResourceCache.cpp index 454fedc..d3b8d70 100644 --- a/libs/hwui/ResourceCache.cpp +++ b/libs/hwui/ResourceCache.cpp @@ -59,13 +59,13 @@ void ResourceCache::unlock() { mLock.unlock(); } -const SkBitmap* ResourceCache::insert(const SkBitmap& bitmapResource) { +const SkBitmap* ResourceCache::insert(const SkBitmap* bitmapResource) { Mutex::Autolock _l(mLock); BitmapKey bitmapKey(bitmapResource); ssize_t index = mBitmapCache.indexOfKey(bitmapKey); if (index == NAME_NOT_FOUND) { - SkBitmap* cachedBitmap = new SkBitmap(bitmapResource); + SkBitmap* cachedBitmap = new SkBitmap(*bitmapResource); index = mBitmapCache.add(bitmapKey, cachedBitmap); return cachedBitmap; } @@ -121,7 +121,7 @@ void ResourceCache::decrementRefcountLocked(void* resource) { } void ResourceCache::decrementRefcountLocked(const SkBitmap* bitmapResource) { - BitmapKey bitmapKey(*bitmapResource); + BitmapKey bitmapKey(bitmapResource); ssize_t index = mBitmapCache.indexOfKey(bitmapKey); LOG_ALWAYS_FATAL_IF(index == NAME_NOT_FOUND, diff --git a/libs/hwui/ResourceCache.h b/libs/hwui/ResourceCache.h index 6c483fa..fae55d1 100644 --- a/libs/hwui/ResourceCache.h +++ b/libs/hwui/ResourceCache.h @@ -53,11 +53,11 @@ public: class BitmapKey { public: - BitmapKey(const SkBitmap& bitmap) + BitmapKey(const SkBitmap* bitmap) : mRefCount(1) - , mBitmapDimensions(bitmap.dimensions()) - , mPixelRefOrigin(bitmap.pixelRefOrigin()) - , mPixelRefStableID(bitmap.pixelRef()->getStableID()) { } + , mBitmapDimensions(bitmap->dimensions()) + , mPixelRefOrigin(bitmap->pixelRefOrigin()) + , mPixelRefStableID(bitmap->pixelRef()->getStableID()) { } void operator=(const BitmapKey& other); bool operator==(const BitmapKey& other) const; @@ -101,7 +101,7 @@ public: * The cache stores a copy of the provided resource or refs an existing resource * if the bitmap has previously been inserted and returns the cached copy. */ - const SkBitmap* insert(const SkBitmap& resource); + const SkBitmap* insert(const SkBitmap* resource); void incrementRefcount(const Res_png_9patch* resource); diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp index a323065..8b11757 100644 --- a/libs/hwui/SkiaCanvas.cpp +++ b/libs/hwui/SkiaCanvas.cpp @@ -31,7 +31,7 @@ namespace android { // Holds an SkCanvas reference plus additional native data. class SkiaCanvas : public Canvas { public: - explicit SkiaCanvas(const SkBitmap& bitmap); + explicit SkiaCanvas(SkBitmap* bitmap); /** * Create a new SkiaCanvas. @@ -49,7 +49,7 @@ public: return mCanvas.get(); } - virtual void setBitmap(const SkBitmap& bitmap) override; + virtual void setBitmap(SkBitmap* bitmap, bool copyState) override; virtual bool isOpaque() override; virtual int width() override; @@ -145,7 +145,19 @@ private: SkAutoTDelete<SkDeque> mSaveStack; // lazily allocated, tracks partial saves. }; -Canvas* Canvas::create_canvas(const SkBitmap& bitmap) { +// Construct an SkCanvas from the bitmap. +static SkCanvas* createCanvas(SkBitmap* bitmap) { + if (bitmap) { + return SkNEW_ARGS(SkCanvas, (*bitmap)); + } + + // Create an empty bitmap device to prevent callers from crashing + // if they attempt to draw into this canvas. + SkBitmap emptyBitmap; + return new SkCanvas(emptyBitmap); +} + +Canvas* Canvas::create_canvas(SkBitmap* bitmap) { return new SkiaCanvas(bitmap); } @@ -153,8 +165,8 @@ Canvas* Canvas::create_canvas(SkCanvas* skiaCanvas) { return new SkiaCanvas(skiaCanvas); } -SkiaCanvas::SkiaCanvas(const SkBitmap& bitmap) { - mCanvas.reset(new SkCanvas(bitmap)); +SkiaCanvas::SkiaCanvas(SkBitmap* bitmap) { + mCanvas.reset(createCanvas(bitmap)); } // ---------------------------------------------------------------------------- @@ -179,11 +191,11 @@ private: SkCanvas* m_dstCanvas; }; -void SkiaCanvas::setBitmap(const SkBitmap& bitmap) { - SkCanvas* newCanvas = new SkCanvas(bitmap); +void SkiaCanvas::setBitmap(SkBitmap* bitmap, bool copyState) { + SkCanvas* newCanvas = createCanvas(bitmap); SkASSERT(newCanvas); - if (!bitmap.isNull()) { + if (copyState) { // Copy the canvas matrix & clip state. newCanvas->setMatrix(mCanvas->getTotalMatrix()); if (NULL != mCanvas->getDevice() && NULL != newCanvas->getDevice()) { diff --git a/libs/hwui/TessellationCache.cpp b/libs/hwui/TessellationCache.cpp index d9d06bf..7edb9fb 100644 --- a/libs/hwui/TessellationCache.cpp +++ b/libs/hwui/TessellationCache.cpp @@ -386,10 +386,7 @@ void TessellationCache::precacheShadows(const Matrix4* drawTransform, const Rect if (mShadowProcessor == nullptr) { mShadowProcessor = new ShadowProcessor(Caches::getInstance()); } - if (!mShadowProcessor->add(task)) { - mShadowProcessor->process(task); - } - + mShadowProcessor->add(task); task->incStrong(nullptr); // not using sp<>s, so manually ref while in the cache mShadowCache.put(key, task.get()); } @@ -424,9 +421,7 @@ TessellationCache::Buffer* TessellationCache::getOrCreateBuffer( if (mProcessor == nullptr) { mProcessor = new TessellationProcessor(Caches::getInstance()); } - if (!mProcessor->add(task)) { - mProcessor->process(task); - } + mProcessor->add(task); mCache.put(entry, buffer); } return buffer; diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp index d15fa39..cc87241 100644 --- a/libs/hwui/renderthread/RenderProxy.cpp +++ b/libs/hwui/renderthread/RenderProxy.cpp @@ -293,11 +293,11 @@ CREATE_BRIDGE3(copyLayerInto, CanvasContext* context, DeferredLayerUpdater* laye return (void*) success; } -bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap) { +bool RenderProxy::copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap) { SETUP_TASK(copyLayerInto); args->context = mContext; args->layer = layer; - args->bitmap = &bitmap; + args->bitmap = bitmap; return (bool) postAndWait(task); } diff --git a/libs/hwui/renderthread/RenderProxy.h b/libs/hwui/renderthread/RenderProxy.h index cc475fa..29c6f08 100644 --- a/libs/hwui/renderthread/RenderProxy.h +++ b/libs/hwui/renderthread/RenderProxy.h @@ -83,7 +83,7 @@ public: ANDROID_API DeferredLayerUpdater* createTextureLayer(); ANDROID_API void buildLayer(RenderNode* node); - ANDROID_API bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap); + ANDROID_API bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap); ANDROID_API void pushLayerUpdate(DeferredLayerUpdater* layer); ANDROID_API void cancelLayerUpdate(DeferredLayerUpdater* layer); ANDROID_API void detachSurfaceTexture(DeferredLayerUpdater* layer); diff --git a/libs/hwui/tests/main.cpp b/libs/hwui/tests/main.cpp index 805989b..61ad082 100644 --- a/libs/hwui/tests/main.cpp +++ b/libs/hwui/tests/main.cpp @@ -21,7 +21,7 @@ #include <ui/PixelFormat.h> #include <AnimationContext.h> -#include <DisplayListRenderer.h> +#include <DisplayListCanvas.h> #include <RenderNode.h> #include <renderthread/RenderProxy.h> #include <renderthread/RenderTask.h> @@ -40,15 +40,15 @@ public: } }; -static DisplayListRenderer* startRecording(RenderNode* node) { - DisplayListRenderer* renderer = new DisplayListRenderer(); +static DisplayListCanvas* startRecording(RenderNode* node) { + DisplayListCanvas* renderer = new DisplayListCanvas(); renderer->setViewport(node->stagingProperties().getWidth(), node->stagingProperties().getHeight()); renderer->prepare(); return renderer; } -static void endRecording(DisplayListRenderer* renderer, RenderNode* node) { +static void endRecording(DisplayListCanvas* renderer, RenderNode* node) { renderer->finish(); node->setStagingDisplayList(renderer->finishRecording()); delete renderer; @@ -58,7 +58,7 @@ class TreeContentAnimation { public: virtual ~TreeContentAnimation() {} virtual int getFrameCount() { return 150; } - virtual void createContent(int width, int height, DisplayListRenderer* renderer) = 0; + virtual void createContent(int width, int height, DisplayListCanvas* renderer) = 0; virtual void doFrame(int frameNr) = 0; template <class T> @@ -89,7 +89,7 @@ public: android::uirenderer::Rect DUMMY; - DisplayListRenderer* renderer = startRecording(rootNode); + DisplayListCanvas* renderer = startRecording(rootNode); animation.createContent(width, height, renderer); endRecording(renderer, rootNode); @@ -110,7 +110,7 @@ public: class ShadowGridAnimation : public TreeContentAnimation { public: std::vector< sp<RenderNode> > cards; - void createContent(int width, int height, DisplayListRenderer* renderer) override { + void createContent(int width, int height, DisplayListCanvas* renderer) override { android::uirenderer::Rect DUMMY; renderer->drawColor(0xFFFFFFFF, SkXfermode::kSrcOver_Mode); @@ -142,7 +142,7 @@ private: node->mutateStagingProperties().mutableOutline().setShouldClip(true); node->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y | RenderNode::Z); - DisplayListRenderer* renderer = startRecording(node.get()); + DisplayListCanvas* renderer = startRecording(node.get()); renderer->drawColor(0xFFEEEEEE, SkXfermode::kSrcOver_Mode); endRecording(renderer, node.get()); return node; @@ -152,7 +152,7 @@ private: class RectGridAnimation : public TreeContentAnimation { public: sp<RenderNode> card; - void createContent(int width, int height, DisplayListRenderer* renderer) override { + void createContent(int width, int height, DisplayListCanvas* renderer) override { android::uirenderer::Rect DUMMY; renderer->drawColor(0xFFFFFFFF, SkXfermode::kSrcOver_Mode); @@ -174,7 +174,7 @@ private: node->mutateStagingProperties().setLeftTopRightBottom(x, y, x + width, y + height); node->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y); - DisplayListRenderer* renderer = startRecording(node.get()); + DisplayListCanvas* renderer = startRecording(node.get()); renderer->drawColor(0xFFFF00FF, SkXfermode::kSrcOver_Mode); float rects[width * height]; @@ -201,7 +201,7 @@ private: class OvalAnimation : public TreeContentAnimation { public: sp<RenderNode> card; - void createContent(int width, int height, DisplayListRenderer* renderer) override { + void createContent(int width, int height, DisplayListCanvas* renderer) override { android::uirenderer::Rect DUMMY; renderer->drawColor(0xFFFFFFFF, SkXfermode::kSrcOver_Mode); @@ -224,7 +224,7 @@ private: node->mutateStagingProperties().setLeftTopRightBottom(x, y, x + width, y + height); node->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y); - DisplayListRenderer* renderer = startRecording(node.get()); + DisplayListCanvas* renderer = startRecording(node.get()); SkPaint paint; paint.setAntiAlias(true); diff --git a/libs/hwui/thread/TaskProcessor.h b/libs/hwui/thread/TaskProcessor.h index ec6519c..82538e9 100644 --- a/libs/hwui/thread/TaskProcessor.h +++ b/libs/hwui/thread/TaskProcessor.h @@ -39,7 +39,17 @@ public: TaskProcessor(TaskManager* manager): mManager(manager) { } virtual ~TaskProcessor() { } - bool add(const sp<Task<T> >& task); + void add(const sp<Task<T> >& task) { + if (!addImpl(task)) { + // fall back to immediate execution + process(task); + } + } + + virtual void onProcess(const sp<Task<T> >& task) = 0; + +private: + bool addImpl(const sp<Task<T> >& task); virtual void process(const sp<TaskBase>& task) override { sp<Task<T> > realTask = static_cast<Task<T>* >(task.get()); @@ -48,13 +58,11 @@ public: onProcess(realTask); } - virtual void onProcess(const sp<Task<T> >& task) = 0; - TaskManager* mManager; }; template<typename T> -bool TaskProcessor<T>::add(const sp<Task<T> >& task) { +bool TaskProcessor<T>::addImpl(const sp<Task<T> >& task) { if (mManager) { sp<TaskProcessor<T> > self(this); return mManager->addTask(task, self); |