diff options
author | 2017-07-12 10:46:35 -0400 | |
---|---|---|
committer | 2017-07-12 11:27:19 -0400 | |
commit | f51a80d2b074d1971b11b19e890c936af5aa57a3 (patch) | |
tree | d45f2acf4d6b458ae3c38fdb18064909acc09c07 | |
parent | 5b3d97a8ab5a9c0b13cacb621dcb4f999623dec7 (diff) |
Remove more references to kIndex_8
Test: Covered by existing tests. No actual change in behavior, since
kIndex_8 is not being used anyway.
Bug: 62483967
Change-Id: I317e3a814dbd102925fe412d2e19111b0af3af38
-rwxr-xr-x | core/jni/android/graphics/Bitmap.cpp | 147 | ||||
-rw-r--r-- | core/jni/android/graphics/BitmapFactory.cpp | 8 | ||||
-rw-r--r-- | core/jni/android/graphics/Graphics.cpp | 24 | ||||
-rw-r--r-- | core/jni/android/opengl/util.cpp | 7 | ||||
-rw-r--r-- | core/jni/android_graphics_Canvas.cpp | 2 | ||||
-rw-r--r-- | core/jni/android_view_SurfaceControl.cpp | 2 | ||||
-rw-r--r-- | libs/hwui/Android.bp | 1 | ||||
-rw-r--r-- | libs/hwui/Texture.cpp | 9 | ||||
-rw-r--r-- | libs/hwui/hwui/Bitmap.cpp | 62 | ||||
-rw-r--r-- | libs/hwui/hwui/Bitmap.h | 20 | ||||
-rw-r--r-- | libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp | 3 | ||||
-rw-r--r-- | libs/hwui/tests/common/BitmapAllocationTestUtils.h | 4 | ||||
-rw-r--r-- | libs/hwui/tests/common/TestUtils.h | 2 | ||||
-rw-r--r-- | libs/hwui/tests/unit/BitmapTests.cpp | 43 |
14 files changed, 71 insertions, 263 deletions
diff --git a/core/jni/android/graphics/Bitmap.cpp b/core/jni/android/graphics/Bitmap.cpp index be8b9de47869..61e138eb69f3 100755 --- a/core/jni/android/graphics/Bitmap.cpp +++ b/core/jni/android/graphics/Bitmap.cpp @@ -485,11 +485,9 @@ bool GraphicsJNI::SetPixels(JNIEnv* env, jintArray srcColors, int srcOffset, int //////////////////// ToColor procs -typedef void (*ToColorProc)(SkColor dst[], const void* src, int width, - SkColorTable*); +typedef void (*ToColorProc)(SkColor dst[], const void* src, int width); -static void ToColor_F16_Alpha(SkColor dst[], const void* src, int width, - SkColorTable*) { +static void ToColor_F16_Alpha(SkColor dst[], const void* src, int width) { SkASSERT(width > 0); uint64_t* s = (uint64_t*)src; do { @@ -497,8 +495,7 @@ static void ToColor_F16_Alpha(SkColor dst[], const void* src, int width, } while (--width != 0); } -static void ToColor_F16_Raw(SkColor dst[], const void* src, int width, - SkColorTable*) { +static void ToColor_F16_Raw(SkColor dst[], const void* src, int width) { SkASSERT(width > 0); uint64_t* s = (uint64_t*)src; do { @@ -506,8 +503,7 @@ static void ToColor_F16_Raw(SkColor dst[], const void* src, int width, } while (--width != 0); } -static void ToColor_S32_Alpha(SkColor dst[], const void* src, int width, - SkColorTable*) { +static void ToColor_S32_Alpha(SkColor dst[], const void* src, int width) { SkASSERT(width > 0); const SkPMColor* s = (const SkPMColor*)src; do { @@ -515,8 +511,7 @@ static void ToColor_S32_Alpha(SkColor dst[], const void* src, int width, } while (--width != 0); } -static void ToColor_S32_Raw(SkColor dst[], const void* src, int width, - SkColorTable*) { +static void ToColor_S32_Raw(SkColor dst[], const void* src, int width) { SkASSERT(width > 0); const SkPMColor* s = (const SkPMColor*)src; do { @@ -526,8 +521,7 @@ static void ToColor_S32_Raw(SkColor dst[], const void* src, int width, } while (--width != 0); } -static void ToColor_S32_Opaque(SkColor dst[], const void* src, int width, - SkColorTable*) { +static void ToColor_S32_Opaque(SkColor dst[], const void* src, int width) { SkASSERT(width > 0); const SkPMColor* s = (const SkPMColor*)src; do { @@ -537,8 +531,7 @@ static void ToColor_S32_Opaque(SkColor dst[], const void* src, int width, } while (--width != 0); } -static void ToColor_S4444_Alpha(SkColor dst[], const void* src, int width, - SkColorTable*) { +static void ToColor_S4444_Alpha(SkColor dst[], const void* src, int width) { SkASSERT(width > 0); const SkPMColor16* s = (const SkPMColor16*)src; do { @@ -546,8 +539,7 @@ static void ToColor_S4444_Alpha(SkColor dst[], const void* src, int width, } while (--width != 0); } -static void ToColor_S4444_Raw(SkColor dst[], const void* src, int width, - SkColorTable*) { +static void ToColor_S4444_Raw(SkColor dst[], const void* src, int width) { SkASSERT(width > 0); const SkPMColor16* s = (const SkPMColor16*)src; do { @@ -557,8 +549,7 @@ static void ToColor_S4444_Raw(SkColor dst[], const void* src, int width, } while (--width != 0); } -static void ToColor_S4444_Opaque(SkColor dst[], const void* src, int width, - SkColorTable*) { +static void ToColor_S4444_Opaque(SkColor dst[], const void* src, int width) { SkASSERT(width > 0); const SkPMColor16* s = (const SkPMColor16*)src; do { @@ -568,8 +559,7 @@ static void ToColor_S4444_Opaque(SkColor dst[], const void* src, int width, } while (--width != 0); } -static void ToColor_S565(SkColor dst[], const void* src, int width, - SkColorTable*) { +static void ToColor_S565(SkColor dst[], const void* src, int width) { SkASSERT(width > 0); const uint16_t* s = (const uint16_t*)src; do { @@ -579,41 +569,7 @@ static void ToColor_S565(SkColor dst[], const void* src, int width, } while (--width != 0); } -static void ToColor_SI8_Alpha(SkColor dst[], const void* src, int width, - SkColorTable* ctable) { - SkASSERT(width > 0); - const uint8_t* s = (const uint8_t*)src; - const SkPMColor* colors = ctable->readColors(); - do { - *dst++ = SkUnPreMultiply::PMColorToColor(colors[*s++]); - } while (--width != 0); -} - -static void ToColor_SI8_Raw(SkColor dst[], const void* src, int width, - SkColorTable* ctable) { - SkASSERT(width > 0); - const uint8_t* s = (const uint8_t*)src; - const SkPMColor* colors = ctable->readColors(); - do { - SkPMColor c = colors[*s++]; - *dst++ = SkColorSetARGB(SkGetPackedA32(c), SkGetPackedR32(c), - SkGetPackedG32(c), SkGetPackedB32(c)); - } while (--width != 0); -} - -static void ToColor_SI8_Opaque(SkColor dst[], const void* src, int width, - SkColorTable* ctable) { - SkASSERT(width > 0); - const uint8_t* s = (const uint8_t*)src; - const SkPMColor* colors = ctable->readColors(); - do { - SkPMColor c = colors[*s++]; - *dst++ = SkColorSetRGB(SkGetPackedR32(c), SkGetPackedG32(c), - SkGetPackedB32(c)); - } while (--width != 0); -} - -static void ToColor_SA8(SkColor dst[], const void* src, int width, SkColorTable*) { +static void ToColor_SA8(SkColor dst[], const void* src, int width) { SkASSERT(width > 0); const uint8_t* s = (const uint8_t*)src; do { @@ -649,20 +605,6 @@ static ToColorProc ChooseToColorProc(const SkBitmap& src) { } case kRGB_565_SkColorType: return ToColor_S565; - case kIndex_8_SkColorType: - if (src.getColorTable() == NULL) { - return NULL; - } - switch (src.alphaType()) { - case kOpaque_SkAlphaType: - return ToColor_SI8_Opaque; - case kPremul_SkAlphaType: - return ToColor_SI8_Alpha; - case kUnpremul_SkAlphaType: - return ToColor_SI8_Raw; - default: - return NULL; - } case kAlpha_8_SkColorType: return ToColor_SA8; case kRGBA_F16_SkColorType: @@ -738,7 +680,7 @@ static jobject Bitmap_creator(JNIEnv* env, jobject, jintArray jColors, bitmap.setInfo(SkImageInfo::Make(width, height, colorType, kPremul_SkAlphaType, colorSpace)); - sk_sp<Bitmap> nativeBitmap = Bitmap::allocateHeapBitmap(&bitmap, NULL); + sk_sp<Bitmap> nativeBitmap = Bitmap::allocateHeapBitmap(&bitmap); if (!nativeBitmap) { return NULL; } @@ -752,8 +694,6 @@ static jobject Bitmap_creator(JNIEnv* env, jobject, jintArray jColors, static bool bitmapCopyTo(SkBitmap* dst, SkColorType dstCT, const SkBitmap& src, SkBitmap::Allocator* alloc) { - LOG_ALWAYS_FATAL_IF(kIndex_8_SkColorType == dstCT, "Error, cannot copyTo kIndex8."); - SkPixmap srcPM; if (!src.peekPixels(&srcPM)) { return false; @@ -766,7 +706,7 @@ static bool bitmapCopyTo(SkBitmap* dst, SkColorType dstCT, const SkBitmap& src, // allow the call to readPixels() to succeed and preserve this lenient behavior. if (kOpaque_SkAlphaType != srcPM.alphaType()) { srcPM = SkPixmap(srcPM.info().makeAlphaType(kOpaque_SkAlphaType), srcPM.addr(), - srcPM.rowBytes(), srcPM.ctable()); + srcPM.rowBytes()); dstInfo = dstInfo.makeAlphaType(kOpaque_SkAlphaType); } break; @@ -800,7 +740,7 @@ static bool bitmapCopyTo(SkBitmap* dst, SkColorType dstCT, const SkBitmap& src, for (int y = 0; y < src.height(); y++) { const uint8_t* srcRow = srcPM.addr8(0, y); uint32_t* dstRow = dst->getAddr32(0, y); - ToColor_SA8(dstRow, srcRow, src.width(), nullptr); + ToColor_SA8(dstRow, srcRow, src.width()); } return true; } @@ -1099,7 +1039,6 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) { kRGBA_F16_SkColorType != colorType && kRGB_565_SkColorType != colorType && kARGB_4444_SkColorType != colorType && - kIndex_8_SkColorType != colorType && kAlpha_8_SkColorType != colorType) { SkDebugf("Bitmap_createFromParcel unknown colortype: %d\n", colorType); return NULL; @@ -1111,24 +1050,6 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) { return NULL; } - sk_sp<SkColorTable> ctable = NULL; - if (colorType == kIndex_8_SkColorType) { - int count = p->readInt32(); - if (count < 0 || count > 256) { - // The data is corrupt, since SkColorTable enforces a value between 0 and 256, - // inclusive. - return NULL; - } - if (count > 0) { - size_t size = count * sizeof(SkPMColor); - const SkPMColor* src = (const SkPMColor*)p->readInplace(size); - if (src == NULL) { - return NULL; - } - ctable = SkColorTable::Make(src, count); - } - } - // Read the bitmap blob. size_t size = bitmap->getSize(); android::Parcel::ReadableBlob blob; @@ -1160,7 +1081,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<Bitmap>(GraphicsJNI::mapAshmemBitmap(env, bitmap.get(), - ctable.get(), dupFd, const_cast<void*>(blob.data()), size, !isMutable)); + nullptr, dupFd, const_cast<void*>(blob.data()), size, !isMutable)); if (!nativeBitmap) { close(dupFd); blob.release(); @@ -1185,7 +1106,7 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) { #endif // Copy the pixels into a new buffer. - nativeBitmap = Bitmap::allocateHeapBitmap(bitmap.get(), ctable); + nativeBitmap = Bitmap::allocateHeapBitmap(bitmap.get()); if (!nativeBitmap) { blob.release(); doThrowRE(env, "Could not allocate java pixel ref."); @@ -1240,19 +1161,6 @@ static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject, p->writeInt32(bitmap.rowBytes()); p->writeInt32(density); - if (bitmap.colorType() == kIndex_8_SkColorType) { - // The bitmap needs to be locked to access its color table. - SkColorTable* ctable = bitmap.getColorTable(); - if (ctable != NULL) { - int count = ctable->count(); - p->writeInt32(count); - memcpy(p->writeInplace(count * sizeof(SkPMColor)), - ctable->readColors(), count * sizeof(SkPMColor)); - } else { - p->writeInt32(0); // indicate no ctable - } - } - // Transfer the underlying ashmem region if we have one and it's immutable. android::status_t status; int fd = bitmapWrapper->bitmap().getAshmemFd(); @@ -1394,7 +1302,7 @@ static jint Bitmap_getPixel(JNIEnv* env, jobject, jlong bitmapHandle, } SkColor dst[1]; - proc(dst, src, 1, bitmap.getColorTable()); + proc(dst, src, 1); SkColorSpace* colorSpace = bitmap.colorSpace(); if (bitmap.colorType() != kRGBA_F16_SkColorType && @@ -1424,7 +1332,6 @@ static void Bitmap_getPixels(JNIEnv* env, jobject, jlong bitmapHandle, return; } - SkColorTable* ctable = bitmap.getColorTable(); jint* dst = env->GetIntArrayElements(pixelArray, NULL); SkColor* d = (SkColor*)dst + offset; @@ -1432,7 +1339,7 @@ static void Bitmap_getPixels(JNIEnv* env, jobject, jlong bitmapHandle, if (bitmap.colorType() == kRGBA_F16_SkColorType || GraphicsJNI::isColorSpaceSRGB(colorSpace)) { while (--height >= 0) { - proc(d, src, width, ctable); + proc(d, src, width); d += stride; src = (void*)((const char*)src + bitmap.rowBytes()); } @@ -1441,7 +1348,7 @@ static void Bitmap_getPixels(JNIEnv* env, jobject, jlong bitmapHandle, auto xform = SkColorSpaceXform::New(colorSpace, sRGB.get()); while (--height >= 0) { - proc(d, src, width, ctable); + proc(d, src, width); xform->apply(SkColorSpaceXform::kBGRA_8888_ColorFormat, d, SkColorSpaceXform::kBGRA_8888_ColorFormat, d, width, @@ -1551,22 +1458,6 @@ static jboolean Bitmap_sameAs(JNIEnv* env, jobject, jlong bm0Handle, jlong bm1Ha return JNI_FALSE; } - if (bm0.colorType() == kIndex_8_SkColorType) { - SkColorTable* ct0 = bm0.getColorTable(); - SkColorTable* ct1 = bm1.getColorTable(); - if (NULL == ct0 || NULL == ct1) { - return JNI_FALSE; - } - if (ct0->count() != ct1->count()) { - return JNI_FALSE; - } - - const size_t size = ct0->count() * sizeof(SkPMColor); - if (memcmp(ct0->readColors(), ct1->readColors(), size) != 0) { - return JNI_FALSE; - } - } - // now compare each scanline. We can't do the entire buffer at once, // since we don't care about the pixel values that might extend beyond // the width (since the scanline might be larger than the logical width) diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp index 0a0e5f4376a0..6ea5e9dd294d 100644 --- a/core/jni/android/graphics/BitmapFactory.cpp +++ b/core/jni/android/graphics/BitmapFactory.cpp @@ -136,7 +136,7 @@ public: : mScale(scale), mSize(size) { } - virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) { + virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable*) { // accounts for scale in final allocation, using eventual size and config const int bytesPerPixel = SkColorTypeBytesPerPixel(bitmap->colorType()); const int requestedSize = bytesPerPixel * @@ -147,7 +147,7 @@ public: mSize, requestedSize); return false; } - return SkBitmap::HeapAllocator::allocPixelRef(bitmap, ctable); + return SkBitmap::HeapAllocator::allocPixelRef(bitmap, nullptr); } private: const float mScale; @@ -163,7 +163,7 @@ public: ~RecyclingPixelAllocator() { } - virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) { + virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable*) { const SkImageInfo& info = bitmap->info(); if (info.colorType() == kUnknown_SkColorType) { ALOGW("unable to reuse a bitmap as the target has an unknown bitmap configuration"); @@ -183,7 +183,7 @@ public: return false; } - mBitmap->reconfigure(info, bitmap->rowBytes(), sk_ref_sp(ctable)); + mBitmap->reconfigure(info, bitmap->rowBytes()); bitmap->setPixelRef(sk_ref_sp(mBitmap), 0, 0); return true; } diff --git a/core/jni/android/graphics/Graphics.cpp b/core/jni/android/graphics/Graphics.cpp index 5a2238ff304d..ddd0821c42b9 100644 --- a/core/jni/android/graphics/Graphics.cpp +++ b/core/jni/android/graphics/Graphics.cpp @@ -327,8 +327,6 @@ jint GraphicsJNI::colorTypeToLegacyBitmapConfig(SkColorType colorType) { return kARGB_4444_LegacyBitmapConfig; case kRGB_565_SkColorType: return kRGB_565_LegacyBitmapConfig; - case kIndex_8_SkColorType: - return kIndex8_LegacyBitmapConfig; case kAlpha_8_SkColorType: return kA8_LegacyBitmapConfig; case kUnknown_SkColorType: @@ -342,7 +340,7 @@ SkColorType GraphicsJNI::legacyBitmapConfigToColorType(jint legacyConfig) { const uint8_t gConfig2ColorType[] = { kUnknown_SkColorType, kAlpha_8_SkColorType, - kIndex_8_SkColorType, + kUnknown_SkColorType, // Previously kIndex_8_SkColorType, kRGB_565_SkColorType, kARGB_4444_SkColorType, kN32_SkColorType, @@ -435,7 +433,7 @@ jobject GraphicsJNI::createRegion(JNIEnv* env, SkRegion* region) /////////////////////////////////////////////////////////////////////////////// android::Bitmap* GraphicsJNI::mapAshmemBitmap(JNIEnv* env, SkBitmap* bitmap, - SkColorTable* ctable, int fd, void* addr, size_t size, bool readOnly) { + SkColorTable*, int fd, void* addr, size_t size, bool readOnly) { const SkImageInfo& info = bitmap->info(); if (info.colorType() == kUnknown_SkColorType) { doThrowIAE(env, "unknown bitmap configuration"); @@ -456,7 +454,7 @@ android::Bitmap* GraphicsJNI::mapAshmemBitmap(JNIEnv* env, SkBitmap* bitmap, // attempting to compute our own. const size_t rowBytes = bitmap->rowBytes(); - auto wrapper = new android::Bitmap(addr, fd, size, info, rowBytes, sk_ref_sp(ctable)); + auto wrapper = new android::Bitmap(addr, fd, size, info, rowBytes); wrapper->getSkBitmap(bitmap); if (readOnly) { bitmap->pixelRef()->setImmutable(); @@ -609,8 +607,8 @@ jobject GraphicsJNI::getColorSpace(JNIEnv* env, sk_sp<SkColorSpace>& decodeColor } /////////////////////////////////////////////////////////////////////////////// -bool HeapAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) { - mStorage = android::Bitmap::allocateHeapBitmap(bitmap, sk_ref_sp(ctable)); +bool HeapAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable*) { + mStorage = android::Bitmap::allocateHeapBitmap(bitmap); return !!mStorage; } @@ -626,7 +624,7 @@ RecyclingClippingPixelAllocator::RecyclingClippingPixelAllocator( RecyclingClippingPixelAllocator::~RecyclingClippingPixelAllocator() {} -bool RecyclingClippingPixelAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) { +bool RecyclingClippingPixelAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable*) { // Ensure that the caller did not pass in a NULL bitmap to the constructor or this // function. LOG_ALWAYS_FATAL_IF(!mRecycledBitmap); @@ -649,7 +647,7 @@ bool RecyclingClippingPixelAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTab const size_t rowBytes = maxInfo.minRowBytes(); const size_t bytesNeeded = maxInfo.getSafeSize(rowBytes); if (bytesNeeded <= mRecycledBytes) { - // Here we take advantage of reconfigure() to reset the rowBytes and ctable + // Here we take advantage of reconfigure() to reset the rowBytes // of mRecycledBitmap. It is very important that we pass in // mRecycledBitmap->info() for the SkImageInfo. According to the // specification for BitmapRegionDecoder, we are not allowed to change @@ -658,7 +656,7 @@ bool RecyclingClippingPixelAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTab // storage needs mRecycledBitmap->reconfigure( mRecycledBitmap->info().makeColorSpace(bitmap->refColorSpace()), - rowBytes, sk_ref_sp(ctable)); + rowBytes); // Give the bitmap the same pixelRef as mRecycledBitmap. // skbug.com/4538: We also need to make sure that the rowBytes on the pixel ref @@ -685,7 +683,7 @@ bool RecyclingClippingPixelAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTab // decode is complete. mNeedsCopy = true; - return heapAllocator.allocPixelRef(bitmap, ctable); + return heapAllocator.allocPixelRef(bitmap, nullptr); } void RecyclingClippingPixelAllocator::copyIfNecessary() { @@ -716,8 +714,8 @@ AshmemPixelAllocator::AshmemPixelAllocator(JNIEnv *env) { "env->GetJavaVM failed"); } -bool AshmemPixelAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) { - mStorage = android::Bitmap::allocateAshmemBitmap(bitmap, sk_ref_sp(ctable)); +bool AshmemPixelAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable*) { + mStorage = android::Bitmap::allocateAshmemBitmap(bitmap); return !!mStorage; } diff --git a/core/jni/android/opengl/util.cpp b/core/jni/android/opengl/util.cpp index 7c1ca8142c7f..d7345b069b9c 100644 --- a/core/jni/android/opengl/util.cpp +++ b/core/jni/android/opengl/util.cpp @@ -623,9 +623,6 @@ void util_multiplyMV(JNIEnv *env, jclass clazz, static int checkFormat(SkColorType colorType, int format, int type) { switch(colorType) { - case kIndex_8_SkColorType: - if (format == GL_PALETTE8_RGBA8_OES) - return 0; case kN32_SkColorType: case kAlpha_8_SkColorType: if (type == GL_UNSIGNED_BYTE) @@ -657,8 +654,6 @@ static int getInternalFormat(SkColorType colorType) return GL_RGBA; case kN32_SkColorType: return GL_RGBA; - case kIndex_8_SkColorType: - return GL_PALETTE8_RGBA8_OES; case kRGB_565_SkColorType: return GL_RGB; default: @@ -675,8 +670,6 @@ static int getType(SkColorType colorType) return GL_UNSIGNED_SHORT_4_4_4_4; case kN32_SkColorType: return GL_UNSIGNED_BYTE; - case kIndex_8_SkColorType: - return -1; // No type for compressed data. case kRGB_565_SkColorType: return GL_UNSIGNED_SHORT_5_6_5; default: diff --git a/core/jni/android_graphics_Canvas.cpp b/core/jni/android_graphics_Canvas.cpp index c0f719ed7abe..80f6abe194b3 100644 --- a/core/jni/android_graphics_Canvas.cpp +++ b/core/jni/android_graphics_Canvas.cpp @@ -452,7 +452,7 @@ static void drawBitmapArray(JNIEnv* env, jobject, jlong canvasHandle, GraphicsJNI::defaultColorSpace()); SkBitmap bitmap; bitmap.setInfo(info); - sk_sp<Bitmap> androidBitmap = Bitmap::allocateHeapBitmap(&bitmap, NULL); + sk_sp<Bitmap> androidBitmap = Bitmap::allocateHeapBitmap(&bitmap); if (!androidBitmap) { return; } diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp index 97aa562823e0..1068d6ff306e 100644 --- a/core/jni/android_view_SurfaceControl.cpp +++ b/core/jni/android_view_SurfaceControl.cpp @@ -245,7 +245,7 @@ static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz, auto bitmap = new Bitmap( (void*) screenshot->getPixels(), (void*) screenshot.get(), DeleteScreenshot, - screenshotInfo, rowBytes, nullptr); + screenshotInfo, rowBytes); screenshot.release(); bitmap->setImmutable(); return bitmap::createBitmap(env, bitmap, diff --git a/libs/hwui/Android.bp b/libs/hwui/Android.bp index 113a4779712f..842e053f054b 100644 --- a/libs/hwui/Android.bp +++ b/libs/hwui/Android.bp @@ -302,7 +302,6 @@ cc_test { "tests/unit/BakedOpDispatcherTests.cpp", "tests/unit/BakedOpRendererTests.cpp", "tests/unit/BakedOpStateTests.cpp", - "tests/unit/BitmapTests.cpp", "tests/unit/CacheManagerTests.cpp", "tests/unit/CanvasContextTests.cpp", "tests/unit/CanvasStateTests.cpp", diff --git a/libs/hwui/Texture.cpp b/libs/hwui/Texture.cpp index 4ef31d59271e..b7c1e290370f 100644 --- a/libs/hwui/Texture.cpp +++ b/libs/hwui/Texture.cpp @@ -217,9 +217,8 @@ void Texture::colorTypeToGlFormatAndType(const Caches& caches, SkColorType color *outType = GL_UNSIGNED_SHORT_5_6_5; } break; - // ARGB_4444 and Index_8 are both upconverted to RGBA_8888 + // ARGB_4444 is upconverted to RGBA_8888 case kARGB_4444_SkColorType: - case kIndex_8_SkColorType: case kN32_SkColorType: *outFormat = GL_RGBA; *outInternalFormat = caches.rgbaInternalFormat(needSRGB); @@ -270,7 +269,6 @@ SkBitmap Texture::uploadToN32(const SkBitmap& bitmap, bool hasLinearBlending, bool Texture::hasUnsupportedColorType(const SkImageInfo& info, bool hasLinearBlending) { return info.colorType() == kARGB_4444_SkColorType - || info.colorType() == kIndex_8_SkColorType || (info.colorType() == kRGB_565_SkColorType && hasLinearBlending && info.colorSpace()->isSRGB()) @@ -279,11 +277,6 @@ bool Texture::hasUnsupportedColorType(const SkImageInfo& info, bool hasLinearBle } void Texture::upload(Bitmap& bitmap) { - if (!bitmap.readyToDraw()) { - ALOGE("Cannot generate texture from bitmap"); - return; - } - ATRACE_FORMAT("Upload %ux%u Texture", bitmap.width(), bitmap.height()); // We could also enable mipmapping if both bitmap dimensions are powers diff --git a/libs/hwui/hwui/Bitmap.cpp b/libs/hwui/hwui/Bitmap.cpp index 6dde005c2fc4..3a8914ecf9d6 100644 --- a/libs/hwui/hwui/Bitmap.cpp +++ b/libs/hwui/hwui/Bitmap.cpp @@ -46,10 +46,10 @@ static bool computeAllocationSize(size_t rowBytes, int height, size_t* size) { return true; } -typedef sk_sp<Bitmap> (*AllocPixeRef)(size_t allocSize, const SkImageInfo& info, size_t rowBytes, - sk_sp<SkColorTable> ctable); +typedef sk_sp<Bitmap> (*AllocPixelRef)(size_t allocSize, const SkImageInfo& info, + size_t rowBytes); -static sk_sp<Bitmap> allocateBitmap(SkBitmap* bitmap, sk_sp<SkColorTable> ctable, AllocPixeRef alloc) { +static sk_sp<Bitmap> allocateBitmap(SkBitmap* bitmap, AllocPixelRef alloc) { const SkImageInfo& info = bitmap->info(); if (info.colorType() == kUnknown_SkColorType) { LOG_ALWAYS_FATAL("unknown bitmap configuration"); @@ -65,32 +65,31 @@ static sk_sp<Bitmap> allocateBitmap(SkBitmap* bitmap, sk_sp<SkColorTable> ctable return nullptr; } - auto wrapper = alloc(size, info, rowBytes, std::move(ctable)); + auto wrapper = alloc(size, info, rowBytes); if (wrapper) { wrapper->getSkBitmap(bitmap); } return wrapper; } -sk_sp<Bitmap> Bitmap::allocateAshmemBitmap(SkBitmap* bitmap, sk_sp<SkColorTable> ctable) { - return allocateBitmap(bitmap, std::move(ctable), &Bitmap::allocateAshmemBitmap); +sk_sp<Bitmap> Bitmap::allocateAshmemBitmap(SkBitmap* bitmap) { + return allocateBitmap(bitmap, &Bitmap::allocateAshmemBitmap); } -static sk_sp<Bitmap> allocateHeapBitmap(size_t size, const SkImageInfo& info, size_t rowBytes, - sk_sp<SkColorTable> ctable) { +static sk_sp<Bitmap> allocateHeapBitmap(size_t size, const SkImageInfo& info, size_t rowBytes) { void* addr = calloc(size, 1); if (!addr) { return nullptr; } - return sk_sp<Bitmap>(new Bitmap(addr, size, info, rowBytes, std::move(ctable))); + return sk_sp<Bitmap>(new Bitmap(addr, size, info, rowBytes)); } sk_sp<Bitmap> Bitmap::allocateHardwareBitmap(SkBitmap& bitmap) { return uirenderer::renderthread::RenderProxy::allocateHardwareBitmap(bitmap); } -sk_sp<Bitmap> Bitmap::allocateHeapBitmap(SkBitmap* bitmap, sk_sp<SkColorTable> ctable) { - return allocateBitmap(bitmap, std::move(ctable), &android::allocateHeapBitmap); +sk_sp<Bitmap> Bitmap::allocateHeapBitmap(SkBitmap* bitmap) { + return allocateBitmap(bitmap, &android::allocateHeapBitmap); } sk_sp<Bitmap> Bitmap::allocateHeapBitmap(const SkImageInfo& info) { @@ -99,11 +98,11 @@ sk_sp<Bitmap> Bitmap::allocateHeapBitmap(const SkImageInfo& info) { LOG_ALWAYS_FATAL("trying to allocate too large bitmap"); return nullptr; } - return android::allocateHeapBitmap(size, info, info.minRowBytes(), nullptr); + return android::allocateHeapBitmap(size, info, info.minRowBytes()); } sk_sp<Bitmap> Bitmap::allocateAshmemBitmap(size_t size, const SkImageInfo& info, - size_t rowBytes, sk_sp<SkColorTable> ctable) { + size_t rowBytes) { // Create new ashmem region with read/write priv int fd = ashmem_create_region("bitmap", size); if (fd < 0) { @@ -121,7 +120,7 @@ sk_sp<Bitmap> Bitmap::allocateAshmemBitmap(size_t size, const SkImageInfo& info, close(fd); return nullptr; } - return sk_sp<Bitmap>(new Bitmap(addr, fd, size, info, rowBytes, std::move(ctable))); + return sk_sp<Bitmap>(new Bitmap(addr, fd, size, info, rowBytes)); } void FreePixelRef(void* addr, void* context) { @@ -132,7 +131,7 @@ void FreePixelRef(void* addr, void* context) { sk_sp<Bitmap> Bitmap::createFrom(const SkImageInfo& info, SkPixelRef& pixelRef) { pixelRef.ref(); return sk_sp<Bitmap>(new Bitmap((void*) pixelRef.pixels(), (void*) &pixelRef, FreePixelRef, - info, pixelRef.rowBytes(), sk_ref_sp(pixelRef.colorTable()))); + info, pixelRef.rowBytes())); } sk_sp<Bitmap> Bitmap::createFrom(sp<GraphicBuffer> graphicBuffer) { @@ -161,11 +160,7 @@ static SkImageInfo validateAlpha(const SkImageInfo& info) { return info.makeAlphaType(alphaType); } -void Bitmap::reconfigure(const SkImageInfo& newInfo, size_t rowBytes, sk_sp<SkColorTable> ctable) { - if (kIndex_8_SkColorType != newInfo.colorType()) { - ctable = nullptr; - } - +void Bitmap::reconfigure(const SkImageInfo& newInfo, size_t rowBytes) { mInfo = validateAlpha(newInfo); // Dirty hack is dirty @@ -173,20 +168,11 @@ void Bitmap::reconfigure(const SkImageInfo& newInfo, size_t rowBytes, sk_sp<SkCo // really hard to work with. Skia really, really wants immutable objects, // but with the nested-ref-count hackery going on that's just not // feasible without going insane trying to figure it out - this->android_only_reset(mInfo.width(), mInfo.height(), rowBytes, std::move(ctable)); + this->android_only_reset(mInfo.width(), mInfo.height(), rowBytes, nullptr); } -static sk_sp<SkColorTable> sanitize(const SkImageInfo& info, sk_sp<SkColorTable> ctable) { - if (info.colorType() == kIndex_8_SkColorType) { - SkASSERT(ctable); - return ctable; - } - return nullptr; // drop the ctable if we're not indexed -} -Bitmap::Bitmap(void* address, size_t size, const SkImageInfo& info, size_t rowBytes, - sk_sp<SkColorTable> ctable) - : SkPixelRef(info.width(), info.height(), address, rowBytes, - sanitize(info, std::move(ctable))) +Bitmap::Bitmap(void* address, size_t size, const SkImageInfo& info, size_t rowBytes) + : SkPixelRef(info.width(), info.height(), address, rowBytes) , mInfo(validateAlpha(info)) , mPixelStorageType(PixelStorageType::Heap) { mPixelStorage.heap.address = address; @@ -194,9 +180,8 @@ Bitmap::Bitmap(void* address, size_t size, const SkImageInfo& info, size_t rowBy } Bitmap::Bitmap(void* address, void* context, FreeFunc freeFunc, - const SkImageInfo& info, size_t rowBytes, sk_sp<SkColorTable> ctable) - : SkPixelRef(info.width(), info.height(), address, rowBytes, - sanitize(info, std::move(ctable))) + const SkImageInfo& info, size_t rowBytes) + : SkPixelRef(info.width(), info.height(), address, rowBytes) , mInfo(validateAlpha(info)) , mPixelStorageType(PixelStorageType::External) { mPixelStorage.external.address = address; @@ -205,9 +190,8 @@ Bitmap::Bitmap(void* address, void* context, FreeFunc freeFunc, } Bitmap::Bitmap(void* address, int fd, size_t mappedSize, - const SkImageInfo& info, size_t rowBytes, sk_sp<SkColorTable> ctable) - : SkPixelRef(info.width(), info.height(), address, rowBytes, - sanitize(info, std::move(ctable))) + const SkImageInfo& info, size_t rowBytes) + : SkPixelRef(info.width(), info.height(), address, rowBytes) , mInfo(validateAlpha(info)) , mPixelStorageType(PixelStorageType::Ashmem) { mPixelStorage.ashmem.address = address; @@ -295,7 +279,7 @@ size_t Bitmap::getAllocationByteCount() const { } void Bitmap::reconfigure(const SkImageInfo& info) { - reconfigure(info, info.minRowBytes(), nullptr); + reconfigure(info, info.minRowBytes()); } void Bitmap::setAlphaType(SkAlphaType alphaType) { diff --git a/libs/hwui/hwui/Bitmap.h b/libs/hwui/hwui/Bitmap.h index 3642406709f9..634e76450c38 100644 --- a/libs/hwui/hwui/Bitmap.h +++ b/libs/hwui/hwui/Bitmap.h @@ -17,7 +17,6 @@ #include <SkBitmap.h> #include <SkColorSpace.h> -#include <SkColorTable.h> #include <SkImage.h> #include <SkImageInfo.h> #include <SkPixelRef.h> @@ -46,32 +45,31 @@ typedef void (*FreeFunc)(void* addr, void* context); class ANDROID_API Bitmap : public SkPixelRef { public: - static sk_sp<Bitmap> allocateHeapBitmap(SkBitmap* bitmap, sk_sp<SkColorTable> ctable); + static sk_sp<Bitmap> allocateHeapBitmap(SkBitmap* bitmap); static sk_sp<Bitmap> allocateHeapBitmap(const SkImageInfo& info); static sk_sp<Bitmap> allocateHardwareBitmap(SkBitmap& bitmap); - static sk_sp<Bitmap> allocateAshmemBitmap(SkBitmap* bitmap, sk_sp<SkColorTable> ctable); + static sk_sp<Bitmap> allocateAshmemBitmap(SkBitmap* bitmap); static sk_sp<Bitmap> allocateAshmemBitmap(size_t allocSize, const SkImageInfo& info, - size_t rowBytes, sk_sp<SkColorTable> ctable); + size_t rowBytes); static sk_sp<Bitmap> createFrom(sp<GraphicBuffer> graphicBuffer); static sk_sp<Bitmap> createFrom(const SkImageInfo&, SkPixelRef&); - Bitmap(void* address, size_t allocSize, const SkImageInfo& info, size_t rowBytes, - sk_sp<SkColorTable> ctable); + Bitmap(void* address, size_t allocSize, const SkImageInfo& info, size_t rowBytes); Bitmap(void* address, void* context, FreeFunc freeFunc, - const SkImageInfo& info, size_t rowBytes, sk_sp<SkColorTable> ctable); + const SkImageInfo& info, size_t rowBytes); Bitmap(void* address, int fd, size_t mappedSize, const SkImageInfo& info, - size_t rowBytes, sk_sp<SkColorTable> ctable); + size_t rowBytes); Bitmap(GraphicBuffer* buffer, const SkImageInfo& info); int rowBytesAsPixels() const { return rowBytes() >> SkColorTypeShiftPerPixel(mInfo.colorType()); } - void reconfigure(const SkImageInfo& info, size_t rowBytes, sk_sp<SkColorTable> ctable); + void reconfigure(const SkImageInfo& info, size_t rowBytes); void reconfigure(const SkImageInfo& info); void setColorSpace(sk_sp<SkColorSpace> colorSpace); void setAlphaType(SkAlphaType alphaType); @@ -92,10 +90,6 @@ public: void getBounds(SkRect* bounds) const; - bool readyToDraw() const { - return this->colorType() != kIndex_8_SkColorType || this->colorTable(); - } - bool isHardware() const { return mPixelStorageType == PixelStorageType::Hardware; } diff --git a/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp b/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp index 6d5ef1d4ff1f..edfd9d4f1973 100644 --- a/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp +++ b/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp @@ -270,8 +270,7 @@ sk_sp<Bitmap> SkiaOpenGLPipeline::allocateHardwareBitmap(renderthread::RenderThr switch (info.colorType()) { case kRGBA_8888_SkColorType: isSupported = true; - // ARGB_4444 and Index_8 are both upconverted to RGBA_8888 - case kIndex_8_SkColorType: + // ARGB_4444 is upconverted to RGBA_8888 case kARGB_4444_SkColorType: pixelFormat = PIXEL_FORMAT_RGBA_8888; format = GL_RGBA; diff --git a/libs/hwui/tests/common/BitmapAllocationTestUtils.h b/libs/hwui/tests/common/BitmapAllocationTestUtils.h index 4892179f0d48..2988979cc266 100644 --- a/libs/hwui/tests/common/BitmapAllocationTestUtils.h +++ b/libs/hwui/tests/common/BitmapAllocationTestUtils.h @@ -41,7 +41,7 @@ public: SkBitmap skBitmap; SkImageInfo info = SkImageInfo::Make(width, height, colorType, kPremul_SkAlphaType); skBitmap.setInfo(info); - sk_sp<Bitmap> heapBitmap(Bitmap::allocateHeapBitmap(&skBitmap, nullptr)); + sk_sp<Bitmap> heapBitmap(Bitmap::allocateHeapBitmap(&skBitmap)); setup(skBitmap); return Bitmap::allocateHardwareBitmap(skBitmap); } @@ -73,4 +73,4 @@ public: } // namespace test } // namespace uirenderer -} // namespace android
\ No newline at end of file +} // namespace android diff --git a/libs/hwui/tests/common/TestUtils.h b/libs/hwui/tests/common/TestUtils.h index 98d5fb3af09a..f29363131030 100644 --- a/libs/hwui/tests/common/TestUtils.h +++ b/libs/hwui/tests/common/TestUtils.h @@ -189,7 +189,7 @@ public: static sk_sp<Bitmap> createBitmap(int width, int height, SkBitmap* outBitmap) { SkImageInfo info = SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType); outBitmap->setInfo(info); - return Bitmap::allocateHeapBitmap(outBitmap, nullptr); + return Bitmap::allocateHeapBitmap(outBitmap); } static sp<DeferredLayerUpdater> createTextureLayerUpdater( diff --git a/libs/hwui/tests/unit/BitmapTests.cpp b/libs/hwui/tests/unit/BitmapTests.cpp deleted file mode 100644 index ed689bd6f174..000000000000 --- a/libs/hwui/tests/unit/BitmapTests.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <gtest/gtest.h> - -#include "hwui/Bitmap.h" - -#include <SkBitmap.h> -#include <SkColorTable.h> -#include <SkImageInfo.h> - -#include <tests/common/TestUtils.h> - -using namespace android; -using namespace android::uirenderer; - -TEST(Bitmap, colorTableRefCounting) { - const SkPMColor c[] = { SkPackARGB32(0x80, 0x80, 0, 0) }; - sk_sp<SkColorTable> ctable = SkColorTable::Make(c, SK_ARRAY_COUNT(c)); - - SkBitmap* bm = new SkBitmap(); - bm->allocPixels(SkImageInfo::Make(1, 1, kIndex_8_SkColorType, kPremul_SkAlphaType), - ctable); - sk_sp<Bitmap> bitmap = Bitmap::allocateHeapBitmap(bm, ctable); - EXPECT_FALSE(ctable->unique()); - delete bm; - bitmap.reset(); - EXPECT_TRUE(ctable->unique()); -} - |