Merge changes I6f00614d,I987eeab2 into oc-dev

am: c273784c91

Change-Id: I732b93decc6ce9b3a846c971ff25484447ff9127
This commit is contained in:
Romain Guy
2017-04-06 21:30:17 +00:00
committed by android-build-merger
2 changed files with 32 additions and 9 deletions

View File

@@ -227,10 +227,16 @@ void Texture::colorTypeToGlFormatAndType(const Caches& caches, SkColorType color
*outType = GL_UNSIGNED_BYTE; *outType = GL_UNSIGNED_BYTE;
break; break;
case kRGBA_F16_SkColorType: case kRGBA_F16_SkColorType:
// This format is always linear if (caches.extensions().getMajorGlVersion() >= 3) {
*outFormat = GL_RGBA; // This format is always linear
*outInternalFormat = GL_RGBA16F; *outFormat = GL_RGBA;
*outType = GL_HALF_FLOAT; *outInternalFormat = GL_RGBA16F;
*outType = GL_HALF_FLOAT;
} else {
*outFormat = GL_RGBA;
*outInternalFormat = caches.rgbaInternalFormat(true);
*outType = GL_UNSIGNED_BYTE;
}
break; break;
default: default:
LOG_ALWAYS_FATAL("Unsupported bitmap colorType: %d", colorType); LOG_ALWAYS_FATAL("Unsupported bitmap colorType: %d", colorType);
@@ -244,8 +250,17 @@ SkBitmap Texture::uploadToN32(const SkBitmap& bitmap, bool hasLinearBlending,
rgbaBitmap.allocPixels(SkImageInfo::MakeN32(bitmap.width(), bitmap.height(), rgbaBitmap.allocPixels(SkImageInfo::MakeN32(bitmap.width(), bitmap.height(),
bitmap.info().alphaType(), hasLinearBlending ? sRGB : nullptr)); bitmap.info().alphaType(), hasLinearBlending ? sRGB : nullptr));
rgbaBitmap.eraseColor(0); rgbaBitmap.eraseColor(0);
SkCanvas canvas(rgbaBitmap);
canvas.drawBitmap(bitmap, 0.0f, 0.0f, nullptr); if (bitmap.colorType() == kRGBA_F16_SkColorType) {
// Drawing RGBA_F16 onto ARGB_8888 is not supported
bitmap.readPixels(rgbaBitmap.info()
.makeColorSpace(SkColorSpace::MakeSRGB()),
rgbaBitmap.getPixels(), rgbaBitmap.rowBytes(), 0, 0);
} else {
SkCanvas canvas(rgbaBitmap);
canvas.drawBitmap(bitmap, 0.0f, 0.0f, nullptr);
}
return rgbaBitmap; return rgbaBitmap;
} }
@@ -254,7 +269,9 @@ bool Texture::hasUnsupportedColorType(const SkImageInfo& info, bool hasLinearBle
|| info.colorType() == kIndex_8_SkColorType || info.colorType() == kIndex_8_SkColorType
|| (info.colorType() == kRGB_565_SkColorType || (info.colorType() == kRGB_565_SkColorType
&& hasLinearBlending && hasLinearBlending
&& info.colorSpace()->isSRGB()); && info.colorSpace()->isSRGB())
|| (info.colorType() == kRGBA_F16_SkColorType
&& Caches::getInstance().extensions().getMajorGlVersion() < 3);
} }
void Texture::upload(Bitmap& bitmap) { void Texture::upload(Bitmap& bitmap) {
@@ -287,10 +304,16 @@ void Texture::upload(Bitmap& bitmap) {
colorTypeToGlFormatAndType(mCaches, bitmap.colorType(), colorTypeToGlFormatAndType(mCaches, bitmap.colorType(),
needSRGB && hasLinearBlending, &internalFormat, &format, &type); needSRGB && hasLinearBlending, &internalFormat, &format, &type);
// Some devices don't support GL_RGBA16F, so we need to compare the color type
// and internal GL format to decide what to do with 16 bit bitmaps
bool rgba16fNeedsConversion = bitmap.colorType() == kRGBA_F16_SkColorType
&& internalFormat != GL_RGBA16F;
mConnector.reset(); mConnector.reset();
// RGBA16F is always extended sRGB, alpha masks don't have color profiles // RGBA16F is always extended sRGB, alpha masks don't have color profiles
if (internalFormat != GL_RGBA16F && internalFormat != GL_ALPHA) { // If an RGBA16F bitmap needs conversion, we know the target will be sRGB
if (internalFormat != GL_RGBA16F && internalFormat != GL_ALPHA && !rgba16fNeedsConversion) {
SkColorSpace* colorSpace = bitmap.info().colorSpace(); SkColorSpace* colorSpace = bitmap.info().colorSpace();
// If the bitmap is sRGB we don't need conversion // If the bitmap is sRGB we don't need conversion
if (colorSpace != nullptr && !colorSpace->isSRGB()) { if (colorSpace != nullptr && !colorSpace->isSRGB()) {

View File

@@ -228,7 +228,7 @@ sk_sp<Bitmap> Bitmap::allocateHardwareBitmap(uirenderer::renderthread::RenderThr
bool hasLinearBlending = caches.extensions().hasLinearBlending(); bool hasLinearBlending = caches.extensions().hasLinearBlending();
GLint format, type, internalFormat; GLint format, type, internalFormat;
uirenderer::Texture::colorTypeToGlFormatAndType(caches, skBitmap.colorType(), uirenderer::Texture::colorTypeToGlFormatAndType(caches, skBitmap.colorType(),
needSRGB, &internalFormat, &format, &type); needSRGB && hasLinearBlending, &internalFormat, &format, &type);
PixelFormat pixelFormat = internalFormatToPixelFormat(internalFormat); PixelFormat pixelFormat = internalFormatToPixelFormat(internalFormat);
sp<GraphicBuffer> buffer = new GraphicBuffer(info.width(), info.height(), pixelFormat, sp<GraphicBuffer> buffer = new GraphicBuffer(info.width(), info.height(), pixelFormat,