Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit af5f9f0

Browse files
bsalomonSkia Commit-Bot
authored andcommitted
Remove GrDeviceSpaceTextureDecalFragmentProcessor.
It was used to sample clip masks using device coords. Replace with a more generic GrDeviceSpaceEffect that simply calls a child FP with sk_FragCoord. Also fix issue in GrQuadPerEdgeAA GP. It wouldn't setup coord transforms at all if they are all applied in the FS (explicit coords). Moreover, the GrGLSLGeometryProcessor::emitTransforms() helper required a valid VS var for local coords even when all FPs use explicit coords and wouldn't use a local coords var. Make CPP SkSL code gen for clone copy the explicit coord status of children. Change-Id: Ib8bb36028354405c8012f6e91e9eb46db75d16a6 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/271658 Commit-Queue: Brian Salomon <[email protected]> Reviewed-by: Brian Osman <[email protected]>
1 parent 7fba244 commit af5f9f0

File tree

10 files changed

+168
-174
lines changed

10 files changed

+168
-174
lines changed

gm/windowrectangles.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@
3333
#include "src/gpu/GrFixedClip.h"
3434
#include "src/gpu/GrFragmentProcessor.h"
3535
#include "src/gpu/GrPaint.h"
36+
#include "src/gpu/GrRecordingContextPriv.h"
3637
#include "src/gpu/GrReducedClip.h"
3738
#include "src/gpu/GrRenderTargetContext.h"
3839
#include "src/gpu/GrRenderTargetContextPriv.h"
3940
#include "src/gpu/GrStencilClip.h"
4041
#include "src/gpu/GrTextureProxy.h"
4142
#include "src/gpu/GrUserStencilSettings.h"
4243
#include "src/gpu/effects/GrTextureDomain.h"
44+
#include "src/gpu/effects/generated/GrDeviceSpaceEffect.h"
4345
#include "tools/ToolUtils.h"
4446

