diff options
author | Brian Osman <brianosman@google.com> | 2018-01-04 09:35:04 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-01-04 15:10:09 +0000 |
commit | 9d44081e00f67361414935b82332df5754bddcaf (patch) | |
tree | 5a02e75c56e441dbbb93633751ab8e2cb7dc7d22 | |
parent | e463d985587389970d6dbe87967c3cedefa9b8e4 (diff) |
Remove conversion to 8888 of sRGB sources with other configs
Our color space xform code now handles applying the transfer function in
the shader if there's a mismatch between the pixel config and the color
space, so this logic is no longer needed. Although it may produce
slightly less accurate filtering, the tradeoff of (for example)
expanding grayscale bitmaps by a factor of four, on the off chance that
we'll draw them to a color managed destination isn't worth it.
Bug: skia:
Change-Id: Ic56e7d48301cd7cbb0d5bccd17cfd383786f98e5
Reviewed-on: https://skia-review.googlesource.com/90901
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
-rw-r--r-- | src/gpu/SkGr.cpp | 76 |
1 files changed, 9 insertions, 67 deletions
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index e95bf341b4..77112fb3e1 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -78,48 +78,6 @@ sk_sp<GrTextureProxy> GrUploadBitmapToTextureProxy(GrResourceProvider* resourceP return GrUploadPixmapToTextureProxy(resourceProvider, pixmap, SkBudgeted::kYes, dstColorSpace); } -static const SkPixmap* compute_desc(const GrCaps& caps, const SkPixmap& pixmap, - GrSurfaceDesc* desc, - SkBitmap* tmpBitmap, SkPixmap* tmpPixmap) { - const SkPixmap* pmap = &pixmap; - - *desc = GrImageInfoToSurfaceDesc(pixmap.info(), caps); - - // TODO: We're checking for srgbSupport, but we can then end up picking sBGRA as our pixel - // config (which may not be supported). We need better fallback management here. - SkColorSpace* colorSpace = pixmap.colorSpace(); - - if (caps.srgbSupport() && - colorSpace && colorSpace->gammaCloseToSRGB() && !GrPixelConfigIsSRGB(desc->fConfig)) { - // We were supplied an sRGB-like color space, but we don't have a suitable pixel config. - // Convert to 8888 sRGB so we can handle the data correctly. The raster backend doesn't - // handle sRGB Index8 -> sRGB 8888 correctly (yet), so lie about both the source and - // destination (claim they're linear): - SkImageInfo linSrcInfo = SkImageInfo::Make(pixmap.width(), pixmap.height(), - pixmap.colorType(), pixmap.alphaType()); - SkPixmap linSrcPixmap(linSrcInfo, pixmap.addr(), pixmap.rowBytes()); - - SkImageInfo dstInfo = SkImageInfo::Make(pixmap.width(), pixmap.height(), - kN32_SkColorType, kPremul_SkAlphaType, - pixmap.info().refColorSpace()); - - tmpBitmap->allocPixels(dstInfo); - - SkImageInfo linDstInfo = SkImageInfo::MakeN32Premul(pixmap.width(), pixmap.height()); - if (!linSrcPixmap.readPixels(linDstInfo, tmpBitmap->getPixels(), tmpBitmap->rowBytes())) { - return nullptr; - } - if (!tmpBitmap->peekPixels(tmpPixmap)) { - return nullptr; - } - pmap = tmpPixmap; - // must rebuild desc, since we've forced the info to be N32 - *desc = GrImageInfoToSurfaceDesc(pmap->info(), caps); - } - - return pmap; -} - sk_sp<GrTextureProxy> GrUploadPixmapToTextureProxy(GrResourceProvider* resourceProvider, const SkPixmap& pixmap, SkBudgeted budgeted, @@ -132,18 +90,10 @@ sk_sp<GrTextureProxy> GrUploadPixmapToTextureProxy(GrResourceProvider* resourceP return nullptr; } - SkBitmap tmpBitmap; - SkPixmap tmpPixmap; - GrSurfaceDesc desc; - ATRACE_ANDROID_FRAMEWORK("Upload Texture [%ux%u]", pixmap.width(), pixmap.height()); - if (const SkPixmap* pmap = compute_desc(*resourceProvider->caps(), pixmap, &desc, - &tmpBitmap, &tmpPixmap)) { - return GrSurfaceProxy::MakeDeferred(resourceProvider, desc, - budgeted, pmap->addr(), pmap->rowBytes()); - } - - return nullptr; + GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(pixmap.info(), *resourceProvider->caps()); + return GrSurfaceProxy::MakeDeferred(resourceProvider, desc, budgeted, pixmap.addr(), + pixmap.rowBytes()); } //////////////////////////////////////////////////////////////////////////////// @@ -177,17 +127,9 @@ sk_sp<GrTextureProxy> GrGenerateMipMapsAndUploadToTextureProxy(GrContext* ctx, return nullptr; } - SkBitmap tmpBitmap; - SkPixmap tmpPixmap; - GrSurfaceDesc desc; - const SkPixmap* pmap = compute_desc(*ctx->resourceProvider()->caps(), pixmap, &desc, - &tmpBitmap, &tmpPixmap); - if (!pmap) { - return nullptr; - } - ATRACE_ANDROID_FRAMEWORK("Upload MipMap Texture [%ux%u]", pmap->width(), pmap->height()); - std::unique_ptr<SkMipMap> mipmaps(SkMipMap::Build(*pmap, colorMode, nullptr)); + GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(pixmap.info(), *ctx->resourceProvider()->caps()); + std::unique_ptr<SkMipMap> mipmaps(SkMipMap::Build(pixmap, colorMode, nullptr)); if (!mipmaps) { return nullptr; } @@ -199,8 +141,8 @@ sk_sp<GrTextureProxy> GrGenerateMipMapsAndUploadToTextureProxy(GrContext* ctx, std::unique_ptr<GrMipLevel[]> texels(new GrMipLevel[mipLevelCount]); - texels[0].fPixels = pmap->addr(); - texels[0].fRowBytes = pmap->rowBytes(); + texels[0].fPixels = pixmap.addr(); + texels[0].fRowBytes = pixmap.rowBytes(); for (int i = 1; i < mipLevelCount; ++i) { SkMipMap::Level generatedMipLevel; @@ -335,8 +277,6 @@ GrColor4f SkColorToUnpremulGrColor4f(SkColor c, const GrColorSpaceInfo& colorSpa GrPixelConfig SkImageInfo2GrPixelConfig(const SkColorType type, SkColorSpace* cs, const GrCaps& caps) { - // We intentionally ignore profile type for non-8888 formats. Anything we can't support - // in hardware will be expanded to sRGB 8888 in GrUploadPixmapToTexture. switch (type) { case kUnknown_SkColorType: return kUnknown_GrPixelConfig; @@ -349,6 +289,8 @@ GrPixelConfig SkImageInfo2GrPixelConfig(const SkColorType type, SkColorSpace* cs case kRGBA_8888_SkColorType: return (caps.srgbSupport() && cs && cs->gammaCloseToSRGB()) ? kSRGBA_8888_GrPixelConfig : kRGBA_8888_GrPixelConfig; + // TODO: We're checking for srgbSupport, but we can then end up picking sBGRA as our pixel + // config (which may not be supported). We need a better test here. case kBGRA_8888_SkColorType: return (caps.srgbSupport() && cs && cs->gammaCloseToSRGB()) ? kSBGRA_8888_GrPixelConfig : kBGRA_8888_GrPixelConfig; |