Loading core/jni/android/graphics/Bitmap.cpp +9 −9 Original line number Original line Diff line number Diff line Loading @@ -725,9 +725,10 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) { return NULL; return NULL; } } // Map the pixels in place and take ownership of the ashmem region. // Map the pixels in place and take ownership of the ashmem region. We must also respect the nativeBitmap = sk_sp<Bitmap>(GraphicsJNI::mapAshmemBitmap(env, bitmap.get(), // rowBytes value already set on the bitmap instead of attempting to compute our own. dupFd, const_cast<void*>(blob.data()), size, !isMutable)); nativeBitmap = Bitmap::createFrom(bitmap->info(), bitmap->rowBytes(), dupFd, const_cast<void*>(blob.data()), size, !isMutable); if (!nativeBitmap) { if (!nativeBitmap) { close(dupFd); close(dupFd); blob.release(); blob.release(); Loading Loading @@ -1097,21 +1098,20 @@ static jobject Bitmap_copyPreserveInternalConfig(JNIEnv* env, jobject, jlong bit SkBitmap src; SkBitmap src; hwuiBitmap.getSkBitmap(&src); hwuiBitmap.getSkBitmap(&src); SkBitmap result; if (src.pixelRef() == nullptr) { HeapAllocator allocator; if (!bitmapCopyTo(&result, hwuiBitmap.info().colorType(), src, &allocator)) { doThrowRE(env, "Could not copy a hardware bitmap."); doThrowRE(env, "Could not copy a hardware bitmap."); return NULL; return NULL; } } return createBitmap(env, allocator.getStorageObjAndReset(), getPremulBitmapCreateFlags(false)); sk_sp<Bitmap> bitmap = Bitmap::createFrom(src.info(), *src.pixelRef()); return createBitmap(env, bitmap.release(), getPremulBitmapCreateFlags(false)); } } static jobject Bitmap_createHardwareBitmap(JNIEnv* env, jobject, jobject graphicBuffer) { static jobject Bitmap_createHardwareBitmap(JNIEnv* env, jobject, jobject graphicBuffer) { sp<GraphicBuffer> buffer(graphicBufferForJavaObject(env, graphicBuffer)); sp<GraphicBuffer> buffer(graphicBufferForJavaObject(env, graphicBuffer)); // Bitmap::createFrom currently assumes SRGB color space for RGBA images. // To support any color space, we need to pass an additional ColorSpace argument to // To support any color space, we need to pass an additional ColorSpace argument to // java Bitmap.createHardwareBitmap. // java Bitmap.createHardwareBitmap. sk_sp<Bitmap> bitmap = Bitmap::createFrom(buffer); sk_sp<Bitmap> bitmap = Bitmap::createFrom(buffer, SkColorSpace::MakeSRGB()); if (!bitmap.get()) { if (!bitmap.get()) { ALOGW("failed to create hardware bitmap from graphic buffer"); ALOGW("failed to create hardware bitmap from graphic buffer"); return NULL; return NULL; Loading core/jni/android/graphics/Graphics.cpp +0 −30 Original line number Original line Diff line number Diff line Loading @@ -424,36 +424,6 @@ jobject GraphicsJNI::createRegion(JNIEnv* env, SkRegion* region) /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// android::Bitmap* GraphicsJNI::mapAshmemBitmap(JNIEnv* env, SkBitmap* bitmap, int fd, void* addr, size_t size, bool readOnly) { const SkImageInfo& info = bitmap->info(); if (info.colorType() == kUnknown_SkColorType) { doThrowIAE(env, "unknown bitmap configuration"); return nullptr; } if (!addr) { // Map existing ashmem region if not already mapped. int flags = readOnly ? (PROT_READ) : (PROT_READ | PROT_WRITE); size = ashmem_get_size_region(fd); addr = mmap(NULL, size, flags, MAP_SHARED, fd, 0); if (addr == MAP_FAILED) { return nullptr; } } // we must respect the rowBytes value already set on the bitmap instead of // attempting to compute our own. const size_t rowBytes = bitmap->rowBytes(); auto wrapper = new android::Bitmap(addr, fd, size, info, rowBytes); wrapper->getSkBitmap(bitmap); if (readOnly) { bitmap->pixelRef()->setImmutable(); } return wrapper; } SkColorSpaceTransferFn GraphicsJNI::getNativeTransferParameters(JNIEnv* env, jobject transferParams) { SkColorSpaceTransferFn GraphicsJNI::getNativeTransferParameters(JNIEnv* env, jobject transferParams) { SkColorSpaceTransferFn p; SkColorSpaceTransferFn p; p.fA = (float) env->GetDoubleField(transferParams, gTransferParams_aFieldID); p.fA = (float) env->GetDoubleField(transferParams, gTransferParams_aFieldID); Loading core/jni/android/graphics/GraphicsJNI.h +0 −3 Original line number Original line Diff line number Diff line Loading @@ -85,9 +85,6 @@ public: static jobject createBitmapRegionDecoder(JNIEnv* env, SkBitmapRegionDecoder* bitmap); static jobject createBitmapRegionDecoder(JNIEnv* env, SkBitmapRegionDecoder* bitmap); static android::Bitmap* mapAshmemBitmap(JNIEnv* env, SkBitmap* bitmap, int fd, void* addr, size_t size, bool readOnly); /** /** * Given a bitmap we natively allocate a memory block to store the contents * Given a bitmap we natively allocate a memory block to store the contents * of that bitmap. The memory is then attached to the bitmap via an * of that bitmap. The memory is then attached to the bitmap via an Loading core/jni/android_view_ThreadedRenderer.cpp +4 −6 Original line number Original line Diff line number Diff line Loading @@ -31,8 +31,6 @@ #include <gui/BufferQueue.h> #include <gui/BufferQueue.h> #include <gui/Surface.h> #include <gui/Surface.h> #include <EGL/egl.h> #include <EGL/eglext.h> #include <private/EGL/cache.h> #include <private/EGL/cache.h> #include <utils/Looper.h> #include <utils/Looper.h> Loading @@ -58,6 +56,7 @@ #include <renderthread/RenderTask.h> #include <renderthread/RenderTask.h> #include <renderthread/RenderThread.h> #include <renderthread/RenderThread.h> #include <pipeline/skia/ShaderCache.h> #include <pipeline/skia/ShaderCache.h> #include <utils/Color.h> namespace android { namespace android { Loading Loading @@ -1011,10 +1010,9 @@ static jobject android_view_ThreadedRenderer_createHardwareBitmapFromRenderNode( buffer->getWidth(), buffer->getHeight(), width, height); buffer->getWidth(), buffer->getHeight(), width, height); // Continue I guess? // Continue I guess? } } sk_sp<Bitmap> bitmap = Bitmap::createFrom(buffer); // Bitmap::createFrom currently can only attach to a GraphicBuffer with PIXEL_FORMAT_RGBA_8888 sk_sp<SkColorSpace> cs = uirenderer::DataSpaceToColorSpace(bufferItem.mDataSpace); // format and SRGB color space. sk_sp<Bitmap> bitmap = Bitmap::createFrom(buffer, cs); // To support any color space, we could extract it from BufferItem and pass it to Bitmap. return bitmap::createBitmap(env, bitmap.release(), return bitmap::createBitmap(env, bitmap.release(), android::bitmap::kBitmapCreateFlag_Premultiplied); android::bitmap::kBitmapCreateFlag_Premultiplied); } } Loading libs/hwui/HardwareBitmapUploader.cpp +2 −1 Original line number Original line Diff line number Diff line Loading @@ -253,7 +253,8 @@ sk_sp<Bitmap> HardwareBitmapUploader::allocateHardwareBitmap(const SkBitmap& sou eglDestroySyncKHR(display, fence); eglDestroySyncKHR(display, fence); } } return sk_sp<Bitmap>(new Bitmap(buffer.get(), bitmap.info(), Bitmap::computePalette(bitmap))); return Bitmap::createFrom(buffer.get(), bitmap.refColorSpace(), bitmap.alphaType(), Bitmap::computePalette(bitmap)); } } } // namespace android::uirenderer } // namespace android::uirenderer Loading
core/jni/android/graphics/Bitmap.cpp +9 −9 Original line number Original line Diff line number Diff line Loading @@ -725,9 +725,10 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) { return NULL; return NULL; } } // Map the pixels in place and take ownership of the ashmem region. // Map the pixels in place and take ownership of the ashmem region. We must also respect the nativeBitmap = sk_sp<Bitmap>(GraphicsJNI::mapAshmemBitmap(env, bitmap.get(), // rowBytes value already set on the bitmap instead of attempting to compute our own. dupFd, const_cast<void*>(blob.data()), size, !isMutable)); nativeBitmap = Bitmap::createFrom(bitmap->info(), bitmap->rowBytes(), dupFd, const_cast<void*>(blob.data()), size, !isMutable); if (!nativeBitmap) { if (!nativeBitmap) { close(dupFd); close(dupFd); blob.release(); blob.release(); Loading Loading @@ -1097,21 +1098,20 @@ static jobject Bitmap_copyPreserveInternalConfig(JNIEnv* env, jobject, jlong bit SkBitmap src; SkBitmap src; hwuiBitmap.getSkBitmap(&src); hwuiBitmap.getSkBitmap(&src); SkBitmap result; if (src.pixelRef() == nullptr) { HeapAllocator allocator; if (!bitmapCopyTo(&result, hwuiBitmap.info().colorType(), src, &allocator)) { doThrowRE(env, "Could not copy a hardware bitmap."); doThrowRE(env, "Could not copy a hardware bitmap."); return NULL; return NULL; } } return createBitmap(env, allocator.getStorageObjAndReset(), getPremulBitmapCreateFlags(false)); sk_sp<Bitmap> bitmap = Bitmap::createFrom(src.info(), *src.pixelRef()); return createBitmap(env, bitmap.release(), getPremulBitmapCreateFlags(false)); } } static jobject Bitmap_createHardwareBitmap(JNIEnv* env, jobject, jobject graphicBuffer) { static jobject Bitmap_createHardwareBitmap(JNIEnv* env, jobject, jobject graphicBuffer) { sp<GraphicBuffer> buffer(graphicBufferForJavaObject(env, graphicBuffer)); sp<GraphicBuffer> buffer(graphicBufferForJavaObject(env, graphicBuffer)); // Bitmap::createFrom currently assumes SRGB color space for RGBA images. // To support any color space, we need to pass an additional ColorSpace argument to // To support any color space, we need to pass an additional ColorSpace argument to // java Bitmap.createHardwareBitmap. // java Bitmap.createHardwareBitmap. sk_sp<Bitmap> bitmap = Bitmap::createFrom(buffer); sk_sp<Bitmap> bitmap = Bitmap::createFrom(buffer, SkColorSpace::MakeSRGB()); if (!bitmap.get()) { if (!bitmap.get()) { ALOGW("failed to create hardware bitmap from graphic buffer"); ALOGW("failed to create hardware bitmap from graphic buffer"); return NULL; return NULL; Loading
core/jni/android/graphics/Graphics.cpp +0 −30 Original line number Original line Diff line number Diff line Loading @@ -424,36 +424,6 @@ jobject GraphicsJNI::createRegion(JNIEnv* env, SkRegion* region) /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// android::Bitmap* GraphicsJNI::mapAshmemBitmap(JNIEnv* env, SkBitmap* bitmap, int fd, void* addr, size_t size, bool readOnly) { const SkImageInfo& info = bitmap->info(); if (info.colorType() == kUnknown_SkColorType) { doThrowIAE(env, "unknown bitmap configuration"); return nullptr; } if (!addr) { // Map existing ashmem region if not already mapped. int flags = readOnly ? (PROT_READ) : (PROT_READ | PROT_WRITE); size = ashmem_get_size_region(fd); addr = mmap(NULL, size, flags, MAP_SHARED, fd, 0); if (addr == MAP_FAILED) { return nullptr; } } // we must respect the rowBytes value already set on the bitmap instead of // attempting to compute our own. const size_t rowBytes = bitmap->rowBytes(); auto wrapper = new android::Bitmap(addr, fd, size, info, rowBytes); wrapper->getSkBitmap(bitmap); if (readOnly) { bitmap->pixelRef()->setImmutable(); } return wrapper; } SkColorSpaceTransferFn GraphicsJNI::getNativeTransferParameters(JNIEnv* env, jobject transferParams) { SkColorSpaceTransferFn GraphicsJNI::getNativeTransferParameters(JNIEnv* env, jobject transferParams) { SkColorSpaceTransferFn p; SkColorSpaceTransferFn p; p.fA = (float) env->GetDoubleField(transferParams, gTransferParams_aFieldID); p.fA = (float) env->GetDoubleField(transferParams, gTransferParams_aFieldID); Loading
core/jni/android/graphics/GraphicsJNI.h +0 −3 Original line number Original line Diff line number Diff line Loading @@ -85,9 +85,6 @@ public: static jobject createBitmapRegionDecoder(JNIEnv* env, SkBitmapRegionDecoder* bitmap); static jobject createBitmapRegionDecoder(JNIEnv* env, SkBitmapRegionDecoder* bitmap); static android::Bitmap* mapAshmemBitmap(JNIEnv* env, SkBitmap* bitmap, int fd, void* addr, size_t size, bool readOnly); /** /** * Given a bitmap we natively allocate a memory block to store the contents * Given a bitmap we natively allocate a memory block to store the contents * of that bitmap. The memory is then attached to the bitmap via an * of that bitmap. The memory is then attached to the bitmap via an Loading
core/jni/android_view_ThreadedRenderer.cpp +4 −6 Original line number Original line Diff line number Diff line Loading @@ -31,8 +31,6 @@ #include <gui/BufferQueue.h> #include <gui/BufferQueue.h> #include <gui/Surface.h> #include <gui/Surface.h> #include <EGL/egl.h> #include <EGL/eglext.h> #include <private/EGL/cache.h> #include <private/EGL/cache.h> #include <utils/Looper.h> #include <utils/Looper.h> Loading @@ -58,6 +56,7 @@ #include <renderthread/RenderTask.h> #include <renderthread/RenderTask.h> #include <renderthread/RenderThread.h> #include <renderthread/RenderThread.h> #include <pipeline/skia/ShaderCache.h> #include <pipeline/skia/ShaderCache.h> #include <utils/Color.h> namespace android { namespace android { Loading Loading @@ -1011,10 +1010,9 @@ static jobject android_view_ThreadedRenderer_createHardwareBitmapFromRenderNode( buffer->getWidth(), buffer->getHeight(), width, height); buffer->getWidth(), buffer->getHeight(), width, height); // Continue I guess? // Continue I guess? } } sk_sp<Bitmap> bitmap = Bitmap::createFrom(buffer); // Bitmap::createFrom currently can only attach to a GraphicBuffer with PIXEL_FORMAT_RGBA_8888 sk_sp<SkColorSpace> cs = uirenderer::DataSpaceToColorSpace(bufferItem.mDataSpace); // format and SRGB color space. sk_sp<Bitmap> bitmap = Bitmap::createFrom(buffer, cs); // To support any color space, we could extract it from BufferItem and pass it to Bitmap. return bitmap::createBitmap(env, bitmap.release(), return bitmap::createBitmap(env, bitmap.release(), android::bitmap::kBitmapCreateFlag_Premultiplied); android::bitmap::kBitmapCreateFlag_Premultiplied); } } Loading
libs/hwui/HardwareBitmapUploader.cpp +2 −1 Original line number Original line Diff line number Diff line Loading @@ -253,7 +253,8 @@ sk_sp<Bitmap> HardwareBitmapUploader::allocateHardwareBitmap(const SkBitmap& sou eglDestroySyncKHR(display, fence); eglDestroySyncKHR(display, fence); } } return sk_sp<Bitmap>(new Bitmap(buffer.get(), bitmap.info(), Bitmap::computePalette(bitmap))); return Bitmap::createFrom(buffer.get(), bitmap.refColorSpace(), bitmap.alphaType(), Bitmap::computePalette(bitmap)); } } } // namespace android::uirenderer } // namespace android::uirenderer