4547
#include <utility>
@@ -177,10 +179,17 @@ class AlphaOnlyClip final : public MaskOnlyClipBase {
177179
AlphaOnlyClip(GrSurfaceProxyView mask, int x, int y) : fMask(std::move(mask)), fX(x), fY(y) {}
178180

179181
private:
180-
bool apply(GrRecordingContext*, GrRenderTargetContext*, bool, bool, GrAppliedClip* out,
182+
bool apply(GrRecordingContext* ctx, GrRenderTargetContext*, bool, bool, GrAppliedClip* out,
181183
SkRect* bounds) const override {
182-
out->addCoverageFP(GrDeviceSpaceTextureDecalFragmentProcessor::Make(
183-
fMask, SkIRect::MakeSize(fMask.proxy()->dimensions()), {fX, fY}));
184+
GrSamplerState samplerState(GrSamplerState::WrapMode::kClampToBorder,
185+
GrSamplerState::Filter::kNearest);
186+
auto m = SkMatrix::MakeTrans(-fX, -fY);
187+
auto subset = SkRect::Make(fMask.dimensions());
188+
auto domain = bounds->makeOffset(-fX, -fY).makeInset(0.5, 0.5);
189+
auto fp = GrTextureEffect::MakeSubset(fMask, kPremul_SkAlphaType, m, samplerState, subset,
190+
domain, *ctx->priv().caps());
191+
fp = GrDeviceSpaceEffect::Make(std::move(fp));
192+
out->addCoverageFP(std::move(fp));
184193
return true;
185194
}
186195
GrSurfaceProxyView fMask;

gn/gpu.gni

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ skia_gpu_sources = [
374374
"$_src/gpu/effects/generated/GrConstColorProcessor.h",
375375
"$_src/gpu/effects/generated/GrEllipseEffect.cpp",
376376
"$_src/gpu/effects/generated/GrEllipseEffect.h",
377+
"$_src/gpu/effects/generated/GrDeviceSpaceEffect.cpp",
378+
"$_src/gpu/effects/generated/GrDeviceSpaceEffect.h",
377379
"$_src/gpu/effects/generated/GrHSLToRGBFilterEffect.cpp",
378380
"$_src/gpu/effects/generated/GrHSLToRGBFilterEffect.h",
379381
"$_src/gpu/effects/generated/GrLumaColorFilterEffect.cpp",

gn/sksl.gni

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ skia_gpu_processor_sources = [
4747
"$_src/gpu/effects/GrConfigConversionEffect.fp",
4848
"$_src/gpu/effects/GrConstColorProcessor.fp",
4949
"$_src/gpu/effects/GrColorMatrixFragmentProcessor.fp",
50+
"$_src/gpu/effects/GrDeviceSpaceEffect.fp",
5051
"$_src/gpu/effects/GrEllipseEffect.fp",
5152
"$_src/gpu/effects/GrHSLToRGBFilterEffect.fp",
5253
"$_src/gpu/effects/GrLumaColorFilterEffect.fp",

src/gpu/GrClipStackClip.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
* found in the LICENSE file.
66
*/
77

8+
#include "src/gpu/GrClipStackClip.h"
9+
810
#include "include/private/SkTo.h"
911
#include "src/core/SkClipOpPriv.h"
1012
#include "src/core/SkTaskGroup.h"
1113
#include "src/core/SkTraceEvent.h"
1214
#include "src/gpu/GrAppliedClip.h"
13-
#include "src/gpu/GrClipStackClip.h"
1415
#include "src/gpu/GrContextPriv.h"
1516
#include "src/gpu/GrDeferredProxyUploader.h"
1617
#include "src/gpu/GrDrawingManager.h"
@@ -26,6 +27,7 @@
2627
#include "src/gpu/effects/GrConvexPolyEffect.h"
2728
#include "src/gpu/effects/GrRRectEffect.h"
2829
#include "src/gpu/effects/GrTextureDomain.h"
30+
#include "src/gpu/effects/generated/GrDeviceSpaceEffect.h"
2931
#include "src/gpu/geometry/GrShape.h"
3032

3133
typedef SkClipStack::Element Element;
@@ -78,11 +80,18 @@ void GrClipStackClip::getConservativeBounds(int width, int height, SkIRect* devR
7880
////////////////////////////////////////////////////////////////////////////////
7981
// set up the draw state to enable the aa clipping mask.
8082
static std::unique_ptr<GrFragmentProcessor> create_fp_for_mask(GrSurfaceProxyView mask,
81-
const SkIRect& devBound) {
82-
SkASSERT(mask.asTextureProxy());
83-
SkIRect domainTexels = SkIRect::MakeWH(devBound.width(), devBound.height());
84-
return GrDeviceSpaceTextureDecalFragmentProcessor::Make(std::move(mask), domainTexels,
85-
{devBound.fLeft, devBound.fTop});
83+
const SkIRect& devBound,
84+
const GrCaps& caps) {
85+
GrSamplerState samplerState(GrSamplerState::WrapMode::kClampToBorder,
86+
GrSamplerState::Filter::kNearest);
87+
auto m = SkMatrix::MakeTrans(-devBound.fLeft, -devBound.fTop);
88+
auto subset = SkRect::Make(devBound.size());
89+
// We scissor to devBounds. The mask's texel centers are aligned to device space
90+
// pixel centers. Hence this domain of texture coordinates.
91+
auto domain = subset.makeInset(0.5, 0.5);
92+
auto fp = GrTextureEffect::MakeSubset(std::move(mask), kPremul_SkAlphaType, m, samplerState,
93+
subset, domain, caps);
94+
return GrDeviceSpaceEffect::Make(std::move(fp));
8695
}
8796

8897
// Does the path in 'element' require SW rendering? If so, return true (and,
@@ -283,7 +292,8 @@ bool GrClipStackClip::applyClipMask(GrRecordingContext* context,
283292
if (result) {
284293
// The mask's top left coord should be pinned to the rounded-out top left corner of
285294
// the clip's device space bounds.
286-
out->addCoverageFP(create_fp_for_mask(std::move(result), reducedClip.scissor()));
295+
out->addCoverageFP(create_fp_for_mask(std::move(result), reducedClip.scissor(),
296+
*context->priv().caps()));
287297
return true;
288298
}
289299

src/gpu/GrProcessor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class GrProcessor {
101101
kGrConicEffect_ClassID,
102102
kGrConstColorProcessor_ClassID,
103103
kGrConvexPolyEffect_ClassID,
104-
kGrDeviceSpaceTextureDecalFragmentProcessor_ClassID,
104+
kGrDeviceSpaceEffect_ClassID,
105105
kGrDiffuseLightingEffect_ClassID,
106106
kGrDisplacementMapEffect_ClassID,
107107
kGrDistanceFieldA8TextGeoProc_ClassID,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Use of this source code is governed by a BSD-style license that can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
in fragmentProcessor fp;
9+
10+
void main() {
11+
sk_OutColor = sample(fp, sk_InColor, sk_FragCoord.xy);
12+
}
13+
14+
@test(d) {
15+
std::unique_ptr<GrFragmentProcessor> fp;
16+
// We have a restriction that explicit coords only work for FPs with exactly one
17+
// coord transform.
18+
do {
19+
fp = GrProcessorUnitTest::MakeChildFP(d);
20+
} while (fp->numCoordTransforms() != 1);
21+
return GrDeviceSpaceEffect::Make(std::move(fp));
22+
}

src/gpu/effects/GrTextureDomain.cpp

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -314,123 +314,3 @@ void GrTextureDomain::GLDomain::setData(const GrGLSLProgramDataManager& pdman,
314314
std::copy_n(decalFilterWeights, 3, fPrevDeclFilterWeights);
315315
}
316316
}
317-
318-
///////////////////////////////////////////////////////////////////////////////
319-
320-
std::unique_ptr<GrFragmentProcessor> GrDeviceSpaceTextureDecalFragmentProcessor::Make(
321-
GrSurfaceProxyView view, const SkIRect& subset, const SkIPoint& deviceSpaceOffset) {
322-
return std::unique_ptr<GrFragmentProcessor>(new GrDeviceSpaceTextureDecalFragmentProcessor(
323-
std::move(view), subset, deviceSpaceOffset));
324-
}
325-
326-
GrDeviceSpaceTextureDecalFragmentProcessor::GrDeviceSpaceTextureDecalFragmentProcessor(
327-
GrSurfaceProxyView view, const SkIRect& subset, const SkIPoint& deviceSpaceOffset)
328-
: INHERITED(kGrDeviceSpaceTextureDecalFragmentProcessor_ClassID,
329-
kCompatibleWithCoverageAsAlpha_OptimizationFlag)
330-
, fTextureDomain(view.proxy(),
331-
GrTextureDomain::MakeTexelDomain(subset, GrTextureDomain::kDecal_Mode),
332-
GrTextureDomain::kDecal_Mode, GrTextureDomain::kDecal_Mode)
333-
, fTextureSampler(std::move(view), GrSamplerState::Filter::kNearest) {
334-
this->setTextureSamplerCnt(1);
335-
fDeviceSpaceOffset.fX = deviceSpaceOffset.fX - subset.fLeft;
336-
fDeviceSpaceOffset.fY = deviceSpaceOffset.fY - subset.fTop;
337-
}
338-
339-
GrDeviceSpaceTextureDecalFragmentProcessor::GrDeviceSpaceTextureDecalFragmentProcessor(
340-
const GrDeviceSpaceTextureDecalFragmentProcessor& that)
341-
: INHERITED(kGrDeviceSpaceTextureDecalFragmentProcessor_ClassID,
342-
kCompatibleWithCoverageAsAlpha_OptimizationFlag)
343-
, fTextureDomain(that.fTextureDomain)
344-
, fTextureSampler(that.fTextureSampler)
345-
, fDeviceSpaceOffset(that.fDeviceSpaceOffset) {
346-
this->setTextureSamplerCnt(1);
347-
}
348-
349-
std::unique_ptr<GrFragmentProcessor> GrDeviceSpaceTextureDecalFragmentProcessor::clone() const {
350-
return std::unique_ptr<GrFragmentProcessor>(
351-
new GrDeviceSpaceTextureDecalFragmentProcessor(*this));
352-
}
353-
354-
GrGLSLFragmentProcessor* GrDeviceSpaceTextureDecalFragmentProcessor::onCreateGLSLInstance() const {
355-
class GLSLProcessor : public GrGLSLFragmentProcessor {
356-
public:
357-
void emitCode(EmitArgs& args) override {
358-
const GrDeviceSpaceTextureDecalFragmentProcessor& dstdfp =
359-
args.fFp.cast<GrDeviceSpaceTextureDecalFragmentProcessor>();
360-
const char* scaleAndTranslateName;
361-
fScaleAndTranslateUni = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
362-
kHalf4_GrSLType,
363-
"scaleAndTranslate",
364-
&scaleAndTranslateName);
365-
args.fFragBuilder->codeAppendf("half2 coords = half2(sk_FragCoord.xy * %s.xy + %s.zw);",
366-
scaleAndTranslateName, scaleAndTranslateName);
367-
fGLDomain.sampleTexture(args.fFragBuilder,
368-
args.fUniformHandler,
369-
args.fShaderCaps,
370-
dstdfp.fTextureDomain,
371-
args.fOutputColor,
372-
SkString("coords"),
373-
args.fTexSamplers[0],
374-
args.fInputColor);
375-
}
376-
377-
protected:
378-
void onSetData(const GrGLSLProgramDataManager& pdman,
379-
const GrFragmentProcessor& fp) override {
380-
const GrDeviceSpaceTextureDecalFragmentProcessor& dstdfp =
381-
fp.cast<GrDeviceSpaceTextureDecalFragmentProcessor>();
382-
const auto& view = dstdfp.textureSampler(0).view();
383-
SkISize textureDims = view.proxy()->backingStoreDimensions();
384-
385-
fGLDomain.setData(pdman, dstdfp.fTextureDomain, view,
386-
dstdfp.textureSampler(0).samplerState());
387-
float iw = 1.f / textureDims.width();
388-
float ih = 1.f / textureDims.height();
389-
float scaleAndTransData[4] = {
390-
iw, ih,
391-
-dstdfp.fDeviceSpaceOffset.fX * iw, -dstdfp.fDeviceSpaceOffset.fY * ih
392-
};
393-
if (view.origin() == kBottomLeft_GrSurfaceOrigin) {
394-
scaleAndTransData[1] = -scaleAndTransData[1];
395-
scaleAndTransData[3] = 1 - scaleAndTransData[3];
396-
}
397-
pdman.set4fv(fScaleAndTranslateUni, 1, scaleAndTransData);
398-
}
399-
400-
private:
401-
GrTextureDomain::GLDomain fGLDomain;
402-
UniformHandle fScaleAndTranslateUni;
403-
};
404-
405-
return new GLSLProcessor;
406-
}
407-
408-
bool GrDeviceSpaceTextureDecalFragmentProcessor::onIsEqual(const GrFragmentProcessor& fp) const {
409-
const GrDeviceSpaceTextureDecalFragmentProcessor& dstdfp =
410-
fp.cast<GrDeviceSpaceTextureDecalFragmentProcessor>();
411-
return dstdfp.fTextureSampler.view().proxy()->underlyingUniqueID() ==
412-
fTextureSampler.view().proxy()->underlyingUniqueID() &&
413-
dstdfp.fDeviceSpaceOffset == fDeviceSpaceOffset &&
414-
dstdfp.fTextureDomain == fTextureDomain;
415-
}
416-
417-
///////////////////////////////////////////////////////////////////////////////
418-
419-
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDeviceSpaceTextureDecalFragmentProcessor);
420-
421-
#if GR_TEST_UTILS
422-
std::unique_ptr<GrFragmentProcessor> GrDeviceSpaceTextureDecalFragmentProcessor::TestCreate(
423-
GrProcessorTestData* d) {
424-
auto [view, at, ct] = d->randomView();
425-
SkIRect subset;
426-
subset.fLeft = d->fRandom->nextULessThan(view.width() - 1);
427-
subset.fRight = d->fRandom->nextRangeU(subset.fLeft, view.width());
428-
subset.fTop = d->fRandom->nextULessThan(view.height() - 1);
429-
subset.fBottom = d->fRandom->nextRangeU(subset.fTop, view.height());
430-
SkIPoint pt;
431-
pt.fX = d->fRandom->nextULessThan(2048);
432-
pt.fY = d->fRandom->nextULessThan(2048);
433-
434-
return GrDeviceSpaceTextureDecalFragmentProcessor::Make(std::move(view), subset, pt);
435-
}
436-
#endif

src/gpu/effects/GrTextureDomain.h

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -231,47 +231,4 @@ class GrTextureDomain {
231231
int fIndex;
232232
};
233233

234-
class GrDeviceSpaceTextureDecalFragmentProcessor : public GrFragmentProcessor {
235-
public:
236-
static std::unique_ptr<GrFragmentProcessor> Make(GrSurfaceProxyView,
237-
const SkIRect& subset,
238-
const SkIPoint& deviceSpaceOffset);
239-
240-
const char* name() const override { return "GrDeviceSpaceTextureDecalFragmentProcessor"; }
241-
242-
#ifdef SK_DEBUG
243-
SkString dumpInfo() const override {
244-
SkString str;
245-
str.appendf("Domain: [L: %.2f, T: %.2f, R: %.2f, B: %.2f] Offset: [%d %d]",
246-
fTextureDomain.domain().fLeft, fTextureDomain.domain().fTop,
247-
fTextureDomain.domain().fRight, fTextureDomain.domain().fBottom,
248-
fDeviceSpaceOffset.fX, fDeviceSpaceOffset.fY);
249-
str.append(INHERITED::dumpInfo());
250-
return str;
251-
}
252-
#endif
253-
254-
std::unique_ptr<GrFragmentProcessor> clone() const override;
255-
256-
private:
257-
GrTextureDomain fTextureDomain;
258-
TextureSampler fTextureSampler;
259-
SkIPoint fDeviceSpaceOffset;
260-
261-
GrDeviceSpaceTextureDecalFragmentProcessor(GrSurfaceProxyView, const SkIRect&, const SkIPoint&);
262-
GrDeviceSpaceTextureDecalFragmentProcessor(const GrDeviceSpaceTextureDecalFragmentProcessor&);
263-
264-
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
265-
266-
// Since we always use decal mode, there is no need for key data.
267-
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
268-
269-
bool onIsEqual(const GrFragmentProcessor& fp) const override;
270-
271-
const TextureSampler& onTextureSampler(int) const override { return fTextureSampler; }
272-
273-
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
274-
275-
typedef GrFragmentProcessor INHERITED;
276-
};
277234
#endif
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Use of this source code is governed by a BSD-style license that can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
/**************************************************************************************************
9+
*** This file was autogenerated from GrDeviceSpaceEffect.fp; do not modify.
10+
**************************************************************************************************/
11+
#include "GrDeviceSpaceEffect.h"
12+
13+
#include "include/gpu/GrTexture.h"
14+
#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
15+
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
16+
#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
17+
#include "src/sksl/SkSLCPP.h"
18+
#include "src/sksl/SkSLUtil.h"
19+
class GrGLSLDeviceSpaceEffect : public GrGLSLFragmentProcessor {
20+
public:
21+
GrGLSLDeviceSpaceEffect() {}
22+
void emitCode(EmitArgs& args) override {
23+
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
24+
const GrDeviceSpaceEffect& _outer = args.fFp.cast<GrDeviceSpaceEffect>();
25+
(void)_outer;
26+
SkString _input204 = SkStringPrintf("%s", args.fInputColor);
27+
SkString _sample204;
28+
SkString _coords204("sk_FragCoord.xy");
29+
_sample204 =
30+
this->invokeChild(_outer.fp_index, _input204.c_str(), args, _coords204.c_str());
31+
fragBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, _sample204.c_str());
32+
}
33+
34+
private:
35+
void onSetData(const GrGLSLProgramDataManager& pdman,
36+
const GrFragmentProcessor& _proc) override {}
37+
};
38+
GrGLSLFragmentProcessor* GrDeviceSpaceEffect::onCreateGLSLInstance() const {
39+
return new GrGLSLDeviceSpaceEffect();
40+
}
41+
void GrDeviceSpaceEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
42+
GrProcessorKeyBuilder* b) const {}
43+
bool GrDeviceSpaceEffect::onIsEqual(const GrFragmentProcessor& other) const {
44+
const GrDeviceSpaceEffect& that = other.cast<GrDeviceSpaceEffect>();
45+
(void)that;
46+
return true;
47+
}
48+
GrDeviceSpaceEffect::GrDeviceSpaceEffect(const GrDeviceSpaceEffect& src)
49+
: INHERITED(kGrDeviceSpaceEffect_ClassID, src.optimizationFlags()), fp_index(src.fp_index) {
50+
{
51+
auto clone = src.childProcessor(fp_index).clone();
52+
clone->setSampledWithExplicitCoords(
53+
src.childProcessor(fp_index).isSampledWithExplicitCoords());
54+
this->registerChildProcessor(std::move(clone));
55+
}
56+
}
57+
std::unique_ptr<GrFragmentProcessor> GrDeviceSpaceEffect::clone() const {
58+
return std::unique_ptr<GrFragmentProcessor>(new GrDeviceSpaceEffect(*this));
59+
}
60+
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDeviceSpaceEffect);
61+
#if GR_TEST_UTILS
62+
std::unique_ptr<GrFragmentProcessor> GrDeviceSpaceEffect::TestCreate(GrProcessorTestData* d) {
63+
std::unique_ptr<GrFragmentProcessor> fp;
64+
// We have a restriction that explicit coords only work for FPs with exactly one
65+
// coord transform.
66+
do {
67+
fp = GrProcessorUnitTest::MakeChildFP(d);
68+
} while (fp->numCoordTransforms() != 1);
69+
return GrDeviceSpaceEffect::Make(std::move(fp));
70+
}
71+
#endif

0 commit comments

Comments
 (0)