Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit def16857 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Only decode to F16 if HARDWARE supports it"

parents 2b69b698 ee3bfe76
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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>
@@ -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);

+5 −0
Original line number Diff line number Diff line
@@ -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>
@@ -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;
+13 −4
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include "core_jni_helpers.h"

#include <hwui/Bitmap.h>
#include <HardwareBitmapUploader.h>

#include <SkAndroidCodec.h>
#include <SkEncodedImageFormat.h>
@@ -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);
@@ -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();
+2 −2
Original line number Diff line number Diff line
@@ -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;

@@ -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;
+3 −1
Original line number Diff line number Diff line
@@ -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