blob: 1e79ec9a77678ca6efaec812020e6f2608c0af2a [file] [log] [blame]
Chris Dalton4e998532020-02-10 11:06:42 -07001/*
2 * Copyright 2020 Google Inc.
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#ifndef GrDrawAtlasPathOp_DEFINED
9#define GrDrawAtlasPathOp_DEFINED
10
Chris Daltond2dc8dd2020-05-19 16:32:02 -060011#include "src/core/SkIPoint16.h"
Chris Daltonc3176002021-07-23 15:33:09 -060012#include "src/gpu/ops/GrAtlasInstancedHelper.h"
Chris Dalton4e998532020-02-10 11:06:42 -070013#include "src/gpu/ops/GrDrawOp.h"
14
Chris Daltonee40d5a2021-07-07 16:34:36 -060015// Fills a rectangle of pixels with a clip against coverage values from an atlas.
Chris Dalton4e998532020-02-10 11:06:42 -070016class GrDrawAtlasPathOp : public GrDrawOp {
17public:
18 DEFINE_OP_CLASS_ID
19
Chris Daltonb1fd64e2021-07-08 15:38:51 -060020 GrDrawAtlasPathOp(SkArenaAlloc* arena, const SkIRect& fillBounds, const SkMatrix& localToDevice,
21 GrPaint&& paint, SkIPoint16 locationInAtlas, const SkIRect& pathDevIBounds,
Chris Daltoncc29a392021-07-12 15:16:29 -060022 bool transposedInAtlas, GrSurfaceProxyView atlasView, bool isInverseFill)
Chris Dalton4e998532020-02-10 11:06:42 -070023 : GrDrawOp(ClassID())
Chris Daltonee40d5a2021-07-07 16:34:36 -060024 , fHeadInstance(arena->make<Instance>(fillBounds, localToDevice, paint.getColor4f(),
25 locationInAtlas, pathDevIBounds,
26 transposedInAtlas))
27 , fTailInstance(&fHeadInstance->fNext)
Chris Daltonb1fd64e2021-07-08 15:38:51 -060028 , fAtlasHelper(std::move(atlasView),
29 isInverseFill ? GrAtlasInstancedHelper::ShaderFlags::kCheckBounds |
30 GrAtlasInstancedHelper::ShaderFlags::kInvertCoverage
31 : GrAtlasInstancedHelper::ShaderFlags::kNone)
Chris Dalton4e998532020-02-10 11:06:42 -070032 , fProcessors(std::move(paint)) {
Chris Daltonee40d5a2021-07-07 16:34:36 -060033 this->setBounds(SkRect::Make(fillBounds), HasAABloat::kYes, IsHairline::kNo);
Chris Dalton4e998532020-02-10 11:06:42 -070034 }
35
36 const char* name() const override { return "GrDrawAtlasPathOp"; }
Chris Daltoncc29a392021-07-12 15:16:29 -060037 FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
Robert Phillips294723d2021-06-17 09:23:58 -040038 void visitProxies(const GrVisitProxyFunc& func) const override {
Chris Daltonb1fd64e2021-07-08 15:38:51 -060039 func(fAtlasHelper.proxy(), GrMipmapped::kNo);
Robert Phillips294723d2021-06-17 09:23:58 -040040 fProcessors.visitProxies(func);
Chris Dalton4e998532020-02-10 11:06:42 -070041 }
Chris Dalton57ab06c2021-04-22 12:57:28 -060042 GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, GrClampType) override;
Herb Derbye25c3002020-10-27 15:57:27 -040043 CombineResult onCombineIfPossible(GrOp*, SkArenaAlloc*, const GrCaps&) override;
Chris Daltonee40d5a2021-07-07 16:34:36 -060044
45 void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView& writeView, GrAppliedClip*,
46 const GrDstProxyView&, GrXferBarrierFlags, GrLoadOp colorLoadOp) override;
Chris Dalton4e998532020-02-10 11:06:42 -070047 void onPrepare(GrOpFlushState*) override;
48 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
49
50private:
Chris Daltonee40d5a2021-07-07 16:34:36 -060051 void prepareProgram(const GrCaps&, SkArenaAlloc*, const GrSurfaceProxyView& writeView,
Chris Daltoncc29a392021-07-12 15:16:29 -060052 bool usesMSAASurface, GrAppliedClip&&, const GrDstProxyView&,
53 GrXferBarrierFlags, GrLoadOp colorLoadOp);
Robert Phillipsc655c3a2020-03-18 13:23:45 -040054
Chris Dalton4e998532020-02-10 11:06:42 -070055 struct Instance {
Chris Daltonee40d5a2021-07-07 16:34:36 -060056 Instance(const SkIRect& fillIBounds, const SkMatrix& m,
57 const SkPMColor4f& color, SkIPoint16 locationInAtlas,
58 const SkIRect& pathDevIBounds, bool transposedInAtlas)
59 : fFillBounds(fillIBounds)
60 , fLocalToDeviceIfUsingLocalCoords{m.getScaleX(), m.getSkewY(),
61 m.getSkewX(), m.getScaleY(),
62 m.getTranslateX(), m.getTranslateY()}
Chris Dalton4e998532020-02-10 11:06:42 -070063 , fColor(color)
Chris Daltonb1fd64e2021-07-08 15:38:51 -060064 , fAtlasInstance(locationInAtlas, pathDevIBounds, transposedInAtlas) {
Chris Dalton4e998532020-02-10 11:06:42 -070065 }
Chris Daltonee40d5a2021-07-07 16:34:36 -060066 SkIRect fFillBounds;
67 std::array<float, 6> fLocalToDeviceIfUsingLocalCoords;
Chris Dalton4e998532020-02-10 11:06:42 -070068 SkPMColor4f fColor;
Chris Daltonb1fd64e2021-07-08 15:38:51 -060069 GrAtlasInstancedHelper::Instance fAtlasInstance;
Chris Daltonbaae2dd2021-06-25 14:52:49 -060070 Instance* fNext = nullptr;
Chris Dalton4e998532020-02-10 11:06:42 -070071 };
72
Chris Daltonee40d5a2021-07-07 16:34:36 -060073 Instance* fHeadInstance;
74 Instance** fTailInstance;
75
Chris Daltonb1fd64e2021-07-08 15:38:51 -060076 GrAtlasInstancedHelper fAtlasHelper;
Chris Dalton4e998532020-02-10 11:06:42 -070077 bool fUsesLocalCoords = false;
78
Chris Dalton4e998532020-02-10 11:06:42 -070079 int fInstanceCount = 1;
80
Chris Daltonbaae2dd2021-06-25 14:52:49 -060081 GrProgramInfo* fProgram = nullptr;
82
Chris Dalton4e998532020-02-10 11:06:42 -070083 sk_sp<const GrBuffer> fInstanceBuffer;
84 int fBaseInstance;
85
Chris Daltona05ccc32021-06-29 19:42:13 -060086 // Only used if sk_VertexID is not supported.
87 sk_sp<const GrGpuBuffer> fVertexBufferIfNoIDSupport;
88
Chris Dalton4e998532020-02-10 11:06:42 -070089 GrProcessorSet fProcessors;
90};
91
92#endif