Loading core/jni/android/graphics/BitmapFactory.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ #include "Utils.h" #include "core_jni_helpers.h" #include <HardwareBitmapUploader.h> #include <nativehelper/JNIHelp.h> #include <androidfw/Asset.h> #include <androidfw/ResourceTypes.h> Loading Loading @@ -278,6 +279,11 @@ static jobject doDecode(JNIEnv* env, std::unique_ptr<SkStreamRewindable> stream, // Set the decode colorType SkColorType decodeColorType = codec->computeOutputColorType(prefColorType); if (decodeColorType == kRGBA_F16_SkColorType && isHardware && !uirenderer::HardwareBitmapUploader::hasFP16Support()) { decodeColorType = kN32_SkColorType; } sk_sp<SkColorSpace> decodeColorSpace = codec->computeOutputColorSpace( decodeColorType, prefColorSpace); Loading core/jni/android/graphics/BitmapRegionDecoder.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ #include "android_util_Binder.h" #include "core_jni_helpers.h" #include <HardwareBitmapUploader.h> #include <nativehelper/JNIHelp.h> #include <androidfw/Asset.h> #include <binder/Parcel.h> Loading Loading @@ -166,6 +167,10 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, jint in SkBitmapRegionDecoder* brd = reinterpret_cast<SkBitmapRegionDecoder*>(brdHandle); SkColorType decodeColorType = brd->computeOutputColorType(colorType); if (decodeColorType == kRGBA_F16_SkColorType && isHardware && !uirenderer::HardwareBitmapUploader::hasFP16Support()) { decodeColorType = kN32_SkColorType; } // Set up the pixel allocator SkBRDAllocator* allocator = nullptr; Loading core/jni/android/graphics/ImageDecoder.cpp +13 −4 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include "core_jni_helpers.h" #include <hwui/Bitmap.h> #include <HardwareBitmapUploader.h> #include <SkAndroidCodec.h> #include <SkEncodedImageFormat.h> Loading Loading @@ -256,6 +257,17 @@ static jobject ImageDecoder_nDecodeBitmap(JNIEnv* env, jobject /*clazz*/, jlong // This is currently the only way to know that we should decode to F16. colorType = codec->computeOutputColorType(colorType); } const bool isHardware = !requireMutable && (allocator == ImageDecoder::kDefault_Allocator || allocator == ImageDecoder::kHardware_Allocator) && colorType != kGray_8_SkColorType; if (colorType == kRGBA_F16_SkColorType && isHardware && !uirenderer::HardwareBitmapUploader::hasFP16Support()) { colorType = kN32_SkColorType; } sk_sp<SkColorSpace> colorSpace = GraphicsJNI::getNativeColorSpace(colorSpaceHandle); colorSpace = codec->computeOutputColorSpace(colorType, colorSpace); decodeInfo = decodeInfo.makeColorType(colorType).makeColorSpace(colorSpace); Loading Loading @@ -449,10 +461,7 @@ static jobject ImageDecoder_nDecodeBitmap(JNIEnv* env, jobject /*clazz*/, jlong if (requireMutable) { bitmapCreateFlags |= bitmap::kBitmapCreateFlag_Mutable; } else { if ((allocator == ImageDecoder::kDefault_Allocator || allocator == ImageDecoder::kHardware_Allocator) && bm.colorType() != kAlpha_8_SkColorType) { if (isHardware) { sk_sp<Bitmap> hwBitmap = Bitmap::allocateHardwareBitmap(bm); if (hwBitmap) { hwBitmap->setImmutable(); Loading libs/hwui/HardwareBitmapUploader.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -86,7 +86,7 @@ static EGLDisplay getUploadEglDisplay() { return sEglManager.eglDisplay(); } static bool hasFP16Support() { bool HardwareBitmapUploader::hasFP16Support() { static std::once_flag sOnce; static bool hasFP16Support = false; Loading Loading @@ -127,7 +127,7 @@ static FormatInfo determineFormat(const SkBitmap& skBitmap) { formatInfo.type = GL_UNSIGNED_BYTE; break; case kRGBA_F16_SkColorType: formatInfo.isSupported = hasFP16Support(); formatInfo.isSupported = HardwareBitmapUploader::hasFP16Support(); if (formatInfo.isSupported) { formatInfo.type = GL_HALF_FLOAT; formatInfo.pixelFormat = PIXEL_FORMAT_RGBA_FP16; Loading libs/hwui/HardwareBitmapUploader.h +3 −1 Original line number Diff line number Diff line Loading @@ -20,10 +20,12 @@ namespace android::uirenderer { class HardwareBitmapUploader { class ANDROID_API HardwareBitmapUploader { public: static sk_sp<Bitmap> allocateHardwareBitmap(const SkBitmap& sourceBitmap); static void terminate(); static bool hasFP16Support(); }; } // namespace android::uirenderer Loading
core/jni/android/graphics/BitmapFactory.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ #include "Utils.h" #include "core_jni_helpers.h" #include <HardwareBitmapUploader.h> #include <nativehelper/JNIHelp.h> #include <androidfw/Asset.h> #include <androidfw/ResourceTypes.h> Loading Loading @@ -278,6 +279,11 @@ static jobject doDecode(JNIEnv* env, std::unique_ptr<SkStreamRewindable> stream, // Set the decode colorType SkColorType decodeColorType = codec->computeOutputColorType(prefColorType); if (decodeColorType == kRGBA_F16_SkColorType && isHardware && !uirenderer::HardwareBitmapUploader::hasFP16Support()) { decodeColorType = kN32_SkColorType; } sk_sp<SkColorSpace> decodeColorSpace = codec->computeOutputColorSpace( decodeColorType, prefColorSpace); Loading
core/jni/android/graphics/BitmapRegionDecoder.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ #include "android_util_Binder.h" #include "core_jni_helpers.h" #include <HardwareBitmapUploader.h> #include <nativehelper/JNIHelp.h> #include <androidfw/Asset.h> #include <binder/Parcel.h> Loading Loading @@ -166,6 +167,10 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, jint in SkBitmapRegionDecoder* brd = reinterpret_cast<SkBitmapRegionDecoder*>(brdHandle); SkColorType decodeColorType = brd->computeOutputColorType(colorType); if (decodeColorType == kRGBA_F16_SkColorType && isHardware && !uirenderer::HardwareBitmapUploader::hasFP16Support()) { decodeColorType = kN32_SkColorType; } // Set up the pixel allocator SkBRDAllocator* allocator = nullptr; Loading
core/jni/android/graphics/ImageDecoder.cpp +13 −4 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include "core_jni_helpers.h" #include <hwui/Bitmap.h> #include <HardwareBitmapUploader.h> #include <SkAndroidCodec.h> #include <SkEncodedImageFormat.h> Loading Loading @@ -256,6 +257,17 @@ static jobject ImageDecoder_nDecodeBitmap(JNIEnv* env, jobject /*clazz*/, jlong // This is currently the only way to know that we should decode to F16. colorType = codec->computeOutputColorType(colorType); } const bool isHardware = !requireMutable && (allocator == ImageDecoder::kDefault_Allocator || allocator == ImageDecoder::kHardware_Allocator) && colorType != kGray_8_SkColorType; if (colorType == kRGBA_F16_SkColorType && isHardware && !uirenderer::HardwareBitmapUploader::hasFP16Support()) { colorType = kN32_SkColorType; } sk_sp<SkColorSpace> colorSpace = GraphicsJNI::getNativeColorSpace(colorSpaceHandle); colorSpace = codec->computeOutputColorSpace(colorType, colorSpace); decodeInfo = decodeInfo.makeColorType(colorType).makeColorSpace(colorSpace); Loading Loading @@ -449,10 +461,7 @@ static jobject ImageDecoder_nDecodeBitmap(JNIEnv* env, jobject /*clazz*/, jlong if (requireMutable) { bitmapCreateFlags |= bitmap::kBitmapCreateFlag_Mutable; } else { if ((allocator == ImageDecoder::kDefault_Allocator || allocator == ImageDecoder::kHardware_Allocator) && bm.colorType() != kAlpha_8_SkColorType) { if (isHardware) { sk_sp<Bitmap> hwBitmap = Bitmap::allocateHardwareBitmap(bm); if (hwBitmap) { hwBitmap->setImmutable(); Loading
libs/hwui/HardwareBitmapUploader.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -86,7 +86,7 @@ static EGLDisplay getUploadEglDisplay() { return sEglManager.eglDisplay(); } static bool hasFP16Support() { bool HardwareBitmapUploader::hasFP16Support() { static std::once_flag sOnce; static bool hasFP16Support = false; Loading Loading @@ -127,7 +127,7 @@ static FormatInfo determineFormat(const SkBitmap& skBitmap) { formatInfo.type = GL_UNSIGNED_BYTE; break; case kRGBA_F16_SkColorType: formatInfo.isSupported = hasFP16Support(); formatInfo.isSupported = HardwareBitmapUploader::hasFP16Support(); if (formatInfo.isSupported) { formatInfo.type = GL_HALF_FLOAT; formatInfo.pixelFormat = PIXEL_FORMAT_RGBA_FP16; Loading
libs/hwui/HardwareBitmapUploader.h +3 −1 Original line number Diff line number Diff line Loading @@ -20,10 +20,12 @@ namespace android::uirenderer { class HardwareBitmapUploader { class ANDROID_API HardwareBitmapUploader { public: static sk_sp<Bitmap> allocateHardwareBitmap(const SkBitmap& sourceBitmap); static void terminate(); static bool hasFP16Support(); }; } // namespace android::uirenderer