Add glue to link the GrContext createCompressedBackendTexture API to the GL and Vulkan backends

Bug: skia:9680
Change-Id: I05230ec8fd4f9733ba868fd595b163a79c30d32a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/261081
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2019-12-19 10:16:32 -05:00 committed by Skia Commit-Bot
parent de30e4233f
commit ead321bdfe
7 changed files with 111 additions and 1 deletions

View File

@ -567,6 +567,45 @@ sk_sp<GrTextureProxy> GrProxyProvider::wrapBackendTexture(const GrBackendTexture
new GrTextureProxy(std::move(tex), origin, readSwizzle, UseAllocator::kNo));
}
sk_sp<GrTextureProxy> GrProxyProvider::wrapCompressedBackendTexture(const GrBackendTexture& beTex,
GrSurfaceOrigin origin,
GrWrapOwnership ownership,
GrWrapCacheable cacheable,
ReleaseProc releaseProc,
ReleaseContext releaseCtx) {
if (this->isAbandoned()) {
return nullptr;
}
// This is only supported on a direct GrContext.
GrContext* direct = fImageContext->priv().asDirectContext();
if (!direct) {
return nullptr;
}
GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
sk_sp<GrTexture> tex = resourceProvider->wrapCompressedBackendTexture(beTex, ownership,
cacheable);
if (!tex) {
return nullptr;
}
if (releaseProc) {
tex->setRelease(releaseProc, releaseCtx);
}
SkASSERT(!tex->asRenderTarget()); // Strictly a GrTexture
// Make sure we match how we created the proxy with SkBudgeted::kNo
SkASSERT(GrBudgetedType::kBudgeted != tex->resourcePriv().budgetedType());
// TODO: this will need to be changed for compressed RGBA formats
GrSwizzle texSwizzle = GrSwizzle::RGB1();
return sk_sp<GrTextureProxy>(
new GrTextureProxy(std::move(tex), origin, texSwizzle, UseAllocator::kNo));
}
sk_sp<GrTextureProxy> GrProxyProvider::wrapRenderableBackendTexture(
const GrBackendTexture& backendTex, GrSurfaceOrigin origin, int sampleCnt,
GrColorType colorType, GrWrapOwnership ownership, GrWrapCacheable cacheable,

View File

@ -111,6 +111,11 @@ public:
GrWrapOwnership, GrWrapCacheable, GrIOType,
ReleaseProc = nullptr, ReleaseContext = nullptr);
sk_sp<GrTextureProxy> wrapCompressedBackendTexture(const GrBackendTexture&, GrSurfaceOrigin,
GrWrapOwnership, GrWrapCacheable,
ReleaseProc = nullptr,
ReleaseContext = nullptr);
/*
* Create a texture proxy that wraps a backend texture and is both texture-able and renderable
*/

View File

@ -293,6 +293,18 @@ sk_sp<GrTexture> GrResourceProvider::wrapBackendTexture(const GrBackendTexture&
return fGpu->wrapBackendTexture(tex, colorType, ownership, cacheable, ioType);
}
sk_sp<GrTexture> GrResourceProvider::wrapCompressedBackendTexture(const GrBackendTexture& tex,
GrWrapOwnership ownership,
GrWrapCacheable cacheable) {
ASSERT_SINGLE_OWNER
if (this->isAbandoned()) {
return nullptr;
}
return fGpu->wrapCompressedBackendTexture(tex, ownership, cacheable);
}
sk_sp<GrTexture> GrResourceProvider::wrapRenderableBackendTexture(const GrBackendTexture& tex,
int sampleCnt,
GrColorType colorType,

View File

@ -128,6 +128,10 @@ public:
sk_sp<GrTexture> wrapBackendTexture(const GrBackendTexture& tex, GrColorType, GrWrapOwnership,
GrWrapCacheable, GrIOType);
sk_sp<GrTexture> wrapCompressedBackendTexture(const GrBackendTexture& tex,
GrWrapOwnership,
GrWrapCacheable);
/**
* This makes the backend texture be renderable. If sampleCnt is > 1 and the underlying API
* uses separate MSAA render buffers then a MSAA render buffer is created that resolves

View File

@ -147,7 +147,27 @@ sk_sp<SkImage> SkImage::MakeFromCompressedTexture(GrContext* ctx,
sk_sp<SkColorSpace> cs,
TextureReleaseProc releaseP,
ReleaseContext releaseC) {
return nullptr;
if (!ctx) {
return nullptr;
}
const GrCaps* caps = ctx->priv().caps();
if (!SkImage_GpuBase::ValidateCompressedBackendTexture(caps, tex, at)) {
return nullptr;
}
GrProxyProvider* proxyProvider = ctx->priv().proxyProvider();
sk_sp<GrTextureProxy> proxy =
proxyProvider->wrapCompressedBackendTexture(tex, origin, kBorrow_GrWrapOwnership,
GrWrapCacheable::kNo, releaseP, releaseC);
if (!proxy) {
return nullptr;
}
GrSurfaceProxyView view(std::move(proxy), origin, GrSwizzle::RGBA());
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, at, std::move(view),
std::move(cs));
}
sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx,

View File

@ -57,6 +57,34 @@ bool SkImage_GpuBase::ValidateBackendTexture(const GrCaps* caps, const GrBackend
return caps->areColorTypeAndFormatCompatible(grCT, backendFormat);
}
bool SkImage_GpuBase::ValidateCompressedBackendTexture(const GrCaps* caps,
const GrBackendTexture& tex,
SkAlphaType at) {
if (!tex.isValid() || tex.width() <= 0 || tex.height() <= 0) {
return false;
}
if (tex.width() > caps->maxTextureSize() || tex.height() > caps->maxTextureSize()) {
return false;
}
if (at == kUnknown_SkAlphaType) {
return false;
}
GrBackendFormat backendFormat = tex.getBackendFormat();
if (!backendFormat.isValid()) {
return false;
}
if (!caps->isFormatCompressed(backendFormat)) {
return false;
}
return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
bool SkImage_GpuBase::getROPixels(SkBitmap* dst, CachingHint chint) const {

View File

@ -59,6 +59,8 @@ public:
static bool ValidateBackendTexture(const GrCaps*, const GrBackendTexture& tex,
GrColorType grCT, SkColorType ct, SkAlphaType at,
sk_sp<SkColorSpace> cs);
static bool ValidateCompressedBackendTexture(const GrCaps*, const GrBackendTexture& tex,
SkAlphaType);
static bool MakeTempTextureProxies(GrContext* ctx, const GrBackendTexture yuvaTextures[],
int numTextures, const SkYUVAIndex [4],
GrSurfaceOrigin imageOrigin,