Line data Source code
1 : /*
2 : * Copyright 2015 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 GrDrawPathOp_DEFINED
9 : #define GrDrawPathOp_DEFINED
10 :
11 : #include "GrDrawOp.h"
12 : #include "GrGpu.h"
13 : #include "GrOpFlushState.h"
14 : #include "GrPath.h"
15 : #include "GrPathProcessor.h"
16 : #include "GrPathRendering.h"
17 : #include "GrProcessorSet.h"
18 : #include "GrStencilSettings.h"
19 :
20 : #include "SkTLList.h"
21 :
22 : class GrPaint;
23 :
24 0 : class GrDrawPathOpBase : public GrDrawOp {
25 : protected:
26 : GrDrawPathOpBase(uint32_t classID, const SkMatrix& viewMatrix, GrPaint&&,
27 : GrPathRendering::FillType, GrAAType);
28 0 : FixedFunctionFlags fixedFunctionFlags() const override {
29 0 : if (GrAATypeIsHW(fAAType)) {
30 0 : return FixedFunctionFlags::kUsesHWAA | FixedFunctionFlags::kUsesStencil;
31 : }
32 0 : return FixedFunctionFlags::kUsesStencil;
33 : }
34 0 : bool xpRequiresDstTexture(const GrCaps& caps, const GrAppliedClip* clip) override {
35 0 : return this->doProcessorAnalysis(caps, clip).requiresDstTexture();
36 : }
37 :
38 : protected:
39 0 : const SkMatrix& viewMatrix() const { return fViewMatrix; }
40 0 : GrColor color() const { return fInputColor; }
41 0 : GrPathRendering::FillType fillType() const { return fFillType; }
42 0 : const GrProcessorSet& processors() const { return fProcessorSet; }
43 : void initPipeline(const GrOpFlushState&, GrPipeline*);
44 0 : const GrProcessorSet::Analysis& doProcessorAnalysis(const GrCaps& caps,
45 : const GrAppliedClip* clip) {
46 0 : bool isMixedSamples = GrAAType::kMixedSamples == fAAType;
47 0 : fAnalysis = fProcessorSet.finalize(fInputColor, GrProcessorAnalysisCoverage::kNone, clip,
48 0 : isMixedSamples, caps, &fInputColor);
49 0 : return fAnalysis;
50 : }
51 0 : const GrProcessorSet::Analysis& processorAnalysis() const {
52 0 : SkASSERT(fAnalysis.isInitialized());
53 0 : return fAnalysis;
54 : }
55 :
56 : private:
57 0 : void onPrepare(GrOpFlushState*) final {}
58 :
59 : SkMatrix fViewMatrix;
60 : GrColor fInputColor;
61 : GrProcessorSet fProcessorSet;
62 : GrProcessorSet::Analysis fAnalysis;
63 : GrPathRendering::FillType fFillType;
64 : GrAAType fAAType;
65 :
66 : typedef GrDrawOp INHERITED;
67 : };
68 :
69 0 : class GrDrawPathOp final : public GrDrawPathOpBase {
70 : public:
71 0 : DEFINE_OP_CLASS_ID
72 :
73 0 : static std::unique_ptr<GrDrawOp> Make(const SkMatrix& viewMatrix, GrPaint&& paint,
74 : GrAAType aaType, GrPath* path) {
75 : return std::unique_ptr<GrDrawOp>(
76 0 : new GrDrawPathOp(viewMatrix, std::move(paint), aaType, path));
77 : }
78 :
79 0 : const char* name() const override { return "DrawPath"; }
80 :
81 : SkString dumpInfo() const override;
82 :
83 : private:
84 0 : GrDrawPathOp(const SkMatrix& viewMatrix, GrPaint&& paint, GrAAType aaType, const GrPath* path)
85 0 : : GrDrawPathOpBase(ClassID(), viewMatrix, std::move(paint), path->getFillType(), aaType)
86 0 : , fPath(path) {
87 0 : this->setTransformedBounds(path->getBounds(), viewMatrix, HasAABloat::kNo, IsZeroArea::kNo);
88 0 : }
89 :
90 0 : bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override { return false; }
91 :
92 : void onExecute(GrOpFlushState* state) override;
93 :
94 : GrPendingIOResource<const GrPath, kRead_GrIOType> fPath;
95 :
96 : typedef GrDrawPathOpBase INHERITED;
97 : };
98 :
99 : // Template this if we decide to support index types other than 16bit
100 0 : class GrDrawPathRangeOp final : public GrDrawPathOpBase {
101 : public:
102 : typedef GrPathRendering::PathTransformType TransformType;
103 :
104 0 : DEFINE_OP_CLASS_ID
105 :
106 : struct InstanceData : private ::SkNoncopyable {
107 : public:
108 0 : static InstanceData* Alloc(TransformType transformType, int reserveCnt) {
109 0 : int transformSize = GrPathRendering::PathTransformSize(transformType);
110 0 : uint8_t* ptr = (uint8_t*)sk_malloc_throw(Align32(sizeof(InstanceData)) +
111 0 : Align32(reserveCnt * sizeof(uint16_t)) +
112 0 : reserveCnt * transformSize * sizeof(float));
113 0 : InstanceData* instanceData = (InstanceData*)ptr;
114 0 : instanceData->fIndices = (uint16_t*)&ptr[Align32(sizeof(InstanceData))];
115 0 : instanceData->fTransformValues = (float*)&ptr[Align32(sizeof(InstanceData)) +
116 0 : Align32(reserveCnt * sizeof(uint16_t))];
117 0 : instanceData->fTransformType = transformType;
118 0 : instanceData->fInstanceCount = 0;
119 0 : instanceData->fRefCnt = 1;
120 0 : SkDEBUGCODE(instanceData->fReserveCnt = reserveCnt);
121 0 : return instanceData;
122 : }
123 :
124 : // Overload this method if we start using other transform types.
125 0 : void append(uint16_t index, float x, float y) {
126 0 : SkASSERT(GrPathRendering::kTranslate_PathTransformType == fTransformType);
127 0 : SkASSERT(fInstanceCount < fReserveCnt);
128 0 : fIndices[fInstanceCount] = index;
129 0 : fTransformValues[2 * fInstanceCount] = x;
130 0 : fTransformValues[2 * fInstanceCount + 1] = y;
131 0 : ++fInstanceCount;
132 0 : }
133 :
134 0 : TransformType transformType() const { return fTransformType; }
135 0 : int count() const { return fInstanceCount; }
136 :
137 0 : const uint16_t* indices() const { return fIndices; }
138 0 : uint16_t* indices() { return fIndices; }
139 :
140 0 : const float* transformValues() const { return fTransformValues; }
141 : float* transformValues() { return fTransformValues; }
142 :
143 0 : void ref() const { ++fRefCnt; }
144 :
145 0 : void unref() const {
146 0 : if (0 == --fRefCnt) {
147 0 : sk_free(const_cast<InstanceData*>(this));
148 : }
149 0 : }
150 :
151 : private:
152 0 : static int Align32(int sizeInBytes) { return (sizeInBytes + 3) & ~3; }
153 :
154 : InstanceData() {}
155 : ~InstanceData() {}
156 :
157 : uint16_t* fIndices;
158 : float* fTransformValues;
159 : TransformType fTransformType;
160 : int fInstanceCount;
161 : mutable int fRefCnt;
162 : SkDEBUGCODE(int fReserveCnt;)
163 : };
164 :
165 0 : static std::unique_ptr<GrDrawOp> Make(const SkMatrix& viewMatrix, SkScalar scale, SkScalar x,
166 : SkScalar y, GrPaint&& paint,
167 : GrPathRendering::FillType fill, GrAAType aaType,
168 : GrPathRange* range, const InstanceData* instanceData,
169 : const SkRect& bounds) {
170 : return std::unique_ptr<GrDrawOp>(new GrDrawPathRangeOp(viewMatrix, scale, x, y,
171 : std::move(paint), fill, aaType,
172 0 : range, instanceData, bounds));
173 : }
174 :
175 0 : const char* name() const override { return "DrawPathRange"; }
176 :
177 : SkString dumpInfo() const override;
178 :
179 : private:
180 : GrDrawPathRangeOp(const SkMatrix& viewMatrix, SkScalar scale, SkScalar x, SkScalar y,
181 : GrPaint&& paint, GrPathRendering::FillType fill, GrAAType aaType,
182 : GrPathRange* range, const InstanceData* instanceData, const SkRect& bounds);
183 :
184 0 : TransformType transformType() const { return fDraws.head()->fInstanceData->transformType(); }
185 :
186 : bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override;
187 :
188 : void onExecute(GrOpFlushState* state) override;
189 :
190 0 : struct Draw {
191 0 : void set(const InstanceData* instanceData, SkScalar x, SkScalar y) {
192 0 : fInstanceData.reset(SkRef(instanceData));
193 0 : fX = x;
194 0 : fY = y;
195 0 : }
196 :
197 : sk_sp<const InstanceData> fInstanceData;
198 : SkScalar fX, fY;
199 : };
200 :
201 : typedef GrPendingIOResource<const GrPathRange, kRead_GrIOType> PendingPathRange;
202 : typedef SkTLList<Draw, 4> DrawList;
203 :
204 : PendingPathRange fPathRange;
205 : DrawList fDraws;
206 : int fTotalPathCount;
207 : SkScalar fScale;
208 :
209 : typedef GrDrawPathOpBase INHERITED;
210 : };
211 :
212 : #endif
|