Loading core/java/android/view/ThreadedRenderer.java +0 −28 Original line number Original line Diff line number Diff line Loading @@ -460,8 +460,6 @@ public class ThreadedRenderer extends HardwareRenderer { if (buffer != null) { if (buffer != null) { long[] map = atlas.getMap(); long[] map = atlas.getMap(); if (map != null) { if (map != null) { // TODO Remove after fixing b/15425820 validateMap(context, map); nSetAtlas(renderProxy, buffer, map); nSetAtlas(renderProxy, buffer, map); } } // If IAssetAtlas is not the same class as the IBinder // If IAssetAtlas is not the same class as the IBinder Loading @@ -476,32 +474,6 @@ public class ThreadedRenderer extends HardwareRenderer { Log.w(LOG_TAG, "Could not acquire atlas", e); Log.w(LOG_TAG, "Could not acquire atlas", e); } } } } private static void validateMap(Context context, long[] map) { Log.d("Atlas", "Validating map..."); HashSet<Long> preloadedPointers = new HashSet<Long>(); // We only care about drawables that hold bitmaps final Resources resources = context.getResources(); final LongSparseArray<Drawable.ConstantState> drawables = resources.getPreloadedDrawables(); final int count = drawables.size(); ArrayList<Bitmap> tmpList = new ArrayList<Bitmap>(); for (int i = 0; i < count; i++) { drawables.valueAt(i).addAtlasableBitmaps(tmpList); for (int j = 0; j < tmpList.size(); j++) { preloadedPointers.add(tmpList.get(j).getSkBitmap()); } tmpList.clear(); } for (int i = 0; i < map.length; i += 4) { if (!preloadedPointers.contains(map[i])) { Log.w("Atlas", String.format("Pointer 0x%X, not in getPreloadedDrawables?", map[i])); map[i] = 0; } } } } } static native void setupShadersDiskCache(String cacheFile); static native void setupShadersDiskCache(String cacheFile); Loading core/jni/android/graphics/Bitmap.cpp +8 −0 Original line number Original line Diff line number Diff line Loading @@ -857,6 +857,13 @@ static void Bitmap_prepareToDraw(JNIEnv* env, jobject, jlong bitmapHandle) { bitmap->unlockPixels(); bitmap->unlockPixels(); } } static jlong Bitmap_refPixelRef(JNIEnv* env, jobject, jlong bitmapHandle) { SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); SkPixelRef* pixelRef = bitmap ? bitmap->pixelRef() : nullptr; SkSafeRef(pixelRef); return reinterpret_cast<jlong>(pixelRef); } /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// static JNINativeMethod gBitmapMethods[] = { static JNINativeMethod gBitmapMethods[] = { Loading Loading @@ -896,6 +903,7 @@ static JNINativeMethod gBitmapMethods[] = { (void*)Bitmap_copyPixelsFromBuffer }, (void*)Bitmap_copyPixelsFromBuffer }, { "nativeSameAs", "(JJ)Z", (void*)Bitmap_sameAs }, { "nativeSameAs", "(JJ)Z", (void*)Bitmap_sameAs }, { "nativePrepareToDraw", "(J)V", (void*)Bitmap_prepareToDraw }, { "nativePrepareToDraw", "(J)V", (void*)Bitmap_prepareToDraw }, { "nativeRefPixelRef", "(J)J", (void*)Bitmap_refPixelRef }, }; }; int register_android_graphics_Bitmap(JNIEnv* env) int register_android_graphics_Bitmap(JNIEnv* env) Loading graphics/java/android/graphics/Bitmap.java +10 −0 Original line number Original line Diff line number Diff line Loading @@ -1573,6 +1573,15 @@ public final class Bitmap implements Parcelable { return mSkBitmapPtr; return mSkBitmapPtr; } } /** * Refs the underlying SkPixelRef and returns a pointer to it. * * @hide * */ public final long refSkPixelRef() { return nativeRefPixelRef(mSkBitmapPtr); } private static class BitmapFinalizer { private static class BitmapFinalizer { private long mNativeBitmap; private long mNativeBitmap; Loading Loading @@ -1661,4 +1670,5 @@ public final class Bitmap implements Parcelable { private static native boolean nativeHasMipMap(long nativeBitmap); private static native boolean nativeHasMipMap(long nativeBitmap); private static native void nativeSetHasMipMap(long nativeBitmap, boolean hasMipMap); private static native void nativeSetHasMipMap(long nativeBitmap, boolean hasMipMap); private static native boolean nativeSameAs(long nativeBitmap0, long nativeBitmap1); private static native boolean nativeSameAs(long nativeBitmap0, long nativeBitmap1); private static native long nativeRefPixelRef(long nativeBitmap); } } libs/hwui/AssetAtlas.cpp +11 −11 Original line number Original line Diff line number Diff line Loading @@ -82,12 +82,12 @@ void AssetAtlas::updateTextureId() { /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// AssetAtlas::Entry* AssetAtlas::getEntry(const SkBitmap* bitmap) const { 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; return index >= 0 ? mEntries.valueAt(index) : nullptr; } } Texture* AssetAtlas::getEntryTexture(const SkBitmap* bitmap) const { 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; return index >= 0 ? mEntries.valueAt(index)->texture : nullptr; } } Loading Loading @@ -120,7 +120,7 @@ void AssetAtlas::createEntries(Caches& caches, int64_t* map, int count) { const float height = float(mTexture->height); const float height = float(mTexture->height); for (int i = 0; i < count; ) { 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 // NOTE: We're converting from 64 bit signed values to 32 bit // signed values. This is guaranteed to be safe because the "x" // signed values. This is guaranteed to be safe because the "x" // and "y" coordinate values are guaranteed to be representable // and "y" coordinate values are guaranteed to be representable Loading @@ -131,21 +131,21 @@ void AssetAtlas::createEntries(Caches& caches, int64_t* map, int count) { bool rotated = map[i++] > 0; bool rotated = map[i++] > 0; // Bitmaps should never be null, we're just extra paranoid // Bitmaps should never be null, we're just extra paranoid if (!bitmap) continue; if (!pixelRef) continue; const UvMapper mapper( const UvMapper mapper( x / width, (x + bitmap->width()) / width, x / width, (x + pixelRef->info().width()) / width, y / height, (y + bitmap->height()) / height); y / height, (y + pixelRef->info().height()) / height); Texture* texture = new DelegateTexture(caches, mTexture); Texture* texture = new DelegateTexture(caches, mTexture); texture->blend = !bitmap->isOpaque(); texture->blend = !SkAlphaTypeIsOpaque(pixelRef->info().alphaType()); texture->width = bitmap->width(); texture->width = pixelRef->info().width(); texture->height = bitmap->height(); 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; texture->uvMapper = &entry->uvMapper; mEntries.add(entry->bitmap, entry); mEntries.add(entry->pixelRef, entry); } } } } Loading libs/hwui/AssetAtlas.h +34 −28 Original line number Original line Diff line number Diff line Loading @@ -48,24 +48,8 @@ public: * Entry representing the position and rotation of a * Entry representing the position and rotation of a * bitmap inside the atlas. * bitmap inside the atlas. */ */ struct Entry { class Entry { /** public: * 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 * A "virtual texture" object that represents the texture * this entry belongs to. This texture should never be * this entry belongs to. This texture should never be Loading @@ -79,11 +63,6 @@ public: */ */ const UvMapper uvMapper; const UvMapper uvMapper; /** * Atlas this entry belongs to. */ const AssetAtlas& atlas; /** /** * Unique identifier used to merge bitmaps and 9-patches stored * Unique identifier used to merge bitmaps and 9-patches stored * in the atlas. * in the atlas. Loading @@ -93,10 +72,37 @@ public: } } private: private: Entry(SkBitmap* bitmap, int x, int y, bool rotated, /** Texture* texture, const UvMapper& mapper, const AssetAtlas& atlas): * The pixel ref that generated this atlas entry. bitmap(bitmap), x(x), y(y), rotated(rotated), */ texture(texture), uvMapper(mapper), atlas(atlas) { 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() { ~Entry() { Loading Loading @@ -178,7 +184,7 @@ private: const bool mBlendKey; const bool mBlendKey; const bool mOpaqueKey; const bool mOpaqueKey; KeyedVector<const SkBitmap*, Entry*> mEntries; KeyedVector<const SkPixelRef*, Entry*> mEntries; }; // class AssetAtlas }; // class AssetAtlas }; // namespace uirenderer }; // namespace uirenderer Loading Loading
core/java/android/view/ThreadedRenderer.java +0 −28 Original line number Original line Diff line number Diff line Loading @@ -460,8 +460,6 @@ public class ThreadedRenderer extends HardwareRenderer { if (buffer != null) { if (buffer != null) { long[] map = atlas.getMap(); long[] map = atlas.getMap(); if (map != null) { if (map != null) { // TODO Remove after fixing b/15425820 validateMap(context, map); nSetAtlas(renderProxy, buffer, map); nSetAtlas(renderProxy, buffer, map); } } // If IAssetAtlas is not the same class as the IBinder // If IAssetAtlas is not the same class as the IBinder Loading @@ -476,32 +474,6 @@ public class ThreadedRenderer extends HardwareRenderer { Log.w(LOG_TAG, "Could not acquire atlas", e); Log.w(LOG_TAG, "Could not acquire atlas", e); } } } } private static void validateMap(Context context, long[] map) { Log.d("Atlas", "Validating map..."); HashSet<Long> preloadedPointers = new HashSet<Long>(); // We only care about drawables that hold bitmaps final Resources resources = context.getResources(); final LongSparseArray<Drawable.ConstantState> drawables = resources.getPreloadedDrawables(); final int count = drawables.size(); ArrayList<Bitmap> tmpList = new ArrayList<Bitmap>(); for (int i = 0; i < count; i++) { drawables.valueAt(i).addAtlasableBitmaps(tmpList); for (int j = 0; j < tmpList.size(); j++) { preloadedPointers.add(tmpList.get(j).getSkBitmap()); } tmpList.clear(); } for (int i = 0; i < map.length; i += 4) { if (!preloadedPointers.contains(map[i])) { Log.w("Atlas", String.format("Pointer 0x%X, not in getPreloadedDrawables?", map[i])); map[i] = 0; } } } } } static native void setupShadersDiskCache(String cacheFile); static native void setupShadersDiskCache(String cacheFile); Loading
core/jni/android/graphics/Bitmap.cpp +8 −0 Original line number Original line Diff line number Diff line Loading @@ -857,6 +857,13 @@ static void Bitmap_prepareToDraw(JNIEnv* env, jobject, jlong bitmapHandle) { bitmap->unlockPixels(); bitmap->unlockPixels(); } } static jlong Bitmap_refPixelRef(JNIEnv* env, jobject, jlong bitmapHandle) { SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); SkPixelRef* pixelRef = bitmap ? bitmap->pixelRef() : nullptr; SkSafeRef(pixelRef); return reinterpret_cast<jlong>(pixelRef); } /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// static JNINativeMethod gBitmapMethods[] = { static JNINativeMethod gBitmapMethods[] = { Loading Loading @@ -896,6 +903,7 @@ static JNINativeMethod gBitmapMethods[] = { (void*)Bitmap_copyPixelsFromBuffer }, (void*)Bitmap_copyPixelsFromBuffer }, { "nativeSameAs", "(JJ)Z", (void*)Bitmap_sameAs }, { "nativeSameAs", "(JJ)Z", (void*)Bitmap_sameAs }, { "nativePrepareToDraw", "(J)V", (void*)Bitmap_prepareToDraw }, { "nativePrepareToDraw", "(J)V", (void*)Bitmap_prepareToDraw }, { "nativeRefPixelRef", "(J)J", (void*)Bitmap_refPixelRef }, }; }; int register_android_graphics_Bitmap(JNIEnv* env) int register_android_graphics_Bitmap(JNIEnv* env) Loading
graphics/java/android/graphics/Bitmap.java +10 −0 Original line number Original line Diff line number Diff line Loading @@ -1573,6 +1573,15 @@ public final class Bitmap implements Parcelable { return mSkBitmapPtr; return mSkBitmapPtr; } } /** * Refs the underlying SkPixelRef and returns a pointer to it. * * @hide * */ public final long refSkPixelRef() { return nativeRefPixelRef(mSkBitmapPtr); } private static class BitmapFinalizer { private static class BitmapFinalizer { private long mNativeBitmap; private long mNativeBitmap; Loading Loading @@ -1661,4 +1670,5 @@ public final class Bitmap implements Parcelable { private static native boolean nativeHasMipMap(long nativeBitmap); private static native boolean nativeHasMipMap(long nativeBitmap); private static native void nativeSetHasMipMap(long nativeBitmap, boolean hasMipMap); private static native void nativeSetHasMipMap(long nativeBitmap, boolean hasMipMap); private static native boolean nativeSameAs(long nativeBitmap0, long nativeBitmap1); private static native boolean nativeSameAs(long nativeBitmap0, long nativeBitmap1); private static native long nativeRefPixelRef(long nativeBitmap); } }
libs/hwui/AssetAtlas.cpp +11 −11 Original line number Original line Diff line number Diff line Loading @@ -82,12 +82,12 @@ void AssetAtlas::updateTextureId() { /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// AssetAtlas::Entry* AssetAtlas::getEntry(const SkBitmap* bitmap) const { 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; return index >= 0 ? mEntries.valueAt(index) : nullptr; } } Texture* AssetAtlas::getEntryTexture(const SkBitmap* bitmap) const { 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; return index >= 0 ? mEntries.valueAt(index)->texture : nullptr; } } Loading Loading @@ -120,7 +120,7 @@ void AssetAtlas::createEntries(Caches& caches, int64_t* map, int count) { const float height = float(mTexture->height); const float height = float(mTexture->height); for (int i = 0; i < count; ) { 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 // NOTE: We're converting from 64 bit signed values to 32 bit // signed values. This is guaranteed to be safe because the "x" // signed values. This is guaranteed to be safe because the "x" // and "y" coordinate values are guaranteed to be representable // and "y" coordinate values are guaranteed to be representable Loading @@ -131,21 +131,21 @@ void AssetAtlas::createEntries(Caches& caches, int64_t* map, int count) { bool rotated = map[i++] > 0; bool rotated = map[i++] > 0; // Bitmaps should never be null, we're just extra paranoid // Bitmaps should never be null, we're just extra paranoid if (!bitmap) continue; if (!pixelRef) continue; const UvMapper mapper( const UvMapper mapper( x / width, (x + bitmap->width()) / width, x / width, (x + pixelRef->info().width()) / width, y / height, (y + bitmap->height()) / height); y / height, (y + pixelRef->info().height()) / height); Texture* texture = new DelegateTexture(caches, mTexture); Texture* texture = new DelegateTexture(caches, mTexture); texture->blend = !bitmap->isOpaque(); texture->blend = !SkAlphaTypeIsOpaque(pixelRef->info().alphaType()); texture->width = bitmap->width(); texture->width = pixelRef->info().width(); texture->height = bitmap->height(); 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; texture->uvMapper = &entry->uvMapper; mEntries.add(entry->bitmap, entry); mEntries.add(entry->pixelRef, entry); } } } } Loading
libs/hwui/AssetAtlas.h +34 −28 Original line number Original line Diff line number Diff line Loading @@ -48,24 +48,8 @@ public: * Entry representing the position and rotation of a * Entry representing the position and rotation of a * bitmap inside the atlas. * bitmap inside the atlas. */ */ struct Entry { class Entry { /** public: * 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 * A "virtual texture" object that represents the texture * this entry belongs to. This texture should never be * this entry belongs to. This texture should never be Loading @@ -79,11 +63,6 @@ public: */ */ const UvMapper uvMapper; const UvMapper uvMapper; /** * Atlas this entry belongs to. */ const AssetAtlas& atlas; /** /** * Unique identifier used to merge bitmaps and 9-patches stored * Unique identifier used to merge bitmaps and 9-patches stored * in the atlas. * in the atlas. Loading @@ -93,10 +72,37 @@ public: } } private: private: Entry(SkBitmap* bitmap, int x, int y, bool rotated, /** Texture* texture, const UvMapper& mapper, const AssetAtlas& atlas): * The pixel ref that generated this atlas entry. bitmap(bitmap), x(x), y(y), rotated(rotated), */ texture(texture), uvMapper(mapper), atlas(atlas) { 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() { ~Entry() { Loading Loading @@ -178,7 +184,7 @@ private: const bool mBlendKey; const bool mBlendKey; const bool mOpaqueKey; const bool mOpaqueKey; KeyedVector<const SkBitmap*, Entry*> mEntries; KeyedVector<const SkPixelRef*, Entry*> mEntries; }; // class AssetAtlas }; // class AssetAtlas }; // namespace uirenderer }; // namespace uirenderer Loading