Skip to content

Commit

Permalink
Pass GrColorType to the GrGpu::wrapRenderableBackendTexture chain of …
Browse files Browse the repository at this point in the history
…calls (take 2)

This is a step towards reducing our reliance-on/use-of the GrPixelConfig stored in the GrBackendTexture.

[email protected]
Bug: skia:6718
Change-Id: I316a98416c51f273e6ab578f9cbaea5f7adfe331
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/227639
Reviewed-by: Robert Phillips <[email protected]>
Commit-Queue: Robert Phillips <[email protected]>
  • Loading branch information
rphilli authored and Skia Commit-Bot committed Jul 16, 2019
1 parent c8e8e70 commit 0902c98
Show file tree
Hide file tree
Showing 24 changed files with 195 additions and 59 deletions.
40 changes: 40 additions & 0 deletions src/gpu/GrCaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,43 @@ GrCaps::SupportedRead GrCaps::supportedReadPixelsColorType(GrPixelConfig config,
GrColorType dstColorType) const {
return SupportedRead{GrSwizzle::RGBA(), GrPixelConfigToColorType(config)};
}

#ifdef SK_DEBUG
bool GrCaps::AreConfigsCompatible(GrPixelConfig genericConfig, GrPixelConfig specificConfig) {
bool compatible = false;

switch (genericConfig) {
case kAlpha_8_GrPixelConfig:
compatible = kAlpha_8_GrPixelConfig == specificConfig || // here bc of the mock context
kAlpha_8_as_Alpha_GrPixelConfig == specificConfig ||
kAlpha_8_as_Red_GrPixelConfig == specificConfig;
break;
case kGray_8_GrPixelConfig:
compatible = kGray_8_GrPixelConfig == specificConfig || // here bc of the mock context
kGray_8_as_Lum_GrPixelConfig == specificConfig ||
kGray_8_as_Red_GrPixelConfig == specificConfig;
break;
case kAlpha_half_GrPixelConfig:
compatible = kAlpha_half_GrPixelConfig == specificConfig || // bc of the mock context
kAlpha_half_as_Red_GrPixelConfig == specificConfig;
break;
case kRGB_888_GrPixelConfig:
compatible = kRGB_888_GrPixelConfig == specificConfig ||
kRGB_888X_GrPixelConfig == specificConfig;
break;
case kRGBA_8888_GrPixelConfig:
compatible = kRGBA_8888_GrPixelConfig == specificConfig ||
kBGRA_8888_GrPixelConfig == specificConfig;
break;
default:
compatible = genericConfig == specificConfig;
break;
}

if (!compatible) {
SkDebugf("Configs are not compatible: %d %d\n", genericConfig, specificConfig);
}

return compatible;
}
#endif
7 changes: 7 additions & 0 deletions src/gpu/GrCaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,13 @@ class GrCaps : public SkRefCnt {

const GrDriverBugWorkarounds& workarounds() const { return fDriverBugWorkarounds; }

#ifdef SK_DEBUG
// This is just a debugging entry point until we're weaned off of GrPixelConfig. It
// should be used to verify that the pixel config from user-level code (the genericConfig)
// is compatible with a pixel config we've computed from scratch (the specificConfig).
static bool AreConfigsCompatible(GrPixelConfig genericConfig, GrPixelConfig specificConfig);
#endif

protected:
/** Subclasses must call this at the end of their constructors in order to apply caps
overrides requested by the client. Note that overrides will only reduce the caps never
Expand Down
4 changes: 2 additions & 2 deletions src/gpu/GrContextPriv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureRenderTargetContex
SkASSERT(sampleCnt > 0);

sk_sp<GrTextureProxy> proxy(this->proxyProvider()->wrapRenderableBackendTexture(
tex, origin, sampleCnt, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, releaseProc,
releaseCtx));
tex, origin, sampleCnt, colorType, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
releaseProc, releaseCtx));
if (!proxy) {
return nullptr;
}
Expand Down
23 changes: 16 additions & 7 deletions src/gpu/GrGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,23 +230,32 @@ sk_sp<GrTexture> GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex,
}

sk_sp<GrTexture> GrGpu::wrapRenderableBackendTexture(const GrBackendTexture& backendTex,
int sampleCnt, GrWrapOwnership ownership,
int sampleCnt, GrColorType colorType,
GrWrapOwnership ownership,
GrWrapCacheable cacheable) {
this->handleDirtyContext();
if (sampleCnt < 1) {
return nullptr;
}
if (!this->caps()->isConfigTexturable(backendTex.config()) ||
!this->caps()->getRenderTargetSampleCount(sampleCnt, backendTex.config())) {

const GrCaps* caps = this->caps();

SkASSERT(GrCaps::AreConfigsCompatible(backendTex.config(),
caps->getConfigFromBackendFormat(
backendTex.getBackendFormat(),
colorType)));

if (!caps->isFormatTexturable(colorType, backendTex.getBackendFormat()) ||
!caps->getRenderTargetSampleCount(sampleCnt, colorType, backendTex.getBackendFormat())) {
return nullptr;
}

if (backendTex.width() > this->caps()->maxRenderTargetSize() ||
backendTex.height() > this->caps()->maxRenderTargetSize()) {
if (backendTex.width() > caps->maxRenderTargetSize() ||
backendTex.height() > caps->maxRenderTargetSize()) {
return nullptr;
}
sk_sp<GrTexture> tex =
this->onWrapRenderableBackendTexture(backendTex, sampleCnt, ownership, cacheable);
sk_sp<GrTexture> tex = this->onWrapRenderableBackendTexture(backendTex, sampleCnt, colorType,
ownership, cacheable);
SkASSERT(!tex || tex->asRenderTarget());
return tex;
}
Expand Down
5 changes: 3 additions & 2 deletions src/gpu/GrGpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class GrGpu : public SkRefCnt {
* Implements GrResourceProvider::wrapRenderableBackendTexture
*/
sk_sp<GrTexture> wrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
GrWrapOwnership, GrWrapCacheable);
GrColorType, GrWrapOwnership, GrWrapCacheable);

