Reland "Reland "Have a GrBackendFormat be stored on gpu proxies.""
This is a reland of 2f9a5ea639925f38785f4d3a0af237822007cfd6
Original change's description:
> Reland "Have a GrBackendFormat be stored on gpu proxies."
>
> This reverts commit 919c9e77c3492af766ff5982acda76ee49da3168.
>
> Reason for revert: Flutter change has landed and fixed memory issue.
>
> Original change's description:
> > Revert "Have a GrBackendFormat be stored on gpu proxies."
> >
> > This reverts commit 51b1c12bbc2fa3f8d4faa29ad19c6f3cb34837ce.
> >
> > Reason for revert: reverting till flutter gets to 1.1 to fix build issues.
> >
> > Original change's description:
> > > Have a GrBackendFormat be stored on gpu proxies.
> > >
> > > Bug: skia:
> > > Change-Id: Iaf1fb24ab29a61d44e5fa59a5e0867ed02dcda90
> > > Reviewed-on: https://skia-review.googlesource.com/c/168021
> > > Reviewed-by: Brian Osman <brianosman@google.com>
> > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> >
> > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com
> >
> > Change-Id: I574fdc084ef5994596c51fb0d60423b5dc01b885
> > No-Presubmit: true
> > No-Tree-Checks: true
> > No-Try: true
> > Bug: chromium:903701 chromium:903756
> > Reviewed-on: https://skia-review.googlesource.com/c/169835
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Greg Daniel <egdaniel@google.com>
>
> TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com
>
> Change-Id: Ifd9b6b8e194af9fb9258fa626644e76e6ecf090d
> Bug: chromium:903701 chromium:903756
> Reviewed-on: https://skia-review.googlesource.com/c/170104
> Commit-Queue: Greg Daniel <egdaniel@google.com>
> Reviewed-by: Greg Daniel <egdaniel@google.com>
> Reviewed-by: Brian Osman <brianosman@google.com>
Bug: chromium:903701 chromium:903756
Change-Id: Id1360067d8e928b0a4e1848dae8bc1e7f1994403
Reviewed-on: https://skia-review.googlesource.com/c/171660
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/src/core/SkDeferredDisplayListRecorder.cpp b/src/core/SkDeferredDisplayListRecorder.cpp
index 9d5f17a..6cb7126 100644
--- a/src/core/SkDeferredDisplayListRecorder.cpp
+++ b/src/core/SkDeferredDisplayListRecorder.cpp
@@ -145,6 +145,9 @@
optionalTextureInfo = &kTextureInfo;
}
+ const GrBackendFormat format = fContext->contextPriv().caps()->getBackendFormatFromColorType(
+ fCharacterization.colorType());
+
sk_sp<GrRenderTargetProxy> proxy = proxyProvider->createLazyRenderTargetProxy(
[lazyProxyData](GrResourceProvider* resourceProvider) {
if (!resourceProvider) {
@@ -156,6 +159,7 @@
SkASSERT(lazyProxyData->fReplayDest->peekSurface());
return sk_ref_sp<GrSurface>(lazyProxyData->fReplayDest->peekSurface());
},
+ format,
desc,
fCharacterization.origin(),
surfaceFlags,
diff --git a/src/core/SkGpuBlurUtils.cpp b/src/core/SkGpuBlurUtils.cpp
index f9aee1c..54f1bc7 100644
--- a/src/core/SkGpuBlurUtils.cpp
+++ b/src/core/SkGpuBlurUtils.cpp
@@ -117,8 +117,14 @@
GrPixelConfig config = get_blur_config(proxy.get());
+ GrBackendFormat format = proxy->backendFormat().makeTexture2D();
+ if (!format.isValid()) {
+ return nullptr;
+ }
+
sk_sp<GrRenderTargetContext> renderTargetContext;
renderTargetContext = context->contextPriv().makeDeferredRenderTargetContext(
+ format,
dstFit, dstII.width(), dstII.height(),
config, dstII.refColorSpace(),
1, GrMipMapped::kNo,
@@ -159,8 +165,14 @@
GrPixelConfig config = get_blur_config(proxy.get());
+ GrBackendFormat format = proxy->backendFormat().makeTexture2D();
+ if (!format.isValid()) {
+ return nullptr;
+ }
+
sk_sp<GrRenderTargetContext> dstRenderTargetContext;
dstRenderTargetContext = context->contextPriv().makeDeferredRenderTargetContext(
+ format,
fit, srcRect.width(),
srcRect.height(),
config,
@@ -276,11 +288,17 @@
sk_sp<GrRenderTargetContext> dstRenderTargetContext;
+ GrBackendFormat format = src->backendFormat().makeTexture2D();
+ if (!format.isValid()) {
+ return nullptr;
+ }
+
for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) {
shrink_irect_by_2(&dstRect, i < scaleFactorX, i < scaleFactorY);
// We know this will not be the final draw so we are free to make it an approx match.
dstRenderTargetContext = context->contextPriv().makeDeferredRenderTargetContext(
+ format,
SkBackingFit::kApprox,
dstRect.fRight,
dstRect.fBottom,
@@ -382,8 +400,14 @@
GrPixelConfig config = get_blur_config(srcProxy.get());
+ GrBackendFormat format = srcProxy->backendFormat().makeTexture2D();
+ if (!format.isValid()) {
+ return nullptr;
+ }
+
sk_sp<GrRenderTargetContext> dstRenderTargetContext =
- context->contextPriv().makeDeferredRenderTargetContext(fit, dstII.width(), dstII.height(),
+ context->contextPriv().makeDeferredRenderTargetContext(format,
+ fit, dstII.width(), dstII.height(),
config, dstII.refColorSpace(),
1, GrMipMapped::kNo,
srcProxy->origin());
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp
index b6ed9b3..710e1ff 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -248,9 +248,12 @@
sk_sp<SkColorSpace> colorSpace = sk_ref_sp(outputProperties.colorSpace());
GrPixelConfig config = SkColorType2GrPixelConfig(outputProperties.colorType());
+ GrBackendFormat format =
+ context->contextPriv().caps()->getBackendFormatFromColorType(
+ outputProperties.colorType());
sk_sp<GrRenderTargetContext> renderTargetContext(
context->contextPriv().makeDeferredRenderTargetContext(
- SkBackingFit::kApprox, bounds.width(), bounds.height(),
+ format, SkBackingFit::kApprox, bounds.width(), bounds.height(),
config, std::move(colorSpace)));
if (!renderTargetContext) {
return nullptr;
diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp
index 4309b80..a1db765 100644
--- a/src/core/SkSpecialImage.cpp
+++ b/src/core/SkSpecialImage.cpp
@@ -436,8 +436,11 @@
return nullptr;
}
+ GrBackendFormat format =
+ fContext->contextPriv().caps()->getBackendFormatFromColorType(outProps.colorType());
+
return SkSpecialSurface::MakeRenderTarget(
- fContext, size.width(), size.height(),
+ fContext, format, size.width(), size.height(),
SkColorType2GrPixelConfig(outProps.colorType()), sk_ref_sp(outProps.colorSpace()),
props);
}
diff --git a/src/core/SkSpecialSurface.cpp b/src/core/SkSpecialSurface.cpp
index a45b40b..a1d76f1 100644
--- a/src/core/SkSpecialSurface.cpp
+++ b/src/core/SkSpecialSurface.cpp
@@ -117,6 +117,7 @@
#if SK_SUPPORT_GPU
///////////////////////////////////////////////////////////////////////////////
+#include "GrBackendSurface.h"
#include "GrContext.h"
#include "SkGpuDevice.h"
@@ -164,6 +165,7 @@
};
sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(GrContext* context,
+ const GrBackendFormat& format,
int width, int height,
GrPixelConfig config,
sk_sp<SkColorSpace> colorSpace,
@@ -174,7 +176,7 @@
sk_sp<GrRenderTargetContext> renderTargetContext(
context->contextPriv().makeDeferredRenderTargetContext(
- SkBackingFit::kApprox, width, height, config, std::move(colorSpace), 1,
+ format, SkBackingFit::kApprox, width, height, config, std::move(colorSpace), 1,
GrMipMapped::kNo, kBottomLeft_GrSurfaceOrigin, props));
if (!renderTargetContext) {
return nullptr;
diff --git a/src/core/SkSpecialSurface.h b/src/core/SkSpecialSurface.h
index b04b28d..1b7aada 100644
--- a/src/core/SkSpecialSurface.h
+++ b/src/core/SkSpecialSurface.h
@@ -16,6 +16,7 @@
#include "GrTypesPriv.h"
#endif
+class GrBackendFormat;
class GrContext;
class SkBitmap;
class SkCanvas;
@@ -60,6 +61,7 @@
* be created, nullptr will be returned.
*/
static sk_sp<SkSpecialSurface> MakeRenderTarget(GrContext*,
+ const GrBackendFormat& format,
int width, int height,
GrPixelConfig config,
sk_sp<SkColorSpace> colorSpace,
diff --git a/src/effects/imagefilters/SkAlphaThresholdFilter.cpp b/src/effects/imagefilters/SkAlphaThresholdFilter.cpp
index 8cc485f..29d5cc5 100644
--- a/src/effects/imagefilters/SkAlphaThresholdFilter.cpp
+++ b/src/effects/imagefilters/SkAlphaThresholdFilter.cpp
@@ -105,10 +105,11 @@
sk_sp<GrTextureProxy> SkAlphaThresholdFilterImpl::createMaskTexture(GrContext* context,
const SkMatrix& inMatrix,
const SkIRect& bounds) const {
-
+ GrBackendFormat format =
+ context->contextPriv().caps()->getBackendFormatFromColorType(kAlpha_8_SkColorType);
sk_sp<GrRenderTargetContext> rtContext(
context->contextPriv().makeDeferredRenderTargetContextWithFallback(
- SkBackingFit::kApprox, bounds.width(), bounds.height(), kAlpha_8_GrPixelConfig,
+ format, SkBackingFit::kApprox, bounds.width(), bounds.height(), kAlpha_8_GrPixelConfig,
nullptr));
if (!rtContext) {
return nullptr;
diff --git a/src/effects/imagefilters/SkArithmeticImageFilter.cpp b/src/effects/imagefilters/SkArithmeticImageFilter.cpp
index 14fd17d..88a7c80 100644
--- a/src/effects/imagefilters/SkArithmeticImageFilter.cpp
+++ b/src/effects/imagefilters/SkArithmeticImageFilter.cpp
@@ -356,10 +356,14 @@
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
+ SkColorType colorType = outputProperties.colorType();
+ GrBackendFormat format =
+ context->contextPriv().caps()->getBackendFormatFromColorType(colorType);
+
sk_sp<GrRenderTargetContext> renderTargetContext(
context->contextPriv().makeDeferredRenderTargetContext(
- SkBackingFit::kApprox, bounds.width(), bounds.height(),
- SkColorType2GrPixelConfig(outputProperties.colorType()),
+ format, SkBackingFit::kApprox, bounds.width(), bounds.height(),
+ SkColorType2GrPixelConfig(colorType),
sk_ref_sp(outputProperties.colorSpace())));
if (!renderTargetContext) {
return nullptr;
diff --git a/src/effects/imagefilters/SkDisplacementMapEffect.cpp b/src/effects/imagefilters/SkDisplacementMapEffect.cpp
index c5403cb..0427cff 100644
--- a/src/effects/imagefilters/SkDisplacementMapEffect.cpp
+++ b/src/effects/imagefilters/SkDisplacementMapEffect.cpp
@@ -300,12 +300,15 @@
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
SkMatrix matrix;
matrix.setTranslate(-SkIntToScalar(colorBounds.x()), -SkIntToScalar(colorBounds.y()));
- GrPixelConfig config = SkColorType2GrPixelConfig(ctx.outputProperties().colorType());
+ SkColorType colorType = ctx.outputProperties().colorType();
+ GrPixelConfig config = SkColorType2GrPixelConfig(colorType);
+ GrBackendFormat format =
+ context->contextPriv().caps()->getBackendFormatFromColorType(colorType);
sk_sp<GrRenderTargetContext> renderTargetContext(
- context->contextPriv().makeDeferredRenderTargetContext(SkBackingFit::kApprox,
- bounds.width(), bounds.height(),
- config, sk_ref_sp(colorSpace)));
+ context->contextPriv().makeDeferredRenderTargetContext(
+ format, SkBackingFit::kApprox, bounds.width(), bounds.height(), config,
+ sk_ref_sp(colorSpace)));
if (!renderTargetContext) {
return nullptr;
}
diff --git a/src/effects/imagefilters/SkLightingImageFilter.cpp b/src/effects/imagefilters/SkLightingImageFilter.cpp
index dbe30c6..d89233f 100644
--- a/src/effects/imagefilters/SkLightingImageFilter.cpp
+++ b/src/effects/imagefilters/SkLightingImageFilter.cpp
@@ -464,11 +464,14 @@
sk_sp<GrTextureProxy> inputProxy(input->asTextureProxyRef(context));
SkASSERT(inputProxy);
+ SkColorType colorType = outputProperties.colorType();
+ GrBackendFormat format =
+ context->contextPriv().caps()->getBackendFormatFromColorType(colorType);
sk_sp<GrRenderTargetContext> renderTargetContext(
context->contextPriv().makeDeferredRenderTargetContext(
- SkBackingFit::kApprox, offsetBounds.width(), offsetBounds.height(),
- SkColorType2GrPixelConfig(outputProperties.colorType()),
+ format, SkBackingFit::kApprox, offsetBounds.width(),
+ offsetBounds.height(), SkColorType2GrPixelConfig(colorType),
sk_ref_sp(outputProperties.colorSpace())));
if (!renderTargetContext) {
return nullptr;
diff --git a/src/effects/imagefilters/SkMorphologyImageFilter.cpp b/src/effects/imagefilters/SkMorphologyImageFilter.cpp
index ae07ffb..662343b 100644
--- a/src/effects/imagefilters/SkMorphologyImageFilter.cpp
+++ b/src/effects/imagefilters/SkMorphologyImageFilter.cpp
@@ -466,7 +466,10 @@
sk_sp<GrTextureProxy> srcTexture(input->asTextureProxyRef(context));
SkASSERT(srcTexture);
sk_sp<SkColorSpace> colorSpace = sk_ref_sp(outputProperties.colorSpace());
- GrPixelConfig config = SkColorType2GrPixelConfig(outputProperties.colorType());
+ SkColorType colorType = outputProperties.colorType();
+ GrBackendFormat format =
+ context->contextPriv().caps()->getBackendFormatFromColorType(colorType);
+ GrPixelConfig config = SkColorType2GrPixelConfig(colorType);
// setup new clip
const GrFixedClip clip(SkIRect::MakeWH(srcTexture->width(), srcTexture->height()));
@@ -479,7 +482,7 @@
if (radius.fWidth > 0) {
sk_sp<GrRenderTargetContext> dstRTContext(
context->contextPriv().makeDeferredRenderTargetContext(
- SkBackingFit::kApprox, rect.width(), rect.height(), config, colorSpace));
+ format, SkBackingFit::kApprox, rect.width(), rect.height(), config, colorSpace));
if (!dstRTContext) {
return nullptr;
}
@@ -498,7 +501,7 @@
if (radius.fHeight > 0) {
sk_sp<GrRenderTargetContext> dstRTContext(
context->contextPriv().makeDeferredRenderTargetContext(
- SkBackingFit::kApprox, rect.width(), rect.height(), config, colorSpace));
+ format, SkBackingFit::kApprox, rect.width(), rect.height(), config, colorSpace));
if (!dstRTContext) {
return nullptr;
}
diff --git a/src/effects/imagefilters/SkXfermodeImageFilter.cpp b/src/effects/imagefilters/SkXfermodeImageFilter.cpp
index 9dad6c2..a56817f 100644
--- a/src/effects/imagefilters/SkXfermodeImageFilter.cpp
+++ b/src/effects/imagefilters/SkXfermodeImageFilter.cpp
@@ -315,10 +315,14 @@
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
+ SkColorType colorType = outputProperties.colorType();
+ GrBackendFormat format =
+ context->contextPriv().caps()->getBackendFormatFromColorType(colorType);
+
sk_sp<GrRenderTargetContext> renderTargetContext(
context->contextPriv().makeDeferredRenderTargetContext(
- SkBackingFit::kApprox, bounds.width(), bounds.height(),
- SkColorType2GrPixelConfig(outputProperties.colorType()),
+ format, SkBackingFit::kApprox, bounds.width(), bounds.height(),
+ SkColorType2GrPixelConfig(colorType),
sk_ref_sp(outputProperties.colorSpace())));
if (!renderTargetContext) {
return nullptr;
diff --git a/src/gpu/GrAHardwareBufferImageGenerator.cpp b/src/gpu/GrAHardwareBufferImageGenerator.cpp
index 76918de..8a3d5c8 100644
--- a/src/gpu/GrAHardwareBufferImageGenerator.cpp
+++ b/src/gpu/GrAHardwareBufferImageGenerator.cpp
@@ -548,7 +548,7 @@
return tex;
},
- desc, fSurfaceOrigin, GrMipMapped::kNo, textureType, SkBackingFit::kExact,
+ backendFormat, desc, fSurfaceOrigin, GrMipMapped::kNo, SkBackingFit::kExact,
SkBudgeted::kNo);
if (!texProxy) {
diff --git a/src/gpu/GrBackendSurface.cpp b/src/gpu/GrBackendSurface.cpp
index 8198d52..55f11c6 100644
--- a/src/gpu/GrBackendSurface.cpp
+++ b/src/gpu/GrBackendSurface.cpp
@@ -20,21 +20,43 @@
GrBackendFormat::GrBackendFormat(GrGLenum format, GrGLenum target)
: fBackend(GrBackendApi::kOpenGL)
- , fValid(true) {
- fGL.fTarget = target;
- fGL.fFormat = format;
+ , fValid(true)
+ , fGLFormat(format) {
+ switch (target) {
+ case GR_GL_TEXTURE_2D:
+ fTextureType = GrTextureType::k2D;
+ break;
+ case GR_GL_TEXTURE_RECTANGLE:
+ fTextureType = GrTextureType::kRectangle;
+ break;
+ case GR_GL_TEXTURE_EXTERNAL:
+ fTextureType = GrTextureType::kExternal;
+ break;
+ default:
+ SK_ABORT("Unexpected texture target");
+ }
}
const GrGLenum* GrBackendFormat::getGLFormat() const {
if (this->isValid() && GrBackendApi::kOpenGL == fBackend) {
- return &fGL.fFormat;
+ return &fGLFormat;
}
return nullptr;
}
const GrGLenum* GrBackendFormat::getGLTarget() const {
if (this->isValid() && GrBackendApi::kOpenGL == fBackend) {
- return &fGL.fTarget;
+ static constexpr GrGLenum k2D = GR_GL_TEXTURE_2D;
+ static constexpr GrGLenum kRect = GR_GL_TEXTURE_RECTANGLE;
+ static constexpr GrGLenum kExternal = GR_GL_TEXTURE_EXTERNAL;
+ switch (fTextureType) {
+ case GrTextureType::k2D:
+ return &k2D;
+ case GrTextureType::kRectangle:
+ return &kRect;
+ case GrTextureType::kExternal:
+ return &kExternal;
+ }
}
return nullptr;
}
@@ -44,9 +66,10 @@
#ifdef SK_VULKAN
, fValid(true)
#else
- ,fValid(false)
+ , fValid(false)
#endif
- , fVkFormat(vkFormat) {
+ , fVkFormat(vkFormat)
+ , fTextureType(GrTextureType::k2D) {
}
const VkFormat* GrBackendFormat::getVkFormat() const {
@@ -60,7 +83,8 @@
GrBackendFormat::GrBackendFormat(GrMTLPixelFormat mtlFormat)
: fBackend(GrBackendApi::kMetal)
, fValid(true)
- , fMtlFormat(mtlFormat) {
+ , fMtlFormat(mtlFormat)
+ , fTextureType(GrTextureType::k2D) {
}
const GrMTLPixelFormat* GrBackendFormat::getMtlFormat() const {
@@ -74,7 +98,8 @@
GrBackendFormat::GrBackendFormat(GrPixelConfig config)
: fBackend(GrBackendApi::kMock)
, fValid(true)
- , fMockFormat(config) {
+ , fMockFormat(config)
+ , fTextureType(GrTextureType::k2D) {
}
const GrPixelConfig* GrBackendFormat::getMockFormat() const {
@@ -84,6 +109,14 @@
return nullptr;
}
+GrBackendFormat GrBackendFormat::makeTexture2D() const {
+ // TODO: once we support ycbcr conversions in Vulkan we need to check if we are using an
+ // external format since they will not be able to be made into a Texture2D.
+ GrBackendFormat copy = *this;
+ copy.fTextureType = GrTextureType::k2D;
+ return copy;
+}
+
GrBackendTexture::GrBackendTexture(int width,
int height,
const GrVkImageInfo& vkInfo)
diff --git a/src/gpu/GrBackendTextureImageGenerator.cpp b/src/gpu/GrBackendTextureImageGenerator.cpp
index 326dab3..4f887f2 100644
--- a/src/gpu/GrBackendTextureImageGenerator.cpp
+++ b/src/gpu/GrBackendTextureImageGenerator.cpp
@@ -133,11 +133,10 @@
GrBackendTexture backendTexture = fBackendTexture;
RefHelper* refHelper = fRefHelper;
- GrTextureType textureType = GrTextureType::k2D;
- GrGLTextureInfo glInfo;
- if (backendTexture.getGLTextureInfo(&glInfo)) {
- textureType = GrGLTexture::TextureTypeFromTarget(glInfo.fTarget);
- }
+ GrBackendFormat format =
+ context->contextPriv().caps()->createFormatFromBackendTexture(backendTexture);
+ SkASSERT(format.isValid());
+
sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy(
[refHelper, releaseProcHelper, semaphore, backendTexture]
(GrResourceProvider* resourceProvider) {
@@ -177,7 +176,7 @@
return tex;
},
- desc, fSurfaceOrigin, mipMapped, textureType, SkBackingFit::kExact, SkBudgeted::kNo);
+ format, desc, fSurfaceOrigin, mipMapped, SkBackingFit::kExact, SkBudgeted::kNo);
if (!proxy) {
return nullptr;
@@ -194,10 +193,16 @@
// layout change in Vulkan and we do not change the layout of borrowed images.
GrMipMapped mipMapped = willNeedMipMaps ? GrMipMapped::kYes : GrMipMapped::kNo;
+ GrBackendFormat format = proxy->backendFormat().makeTexture2D();
+ if (!format.isValid()) {
+ return nullptr;
+ }
+
sk_sp<GrRenderTargetContext> rtContext(
context->contextPriv().makeDeferredRenderTargetContext(
- SkBackingFit::kExact, info.width(), info.height(), proxy->config(), nullptr, 1,
- mipMapped, proxy->origin(), nullptr, SkBudgeted::kYes));
+ format, SkBackingFit::kExact, info.width(), info.height(),
+ proxy->config(), nullptr, 1, mipMapped, proxy->origin(), nullptr,
+ SkBudgeted::kYes));
if (!rtContext) {
return nullptr;
diff --git a/src/gpu/GrBlurUtils.cpp b/src/gpu/GrBlurUtils.cpp
index b4b93f4..4e29461 100644
--- a/src/gpu/GrBlurUtils.cpp
+++ b/src/gpu/GrBlurUtils.cpp
@@ -175,10 +175,13 @@
const SkMatrix& origViewMatrix,
const GrShape& shape,
int sampleCnt) {
+ GrBackendFormat format =
+ context->contextPriv().caps()->getBackendFormatFromColorType(kAlpha_8_SkColorType);
sk_sp<GrRenderTargetContext> rtContext(
context->contextPriv().makeDeferredRenderTargetContextWithFallback(
- SkBackingFit::kApprox, maskRect.width(), maskRect.height(), kAlpha_8_GrPixelConfig,
- nullptr, sampleCnt, GrMipMapped::kNo, kTopLeft_GrSurfaceOrigin));
+ format, SkBackingFit::kApprox, maskRect.width(), maskRect.height(),
+ kAlpha_8_GrPixelConfig, nullptr, sampleCnt, GrMipMapped::kNo,
+ kTopLeft_GrSurfaceOrigin));
if (!rtContext) {
return nullptr;
}
diff --git a/src/gpu/GrCaps.cpp b/src/gpu/GrCaps.cpp
index c2a5a91..64625d9 100644
--- a/src/gpu/GrCaps.cpp
+++ b/src/gpu/GrCaps.cpp
@@ -9,6 +9,7 @@
#include "GrBackendSurface.h"
#include "GrContextOptions.h"
+#include "GrTypesPriv.h"
#include "GrWindowRectangles.h"
#include "SkJSONWriter.h"
@@ -276,9 +277,14 @@
return true;
}
+GrBackendFormat GrCaps::getBackendFormatFromColorType(SkColorType ct) const {
+ return this->getBackendFormatFromGrColorType(SkColorTypeToGrColorType(ct), GrSRGBEncoded::kNo);
+}
+
GrBackendFormat GrCaps::createFormatFromBackendTexture(const GrBackendTexture& backendTex) const {
if (!backendTex.isValid()) {
return GrBackendFormat();
}
return this->onCreateFormatFromBackendTexture(backendTex);
}
+
diff --git a/src/gpu/GrCaps.h b/src/gpu/GrCaps.h
index 98eaa41..c695ebe 100644
--- a/src/gpu/GrCaps.h
+++ b/src/gpu/GrCaps.h
@@ -303,13 +303,15 @@
virtual bool getYUVAConfigFromBackendFormat(const GrBackendFormat& format,
GrPixelConfig*) const = 0;
-#ifdef GR_TEST_UTILS
+ virtual GrBackendFormat getBackendFormatFromGrColorType(GrColorType ct,
+ GrSRGBEncoded srgbEncoded) const = 0;
+ GrBackendFormat getBackendFormatFromColorType(SkColorType ct) const;
+
/**
* Creates a GrBackendFormat which matches the backend texture. If the backend texture is
* invalid, the function will return the default GrBackendFormat.
*/
GrBackendFormat createFormatFromBackendTexture(const GrBackendTexture&) const;
-#endif
const GrDriverBugWorkarounds& workarounds() const { return fDriverBugWorkarounds; }
@@ -319,13 +321,11 @@
expand them. */
void applyOptionsOverrides(const GrContextOptions& options);
-#ifdef GR_TEST_UTILS
/**
* Subclasses implement this to actually create a GrBackendFormat to match backend texture. At
* this point, the backend texture has already been validated.
*/
virtual GrBackendFormat onCreateFormatFromBackendTexture(const GrBackendTexture&) const = 0;
-#endif
sk_sp<GrShaderCaps> fShaderCaps;
diff --git a/src/gpu/GrClipStackClip.cpp b/src/gpu/GrClipStackClip.cpp
index 92af020..ca5043d 100644
--- a/src/gpu/GrClipStackClip.cpp
+++ b/src/gpu/GrClipStackClip.cpp
@@ -344,8 +344,11 @@
return proxy;
}
+ GrBackendFormat format =
+ context->contextPriv().caps()->getBackendFormatFromColorType(kAlpha_8_SkColorType);
sk_sp<GrRenderTargetContext> rtc(
context->contextPriv().makeDeferredRenderTargetContextWithFallback(
+ format,
SkBackingFit::kApprox,
reducedClip.width(),
reducedClip.height(),
@@ -473,10 +476,15 @@
desc.fWidth = maskSpaceIBounds.width();
desc.fHeight = maskSpaceIBounds.height();
desc.fConfig = kAlpha_8_GrPixelConfig;
+
+ GrBackendFormat format =
+ context->contextPriv().caps()->getBackendFormatFromColorType(kAlpha_8_SkColorType);
+
// MDB TODO: We're going to fill this proxy with an ASAP upload (which is out of order wrt
// to ops), so it can't have any pending IO.
- proxy = proxyProvider->createProxy(desc, kTopLeft_GrSurfaceOrigin, SkBackingFit::kApprox,
- SkBudgeted::kYes, GrInternalSurfaceFlags::kNoPendingIO);
+ proxy = proxyProvider->createProxy(format, desc, kTopLeft_GrSurfaceOrigin,
+ SkBackingFit::kApprox, SkBudgeted::kYes,
+ GrInternalSurfaceFlags::kNoPendingIO);
auto uploader = skstd::make_unique<GrTDeferredProxyUploader<ClipMaskData>>(reducedClip);
GrTDeferredProxyUploader<ClipMaskData>* uploaderRaw = uploader.get();
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index e7c72fa..d962bbd 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -496,7 +496,8 @@
fContext->contextPriv().caps()->isConfigTexturable(kRGBA_8888_GrPixelConfig) &&
fContext->validPMUPMConversionExists();
- if (!fContext->contextPriv().caps()->surfaceSupportsWritePixels(dstSurface) ||
+ const GrCaps* caps = this->caps();
+ if (!caps->surfaceSupportsWritePixels(dstSurface) ||
canvas2DFastPath) {
// We don't expect callers that are skipping flushes to require an intermediate draw.
SkASSERT(!(pixelOpsFlags & kDontFlush_PixelOpsFlag));
@@ -505,12 +506,25 @@
}
GrSurfaceDesc desc;
- desc.fConfig = canvas2DFastPath ? kRGBA_8888_GrPixelConfig : dstProxy->config();
desc.fWidth = width;
desc.fHeight = height;
desc.fSampleCnt = 1;
+
+ GrBackendFormat format;
+ if (canvas2DFastPath) {
+ desc.fConfig = kRGBA_8888_GrPixelConfig;
+ format =
+ fContext->contextPriv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
+ } else {
+ desc.fConfig = dstProxy->config();
+ format = dstProxy->backendFormat().makeTexture2D();
+ if (!format.isValid()) {
+ return false;
+ }
+ }
+
auto tempProxy = this->proxyProvider()->createProxy(
- desc, kTopLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes);
+ format, desc, kTopLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes);
if (!tempProxy) {
return false;
}
@@ -683,8 +697,23 @@
desc.fWidth = width;
desc.fHeight = height;
desc.fSampleCnt = 1;
+
+ GrBackendFormat format;
+ if (canvas2DFastPath) {
+ desc.fFlags = kRenderTarget_GrSurfaceFlag;
+ desc.fConfig = kRGBA_8888_GrPixelConfig;
+ format = this->caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
+ } else {
+ desc.fFlags = kNone_GrSurfaceFlags;
+ desc.fConfig = srcProxy->config();
+ format = srcProxy->backendFormat().makeTexture2D();
+ if (!format.isValid()) {
+ return false;
+ }
+ }
+
auto tempProxy = this->proxyProvider()->createProxy(
- desc, kTopLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes);
+ format, desc, kTopLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes);
if (!tempProxy) {
return false;
}
@@ -864,7 +893,8 @@
}
}
-sk_sp<GrSurfaceContext> GrContextPriv::makeDeferredSurfaceContext(const GrSurfaceDesc& dstDesc,
+sk_sp<GrSurfaceContext> GrContextPriv::makeDeferredSurfaceContext(const GrBackendFormat& format,
+ const GrSurfaceDesc& dstDesc,
GrSurfaceOrigin origin,
GrMipMapped mipMapped,
SkBackingFit fit,
@@ -873,10 +903,10 @@
const SkSurfaceProps* props) {
sk_sp<GrTextureProxy> proxy;
if (GrMipMapped::kNo == mipMapped) {
- proxy = this->proxyProvider()->createProxy(dstDesc, origin, fit, isDstBudgeted);
+ proxy = this->proxyProvider()->createProxy(format, dstDesc, origin, fit, isDstBudgeted);
} else {
SkASSERT(SkBackingFit::kExact == fit);
- proxy = this->proxyProvider()->createMipMapProxy(dstDesc, origin, isDstBudgeted);
+ proxy = this->proxyProvider()->createMipMapProxy(format, dstDesc, origin, isDstBudgeted);
}
if (!proxy) {
return nullptr;
@@ -999,6 +1029,7 @@
}
sk_sp<GrRenderTargetContext> GrContextPriv::makeDeferredRenderTargetContextWithFallback(
+ const GrBackendFormat& format,
SkBackingFit fit,
int width, int height,
GrPixelConfig config,
@@ -1008,17 +1039,28 @@
GrSurfaceOrigin origin,
const SkSurfaceProps* surfaceProps,
SkBudgeted budgeted) {
+ GrBackendFormat localFormat = format;
SkASSERT(sampleCnt > 0);
if (0 == fContext->contextPriv().caps()->getRenderTargetSampleCount(sampleCnt, config)) {
config = GrPixelConfigFallback(config);
+ // TODO: First we should be checking the getRenderTargetSampleCount from the GrBackendFormat
+ // and not GrPixelConfig. Besides that, we should implement the fallback in the caps, but
+ // for now we just convert the fallback pixel config to an SkColorType and then get the
+ // GrBackendFormat from that.
+ SkColorType colorType;
+ if (!GrPixelConfigToColorType(config, &colorType)) {
+ return nullptr;
+ }
+ localFormat = fContext->fCaps->getBackendFormatFromColorType(colorType);
}
- return this->makeDeferredRenderTargetContext(fit, width, height, config, std::move(colorSpace),
- sampleCnt, mipMapped, origin, surfaceProps,
- budgeted);
+ return this->makeDeferredRenderTargetContext(localFormat, fit, width, height, config,
+ std::move(colorSpace), sampleCnt, mipMapped,
+ origin, surfaceProps, budgeted);
}
sk_sp<GrRenderTargetContext> GrContextPriv::makeDeferredRenderTargetContext(
+ const GrBackendFormat& format,
SkBackingFit fit,
int width, int height,
GrPixelConfig config,
@@ -1042,9 +1084,9 @@
sk_sp<GrTextureProxy> rtp;
if (GrMipMapped::kNo == mipMapped) {
- rtp = fContext->fProxyProvider->createProxy(desc, origin, fit, budgeted);
+ rtp = fContext->fProxyProvider->createProxy(format, desc, origin, fit, budgeted);
} else {
- rtp = fContext->fProxyProvider->createMipMapProxy(desc, origin, budgeted);
+ rtp = fContext->fProxyProvider->createMipMapProxy(format, desc, origin, budgeted);
}
if (!rtp) {
return nullptr;
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index ba7b0cf..f62979a 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -12,6 +12,7 @@
#include "GrSurfaceContext.h"
#include "text/GrAtlasManager.h"
+class GrBackendFormat;
class GrBackendRenderTarget;
class GrOpMemoryPool;
class GrOnFlushCallbackObject;
@@ -43,7 +44,8 @@
sk_sp<SkColorSpace> = nullptr,
const SkSurfaceProps* = nullptr);
- sk_sp<GrSurfaceContext> makeDeferredSurfaceContext(const GrSurfaceDesc&,
+ sk_sp<GrSurfaceContext> makeDeferredSurfaceContext(const GrBackendFormat&,
+ const GrSurfaceDesc&,
GrSurfaceOrigin,
GrMipMapped,
SkBackingFit,
@@ -217,6 +219,7 @@
* renderTargetContexts created via this entry point.
*/
sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContext(
+ const GrBackendFormat& format,
SkBackingFit fit,
int width, int height,
GrPixelConfig config,
@@ -233,6 +236,7 @@
* SRGB-ness will be preserved.
*/
sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContextWithFallback(
+ const GrBackendFormat& format,
SkBackingFit fit,
int width, int height,
GrPixelConfig config,
diff --git a/src/gpu/GrDrawOpAtlas.cpp b/src/gpu/GrDrawOpAtlas.cpp
index 88308e4..6918123 100644
--- a/src/gpu/GrDrawOpAtlas.cpp
+++ b/src/gpu/GrDrawOpAtlas.cpp
@@ -34,12 +34,13 @@
}
std::unique_ptr<GrDrawOpAtlas> GrDrawOpAtlas::Make(GrProxyProvider* proxyProvider,
+ const GrBackendFormat& format,
GrPixelConfig config, int width,
int height, int numPlotsX, int numPlotsY,
AllowMultitexturing allowMultitexturing,
GrDrawOpAtlas::EvictionFunc func, void* data) {
- std::unique_ptr<GrDrawOpAtlas> atlas(new GrDrawOpAtlas(proxyProvider, config, width, height,
- numPlotsX, numPlotsY,
+ std::unique_ptr<GrDrawOpAtlas> atlas(new GrDrawOpAtlas(proxyProvider, format, config, width,
+ height, numPlotsX, numPlotsY,
allowMultitexturing));
if (!atlas->getProxies()[0]) {
return nullptr;
@@ -178,10 +179,11 @@
///////////////////////////////////////////////////////////////////////////////
-GrDrawOpAtlas::GrDrawOpAtlas(GrProxyProvider* proxyProvider,
+GrDrawOpAtlas::GrDrawOpAtlas(GrProxyProvider* proxyProvider, const GrBackendFormat& format,
GrPixelConfig config, int width, int height,
int numPlotsX, int numPlotsY, AllowMultitexturing allowMultitexturing)
- : fPixelConfig(config)
+ : fFormat(format)
+ , fPixelConfig(config)
, fTextureWidth(width)
, fTextureHeight(height)
, fAtlasGeneration(kInvalidAtlasGeneration + 1)
@@ -521,7 +523,7 @@
int numPlotsY = fTextureHeight/fPlotHeight;
for (uint32_t i = 0; i < this->maxPages(); ++i) {
- fProxies[i] = proxyProvider->createProxy(desc, kTopLeft_GrSurfaceOrigin,
+ fProxies[i] = proxyProvider->createProxy(fFormat, desc, kTopLeft_GrSurfaceOrigin,
SkBackingFit::kExact, SkBudgeted::kYes, GrInternalSurfaceFlags::kNoPendingIO);
if (!fProxies[i]) {
return false;
@@ -647,4 +649,3 @@
constexpr int GrDrawOpAtlasConfig::kMaxDistanceFieldDim;
constexpr int GrDrawOpAtlasConfig::kPlotSize;
-
diff --git a/src/gpu/GrDrawOpAtlas.h b/src/gpu/GrDrawOpAtlas.h
index 2e8f3e7..c9d5546 100644
--- a/src/gpu/GrDrawOpAtlas.h
+++ b/src/gpu/GrDrawOpAtlas.h
@@ -90,7 +90,9 @@
* eviction occurs
* @return An initialized GrDrawOpAtlas, or nullptr if creation fails
*/
- static std::unique_ptr<GrDrawOpAtlas> Make(GrProxyProvider*, GrPixelConfig,
+ static std::unique_ptr<GrDrawOpAtlas> Make(GrProxyProvider*,
+ const GrBackendFormat& format,
+ GrPixelConfig,
int width, int height,
int numPlotsX, int numPlotsY,
AllowMultitexturing allowMultitexturing,
@@ -240,8 +242,9 @@
void setMaxPages_TestingOnly(uint32_t maxPages);
private:
- GrDrawOpAtlas(GrProxyProvider*, GrPixelConfig, int width, int height, int numPlotsX,
- int numPlotsY, AllowMultitexturing allowMultitexturing);
+ GrDrawOpAtlas(GrProxyProvider*, const GrBackendFormat& format, GrPixelConfig, int width,
+ int height, int numPlotsX, int numPlotsY,
+ AllowMultitexturing allowMultitexturing);
/**
* The backing GrTexture for a GrDrawOpAtlas is broken into a spatial grid of Plots. The Plots
@@ -377,6 +380,7 @@
plot->resetRects();
}
+ GrBackendFormat fFormat;
GrPixelConfig fPixelConfig;
int fTextureWidth;
int fTextureHeight;
diff --git a/src/gpu/GrOnFlushResourceProvider.cpp b/src/gpu/GrOnFlushResourceProvider.cpp
index d63c5ac..33d116c 100644
--- a/src/gpu/GrOnFlushResourceProvider.cpp
+++ b/src/gpu/GrOnFlushResourceProvider.cpp
@@ -14,48 +14,6 @@
#include "GrSurfaceProxy.h"
sk_sp<GrRenderTargetContext> GrOnFlushResourceProvider::makeRenderTargetContext(
- const GrSurfaceDesc& desc,
- GrSurfaceOrigin origin,
- sk_sp<SkColorSpace> colorSpace,
- const SkSurfaceProps* props) {
- GrSurfaceDesc tmpDesc = desc;
- tmpDesc.fFlags |= kRenderTarget_GrSurfaceFlag;
-
- auto proxyProvider = fDrawingMgr->getContext()->contextPriv().proxyProvider();
- auto resourceProvider = fDrawingMgr->getContext()->contextPriv().resourceProvider();
-
- // Because this is being allocated at the start of a flush we must ensure the proxy
- // will, when instantiated, have no pending IO.
- // TODO: fold the kNoPendingIO_Flag into GrSurfaceFlags?
- sk_sp<GrSurfaceProxy> proxy =
- proxyProvider->createProxy(tmpDesc, origin, SkBackingFit::kExact, SkBudgeted::kYes,
- GrInternalSurfaceFlags::kNoPendingIO);
- if (!proxy || !proxy->asRenderTargetProxy()) {
- return nullptr;
- }
-
- sk_sp<GrRenderTargetContext> renderTargetContext(
- fDrawingMgr->makeRenderTargetContext(std::move(proxy),
- std::move(colorSpace),
- props, false));
-
- if (!renderTargetContext) {
- return nullptr;
- }
-
- // Since this is at flush time and these won't be allocated for us by the GrResourceAllocator
- // we have to manually ensure it is allocated here. The proxy had best have been created
- // with the kNoPendingIO flag!
- if (!renderTargetContext->asSurfaceProxy()->instantiate(resourceProvider)) {
- return nullptr;
- }
-
- renderTargetContext->discard();
-
- return renderTargetContext;
-}
-
-sk_sp<GrRenderTargetContext> GrOnFlushResourceProvider::makeRenderTargetContext(
sk_sp<GrSurfaceProxy> proxy,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* props) {
diff --git a/src/gpu/GrOnFlushResourceProvider.h b/src/gpu/GrOnFlushResourceProvider.h
index c30ec61..9ff2384 100644
--- a/src/gpu/GrOnFlushResourceProvider.h
+++ b/src/gpu/GrOnFlushResourceProvider.h
@@ -66,10 +66,12 @@
public:
explicit GrOnFlushResourceProvider(GrDrawingManager* drawingMgr) : fDrawingMgr(drawingMgr) {}
+#if 0
sk_sp<GrRenderTargetContext> makeRenderTargetContext(const GrSurfaceDesc&,
GrSurfaceOrigin,
sk_sp<SkColorSpace>,
const SkSurfaceProps*);
+#endif
sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>,
sk_sp<SkColorSpace>,
diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp
index c1f8fad..3259f28 100644
--- a/src/gpu/GrProxyProvider.cpp
+++ b/src/gpu/GrProxyProvider.cpp
@@ -194,6 +194,11 @@
return nullptr;
}
+ GrBackendFormat format = fCaps->getBackendFormatFromColorType(info.colorType());
+ if (!format.isValid()) {
+ return nullptr;
+ }
+
if (!this->caps()->isConfigTexturable(config)) {
SkBitmap copy8888;
if (!copy8888.tryAllocPixels(info.makeColorType(kRGBA_8888_SkColorType)) ||
@@ -246,8 +251,7 @@
return resourceProvider->createTexture(desc, budgeted, fit, mipLevel,
resourceProviderFlags);
},
- desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, GrTextureType::k2D, surfaceFlags, fit,
- budgeted);
+ format, desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, surfaceFlags, fit, budgeted);
if (!proxy) {
return nullptr;
@@ -266,7 +270,8 @@
return proxy;
}
-sk_sp<GrTextureProxy> GrProxyProvider::createMipMapProxy(const GrSurfaceDesc& desc,
+sk_sp<GrTextureProxy> GrProxyProvider::createMipMapProxy(const GrBackendFormat& format,
+ const GrSurfaceDesc& desc,
GrSurfaceOrigin origin,
SkBudgeted budgeted) {
ASSERT_SINGLE_OWNER
@@ -275,8 +280,8 @@
return nullptr;
}
- return this->createProxy(desc, origin, GrMipMapped::kYes, SkBackingFit::kExact, budgeted,
- GrInternalSurfaceFlags::kNone);
+ return this->createProxy(format, desc, origin, GrMipMapped::kYes, SkBackingFit::kExact,
+ budgeted, GrInternalSurfaceFlags::kNone);
}
sk_sp<GrTextureProxy> GrProxyProvider::createMipMapProxyFromBitmap(const SkBitmap& bitmap) {
@@ -302,6 +307,11 @@
SkBackingFit::kExact);
}
+ const GrBackendFormat format = fCaps->getBackendFormatFromColorType(bitmap.info().colorType());
+ if (!format.isValid()) {
+ return nullptr;
+ }
+
GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info());
if (!this->caps()->isConfigTexturable(desc.fConfig)) {
SkBitmap copy8888;
@@ -349,8 +359,8 @@
return resourceProvider->createTexture(desc, SkBudgeted::kYes, texels.get(),
mipLevelCount);
},
- desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kYes, GrTextureType::k2D,
- SkBackingFit::kExact, SkBudgeted::kYes);
+ format, desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kYes, SkBackingFit::kExact,
+ SkBudgeted::kYes);
if (!proxy) {
return nullptr;
@@ -366,7 +376,8 @@
return proxy;
}
-sk_sp<GrTextureProxy> GrProxyProvider::createProxy(const GrSurfaceDesc& desc,
+sk_sp<GrTextureProxy> GrProxyProvider::createProxy(const GrBackendFormat& format,
+ const GrSurfaceDesc& desc,
GrSurfaceOrigin origin,
GrMipMapped mipMapped,
SkBackingFit fit,
@@ -392,12 +403,12 @@
if (copyDesc.fFlags & kRenderTarget_GrSurfaceFlag) {
// We know anything we instantiate later from this deferred path will be
// both texturable and renderable
- return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(*this->caps(), copyDesc, origin,
- mipMapped, GrTextureType::k2D,
+ return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(*this->caps(), format, copyDesc,
+ origin, mipMapped,
fit, budgeted, surfaceFlags));
}
- return sk_sp<GrTextureProxy>(new GrTextureProxy(copyDesc, origin, mipMapped, GrTextureType::k2D,
+ return sk_sp<GrTextureProxy>(new GrTextureProxy(format, copyDesc, origin, mipMapped,
fit, budgeted, surfaceFlags));
}
@@ -512,36 +523,36 @@
}
sk_sp<GrTextureProxy> GrProxyProvider::createLazyProxy(LazyInstantiateCallback&& callback,
+ const GrBackendFormat& format,
const GrSurfaceDesc& desc,
GrSurfaceOrigin origin,
GrMipMapped mipMapped,
- GrTextureType textureType,
SkBackingFit fit,
SkBudgeted budgeted) {
- return this->createLazyProxy(std::move(callback), desc, origin, mipMapped, textureType,
+ return this->createLazyProxy(std::move(callback), format, desc, origin, mipMapped,
GrInternalSurfaceFlags::kNone, fit, budgeted);
}
sk_sp<GrTextureProxy> GrProxyProvider::createLazyProxy(LazyInstantiateCallback&& callback,
+ const GrBackendFormat& format,
const GrSurfaceDesc& desc,
GrSurfaceOrigin origin,
GrMipMapped mipMapped,
- GrTextureType textureType,
GrInternalSurfaceFlags surfaceFlags,
SkBackingFit fit,
SkBudgeted budgeted) {
// For non-ddl draws always make lazy proxy's single use.
LazyInstantiationType lazyType = fResourceProvider ? LazyInstantiationType::kSingleUse
: LazyInstantiationType::kMultipleUse;
- return this->createLazyProxy(std::move(callback), desc, origin, mipMapped, textureType,
- surfaceFlags, fit, budgeted, lazyType);
+ return this->createLazyProxy(std::move(callback), format, desc, origin, mipMapped, surfaceFlags,
+ fit, budgeted, lazyType);
}
sk_sp<GrTextureProxy> GrProxyProvider::createLazyProxy(LazyInstantiateCallback&& callback,
+ const GrBackendFormat& format,
const GrSurfaceDesc& desc,
GrSurfaceOrigin origin,
GrMipMapped mipMapped,
- GrTextureType textureType,
GrInternalSurfaceFlags surfaceFlags,
SkBackingFit fit,
SkBudgeted budgeted,
@@ -567,17 +578,16 @@
return sk_sp<GrTextureProxy>(
SkToBool(kRenderTarget_GrSurfaceFlag & desc.fFlags)
- ? new GrTextureRenderTargetProxy(std::move(callback), lazyType, desc, origin,
- mipMapped, textureType, fit, budgeted,
- surfaceFlags)
- : new GrTextureProxy(std::move(callback), lazyType, desc, origin, mipMapped,
- textureType, fit, budgeted, surfaceFlags));
+ ? new GrTextureRenderTargetProxy(std::move(callback), lazyType, format, desc,
+ origin, mipMapped, fit, budgeted, surfaceFlags)
+ : new GrTextureProxy(std::move(callback), lazyType, format, desc, origin,
+ mipMapped, fit, budgeted, surfaceFlags));
}
sk_sp<GrRenderTargetProxy> GrProxyProvider::createLazyRenderTargetProxy(
- LazyInstantiateCallback&& callback, const GrSurfaceDesc& desc, GrSurfaceOrigin origin,
- GrInternalSurfaceFlags surfaceFlags, const TextureInfo* textureInfo, SkBackingFit fit,
- SkBudgeted budgeted) {
+ LazyInstantiateCallback&& callback, const GrBackendFormat& format,
+ const GrSurfaceDesc& desc, GrSurfaceOrigin origin, GrInternalSurfaceFlags surfaceFlags,
+ const TextureInfo* textureInfo, SkBackingFit fit, SkBudgeted budgeted) {
SkASSERT((desc.fWidth <= 0 && desc.fHeight <= 0) ||
(desc.fWidth > 0 && desc.fHeight > 0));
@@ -603,15 +613,16 @@
if (textureInfo) {
return sk_sp<GrRenderTargetProxy>(new GrTextureRenderTargetProxy(
- std::move(callback), lazyType, desc, origin, textureInfo->fMipMapped,
- textureInfo->fTextureType, fit, budgeted, surfaceFlags));
+ std::move(callback), lazyType, format, desc, origin, textureInfo->fMipMapped,
+ fit, budgeted, surfaceFlags));
}
return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy(
- std::move(callback), lazyType, desc, origin, fit, budgeted, surfaceFlags));
+ std::move(callback), lazyType, format, desc, origin, fit, budgeted, surfaceFlags));
}
sk_sp<GrTextureProxy> GrProxyProvider::MakeFullyLazyProxy(LazyInstantiateCallback&& callback,
+ const GrBackendFormat& format,
Renderable renderable,
GrSurfaceOrigin origin,
GrPixelConfig config,
@@ -629,15 +640,14 @@
desc.fConfig = config;
desc.fSampleCnt = 1;
- static constexpr auto kTextureType = GrTextureType::k2D;
return sk_sp<GrTextureProxy>(
(Renderable::kYes == renderable)
? new GrTextureRenderTargetProxy(
- std::move(callback), LazyInstantiationType::kSingleUse, desc, origin,
- GrMipMapped::kNo, kTextureType, SkBackingFit::kApprox,
- SkBudgeted::kYes, surfaceFlags)
+ std::move(callback), LazyInstantiationType::kSingleUse, format, desc,
+ origin, GrMipMapped::kNo, SkBackingFit::kApprox, SkBudgeted::kYes,
+ surfaceFlags)
: new GrTextureProxy(std::move(callback), LazyInstantiationType::kSingleUse,
- desc, origin, GrMipMapped::kNo, kTextureType,
+ format, desc, origin, GrMipMapped::kNo,
SkBackingFit::kApprox, SkBudgeted::kYes, surfaceFlags));
}
diff --git a/src/gpu/GrProxyProvider.h b/src/gpu/GrProxyProvider.h
index 26dc6e9..1e26f51 100644
--- a/src/gpu/GrProxyProvider.h
+++ b/src/gpu/GrProxyProvider.h
@@ -76,7 +76,8 @@
* simply has space allocated for the mips. We will allocated the full amount of mip levels
* based on the width and height in the GrSurfaceDesc.
*/
- sk_sp<GrTextureProxy> createMipMapProxy(const GrSurfaceDesc&, GrSurfaceOrigin, SkBudgeted);
+ sk_sp<GrTextureProxy> createMipMapProxy(const GrBackendFormat&, const GrSurfaceDesc&,
+ GrSurfaceOrigin, SkBudgeted);
/*
* Creates a new mipmapped texture proxy for the bitmap with mip levels generated by the cpu.
@@ -86,14 +87,16 @@
/*
* Create a GrSurfaceProxy without any data.
*/
- sk_sp<GrTextureProxy> createProxy(const GrSurfaceDesc&, GrSurfaceOrigin, GrMipMapped,
- SkBackingFit, SkBudgeted, GrInternalSurfaceFlags);
+ sk_sp<GrTextureProxy> createProxy(const GrBackendFormat&, const GrSurfaceDesc&, GrSurfaceOrigin,
+ GrMipMapped, SkBackingFit, SkBudgeted,
+ GrInternalSurfaceFlags);
sk_sp<GrTextureProxy> createProxy(
- const GrSurfaceDesc& desc, GrSurfaceOrigin origin,
- SkBackingFit fit, SkBudgeted budgeted,
+ const GrBackendFormat& format, const GrSurfaceDesc& desc,
+ GrSurfaceOrigin origin, SkBackingFit fit, SkBudgeted budgeted,
GrInternalSurfaceFlags surfaceFlags = GrInternalSurfaceFlags::kNone) {
- return this->createProxy(desc, origin, GrMipMapped::kNo, fit, budgeted, surfaceFlags);
+ return this->createProxy(format, desc, origin, GrMipMapped::kNo, fit, budgeted,
+ surfaceFlags);
}
// These match the definitions in SkImage & GrTexture.h, for whence they came
@@ -150,21 +153,22 @@
* It also must support being passed in a null GrResourceProvider. When this happens, the
* callback should cleanup any resources it captured and return an empty sk_sp<GrTextureProxy>.
*/
- sk_sp<GrTextureProxy> createLazyProxy(LazyInstantiateCallback&&, const GrSurfaceDesc&,
- GrSurfaceOrigin, GrMipMapped, GrTextureType,
+ sk_sp<GrTextureProxy> createLazyProxy(LazyInstantiateCallback&&, const GrBackendFormat&,
+ const GrSurfaceDesc&, GrSurfaceOrigin, GrMipMapped,
GrInternalSurfaceFlags, SkBackingFit, SkBudgeted,
LazyInstantiationType);
- sk_sp<GrTextureProxy> createLazyProxy(LazyInstantiateCallback&&, const GrSurfaceDesc&,
- GrSurfaceOrigin, GrMipMapped, GrTextureType,
+ sk_sp<GrTextureProxy> createLazyProxy(LazyInstantiateCallback&&, const GrBackendFormat&,
+ const GrSurfaceDesc&, GrSurfaceOrigin, GrMipMapped,
GrInternalSurfaceFlags, SkBackingFit, SkBudgeted);
- sk_sp<GrTextureProxy> createLazyProxy(LazyInstantiateCallback&&, const GrSurfaceDesc&,
- GrSurfaceOrigin, GrMipMapped, GrTextureType, SkBackingFit,
- SkBudgeted);
+ sk_sp<GrTextureProxy> createLazyProxy(LazyInstantiateCallback&&, const GrBackendFormat&,
+ const GrSurfaceDesc&, GrSurfaceOrigin, GrMipMapped,
+ SkBackingFit, SkBudgeted);
/** A null TextureInfo indicates a non-textureable render target. */
sk_sp<GrRenderTargetProxy> createLazyRenderTargetProxy(LazyInstantiateCallback&&,
+ const GrBackendFormat&,
const GrSurfaceDesc&,
GrSurfaceOrigin origin,
GrInternalSurfaceFlags,
@@ -176,7 +180,8 @@
* Fully lazy proxies have unspecified width and height. Methods that rely on those values
* (e.g., width, height, getBoundsRect) should be avoided.
*/
- static sk_sp<GrTextureProxy> MakeFullyLazyProxy(LazyInstantiateCallback&&, Renderable,
+ static sk_sp<GrTextureProxy> MakeFullyLazyProxy(LazyInstantiateCallback&&,
+ const GrBackendFormat&, Renderable,
GrSurfaceOrigin, GrPixelConfig, const GrCaps&);
// 'proxy' is about to be used as a texture src or drawn to. This query can be used to
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index 9e857f3..614415d 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -1872,8 +1872,10 @@
fit = SkBackingFit::kApprox;
}
+ SkASSERT(rtProxy->backendFormat().textureType() == GrTextureType::k2D);
+ const GrBackendFormat& format = rtProxy->backendFormat();
sk_sp<GrSurfaceContext> sContext = fContext->contextPriv().makeDeferredSurfaceContext(
- desc, origin, GrMipMapped::kNo, fit, SkBudgeted::kYes,
+ format, desc, origin, GrMipMapped::kNo, fit, SkBudgeted::kYes,
sk_ref_sp(this->colorSpaceInfo().colorSpace()));
if (!sContext) {
SkDebugf("setupDstTexture: surfaceContext creation failed.\n");
diff --git a/src/gpu/GrRenderTargetProxy.cpp b/src/gpu/GrRenderTargetProxy.cpp
index 5488625..39fdee3 100644
--- a/src/gpu/GrRenderTargetProxy.cpp
+++ b/src/gpu/GrRenderTargetProxy.cpp
@@ -19,10 +19,11 @@
// Deferred version
// TODO: we can probably munge the 'desc' in both the wrapped and deferred
// cases to make the sampleConfig/numSamples stuff more rational.
-GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, const GrSurfaceDesc& desc,
- GrSurfaceOrigin origin, SkBackingFit fit,
- SkBudgeted budgeted, GrInternalSurfaceFlags surfaceFlags)
- : INHERITED(desc, origin, fit, budgeted, surfaceFlags)
+GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, const GrBackendFormat& format,
+ const GrSurfaceDesc& desc, GrSurfaceOrigin origin,
+ SkBackingFit fit, SkBudgeted budgeted,
+ GrInternalSurfaceFlags surfaceFlags)
+ : INHERITED(format, desc, origin, fit, budgeted, surfaceFlags)
, fSampleCnt(desc.fSampleCnt)
, fNeedsStencil(false) {
// Since we know the newly created render target will be internal, we are able to precompute
@@ -37,10 +38,12 @@
// Lazy-callback version
GrRenderTargetProxy::GrRenderTargetProxy(LazyInstantiateCallback&& callback,
- LazyInstantiationType lazyType, const GrSurfaceDesc& desc,
- GrSurfaceOrigin origin, SkBackingFit fit,
+ LazyInstantiationType lazyType,
+ const GrBackendFormat& format, const GrSurfaceDesc& desc,
+ GrSurfaceOrigin origin, SkBackingFit fit,
SkBudgeted budgeted, GrInternalSurfaceFlags surfaceFlags)
- : INHERITED(std::move(callback), lazyType, desc, origin, fit, budgeted, surfaceFlags)
+ : INHERITED(std::move(callback), lazyType, format, desc, origin, fit, budgeted,
+ surfaceFlags)
, fSampleCnt(desc.fSampleCnt)
, fNeedsStencil(false) {
SkASSERT(SkToBool(kRenderTarget_GrSurfaceFlag & desc.fFlags));
diff --git a/src/gpu/GrSoftwarePathRenderer.cpp b/src/gpu/GrSoftwarePathRenderer.cpp
index 05b2795..68e51c9 100644
--- a/src/gpu/GrSoftwarePathRenderer.cpp
+++ b/src/gpu/GrSoftwarePathRenderer.cpp
@@ -181,9 +181,12 @@
desc.fHeight = height;
desc.fConfig = kAlpha_8_GrPixelConfig;
+ const GrBackendFormat format =
+ context->contextPriv().caps()->getBackendFormatFromColorType(kAlpha_8_SkColorType);
+
// MDB TODO: We're going to fill this proxy with an ASAP upload (which is out of order wrt to
// ops), so it can't have any pending IO.
- return proxyProvider->createProxy(desc, kTopLeft_GrSurfaceOrigin, fit, SkBudgeted::kYes,
+ return proxyProvider->createProxy(format, desc, kTopLeft_GrSurfaceOrigin, fit, SkBudgeted::kYes,
GrInternalSurfaceFlags::kNoPendingIO);
}
diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp
index c0e65c0..ac650af 100644
--- a/src/gpu/GrSurfaceProxy.cpp
+++ b/src/gpu/GrSurfaceProxy.cpp
@@ -49,9 +49,11 @@
// Lazy-callback version
GrSurfaceProxy::GrSurfaceProxy(LazyInstantiateCallback&& callback, LazyInstantiationType lazyType,
- const GrSurfaceDesc& desc, GrSurfaceOrigin origin, SkBackingFit fit,
+ const GrBackendFormat& format, const GrSurfaceDesc& desc,
+ GrSurfaceOrigin origin, SkBackingFit fit,
SkBudgeted budgeted, GrInternalSurfaceFlags surfaceFlags)
: fSurfaceFlags(surfaceFlags)
+ , fFormat(format)
, fConfig(desc.fConfig)
, fWidth(desc.fWidth)
, fHeight(desc.fHeight)
@@ -63,6 +65,7 @@
, fNeedsClear(SkToBool(desc.fFlags & kPerformInitialClear_GrSurfaceFlag))
, fGpuMemorySize(kInvalidGpuMemorySize)
, fLastOpList(nullptr) {
+ SkASSERT(fFormat.isValid());
// NOTE: the default fUniqueID ctor pulls a value from the same pool as the GrGpuResources.
if (fLazyInstantiateCallback) {
SkASSERT(is_valid_fully_lazy(desc, fit) || is_valid_partially_lazy(desc));
@@ -75,6 +78,7 @@
GrSurfaceProxy::GrSurfaceProxy(sk_sp<GrSurface> surface, GrSurfaceOrigin origin, SkBackingFit fit)
: INHERITED(std::move(surface))
, fSurfaceFlags(fTarget->surfacePriv().flags())
+ , fFormat(fTarget->backendFormat())
, fConfig(fTarget->config())
, fWidth(fTarget->width())
, fHeight(fTarget->height())
@@ -85,6 +89,7 @@
, fNeedsClear(false)
, fGpuMemorySize(kInvalidGpuMemorySize)
, fLastOpList(nullptr) {
+ SkASSERT(fFormat.isValid());
}
GrSurfaceProxy::~GrSurfaceProxy() {
@@ -336,8 +341,13 @@
dstDesc.fHeight = srcRect.height();
dstDesc.fConfig = src->config();
+ GrBackendFormat format = src->backendFormat().makeTexture2D();
+ if (!format.isValid()) {
+ return nullptr;
+ }
+
sk_sp<GrSurfaceContext> dstContext(context->contextPriv().makeDeferredSurfaceContext(
- dstDesc, src->origin(), mipMapped, SkBackingFit::kExact, budgeted));
+ format, dstDesc, src->origin(), mipMapped, SkBackingFit::kExact, budgeted));
if (!dstContext) {
return nullptr;
}
@@ -358,8 +368,14 @@
sk_sp<GrSurfaceContext> GrSurfaceProxy::TestCopy(GrContext* context, const GrSurfaceDesc& dstDesc,
GrSurfaceOrigin origin, GrSurfaceProxy* srcProxy) {
SkASSERT(LazyState::kFully != srcProxy->lazyInstantiationState());
+
+ GrBackendFormat format = srcProxy->backendFormat().makeTexture2D();
+ if (!format.isValid()) {
+ return nullptr;
+ }
+
sk_sp<GrSurfaceContext> dstContext(context->contextPriv().makeDeferredSurfaceContext(
- dstDesc, origin, GrMipMapped::kNo, SkBackingFit::kExact, SkBudgeted::kYes));
+ format, dstDesc, origin, GrMipMapped::kNo, SkBackingFit::kExact, SkBudgeted::kYes));
if (!dstContext) {
return nullptr;
}
diff --git a/src/gpu/GrTextureProducer.cpp b/src/gpu/GrTextureProducer.cpp
index cbff079..97417f9 100644
--- a/src/gpu/GrTextureProducer.cpp
+++ b/src/gpu/GrTextureProducer.cpp
@@ -44,10 +44,15 @@
}
}
+ GrBackendFormat format = inputProxy->backendFormat().makeTexture2D();
+ if (!format.isValid()) {
+ return nullptr;
+ }
+
sk_sp<GrRenderTargetContext> copyRTC =
context->contextPriv().makeDeferredRenderTargetContextWithFallback(
- SkBackingFit::kExact, dstRect.width(), dstRect.height(), inputProxy->config(),
- nullptr, 1, mipMapped, inputProxy->origin());
+ format, SkBackingFit::kExact, dstRect.width(), dstRect.height(),
+ inputProxy->config(), nullptr, 1, mipMapped, inputProxy->origin());
if (!copyRTC) {
return nullptr;
}
diff --git a/src/gpu/GrTextureProxy.cpp b/src/gpu/GrTextureProxy.cpp
index a65f241..517b832 100644
--- a/src/gpu/GrTextureProxy.cpp
+++ b/src/gpu/GrTextureProxy.cpp
@@ -16,36 +16,35 @@
#include "GrTexturePriv.h"
// Deferred version - with data
-GrTextureProxy::GrTextureProxy(const GrSurfaceDesc& srcDesc, GrMipMapped mipMapped,
- GrTextureType textureType, SkBackingFit fit, SkBudgeted budgeted,
+GrTextureProxy::GrTextureProxy(const GrBackendFormat& format, const GrSurfaceDesc& srcDesc,
+ GrMipMapped mipMapped, SkBackingFit fit, SkBudgeted budgeted,
const void* srcData, size_t /*rowBytes*/,
GrInternalSurfaceFlags surfaceFlags)
- : INHERITED(srcDesc, kTopLeft_GrSurfaceOrigin, fit, budgeted, surfaceFlags)
+ : INHERITED(format, srcDesc, kTopLeft_GrSurfaceOrigin, fit, budgeted, surfaceFlags)
, fMipMapped(mipMapped)
- , fTextureType(textureType)
, fProxyProvider(nullptr)
, fDeferredUploader(nullptr) {
SkASSERT(!srcData); // currently handled in Make()
}
// Deferred version - no data
-GrTextureProxy::GrTextureProxy(const GrSurfaceDesc& srcDesc, GrSurfaceOrigin origin,
- GrMipMapped mipMapped, GrTextureType textureType, SkBackingFit fit,
- SkBudgeted budgeted, GrInternalSurfaceFlags surfaceFlags)
- : INHERITED(srcDesc, origin, fit, budgeted, surfaceFlags)
+GrTextureProxy::GrTextureProxy(const GrBackendFormat& format, const GrSurfaceDesc& srcDesc,
+ GrSurfaceOrigin origin, GrMipMapped mipMapped,
+ SkBackingFit fit, SkBudgeted budgeted,
+ GrInternalSurfaceFlags surfaceFlags)
+ : INHERITED(format, srcDesc, origin, fit, budgeted, surfaceFlags)
, fMipMapped(mipMapped)
- , fTextureType(textureType)
, fProxyProvider(nullptr)
, fDeferredUploader(nullptr) {}
// Lazy-callback version
GrTextureProxy::GrTextureProxy(LazyInstantiateCallback&& callback, LazyInstantiationType lazyType,
- const GrSurfaceDesc& desc, GrSurfaceOrigin origin,
- GrMipMapped mipMapped, GrTextureType textureType, SkBackingFit fit,
+ const GrBackendFormat& format, const GrSurfaceDesc& desc,
+ GrSurfaceOrigin origin, GrMipMapped mipMapped, SkBackingFit fit,
SkBudgeted budgeted, GrInternalSurfaceFlags surfaceFlags)
- : INHERITED(std::move(callback), lazyType, desc, origin, fit, budgeted, surfaceFlags)
+ : INHERITED(std::move(callback), lazyType, format, desc, origin, fit, budgeted,
+ surfaceFlags)
, fMipMapped(mipMapped)
- , fTextureType(textureType)
, fProxyProvider(nullptr)
, fDeferredUploader(nullptr) {}
@@ -53,7 +52,6 @@
GrTextureProxy::GrTextureProxy(sk_sp<GrSurface> surf, GrSurfaceOrigin origin)
: INHERITED(std::move(surf), origin, SkBackingFit::kExact)
, fMipMapped(fTarget->asTexture()->texturePriv().mipMapped())
- , fTextureType(fTarget->asTexture()->texturePriv().textureType())
, fProxyProvider(nullptr)
, fDeferredUploader(nullptr) {
if (fTarget->getUniqueKey().isValid()) {
@@ -168,7 +166,7 @@
SkASSERT(surface->asTexture());
SkASSERT(GrMipMapped::kNo == this->proxyMipMapped() ||
GrMipMapped::kYes == surface->asTexture()->texturePriv().mipMapped());
- SkASSERT(surface->asTexture()->texturePriv().textureType() == fTextureType);
+ SkASSERT(surface->asTexture()->texturePriv().textureType() == this->textureType());
}
#endif
diff --git a/src/gpu/GrTextureRenderTargetProxy.cpp b/src/gpu/GrTextureRenderTargetProxy.cpp
index fba48e7..a665270 100644
--- a/src/gpu/GrTextureRenderTargetProxy.cpp
+++ b/src/gpu/GrTextureRenderTargetProxy.cpp
@@ -19,34 +19,35 @@
// This class is virtually derived from GrSurfaceProxy (via both GrTextureProxy and
// GrRenderTargetProxy) so its constructor must be explicitly called.
GrTextureRenderTargetProxy::GrTextureRenderTargetProxy(const GrCaps& caps,
+ const GrBackendFormat& format,
const GrSurfaceDesc& desc,
GrSurfaceOrigin origin,
GrMipMapped mipMapped,
- GrTextureType textureType,
SkBackingFit fit,
SkBudgeted budgeted,
GrInternalSurfaceFlags surfaceFlags)
- : GrSurfaceProxy(desc, origin, fit, budgeted, surfaceFlags)
+ : GrSurfaceProxy(format, desc, origin, fit, budgeted, surfaceFlags)
// for now textures w/ data are always wrapped
- , GrRenderTargetProxy(caps, desc, origin, fit, budgeted, surfaceFlags)
- , GrTextureProxy(desc, origin, mipMapped, textureType, fit, budgeted, surfaceFlags) {}
+ , GrRenderTargetProxy(caps, format, desc, origin, fit, budgeted, surfaceFlags)
+ , GrTextureProxy(format, desc, origin, mipMapped, fit, budgeted, surfaceFlags) {}
// Lazy-callback version
GrTextureRenderTargetProxy::GrTextureRenderTargetProxy(LazyInstantiateCallback&& callback,
LazyInstantiationType lazyType,
+ const GrBackendFormat& format,
const GrSurfaceDesc& desc,
GrSurfaceOrigin origin,
GrMipMapped mipMapped,
- GrTextureType textureType,
SkBackingFit fit,
SkBudgeted budgeted,
GrInternalSurfaceFlags surfaceFlags)
- : GrSurfaceProxy(std::move(callback), lazyType, desc, origin, fit, budgeted, surfaceFlags)
+ : GrSurfaceProxy(std::move(callback), lazyType, format, desc, origin, fit, budgeted,
+ surfaceFlags)
// Since we have virtual inheritance, we initialize GrSurfaceProxy directly. Send null
// callbacks to the texture and RT proxies simply to route to the appropriate constructors.
- , GrRenderTargetProxy(LazyInstantiateCallback(), lazyType, desc, origin, fit, budgeted,
- surfaceFlags)
- , GrTextureProxy(LazyInstantiateCallback(), lazyType, desc, origin, mipMapped, textureType,
+ , GrRenderTargetProxy(LazyInstantiateCallback(), lazyType, format, desc, origin, fit,
+ budgeted, surfaceFlags)
+ , GrTextureProxy(LazyInstantiateCallback(), lazyType, format, desc, origin, mipMapped,
fit, budgeted, surfaceFlags) {}
// Wrapped version
diff --git a/src/gpu/GrTextureRenderTargetProxy.h b/src/gpu/GrTextureRenderTargetProxy.h
index a60c230..18c1419 100644
--- a/src/gpu/GrTextureRenderTargetProxy.h
+++ b/src/gpu/GrTextureRenderTargetProxy.h
@@ -28,13 +28,14 @@
friend class GrProxyProvider; // for ctors
// Deferred version
- GrTextureRenderTargetProxy(const GrCaps&, const GrSurfaceDesc&, GrSurfaceOrigin, GrMipMapped,
- GrTextureType, SkBackingFit, SkBudgeted, GrInternalSurfaceFlags);
+ GrTextureRenderTargetProxy(const GrCaps&, const GrBackendFormat&, const GrSurfaceDesc&,
+ GrSurfaceOrigin, GrMipMapped, SkBackingFit, SkBudgeted,
+ GrInternalSurfaceFlags);
// Lazy-callback version
GrTextureRenderTargetProxy(LazyInstantiateCallback&&, LazyInstantiationType,
- const GrSurfaceDesc& desc, GrSurfaceOrigin, GrMipMapped,
- GrTextureType, SkBackingFit, SkBudgeted, GrInternalSurfaceFlags);
+ const GrBackendFormat&, const GrSurfaceDesc& desc, GrSurfaceOrigin,
+ GrMipMapped, SkBackingFit, SkBudgeted, GrInternalSurfaceFlags);
// Wrapped version
GrTextureRenderTargetProxy(sk_sp<GrSurface>, GrSurfaceOrigin);
diff --git a/src/gpu/GrYUVProvider.cpp b/src/gpu/GrYUVProvider.cpp
index eedde34..16027df 100644
--- a/src/gpu/GrYUVProvider.cpp
+++ b/src/gpu/GrYUVProvider.cpp
@@ -101,7 +101,9 @@
cachedData->unref();
}
-sk_sp<GrTextureProxy> GrYUVProvider::refAsTextureProxy(GrContext* ctx, const GrSurfaceDesc& desc,
+sk_sp<GrTextureProxy> GrYUVProvider::refAsTextureProxy(GrContext* ctx,
+ const GrBackendFormat& format,
+ const GrSurfaceDesc& desc,
SkColorSpace* srcColorSpace,
SkColorSpace* dstColorSpace) {
SkYUVASizeInfo yuvSizeInfo;
@@ -156,7 +158,7 @@
// TODO: investigate preallocating mip maps here
sk_sp<GrRenderTargetContext> renderTargetContext(
ctx->contextPriv().makeDeferredRenderTargetContext(
- SkBackingFit::kExact, desc.fWidth, desc.fHeight, desc.fConfig, nullptr,
+ format, SkBackingFit::kExact, desc.fWidth, desc.fHeight, desc.fConfig, nullptr,
desc.fSampleCnt, GrMipMapped::kNo, kTopLeft_GrSurfaceOrigin));
if (!renderTargetContext) {
return nullptr;
diff --git a/src/gpu/GrYUVProvider.h b/src/gpu/GrYUVProvider.h
index e62a2ee..633ccfb 100644
--- a/src/gpu/GrYUVProvider.h
+++ b/src/gpu/GrYUVProvider.h
@@ -14,6 +14,7 @@
#include "SkYUVASizeInfo.h"
class GrContext;
+class GrBackendFormat;
struct GrSurfaceDesc;
class GrTexture;
class GrTextureProxy;
@@ -40,7 +41,9 @@
*
* On failure (e.g. the provider had no data), this returns NULL.
*/
- sk_sp<GrTextureProxy> refAsTextureProxy(GrContext*, const GrSurfaceDesc&,
+ sk_sp<GrTextureProxy> refAsTextureProxy(GrContext*,
+ const GrBackendFormat&,
+ const GrSurfaceDesc&,
SkColorSpace* srcColorSpace,
SkColorSpace* dstColorSpace);
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index ff9e443..8e88dfd 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -164,10 +164,12 @@
if (kUnknown_GrPixelConfig == config) {
return nullptr;
}
+ GrBackendFormat format =
+ context->contextPriv().caps()->getBackendFormatFromColorType(origInfo.colorType());
// This method is used to create SkGpuDevice's for SkSurface_Gpus. In this case
// they need to be exact.
return context->contextPriv().makeDeferredRenderTargetContext(
- SkBackingFit::kExact,
+ format, SkBackingFit::kExact,
origInfo.width(), origInfo.height(),
config, origInfo.refColorSpace(), sampleCount,
mipMapped, origin, surfaceProps, budgeted);
@@ -1749,14 +1751,21 @@
: SkBackingFit::kExact;
GrPixelConfig config = fRenderTargetContext->colorSpaceInfo().config();
+ const GrBackendFormat& origFormat = fRenderTargetContext->asSurfaceProxy()->backendFormat();
+ GrBackendFormat format = origFormat.makeTexture2D();
+ if (!format.isValid()) {
+ return nullptr;
+ }
if (kRGBA_1010102_GrPixelConfig == config) {
// If the original device is 1010102, fall back to 8888 so that we have a usable alpha
// channel in the layer.
config = kRGBA_8888_GrPixelConfig;
+ format =
+ fContext->contextPriv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
}
sk_sp<GrRenderTargetContext> rtc(fContext->contextPriv().makeDeferredRenderTargetContext(
- fit, cinfo.fInfo.width(), cinfo.fInfo.height(), config,
+ format, fit, cinfo.fInfo.width(), cinfo.fInfo.height(), config,
fRenderTargetContext->colorSpaceInfo().refColorSpace(),
fRenderTargetContext->numStencilSamples(), GrMipMapped::kNo,
kBottomLeft_GrSurfaceOrigin, &props));
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 7e7fde9..e51925e 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -160,8 +160,13 @@
desc.fConfig = baseProxy->config();
desc.fSampleCnt = 1;
+ GrBackendFormat format = baseProxy->backendFormat().makeTexture2D();
+ if (!format.isValid()) {
+ return nullptr;
+ }
+
sk_sp<GrTextureProxy> proxy =
- proxyProvider->createMipMapProxy(desc, baseProxy->origin(), SkBudgeted::kYes);
+ proxyProvider->createMipMapProxy(format, desc, baseProxy->origin(), SkBudgeted::kYes);
if (!proxy) {
return nullptr;
}
diff --git a/src/gpu/ccpr/GrCCAtlas.cpp b/src/gpu/ccpr/GrCCAtlas.cpp
index 0d1f9d9..6dc523d 100644
--- a/src/gpu/ccpr/GrCCAtlas.cpp
+++ b/src/gpu/ccpr/GrCCAtlas.cpp
@@ -72,6 +72,13 @@
fTopNode = skstd::make_unique<Node>(nullptr, 0, 0, fWidth, fHeight);
+ // TODO: don't have this rely on the GrPixelConfig
+ GrSRGBEncoded srgbEncoded = GrSRGBEncoded::kNo;
+ GrColorType colorType = GrPixelConfigToColorTypeAndEncoding(pixelConfig, &srgbEncoded);
+
+ const GrBackendFormat format =
+ caps.getBackendFormatFromGrColorType(colorType, srgbEncoded);
+
fTextureProxy = GrProxyProvider::MakeFullyLazyProxy(
[this, pixelConfig](GrResourceProvider* resourceProvider) {
if (!resourceProvider) {
@@ -87,7 +94,7 @@
}
return fBackingTexture;
},
- GrProxyProvider::Renderable::kYes, kTextureOrigin, pixelConfig, caps);
+ format, GrProxyProvider::Renderable::kYes, kTextureOrigin, pixelConfig, caps);
}
GrCCAtlas::~GrCCAtlas() {
diff --git a/src/gpu/ccpr/GrCCClipPath.cpp b/src/gpu/ccpr/GrCCClipPath.cpp
index d70b4f7..8b8d8a6 100644
--- a/src/gpu/ccpr/GrCCClipPath.cpp
+++ b/src/gpu/ccpr/GrCCClipPath.cpp
@@ -16,6 +16,9 @@
int rtHeight, const GrCaps& caps) {
SkASSERT(!this->isInitialized());
+ const GrBackendFormat format = caps.getBackendFormatFromGrColorType(GrColorType::kAlpha_F16,
+ GrSRGBEncoded::kNo);
+
fAtlasLazyProxy = GrProxyProvider::MakeFullyLazyProxy(
[this](GrResourceProvider* resourceProvider) {
if (!resourceProvider) {
@@ -40,8 +43,8 @@
return sk_ref_sp(textureProxy->peekTexture());
},
- GrProxyProvider::Renderable::kYes, kTopLeft_GrSurfaceOrigin, kAlpha_half_GrPixelConfig,
- caps);
+ format, GrProxyProvider::Renderable::kYes, kTopLeft_GrSurfaceOrigin,
+ kAlpha_half_GrPixelConfig, caps);
fDeviceSpacePath = deviceSpacePath;
fDeviceSpacePath.getBounds().roundOut(&fPathDevIBounds);
diff --git a/src/gpu/effects/GrConfigConversionEffect.fp b/src/gpu/effects/GrConfigConversionEffect.fp
index f466cc7..6cee538 100644
--- a/src/gpu/effects/GrConfigConversionEffect.fp
+++ b/src/gpu/effects/GrConfigConversionEffect.fp
@@ -17,6 +17,9 @@
static bool TestForPreservingPMConversions(GrContext* context) {
static constexpr int kSize = 256;
static constexpr GrPixelConfig kConfig = kRGBA_8888_GrPixelConfig;
+ static constexpr SkColorType kColorType = kRGBA_8888_SkColorType;
+ const GrBackendFormat format =
+ context->contextPriv().caps()->getBackendFormatFromColorType(kColorType);
SkAutoTMalloc<uint32_t> data(kSize * kSize * 3);
uint32_t* srcData = data.get();
uint32_t* firstRead = data.get() + kSize * kSize;
@@ -41,11 +44,11 @@
kRGBA_8888_SkColorType, kPremul_SkAlphaType);
sk_sp<GrRenderTargetContext> readRTC(
- context->contextPriv().makeDeferredRenderTargetContext(SkBackingFit::kExact,
+ context->contextPriv().makeDeferredRenderTargetContext(format, SkBackingFit::kExact,
kSize, kSize,
kConfig, nullptr));
sk_sp<GrRenderTargetContext> tempRTC(
- context->contextPriv().makeDeferredRenderTargetContext(SkBackingFit::kExact,
+ context->contextPriv().makeDeferredRenderTargetContext(format, SkBackingFit::kExact,
kSize, kSize,
kConfig, nullptr));
if (!readRTC || !readRTC->asTextureProxy() || !tempRTC) {
diff --git a/src/gpu/effects/GrConfigConversionEffect.h b/src/gpu/effects/GrConfigConversionEffect.h
index 4da5b0f..301a6f9 100644
--- a/src/gpu/effects/GrConfigConversionEffect.h
+++ b/src/gpu/effects/GrConfigConversionEffect.h
@@ -24,6 +24,9 @@
static bool TestForPreservingPMConversions(GrContext* context) {
static constexpr int kSize = 256;
static constexpr GrPixelConfig kConfig = kRGBA_8888_GrPixelConfig;
+ static constexpr SkColorType kColorType = kRGBA_8888_SkColorType;
+ const GrBackendFormat format =
+ context->contextPriv().caps()->getBackendFormatFromColorType(kColorType);
SkAutoTMalloc<uint32_t> data(kSize * kSize * 3);
uint32_t* srcData = data.get();
uint32_t* firstRead = data.get() + kSize * kSize;
@@ -48,9 +51,9 @@
SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
sk_sp<GrRenderTargetContext> readRTC(context->contextPriv().makeDeferredRenderTargetContext(
- SkBackingFit::kExact, kSize, kSize, kConfig, nullptr));
+ format, SkBackingFit::kExact, kSize, kSize, kConfig, nullptr));
sk_sp<GrRenderTargetContext> tempRTC(context->contextPriv().makeDeferredRenderTargetContext(
- SkBackingFit::kExact, kSize, kSize, kConfig, nullptr));
+ format, SkBackingFit::kExact, kSize, kSize, kConfig, nullptr));
if (!readRTC || !readRTC->asTextureProxy() || !tempRTC) {
return false;
}
diff --git a/src/gpu/effects/GrRRectBlurEffect.fp b/src/gpu/effects/GrRRectBlurEffect.fp
index a577d91..ccaad63 100644
--- a/src/gpu/effects/GrRRectBlurEffect.fp
+++ b/src/gpu/effects/GrRRectBlurEffect.fp
@@ -51,11 +51,13 @@
sk_sp<GrTextureProxy> mask(proxyProvider->findOrCreateProxyByUniqueKey(
key, kBottomLeft_GrSurfaceOrigin));
if (!mask) {
+ GrBackendFormat format =
+ context->contextPriv().caps()->getBackendFormatFromColorType(kAlpha_8_SkColorType);
// TODO: this could be approx but the texture coords will need to be updated
sk_sp<GrRenderTargetContext> rtc(
context->contextPriv().makeDeferredRenderTargetContextWithFallback(
- SkBackingFit::kExact, size.fWidth, size.fHeight,
- kAlpha_8_GrPixelConfig, nullptr));
+ format, SkBackingFit::kExact, size.fWidth,
+ size.fHeight, kAlpha_8_GrPixelConfig, nullptr));
if (!rtc) {
return nullptr;
}
diff --git a/src/gpu/effects/GrRRectBlurEffect.h b/src/gpu/effects/GrRRectBlurEffect.h
index e760f60..a774e2c 100644
--- a/src/gpu/effects/GrRRectBlurEffect.h
+++ b/src/gpu/effects/GrRRectBlurEffect.h
@@ -51,11 +51,13 @@
sk_sp<GrTextureProxy> mask(
proxyProvider->findOrCreateProxyByUniqueKey(key, kBottomLeft_GrSurfaceOrigin));
if (!mask) {
+ GrBackendFormat format = context->contextPriv().caps()->getBackendFormatFromColorType(
+ kAlpha_8_SkColorType);
// TODO: this could be approx but the texture coords will need to be updated
sk_sp<GrRenderTargetContext> rtc(
context->contextPriv().makeDeferredRenderTargetContextWithFallback(
- SkBackingFit::kExact, size.fWidth, size.fHeight, kAlpha_8_GrPixelConfig,
- nullptr));
+ format, SkBackingFit::kExact, size.fWidth, size.fHeight,
+ kAlpha_8_GrPixelConfig, nullptr));
if (!rtc) {
return nullptr;
}
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index 74772ed..bf14d50 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -15,6 +15,7 @@
#include "GrSurfaceProxyPriv.h"
#include "GrTextureProxyPriv.h"
#include "SkJSONWriter.h"
+#include "SkGr.h"
#include "SkTSearch.h"
#include "SkTSort.h"
@@ -2999,12 +3000,19 @@
return get_yuva_config(*glFormat, config);
}
-
-#ifdef GR_TEST_UTILS
GrBackendFormat GrGLCaps::onCreateFormatFromBackendTexture(
const GrBackendTexture& backendTex) const {
GrGLTextureInfo glInfo;
SkAssertResult(backendTex.getGLTextureInfo(&glInfo));
return GrBackendFormat::MakeGL(glInfo.fFormat, glInfo.fTarget);
}
-#endif
+
+GrBackendFormat GrGLCaps::getBackendFormatFromGrColorType(GrColorType ct,
+ GrSRGBEncoded srgbEncoded) const {
+ GrPixelConfig config = GrColorTypeToPixelConfig(ct, srgbEncoded);
+ if (config == kUnknown_GrPixelConfig) {
+ return GrBackendFormat();
+ }
+ return GrBackendFormat::MakeGL(this->configSizedInternalFormat(config), GR_GL_TEXTURE_2D);
+}
+
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h
index fda673e..329618b 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -441,6 +441,9 @@
bool getYUVAConfigFromBackendFormat(const GrBackendFormat&,
GrPixelConfig*) const override;
+ GrBackendFormat getBackendFormatFromGrColorType(GrColorType ct,
+ GrSRGBEncoded srgbEncoded) const override;
+
#if GR_TEST_UTILS
GrGLStandard standard() const { return fStandard; }
#endif
@@ -466,9 +469,7 @@
void onApplyOptionsOverrides(const GrContextOptions& options) override;
-#ifdef GR_TEST_UTILS
GrBackendFormat onCreateFormatFromBackendTexture(const GrBackendTexture&) const override;
-#endif
bool onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget&) const override;
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 17383cc..038b2c1 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -755,7 +755,7 @@
desc.fSampleCnt =
this->caps()->getRenderTargetSampleCount(backendRT.sampleCnt(), backendRT.config());
- return GrGLRenderTarget::MakeWrapped(this, desc, idDesc, backendRT.stencilBits());
+ return GrGLRenderTarget::MakeWrapped(this, desc, info.fFormat, idDesc, backendRT.stencilBits());
}
sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
@@ -784,7 +784,7 @@
if (!this->createRenderTargetObjects(surfDesc, info, &rtIDDesc)) {
return nullptr;
}
- return GrGLRenderTarget::MakeWrapped(this, surfDesc, rtIDDesc, 0);
+ return GrGLRenderTarget::MakeWrapped(this, surfDesc, info.fFormat, rtIDDesc, 0);
}
static bool check_write_and_transfer_input(GrGLTexture* glTex) {
diff --git a/src/gpu/gl/GrGLRenderTarget.cpp b/src/gpu/gl/GrGLRenderTarget.cpp
index 34f8df1..7344dd7 100644
--- a/src/gpu/gl/GrGLRenderTarget.cpp
+++ b/src/gpu/gl/GrGLRenderTarget.cpp
@@ -21,21 +21,22 @@
// Constructor for wrapped render targets.
GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu,
const GrSurfaceDesc& desc,
+ GrGLenum format,
const IDDesc& idDesc,
GrGLStencilAttachment* stencil)
: GrSurface(gpu, desc)
, INHERITED(gpu, desc, stencil) {
this->setFlags(gpu->glCaps(), idDesc);
- this->init(desc, idDesc);
+ this->init(desc, format, idDesc);
this->registerWithCacheWrapped();
}
-GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc,
+GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, GrGLenum format,
const IDDesc& idDesc)
: GrSurface(gpu, desc)
, INHERITED(gpu, desc) {
this->setFlags(gpu->glCaps(), idDesc);
- this->init(desc, idDesc);
+ this->init(desc, format, idDesc);
}
inline void GrGLRenderTarget::setFlags(const GrGLCaps& glCaps, const IDDesc& idDesc) {
@@ -51,12 +52,14 @@
}
}
-void GrGLRenderTarget::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) {
+void GrGLRenderTarget::init(const GrSurfaceDesc& desc, GrGLenum format, const IDDesc& idDesc) {
fRTFBOID = idDesc.fRTFBOID;
fTexFBOID = idDesc.fTexFBOID;
fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID;
fRTFBOOwnership = idDesc.fRTFBOOwnership;
+ fRTFormat = format;
+
fViewport.fLeft = 0;
fViewport.fBottom = 0;
fViewport.fWidth = desc.fWidth;
@@ -67,6 +70,7 @@
sk_sp<GrGLRenderTarget> GrGLRenderTarget::MakeWrapped(GrGLGpu* gpu,
const GrSurfaceDesc& desc,
+ GrGLenum format,
const IDDesc& idDesc,
int stencilBits) {
GrGLStencilAttachment* sb = nullptr;
@@ -81,7 +85,7 @@
sb = new GrGLStencilAttachment(gpu, sbDesc, desc.fWidth, desc.fHeight,
desc.fSampleCnt, format);
}
- return sk_sp<GrGLRenderTarget>(new GrGLRenderTarget(gpu, desc, idDesc, sb));
+ return sk_sp<GrGLRenderTarget>(new GrGLRenderTarget(gpu, desc, format, idDesc, sb));
}
GrBackendRenderTarget GrGLRenderTarget::getBackendRenderTarget() const {
@@ -97,6 +101,12 @@
numStencilBits, fbi);
}
+GrBackendFormat GrGLRenderTarget::backendFormat() const {
+ // We should never have a GrGLRenderTarget (even a textureable one with a target that is not
+ // texture 2D.
+ return GrBackendFormat::MakeGL(fRTFormat, GR_GL_TEXTURE_2D);
+}
+
size_t GrGLRenderTarget::onGpuMemorySize() const {
return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
fNumSamplesOwnedPerPixel, GrMipMapped::kNo);
diff --git a/src/gpu/gl/GrGLRenderTarget.h b/src/gpu/gl/GrGLRenderTarget.h
index a9ec3c3..49f1631 100644
--- a/src/gpu/gl/GrGLRenderTarget.h
+++ b/src/gpu/gl/GrGLRenderTarget.h
@@ -36,6 +36,7 @@
static sk_sp<GrGLRenderTarget> MakeWrapped(GrGLGpu*,
const GrSurfaceDesc&,
+ GrGLenum format,
const IDDesc&,
int stencilBits);
@@ -63,6 +64,8 @@
GrBackendRenderTarget getBackendRenderTarget() const override;
+ GrBackendFormat backendFormat() const override;
+
bool canAttemptStencilAttachment() const override;
// GrGLRenderTarget overrides dumpMemoryStatistics so it can log its texture and renderbuffer
@@ -71,9 +74,9 @@
protected:
// Constructor for subclasses.
- GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
+ GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, GrGLenum format, const IDDesc&);
- void init(const GrSurfaceDesc&, const IDDesc&);
+ void init(const GrSurfaceDesc&, GrGLenum format, const IDDesc&);
void onAbandon() override;
void onRelease() override;
@@ -82,7 +85,8 @@
private:
// Constructor for instances wrapping backend objects.
- GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, GrGLStencilAttachment*);
+ GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, GrGLenum format, const IDDesc&,
+ GrGLStencilAttachment*);
void setFlags(const GrGLCaps&, const IDDesc&);
@@ -98,6 +102,7 @@
GrGLuint fRTFBOID;
GrGLuint fTexFBOID;
GrGLuint fMSColorRenderbufferID;
+ GrGLenum fRTFormat;
GrBackendObjectOwnership fRTFBOOwnership;
diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp
index deb47d0..2d432fe 100644
--- a/src/gpu/gl/GrGLTexture.cpp
+++ b/src/gpu/gl/GrGLTexture.cpp
@@ -104,6 +104,11 @@
return GrBackendTexture(this->width(), this->height(), this->texturePriv().mipMapped(), info);
}
+GrBackendFormat GrGLTexture::backendFormat() const {
+ return GrBackendFormat::MakeGL(fFormat,
+ target_from_texture_type(this->texturePriv().textureType()));
+}
+
sk_sp<GrGLTexture> GrGLTexture::MakeWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc,
GrMipMapsStatus mipMapsStatus, const IDDesc& idDesc,
bool purgeImmediately) {
diff --git a/src/gpu/gl/GrGLTexture.h b/src/gpu/gl/GrGLTexture.h
index 25ba38a..a9d7a38 100644
--- a/src/gpu/gl/GrGLTexture.h
+++ b/src/gpu/gl/GrGLTexture.h
@@ -66,6 +66,8 @@
GrBackendTexture getBackendTexture() const override;
+ GrBackendFormat backendFormat() const override;
+
void textureParamsModified() override {
fSamplerParams.invalidate();
fNonSamplerParams.invalidate();
diff --git a/src/gpu/gl/GrGLTextureRenderTarget.cpp b/src/gpu/gl/GrGLTextureRenderTarget.cpp
index a9d7f14..04f8ffc 100644
--- a/src/gpu/gl/GrGLTextureRenderTarget.cpp
+++ b/src/gpu/gl/GrGLTextureRenderTarget.cpp
@@ -20,7 +20,7 @@
GrMipMapsStatus mipMapsStatus)
: GrSurface(gpu, desc)
, GrGLTexture(gpu, desc, texIDDesc, mipMapsStatus)
- , GrGLRenderTarget(gpu, desc, rtIDDesc) {
+ , GrGLRenderTarget(gpu, desc, texIDDesc.fInfo.fFormat, rtIDDesc) {
this->registerWithCache(budgeted);
}
@@ -31,7 +31,7 @@
GrMipMapsStatus mipMapsStatus)
: GrSurface(gpu, desc)
, GrGLTexture(gpu, desc, texIDDesc, mipMapsStatus)
- , GrGLRenderTarget(gpu, desc, rtIDDesc) {
+ , GrGLRenderTarget(gpu, desc, texIDDesc.fInfo.fFormat, rtIDDesc) {
this->registerWithCacheWrapped();
}
diff --git a/src/gpu/gl/GrGLTextureRenderTarget.h b/src/gpu/gl/GrGLTextureRenderTarget.h
index 4a6cae0..f33ff28 100644
--- a/src/gpu/gl/GrGLTextureRenderTarget.h
+++ b/src/gpu/gl/GrGLTextureRenderTarget.h
@@ -39,6 +39,12 @@
const GrGLTexture::IDDesc& texIDDesc,
const GrGLRenderTarget::IDDesc& rtIDDesc,
GrMipMapsStatus);
+
+ GrBackendFormat backendFormat() const override {
+ // It doesn't matter if we take the texture or render target path, so just pick texture.
+ return GrGLTexture::backendFormat();
+ }
+
protected:
void onAbandon() override {
GrGLRenderTarget::onAbandon();
diff --git a/src/gpu/mock/GrMockCaps.h b/src/gpu/mock/GrMockCaps.h
index c5459b2..d24afa5 100644
--- a/src/gpu/mock/GrMockCaps.h
+++ b/src/gpu/mock/GrMockCaps.h
@@ -9,6 +9,7 @@
#define GrMockCaps_DEFINED
#include "GrCaps.h"
+#include "SkGr.h"
#include "mock/GrMockTypes.h"
class GrMockCaps : public GrCaps {
@@ -125,15 +126,22 @@
return true;
}
+ GrBackendFormat getBackendFormatFromGrColorType(GrColorType ct,
+ GrSRGBEncoded srgbEncoded) const override {
+ GrPixelConfig config = GrColorTypeToPixelConfig(ct, srgbEncoded);
+ if (config == kUnknown_GrPixelConfig) {
+ return GrBackendFormat();
+ }
+ return GrBackendFormat::MakeMock(config);
+ }
+
private:
-#ifdef GR_TEST_UTILS
GrBackendFormat onCreateFormatFromBackendTexture(
const GrBackendTexture& backendTex) const override {
GrMockTextureInfo mockInfo;
SkAssertResult(backendTex.getMockTextureInfo(&mockInfo));
return GrBackendFormat::MakeMock(mockInfo.fConfig);
}
-#endif
static const int kMaxSampleCnt = 16;
diff --git a/src/gpu/mock/GrMockTexture.h b/src/gpu/mock/GrMockTexture.h
index ebf7b73..0565f81 100644
--- a/src/gpu/mock/GrMockTexture.h
+++ b/src/gpu/mock/GrMockTexture.h
@@ -37,6 +37,10 @@
fInfo);
}
+ GrBackendFormat backendFormat() const override {
+ return GrBackendFormat::MakeMock(fInfo.fConfig);
+ }
+
void textureParamsModified() override {}
void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {
fReleaseHelper = std::move(releaseHelper);
@@ -115,6 +119,10 @@
return {this->width(), this->height(), this->numColorSamples(), numStencilBits, fInfo};
}
+ GrBackendFormat backendFormat() const override {
+ return GrBackendFormat::MakeMock(fInfo.fConfig);
+ }
+
protected:
// constructor for subclasses
GrMockRenderTarget(GrMockGpu* gpu, const GrSurfaceDesc& desc,
@@ -154,6 +162,10 @@
const GrTexture* asTexture() const override { return this; }
const GrRenderTarget* asRenderTarget() const override { return this; }
+ GrBackendFormat backendFormat() const override {
+ return GrMockTexture::backendFormat();
+ }
+
private:
void onAbandon() override {
GrRenderTarget::onAbandon();
diff --git a/src/gpu/mtl/GrMtlCaps.h b/src/gpu/mtl/GrMtlCaps.h
index 6eb775c..7edfa79 100644
--- a/src/gpu/mtl/GrMtlCaps.h
+++ b/src/gpu/mtl/GrMtlCaps.h
@@ -90,6 +90,9 @@
return false;
}
+ GrBackendFormat getBackendFormatFromGrColorType(GrColorType ct,
+ GrSRGBEncoded srgbEncoded) const override;
+
bool performPartialClearsAsDraws() const override {
return true;
}
@@ -102,9 +105,7 @@
void initGrCaps(const id<MTLDevice> device);
void initShaderCaps();
-#ifdef GR_TEST_UTILS
GrBackendFormat onCreateFormatFromBackendTexture(const GrBackendTexture&) const override;
-#endif
void initConfigTable();
diff --git a/src/gpu/mtl/GrMtlCaps.mm b/src/gpu/mtl/GrMtlCaps.mm
index 3085811..ca3779b 100644
--- a/src/gpu/mtl/GrMtlCaps.mm
+++ b/src/gpu/mtl/GrMtlCaps.mm
@@ -414,7 +414,6 @@
fPreferredStencilFormat = StencilFormat{ MTLPixelFormatStencil8, 8, 8, true };
}
-#ifdef GR_TEST_UTILS
GrBackendFormat GrMtlCaps::onCreateFormatFromBackendTexture(
const GrBackendTexture& backendTex) const {
GrMtlTextureInfo mtlInfo;
@@ -423,5 +422,17 @@
GrWrapOwnership::kBorrow_GrWrapOwnership);
return GrBackendFormat::MakeMtl(mtlTexture.pixelFormat);
}
-#endif
+
+GrBackendFormat GrMtlCaps::getBackendFormatFromGrColorType(GrColorType ct,
+ GrSRGBEncoded srgbEncoded) const {
+ GrPixelConfig config = GrColorTypeToPixelConfig(ct, srgbEncoded);
+ if (config == kUnknown_GrPixelConfig) {
+ return GrBackendFormat();
+ }
+ MTLPixelFormat format;
+ if (!GrPixelConfigToMTLFormat(config, &format)) {
+ return GrBackendFormat();
+ }
+ return GrBackendFormat::MakeMtl(format);
+}
diff --git a/src/gpu/mtl/GrMtlRenderTarget.h b/src/gpu/mtl/GrMtlRenderTarget.h
index 12f7064..98fa8e0 100644
--- a/src/gpu/mtl/GrMtlRenderTarget.h
+++ b/src/gpu/mtl/GrMtlRenderTarget.h
@@ -43,6 +43,8 @@
GrBackendRenderTarget getBackendRenderTarget() const override;
+ GrBackendFormat backendFormat() const override;
+
protected:
GrMtlRenderTarget(GrMtlGpu* gpu,
const GrSurfaceDesc& desc,
diff --git a/src/gpu/mtl/GrMtlRenderTarget.mm b/src/gpu/mtl/GrMtlRenderTarget.mm
index d14ff7c..59fd479 100644
--- a/src/gpu/mtl/GrMtlRenderTarget.mm
+++ b/src/gpu/mtl/GrMtlRenderTarget.mm
@@ -54,6 +54,10 @@
return GrBackendRenderTarget(this->width(), this->height(), fRenderTexture.sampleCount, info);
}
+GrBackendFormat GrMtlRenderTarget::backendFormat() const {
+ return GrBackendFormat::MakeMtl(fRenderTexture.pixelFormat);
+}
+
GrMtlGpu* GrMtlRenderTarget::getMtlGpu() const {
SkASSERT(!this->wasDestroyed());
return static_cast<GrMtlGpu*>(this->getGpu());
diff --git a/src/gpu/mtl/GrMtlTexture.h b/src/gpu/mtl/GrMtlTexture.h
index b26d65f..5f6234e 100644
--- a/src/gpu/mtl/GrMtlTexture.h
+++ b/src/gpu/mtl/GrMtlTexture.h
@@ -30,6 +30,8 @@
GrBackendTexture getBackendTexture() const override;
+ GrBackendFormat backendFormat() const override;
+
void textureParamsModified() override {}
bool reallocForMipmap(GrMtlGpu* gpu, uint32_t mipLevels);
diff --git a/src/gpu/mtl/GrMtlTexture.mm b/src/gpu/mtl/GrMtlTexture.mm
index 5825ed6..711d5ae 100644
--- a/src/gpu/mtl/GrMtlTexture.mm
+++ b/src/gpu/mtl/GrMtlTexture.mm
@@ -93,3 +93,7 @@
return GrBackendTexture(this->width(), this->height(), mipMapped, info);
}
+GrBackendFormat GrMtlTexture::backendFormat() const {
+ return GrBackendFormat::MakeMtl(fTexture.pixelFormat);
+}
+
diff --git a/src/gpu/mtl/GrMtlTextureRenderTarget.h b/src/gpu/mtl/GrMtlTextureRenderTarget.h
index dae3cbc..412af7b 100644
--- a/src/gpu/mtl/GrMtlTextureRenderTarget.h
+++ b/src/gpu/mtl/GrMtlTextureRenderTarget.h
@@ -22,6 +22,9 @@
static sk_sp<GrMtlTextureRenderTarget> MakeWrappedTextureRenderTarget(GrMtlGpu*,
const GrSurfaceDesc&,
id<MTLTexture>);
+ GrBackendFormat backendFormat() const override {
+ return GrMtlTexture::backendFormat();
+ }
protected:
void onAbandon() override {
diff --git a/src/gpu/ops/GrLatticeOp.cpp b/src/gpu/ops/GrLatticeOp.cpp
index 7551668..19f9d72 100644
--- a/src/gpu/ops/GrLatticeOp.cpp
+++ b/src/gpu/ops/GrLatticeOp.cpp
@@ -378,8 +378,10 @@
desc.fHeight = random->nextRangeU(1, 1000);
GrSurfaceOrigin origin =
random->nextBool() ? kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin;
+ const GrBackendFormat format =
+ context->contextPriv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
auto proxy = context->contextPriv().proxyProvider()->createProxy(
- desc, origin, SkBackingFit::kExact, SkBudgeted::kYes);
+ format, desc, origin, SkBackingFit::kExact, SkBudgeted::kYes);
do {
if (random->nextBool()) {
diff --git a/src/gpu/ops/GrSmallPathRenderer.cpp b/src/gpu/ops/GrSmallPathRenderer.cpp
index 2582262..4f902e0 100644
--- a/src/gpu/ops/GrSmallPathRenderer.cpp
+++ b/src/gpu/ops/GrSmallPathRenderer.cpp
@@ -873,7 +873,11 @@
SkASSERT(!args.fShape->isEmpty());
SkASSERT(args.fShape->hasUnstyledKey());
if (!fAtlas) {
+ const GrBackendFormat format =
+ args.fContext->contextPriv().caps()->getBackendFormatFromColorType(
+ kAlpha_8_SkColorType);
fAtlas = GrDrawOpAtlas::Make(args.fContext->contextPriv().proxyProvider(),
+ format,
kAlpha_8_GrPixelConfig,
ATLAS_TEXTURE_WIDTH, ATLAS_TEXTURE_HEIGHT,
NUM_PLOTS_X, NUM_PLOTS_Y,
@@ -960,8 +964,10 @@
if (context->uniqueID() != gTestStruct.fContextID) {
gTestStruct.fContextID = context->uniqueID();
gTestStruct.reset();
+ const GrBackendFormat format =
+ context->contextPriv().caps()->getBackendFormatFromColorType(kAlpha_8_SkColorType);
gTestStruct.fAtlas = GrDrawOpAtlas::Make(context->contextPriv().proxyProvider(),
- kAlpha_8_GrPixelConfig,
+ format, kAlpha_8_GrPixelConfig,
ATLAS_TEXTURE_WIDTH, ATLAS_TEXTURE_HEIGHT,
NUM_PLOTS_X, NUM_PLOTS_Y,
GrDrawOpAtlas::AllowMultitexturing::kYes,
diff --git a/src/gpu/ops/GrTextureOp.cpp b/src/gpu/ops/GrTextureOp.cpp
index dd03f9d..4255d2c 100644
--- a/src/gpu/ops/GrTextureOp.cpp
+++ b/src/gpu/ops/GrTextureOp.cpp
@@ -669,8 +669,11 @@
fit = random->nextBool() ? SkBackingFit::kApprox : SkBackingFit::kExact;
}
+ const GrBackendFormat format =
+ context->contextPriv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
+
GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
- sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(desc, origin, mipMapped, fit,
+ sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(format, desc, origin, mipMapped, fit,
SkBudgeted::kNo,
GrInternalSurfaceFlags::kNone);
diff --git a/src/gpu/text/GrAtlasManager.cpp b/src/gpu/text/GrAtlasManager.cpp
index 143f84d..486127d 100644
--- a/src/gpu/text/GrAtlasManager.cpp
+++ b/src/gpu/text/GrAtlasManager.cpp
@@ -35,6 +35,21 @@
}
}
+static SkColorType mask_format_to_color_type(GrMaskFormat format) {
+ switch (format) {
+ case kA8_GrMaskFormat:
+ return kAlpha_8_SkColorType;
+ case kA565_GrMaskFormat:
+ return kRGB_565_SkColorType;
+ case kARGB_GrMaskFormat:
+ return kRGBA_8888_SkColorType;
+ default:
+ SkDEBUGFAIL("unsupported GrMaskFormat");
+ return kAlpha_8_SkColorType;
+ }
+
+}
+
void GrAtlasManager::freeAll() {
for (int i = 0; i < kMaskFormatCount; ++i) {
fAtlases[i] = nullptr;
@@ -161,11 +176,14 @@
int index = MaskFormatToAtlasIndex(format);
if (fAtlases[index] == nullptr) {
GrPixelConfig config = mask_format_to_pixel_config(format);
+ SkColorType colorType = mask_format_to_color_type(format);
SkISize atlasDimensions = fAtlasConfigs.atlasDimensions(format);
SkISize numPlots = fAtlasConfigs.numPlots(format);
+ const GrBackendFormat format = fCaps->getBackendFormatFromColorType(colorType);
+
fAtlases[index] = GrDrawOpAtlas::Make(
- fProxyProvider, config, atlasDimensions.width(), atlasDimensions.height(),
+ fProxyProvider, format, config, atlasDimensions.width(), atlasDimensions.height(),
numPlots.width(), numPlots.height(), fAllowMultitexturing,
&GrGlyphCache::HandleEviction, fGlyphCache);
if (!fAtlases[index]) {
diff --git a/src/gpu/text/GrTextContext.cpp b/src/gpu/text/GrTextContext.cpp
index ee8f1d00..acb01d7 100644
--- a/src/gpu/text/GrTextContext.cpp
+++ b/src/gpu/text/GrTextContext.cpp
@@ -214,9 +214,12 @@
gTextContext = GrTextContext::Make(GrTextContext::Options());
}
+ const GrBackendFormat format =
+ context->contextPriv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
+
// Setup dummy SkPaint / GrPaint / GrRenderTargetContext
sk_sp<GrRenderTargetContext> rtc(context->contextPriv().makeDeferredRenderTargetContext(
- SkBackingFit::kApprox, 1024, 1024, kRGBA_8888_GrPixelConfig, nullptr));
+ format, SkBackingFit::kApprox, 1024, 1024, kRGBA_8888_GrPixelConfig, nullptr));
SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random);
diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp
index 01cad06..6f4cb8d 100644
--- a/src/gpu/vk/GrVkCaps.cpp
+++ b/src/gpu/vk/GrVkCaps.cpp
@@ -12,6 +12,7 @@
#include "GrShaderCaps.h"
#include "GrVkInterface.h"
#include "GrVkUtil.h"
+#include "SkGr.h"
#include "vk/GrVkBackendContext.h"
#include "vk/GrVkExtensions.h"
@@ -823,12 +824,23 @@
return get_yuva_config(*vkFormat, config);
}
-#ifdef GR_TEST_UTILS
GrBackendFormat GrVkCaps::onCreateFormatFromBackendTexture(
const GrBackendTexture& backendTex) const {
GrVkImageInfo vkInfo;
SkAssertResult(backendTex.getVkImageInfo(&vkInfo));
return GrBackendFormat::MakeVk(vkInfo.fFormat);
}
-#endif
+
+GrBackendFormat GrVkCaps::getBackendFormatFromGrColorType(GrColorType ct,
+ GrSRGBEncoded srgbEncoded) const {
+ GrPixelConfig config = GrColorTypeToPixelConfig(ct, srgbEncoded);
+ if (config == kUnknown_GrPixelConfig) {
+ return GrBackendFormat();
+ }
+ VkFormat format;
+ if (!GrPixelConfigToVkFormat(config, &format)) {
+ return GrBackendFormat();
+ }
+ return GrBackendFormat::MakeVk(format);
+}
diff --git a/src/gpu/vk/GrVkCaps.h b/src/gpu/vk/GrVkCaps.h
index 0154c0b..0b1243a 100644
--- a/src/gpu/vk/GrVkCaps.h
+++ b/src/gpu/vk/GrVkCaps.h
@@ -165,6 +165,9 @@
bool getYUVAConfigFromBackendFormat(const GrBackendFormat&,
GrPixelConfig*) const override;
+ GrBackendFormat getBackendFormatFromGrColorType(GrColorType ct,
+ GrSRGBEncoded srgbEncoded) const override;
+
private:
enum VkVendor {
kAMD_VkVendor = 4098,
@@ -185,9 +188,7 @@
const GrVkExtensions&);
void initShaderCaps(const VkPhysicalDeviceProperties&, const VkPhysicalDeviceFeatures2&);
-#ifdef GR_TEST_UTILS
GrBackendFormat onCreateFormatFromBackendTexture(const GrBackendTexture&) const override;
-#endif
void initConfigTable(const GrVkInterface*, VkPhysicalDevice, const VkPhysicalDeviceProperties&);
void initStencilFormat(const GrVkInterface* iface, VkPhysicalDevice physDev);
diff --git a/src/gpu/vk/GrVkImage.h b/src/gpu/vk/GrVkImage.h
index 7381e63..5240250 100644
--- a/src/gpu/vk/GrVkImage.h
+++ b/src/gpu/vk/GrVkImage.h
@@ -10,6 +10,7 @@
#include "GrVkResource.h"
+#include "GrBackendSurface.h"
#include "GrTypesPriv.h"
#include "GrVkImageLayout.h"
#include "SkTypes.h"
@@ -42,6 +43,9 @@
VkImage image() const { return fInfo.fImage; }
const GrVkAlloc& alloc() const { return fInfo.fAlloc; }
VkFormat imageFormat() const { return fInfo.fFormat; }
+ GrBackendFormat getBackendFormat() const {
+ return GrBackendFormat::MakeVk(this->imageFormat());
+ }
uint32_t mipLevels() const { return fInfo.fLevelCount; }
const Resource* resource() const { return fResource; }
bool isLinearTiled() const {
diff --git a/src/gpu/vk/GrVkRenderTarget.h b/src/gpu/vk/GrVkRenderTarget.h
index 2438a90..33f4949 100644
--- a/src/gpu/vk/GrVkRenderTarget.h
+++ b/src/gpu/vk/GrVkRenderTarget.h
@@ -37,6 +37,8 @@
~GrVkRenderTarget() override;
+ GrBackendFormat backendFormat() const override { return this->getBackendFormat(); }
+
const GrVkFramebuffer* framebuffer() const { return fFramebuffer; }
const GrVkImageView* colorAttachmentView() const { return fColorAttachmentView; }
const GrVkResource* msaaImageResource() const {
diff --git a/src/gpu/vk/GrVkTexture.h b/src/gpu/vk/GrVkTexture.h
index 9a2d0b6..0cdb8cf 100644
--- a/src/gpu/vk/GrVkTexture.h
+++ b/src/gpu/vk/GrVkTexture.h
@@ -31,6 +31,8 @@
GrBackendTexture getBackendTexture() const override;
+ GrBackendFormat backendFormat() const override { return this->getBackendFormat(); }
+
void textureParamsModified() override {}
const GrVkImageView* textureView();
diff --git a/src/gpu/vk/GrVkTextureRenderTarget.h b/src/gpu/vk/GrVkTextureRenderTarget.h
index bd3973c..dc4dc92 100644
--- a/src/gpu/vk/GrVkTextureRenderTarget.h
+++ b/src/gpu/vk/GrVkTextureRenderTarget.h
@@ -38,6 +38,8 @@
bool updateForMipmap(GrVkGpu* gpu, const GrVkImageInfo& newInfo);
+ GrBackendFormat backendFormat() const override { return this->getBackendFormat(); }
+
protected:
void onAbandon() override {
GrVkRenderTarget::onAbandon();
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index b8aa1a5..600ba39 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -155,10 +155,13 @@
const int width = imageSize.width();
const int height = imageSize.height();
+ const GrBackendFormat format =
+ ctx->contextPriv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
+
// Needs to create a render target in order to draw to it for the yuv->rgb conversion.
sk_sp<GrRenderTargetContext> renderTargetContext(
ctx->contextPriv().makeDeferredRenderTargetContext(
- SkBackingFit::kExact, width, height, kRGBA_8888_GrPixelConfig,
+ format, SkBackingFit::kExact, width, height, kRGBA_8888_GrPixelConfig,
std::move(imageColorSpace), 1, GrMipMapped::kNo, imageOrigin));
if (!renderTargetContext) {
return nullptr;
@@ -312,13 +315,6 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
-static GrTextureType TextureTypeFromBackendFormat(const GrBackendFormat& backendFormat) {
- if (const GrGLenum* target = backendFormat.getGLTarget()) {
- return GrGLTexture::TextureTypeFromTarget(*target);
- }
- return GrTextureType::k2D;
-}
-
sk_sp<SkImage> SkImage_Gpu::MakePromiseTexture(GrContext* context,
const GrBackendFormat& backendFormat,
int width,
@@ -363,9 +359,8 @@
return nullptr;
}
- GrTextureType textureType = TextureTypeFromBackendFormat(backendFormat);
-
- if (mipMapped == GrMipMapped::kYes && GrTextureTypeHasRestrictedSampling(textureType)) {
+ if (mipMapped == GrMipMapped::kYes &&
+ GrTextureTypeHasRestrictedSampling(backendFormat.textureType())) {
// It is invalid to have a GL_TEXTURE_EXTERNAL or GL_TEXTURE_RECTANGLE and have mips as
// well.
return nullptr;
@@ -387,7 +382,7 @@
return promiseHelper.getTexture(resourceProvider, config);
},
- desc, origin, mipMapped, textureType, GrInternalSurfaceFlags::kNone,
+ backendFormat, desc, origin, mipMapped, GrInternalSurfaceFlags::kNone,
SkBackingFit::kExact, SkBudgeted::kNo,
GrSurfaceProxy::LazyInstantiationType::kUninstantiate);
@@ -537,7 +532,8 @@
return sk_ref_sp<GrTexture>(tmp->getTexture());
#endif
},
- desc, imageOrigin, GrMipMapped::kNo, GrTextureType::k2D,
+ yuvaFormats[yuvaIndices[SkYUVAIndex::kY_Index].fIndex],
+ desc, imageOrigin, GrMipMapped::kNo,
GrInternalSurfaceFlags::kNone, SkBackingFit::kExact, SkBudgeted::kNo,
GrSurfaceProxy::LazyInstantiationType::kUninstantiate);
diff --git a/src/image/SkImage_GpuBase.cpp b/src/image/SkImage_GpuBase.cpp
index 8360361..4dfc483 100644
--- a/src/image/SkImage_GpuBase.cpp
+++ b/src/image/SkImage_GpuBase.cpp
@@ -100,8 +100,13 @@
desc.fHeight = subset.height();
desc.fConfig = proxy->config();
+ GrBackendFormat format = proxy->backendFormat().makeTexture2D();
+ if (!format.isValid()) {
+ return nullptr;
+ }
+
sk_sp<GrSurfaceContext> sContext(fContext->contextPriv().makeDeferredSurfaceContext(
- desc, proxy->origin(), GrMipMapped::kNo, SkBackingFit::kExact, fBudgeted));
+ format, desc, proxy->origin(), GrMipMapped::kNo, SkBackingFit::kExact, fBudgeted));
if (!sContext) {
return nullptr;
}
@@ -253,9 +258,15 @@
sk_sp<GrTextureProxy> proxy = this->asTextureProxyRef();
+ GrBackendFormat format = proxy->backendFormat().makeTexture2D();
+ if (!format.isValid()) {
+ return nullptr;
+ }
+
sk_sp<GrRenderTargetContext> renderTargetContext(
fContext->contextPriv().makeDeferredRenderTargetContextWithFallback(
- SkBackingFit::kExact, this->width(), this->height(), proxy->config(), nullptr));
+ format, SkBackingFit::kExact, this->width(), this->height(),
+ proxy->config(), nullptr));
if (!renderTargetContext) {
return nullptr;
}
diff --git a/src/image/SkImage_GpuYUVA.cpp b/src/image/SkImage_GpuYUVA.cpp
index ab13835..a1d0696 100644
--- a/src/image/SkImage_GpuYUVA.cpp
+++ b/src/image/SkImage_GpuYUVA.cpp
@@ -78,11 +78,14 @@
sk_sp<GrTextureProxy> SkImage_GpuYUVA::asTextureProxyRef() const {
if (!fRGBProxy) {
+ const GrBackendFormat format =
+ fContext->contextPriv().caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
+
// Needs to create a render target in order to draw to it for the yuv->rgb conversion.
sk_sp<GrRenderTargetContext> renderTargetContext(
fContext->contextPriv().makeDeferredRenderTargetContext(
- SkBackingFit::kExact, this->width(), this->height(), kRGBA_8888_GrPixelConfig,
- fColorSpace, 1, GrMipMapped::kNo, fOrigin));
+ format, SkBackingFit::kExact, this->width(), this->height(),
+ kRGBA_8888_GrPixelConfig, fColorSpace, 1, GrMipMapped::kNo, fOrigin));
if (!renderTargetContext) {
return nullptr;
}
@@ -242,8 +245,8 @@
desc.fConfig = params.fConfig;
desc.fSampleCnt = 1;
proxies[texIdx] = proxyProvider->createLazyProxy(
- std::move(lazyInstCallback), desc, imageOrigin, GrMipMapped::kNo,
- GrTextureType::k2D, GrInternalSurfaceFlags::kNone,
+ std::move(lazyInstCallback), yuvaFormats[texIdx], desc, imageOrigin,
+ GrMipMapped::kNo, GrInternalSurfaceFlags::kNone,
SkBackingFit::kExact, SkBudgeted::kNo,
GrSurfaceProxy::LazyInstantiationType::kUninstantiate);
if (!proxies[texIdx]) {
diff --git a/src/image/SkImage_Lazy.cpp b/src/image/SkImage_Lazy.cpp
index bd219c6..fef4bf4 100644
--- a/src/image/SkImage_Lazy.cpp
+++ b/src/image/SkImage_Lazy.cpp
@@ -418,6 +418,11 @@
// the texture we fall through here and have the CPU generate the mip maps for us.
if (!proxy && !willBeMipped && !ctx->contextPriv().disableGpuYUVConversion()) {
const GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(fInfo);
+
+ SkColorType colorType = fInfo.colorType();
+ GrBackendFormat format =
+ ctx->contextPriv().caps()->getBackendFormatFromColorType(colorType);
+
ScopedGenerator generator(fSharedGenerator);
Generator_GrYUVProvider provider(generator);
@@ -429,7 +434,7 @@
// TODO: Update to create the mipped surface in the YUV generator and draw the base
// layer directly into the mipped surface.
- proxy = provider.refAsTextureProxy(ctx, desc, generatorColorSpace, thisColorSpace);
+ proxy = provider.refAsTextureProxy(ctx, format, desc, generatorColorSpace, thisColorSpace);
if (proxy) {
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kYUV_LockTexturePath,
kLockTexturePathCount);
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index 9c04ac2..af0b564 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -300,8 +300,11 @@
desc.fConfig = c.config();
desc.fSampleCnt = c.stencilCount();
+ const GrBackendFormat format =
+ context->contextPriv().caps()->getBackendFormatFromColorType(c.colorType());
+
sk_sp<GrSurfaceContext> sc(
- context->contextPriv().makeDeferredSurfaceContext(desc, c.origin(),
+ context->contextPriv().makeDeferredSurfaceContext(format, desc, c.origin(),
GrMipMapped(c.isMipMapped()),
SkBackingFit::kExact, budgeted,
c.refColorSpace(),