diff --git a/core/jni/android/graphics/Bitmap.cpp b/core/jni/android/graphics/Bitmap.cpp index 6e3fbf7ccbbef..4a2f287831538 100755 --- a/core/jni/android/graphics/Bitmap.cpp +++ b/core/jni/android/graphics/Bitmap.cpp @@ -17,7 +17,7 @@ #include "android_nio_utils.h" #include "CreateJavaOutputStreamAdaptor.h" #include -#include +#include #include #include "core_jni_helpers.h" @@ -37,25 +37,25 @@ static jmethodID gBitmap_getAllocationByteCountMethodID; namespace android { -class Bitmap { +class BitmapWrapper { public: - Bitmap(PixelRef* pixelRef) - : mPixelRef(pixelRef) { } + BitmapWrapper(Bitmap* bitmap) + : mBitmap(bitmap) { } void freePixels() { - mInfo = mPixelRef->info(); - mHasHardwareMipMap = mPixelRef->hasHardwareMipMap(); - mAllocationSize = mPixelRef->getAllocationByteCount(); - mRowBytes = mPixelRef->rowBytes(); - mGenerationId = mPixelRef->getGenerationID(); - mPixelRef.reset(); + mInfo = mBitmap->info(); + mHasHardwareMipMap = mBitmap->hasHardwareMipMap(); + mAllocationSize = mBitmap->getAllocationByteCount(); + mRowBytes = mBitmap->rowBytes(); + mGenerationId = mBitmap->getGenerationID(); + mBitmap.reset(); } bool valid() { - return !!mPixelRef; + return !!mBitmap; } - PixelRef* pixelRef() { return mPixelRef.get(); } + Bitmap* bitmap() { return mBitmap.get(); } void assertValid() { LOG_ALWAYS_FATAL_IF(!valid(), "Error, cannot access an invalid/free'd bitmap here!"); @@ -63,58 +63,58 @@ public: void getSkBitmap(SkBitmap* outBitmap) { assertValid(); - mPixelRef->getSkBitmap(outBitmap); + mBitmap->getSkBitmap(outBitmap); } bool hasHardwareMipMap() { - if (mPixelRef) { - return mPixelRef->hasHardwareMipMap(); + if (mBitmap) { + return mBitmap->hasHardwareMipMap(); } return mHasHardwareMipMap; } void setHasHardwareMipMap(bool hasMipMap) { assertValid(); - mPixelRef->setHasHardwareMipMap(hasMipMap); + mBitmap->setHasHardwareMipMap(hasMipMap); } void setAlphaType(SkAlphaType alphaType) { assertValid(); - mPixelRef->setAlphaType(alphaType); + mBitmap->setAlphaType(alphaType); } const SkImageInfo& info() { - if (mPixelRef) { - return mPixelRef->info(); + if (mBitmap) { + return mBitmap->info(); } return mInfo; } size_t getAllocationByteCount() const { - if (mPixelRef) { - return mPixelRef->getAllocationByteCount(); + if (mBitmap) { + return mBitmap->getAllocationByteCount(); } return mAllocationSize; } size_t rowBytes() const { - if (mPixelRef) { - return mPixelRef->rowBytes(); + if (mBitmap) { + return mBitmap->rowBytes(); } return mRowBytes; } uint32_t getGenerationID() const { - if (mPixelRef) { - return mPixelRef->getGenerationID(); + if (mBitmap) { + return mBitmap->getGenerationID(); } return mGenerationId; } - ~Bitmap() { } + ~BitmapWrapper() { } private: - sk_sp mPixelRef; + sk_sp mBitmap; SkImageInfo mInfo; bool mHasHardwareMipMap; size_t mAllocationSize; @@ -127,22 +127,22 @@ private: class LocalScopedBitmap { public: explicit LocalScopedBitmap(jlong bitmapHandle) - : mBitmap(reinterpret_cast(bitmapHandle)) {} + : mBitmapWrapper(reinterpret_cast(bitmapHandle)) {} - Bitmap* operator->() { - return mBitmap; + BitmapWrapper* operator->() { + return mBitmapWrapper; } void* pixels() { - return mBitmap->pixelRef()->pixels(); + return mBitmapWrapper->bitmap()->pixels(); } bool valid() { - return mBitmap && mBitmap->valid(); + return mBitmapWrapper && mBitmapWrapper->valid(); } private: - Bitmap* mBitmap; + BitmapWrapper* mBitmapWrapper; }; namespace bitmap { @@ -175,18 +175,18 @@ int getBitmapAllocationByteCount(JNIEnv* env, jobject javaBitmap) return env->CallIntMethod(javaBitmap, gBitmap_getAllocationByteCountMethodID); } -jobject createBitmap(JNIEnv* env, PixelRef* pixelRef, +jobject createBitmap(JNIEnv* env, Bitmap* bitmap, int bitmapCreateFlags, jbyteArray ninePatchChunk, jobject ninePatchInsets, int density) { bool isMutable = bitmapCreateFlags & kBitmapCreateFlag_Mutable; bool isPremultiplied = bitmapCreateFlags & kBitmapCreateFlag_Premultiplied; // The caller needs to have already set the alpha type properly, so the // native SkBitmap stays in sync with the Java Bitmap. - assert_premultiplied(pixelRef->info(), isPremultiplied); - Bitmap* bitmap = new Bitmap(pixelRef); + assert_premultiplied(bitmap->info(), isPremultiplied); + BitmapWrapper* bitmapWrapper = new BitmapWrapper(bitmap); jobject obj = env->NewObject(gBitmap_class, gBitmap_constructorMethodID, - reinterpret_cast(bitmap), pixelRef->width(), pixelRef->height(), density, isMutable, - isPremultiplied, ninePatchChunk, ninePatchInsets); + reinterpret_cast(bitmapWrapper), bitmap->width(), bitmap->height(), density, + isMutable, isPremultiplied, ninePatchChunk, ninePatchInsets); if (env->ExceptionCheck() != 0) { ALOGE("*** Uncaught exception returned from Java call!\n"); @@ -200,14 +200,14 @@ void toSkBitmap(jlong bitmapHandle, SkBitmap* outBitmap) { bitmap->getSkBitmap(outBitmap); } -PixelRef* toPixelRef(JNIEnv* env, jobject bitmap) { +Bitmap* toBitmap(JNIEnv* env, jobject bitmap) { SkASSERT(env); SkASSERT(bitmap); SkASSERT(env->IsInstanceOf(bitmap, gBitmap_class)); jlong bitmapHandle = env->GetLongField(bitmap, gBitmap_nativePtr); LocalScopedBitmap localBitmap(bitmapHandle); localBitmap->assertValid(); - return localBitmap->pixelRef(); + return localBitmap->bitmap(); } } // namespace bitmap @@ -548,7 +548,7 @@ static jobject Bitmap_creator(JNIEnv* env, jobject, jintArray jColors, bitmap.setInfo(SkImageInfo::Make(width, height, colorType, kPremul_SkAlphaType, GraphicsJNI::defaultColorSpace())); - sk_sp nativeBitmap = PixelRef::allocateHeapPixelRef(&bitmap, NULL); + sk_sp nativeBitmap = Bitmap::allocateHeapBitmap(&bitmap, NULL); if (!nativeBitmap) { return NULL; } @@ -564,7 +564,7 @@ static jobject Bitmap_creator(JNIEnv* env, jobject, jintArray jColors, static jobject Bitmap_copy(JNIEnv* env, jobject, jlong srcHandle, jint dstConfigHandle, jboolean isMutable) { SkBitmap src; - reinterpret_cast(srcHandle)->getSkBitmap(&src); + reinterpret_cast(srcHandle)->getSkBitmap(&src); SkColorType dstCT = GraphicsJNI::legacyBitmapConfigToColorType(dstConfigHandle); SkBitmap result; HeapAllocator allocator; @@ -572,41 +572,41 @@ static jobject Bitmap_copy(JNIEnv* env, jobject, jlong srcHandle, if (!src.copyTo(&result, dstCT, &allocator)) { return NULL; } - auto pixelRef = allocator.getStorageObjAndReset(); - return createBitmap(env, pixelRef, getPremulBitmapCreateFlags(isMutable)); + auto bitmap = allocator.getStorageObjAndReset(); + return createBitmap(env, bitmap, getPremulBitmapCreateFlags(isMutable)); } -static PixelRef* Bitmap_copyAshmemImpl(JNIEnv* env, SkBitmap& src, SkColorType& dstCT) { +static Bitmap* Bitmap_copyAshmemImpl(JNIEnv* env, SkBitmap& src, SkColorType& dstCT) { SkBitmap result; AshmemPixelAllocator allocator(env); if (!src.copyTo(&result, dstCT, &allocator)) { return NULL; } - auto pixelRef = allocator.getStorageObjAndReset(); - pixelRef->setImmutable(); - return pixelRef; + auto bitmap = allocator.getStorageObjAndReset(); + bitmap->setImmutable(); + return bitmap; } static jobject Bitmap_copyAshmem(JNIEnv* env, jobject, jlong srcHandle) { SkBitmap src; - reinterpret_cast(srcHandle)->getSkBitmap(&src); + reinterpret_cast(srcHandle)->getSkBitmap(&src); SkColorType dstCT = src.colorType(); - auto pixelRef = Bitmap_copyAshmemImpl(env, src, dstCT); - jobject ret = createBitmap(env, pixelRef, getPremulBitmapCreateFlags(false)); + auto bitmap = Bitmap_copyAshmemImpl(env, src, dstCT); + jobject ret = createBitmap(env, bitmap, getPremulBitmapCreateFlags(false)); return ret; } static jobject Bitmap_copyAshmemConfig(JNIEnv* env, jobject, jlong srcHandle, jint dstConfigHandle) { SkBitmap src; - reinterpret_cast(srcHandle)->getSkBitmap(&src); + reinterpret_cast(srcHandle)->getSkBitmap(&src); SkColorType dstCT = GraphicsJNI::legacyBitmapConfigToColorType(dstConfigHandle); - auto pixelRef = Bitmap_copyAshmemImpl(env, src, dstCT); - jobject ret = createBitmap(env, pixelRef, getPremulBitmapCreateFlags(false)); + auto bitmap = Bitmap_copyAshmemImpl(env, src, dstCT); + jobject ret = createBitmap(env, bitmap, getPremulBitmapCreateFlags(false)); return ret; } -static void Bitmap_destruct(Bitmap* bitmap) { +static void Bitmap_destruct(BitmapWrapper* bitmap) { delete bitmap; } @@ -646,7 +646,7 @@ static void Bitmap_reconfigure(JNIEnv* env, jobject clazz, jlong bitmapHandle, // Otherwise respect the premultiplied request. alphaType = requestPremul ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; } - bitmap->pixelRef()->reconfigure(SkImageInfo::Make(width, height, colorType, alphaType, + bitmap->bitmap()->reconfigure(SkImageInfo::Make(width, height, colorType, alphaType, sk_sp(bitmap->info().colorSpace()))); } @@ -831,7 +831,7 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) { } // Map the bitmap in place from the ashmem region if possible otherwise copy. - sk_sp nativeBitmap; + sk_sp nativeBitmap; if (blob.fd() >= 0 && (blob.isMutable() || !isMutable) && (size >= ASHMEM_BITMAP_MIN_SIZE)) { #if DEBUG_PARCEL ALOGD("Bitmap.createFromParcel: mapped contents of %s bitmap from %s blob " @@ -852,7 +852,7 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) { } // Map the pixels in place and take ownership of the ashmem region. - nativeBitmap = sk_sp(GraphicsJNI::mapAshmemPixelRef(env, bitmap.get(), + nativeBitmap = sk_sp(GraphicsJNI::mapAshmemBitmap(env, bitmap.get(), ctable, dupFd, const_cast(blob.data()), size, !isMutable)); SkSafeUnref(ctable); if (!nativeBitmap) { @@ -879,7 +879,7 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) { #endif // Copy the pixels into a new buffer. - nativeBitmap = PixelRef::allocateHeapPixelRef(bitmap.get(), ctable); + nativeBitmap = Bitmap::allocateHeapBitmap(bitmap.get(), ctable); SkSafeUnref(ctable); if (!nativeBitmap) { blob.release(); @@ -910,8 +910,8 @@ static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject, android::Parcel* p = android::parcelForJavaObject(env, parcel); SkBitmap bitmap; - auto androidBitmap = reinterpret_cast(bitmapHandle); - androidBitmap->getSkBitmap(&bitmap); + auto bitmapWrapper = reinterpret_cast(bitmapHandle); + bitmapWrapper->getSkBitmap(&bitmap); sk_sp sRGB = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); bool isSRGB = bitmap.colorSpace() == sRGB.get(); @@ -941,7 +941,7 @@ static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject, // Transfer the underlying ashmem region if we have one and it's immutable. android::status_t status; - int fd = androidBitmap->pixelRef()->getAshmemFd(); + int fd = bitmapWrapper->bitmap()->getAshmemFd(); if (fd >= 0 && !isMutable && p->allowFds()) { #if DEBUG_PARCEL ALOGD("Bitmap.writeToParcel: transferring immutable bitmap's ashmem fd as " @@ -991,7 +991,7 @@ static jobject Bitmap_extractAlpha(JNIEnv* env, jobject clazz, jlong srcHandle, jlong paintHandle, jintArray offsetXY) { SkBitmap src; - reinterpret_cast(srcHandle)->getSkBitmap(&src); + reinterpret_cast(srcHandle)->getSkBitmap(&src); const android::Paint* paint = reinterpret_cast(paintHandle); SkIPoint offset; SkBitmap dst; @@ -1020,7 +1020,7 @@ static jobject Bitmap_extractAlpha(JNIEnv* env, jobject clazz, static jint Bitmap_getPixel(JNIEnv* env, jobject, jlong bitmapHandle, jint x, jint y) { SkBitmap bitmap; - reinterpret_cast(bitmapHandle)->getSkBitmap(&bitmap); + reinterpret_cast(bitmapHandle)->getSkBitmap(&bitmap); SkAutoLockPixels alp(bitmap); ToColorProc proc = ChooseToColorProc(bitmap); @@ -1041,7 +1041,7 @@ static void Bitmap_getPixels(JNIEnv* env, jobject, jlong bitmapHandle, jintArray pixelArray, jint offset, jint stride, jint x, jint y, jint width, jint height) { SkBitmap bitmap; - reinterpret_cast(bitmapHandle)->getSkBitmap(&bitmap); + reinterpret_cast(bitmapHandle)->getSkBitmap(&bitmap); SkAutoLockPixels alp(bitmap); ToColorProc proc = ChooseToColorProc(bitmap); @@ -1069,7 +1069,7 @@ static void Bitmap_getPixels(JNIEnv* env, jobject, jlong bitmapHandle, static void Bitmap_setPixel(JNIEnv* env, jobject, jlong bitmapHandle, jint x, jint y, jint colorHandle) { SkBitmap bitmap; - reinterpret_cast(bitmapHandle)->getSkBitmap(&bitmap); + reinterpret_cast(bitmapHandle)->getSkBitmap(&bitmap); SkColor color = static_cast(colorHandle); SkAutoLockPixels alp(bitmap); if (NULL == bitmap.getPixels()) { @@ -1089,7 +1089,7 @@ static void Bitmap_setPixels(JNIEnv* env, jobject, jlong bitmapHandle, jintArray pixelArray, jint offset, jint stride, jint x, jint y, jint width, jint height) { SkBitmap bitmap; - reinterpret_cast(bitmapHandle)->getSkBitmap(&bitmap); + reinterpret_cast(bitmapHandle)->getSkBitmap(&bitmap); GraphicsJNI::SetPixels(env, pixelArray, offset, stride, x, y, width, height, bitmap); } @@ -1097,7 +1097,7 @@ static void Bitmap_setPixels(JNIEnv* env, jobject, jlong bitmapHandle, static void Bitmap_copyPixelsToBuffer(JNIEnv* env, jobject, jlong bitmapHandle, jobject jbuffer) { SkBitmap bitmap; - reinterpret_cast(bitmapHandle)->getSkBitmap(&bitmap); + reinterpret_cast(bitmapHandle)->getSkBitmap(&bitmap); SkAutoLockPixels alp(bitmap); const void* src = bitmap.getPixels(); @@ -1112,7 +1112,7 @@ static void Bitmap_copyPixelsToBuffer(JNIEnv* env, jobject, static void Bitmap_copyPixelsFromBuffer(JNIEnv* env, jobject, jlong bitmapHandle, jobject jbuffer) { SkBitmap bitmap; - reinterpret_cast(bitmapHandle)->getSkBitmap(&bitmap); + reinterpret_cast(bitmapHandle)->getSkBitmap(&bitmap); SkAutoLockPixels alp(bitmap); void* dst = bitmap.getPixels(); @@ -1128,8 +1128,8 @@ static jboolean Bitmap_sameAs(JNIEnv* env, jobject, jlong bm0Handle, jlong bm1Handle) { SkBitmap bm0; SkBitmap bm1; - reinterpret_cast(bm0Handle)->getSkBitmap(&bm0); - reinterpret_cast(bm1Handle)->getSkBitmap(&bm1); + reinterpret_cast(bm0Handle)->getSkBitmap(&bm0); + reinterpret_cast(bm1Handle)->getSkBitmap(&bm1); if (bm0.width() != bm1.width() || bm0.height() != bm1.height() || bm0.colorType() != bm1.colorType() || @@ -1189,7 +1189,7 @@ static jboolean Bitmap_sameAs(JNIEnv* env, jobject, jlong bm0Handle, static jlong Bitmap_refPixelRef(JNIEnv* env, jobject, jlong bitmapHandle) { LocalScopedBitmap bitmap(bitmapHandle); - SkPixelRef* pixelRef = bitmap->pixelRef(); + SkPixelRef* pixelRef = bitmap->bitmap(); SkSafeRef(pixelRef); return reinterpret_cast(pixelRef); } diff --git a/core/jni/android/graphics/Bitmap.h b/core/jni/android/graphics/Bitmap.h index 588a99c23bd33..c2b3922db7a25 100644 --- a/core/jni/android/graphics/Bitmap.h +++ b/core/jni/android/graphics/Bitmap.h @@ -24,7 +24,7 @@ namespace android { -class PixelRef; +class Bitmap; namespace bitmap { @@ -34,14 +34,14 @@ enum BitmapCreateFlags { kBitmapCreateFlag_Premultiplied = 0x2, }; -jobject createBitmap(JNIEnv* env, PixelRef* bitmap, +jobject createBitmap(JNIEnv* env, Bitmap* bitmap, int bitmapCreateFlags, jbyteArray ninePatchChunk = NULL, jobject ninePatchInsets = NULL, int density = -1); void toSkBitmap(jlong bitmapHandle, SkBitmap* outBitmap); -PixelRef* toPixelRef(JNIEnv* env, jobject bitmap); +Bitmap* toBitmap(JNIEnv* env, jobject bitmap); /** Reinitialize a bitmap. bitmap must already have its SkAlphaType set in sync with isPremultiplied diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp index ad39a5758afd6..dbb1f4054935c 100644 --- a/core/jni/android/graphics/BitmapFactory.cpp +++ b/core/jni/android/graphics/BitmapFactory.cpp @@ -162,7 +162,7 @@ private: class RecyclingPixelAllocator : public SkBitmap::Allocator { public: - RecyclingPixelAllocator(android::PixelRef* bitmap, unsigned int size) + RecyclingPixelAllocator(android::Bitmap* bitmap, unsigned int size) : mBitmap(bitmap), mSize(size) { } @@ -200,7 +200,7 @@ public: } private: - android::PixelRef* const mBitmap; + android::Bitmap* const mBitmap; const unsigned int mSize; }; @@ -327,10 +327,10 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding scaledHeight = static_cast(scaledHeight * scale + 0.5f); } - android::PixelRef* reuseBitmap = nullptr; + android::Bitmap* reuseBitmap = nullptr; unsigned int existingBufferSize = 0; if (javaBitmap != NULL) { - reuseBitmap = bitmap::toPixelRef(env, javaBitmap); + reuseBitmap = bitmap::toBitmap(env, javaBitmap); if (reuseBitmap->isImmutable()) { ALOGW("Unable to reuse an immutable bitmap as an image decoder target."); javaBitmap = NULL; diff --git a/core/jni/android/graphics/BitmapRegionDecoder.cpp b/core/jni/android/graphics/BitmapRegionDecoder.cpp index 7d0915ba1bc2f..763ce0b85e507 100644 --- a/core/jni/android/graphics/BitmapRegionDecoder.cpp +++ b/core/jni/android/graphics/BitmapRegionDecoder.cpp @@ -148,10 +148,10 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, jint in } // Recycle a bitmap if possible. - android::PixelRef* recycledBitmap = nullptr; + android::Bitmap* recycledBitmap = nullptr; size_t recycledBytes = 0; if (javaBitmap) { - recycledBitmap = bitmap::toPixelRef(env, javaBitmap); + recycledBitmap = bitmap::toBitmap(env, javaBitmap); if (recycledBitmap->isImmutable()) { ALOGW("Warning: Reusing an immutable bitmap as an image decoder target."); } diff --git a/core/jni/android/graphics/Graphics.cpp b/core/jni/android/graphics/Graphics.cpp index a866bae84bdd1..656e8155d6231 100644 --- a/core/jni/android/graphics/Graphics.cpp +++ b/core/jni/android/graphics/Graphics.cpp @@ -337,11 +337,11 @@ SkColorType GraphicsJNI::legacyBitmapConfigToColorType(jint legacyConfig) { } void GraphicsJNI::getSkBitmap(JNIEnv* env, jobject bitmap, SkBitmap* outBitmap) { - android::bitmap::toPixelRef(env, bitmap)->getSkBitmap(outBitmap); + android::bitmap::toBitmap(env, bitmap)->getSkBitmap(outBitmap); } SkPixelRef* GraphicsJNI::refSkPixelRef(JNIEnv* env, jobject bitmap) { - SkPixelRef* pixelRef = android::bitmap::toPixelRef(env, bitmap); + SkPixelRef* pixelRef = android::bitmap::toBitmap(env, bitmap); pixelRef->ref(); return pixelRef; } @@ -401,7 +401,7 @@ jobject GraphicsJNI::createRegion(JNIEnv* env, SkRegion* region) /////////////////////////////////////////////////////////////////////////////// -android::PixelRef* GraphicsJNI::mapAshmemPixelRef(JNIEnv* env, SkBitmap* bitmap, +android::Bitmap* GraphicsJNI::mapAshmemBitmap(JNIEnv* env, SkBitmap* bitmap, SkColorTable* ctable, int fd, void* addr, size_t size, bool readOnly) { const SkImageInfo& info = bitmap->info(); if (info.colorType() == kUnknown_SkColorType) { @@ -423,7 +423,7 @@ android::PixelRef* GraphicsJNI::mapAshmemPixelRef(JNIEnv* env, SkBitmap* bitmap, // attempting to compute our own. const size_t rowBytes = bitmap->rowBytes(); - auto wrapper = new android::PixelRef(addr, fd, size, info, rowBytes, ctable); + auto wrapper = new android::Bitmap(addr, fd, size, info, rowBytes, ctable); wrapper->getSkBitmap(bitmap); if (readOnly) { bitmap->pixelRef()->setImmutable(); @@ -445,14 +445,14 @@ sk_sp GraphicsJNI::defaultColorSpace() { /////////////////////////////////////////////////////////////////////////////// bool HeapAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) { - mStorage = android::PixelRef::allocateHeapPixelRef(bitmap, ctable); + mStorage = android::Bitmap::allocateHeapBitmap(bitmap, ctable); return !!mStorage; } //////////////////////////////////////////////////////////////////////////////// RecyclingClippingPixelAllocator::RecyclingClippingPixelAllocator( - android::PixelRef* recycledBitmap, size_t recycledBytes) + android::Bitmap* recycledBitmap, size_t recycledBytes) : mRecycledBitmap(recycledBitmap) , mRecycledBytes(recycledBytes) , mSkiaBitmap(nullptr) @@ -550,7 +550,7 @@ AshmemPixelAllocator::AshmemPixelAllocator(JNIEnv *env) { } bool AshmemPixelAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) { - mStorage = android::PixelRef::allocateAshmemPixelRef(bitmap, ctable); + mStorage = android::Bitmap::allocateAshmemBitmap(bitmap, ctable); return !!mStorage; } diff --git a/core/jni/android/graphics/GraphicsJNI.h b/core/jni/android/graphics/GraphicsJNI.h index 343ed4250ba31..aaa8db91a4b9f 100644 --- a/core/jni/android/graphics/GraphicsJNI.h +++ b/core/jni/android/graphics/GraphicsJNI.h @@ -13,7 +13,7 @@ #include "SkColorSpace.h" #include #include -#include +#include class SkBitmapRegionDecoder; class SkCanvas; @@ -72,7 +72,7 @@ public: static jobject createBitmapRegionDecoder(JNIEnv* env, SkBitmapRegionDecoder* bitmap); - static android::PixelRef* mapAshmemPixelRef(JNIEnv* env, SkBitmap* bitmap, + static android::Bitmap* mapAshmemBitmap(JNIEnv* env, SkBitmap* bitmap, SkColorTable* ctable, int fd, void* addr, size_t size, bool readOnly); /** @@ -104,13 +104,13 @@ public: /** * Fetches the backing allocation object. Must be called! */ - android::PixelRef* getStorageObjAndReset() { + android::Bitmap* getStorageObjAndReset() { return mStorage.release(); }; SkCodec::ZeroInitialized zeroInit() const override { return SkCodec::kYes_ZeroInitialized; } private: - sk_sp mStorage; + sk_sp mStorage; }; /** @@ -143,7 +143,7 @@ private: class RecyclingClippingPixelAllocator : public SkBRDAllocator { public: - RecyclingClippingPixelAllocator(android::PixelRef* recycledBitmap, + RecyclingClippingPixelAllocator(android::Bitmap* recycledBitmap, size_t recycledBytes); ~RecyclingClippingPixelAllocator(); @@ -168,7 +168,7 @@ public: SkCodec::ZeroInitialized zeroInit() const override { return SkCodec::kNo_ZeroInitialized; } private: - android::PixelRef* mRecycledBitmap; + android::Bitmap* mRecycledBitmap; const size_t mRecycledBytes; SkBitmap* mSkiaBitmap; bool mNeedsCopy; @@ -179,13 +179,13 @@ public: explicit AshmemPixelAllocator(JNIEnv* env); ~AshmemPixelAllocator() { }; virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable); - android::PixelRef* getStorageObjAndReset() { + android::Bitmap* getStorageObjAndReset() { return mStorage.release(); }; private: JavaVM* mJavaVM; - sk_sp mStorage; + sk_sp mStorage; }; diff --git a/core/jni/android_graphics_Canvas.cpp b/core/jni/android_graphics_Canvas.cpp index c5b9d64fc2a28..55a9d6d69de0e 100644 --- a/core/jni/android_graphics_Canvas.cpp +++ b/core/jni/android_graphics_Canvas.cpp @@ -446,8 +446,8 @@ static void drawBitmapArray(JNIEnv* env, jobject, jlong canvasHandle, GraphicsJNI::defaultColorSpace()); SkBitmap bitmap; bitmap.setInfo(info); - sk_sp pixelRef = PixelRef::allocateHeapPixelRef(&bitmap, NULL); - if (!pixelRef) { + sk_sp androidBitmap = Bitmap::allocateHeapBitmap(&bitmap, NULL); + if (!androidBitmap) { return; } diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp index 65f12ac1907a8..5b8818171b6f0 100644 --- a/core/jni/android_view_SurfaceControl.cpp +++ b/core/jni/android_view_SurfaceControl.cpp @@ -186,14 +186,13 @@ static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz, return NULL; } - auto pixelRef = new PixelRef( + auto bitmap = new Bitmap( (void*) screenshot->getPixels(), (void*) screenshot.get(), DeleteScreenshot, screenshotInfo, rowBytes, nullptr); screenshot.release(); - pixelRef->setImmutable(); - - return bitmap::createBitmap(env, pixelRef, - bitmap::kBitmapCreateFlag_Premultiplied, NULL); + bitmap->setImmutable(); + return bitmap::createBitmap(env, bitmap, + android::bitmap::kBitmapCreateFlag_Premultiplied, NULL); } static void nativeScreenshot(JNIEnv* env, jclass clazz, jobject displayTokenObj, diff --git a/libs/hwui/Android.mk b/libs/hwui/Android.mk index 1282846559552..0aa78081b0167 100644 --- a/libs/hwui/Android.mk +++ b/libs/hwui/Android.mk @@ -10,13 +10,13 @@ BUGREPORT_FONT_CACHE_USAGE := false HWUI_ENABLE_OPENGL_VALIDATION := false hwui_src_files := \ + hwui/Bitmap.cpp \ font/CacheTexture.cpp \ font/Font.cpp \ hwui/Canvas.cpp \ hwui/MinikinSkia.cpp \ hwui/MinikinUtils.cpp \ hwui/PaintImpl.cpp \ - hwui/PixelRef.cpp \ hwui/Typeface.cpp \ renderstate/Blend.cpp \ renderstate/MeshState.cpp \ diff --git a/libs/hwui/hwui/PixelRef.cpp b/libs/hwui/hwui/Bitmap.cpp similarity index 78% rename from libs/hwui/hwui/PixelRef.cpp rename to libs/hwui/hwui/Bitmap.cpp index 949ee65ad6846..f2fce189f38c5 100644 --- a/libs/hwui/hwui/PixelRef.cpp +++ b/libs/hwui/hwui/Bitmap.cpp @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "PixelRef.h" +#include "Bitmap.h" #include "Caches.h" @@ -34,10 +34,10 @@ static bool computeAllocationSize(const SkBitmap& bitmap, size_t* size) { return true; } -typedef sk_sp (*AllocPixeRef)(size_t allocSize, const SkImageInfo& info, size_t rowBytes, +typedef sk_sp (*AllocPixeRef)(size_t allocSize, const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable); -static sk_sp allocatePixelRef(SkBitmap* bitmap, SkColorTable* ctable, AllocPixeRef alloc) { +static sk_sp allocateBitmap(SkBitmap* bitmap, SkColorTable* ctable, AllocPixeRef alloc) { const SkImageInfo& info = bitmap->info(); if (info.colorType() == kUnknown_SkColorType) { LOG_ALWAYS_FATAL("unknown bitmap configuration"); @@ -62,24 +62,24 @@ static sk_sp allocatePixelRef(SkBitmap* bitmap, SkColorTable* ctable, return wrapper; } -sk_sp PixelRef::allocateHeapPixelRef(SkBitmap* bitmap, SkColorTable* ctable) { - return allocatePixelRef(bitmap, ctable, &PixelRef::allocateHeapPixelRef); +sk_sp Bitmap::allocateHeapBitmap(SkBitmap* bitmap, SkColorTable* ctable) { + return allocateBitmap(bitmap, ctable, &Bitmap::allocateHeapBitmap); } -sk_sp PixelRef::allocateAshmemPixelRef(SkBitmap* bitmap, SkColorTable* ctable) { - return allocatePixelRef(bitmap, ctable, &PixelRef::allocateAshmemPixelRef); +sk_sp Bitmap::allocateAshmemBitmap(SkBitmap* bitmap, SkColorTable* ctable) { + return allocateBitmap(bitmap, ctable, &Bitmap::allocateAshmemBitmap); } -sk_sp PixelRef::allocateHeapPixelRef(size_t size, const SkImageInfo& info, size_t rowBytes, +sk_sp Bitmap::allocateHeapBitmap(size_t size, const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable) { void* addr = calloc(size, 1); if (!addr) { return nullptr; } - return sk_sp(new PixelRef(addr, size, info, rowBytes, ctable)); + return sk_sp(new Bitmap(addr, size, info, rowBytes, ctable)); } -sk_sp PixelRef::allocateAshmemPixelRef(size_t size, const SkImageInfo& info, +sk_sp Bitmap::allocateAshmemBitmap(size_t size, const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable) { // Create new ashmem region with read/write priv int fd = ashmem_create_region("bitmap", size); @@ -98,10 +98,10 @@ sk_sp PixelRef::allocateAshmemPixelRef(size_t size, const SkImageInfo& close(fd); return nullptr; } - return sk_sp(new PixelRef(addr, fd, size, info, rowBytes, ctable)); + return sk_sp(new Bitmap(addr, fd, size, info, rowBytes, ctable)); } -void PixelRef::reconfigure(const SkImageInfo& newInfo, size_t rowBytes, SkColorTable* ctable) { +void Bitmap::reconfigure(const SkImageInfo& newInfo, size_t rowBytes, SkColorTable* ctable) { if (kIndex_8_SkColorType != newInfo.colorType()) { ctable = nullptr; } @@ -132,7 +132,7 @@ void PixelRef::reconfigure(const SkImageInfo& newInfo, size_t rowBytes, SkColorT setPreLocked(getStorage(), mRowBytes, mColorTable.get()); } -PixelRef::PixelRef(void* address, size_t size, const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable) +Bitmap::Bitmap(void* address, size_t size, const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable) : SkPixelRef(info) , mPixelStorageType(PixelStorageType::Heap) { mPixelStorage.heap.address = address; @@ -140,7 +140,7 @@ PixelRef::PixelRef(void* address, size_t size, const SkImageInfo& info, size_t r reconfigure(info, rowBytes, ctable); } -PixelRef::PixelRef(void* address, void* context, FreeFunc freeFunc, +Bitmap::Bitmap(void* address, void* context, FreeFunc freeFunc, const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable) : SkPixelRef(info) , mPixelStorageType(PixelStorageType::External) { @@ -150,7 +150,7 @@ PixelRef::PixelRef(void* address, void* context, FreeFunc freeFunc, reconfigure(info, rowBytes, ctable); } -PixelRef::PixelRef(void* address, int fd, size_t mappedSize, +Bitmap::Bitmap(void* address, int fd, size_t mappedSize, const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable) : SkPixelRef(info) , mPixelStorageType(PixelStorageType::Ashmem) { @@ -160,7 +160,7 @@ PixelRef::PixelRef(void* address, int fd, size_t mappedSize, reconfigure(info, rowBytes, ctable); } -PixelRef::~PixelRef() { +Bitmap::~Bitmap() { switch (mPixelStorageType) { case PixelStorageType::External: mPixelStorage.external.freeFunc(mPixelStorage.external.address, @@ -180,15 +180,15 @@ PixelRef::~PixelRef() { } } -bool PixelRef::hasHardwareMipMap() const { +bool Bitmap::hasHardwareMipMap() const { return mHasHardwareMipMap; } -void PixelRef::setHasHardwareMipMap(bool hasMipMap) { +void Bitmap::setHasHardwareMipMap(bool hasMipMap) { mHasHardwareMipMap = hasMipMap; } -void* PixelRef::getStorage() const { +void* Bitmap::getStorage() const { switch (mPixelStorageType) { case PixelStorageType::External: return mPixelStorage.external.address; @@ -199,18 +199,18 @@ void* PixelRef::getStorage() const { } } -bool PixelRef::onNewLockPixels(LockRec* rec) { +bool Bitmap::onNewLockPixels(LockRec* rec) { rec->fPixels = getStorage(); rec->fRowBytes = mRowBytes; rec->fColorTable = mColorTable.get(); return true; } -size_t PixelRef::getAllocatedSizeInBytes() const { +size_t Bitmap::getAllocatedSizeInBytes() const { return info().getSafeSize(mRowBytes); } -int PixelRef::getAshmemFd() const { +int Bitmap::getAshmemFd() const { switch (mPixelStorageType) { case PixelStorageType::Ashmem: return mPixelStorage.ashmem.fd; @@ -219,7 +219,7 @@ int PixelRef::getAshmemFd() const { } } -size_t PixelRef::getAllocationByteCount() const { +size_t Bitmap::getAllocationByteCount() const { switch (mPixelStorageType) { case PixelStorageType::Heap: return mPixelStorage.heap.size; @@ -228,11 +228,11 @@ size_t PixelRef::getAllocationByteCount() const { } } -void PixelRef::reconfigure(const SkImageInfo& info) { +void Bitmap::reconfigure(const SkImageInfo& info) { reconfigure(info, info.minRowBytes(), nullptr); } -void PixelRef::setAlphaType(SkAlphaType alphaType) { +void Bitmap::setAlphaType(SkAlphaType alphaType) { if (!SkColorTypeValidateAlphaType(info().colorType(), alphaType, &alphaType)) { return; } @@ -240,7 +240,7 @@ void PixelRef::setAlphaType(SkAlphaType alphaType) { changeAlphaType(alphaType); } -void PixelRef::getSkBitmap(SkBitmap* outBitmap) { +void Bitmap::getSkBitmap(SkBitmap* outBitmap) { outBitmap->setInfo(info(), rowBytes()); outBitmap->setPixelRef(this); outBitmap->setHasHardwareMipMap(mHasHardwareMipMap); diff --git a/libs/hwui/hwui/PixelRef.h b/libs/hwui/hwui/Bitmap.h similarity index 77% rename from libs/hwui/hwui/PixelRef.h rename to libs/hwui/hwui/Bitmap.h index 0baf4b86eed0a..047f9f5d1fdac 100644 --- a/libs/hwui/hwui/PixelRef.h +++ b/libs/hwui/hwui/Bitmap.h @@ -31,21 +31,21 @@ enum class PixelStorageType { typedef void (*FreeFunc)(void* addr, void* context); -class ANDROID_API PixelRef : public SkPixelRef { +class ANDROID_API Bitmap : public SkPixelRef { public: - static sk_sp allocateHeapPixelRef(SkBitmap* bitmap, SkColorTable* ctable); - static sk_sp allocateHeapPixelRef(size_t allocSize, const SkImageInfo& info, + static sk_sp allocateHeapBitmap(SkBitmap* bitmap, SkColorTable* ctable); + static sk_sp allocateHeapBitmap(size_t allocSize, const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable); - static sk_sp allocateAshmemPixelRef(SkBitmap* bitmap, SkColorTable* ctable); - static sk_sp allocateAshmemPixelRef(size_t allocSize, const SkImageInfo& info, + static sk_sp allocateAshmemBitmap(SkBitmap* bitmap, SkColorTable* ctable); + static sk_sp allocateAshmemBitmap(size_t allocSize, const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable); - PixelRef(void* address, size_t allocSize, const SkImageInfo& info, size_t rowBytes, + Bitmap(void* address, size_t allocSize, const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable); - PixelRef(void* address, void* context, FreeFunc freeFunc, + Bitmap(void* address, void* context, FreeFunc freeFunc, const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable); - PixelRef(void* address, int fd, size_t mappedSize, const SkImageInfo& info, + Bitmap(void* address, int fd, size_t mappedSize, const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable); int width() const { return info().width(); } @@ -54,7 +54,7 @@ public: // Can't mark as override since SkPixelRef::rowBytes isn't virtual // but that's OK since we just want Bitmap to be able to rely // on calling rowBytes() on an unlocked pixelref, which it will be - // doing on a PixelRef type, not a SkPixelRef, so static + // doing on a Bitmap type, not a SkPixelRef, so static // dispatching will do what we want. size_t rowBytes() const { return mRowBytes; } void reconfigure(const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable); @@ -66,17 +66,17 @@ public: int getAshmemFd() const; size_t getAllocationByteCount() const; + void setHasHardwareMipMap(bool hasMipMap); + bool hasHardwareMipMap() const; + protected: virtual bool onNewLockPixels(LockRec* rec) override; virtual void onUnlockPixels() override { }; virtual size_t getAllocatedSizeInBytes() const override; private: - friend class Bitmap; - virtual ~PixelRef(); + virtual ~Bitmap(); void doFreePixels(); void* getStorage() const; - void setHasHardwareMipMap(bool hasMipMap); - bool hasHardwareMipMap() const; PixelStorageType mPixelStorageType; diff --git a/libs/hwui/tests/common/TestUtils.h b/libs/hwui/tests/common/TestUtils.h index 168c23d51f697..470854768bf28 100644 --- a/libs/hwui/tests/common/TestUtils.h +++ b/libs/hwui/tests/common/TestUtils.h @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include @@ -129,7 +129,7 @@ public: SkImageInfo info = SkImageInfo::Make(width, height, colorType, kPremul_SkAlphaType, colorSpace); bitmap.setInfo(info); - PixelRef::allocateHeapPixelRef(&bitmap, nullptr); + Bitmap::allocateHeapBitmap(&bitmap, nullptr); return bitmap; }