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

Commit df283d0

Browse files
bsalomonSkia Commit-Bot
authored and
Skia Commit-Bot
committed
Revert "Remove GrDeviceSpaceTextureDecalFragmentProcessor."
This reverts commit af5f9f0. Reason for revert: bad GM results on Metal Original change's description: > 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]> [email protected],[email protected] Change-Id: Ie02951dcc037d282dc3829cad216a0a0c9474038 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/c/skia/+/272518 Reviewed-by: Brian Salomon <[email protected]> Commit-Queue: Brian Salomon <[email protected]>
1 parent af5f9f0 commit df283d0

10 files changed

+174
-168
lines changed

gm/windowrectangles.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,13 @@
3333
#include "src/gpu/GrFixedClip.h"
3434
#include "src/gpu/GrFragmentProcessor.h"
3535
#include "src/gpu/GrPaint.h"
36-
#include "src/gpu/GrRecordingContextPriv.h"
3736
#include "src/gpu/GrReducedClip.h"
3837
#include "src/gpu/GrRenderTargetContext.h"
3938
#include "src/gpu/GrRenderTargetContextPriv.h"
4039
#include "src/gpu/GrStencilClip.h"
4140
#include "src/gpu/GrTextureProxy.h"
4241
#include "src/gpu/GrUserStencilSettings.h"
4342
#include "src/gpu/effects/GrTextureDomain.h"
44-
#include "src/gpu/effects/generated/GrDeviceSpaceEffect.h"
4543
#include "tools/ToolUtils.h"
4644

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

181179
private:
182-
bool apply(GrRecordingContext* ctx, GrRenderTargetContext*, bool, bool, GrAppliedClip* out,
180+
bool apply(GrRecordingContext*, GrRenderTargetContext*, bool, bool, GrAppliedClip* out,
183181
SkRect* bounds) const override {
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));
182+
out->addCoverageFP(GrDeviceSpaceTextureDecalFragmentProcessor::Make(
183+
fMask, SkIRect::MakeSize(fMask.proxy()->dimensions()), {fX, fY}));
193184
return true;
194185
}
195186
GrSurfaceProxyView fMask;

gn/gpu.gni

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,6 @@ 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",
379377
"$_src/gpu/effects/generated/GrHSLToRGBFilterEffect.cpp",
380378
"$_src/gpu/effects/generated/GrHSLToRGBFilterEffect.h",
381379
"$_src/gpu/effects/generated/GrLumaColorFilterEffect.cpp",

gn/sksl.gni

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ 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",
5150
"$_src/gpu/effects/GrEllipseEffect.fp",
5251
"$_src/gpu/effects/GrHSLToRGBFilterEffect.fp",
5352
"$_src/gpu/effects/GrLumaColorFilterEffect.fp",

src/gpu/GrClipStackClip.cpp

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

8-
#include "src/gpu/GrClipStackClip.h"
9-
108
#include "include/private/SkTo.h"
119
#include "src/core/SkClipOpPriv.h"
1210
#include "src/core/SkTaskGroup.h"
1311
#include "src/core/SkTraceEvent.h"
1412
#include "src/gpu/GrAppliedClip.h"
13+
#include "src/gpu/GrClipStackClip.h"
1514
#include "src/gpu/GrContextPriv.h"
1615
#include "src/gpu/GrDeferredProxyUploader.h"
1716
#include "src/gpu/GrDrawingManager.h"
@@ -27,7 +26,6 @@
2726
#include "src/gpu/effects/GrConvexPolyEffect.h"
2827
#include "src/gpu/effects/GrRRectEffect.h"
2928
#include "src/gpu/effects/GrTextureDomain.h"
30-
#include "src/gpu/effects/generated/GrDeviceSpaceEffect.h"
3129
#include "src/gpu/geometry/GrShape.h"
3230

3331
typedef SkClipStack::Element Element;
@@ -80,18 +78,11 @@ void GrClipStackClip::getConservativeBounds(int width, int height, SkIRect* devR
8078
////////////////////////////////////////////////////////////////////////////////
8179
// set up the draw state to enable the aa clipping mask.
8280
static std::unique_ptr<GrFragmentProcessor> create_fp_for_mask(GrSurfaceProxyView mask,
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));
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});
9586
}
9687

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

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-
kGrDeviceSpaceEffect_ClassID,
104+
kGrDeviceSpaceTextureDecalFragmentProcessor_ClassID,
105105
kGrDiffuseLightingEffect_ClassID,
106106
kGrDisplacementMapEffect_ClassID,
107107
kGrDistanceFieldA8TextGeoProc_ClassID,

src/gpu/effects/GrDeviceSpaceEffect.fp

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/gpu/effects/GrTextureDomain.cpp

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,123 @@ 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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,47 @@ 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+
};
234277
#endif

src/gpu/effects/generated/GrDeviceSpaceEffect.cpp

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)