/**
* Implements GrResourceProvider::wrapBackendRenderTarget
Expand Down Expand Up @@ -527,7 +527,8 @@ class GrGpu : public SkRefCnt {
virtual sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership,
GrWrapCacheable, GrIOType) = 0;
virtual sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
GrWrapOwnership, GrWrapCacheable) = 0;
GrColorType, GrWrapOwnership,
GrWrapCacheable) = 0;
virtual sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) = 0;
virtual sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
int sampleCnt) = 0;
Expand Down
52 changes: 33 additions & 19 deletions src/gpu/GrProxyProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,12 @@ static bool validate_backend_format_and_config(const GrCaps* caps,

return caps->areColorTypeAndFormatCompatible(grCT, format);
}

static bool validate_backend_format_and_colortype(const GrCaps* caps,
GrColorType colorType,
const GrBackendFormat& format) {
return caps->areColorTypeAndFormatCompatible(colorType, format);
}
#endif

sk_sp<GrTextureProxy> GrProxyProvider::createProxy(const GrBackendFormat& format,
Expand All @@ -431,11 +437,17 @@ sk_sp<GrTextureProxy> GrProxyProvider::createProxy(const GrBackendFormat& format
SkBackingFit fit,
SkBudgeted budgeted,
GrInternalSurfaceFlags surfaceFlags) {
SkASSERT(validate_backend_format_and_config(this->caps(), format, desc.fConfig));
if (GrPixelConfigIsCompressed(desc.fConfig)) {
// Deferred proxies for compressed textures are not supported.
return nullptr;
}

const GrCaps* caps = this->caps();
GrColorType colorType = GrPixelConfigToColorType(desc.fConfig);

SkASSERT(GrCaps::AreConfigsCompatible(desc.fConfig,
caps->getConfigFromBackendFormat(format, colorType)));
SkASSERT(validate_backend_format_and_colortype(caps, colorType, format));
if (GrMipMapped::kYes == mipMapped) {
// SkMipMap doesn't include the base level in the level count so we have to add 1
int mipCount = SkMipMap::ComputeLevelCount(desc.fWidth, desc.fHeight) + 1;
Expand All @@ -444,23 +456,21 @@ sk_sp<GrTextureProxy> GrProxyProvider::createProxy(const GrBackendFormat& format
}
}

if (!this->caps()->validateSurfaceDesc(desc, mipMapped)) {
if (!caps->validateSurfaceDesc(desc, mipMapped)) {
return nullptr;
}
GrSurfaceDesc copyDesc = desc;
if (desc.fFlags & kRenderTarget_GrSurfaceFlag) {
copyDesc.fSampleCnt =
this->caps()->getRenderTargetSampleCount(desc.fSampleCnt, desc.fConfig);
copyDesc.fSampleCnt = caps->getRenderTargetSampleCount(desc.fSampleCnt, colorType, format);
}

GrColorType colorType = GrPixelConfigToColorType(desc.fConfig);
GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(format, colorType);
GrSwizzle texSwizzle = caps->getTextureSwizzle(format, colorType);

if (copyDesc.fFlags & kRenderTarget_GrSurfaceFlag) {
// We know anything we instantiate later from this deferred path will be
// both texturable and renderable
GrSwizzle outSwizzle = this->caps()->getOutputSwizzle(format, colorType);
return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(*this->caps(), format, copyDesc,
GrSwizzle outSwizzle = caps->getOutputSwizzle(format, colorType);
return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(*caps, format, copyDesc,
origin, mipMapped, texSwizzle,
outSwizzle, fit, budgeted,
surfaceFlags));
Expand Down Expand Up @@ -526,10 +536,8 @@ sk_sp<GrTextureProxy> GrProxyProvider::wrapBackendTexture(const GrBackendTexture
return nullptr;
}

#ifdef SK_DEBUG
SkASSERT(validate_backend_format_and_config(this->caps(), backendTex.getBackendFormat(),
backendTex.config()));
#endif

GrResourceProvider* resourceProvider = direct->priv().resourceProvider();

Expand All @@ -555,8 +563,8 @@ sk_sp<GrTextureProxy> GrProxyProvider::wrapBackendTexture(const GrBackendTexture

sk_sp<GrTextureProxy> GrProxyProvider::wrapRenderableBackendTexture(
const GrBackendTexture& backendTex, GrSurfaceOrigin origin, int sampleCnt,
GrWrapOwnership ownership, GrWrapCacheable cacheable, ReleaseProc releaseProc,
ReleaseContext releaseCtx) {
GrColorType colorType, GrWrapOwnership ownership, GrWrapCacheable cacheable,
ReleaseProc releaseProc, ReleaseContext releaseCtx) {
if (this->isAbandoned()) {
return nullptr;
}
Expand All @@ -567,18 +575,25 @@ sk_sp<GrTextureProxy> GrProxyProvider::wrapRenderableBackendTexture(
return nullptr;
}

SkASSERT(validate_backend_format_and_config(this->caps(), backendTex.getBackendFormat(),
backendTex.config()));
const GrCaps* caps = this->caps();

SkASSERT(GrCaps::AreConfigsCompatible(backendTex.config(),
caps->getConfigFromBackendFormat(
backendTex.getBackendFormat(),
colorType)));
SkASSERT(validate_backend_format_and_colortype(caps, colorType, backendTex.getBackendFormat()));

GrResourceProvider* resourceProvider = direct->priv().resourceProvider();

sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, backendTex.config());
sampleCnt = caps->getRenderTargetSampleCount(sampleCnt, colorType,
backendTex.getBackendFormat());
if (!sampleCnt) {
return nullptr;
}

sk_sp<GrTexture> tex = resourceProvider->wrapRenderableBackendTexture(backendTex, sampleCnt,
ownership, cacheable);
colorType, ownership,
cacheable);
if (!tex) {
return nullptr;
}
Expand All @@ -591,9 +606,8 @@ sk_sp<GrTextureProxy> GrProxyProvider::wrapRenderableBackendTexture(
// Make sure we match how we created the proxy with SkBudgeted::kNo
SkASSERT(GrBudgetedType::kBudgeted != tex->resourcePriv().budgetedType());

GrColorType colorType = GrPixelConfigToColorType(tex->config());
GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(tex->backendFormat(), colorType);
GrSwizzle outSwizzle = this->caps()->getOutputSwizzle(tex->backendFormat(), colorType);
GrSwizzle texSwizzle = caps->getTextureSwizzle(tex->backendFormat(), colorType);
GrSwizzle outSwizzle = caps->getOutputSwizzle(tex->backendFormat(), colorType);

return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(std::move(tex), origin, texSwizzle,
outSwizzle));
Expand Down
5 changes: 3 additions & 2 deletions src/gpu/GrProxyProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ class GrProxyProvider {
* Create a texture proxy that wraps a backend texture and is both texture-able and renderable
*/
sk_sp<GrTextureProxy> wrapRenderableBackendTexture(const GrBackendTexture&, GrSurfaceOrigin,
int sampleCnt, GrWrapOwnership,
GrWrapCacheable, ReleaseProc = nullptr,
int sampleCnt, GrColorType,
GrWrapOwnership, GrWrapCacheable,
ReleaseProc = nullptr,
ReleaseContext = nullptr);

