Update GrClipStackClip and GrDeviceSpaceTextureDecalFP to use views.
Bug: skia:9556
Change-Id: I61346e31b67ca1dffc5132e0af47aff4fdfc6e22
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/269907
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/GrClipStackClip.cpp b/src/gpu/GrClipStackClip.cpp
index 250a81a..283d3a8 100644
--- a/src/gpu/GrClipStackClip.cpp
+++ b/src/gpu/GrClipStackClip.cpp
@@ -77,8 +77,9 @@
////////////////////////////////////////////////////////////////////////////////
// set up the draw state to enable the aa clipping mask.
-static std::unique_ptr<GrFragmentProcessor> create_fp_for_mask(sk_sp<GrTextureProxy> mask,
+static std::unique_ptr<GrFragmentProcessor> create_fp_for_mask(GrSurfaceProxyView mask,
const SkIRect& devBound) {
+ SkASSERT(mask.asTextureProxy());
SkIRect domainTexels = SkIRect::MakeWH(devBound.width(), devBound.height());
return GrDeviceSpaceTextureDecalFragmentProcessor::Make(std::move(mask), domainTexels,
{devBound.fLeft, devBound.fTop});
@@ -270,7 +271,7 @@
if ((renderTargetContext->numSamples() <= 1 && reducedClip.maskRequiresAA()) ||
context->priv().caps()->avoidStencilBuffers() ||
renderTargetContext->wrapsVkSecondaryCB()) {
- sk_sp<GrTextureProxy> result;
+ GrSurfaceProxyView result;
if (UseSWOnlyPath(context, hasUserStencilSettings, renderTargetContext, reducedClip)) {
// The clip geometry is complex enough that it will be more efficient to create it
// entirely in software
@@ -341,38 +342,39 @@
SkDEBUGFAIL("Gen ID was not found in stack.");
}
-sk_sp<GrTextureProxy> GrClipStackClip::createAlphaClipMask(GrRecordingContext* context,
- const GrReducedClip& reducedClip) const {
+GrSurfaceProxyView GrClipStackClip::createAlphaClipMask(GrRecordingContext* context,
+ const GrReducedClip& reducedClip) const {
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
GrUniqueKey key;
create_clip_mask_key(reducedClip.maskGenID(), reducedClip.scissor(),
reducedClip.numAnalyticFPs(), &key);
- sk_sp<GrTextureProxy> proxy(proxyProvider->findOrCreateProxyByUniqueKey(
- key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin));
- if (proxy) {
- return proxy;
+ if (sk_sp<GrTextureProxy> proxy = proxyProvider->findOrCreateProxyByUniqueKey(
+ key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin)) {
+ GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(),
+ GrColorType::kAlpha_8);
+ return {std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle};
}
auto rtc = GrRenderTargetContext::MakeWithFallback(
context, GrColorType::kAlpha_8, nullptr, SkBackingFit::kApprox,
- {reducedClip.width(), reducedClip.height()}, 1, GrMipMapped::kNo, proxy->isProtected(),
+ {reducedClip.width(), reducedClip.height()}, 1, GrMipMapped::kNo, GrProtected::kNo,
kTopLeft_GrSurfaceOrigin);
if (!rtc) {
- return nullptr;
+ return {};
}
if (!reducedClip.drawAlphaClipMask(rtc.get())) {
- return nullptr;
+ return {};
}
- sk_sp<GrTextureProxy> result(rtc->asTextureProxyRef());
- if (!result) {
- return nullptr;
+ GrSurfaceProxyView result = rtc->readSurfaceView();
+ if (!result || !result.asTextureProxy()) {
+ return {};
}
- SkASSERT(result->origin() == kTopLeft_GrSurfaceOrigin);
- proxyProvider->assignUniqueKeyToProxy(key, result.get());
+ SkASSERT(result.origin() == kTopLeft_GrSurfaceOrigin);
+ proxyProvider->assignUniqueKeyToProxy(key, result.asTextureProxy());
add_invalidate_on_pop_message(context, *fStack, reducedClip.maskGenID(), key);
return result;
@@ -452,7 +454,7 @@
}
}
-sk_sp<GrTextureProxy> GrClipStackClip::createSoftwareClipMask(
+GrSurfaceProxyView GrClipStackClip::createSoftwareClipMask(
GrRecordingContext* context, const GrReducedClip& reducedClip,
GrRenderTargetContext* renderTargetContext) const {
GrUniqueKey key;
@@ -462,10 +464,11 @@
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
const GrCaps* caps = context->priv().caps();
- sk_sp<GrTextureProxy> proxy(proxyProvider->findOrCreateProxyByUniqueKey(
- key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin));
- if (proxy) {
- return proxy;
+ if (sk_sp<GrTextureProxy> proxy = proxyProvider->findOrCreateProxyByUniqueKey(
+ key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin)) {
+ GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(),
+ GrColorType::kAlpha_8);
+ return {std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle};
}
// The mask texture may be larger than necessary. We round out the clip bounds and pin the top
@@ -477,6 +480,7 @@
taskGroup = direct->priv().getTaskGroup();
}
+ GrSurfaceProxyView view;
if (taskGroup && renderTargetContext) {
// Create our texture proxy
GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kAlpha_8,
@@ -486,16 +490,16 @@
// 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(format,
- maskSpaceIBounds.size(),
- swizzle,
- GrRenderable::kNo,
- 1,
- kTopLeft_GrSurfaceOrigin,
- GrMipMapped::kNo,
- SkBackingFit::kApprox,
- SkBudgeted::kYes,
- GrProtected::kNo);
+ auto proxy = proxyProvider->createProxy(format,
+ maskSpaceIBounds.size(),
+ swizzle,
+ GrRenderable::kNo,
+ 1,
+ kTopLeft_GrSurfaceOrigin,
+ GrMipMapped::kNo,
+ SkBackingFit::kApprox,
+ SkBudgeted::kYes,
+ GrProtected::kNo);
auto uploader = std::make_unique<GrTDeferredProxyUploader<ClipMaskData>>(reducedClip);
GrTDeferredProxyUploader<ClipMaskData>* uploaderRaw = uploader.get();
@@ -514,20 +518,23 @@
taskGroup->add(std::move(drawAndUploadMask));
proxy->texPriv().setDeferredUploader(std::move(uploader));
+
+ view = {std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle};
} else {
GrSWMaskHelper helper;
if (!helper.init(maskSpaceIBounds)) {
- return nullptr;
+ return {};
}
draw_clip_elements_to_mask_helper(helper, reducedClip.maskElements(), reducedClip.scissor(),
reducedClip.initialState());
- proxy = helper.toTextureView(context, SkBackingFit::kApprox).asTextureProxyRef();
+ view = helper.toTextureView(context, SkBackingFit::kApprox);
}
- SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin);
- proxyProvider->assignUniqueKeyToProxy(key, proxy.get());
+ SkASSERT(view);
+ SkASSERT(view.origin() == kTopLeft_GrSurfaceOrigin);
+ proxyProvider->assignUniqueKeyToProxy(key, view.asTextureProxy());
add_invalidate_on_pop_message(context, *fStack, reducedClip.maskGenID(), key);
- return proxy;
+ return view;
}