Fix extra texture creation in GrResourceProvider::createTexture() with SRGB data.
We would make a temporary surface context around a scratch texture with a SRGB color space and then attempt writePixels with a src SkImageInfo with no color space. Then we'd fall back to creating a texture with initial data. Now we will make the src SkImageInfo have a SRGB color space and then assume success. Bug: b/78866720 Change-Id: I541a3b73c72f610533cfbc6892b2782c90e5121d Reviewed-on: https://skia-review.googlesource.com/127130 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
parent
d813f9cdc7
commit
1fcac05569
@ -95,16 +95,6 @@ sk_sp<GrTexture> GrResourceProvider::getExactScratch(const GrSurfaceDesc& desc,
|
||||
return tex;
|
||||
}
|
||||
|
||||
static bool make_info(int w, int h, GrPixelConfig config, SkImageInfo* ii) {
|
||||
SkColorType colorType;
|
||||
if (!GrPixelConfigToColorType(config, &colorType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*ii = SkImageInfo::Make(w, h, colorType, kUnknown_SkAlphaType, nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
sk_sp<GrTexture> GrResourceProvider::createTexture(const GrSurfaceDesc& desc,
|
||||
SkBudgeted budgeted,
|
||||
SkBackingFit fit,
|
||||
@ -126,34 +116,36 @@ sk_sp<GrTexture> GrResourceProvider::createTexture(const GrSurfaceDesc& desc,
|
||||
GrContext* context = fGpu->getContext();
|
||||
GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
|
||||
|
||||
SkImageInfo srcInfo;
|
||||
|
||||
if (make_info(desc.fWidth, desc.fHeight, desc.fConfig, &srcInfo)) {
|
||||
SkColorType colorType;
|
||||
if (GrPixelConfigToColorType(desc.fConfig, &colorType)) {
|
||||
// DDL TODO: remove this use of createInstantiatedProxy and convert it to a testing-only
|
||||
// method.
|
||||
sk_sp<GrTextureProxy> proxy = proxyProvider->createInstantiatedProxy(
|
||||
desc, kTopLeft_GrSurfaceOrigin, fit, budgeted);
|
||||
if (proxy) {
|
||||
// We use an ephemeral surface context to do the write pixels. Here it isn't clear what
|
||||
// color space to tag it with. That's ok because GrSurfaceContext::writePixels doesn't
|
||||
// do any color space conversions. Though, that is likely to change. However, if the
|
||||
// pixel config is sRGB then the passed color space here must have sRGB gamma or
|
||||
// GrSurfaceContext creation fails.
|
||||
sk_sp<SkColorSpace> colorSpace;
|
||||
if (GrPixelConfigIsSRGB(desc.fConfig)) {
|
||||
colorSpace = SkColorSpace::MakeSRGB();
|
||||
}
|
||||
sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext(
|
||||
std::move(proxy), std::move(colorSpace));
|
||||
if (sContext) {
|
||||
if (sContext->writePixels(srcInfo, mipLevel.fPixels, mipLevel.fRowBytes, 0, 0)) {
|
||||
return sk_ref_sp(sContext->asTextureProxy()->priv().peekTexture());
|
||||
}
|
||||
}
|
||||
if (!proxy) {
|
||||
return nullptr;
|
||||
}
|
||||
// We use an ephemeral surface context to do the write pixels. Here it isn't clear what
|
||||
// color space to tag it with. That's ok because GrSurfaceContext::writePixels doesn't
|
||||
// do any color space conversions. Though, that is likely to change. However, if the
|
||||
// pixel config is sRGB then the passed color space here must have sRGB gamma or
|
||||
// GrSurfaceContext creation fails.
|
||||
sk_sp<SkColorSpace> colorSpace;
|
||||
if (GrPixelConfigIsSRGB(desc.fConfig)) {
|
||||
colorSpace = SkColorSpace::MakeSRGB();
|
||||
}
|
||||
auto srcInfo = SkImageInfo::Make(desc.fWidth, desc.fHeight, colorType,
|
||||
kUnknown_SkAlphaType, colorSpace);
|
||||
sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext(
|
||||
std::move(proxy), std::move(colorSpace));
|
||||
if (!sContext) {
|
||||
return nullptr;
|
||||
}
|
||||
SkAssertResult(sContext->writePixels(srcInfo, mipLevel.fPixels, mipLevel.fRowBytes, 0, 0));
|
||||
return sk_ref_sp(sContext->asTextureProxy()->priv().peekTexture());
|
||||
} else {
|
||||
return fGpu->createTexture(desc, budgeted, &mipLevel, 1);
|
||||
}
|
||||
|
||||
return fGpu->createTexture(desc, budgeted, &mipLevel, 1);
|
||||
}
|
||||
|
||||
sk_sp<GrTexture> GrResourceProvider::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
|
||||
|
Loading…
Reference in New Issue
Block a user