Simplify code in GrResourceProvider now that GrSurfaceContext writePixels takes GrColorType

Change-Id: I3e4cd49d59d38b8c278b7667ad3968b116b58ad6
Bug: skia:6718
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/227260
Auto-Submit: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2019-07-13 17:48:58 -04:00 committed by Skia Commit-Bot
parent 563d044c0e
commit a495d6d985

View File

@ -144,36 +144,30 @@ sk_sp<GrTexture> GrResourceProvider::createTexture(const GrSurfaceDesc& desc,
return nullptr;
}
SkColorType colorType;
if (GrPixelConfigToColorType(desc.fConfig, &colorType)) {
sk_sp<GrTexture> tex = (SkBackingFit::kApprox == fit)
? this->createApproxTexture(desc, flags)
: this->createTexture(desc, budgeted, flags);
if (!tex) {
return nullptr;
}
sk_sp<GrTextureProxy> proxy = proxyProvider->createWrapped(std::move(tex),
kTopLeft_GrSurfaceOrigin);
if (!proxy) {
return nullptr;
}
// Here we don't really know the alpha type of the data we want to upload. All we really
// care about is that it is not converted. So we use the same alpha type of the data
// and the surface context.
static constexpr auto kAlphaType = kPremul_SkAlphaType;
auto srcInfo = SkImageInfo::Make(desc.fWidth, desc.fHeight, colorType, kAlphaType);
sk_sp<GrSurfaceContext> sContext = context->priv().makeWrappedSurfaceContext(
std::move(proxy), SkColorTypeToGrColorType(colorType), kAlphaType);
if (!sContext) {
return nullptr;
}
SkAssertResult(
sContext->writePixels(srcInfo, tmpLevel.fPixels, tmpLevel.fRowBytes, {0, 0}));
return sk_ref_sp(sContext->asTextureProxy()->peekTexture());
} else {
return fGpu->createTexture(desc, budgeted, &tmpLevel, 1);
GrColorType colorType = GrPixelConfigToColorType(desc.fConfig);
sk_sp<GrTexture> tex = (SkBackingFit::kApprox == fit)
? this->createApproxTexture(desc, flags)
: this->createTexture(desc, budgeted, flags);
if (!tex) {
return nullptr;
}
sk_sp<GrTextureProxy> proxy = proxyProvider->createWrapped(tex, kTopLeft_GrSurfaceOrigin);
if (!proxy) {
return nullptr;
}
// Here we don't really know the alpha type of the data we want to upload. All we really
// care about is that it is not converted. So we use the same alpha type for the data
// and the surface context.
static constexpr auto kAlphaType = kPremul_SkAlphaType;
sk_sp<GrSurfaceContext> sContext =
context->priv().makeWrappedSurfaceContext(std::move(proxy), colorType, kAlphaType);
if (!sContext) {
return nullptr;
}
GrPixelInfo srcInfo(colorType, kAlphaType, nullptr, desc.fWidth, desc.fHeight);
SkAssertResult(sContext->writePixels(srcInfo, tmpLevel.fPixels, tmpLevel.fRowBytes, {0, 0}));
return tex;
}
sk_sp<GrTexture> GrResourceProvider::createCompressedTexture(int width, int height,