Flutter Engine
The Flutter Engine
DrawAtlasPathOp.h
Go to the documentation of this file.
1/*
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 DrawAtlasPathOp_DEFINED
9#define DrawAtlasPathOp_DEFINED
10
12#include "include/core/SkRect.h"
18#include "src/core/SkIPoint16.h"
28
29#include <array>
30#include <utility>
31
32class GrAppliedClip;
33class GrDstProxyView;
34class GrOpFlushState;
35class GrProgramInfo;
37enum class GrXferBarrierFlags;
38
39namespace skgpu::ganesh {
40
41// Fills a rectangle of pixels with a clip against coverage values from an atlas.
42class DrawAtlasPathOp final : public GrDrawOp {
43public:
45
46 DrawAtlasPathOp(SkArenaAlloc* arena, const SkIRect& fillBounds, const SkMatrix& localToDevice,
47 GrPaint&& paint, SkIPoint16 locationInAtlas, const SkIRect& pathDevIBounds,
48 bool transposedInAtlas, GrSurfaceProxyView atlasView, bool isInverseFill)
49 : GrDrawOp(ClassID())
50 , fHeadInstance(arena->make<Instance>(fillBounds, localToDevice, paint.getColor4f(),
51 locationInAtlas, pathDevIBounds,
52 transposedInAtlas))
53 , fTailInstance(&fHeadInstance->fNext)
54 , fAtlasHelper(std::move(atlasView),
55 isInverseFill ? AtlasInstancedHelper::ShaderFlags::kCheckBounds |
56 AtlasInstancedHelper::ShaderFlags::kInvertCoverage
57 : AtlasInstancedHelper::ShaderFlags::kNone)
58 , fProcessors(std::move(paint)) {
60 }
61
62 const char* name() const override { return "DrawAtlasPathOp"; }
64 void visitProxies(const GrVisitProxyFunc& func) const override {
65 func(fAtlasHelper.proxy(), skgpu::Mipmapped::kNo);
66 fProcessors.visitProxies(func);
67 }
70
72 const GrDstProxyView&, GrXferBarrierFlags, GrLoadOp colorLoadOp) override;
73 void onPrepare(GrOpFlushState*) override;
74 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
75
76private:
77 void prepareProgram(const GrCaps&, SkArenaAlloc*, const GrSurfaceProxyView& writeView,
78 bool usesMSAASurface, GrAppliedClip&&, const GrDstProxyView&,
79 GrXferBarrierFlags, GrLoadOp colorLoadOp);
80
81 struct Instance {
82 Instance(const SkIRect& fillIBounds, const SkMatrix& m,
83 const SkPMColor4f& color, SkIPoint16 locationInAtlas,
84 const SkIRect& pathDevIBounds, bool transposedInAtlas)
85 : fFillBounds(fillIBounds)
86 , fLocalToDeviceIfUsingLocalCoords{m.getScaleX(), m.getSkewY(),
87 m.getSkewX(), m.getScaleY(),
88 m.getTranslateX(), m.getTranslateY()}
89 , fColor(color)
90 , fAtlasInstance(locationInAtlas, pathDevIBounds, transposedInAtlas) {
91 }
92 SkIRect fFillBounds;
93 std::array<float, 6> fLocalToDeviceIfUsingLocalCoords;
94 SkPMColor4f fColor;
95 AtlasInstancedHelper::Instance fAtlasInstance;
96 Instance* fNext = nullptr;
97 };
98
99 Instance* fHeadInstance;
100 Instance** fTailInstance;
101
102 AtlasInstancedHelper fAtlasHelper;
103 bool fUsesLocalCoords = false;
104
105 int fInstanceCount = 1;
106
107 GrProgramInfo* fProgram = nullptr;
108
109 sk_sp<const GrBuffer> fInstanceBuffer;
110 int fBaseInstance;
111
112 // Only used if sk_VertexID is not supported.
113 sk_sp<const GrGpuBuffer> fVertexBufferIfNoIDSupport;
114
115 GrProcessorSet fProcessors;
116};
117
118} // namespace skgpu::ganesh
119
120#endif // DrawAtlasPathOp_DEFINED
Instance * fNext
#define DEFINE_OP_CLASS_ID
Definition: GrOp.h:64
GrClampType
Definition: GrTypesPriv.h:228
std::function< void(GrSurfaceProxy *, skgpu::Mipmapped)> GrVisitProxyFunc
Definition: GrTypesPriv.h:943
GrLoadOp
Definition: GrTypesPriv.h:155
GrXferBarrierFlags
Definition: GrCaps.h:57
FixedFunctionFlags
Definition: GrDrawOp.h:104
Definition: GrOp.h:70
CombineResult
Definition: GrOp.h:99
void setBounds(const SkRect &newBounds, HasAABloat aabloat, IsHairline zeroArea)
Definition: GrOp.h:279
void visitProxies(const GrVisitProxyFunc &) const
void onPrePrepare(GrRecordingContext *, const GrSurfaceProxyView &writeView, GrAppliedClip *, const GrDstProxyView &, GrXferBarrierFlags, GrLoadOp colorLoadOp) override
GrProcessorSet::Analysis finalize(const GrCaps &, const GrAppliedClip *, GrClampType) override
DEFINE_OP_CLASS_ID DrawAtlasPathOp(SkArenaAlloc *arena, const SkIRect &fillBounds, const SkMatrix &localToDevice, GrPaint &&paint, SkIPoint16 locationInAtlas, const SkIRect &pathDevIBounds, bool transposedInAtlas, GrSurfaceProxyView atlasView, bool isInverseFill)
void onExecute(GrOpFlushState *, const SkRect &chainBounds) override
CombineResult onCombineIfPossible(GrOp *, SkArenaAlloc *, const GrCaps &) override
void onPrepare(GrOpFlushState *) override
const char * name() const override
void visitProxies(const GrVisitProxyFunc &func) const override
FixedFunctionFlags fixedFunctionFlags() const override
const Paint & paint
Definition: color_source.cc:38
DlColor color
static void make(SkBitmap *bitmap, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace)
Definition: encode_srgb.cpp:35
Definition: ref_ptr.h:256
Definition: SkRect.h:32
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669