diff options
Diffstat (limited to 'libs/hwui')
-rw-r--r-- | libs/hwui/AssetAtlas.cpp | 22 | ||||
-rw-r--r-- | libs/hwui/AssetAtlas.h | 62 | ||||
-rw-r--r-- | libs/hwui/DisplayListCanvas.cpp | 14 | ||||
-rw-r--r-- | libs/hwui/DisplayListCanvas.h | 4 | ||||
-rw-r--r-- | libs/hwui/ResourceCache.cpp | 6 | ||||
-rw-r--r-- | libs/hwui/ResourceCache.h | 10 | ||||
-rw-r--r-- | libs/hwui/renderthread/RenderProxy.cpp | 2 |
7 files changed, 63 insertions, 57 deletions
diff --git a/libs/hwui/AssetAtlas.cpp b/libs/hwui/AssetAtlas.cpp index 4d2e3a0..882826e 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); + ssize_t index = mEntries.indexOfKey(bitmap->pixelRef()); return index >= 0 ? mEntries.valueAt(index) : nullptr; } Texture* AssetAtlas::getEntryTexture(const SkBitmap* bitmap) const { - ssize_t index = mEntries.indexOfKey(bitmap); + ssize_t index = mEntries.indexOfKey(bitmap->pixelRef()); 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; ) { - SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(map[i++]); + SkPixelRef* pixelRef = reinterpret_cast<SkPixelRef*>(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 (!bitmap) continue; + if (!pixelRef) continue; const UvMapper mapper( - x / width, (x + bitmap->width()) / width, - y / height, (y + bitmap->height()) / height); + x / width, (x + pixelRef->info().width()) / width, + y / height, (y + pixelRef->info().height()) / height); Texture* texture = new DelegateTexture(caches, mTexture); - texture->blend = !bitmap->isOpaque(); - texture->width = bitmap->width(); - texture->height = bitmap->height(); + texture->blend = !SkAlphaTypeIsOpaque(pixelRef->info().alphaType()); + texture->width = pixelRef->info().width(); + texture->height = pixelRef->info().height(); - Entry* entry = new Entry(bitmap, x, y, rotated, texture, mapper, *this); + Entry* entry = new Entry(pixelRef, x, y, rotated, texture, mapper, *this); texture->uvMapper = &entry->uvMapper; - mEntries.add(entry->bitmap, entry); + mEntries.add(entry->pixelRef, entry); } } diff --git a/libs/hwui/AssetAtlas.h b/libs/hwui/AssetAtlas.h index 1772eff..17c5281 100644 --- a/libs/hwui/AssetAtlas.h +++ b/libs/hwui/AssetAtlas.h @@ -48,24 +48,8 @@ public: * Entry representing the position and rotation of a * bitmap inside the atlas. */ - 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; - + class Entry { + public: /* * A "virtual texture" object that represents the texture * this entry belongs to. This texture should never be @@ -80,11 +64,6 @@ 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. */ @@ -93,10 +72,37 @@ public: } private: - 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) { + /** + * 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() { @@ -178,7 +184,7 @@ private: const bool mBlendKey; const bool mOpaqueKey; - KeyedVector<const SkBitmap*, Entry*> mEntries; + KeyedVector<const SkPixelRef*, Entry*> mEntries; }; // class AssetAtlas }; // namespace uirenderer diff --git a/libs/hwui/DisplayListCanvas.cpp b/libs/hwui/DisplayListCanvas.cpp index a7784b6..cbb6fd5 100644 --- a/libs/hwui/DisplayListCanvas.cpp +++ b/libs/hwui/DisplayListCanvas.cpp @@ -218,7 +218,7 @@ void DisplayListCanvas::drawLayer(DeferredLayerUpdater* layerHandle, float x, fl } void DisplayListCanvas::drawBitmap(const SkBitmap* bitmap, const SkPaint* paint) { - bitmap = refBitmap(bitmap); + bitmap = refBitmap(*bitmap); paint = refPaint(paint); addDrawOp(new (alloc()) DrawBitmapOp(bitmap, paint)); @@ -284,7 +284,7 @@ void DisplayListCanvas::drawBitmap(const SkBitmap& bitmap, float srcLeft, float 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(); @@ -292,7 +292,7 @@ void DisplayListCanvas::drawBitmap(const SkBitmap& bitmap, float srcLeft, float } } - addDrawOp(new (alloc()) DrawBitmapRectOp(refBitmap(&bitmap), + addDrawOp(new (alloc()) DrawBitmapRectOp(refBitmap(bitmap), srcLeft, srcTop, srcRight, srcBottom, dstLeft, dstTop, dstRight, dstBottom, paint)); } @@ -305,17 +305,17 @@ void DisplayListCanvas::drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, in 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 DisplayListCanvas::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) { - bitmap = refBitmap(bitmap); + const SkBitmap* bitmapPtr = refBitmap(bitmap); patch = refPatch(patch); paint = refPaint(paint); - addDrawOp(new (alloc()) DrawPatchOp(bitmap, patch, left, top, right, bottom, paint)); + addDrawOp(new (alloc()) DrawPatchOp(bitmapPtr, patch, left, top, right, bottom, paint)); } void DisplayListCanvas::drawColor(int color, SkXfermode::Mode mode) { diff --git a/libs/hwui/DisplayListCanvas.h b/libs/hwui/DisplayListCanvas.h index fa4b2b4..0064236 100644 --- a/libs/hwui/DisplayListCanvas.h +++ b/libs/hwui/DisplayListCanvas.h @@ -98,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 @@ -345,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, diff --git a/libs/hwui/ResourceCache.cpp b/libs/hwui/ResourceCache.cpp index d3b8d70..454fedc 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 fae55d1..6c483fa 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/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp index d15fa39..7c04f40 100644 --- a/libs/hwui/renderthread/RenderProxy.cpp +++ b/libs/hwui/renderthread/RenderProxy.cpp @@ -135,7 +135,7 @@ void RenderProxy::setName(const char* name) { SETUP_TASK(setName); args->context = mContext; args->name = name; - post(task); + postAndWait(task); } CREATE_BRIDGE2(initialize, CanvasContext* context, ANativeWindow* window) { |