Merge "Only decode to F16 if HARDWARE supports it"

This commit is contained in:
TreeHugger Robot
2019-01-31 19:37:54 +00:00
committed by Android (Google) Code Review
5 changed files with 29 additions and 7 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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();

View File

@@ -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;

View File

@@ -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