Pipe all SDC creation through the recording context
In the new GrSurfaceContext class hierarchy we can get either a v1 or v2 SFC/SDC depending on the context options setting.
Bug: skia:11837
Change-Id: Ia25bc10b58bbbaf65a484b323d9d0eee471bb7ef
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/435276
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
diff --git a/gm/clear_swizzle.cpp b/gm/clear_swizzle.cpp
index abcd815..59ba717 100644
--- a/gm/clear_swizzle.cpp
+++ b/gm/clear_swizzle.cpp
@@ -33,19 +33,18 @@
auto make_offscreen = [&](const SkISize dimensions) {
GrSwizzle readSwizzle = GrSwizzle::Concat(sfc->readSwizzle(), GrSwizzle{"bgra"});
GrSwizzle writeSwizzle = GrSwizzle::Concat(sfc->readSwizzle(), GrSwizzle{"bgra"});
- return GrSurfaceFillContext::Make(rContext,
- kPremul_SkAlphaType,
- sfc->colorInfo().refColorSpace(),
- dimensions,
- SkBackingFit::kExact,
- sfc->asSurfaceProxy()->backendFormat(),
- /* sample count*/ 1,
- GrMipmapped::kNo,
- sfc->asSurfaceProxy()->isProtected(),
- readSwizzle,
- writeSwizzle,
- kTopLeft_GrSurfaceOrigin,
- SkBudgeted::kYes);
+ return rContext->priv().makeSFC(kPremul_SkAlphaType,
+ sfc->colorInfo().refColorSpace(),
+ dimensions,
+ SkBackingFit::kExact,
+ sfc->asSurfaceProxy()->backendFormat(),
+ /* sample count*/ 1,
+ GrMipmapped::kNo,
+ sfc->asSurfaceProxy()->isProtected(),
+ readSwizzle,
+ writeSwizzle,
+ kTopLeft_GrSurfaceOrigin,
+ SkBudgeted::kYes);
};
struct {
diff --git a/gm/gpu_blur_utils.cpp b/gm/gpu_blur_utils.cpp
index b504895..7706283 100644
--- a/gm/gpu_blur_utils.cpp
+++ b/gm/gpu_blur_utils.cpp
@@ -46,20 +46,20 @@
// Performs tiling first of the src into dst bounds with a surrounding skirt so the blur can use
// clamp. Does repeated blurs rather than invoking downsampling.
-static GrSurfaceProxyView slow_blur(GrRecordingContext* ctx,
+static GrSurfaceProxyView slow_blur(GrRecordingContext* rContext,
GrSurfaceProxyView src,
SkIRect dstB,
SkIRect srcB,
float sigmaX,
float sigmaY,
SkTileMode mode) {
- auto tileInto = [ctx](GrSurfaceProxyView src,
- SkIRect srcTileRect,
- SkISize resultSize,
- SkIPoint offset,
- SkTileMode mode) {
+ auto tileInto = [rContext](GrSurfaceProxyView src,
+ SkIRect srcTileRect,
+ SkISize resultSize,
+ SkIPoint offset,
+ SkTileMode mode) {
GrImageInfo info(GrColorType::kRGBA_8888, kPremul_SkAlphaType, nullptr, resultSize);
- auto sfc = GrSurfaceFillContext::Make(ctx, info);
+ auto sfc = rContext->priv().makeSFC(info);
if (!sfc) {
return GrSurfaceProxyView{};
}
@@ -69,7 +69,7 @@
SkMatrix::Translate(-offset.x(), -offset.y()),
sampler,
SkRect::Make(srcTileRect),
- *ctx->priv().caps());
+ *rContext->priv().caps());
sfc->fillWithFP(std::move(fp));
return sfc->readSurfaceView();
};
@@ -100,7 +100,7 @@
sigmaY = 0.f;
}
auto bounds = SkIRect::MakeSize(src.dimensions());
- auto sdc = SkGpuBlurUtils::GaussianBlur(ctx,
+ auto sdc = SkGpuBlurUtils::GaussianBlur(rContext,
std::move(src),
GrColorType::kRGBA_8888,
kPremul_SkAlphaType,
diff --git a/src/core/SkGpuBlurUtils.cpp b/src/core/SkGpuBlurUtils.cpp
index 8fff762..1492b08 100644
--- a/src/core/SkGpuBlurUtils.cpp
+++ b/src/core/SkGpuBlurUtils.cpp
@@ -9,6 +9,7 @@
#include "include/core/SkBitmap.h"
#include "include/core/SkRect.h"
+#include "src/core/SkMathPriv.h"
#if SK_SUPPORT_GPU
#include "include/gpu/GrRecordingContext.h"
@@ -18,9 +19,9 @@
#include "src/gpu/effects/GrGaussianConvolutionFragmentProcessor.h"
#include "src/gpu/effects/GrMatrixConvolutionEffect.h"
#include "src/gpu/effects/GrTextureEffect.h"
-#include "src/gpu/v1/SurfaceDrawContext_v1.h"
#if SK_GPU_V1
+#include "src/gpu/v1/SurfaceDrawContext_v1.h"
using Direction = GrGaussianConvolutionFragmentProcessor::Direction;
@@ -567,7 +568,7 @@
}
GrColorInfo colorInfo(srcColorType, srcAlphaType, colorSpace);
- auto srcCtx = GrSurfaceContext::Make(rContext, srcView, colorInfo);
+ auto srcCtx = rContext->priv().makeSC(srcView, colorInfo);
SkASSERT(srcCtx);
float scaleX = sigmaX > kMaxSigma ? kMaxSigma/sigmaX : 1.f;
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp
index 2df25da..3b60bde 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -593,13 +593,12 @@
sk_ref_sp(colorSpace),
bounds.size());
- auto sfc = GrSurfaceFillContext::Make(rContext,
- info,
- SkBackingFit::kApprox,
- 1,
- GrMipmapped::kNo,
- isProtected,
- kBottomLeft_GrSurfaceOrigin);
+ auto sfc = rContext->priv().makeSFC(info,
+ SkBackingFit::kApprox,
+ 1,
+ GrMipmapped::kNo,
+ isProtected,
+ kBottomLeft_GrSurfaceOrigin);
if (!sfc) {
return nullptr;
}
diff --git a/src/core/SkRuntimeEffect.cpp b/src/core/SkRuntimeEffect.cpp
index 2c9794e..023a91e 100644
--- a/src/core/SkRuntimeEffect.cpp
+++ b/src/core/SkRuntimeEffect.cpp
@@ -1264,22 +1264,21 @@
children, isOpaque));
}
-sk_sp<SkImage> SkRuntimeEffect::makeImage(GrRecordingContext* recordingContext,
+sk_sp<SkImage> SkRuntimeEffect::makeImage(GrRecordingContext* rContext,
sk_sp<SkData> uniforms,
SkSpan<ChildPtr> children,
const SkMatrix* localMatrix,
SkImageInfo resultInfo,
bool mipmapped) const {
- if (recordingContext) {
+ if (rContext) {
#if SK_SUPPORT_GPU
- if (!recordingContext->priv().caps()->mipmapSupport()) {
+ if (!rContext->priv().caps()->mipmapSupport()) {
mipmapped = false;
}
- auto fillContext = GrSurfaceFillContext::Make(recordingContext,
- resultInfo,
- SkBackingFit::kExact,
- /*sample count*/ 1,
- GrMipmapped(mipmapped));
+ auto fillContext = rContext->priv().makeSFC(resultInfo,
+ SkBackingFit::kExact,
+ /*sample count*/ 1,
+ GrMipmapped(mipmapped));
if (!fillContext) {
return nullptr;
}
@@ -1288,7 +1287,7 @@
SkSimpleMatrixProvider matrixProvider(SkMatrix::I());
GrColorInfo colorInfo(resultInfo.colorInfo());
- GrFPArgs args(recordingContext, matrixProvider, &colorInfo);
+ GrFPArgs args(rContext, matrixProvider, &colorInfo);
SkSTArray<8, std::unique_ptr<GrFragmentProcessor>> childFPs;
for (size_t i = 0; i < children.size(); ++i) {
// TODO: add support for other types of child effects
@@ -1314,7 +1313,7 @@
} else {
fillContext->fillWithFP(std::move(fp));
}
- return sk_sp<SkImage>(new SkImage_Gpu(sk_ref_sp(recordingContext),
+ return sk_sp<SkImage>(new SkImage_Gpu(sk_ref_sp(rContext),
kNeedNewImageUniqueID,
fillContext->readSurfaceView(),
resultInfo.colorInfo()));
diff --git a/src/effects/imagefilters/SkArithmeticImageFilter.cpp b/src/effects/imagefilters/SkArithmeticImageFilter.cpp
index 964c40a..a946aef 100644
--- a/src/effects/imagefilters/SkArithmeticImageFilter.cpp
+++ b/src/effects/imagefilters/SkArithmeticImageFilter.cpp
@@ -403,13 +403,12 @@
}
GrImageInfo info(ctx.grColorType(), kPremul_SkAlphaType, ctx.refColorSpace(), bounds.size());
- auto sfc = GrSurfaceFillContext::Make(rContext,
- info,
- SkBackingFit::kApprox,
- 1,
- GrMipmapped::kNo,
- isProtected,
- kBottomLeft_GrSurfaceOrigin);
+ auto sfc = rContext->priv().makeSFC(info,
+ SkBackingFit::kApprox,
+ 1,
+ GrMipmapped::kNo,
+ isProtected,
+ kBottomLeft_GrSurfaceOrigin);
if (!sfc) {
return nullptr;
}
diff --git a/src/effects/imagefilters/SkBlendImageFilter.cpp b/src/effects/imagefilters/SkBlendImageFilter.cpp
index 321387f..5968888 100644
--- a/src/effects/imagefilters/SkBlendImageFilter.cpp
+++ b/src/effects/imagefilters/SkBlendImageFilter.cpp
@@ -312,7 +312,7 @@
fp = as_BB(fBlender)->asFragmentProcessor(std::move(fgFP), std::move(fp), args);
}
- auto sfc = GrSurfaceFillContext::Make(rContext, info, SkBackingFit::kApprox);
+ auto sfc = rContext->priv().makeSFC(info, SkBackingFit::kApprox);
if (!sfc) {
return nullptr;
}
diff --git a/src/effects/imagefilters/SkBlurImageFilter.cpp b/src/effects/imagefilters/SkBlurImageFilter.cpp
index 0610a0e..286f707 100644
--- a/src/effects/imagefilters/SkBlurImageFilter.cpp
+++ b/src/effects/imagefilters/SkBlurImageFilter.cpp
@@ -26,8 +26,10 @@
#if SK_SUPPORT_GPU
#include "src/gpu/GrTextureProxy.h"
#include "src/gpu/SkGr.h"
+#if SK_GPU_V1
#include "src/gpu/v1/SurfaceDrawContext_v1.h"
#endif
+#endif
namespace {
diff --git a/src/effects/imagefilters/SkDisplacementMapImageFilter.cpp b/src/effects/imagefilters/SkDisplacementMapImageFilter.cpp
index 15d5b0f..907d044 100644
--- a/src/effects/imagefilters/SkDisplacementMapImageFilter.cpp
+++ b/src/effects/imagefilters/SkDisplacementMapImageFilter.cpp
@@ -315,13 +315,12 @@
kPremul_SkAlphaType,
ctx.refColorSpace(),
bounds.size());
- auto sfc = GrSurfaceFillContext::Make(context,
- info,
- SkBackingFit::kApprox,
- 1,
- GrMipmapped::kNo,
- isProtected,
- kBottomLeft_GrSurfaceOrigin);
+ auto sfc = context->priv().makeSFC(info,
+ SkBackingFit::kApprox,
+ 1,
+ GrMipmapped::kNo,
+ isProtected,
+ kBottomLeft_GrSurfaceOrigin);
if (!sfc) {
return nullptr;
}
diff --git a/src/effects/imagefilters/SkLightingImageFilter.cpp b/src/effects/imagefilters/SkLightingImageFilter.cpp
index 20a3cb9..e756322 100644
--- a/src/effects/imagefilters/SkLightingImageFilter.cpp
+++ b/src/effects/imagefilters/SkLightingImageFilter.cpp
@@ -483,13 +483,12 @@
kPremul_SkAlphaType,
ctx.refColorSpace(),
offsetBounds.size());
- auto sfc = GrSurfaceFillContext::Make(rContext,
- info,
- SkBackingFit::kApprox,
- 1,
- GrMipmapped::kNo,
- inputView.proxy()->isProtected(),
- kBottomLeft_GrSurfaceOrigin);
+ auto sfc = rContext->priv().makeSFC(info,
+ SkBackingFit::kApprox,
+ 1,
+ GrMipmapped::kNo,
+ inputView.proxy()->isProtected(),
+ kBottomLeft_GrSurfaceOrigin);
if (!sfc) {
return nullptr;
}
diff --git a/src/effects/imagefilters/SkMorphologyImageFilter.cpp b/src/effects/imagefilters/SkMorphologyImageFilter.cpp
index 1c088f7..326207d 100644
--- a/src/effects/imagefilters/SkMorphologyImageFilter.cpp
+++ b/src/effects/imagefilters/SkMorphologyImageFilter.cpp
@@ -454,13 +454,12 @@
if (radius.fWidth > 0) {
GrImageInfo info(colorType, kPremul_SkAlphaType, colorSpace, rect.size());
- auto dstFillContext = GrSurfaceFillContext::Make(rContext,
- info,
- SkBackingFit::kApprox,
- 1,
- GrMipmapped::kNo,
- proxy->isProtected(),
- kBottomLeft_GrSurfaceOrigin);
+ auto dstFillContext = rContext->priv().makeSFC(info,
+ SkBackingFit::kApprox,
+ 1,
+ GrMipmapped::kNo,
+ proxy->isProtected(),
+ kBottomLeft_GrSurfaceOrigin);
if (!dstFillContext) {
return nullptr;
}
@@ -479,13 +478,12 @@
}
if (radius.fHeight > 0) {
GrImageInfo info(colorType, kPremul_SkAlphaType, colorSpace, rect.size());
- auto dstFillContext = GrSurfaceFillContext::Make(rContext,
- info,
- SkBackingFit::kApprox,
- 1,
- GrMipmapped::kNo,
- srcView.proxy()->isProtected(),
- kBottomLeft_GrSurfaceOrigin);
+ auto dstFillContext = rContext->priv().makeSFC(info,
+ SkBackingFit::kApprox,
+ 1,
+ GrMipmapped::kNo,
+ srcView.proxy()->isProtected(),
+ kBottomLeft_GrSurfaceOrigin);
if (!dstFillContext) {
return nullptr;
}
diff --git a/src/gpu/GrDirectContextPriv.cpp b/src/gpu/GrDirectContextPriv.cpp
index ba08749..cfd91c3 100644
--- a/src/gpu/GrDirectContextPriv.cpp
+++ b/src/gpu/GrDirectContextPriv.cpp
@@ -251,8 +251,8 @@
SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
const SkImageInfo upmII = pmII.makeAlphaType(kUnpremul_SkAlphaType);
- auto readSFC = GrSurfaceFillContext::Make(dContext, upmII, SkBackingFit::kExact);
- auto tempSFC = GrSurfaceFillContext::Make(dContext, pmII, SkBackingFit::kExact);
+ auto readSFC = dContext->priv().makeSFC(upmII, SkBackingFit::kExact);
+ auto tempSFC = dContext->priv().makeSFC(pmII, SkBackingFit::kExact);
if (!readSFC || !tempSFC) {
return false;
}
@@ -368,3 +368,44 @@
mipmapped, isProtected,
origin, props, init);
}
+
+std::unique_ptr<GrSurfaceContext> GrDirectContextPriv::makeSC(GrSurfaceProxyView readView,
+ const GrColorInfo& info) {
+ return fContext->GrRecordingContext::priv().makeSC(readView, info);
+}
+
+std::unique_ptr<GrSurfaceFillContext> GrDirectContextPriv::makeSFC(GrImageInfo info,
+ SkBackingFit fit,
+ int sampleCount,
+ GrMipmapped mipmapped,
+ GrProtected isProtected,
+ GrSurfaceOrigin origin,
+ SkBudgeted budgeted) {
+ return fContext->GrRecordingContext::priv().makeSFC(info, fit, sampleCount, mipmapped,
+ isProtected, origin, budgeted);
+}
+
+std::unique_ptr<GrSurfaceFillContext> GrDirectContextPriv::makeSFCWithFallback(
+ GrImageInfo info,
+ SkBackingFit fit,
+ int sampleCount,
+ GrMipmapped mipmapped,
+ GrProtected isProtected,
+ GrSurfaceOrigin origin,
+ SkBudgeted budgeted) {
+ return fContext->GrRecordingContext::priv().makeSFCWithFallback(info, fit, sampleCount,
+ mipmapped, isProtected,
+ origin, budgeted);
+}
+
+std::unique_ptr<GrSurfaceFillContext> GrDirectContextPriv::makeSFCFromBackendTexture(
+ GrColorInfo info,
+ const GrBackendTexture& tex,
+ int sampleCount,
+ GrSurfaceOrigin origin,
+ sk_sp<GrRefCntedCallback> releaseHelper) {
+ return fContext->GrRecordingContext::priv().makeSFCFromBackendTexture(info, tex, sampleCount,
+ origin,
+ std::move(releaseHelper));
+
+}
diff --git a/src/gpu/GrDirectContextPriv.h b/src/gpu/GrDirectContextPriv.h
index c25fd4f..e2c5393 100644
--- a/src/gpu/GrDirectContextPriv.h
+++ b/src/gpu/GrDirectContextPriv.h
@@ -16,6 +16,7 @@
class GrAtlasManager;
class GrBackendFormat;
class GrBackendRenderTarget;
+class GrImageInfo;
class GrMemoryPool;
class GrOnFlushCallbackObject;
class GrRenderTargetProxy;
@@ -161,6 +162,32 @@
const SkSurfaceProps&,
skgpu::BaseDevice::InitContents);
+ std::unique_ptr<GrSurfaceContext> makeSC(GrSurfaceProxyView readView, const GrColorInfo&);
+
+ std::unique_ptr<GrSurfaceFillContext> makeSFC(GrImageInfo,
+ SkBackingFit = SkBackingFit::kExact,
+ int sampleCount = 1,
+ GrMipmapped = GrMipmapped::kNo,
+ GrProtected = GrProtected::kNo,
+ GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin,
+ SkBudgeted = SkBudgeted::kYes);
+
+ std::unique_ptr<GrSurfaceFillContext> makeSFCWithFallback(
+ GrImageInfo,
+ SkBackingFit = SkBackingFit::kExact,
+ int sampleCount = 1,
+ GrMipmapped = GrMipmapped::kNo,
+ GrProtected = GrProtected::kNo,
+ GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin,
+ SkBudgeted = SkBudgeted::kYes);
+
+ std::unique_ptr<GrSurfaceFillContext> makeSFCFromBackendTexture(
+ GrColorInfo,
+ const GrBackendTexture&,
+ int sampleCount,
+ GrSurfaceOrigin,
+ sk_sp<GrRefCntedCallback> releaseHelper);
+
#if GR_TEST_UTILS
/** Reset GPU stats */
void resetGpuStats() const;
diff --git a/src/gpu/GrRecordingContextPriv.cpp b/src/gpu/GrRecordingContextPriv.cpp
index 084153f..fbd3048 100644
--- a/src/gpu/GrRecordingContextPriv.cpp
+++ b/src/gpu/GrRecordingContextPriv.cpp
@@ -9,12 +9,16 @@
#include "src/gpu/GrCaps.h"
#include "src/gpu/GrDrawingManager.h"
+#include "src/gpu/GrProxyProvider.h"
#include "src/gpu/GrRenderTargetProxy.h"
+#include "src/gpu/GrSurfaceProxyView.h"
#if SK_GPU_V1
#include "src/gpu/v1/Device_v1.h"
+#include "src/gpu/v1/SurfaceDrawContext_v1.h"
#endif
#if SK_GPU_V2
+#include "src/gpu/GrSurfaceFillContext.h"
#include "src/gpu/v2/Device_v2.h"
#endif
@@ -31,7 +35,7 @@
origin, props, init);
#else
return nullptr;
-#endif
+#endif // GR_TEST_UTILS
} else
#endif
{
@@ -62,7 +66,7 @@
return nullptr;
#endif
} else
-#endif
+#endif // GR_TEST_UTILS
{
#if SK_GPU_V1
return skgpu::v1::Device::Make(fContext, budgeted, ii, fit, sampleCount,
@@ -84,3 +88,295 @@
this->options().fMinDistanceFieldFontSize,
this->options().fGlyphsAsPathsFontSize};
}
+
+std::unique_ptr<GrSurfaceContext> GrRecordingContextPriv::makeSC(GrSurfaceProxyView readView,
+ const GrColorInfo& info) {
+#if GR_TEST_UTILS
+ if (this->options().fUseSkGpuV2 == GrContextOptions::Enable::kYes) {
+#if SK_GPU_V2
+ return nullptr;
+#endif
+ } else
+#endif // GR_TEST_UTILS
+ {
+#if SK_GPU_V1
+ // It is probably not necessary to check if the context is abandoned here since uses of the
+ // GrSurfaceContext which need the context will mostly likely fail later on w/o an issue.
+ // However having this hear adds some reassurance in case there is a path doesn't handle an
+ // abandoned context correctly. It also lets us early out of some extra work.
+ if (fContext->abandoned()) {
+ return nullptr;
+ }
+ GrSurfaceProxy* proxy = readView.proxy();
+ SkASSERT(proxy && proxy->asTextureProxy());
+
+ std::unique_ptr<GrSurfaceContext> sc;
+ if (proxy->asRenderTargetProxy()) {
+ // Will we ever want a swizzle that is not the default write swizzle for the format and
+ // colorType here? If so we will need to manually pass that in.
+ GrSwizzle writeSwizzle;
+ if (info.colorType() != GrColorType::kUnknown) {
+ writeSwizzle = this->caps()->getWriteSwizzle(proxy->backendFormat(),
+ info.colorType());
+ }
+ GrSurfaceProxyView writeView(readView.refProxy(), readView.origin(), writeSwizzle);
+ if (info.alphaType() == kPremul_SkAlphaType ||
+ info.alphaType() == kOpaque_SkAlphaType) {
+ sc = std::make_unique<skgpu::v1::SurfaceDrawContext>(fContext,
+ std::move(readView),
+ std::move(writeView),
+ info.colorType(),
+ info.refColorSpace(),
+ SkSurfaceProps());
+ } else {
+ sc = std::make_unique<GrSurfaceFillContext>(fContext,
+ std::move(readView),
+ std::move(writeView),
+ info);
+ }
+ } else {
+ sc = std::make_unique<GrSurfaceContext>(fContext, std::move(readView), info);
+ }
+ SkDEBUGCODE(sc->validate();)
+ return sc;
+#endif
+ }
+
+ return nullptr;
+}
+
+std::unique_ptr<GrSurfaceFillContext> GrRecordingContextPriv::makeSFC(GrImageInfo info,
+ SkBackingFit fit,
+ int sampleCount,
+ GrMipmapped mipmapped,
+ GrProtected isProtected,
+ GrSurfaceOrigin origin,
+ SkBudgeted budgeted) {
+
+#if GR_TEST_UTILS
+ if (this->options().fUseSkGpuV2 == GrContextOptions::Enable::kYes) {
+#if SK_GPU_V2
+ return nullptr;
+#endif
+ } else
+#endif // GR_TEST_UTILS
+ {
+#if SK_GPU_V1
+ if (info.alphaType() == kPremul_SkAlphaType || info.alphaType() == kOpaque_SkAlphaType) {
+ return skgpu::v1::SurfaceDrawContext::Make(fContext,
+ info.colorType(),
+ info.refColorSpace(),
+ fit,
+ info.dimensions(),
+ SkSurfaceProps(),
+ sampleCount,
+ mipmapped,
+ isProtected,
+ origin,
+ budgeted);
+ }
+ GrBackendFormat format = this->caps()->getDefaultBackendFormat(info.colorType(),
+ GrRenderable::kYes);
+ sk_sp<GrTextureProxy> proxy = this->proxyProvider()->createProxy(format,
+ info.dimensions(),
+ GrRenderable::kYes,
+ sampleCount,
+ mipmapped,
+ fit,
+ budgeted,
+ isProtected);
+ if (!proxy) {
+ return nullptr;
+ }
+ GrSwizzle readSwizzle = this->caps()->getReadSwizzle (format, info.colorType());
+ GrSwizzle writeSwizzle = this->caps()->getWriteSwizzle(format, info.colorType());
+
+ GrSurfaceProxyView readView( proxy, origin, readSwizzle);
+ GrSurfaceProxyView writeView(std::move(proxy), origin, writeSwizzle);
+ auto fillContext = std::make_unique<GrSurfaceFillContext>(fContext,
+ std::move(readView),
+ std::move(writeView),
+ info.colorInfo());
+ fillContext->discard();
+ return fillContext;
+#endif
+ }
+
+ return nullptr;
+}
+
+std::unique_ptr<GrSurfaceFillContext> GrRecordingContextPriv::makeSFC(SkAlphaType alphaType,
+ sk_sp<SkColorSpace> cs,
+ SkISize dimensions,
+ SkBackingFit fit,
+ const GrBackendFormat& format,
+ int sampleCount,
+ GrMipmapped mipmapped,
+ GrProtected isProtected,
+ GrSwizzle readSwizzle,
+ GrSwizzle writeSwizzle,
+ GrSurfaceOrigin origin,
+ SkBudgeted budgeted) {
+
+#if GR_TEST_UTILS
+ if (fContext->options().fUseSkGpuV2 == GrContextOptions::Enable::kYes) {
+#if SK_GPU_V2
+ return nullptr;
+#endif
+ } else
+#endif // GR_TEST_UTILS
+ {
+#if SK_GPU_V1
+ SkASSERT(!dimensions.isEmpty());
+ SkASSERT(sampleCount >= 1);
+ SkASSERT(format.isValid() && format.backend() == fContext->backend());
+ if (alphaType == kPremul_SkAlphaType || alphaType == kOpaque_SkAlphaType) {
+ return skgpu::v1::SurfaceDrawContext::Make(fContext,
+ std::move(cs),
+ fit,
+ dimensions,
+ format,
+ sampleCount,
+ mipmapped,
+ isProtected,
+ readSwizzle,
+ writeSwizzle,
+ origin,
+ budgeted,
+ SkSurfaceProps());
+ }
+
+ sk_sp<GrTextureProxy> proxy = this->proxyProvider()->createProxy(format,
+ dimensions,
+ GrRenderable::kYes,
+ sampleCount,
+ mipmapped,
+ fit,
+ budgeted,
+ isProtected);
+ if (!proxy) {
+ return nullptr;
+ }
+ GrImageInfo info(GrColorType::kUnknown, alphaType, std::move(cs), dimensions);
+ GrSurfaceProxyView readView( proxy, origin, readSwizzle);
+ GrSurfaceProxyView writeView(std::move(proxy), origin, writeSwizzle);
+ auto fillContext = std::make_unique<GrSurfaceFillContext>(fContext,
+ std::move(readView),
+ std::move(writeView),
+ info.colorInfo());
+ fillContext->discard();
+ return fillContext;
+#endif
+ }
+
+ return nullptr;
+}
+
+std::unique_ptr<GrSurfaceFillContext> GrRecordingContextPriv::makeSFCWithFallback(
+ GrImageInfo info,
+ SkBackingFit fit,
+ int sampleCount,
+ GrMipmapped mipmapped,
+ GrProtected isProtected,
+ GrSurfaceOrigin origin,
+ SkBudgeted budgeted) {
+
+#if GR_TEST_UTILS
+ if (this->options().fUseSkGpuV2 == GrContextOptions::Enable::kYes) {
+#if SK_GPU_V2
+ return nullptr;
+#endif
+ } else
+#endif // GR_TEST_UTILS
+ {
+#if SK_GPU_V1
+ if (info.alphaType() == kPremul_SkAlphaType || info.alphaType() == kOpaque_SkAlphaType) {
+ return skgpu::v1::SurfaceDrawContext::MakeWithFallback(fContext,
+ info.colorType(),
+ info.refColorSpace(),
+ fit,
+ info.dimensions(),
+ SkSurfaceProps(),
+ sampleCount,
+ mipmapped,
+ isProtected,
+ origin,
+ budgeted);
+ }
+ const GrCaps* caps = this->caps();
+
+ auto [ct, _] = caps->getFallbackColorTypeAndFormat(info.colorType(), sampleCount);
+ if (ct == GrColorType::kUnknown) {
+ return nullptr;
+ }
+ info = info.makeColorType(ct);
+ return this->makeSFC(info,
+ fit,
+ sampleCount,
+ mipmapped,
+ isProtected,
+ origin,
+ budgeted);
+#endif
+ }
+
+ return nullptr;
+}
+
+std::unique_ptr<GrSurfaceFillContext> GrRecordingContextPriv::makeSFCFromBackendTexture(
+ GrColorInfo info,
+ const GrBackendTexture& tex,
+ int sampleCount,
+ GrSurfaceOrigin origin,
+ sk_sp<GrRefCntedCallback> releaseHelper) {
+
+#if GR_TEST_UTILS
+ if (this->options().fUseSkGpuV2 == GrContextOptions::Enable::kYes) {
+#if SK_GPU_V2
+ return nullptr;
+#endif
+ } else
+#endif // GR_TEST_UTILS
+ {
+#if SK_GPU_V1
+ SkASSERT(sampleCount > 0);
+
+ if (info.alphaType() == kPremul_SkAlphaType || info.alphaType() == kOpaque_SkAlphaType) {
+ return skgpu::v1::SurfaceDrawContext::MakeFromBackendTexture(fContext,
+ info.colorType(),
+ info.refColorSpace(),
+ tex,
+ sampleCount,
+ origin,
+ SkSurfaceProps(),
+ std::move(releaseHelper));
+ }
+ const GrBackendFormat& format = tex.getBackendFormat();
+ GrSwizzle readSwizzle, writeSwizzle;
+ if (info.colorType() != GrColorType::kUnknown) {
+ if (!this->caps()->areColorTypeAndFormatCompatible(info.colorType(), format)) {
+ return nullptr;
+ }
+ readSwizzle = this->caps()->getReadSwizzle (format, info.colorType());
+ writeSwizzle = this->caps()->getWriteSwizzle(format, info.colorType());
+ }
+
+ sk_sp<GrTextureProxy> proxy(this->proxyProvider()->wrapRenderableBackendTexture(
+ tex, sampleCount, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
+ std::move(releaseHelper)));
+ if (!proxy) {
+ return nullptr;
+ }
+
+ GrSurfaceProxyView readView( proxy, origin, readSwizzle);
+ GrSurfaceProxyView writeView(std::move(proxy), origin, writeSwizzle);
+
+ return std::make_unique<GrSurfaceFillContext>(fContext,
+ std::move(readView),
+ std::move(writeView),
+ std::move(info));
+#endif
+ }
+
+ return nullptr;
+}
diff --git a/src/gpu/GrRecordingContextPriv.h b/src/gpu/GrRecordingContextPriv.h
index 8edd06e6..6110bc1 100644
--- a/src/gpu/GrRecordingContextPriv.h
+++ b/src/gpu/GrRecordingContextPriv.h
@@ -13,6 +13,8 @@
#include "src/gpu/BaseDevice.h"
#include "src/gpu/text/GrSDFTControl.h"
+class GrImageInfo;
+class GrSwizzle;
class SkDeferredDisplayList;
/** Class that exposes methods to GrRecordingContext that are only intended for use internal to
@@ -134,6 +136,66 @@
const SkSurfaceProps&,
skgpu::BaseDevice::InitContents);
+ // If the passed in GrSurfaceProxy is renderable this will return a SurfaceDrawContext,
+ // otherwise it will return a GrSurfaceContext.
+ std::unique_ptr<GrSurfaceContext> makeSC(GrSurfaceProxyView readView,
+ const GrColorInfo&);
+
+ /**
+ * Uses GrImageInfo's color type to pick the default texture format. Will return a
+ * SurfaceDrawContext if possible.
+ */
+ std::unique_ptr<GrSurfaceFillContext> makeSFC(GrImageInfo,
+ SkBackingFit = SkBackingFit::kExact,
+ int sampleCount = 1,
+ GrMipmapped = GrMipmapped::kNo,
+ GrProtected = GrProtected::kNo,
+ GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin,
+ SkBudgeted = SkBudgeted::kYes);
+
+ /**
+ * Makes a custom configured GrSurfaceFillContext where the caller specifies the specific
+ * texture format and swizzles. The color type will be kUnknown. Returns a SurfaceDrawContext
+ * if possible.
+ */
+ std::unique_ptr<GrSurfaceFillContext> makeSFC(SkAlphaType,
+ sk_sp<SkColorSpace>,
+ SkISize dimensions,
+ SkBackingFit,
+ const GrBackendFormat&,
+ int sampleCount,
+ GrMipmapped,
+ GrProtected,
+ GrSwizzle readSwizzle,
+ GrSwizzle writeSwizzle,
+ GrSurfaceOrigin,
+ SkBudgeted);
+
+ /**
+ * Like the above but uses GetFallbackColorTypeAndFormat to find a fallback color type (and
+ * compatible format) if the passed GrImageInfo's color type is not renderable.
+ */
+ std::unique_ptr<GrSurfaceFillContext> makeSFCWithFallback(
+ GrImageInfo,
+ SkBackingFit = SkBackingFit::kExact,
+ int sampleCount = 1,
+ GrMipmapped = GrMipmapped::kNo,
+ GrProtected = GrProtected::kNo,
+ GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin,
+ SkBudgeted = SkBudgeted::kYes);
+
+ /**
+ * Creates a GrSurfaceFillContext from an existing GrBackendTexture. The GrColorInfo's color
+ * type must be compatible with backend texture's format or this will fail. All formats are
+ * considered compatible with kUnknown. Returns a SurfaceDrawContext if possible.
+ */
+ std::unique_ptr<GrSurfaceFillContext> makeSFCFromBackendTexture(
+ GrColorInfo,
+ const GrBackendTexture&,
+ int sampleCount,
+ GrSurfaceOrigin,
+ sk_sp<GrRefCntedCallback> releaseHelper);
+
private:
explicit GrRecordingContextPriv(GrRecordingContext* context) : fContext(context) {}
GrRecordingContextPriv(const GrRecordingContextPriv&) = delete;
diff --git a/src/gpu/GrSurfaceContext.cpp b/src/gpu/GrSurfaceContext.cpp
index 7eda9a2..72c95f5 100644
--- a/src/gpu/GrSurfaceContext.cpp
+++ b/src/gpu/GrSurfaceContext.cpp
@@ -28,56 +28,12 @@
#include "src/gpu/SkGr.h"
#include "src/gpu/effects/GrBicubicEffect.h"
#include "src/gpu/effects/GrTextureEffect.h"
-#include "src/gpu/v1/SurfaceDrawContext_v1.h"
#define ASSERT_SINGLE_OWNER GR_ASSERT_SINGLE_OWNER(this->singleOwner())
#define RETURN_FALSE_IF_ABANDONED if (this->fContext->abandoned()) { return false; }
#define RETURN_NULLPTR_IF_ABANDONED if (this->fContext->abandoned()) { return nullptr; }
std::unique_ptr<GrSurfaceContext> GrSurfaceContext::Make(GrRecordingContext* rContext,
- GrSurfaceProxyView readView,
- const GrColorInfo& info) {
- // It is probably not necessary to check if the context is abandoned here since uses of the
- // GrSurfaceContext which need the context will mostly likely fail later on without an issue.
- // However having this hear adds some reassurance in case there is a path doesn't handle an
- // abandoned context correctly. It also lets us early out of some extra work.
- if (rContext->abandoned()) {
- return nullptr;
- }
- GrSurfaceProxy* proxy = readView.proxy();
- SkASSERT(proxy && proxy->asTextureProxy());
-
- std::unique_ptr<GrSurfaceContext> surfaceContext;
- if (proxy->asRenderTargetProxy()) {
- // Will we ever want a swizzle that is not the default write swizzle for the format and
- // colorType here? If so we will need to manually pass that in.
- GrSwizzle writeSwizzle;
- if (info.colorType() != GrColorType::kUnknown) {
- writeSwizzle = rContext->priv().caps()->getWriteSwizzle(proxy->backendFormat(),
- info.colorType());
- }
- GrSurfaceProxyView writeView(readView.refProxy(), readView.origin(), writeSwizzle);
- if (info.alphaType() == kPremul_SkAlphaType || info.alphaType() == kOpaque_SkAlphaType) {
- surfaceContext = std::make_unique<skgpu::v1::SurfaceDrawContext>(rContext,
- std::move(readView),
- std::move(writeView),
- info.colorType(),
- info.refColorSpace(),
- SkSurfaceProps());
- } else {
- surfaceContext = std::make_unique<GrSurfaceFillContext>(rContext,
- std::move(readView),
- std::move(writeView),
- info);
- }
- } else {
- surfaceContext = std::make_unique<GrSurfaceContext>(rContext, std::move(readView), info);
- }
- SkDEBUGCODE(surfaceContext->validate();)
- return surfaceContext;
-}
-
-std::unique_ptr<GrSurfaceContext> GrSurfaceContext::Make(GrRecordingContext* context,
const GrImageInfo& info,
const GrBackendFormat& format,
SkBackingFit fit,
@@ -87,34 +43,34 @@
GrMipmapped mipmapped,
GrProtected isProtected,
SkBudgeted budgeted) {
- SkASSERT(context);
+ SkASSERT(rContext);
SkASSERT(renderable == GrRenderable::kYes || sampleCount == 1);
- if (context->abandoned()) {
+ if (rContext->abandoned()) {
return nullptr;
}
- sk_sp<GrTextureProxy> proxy = context->priv().proxyProvider()->createProxy(format,
- info.dimensions(),
- renderable,
- sampleCount,
- mipmapped,
- fit,
- budgeted,
- isProtected);
+ sk_sp<GrTextureProxy> proxy = rContext->priv().proxyProvider()->createProxy(format,
+ info.dimensions(),
+ renderable,
+ sampleCount,
+ mipmapped,
+ fit,
+ budgeted,
+ isProtected);
if (!proxy) {
return nullptr;
}
GrSwizzle swizzle;
if (info.colorType() != GrColorType::kUnknown &&
- !context->priv().caps()->isFormatCompressed(format)) {
- swizzle = context->priv().caps()->getReadSwizzle(format, info.colorType());
+ !rContext->priv().caps()->isFormatCompressed(format)) {
+ swizzle = rContext->priv().caps()->getReadSwizzle(format, info.colorType());
}
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
- return GrSurfaceContext::Make(context, std::move(view), info.colorInfo());
+ return rContext->priv().makeSC(std::move(view), info.colorInfo());
}
-std::unique_ptr<GrSurfaceContext> GrSurfaceContext::Make(GrRecordingContext* context,
+std::unique_ptr<GrSurfaceContext> GrSurfaceContext::Make(GrRecordingContext* rContext,
const GrImageInfo& info,
SkBackingFit fit,
GrSurfaceOrigin origin,
@@ -123,9 +79,9 @@
GrMipmapped mipmapped,
GrProtected isProtected,
SkBudgeted budgeted) {
- GrBackendFormat format = context->priv().caps()->getDefaultBackendFormat(info.colorType(),
- renderable);
- return Make(context,
+ GrBackendFormat format = rContext->priv().caps()->getDefaultBackendFormat(info.colorType(),
+ renderable);
+ return Make(rContext,
info,
format,
fit,
@@ -246,7 +202,7 @@
alphaType,
this->colorInfo().refColorSpace(),
dst.dimensions());
- auto sfc = GrSurfaceFillContext::Make(dContext, tempInfo, SkBackingFit::kApprox);
+ auto sfc = dContext->priv().makeSFC(tempInfo, SkBackingFit::kApprox);
if (!sfc) {
return false;
}
@@ -302,7 +258,7 @@
return false;
}
GrSurfaceProxyView view{std::move(copy), this->origin(), this->readSwizzle()};
- tempCtx = GrSurfaceContext::Make(dContext, std::move(view), this->colorInfo());
+ tempCtx = dContext->priv().makeSC(std::move(view), this->colorInfo());
SkASSERT(tempCtx);
}
return tempCtx->readPixels(dContext, dst, pt);
@@ -948,11 +904,11 @@
}
auto yInfo = SkImageInfo::MakeA8(dstSize);
- auto yFC = GrSurfaceFillContext::MakeWithFallback(dContext, yInfo, SkBackingFit::kApprox);
+ auto yFC = dContext->priv().makeSFCWithFallback(yInfo, SkBackingFit::kApprox);
auto uvInfo = yInfo.makeWH(yInfo.width()/2, yInfo.height()/2);
- auto uFC = GrSurfaceFillContext::MakeWithFallback(dContext, uvInfo, SkBackingFit::kApprox);
- auto vFC = GrSurfaceFillContext::MakeWithFallback(dContext, uvInfo, SkBackingFit::kApprox);
+ auto uFC = dContext->priv().makeSFCWithFallback(uvInfo, SkBackingFit::kApprox);
+ auto vFC = dContext->priv().makeSFCWithFallback(uvInfo, SkBackingFit::kApprox);
if (!yFC || !uFC || !vFC) {
callback(callbackContext, nullptr);
@@ -1155,13 +1111,12 @@
SkIRect srcRect,
RescaleGamma rescaleGamma,
RescaleMode rescaleMode) {
- auto sfc = GrSurfaceFillContext::MakeWithFallback(fContext,
- info,
- SkBackingFit::kExact,
- 1,
- GrMipmapped::kNo,
- this->asSurfaceProxy()->isProtected(),
- origin);
+ auto sfc = fContext->priv().makeSFCWithFallback(info,
+ SkBackingFit::kExact,
+ 1,
+ GrMipmapped::kNo,
+ this->asSurfaceProxy()->isProtected(),
+ origin);
if (!sfc || !this->rescaleInto(sfc.get(),
SkIRect::MakeSize(sfc->dimensions()),
srcRect,
@@ -1225,13 +1180,12 @@
dst->colorInfo().alphaType(),
std::move(cs),
srcRect.size());
- auto linearRTC = GrSurfaceFillContext::MakeWithFallback(fContext,
- std::move(ii),
- SkBackingFit::kApprox,
- 1,
- GrMipmapped::kNo,
- GrProtected::kNo,
- dst->origin());
+ auto linearRTC = fContext->priv().makeSFCWithFallback(std::move(ii),
+ SkBackingFit::kApprox,
+ 1,
+ GrMipmapped::kNo,
+ GrProtected::kNo,
+ dst->origin());
if (!linearRTC) {
return false;
}
@@ -1274,9 +1228,7 @@
xform = GrColorSpaceXform::Make(input->colorInfo(), dst->colorInfo());
} else {
GrImageInfo nextInfo(input->colorInfo(), nextDims);
- tempB = GrSurfaceFillContext::MakeWithFallback(fContext,
- nextInfo,
- SkBackingFit::kApprox);
+ tempB = fContext->priv().makeSFCWithFallback(nextInfo, SkBackingFit::kApprox);
if (!tempB) {
return false;
}
diff --git a/src/gpu/GrSurfaceContext.h b/src/gpu/GrSurfaceContext.h
index f8a1cb7..069c562 100644
--- a/src/gpu/GrSurfaceContext.h
+++ b/src/gpu/GrSurfaceContext.h
@@ -38,12 +38,6 @@
*/
class GrSurfaceContext {
public:
- // If the passed in GrSurfaceProxy is renderable this will return a SurfaceDrawContext,
- // otherwise it will return a GrSurfaceContext.
- static std::unique_ptr<GrSurfaceContext> Make(GrRecordingContext*,
- GrSurfaceProxyView readView,
- const GrColorInfo&);
-
// Makes either a GrSurfaceContext, GrFillDrawContext, or a SurfaceDrawContext, depending on
// GrRenderable and the GrImageInfo.
static std::unique_ptr<GrSurfaceContext> Make(GrRecordingContext*,
@@ -234,6 +228,7 @@
ReadPixelsContext);
private:
+ friend class GrRecordingContextPriv; // for validate
friend class GrSurfaceProxy; // for copy
SkDEBUGCODE(virtual void onValidate() const {})
diff --git a/src/gpu/GrSurfaceFillContext.cpp b/src/gpu/GrSurfaceFillContext.cpp
index 9a560bf..8d9a439 100644
--- a/src/gpu/GrSurfaceFillContext.cpp
+++ b/src/gpu/GrSurfaceFillContext.cpp
@@ -15,7 +15,6 @@
#include "src/gpu/geometry/GrRect.h"
#include "src/gpu/ops/GrClearOp.h"
#include "src/gpu/ops/GrFillRectOp.h"
-#include "src/gpu/v1/SurfaceDrawContext_v1.h"
#define ASSERT_SINGLE_OWNER GR_ASSERT_SINGLE_OWNER(this->singleOwner())
#define RETURN_IF_ABANDONED if (fContext->abandoned()) { return; }
@@ -31,193 +30,6 @@
GrDrawingManager* fDrawingManager;
};
-std::unique_ptr<GrSurfaceFillContext> GrSurfaceFillContext::Make(GrRecordingContext* rContext,
- SkAlphaType alphaType,
- sk_sp<SkColorSpace> colorSpace,
- SkISize dimensions,
- SkBackingFit fit,
- const GrBackendFormat& format,
- int sampleCount,
- GrMipmapped mipmapped,
- GrProtected isProtected,
- GrSwizzle readSwizzle,
- GrSwizzle writeSwizzle,
- GrSurfaceOrigin origin,
- SkBudgeted budgeted) {
- SkASSERT(rContext);
- SkASSERT(!dimensions.isEmpty());
- SkASSERT(sampleCount >= 1);
- SkASSERT(format.isValid() && format.backend() == rContext->backend());
- if (alphaType == kPremul_SkAlphaType || alphaType == kOpaque_SkAlphaType) {
- return skgpu::v1::SurfaceDrawContext::Make(rContext,
- std::move(colorSpace),
- fit,
- dimensions,
- format,
- sampleCount,
- mipmapped,
- isProtected,
- readSwizzle,
- writeSwizzle,
- origin,
- budgeted,
- SkSurfaceProps());
- }
-
- sk_sp<GrTextureProxy> proxy = rContext->priv().proxyProvider()->createProxy(format,
- dimensions,
- GrRenderable::kYes,
- sampleCount,
- mipmapped,
- fit,
- budgeted,
- isProtected);
- if (!proxy) {
- return nullptr;
- }
- GrImageInfo info(GrColorType::kUnknown, alphaType, std::move(colorSpace), dimensions);
- GrSurfaceProxyView readView( proxy, origin, readSwizzle);
- GrSurfaceProxyView writeView(std::move(proxy), origin, writeSwizzle);
- auto fillContext = std::make_unique<GrSurfaceFillContext>(rContext,
- std::move(readView),
- std::move(writeView),
- info.colorInfo());
- fillContext->discard();
- return fillContext;
-}
-
-std::unique_ptr<GrSurfaceFillContext> GrSurfaceFillContext::Make(GrRecordingContext* rContext,
- GrImageInfo info,
- SkBackingFit fit,
- int sampleCount,
- GrMipmapped mipmapped,
- GrProtected isProtected,
- GrSurfaceOrigin origin,
- SkBudgeted budgeted) {
- if (info.alphaType() == kPremul_SkAlphaType || info.alphaType() == kOpaque_SkAlphaType) {
- return skgpu::v1::SurfaceDrawContext::Make(rContext,
- info.colorType(),
- info.refColorSpace(),
- fit,
- info.dimensions(),
- SkSurfaceProps(),
- sampleCount,
- mipmapped,
- isProtected,
- origin,
- budgeted);
- }
- GrBackendFormat format = rContext->priv().caps()->getDefaultBackendFormat(info.colorType(),
- GrRenderable::kYes);
- sk_sp<GrTextureProxy> proxy = rContext->priv().proxyProvider()->createProxy(format,
- info.dimensions(),
- GrRenderable::kYes,
- sampleCount,
- mipmapped,
- fit,
- budgeted,
- isProtected);
- if (!proxy) {
- return nullptr;
- }
- GrSwizzle readSwizzle = rContext->priv().caps()->getReadSwizzle (format, info.colorType());
- GrSwizzle writeSwizzle = rContext->priv().caps()->getWriteSwizzle(format, info.colorType());
-
- GrSurfaceProxyView readView( proxy, origin, readSwizzle);
- GrSurfaceProxyView writeView(std::move(proxy), origin, writeSwizzle);
- auto fillContext = std::make_unique<GrSurfaceFillContext>(rContext,
- std::move(readView),
- std::move(writeView),
- info.colorInfo());
- fillContext->discard();
- return fillContext;
-}
-
-std::unique_ptr<GrSurfaceFillContext> GrSurfaceFillContext::MakeWithFallback(
- GrRecordingContext* rContext,
- GrImageInfo info,
- SkBackingFit fit,
- int sampleCount,
- GrMipmapped mipmapped,
- GrProtected isProtected,
- GrSurfaceOrigin origin,
- SkBudgeted budgeted) {
- if (info.alphaType() == kPremul_SkAlphaType || info.alphaType() == kOpaque_SkAlphaType) {
- return skgpu::v1::SurfaceDrawContext::MakeWithFallback(rContext,
- info.colorType(),
- info.refColorSpace(),
- fit,
- info.dimensions(),
- SkSurfaceProps(),
- sampleCount,
- mipmapped,
- isProtected,
- origin,
- budgeted);
- }
- const GrCaps* caps = rContext->priv().caps();
-
- auto [ct, _] = caps->getFallbackColorTypeAndFormat(info.colorType(), sampleCount);
- if (ct == GrColorType::kUnknown) {
- return nullptr;
- }
- info = info.makeColorType(ct);
- return GrSurfaceFillContext::Make(rContext,
- info,
- fit,
- sampleCount,
- mipmapped,
- isProtected,
- origin,
- budgeted);
-}
-
-std::unique_ptr<GrSurfaceFillContext> GrSurfaceFillContext::MakeFromBackendTexture(
- GrRecordingContext* context,
- GrColorInfo info,
- const GrBackendTexture& tex,
- int sampleCount,
- GrSurfaceOrigin origin,
- sk_sp<GrRefCntedCallback> releaseHelper) {
- SkASSERT(sampleCount > 0);
-
- if (info.alphaType() == kPremul_SkAlphaType || info.alphaType() == kOpaque_SkAlphaType) {
- return skgpu::v1::SurfaceDrawContext::MakeFromBackendTexture(context,
- info.colorType(),
- info.refColorSpace(),
- tex,
- sampleCount,
- origin,
- SkSurfaceProps(),
- std::move(releaseHelper));
- }
- const GrBackendFormat& format = tex.getBackendFormat();
- GrSwizzle readSwizzle, writeSwizzle;
- if (info.colorType() != GrColorType::kUnknown) {
- if (!context->priv().caps()->areColorTypeAndFormatCompatible(info.colorType(), format)) {
- return nullptr;
- }
- readSwizzle = context->priv().caps()->getReadSwizzle (format, info.colorType());
- writeSwizzle = context->priv().caps()->getWriteSwizzle(format, info.colorType());
- }
-
- sk_sp<GrTextureProxy> proxy(context->priv().proxyProvider()->wrapRenderableBackendTexture(
- tex, sampleCount, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
- std::move(releaseHelper)));
- if (!proxy) {
- return nullptr;
- }
-
- GrSurfaceProxyView readView( proxy, origin, readSwizzle);
- GrSurfaceProxyView writeView(std::move(proxy), origin, writeSwizzle);
-
- return std::make_unique<GrSurfaceFillContext>(context,
- std::move(readView),
- std::move(writeView),
- std::move(info));
-
-}
-
// In MDB mode the reffing of the 'getLastOpsTask' call's result allows in-progress
// GrOpsTask to be picked up and added to by GrSurfaceFillContext lower in the call
// stack. When this occurs with a closed GrOpsTask, a new one will be allocated
diff --git a/src/gpu/GrSurfaceFillContext.h b/src/gpu/GrSurfaceFillContext.h
index 8d0b7f5..cbd268a 100644
--- a/src/gpu/GrSurfaceFillContext.h
+++ b/src/gpu/GrSurfaceFillContext.h
@@ -35,65 +35,6 @@
const GrColorInfo&,
bool flushTimeOpsTask = false);
- /**
- * Uses GrImageInfo's color type to pick the default texture format. Will return a
- * SurfaceDrawContext if possible.
- */
- static std::unique_ptr<GrSurfaceFillContext> Make(GrRecordingContext*,
- GrImageInfo,
- SkBackingFit = SkBackingFit::kExact,
- int sampleCount = 1,
- GrMipmapped = GrMipmapped::kNo,
- GrProtected = GrProtected::kNo,
- GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin,
- SkBudgeted = SkBudgeted::kYes);
-
- /**
- * Like the above but uses GetFallbackColorTypeAndFormat to find a fallback color type (and
- * compatible format) if the passed GrImageInfo's color type is not renderable.
- */
- static std::unique_ptr<GrSurfaceFillContext> MakeWithFallback(
- GrRecordingContext*,
- GrImageInfo,
- SkBackingFit = SkBackingFit::kExact,
- int sampleCount = 1,
- GrMipmapped = GrMipmapped::kNo,
- GrProtected = GrProtected::kNo,
- GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin,
- SkBudgeted = SkBudgeted::kYes);
-
- /**
- * Makes a custom configured GrSurfaceFillContext where the caller specifies the specific
- * texture format and swizzles. The color type will be kUnknown. Returns a SurfaceDrawContext
- * if possible.
- */
- static std::unique_ptr<GrSurfaceFillContext> Make(GrRecordingContext*,
- SkAlphaType,
- sk_sp<SkColorSpace>,
- SkISize dimensions,
- SkBackingFit,
- const GrBackendFormat&,
- int sampleCount,
- GrMipmapped,
- GrProtected,
- GrSwizzle readSwizzle,
- GrSwizzle writeSwizzle,
- GrSurfaceOrigin,
- SkBudgeted);
-
- /**
- * Creates a GrSurfaceFillContext from an existing GrBackendTexture. The GrColorInfo's color
- * type must be compatible with backend texture's format or this will fail. All formats are
- * considered compatible with kUnknown. Returns a SurfaceDrawContext if possible.
- */
- static std::unique_ptr<GrSurfaceFillContext> MakeFromBackendTexture(
- GrRecordingContext*,
- GrColorInfo,
- const GrBackendTexture&,
- int sampleCount,
- GrSurfaceOrigin,
- sk_sp<GrRefCntedCallback> releaseHelper);
-
GrSurfaceFillContext* asFillContext() override { return this; }
/**
diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp
index db96ad6..da7bb1f 100644
--- a/src/gpu/GrSurfaceProxy.cpp
+++ b/src/gpu/GrSurfaceProxy.cpp
@@ -298,19 +298,18 @@
}
}
if (src->asTextureProxy()) {
- auto dstContext = GrSurfaceFillContext::Make(context,
- kUnknown_SkAlphaType,
- nullptr,
- {width, height},
- fit,
- format,
- 1,
- mipMapped,
- src->isProtected(),
- GrSwizzle::RGBA(),
- GrSwizzle::RGBA(),
- origin,
- budgeted);
+ auto dstContext = context->priv().makeSFC(kUnknown_SkAlphaType,
+ nullptr,
+ {width, height},
+ fit,
+ format,
+ 1,
+ mipMapped,
+ src->isProtected(),
+ GrSwizzle::RGBA(),
+ GrSwizzle::RGBA(),
+ origin,
+ budgeted);
GrSurfaceProxyView view(std::move(src), origin, GrSwizzle::RGBA());
if (dstContext && dstContext->blitTexture(std::move(view), srcRect, dstPoint)) {
if (outTask) {
diff --git a/src/gpu/text/GrAtlasManager.cpp b/src/gpu/text/GrAtlasManager.cpp
index 667cbc2..92ac968 100644
--- a/src/gpu/text/GrAtlasManager.cpp
+++ b/src/gpu/text/GrAtlasManager.cpp
@@ -234,9 +234,8 @@
return false;
}
- auto sContext = GrSurfaceContext::Make(dContext,
- std::move(view),
- {colorType, kUnknown_SkAlphaType, nullptr});
+ auto sContext = dContext->priv().makeSC(std::move(view),
+ {colorType, kUnknown_SkAlphaType, nullptr});
if (!sContext || !sContext->asTextureProxy()) {
return false;
}
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 6b476de..14689ab 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -287,34 +287,32 @@
sk_sp<SkImage> SkImage_Gpu::onMakeColorTypeAndColorSpace(SkColorType targetCT,
sk_sp<SkColorSpace> targetCS,
- GrDirectContext* direct) const {
+ GrDirectContext* dContext) const {
SkColorInfo info(targetCT, this->alphaType(), std::move(targetCS));
- if (!fContext->priv().matches(direct)) {
+ if (!fContext->priv().matches(dContext)) {
return nullptr;
}
- auto surfaceFillContext = GrSurfaceFillContext::MakeWithFallback(
- direct,
- GrImageInfo(info, this->dimensions()),
- SkBackingFit::kExact);
- if (!surfaceFillContext) {
+ auto sfc = dContext->priv().makeSFCWithFallback(GrImageInfo(info, this->dimensions()),
+ SkBackingFit::kExact);
+ if (!sfc) {
return nullptr;
}
// We respecify info's CT because we called MakeWithFallback.
- auto ct = GrColorTypeToSkColorType(surfaceFillContext->colorInfo().colorType());
+ auto ct = GrColorTypeToSkColorType(sfc->colorInfo().colorType());
info = info.makeColorType(ct);
// Draw this image's texture into the SFC.
- auto [view, _] = this->asView(direct, GrMipmapped(this->hasMipmaps()));
+ auto [view, _] = this->asView(dContext, GrMipmapped(this->hasMipmaps()));
auto texFP = GrTextureEffect::Make(std::move(view), this->alphaType());
auto colorFP = GrColorSpaceXformEffect::Make(std::move(texFP),
this->imageInfo().colorInfo(),
info);
- surfaceFillContext->fillWithFP(std::move(colorFP));
+ sfc->fillWithFP(std::move(colorFP));
- return sk_make_sp<SkImage_Gpu>(sk_ref_sp(direct),
+ return sk_make_sp<SkImage_Gpu>(sk_ref_sp(dContext),
kNeedNewImageUniqueID,
- surfaceFillContext->readSurfaceView(),
+ sfc->readSurfaceView(),
std::move(info));
}
@@ -340,9 +338,7 @@
callback(context, nullptr);
return;
}
- auto ctx = GrSurfaceContext::Make(dContext,
- this->makeView(dContext),
- this->imageInfo().colorInfo());
+ auto ctx = dContext->priv().makeSC(this->makeView(dContext), this->imageInfo().colorInfo());
if (!ctx) {
callback(context, nullptr);
return;
@@ -365,9 +361,7 @@
callback(context, nullptr);
return;
}
- auto ctx = GrSurfaceContext::Make(dContext,
- this->makeView(dContext),
- this->imageInfo().colorInfo());
+ auto ctx = dContext->priv().makeSC(this->makeView(dContext), this->imageInfo().colorInfo());
if (!ctx) {
callback(context, nullptr);
return;
diff --git a/src/image/SkImage_GpuBase.cpp b/src/image/SkImage_GpuBase.cpp
index ab64bad..3b8f157 100644
--- a/src/image/SkImage_GpuBase.cpp
+++ b/src/image/SkImage_GpuBase.cpp
@@ -114,7 +114,7 @@
}
GrColorInfo colorInfo(ct, this->alphaType(), this->refColorSpace());
- auto sContext = GrSurfaceContext::Make(dContext, std::move(view), std::move(colorInfo));
+ auto sContext = dContext->priv().makeSC(std::move(view), std::move(colorInfo));
if (!sContext) {
return false;
}
@@ -174,7 +174,7 @@
SkASSERT(view);
GrColorInfo colorInfo(ct, this->alphaType(), this->refColorSpace());
- auto sContext = GrSurfaceContext::Make(dContext, std::move(view), colorInfo);
+ auto sContext = dContext->priv().makeSC(std::move(view), colorInfo);
if (!sContext) {
return false;
}
diff --git a/src/image/SkImage_GpuYUVA.cpp b/src/image/SkImage_GpuYUVA.cpp
index 19a8e62..6fe926c 100644
--- a/src/image/SkImage_GpuYUVA.cpp
+++ b/src/image/SkImage_GpuYUVA.cpp
@@ -150,25 +150,24 @@
}
std::tuple<GrSurfaceProxyView, GrColorType> SkImage_GpuYUVA::onAsView(
- GrRecordingContext* context,
+ GrRecordingContext* rContext,
GrMipmapped mipmapped,
GrImageTexGenPolicy) const {
- if (!fContext->priv().matches(context)) {
+ if (!fContext->priv().matches(rContext)) {
return {};
}
- auto sfc = GrSurfaceFillContext::Make(context,
- this->imageInfo(),
- SkBackingFit::kExact,
- /*sample count*/ 1,
- mipmapped,
- GrProtected::kNo,
- kTopLeft_GrSurfaceOrigin,
- SkBudgeted::kYes);
+ auto sfc = rContext->priv().makeSFC(this->imageInfo(),
+ SkBackingFit::kExact,
+ /*sample count*/ 1,
+ mipmapped,
+ GrProtected::kNo,
+ kTopLeft_GrSurfaceOrigin,
+ SkBudgeted::kYes);
if (!sfc) {
return {};
}
- const GrCaps& caps = *context->priv().caps();
+ const GrCaps& caps = *rContext->priv().caps();
auto fp = GrYUVtoRGBEffect::Make(fYUVAProxies, GrSamplerState::Filter::kNearest, caps);
if (fFromColorSpace) {
fp = GrColorSpaceXformEffect::Make(std::move(fp),
diff --git a/src/image/SkImage_Lazy.cpp b/src/image/SkImage_Lazy.cpp
index eece2cc..6763df9 100644
--- a/src/image/SkImage_Lazy.cpp
+++ b/src/image/SkImage_Lazy.cpp
@@ -327,14 +327,13 @@
kPremul_SkAlphaType,
/*color space*/ nullptr,
this->dimensions());
- auto surfaceFillContext = GrSurfaceFillContext::Make(ctx,
- info,
- SkBackingFit::kExact,
- 1,
- GrMipmapped::kNo,
- GrProtected::kNo,
- kTopLeft_GrSurfaceOrigin,
- budgeted);
+ auto surfaceFillContext = ctx->priv().makeSFC(info,
+ SkBackingFit::kExact,
+ 1,
+ GrMipmapped::kNo,
+ GrProtected::kNo,
+ kTopLeft_GrSurfaceOrigin,
+ budgeted);
if (!surfaceFillContext) {
return {};
}
diff --git a/tests/BackendAllocationTest.cpp b/tests/BackendAllocationTest.cpp
index 16d24ff..1cedf96 100644
--- a/tests/BackendAllocationTest.cpp
+++ b/tests/BackendAllocationTest.cpp
@@ -283,7 +283,7 @@
colorType);
GrSurfaceProxyView readView(proxy, kTopLeft_GrSurfaceOrigin, swizzle);
GrColorInfo info(colorType, kUnpremul_SkAlphaType, nullptr);
- auto surfaceContext = GrSurfaceContext::Make(dContext, readView, info);
+ auto surfaceContext = dContext->priv().makeSC(readView, info);
if (!surfaceContext) {
ERRORF(reporter, "Could not create surface context for colorType: %d\n", colorType);
}
@@ -378,7 +378,7 @@
}
GrImageInfo info(GrColorType::kRGBA_8888, kUnpremul_SkAlphaType, nullptr, {32, 32});
- auto dstFillContext = GrSurfaceFillContext::Make(dContext, info);
+ auto dstFillContext = dContext->priv().makeSFC(info);
if (!dstFillContext) {
ERRORF(reporter, "Could not make dst fill context.");
return;
diff --git a/tests/CopySurfaceTest.cpp b/tests/CopySurfaceTest.cpp
index 23d7ad4..baf928f 100644
--- a/tests/CopySurfaceTest.cpp
+++ b/tests/CopySurfaceTest.cpp
@@ -104,9 +104,8 @@
}
}
- auto dstContext = GrSurfaceContext::Make(dContext,
- std::move(dstView),
- ii.colorInfo());
+ auto dstContext = dContext->priv().makeSC(std::move(dstView),
+ ii.colorInfo());
bool result = false;
if (sOrigin == dOrigin) {
diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp
index 43e0e6f..5823835 100644
--- a/tests/EGLImageTest.cpp
+++ b/tests/EGLImageTest.cpp
@@ -165,7 +165,7 @@
GrSwizzle swizzle = context0->priv().caps()->getReadSwizzle(texProxy->backendFormat(),
colorInfo.colorType());
GrSurfaceProxyView view(std::move(texProxy), origin, swizzle);
- auto surfaceContext = GrSurfaceContext::Make(context0, std::move(view), colorInfo);
+ auto surfaceContext = context0->priv().makeSC(std::move(view), colorInfo);
if (!surfaceContext) {
ERRORF(reporter, "Error wrapping external texture in GrSurfaceContext.");
@@ -184,12 +184,11 @@
// Should not be able to wrap as a RT
{
- auto temp = GrSurfaceFillContext::MakeFromBackendTexture(context0,
- colorInfo,
- backendTex,
- 1,
- origin,
- /*release helper*/ nullptr);
+ auto temp = context0->priv().makeSFCFromBackendTexture(colorInfo,
+ backendTex,
+ 1,
+ origin,
+ /*release helper*/ nullptr);
if (temp) {
ERRORF(reporter, "Should not be able to wrap an EXTERNAL texture as a RT.");
}
diff --git a/tests/FloatingPointTextureTest.cpp b/tests/FloatingPointTextureTest.cpp
index c210b5b..ad18d90 100644
--- a/tests/FloatingPointTextureTest.cpp
+++ b/tests/FloatingPointTextureTest.cpp
@@ -60,7 +60,7 @@
continue;
}
- auto sContext = GrSurfaceContext::Make(dContext, std::move(fpView), info.colorInfo());
+ auto sContext = dContext->priv().makeSC(std::move(fpView), info.colorInfo());
REPORTER_ASSERT(reporter, sContext);
GrPixmap readPixmap(info, readBuffer.begin(), info.minRowBytes());
diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp
index 9244c0f..525788c 100644
--- a/tests/GrSurfaceTest.cpp
+++ b/tests/GrSurfaceTest.cpp
@@ -269,7 +269,7 @@
GrSurfaceProxyView view(std::move(proxy), kTopLeft_GrSurfaceOrigin,
swizzle);
GrColorInfo info(combo.fColorType, kPremul_SkAlphaType, nullptr);
- auto texCtx = GrSurfaceContext::Make(dContext, std::move(view), info);
+ auto texCtx = dContext->priv().makeSC(std::move(view), info);
readback.erase(kClearColor);
if (texCtx->readPixels(dContext, readback, {0, 0})) {
@@ -368,7 +368,7 @@
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(proxy->backendFormat(),
GrColorType::kRGBA_8888);
GrSurfaceProxyView view(proxy, kTopLeft_GrSurfaceOrigin, swizzle);
- auto surfContext = GrSurfaceContext::Make(dContext, std::move(view), ii.colorInfo());
+ auto surfContext = dContext->priv().makeSC(std::move(view), ii.colorInfo());
// Read pixels should work with a read-only texture.
{
SkAutoPixmapStorage read;
diff --git a/tests/ProcessorTest.cpp b/tests/ProcessorTest.cpp
index 1bc9bb4..a6f8188 100644
--- a/tests/ProcessorTest.cpp
+++ b/tests/ProcessorTest.cpp
@@ -393,7 +393,7 @@
SkImageInfo ii = SkImageInfo::Make(src.proxy()->dimensions(), kRGBA_8888_SkColorType,
kLogAlphaType);
- auto sContext = GrSurfaceContext::Make(dContext, std::move(src), ii.colorInfo());
+ auto sContext = dContext->priv().makeSC(std::move(src), ii.colorInfo());
SkBitmap bm;
SkAssertResult(bm.tryAllocPixels(ii));
SkAssertResult(sContext->readPixels(dContext, bm.pixmap(), {0, 0}));
diff --git a/tests/RectangleTextureTest.cpp b/tests/RectangleTextureTest.cpp
index 1ecdac9..8a7cbbb 100644
--- a/tests/RectangleTextureTest.cpp
+++ b/tests/RectangleTextureTest.cpp
@@ -25,14 +25,14 @@
static void test_basic_draw_as_src(skiatest::Reporter* reporter, GrDirectContext* dContext,
GrSurfaceProxyView rectView, GrColorType colorType,
SkAlphaType alphaType, uint32_t expectedPixelValues[]) {
- auto fillContext = GrSurfaceFillContext::Make(
- dContext, {colorType, kPremul_SkAlphaType, nullptr, rectView.dimensions()});
+ auto sfc = dContext->priv().makeSFC(
+ {colorType, kPremul_SkAlphaType, nullptr, rectView.dimensions()});
for (auto filter : {GrSamplerState::Filter::kNearest, GrSamplerState::Filter::kLinear}) {
for (auto mm : {GrSamplerState::MipmapMode::kNone, GrSamplerState::MipmapMode::kLinear}) {
- fillContext->clear(SkPMColor4f::FromBytes_RGBA(0xDDCCBBAA));
+ sfc->clear(SkPMColor4f::FromBytes_RGBA(0xDDCCBBAA));
auto fp = GrTextureEffect::Make(rectView, alphaType, SkMatrix::I(), filter, mm);
- fillContext->fillWithFP(std::move(fp));
- TestReadPixels(reporter, dContext, fillContext.get(), expectedPixelValues,
+ sfc->fillWithFP(std::move(fp));
+ TestReadPixels(reporter, dContext, sfc.get(), expectedPixelValues,
"RectangleTexture-basic-draw");
}
}
@@ -183,7 +183,7 @@
TestCopyFromSurface(reporter, dContext, rectProxy, origin, grII.colorType(), refPixels,
"RectangleTexture-copy-from");
- auto rectContext = GrSurfaceContext::Make(dContext, std::move(view), grII.colorInfo());
+ auto rectContext = dContext->priv().makeSC(std::move(view), grII.colorInfo());
SkASSERT(rectContext);
TestReadPixels(reporter, dContext, rectContext.get(), refPixels, "RectangleTexture-read");
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index 57a0ff1..2c0bc52 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -794,7 +794,7 @@
auto gpuImage = static_cast<SkImage_Gpu*>(as_IB(i));
auto [view, ct] = gpuImage->asView(dContext, GrMipmapped::kNo);
GrColorInfo colorInfo(ct, i->alphaType(), i->refColorSpace());
- return GrSurfaceContext::Make(dContext, view, std::move(colorInfo));
+ return dContext->priv().makeSC(view, std::move(colorInfo));
};
// Test that non-wrapped RTs are created clear.
diff --git a/tests/TestUtils.cpp b/tests/TestUtils.cpp
index 7a269e9..e983a6f 100644
--- a/tests/TestUtils.cpp
+++ b/tests/TestUtils.cpp
@@ -92,9 +92,8 @@
SkASSERT(copy && copy->asTextureProxy());
auto swizzle = dContext->priv().caps()->getReadSwizzle(copy->backendFormat(), colorType);
GrSurfaceProxyView view(std::move(copy), origin, swizzle);
- auto dstContext = GrSurfaceContext::Make(dContext,
- std::move(view),
- {colorType, kPremul_SkAlphaType, nullptr});
+ auto dstContext = dContext->priv().makeSC(std::move(view),
+ {colorType, kPremul_SkAlphaType, nullptr});
SkASSERT(dstContext);
TestReadPixels(reporter, dContext, dstContext.get(), expectedPixelValues, testName);
diff --git a/tools/gpu/ProxyUtils.cpp b/tools/gpu/ProxyUtils.cpp
index f2fe4e9..139ea27 100644
--- a/tools/gpu/ProxyUtils.cpp
+++ b/tools/gpu/ProxyUtils.cpp
@@ -78,7 +78,7 @@
return {};
}
GrSurfaceProxyView view(proxy, origin, swizzle);
- auto sContext = GrSurfaceContext::Make(dContext, std::move(view), pixmap.colorInfo());
+ auto sContext = dContext->priv().makeSC(std::move(view), pixmap.colorInfo());
if (!sContext) {
return {};
}