/*
Expand Down
3 changes: 2 additions & 1 deletion src/gpu/GrResourceProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,14 @@ sk_sp<GrTexture> GrResourceProvider::wrapBackendTexture(const GrBackendTexture&

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

sk_sp<GrRenderTarget> GrResourceProvider::wrapBackendRenderTarget(
Expand Down
1 change: 1 addition & 0 deletions src/gpu/GrResourceProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class GrResourceProvider {
*/
sk_sp<GrTexture> wrapRenderableBackendTexture(const GrBackendTexture& tex,
int sampleCnt,
GrColorType,
GrWrapOwnership,
GrWrapCacheable);

Expand Down
4 changes: 2 additions & 2 deletions src/gpu/gl/GrGLCaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3775,7 +3775,7 @@ GrGLFormat GrGLCaps::pixelConfigToFormat(GrPixelConfig config) const {
}

// A near clone of format_color_type_valid_pair
GrPixelConfig validate_sized_format(GrGLenum format, GrColorType ct, GrGLStandard standard) {
static GrPixelConfig validate_sized_format(GrGLenum format, GrColorType ct, GrGLStandard standard) {
switch (ct) {
case GrColorType::kUnknown:
return kUnknown_GrPixelConfig;
Expand Down Expand Up @@ -3843,7 +3843,7 @@ GrPixelConfig validate_sized_format(GrGLenum format, GrColorType ct, GrGLStandar
break;
case GrColorType::kAlpha_F16:
if (GR_GL_R16F == format) {
return kAlpha_half_GrPixelConfig;
return kAlpha_half_as_Red_GrPixelConfig;
}
break;
case GrColorType::kRGBA_F16:
Expand Down
6 changes: 5 additions & 1 deletion src/gpu/gl/GrGLGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ sk_sp<GrTexture> GrGLGpu::onWrapBackendTexture(const GrBackendTexture& backendTe

sk_sp<GrTexture> GrGLGpu::onWrapRenderableBackendTexture(const GrBackendTexture& backendTex,
int sampleCnt,
GrColorType colorType,
GrWrapOwnership ownership,
GrWrapCacheable cacheable) {
GrGLTexture::IDDesc idDesc;
Expand All @@ -735,12 +736,15 @@ sk_sp<GrTexture> GrGLGpu::onWrapRenderableBackendTexture(const GrBackendTexture&
idDesc.fOwnership = GrBackendObjectOwnership::kOwned;
}

const GrCaps* caps = this->caps();

GrSurfaceDesc surfDesc;
surfDesc.fFlags = kRenderTarget_GrSurfaceFlag;
surfDesc.fWidth = backendTex.width();
surfDesc.fHeight = backendTex.height();
surfDesc.fConfig = backendTex.config();
surfDesc.fSampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, backendTex.config());
surfDesc.fSampleCnt = caps->getRenderTargetSampleCount(sampleCnt, colorType,
backendTex.getBackendFormat());
if (surfDesc.fSampleCnt < 1) {
return nullptr;
}
Expand Down
3 changes: 2 additions & 1 deletion src/gpu/gl/GrGLGpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ class GrGLGpu final : public GrGpu, private GrMesh::SendToGpuImpl {
sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable,
GrIOType) override;
sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
GrWrapOwnership, GrWrapCacheable) override;
GrColorType, GrWrapOwnership,
GrWrapCacheable) override;
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
int sampleCnt) override;
Expand Down
2 changes: 2 additions & 0 deletions src/gpu/mock/GrMockGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,13 @@ sk_sp<GrTexture> GrMockGpu::onWrapBackendTexture(const GrBackendTexture& tex,

sk_sp<GrTexture> GrMockGpu::onWrapRenderableBackendTexture(const GrBackendTexture& tex,
int sampleCnt,
GrColorType colorType,
GrWrapOwnership ownership,
GrWrapCacheable cacheable) {
GrMockTextureInfo texInfo;
SkAssertResult(tex.getMockTextureInfo(&texInfo));

SkASSERT(colorType == texInfo.fColorType);
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fWidth = tex.width();
Expand Down
1 change: 1 addition & 0 deletions src/gpu/mock/GrMockGpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class GrMockGpu : public GrGpu {

sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
int sampleCnt,
GrColorType,
GrWrapOwnership,
GrWrapCacheable) override;

Expand Down
3 changes: 2 additions & 1 deletion src/gpu/mtl/GrMtlGpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ class GrMtlGpu : public GrGpu {
GrIOType) override;

sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
GrWrapOwnership, GrWrapCacheable) override;
GrColorType, GrWrapOwnership,
GrWrapCacheable) override;

sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;

Expand Down
Loading

0 comments on commit 0902c98

Please sign in to comment.