Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: src/gpu/effects/GrConvexPolyEffect.cpp

Issue 582963002: Solo gp (Closed) Base URL: https://skia.googlesource.com/skia.git@no_peb
Patch Set: rebase Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/effects/GrConvexPolyEffect.h ('k') | src/gpu/effects/GrConvolutionEffect.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gl/builders/GrGLProgramBuilder.h" 8 #include "gl/builders/GrGLProgramBuilder.h"
9 #include "GrConvexPolyEffect.h" 9 #include "GrConvexPolyEffect.h"
10 10
11 #include "gl/GrGLEffect.h" 11 #include "gl/GrGLProcessor.h"
12 #include "gl/GrGLSL.h" 12 #include "gl/GrGLSL.h"
13 #include "GrTBackendEffectFactory.h" 13 #include "GrTBackendProcessorFactory.h"
14 14
15 #include "SkPath.h" 15 #include "SkPath.h"
16 16
17 ////////////////////////////////////////////////////////////////////////////// 17 //////////////////////////////////////////////////////////////////////////////
18 class GLAARectEffect; 18 class GLAARectEffect;
19 19
20 class AARectEffect : public GrEffect { 20 class AARectEffect : public GrFragmentProcessor {
21 public: 21 public:
22 typedef GLAARectEffect GLEffect; 22 typedef GLAARectEffect GLProcessor;
23 23
24 const SkRect& getRect() const { return fRect; } 24 const SkRect& getRect() const { return fRect; }
25 25
26 static const char* Name() { return "AARect"; } 26 static const char* Name() { return "AARect"; }
27 27
28 static GrEffect* Create(GrEffectEdgeType edgeType, const SkRect& rect) { 28 static GrFragmentProcessor* Create(GrPrimitiveEdgeType edgeType, const SkRec t& rect) {
29 return SkNEW_ARGS(AARectEffect, (edgeType, rect)); 29 return SkNEW_ARGS(AARectEffect, (edgeType, rect));
30 } 30 }
31 31
32 virtual void getConstantColorComponents(GrColor* color, 32 virtual void getConstantColorComponents(GrColor* color,
33 uint32_t* validFlags) const SK_OVERR IDE { 33 uint32_t* validFlags) const SK_OVERR IDE {
34 if (fRect.isEmpty()) { 34 if (fRect.isEmpty()) {
35 // An empty rect will have no coverage anywhere. 35 // An empty rect will have no coverage anywhere.
36 *color = 0x00000000; 36 *color = 0x00000000;
37 *validFlags = kRGBA_GrColorComponentFlags; 37 *validFlags = kRGBA_GrColorComponentFlags;
38 } else { 38 } else {
39 *validFlags = 0; 39 *validFlags = 0;
40 } 40 }
41 } 41 }
42 42
43 GrEffectEdgeType getEdgeType() const { return fEdgeType; } 43 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; }
44 44
45 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; 45 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR IDE;
46 46
47 private: 47 private:
48 AARectEffect(GrEffectEdgeType edgeType, const SkRect& rect) : fRect(rect), f EdgeType(edgeType) { 48 AARectEffect(GrPrimitiveEdgeType edgeType, const SkRect& rect) : fRect(rect) , fEdgeType(edgeType) {
49 this->setWillReadFragmentPosition(); 49 this->setWillReadFragmentPosition();
50 } 50 }
51 51
52 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { 52 virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE {
53 const AARectEffect& aare = other.cast<AARectEffect>(); 53 const AARectEffect& aare = other.cast<AARectEffect>();
54 return fRect == aare.fRect; 54 return fRect == aare.fRect;
55 } 55 }
56 56
57 SkRect fRect; 57 SkRect fRect;
58 GrEffectEdgeType fEdgeType; 58 GrPrimitiveEdgeType fEdgeType;
59 59
60 typedef GrEffect INHERITED; 60 typedef GrFragmentProcessor INHERITED;
61 61
62 GR_DECLARE_EFFECT_TEST; 62 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
63 63
64 }; 64 };
65 65
66 GR_DEFINE_EFFECT_TEST(AARectEffect); 66 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(AARectEffect);
67 67
68 GrEffect* AARectEffect::TestCreate(SkRandom* random, 68 GrFragmentProcessor* AARectEffect::TestCreate(SkRandom* random,
69 GrContext*, 69 GrContext*,
70 const GrDrawTargetCaps& caps, 70 const GrDrawTargetCaps& caps,
71 GrTexture*[]) { 71 GrTexture*[]) {
72 SkRect rect = SkRect::MakeLTRB(random->nextSScalar1(), 72 SkRect rect = SkRect::MakeLTRB(random->nextSScalar1(),
73 random->nextSScalar1(), 73 random->nextSScalar1(),
74 random->nextSScalar1(), 74 random->nextSScalar1(),
75 random->nextSScalar1()); 75 random->nextSScalar1());
76 GrEffect* effect; 76 GrFragmentProcessor* fp;
77 do { 77 do {
78 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>(random->nextUL essThan( 78 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(random-> nextULessThan(
79 kGrEffectEdg eTypeCnt)); 79 kGrProcessor EdgeTypeCnt));
80 80
81 effect = AARectEffect::Create(edgeType, rect); 81 fp = AARectEffect::Create(edgeType, rect);
82 } while (NULL == effect); 82 } while (NULL == fp);
83 return effect; 83 return fp;
84 } 84 }
85 85
86 ////////////////////////////////////////////////////////////////////////////// 86 //////////////////////////////////////////////////////////////////////////////
87 87
88 class GLAARectEffect : public GrGLEffect { 88 class GLAARectEffect : public GrGLFragmentProcessor {
89 public: 89 public:
90 GLAARectEffect(const GrBackendEffectFactory&, const GrEffect&); 90 GLAARectEffect(const GrBackendProcessorFactory&, const GrProcessor&);
91 91
92 virtual void emitCode(GrGLProgramBuilder* builder, 92 virtual void emitCode(GrGLProgramBuilder* builder,
93 const GrEffect& effect, 93 const GrFragmentProcessor& fp,
94 const GrEffectKey& key, 94 const GrProcessorKey& key,
95 const char* outputColor, 95 const char* outputColor,
96 const char* inputColor, 96 const char* inputColor,
97 const TransformedCoordsArray&, 97 const TransformedCoordsArray&,
98 const TextureSamplerArray&) SK_OVERRIDE; 98 const TextureSamplerArray&) SK_OVERRIDE;
99 99
100 static inline void GenKey(const GrEffect&, const GrGLCaps&, GrEffectKeyBuild er*); 100 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe yBuilder*);
101 101
102 virtual void setData(const GrGLProgramDataManager&, const GrEffect&) SK_OVER RIDE; 102 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O VERRIDE;
103 103
104 private: 104 private:
105 GrGLProgramDataManager::UniformHandle fRectUniform; 105 GrGLProgramDataManager::UniformHandle fRectUniform;
106 SkRect fPrevRect; 106 SkRect fPrevRect;
107 typedef GrGLEffect INHERITED; 107 typedef GrGLFragmentProcessor INHERITED;
108 }; 108 };
109 109
110 GLAARectEffect::GLAARectEffect(const GrBackendEffectFactory& factory, 110 GLAARectEffect::GLAARectEffect(const GrBackendProcessorFactory& factory,
111 const GrEffect& effect) 111 const GrProcessor& effect)
112 : INHERITED (factory) { 112 : INHERITED (factory) {
113 fPrevRect.fLeft = SK_ScalarNaN; 113 fPrevRect.fLeft = SK_ScalarNaN;
114 } 114 }
115 115
116 void GLAARectEffect::emitCode(GrGLProgramBuilder* builder, 116 void GLAARectEffect::emitCode(GrGLProgramBuilder* builder,
117 const GrEffect& effect, 117 const GrFragmentProcessor& fp,
118 const GrEffectKey& key, 118 const GrProcessorKey& key,
119 const char* outputColor, 119 const char* outputColor,
120 const char* inputColor, 120 const char* inputColor,
121 const TransformedCoordsArray&, 121 const TransformedCoordsArray&,
122 const TextureSamplerArray& samplers) { 122 const TextureSamplerArray& samplers) {
123 const AARectEffect& aare = effect.cast<AARectEffect>(); 123 const AARectEffect& aare = fp.cast<AARectEffect>();
124 const char *rectName; 124 const char *rectName;
125 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot tom - 0.5), 125 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot tom - 0.5),
126 // respectively. 126 // respectively.
127 fRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, 127 fRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
128 kVec4f_GrSLType, 128 kVec4f_GrSLType,
129 "rect", 129 "rect",
130 &rectName); 130 &rectName);
131 131
132 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 132 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder();
133 const char* fragmentPos = fsBuilder->fragmentPosition(); 133 const char* fragmentPos = fsBuilder->fragmentPosition();
134 if (GrEffectEdgeTypeIsAA(aare.getEdgeType())) { 134 if (GrProcessorEdgeTypeIsAA(aare.getEdgeType())) {
135 // The amount of coverage removed in x and y by the edges is computed as a pair of negative 135 // The amount of coverage removed in x and y by the edges is computed as a pair of negative
136 // numbers, xSub and ySub. 136 // numbers, xSub and ySub.
137 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n"); 137 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n");
138 fsBuilder->codeAppendf("\t\txSub = min(%s.x - %s.x, 0.0);\n", fragmentPo s, rectName); 138 fsBuilder->codeAppendf("\t\txSub = min(%s.x - %s.x, 0.0);\n", fragmentPo s, rectName);
139 fsBuilder->codeAppendf("\t\txSub += min(%s.z - %s.x, 0.0);\n", rectName, fragmentPos); 139 fsBuilder->codeAppendf("\t\txSub += min(%s.z - %s.x, 0.0);\n", rectName, fragmentPos);
140 fsBuilder->codeAppendf("\t\tySub = min(%s.y - %s.y, 0.0);\n", fragmentPo s, rectName); 140 fsBuilder->codeAppendf("\t\tySub = min(%s.y - %s.y, 0.0);\n", fragmentPo s, rectName);
141 fsBuilder->codeAppendf("\t\tySub += min(%s.w - %s.y, 0.0);\n", rectName, fragmentPos); 141 fsBuilder->codeAppendf("\t\tySub += min(%s.w - %s.y, 0.0);\n", rectName, fragmentPos);
142 // Now compute coverage in x and y and multiply them to get the fraction of the pixel 142 // Now compute coverage in x and y and multiply them to get the fraction of the pixel
143 // covered. 143 // covered.
144 fsBuilder->codeAppendf("\t\tfloat alpha = (1.0 + max(xSub, -1.0)) * (1.0 + max(ySub, -1.0));\n"); 144 fsBuilder->codeAppendf("\t\tfloat alpha = (1.0 + max(xSub, -1.0)) * (1.0 + max(ySub, -1.0));\n");
145 } else { 145 } else {
146 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n"); 146 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n");
147 fsBuilder->codeAppendf("\t\talpha *= (%s.x - %s.x) > -0.5 ? 1.0 : 0.0;\n ", fragmentPos, rectName); 147 fsBuilder->codeAppendf("\t\talpha *= (%s.x - %s.x) > -0.5 ? 1.0 : 0.0;\n ", fragmentPos, rectName);
148 fsBuilder->codeAppendf("\t\talpha *= (%s.z - %s.x) > -0.5 ? 1.0 : 0.0;\n ", rectName, fragmentPos); 148 fsBuilder->codeAppendf("\t\talpha *= (%s.z - %s.x) > -0.5 ? 1.0 : 0.0;\n ", rectName, fragmentPos);
149 fsBuilder->codeAppendf("\t\talpha *= (%s.y - %s.y) > -0.5 ? 1.0 : 0.0;\n ", fragmentPos, rectName); 149 fsBuilder->codeAppendf("\t\talpha *= (%s.y - %s.y) > -0.5 ? 1.0 : 0.0;\n ", fragmentPos, rectName);
150 fsBuilder->codeAppendf("\t\talpha *= (%s.w - %s.y) > -0.5 ? 1.0 : 0.0;\n ", rectName, fragmentPos); 150 fsBuilder->codeAppendf("\t\talpha *= (%s.w - %s.y) > -0.5 ? 1.0 : 0.0;\n ", rectName, fragmentPos);
151 } 151 }
152 152
153 if (GrEffectEdgeTypeIsInverseFill(aare.getEdgeType())) { 153 if (GrProcessorEdgeTypeIsInverseFill(aare.getEdgeType())) {
154 fsBuilder->codeAppend("\t\talpha = 1.0 - alpha;\n"); 154 fsBuilder->codeAppend("\t\talpha = 1.0 - alpha;\n");
155 } 155 }
156 fsBuilder->codeAppendf("\t\t%s = %s;\n", outputColor, 156 fsBuilder->codeAppendf("\t\t%s = %s;\n", outputColor,
157 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st r()); 157 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st r());
158 } 158 }
159 159
160 void GLAARectEffect::setData(const GrGLProgramDataManager& pdman, const GrEffect & effect) { 160 void GLAARectEffect::setData(const GrGLProgramDataManager& pdman, const GrProces sor& processor) {
161 const AARectEffect& aare = effect.cast<AARectEffect>(); 161 const AARectEffect& aare = processor.cast<AARectEffect>();
162 const SkRect& rect = aare.getRect(); 162 const SkRect& rect = aare.getRect();
163 if (rect != fPrevRect) { 163 if (rect != fPrevRect) {
164 pdman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f, 164 pdman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f,
165 rect.fRight - 0.5f, rect.fBottom - 0.5f); 165 rect.fRight - 0.5f, rect.fBottom - 0.5f);
166 fPrevRect = rect; 166 fPrevRect = rect;
167 } 167 }
168 } 168 }
169 169
170 void GLAARectEffect::GenKey(const GrEffect& effect, const GrGLCaps&, 170 void GLAARectEffect::GenKey(const GrProcessor& processor, const GrGLCaps&,
171 GrEffectKeyBuilder* b) { 171 GrProcessorKeyBuilder* b) {
172 const AARectEffect& aare = effect.cast<AARectEffect>(); 172 const AARectEffect& aare = processor.cast<AARectEffect>();
173 b->add32(aare.getEdgeType()); 173 b->add32(aare.getEdgeType());
174 } 174 }
175 175
176 const GrBackendEffectFactory& AARectEffect::getFactory() const { 176 const GrBackendFragmentProcessorFactory& AARectEffect::getFactory() const {
177 return GrTBackendEffectFactory<AARectEffect>::getInstance(); 177 return GrTBackendFragmentProcessorFactory<AARectEffect>::getInstance();
178 } 178 }
179 179
180 ////////////////////////////////////////////////////////////////////////////// 180 //////////////////////////////////////////////////////////////////////////////
181 181
182 class GrGLConvexPolyEffect : public GrGLEffect { 182 class GrGLConvexPolyEffect : public GrGLFragmentProcessor {
183 public: 183 public:
184 GrGLConvexPolyEffect(const GrBackendEffectFactory&, const GrEffect&); 184 GrGLConvexPolyEffect(const GrBackendProcessorFactory&, const GrProcessor&);
185 185
186 virtual void emitCode(GrGLProgramBuilder* builder, 186 virtual void emitCode(GrGLProgramBuilder* builder,
187 const GrEffect& effect, 187 const GrFragmentProcessor& fp,
188 const GrEffectKey& key, 188 const GrProcessorKey& key,
189 const char* outputColor, 189 const char* outputColor,
190 const char* inputColor, 190 const char* inputColor,
191 const TransformedCoordsArray&, 191 const TransformedCoordsArray&,
192 const TextureSamplerArray&) SK_OVERRIDE; 192 const TextureSamplerArray&) SK_OVERRIDE;
193 193
194 static inline void GenKey(const GrEffect&, const GrGLCaps&, GrEffectKeyBuild er*); 194 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe yBuilder*);
195 195
196 virtual void setData(const GrGLProgramDataManager&, const GrEffect&) SK_OVER RIDE; 196 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O VERRIDE;
197 197
198 private: 198 private:
199 GrGLProgramDataManager::UniformHandle fEdgeUniform; 199 GrGLProgramDataManager::UniformHandle fEdgeUniform;
200 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMa xEdges]; 200 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMa xEdges];
201 typedef GrGLEffect INHERITED; 201 typedef GrGLFragmentProcessor INHERITED;
202 }; 202 };
203 203
204 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrBackendEffectFactory& factory , 204 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrBackendProcessorFactory& fact ory,
205 const GrEffect& effect) 205 const GrProcessor&)
206 : INHERITED (factory) { 206 : INHERITED (factory) {
207 fPrevEdges[0] = SK_ScalarNaN; 207 fPrevEdges[0] = SK_ScalarNaN;
208 } 208 }
209 209
210 void GrGLConvexPolyEffect::emitCode(GrGLProgramBuilder* builder, 210 void GrGLConvexPolyEffect::emitCode(GrGLProgramBuilder* builder,
211 const GrEffect& effect, 211 const GrFragmentProcessor& fp,
212 const GrEffectKey& key, 212 const GrProcessorKey& key,
213 const char* outputColor, 213 const char* outputColor,
214 const char* inputColor, 214 const char* inputColor,
215 const TransformedCoordsArray&, 215 const TransformedCoordsArray&,
216 const TextureSamplerArray& samplers) { 216 const TextureSamplerArray& samplers) {
217 const GrConvexPolyEffect& cpe = effect.cast<GrConvexPolyEffect>(); 217 const GrConvexPolyEffect& cpe = fp.cast<GrConvexPolyEffect>();
218 218
219 const char *edgeArrayName; 219 const char *edgeArrayName;
220 fEdgeUniform = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibi lity, 220 fEdgeUniform = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibi lity,
221 kVec3f_GrSLType, 221 kVec3f_GrSLType,
222 "edges", 222 "edges",
223 cpe.getEdgeCount(), 223 cpe.getEdgeCount(),
224 &edgeArrayName); 224 &edgeArrayName);
225 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 225 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder();
226 fsBuilder->codeAppend("\t\tfloat alpha = 1.0;\n"); 226 fsBuilder->codeAppend("\t\tfloat alpha = 1.0;\n");
227 fsBuilder->codeAppend("\t\tfloat edge;\n"); 227 fsBuilder->codeAppend("\t\tfloat edge;\n");
228 const char* fragmentPos = fsBuilder->fragmentPosition(); 228 const char* fragmentPos = fsBuilder->fragmentPosition();
229 for (int i = 0; i < cpe.getEdgeCount(); ++i) { 229 for (int i = 0; i < cpe.getEdgeCount(); ++i) {
230 fsBuilder->codeAppendf("\t\tedge = dot(%s[%d], vec3(%s.x, %s.y, 1));\n", 230 fsBuilder->codeAppendf("\t\tedge = dot(%s[%d], vec3(%s.x, %s.y, 1));\n",
231 edgeArrayName, i, fragmentPos, fragmentPos); 231 edgeArrayName, i, fragmentPos, fragmentPos);
232 if (GrEffectEdgeTypeIsAA(cpe.getEdgeType())) { 232 if (GrProcessorEdgeTypeIsAA(cpe.getEdgeType())) {
233 fsBuilder->codeAppend("\t\tedge = clamp(edge, 0.0, 1.0);\n"); 233 fsBuilder->codeAppend("\t\tedge = clamp(edge, 0.0, 1.0);\n");
234 } else { 234 } else {
235 fsBuilder->codeAppend("\t\tedge = edge >= 0.5 ? 1.0 : 0.0;\n"); 235 fsBuilder->codeAppend("\t\tedge = edge >= 0.5 ? 1.0 : 0.0;\n");
236 } 236 }
237 fsBuilder->codeAppend("\t\talpha *= edge;\n"); 237 fsBuilder->codeAppend("\t\talpha *= edge;\n");
238 } 238 }
239 239
240 // Woe is me. See skbug.com/2149. 240 // Woe is me. See skbug.com/2149.
241 if (kTegra2_GrGLRenderer == builder->ctxInfo().renderer()) { 241 if (kTegra2_GrGLRenderer == builder->ctxInfo().renderer()) {
242 fsBuilder->codeAppend("\t\tif (-1.0 == alpha) {\n\t\t\tdiscard;\n\t\t}\n "); 242 fsBuilder->codeAppend("\t\tif (-1.0 == alpha) {\n\t\t\tdiscard;\n\t\t}\n ");
243 } 243 }
244 244
245 if (GrEffectEdgeTypeIsInverseFill(cpe.getEdgeType())) { 245 if (GrProcessorEdgeTypeIsInverseFill(cpe.getEdgeType())) {
246 fsBuilder->codeAppend("\talpha = 1.0 - alpha;\n"); 246 fsBuilder->codeAppend("\talpha = 1.0 - alpha;\n");
247 } 247 }
248 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, 248 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor,
249 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st r()); 249 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st r());
250 } 250 }
251 251
252 void GrGLConvexPolyEffect::setData(const GrGLProgramDataManager& pdman, const Gr Effect& effect) { 252 void GrGLConvexPolyEffect::setData(const GrGLProgramDataManager& pdman, const Gr Processor& effect) {
253 const GrConvexPolyEffect& cpe = effect.cast<GrConvexPolyEffect>(); 253 const GrConvexPolyEffect& cpe = effect.cast<GrConvexPolyEffect>();
254 size_t byteSize = 3 * cpe.getEdgeCount() * sizeof(SkScalar); 254 size_t byteSize = 3 * cpe.getEdgeCount() * sizeof(SkScalar);
255 if (0 != memcmp(fPrevEdges, cpe.getEdges(), byteSize)) { 255 if (0 != memcmp(fPrevEdges, cpe.getEdges(), byteSize)) {
256 pdman.set3fv(fEdgeUniform, cpe.getEdgeCount(), cpe.getEdges()); 256 pdman.set3fv(fEdgeUniform, cpe.getEdgeCount(), cpe.getEdges());
257 memcpy(fPrevEdges, cpe.getEdges(), byteSize); 257 memcpy(fPrevEdges, cpe.getEdges(), byteSize);
258 } 258 }
259 } 259 }
260 260
261 void GrGLConvexPolyEffect::GenKey(const GrEffect& effect, const GrGLCaps&, 261 void GrGLConvexPolyEffect::GenKey(const GrProcessor& processor, const GrGLCaps&,
262 GrEffectKeyBuilder* b) { 262 GrProcessorKeyBuilder* b) {
263 const GrConvexPolyEffect& cpe = effect.cast<GrConvexPolyEffect>(); 263 const GrConvexPolyEffect& cpe = processor.cast<GrConvexPolyEffect>();
264 GR_STATIC_ASSERT(kGrEffectEdgeTypeCnt <= 8); 264 GR_STATIC_ASSERT(kGrProcessorEdgeTypeCnt <= 8);
265 uint32_t key = (cpe.getEdgeCount() << 3) | cpe.getEdgeType(); 265 uint32_t key = (cpe.getEdgeCount() << 3) | cpe.getEdgeType();
266 b->add32(key); 266 b->add32(key);
267 } 267 }
268 268
269 ////////////////////////////////////////////////////////////////////////////// 269 //////////////////////////////////////////////////////////////////////////////
270 270
271 GrEffect* GrConvexPolyEffect::Create(GrEffectEdgeType type, const SkPath& path, 271 GrFragmentProcessor* GrConvexPolyEffect::Create(GrPrimitiveEdgeType type, const SkPath& path,
272 const SkVector* offset) { 272 const SkVector* offset) {
273 if (kHairlineAA_GrEffectEdgeType == type) { 273 if (kHairlineAA_GrProcessorEdgeType == type) {
274 return NULL; 274 return NULL;
275 } 275 }
276 if (path.getSegmentMasks() != SkPath::kLine_SegmentMask || 276 if (path.getSegmentMasks() != SkPath::kLine_SegmentMask ||
277 !path.isConvex()) { 277 !path.isConvex()) {
278 return NULL; 278 return NULL;
279 } 279 }
280 280
281 if (path.countPoints() > kMaxEdges) { 281 if (path.countPoints() > kMaxEdges) {
282 return NULL; 282 return NULL;
283 } 283 }
(...skipping 23 matching lines...) Expand all
307 } else { 307 } else {
308 edges[3 * n] = -v.fY; 308 edges[3 * n] = -v.fY;
309 edges[3 * n + 1] = v.fX; 309 edges[3 * n + 1] = v.fX;
310 } 310 }
311 SkPoint p = pts[i] + t; 311 SkPoint p = pts[i] + t;
312 edges[3 * n + 2] = -(edges[3 * n] * p.fX + edges[3 * n + 1] * p.fY); 312 edges[3 * n + 2] = -(edges[3 * n] * p.fX + edges[3 * n + 1] * p.fY);
313 ++n; 313 ++n;
314 } 314 }
315 } 315 }
316 if (path.isInverseFillType()) { 316 if (path.isInverseFillType()) {
317 type = GrInvertEffectEdgeType(type); 317 type = GrInvertProcessorEdgeType(type);
318 } 318 }
319 return Create(type, n, edges); 319 return Create(type, n, edges);
320 } 320 }
321 321
322 GrEffect* GrConvexPolyEffect::Create(GrEffectEdgeType edgeType, const SkRect& re ct) { 322 GrFragmentProcessor* GrConvexPolyEffect::Create(GrPrimitiveEdgeType edgeType, co nst SkRect& rect) {
323 if (kHairlineAA_GrEffectEdgeType == edgeType){ 323 if (kHairlineAA_GrProcessorEdgeType == edgeType){
324 return NULL; 324 return NULL;
325 } 325 }
326 return AARectEffect::Create(edgeType, rect); 326 return AARectEffect::Create(edgeType, rect);
327 } 327 }
328 328
329 GrConvexPolyEffect::~GrConvexPolyEffect() {} 329 GrConvexPolyEffect::~GrConvexPolyEffect() {}
330 330
331 void GrConvexPolyEffect::getConstantColorComponents(GrColor* color, uint32_t* va lidFlags) const { 331 void GrConvexPolyEffect::getConstantColorComponents(GrColor* color, uint32_t* va lidFlags) const {
332 *validFlags = 0; 332 *validFlags = 0;
333 } 333 }
334 334
335 const GrBackendEffectFactory& GrConvexPolyEffect::getFactory() const { 335 const GrBackendFragmentProcessorFactory& GrConvexPolyEffect::getFactory() const {
336 return GrTBackendEffectFactory<GrConvexPolyEffect>::getInstance(); 336 return GrTBackendFragmentProcessorFactory<GrConvexPolyEffect>::getInstance() ;
337 } 337 }
338 338
339 GrConvexPolyEffect::GrConvexPolyEffect(GrEffectEdgeType edgeType, int n, const S kScalar edges[]) 339 GrConvexPolyEffect::GrConvexPolyEffect(GrPrimitiveEdgeType edgeType, int n, cons t SkScalar edges[])
340 : fEdgeType(edgeType) 340 : fEdgeType(edgeType)
341 , fEdgeCount(n) { 341 , fEdgeCount(n) {
342 // Factory function should have already ensured this. 342 // Factory function should have already ensured this.
343 SkASSERT(n <= kMaxEdges); 343 SkASSERT(n <= kMaxEdges);
344 memcpy(fEdges, edges, 3 * n * sizeof(SkScalar)); 344 memcpy(fEdges, edges, 3 * n * sizeof(SkScalar));
345 // Outset the edges by 0.5 so that a pixel with center on an edge is 50% cov ered in the AA case 345 // Outset the edges by 0.5 so that a pixel with center on an edge is 50% cov ered in the AA case
346 // and 100% covered in the non-AA case. 346 // and 100% covered in the non-AA case.
347 for (int i = 0; i < n; ++i) { 347 for (int i = 0; i < n; ++i) {
348 fEdges[3 * i + 2] += SK_ScalarHalf; 348 fEdges[3 * i + 2] += SK_ScalarHalf;
349 } 349 }
350 this->setWillReadFragmentPosition(); 350 this->setWillReadFragmentPosition();
351 } 351 }
352 352
353 bool GrConvexPolyEffect::onIsEqual(const GrEffect& other) const { 353 bool GrConvexPolyEffect::onIsEqual(const GrProcessor& other) const {
354 const GrConvexPolyEffect& cpe = other.cast<GrConvexPolyEffect>(); 354 const GrConvexPolyEffect& cpe = other.cast<GrConvexPolyEffect>();
355 // ignore the fact that 0 == -0 and just use memcmp. 355 // ignore the fact that 0 == -0 and just use memcmp.
356 return (cpe.fEdgeType == fEdgeType && cpe.fEdgeCount == fEdgeCount && 356 return (cpe.fEdgeType == fEdgeType && cpe.fEdgeCount == fEdgeCount &&
357 0 == memcmp(cpe.fEdges, fEdges, 3 * fEdgeCount * sizeof(SkScalar))); 357 0 == memcmp(cpe.fEdges, fEdges, 3 * fEdgeCount * sizeof(SkScalar)));
358 } 358 }
359 359
360 ////////////////////////////////////////////////////////////////////////////// 360 //////////////////////////////////////////////////////////////////////////////
361 361
362 GR_DEFINE_EFFECT_TEST(GrConvexPolyEffect); 362 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConvexPolyEffect);
363 363
364 GrEffect* GrConvexPolyEffect::TestCreate(SkRandom* random, 364 GrFragmentProcessor* GrConvexPolyEffect::TestCreate(SkRandom* random,
365 GrContext*, 365 GrContext*,
366 const GrDrawTargetCaps& caps, 366 const GrDrawTargetCaps& caps ,
367 GrTexture*[]) { 367 GrTexture*[]) {
368 int count = random->nextULessThan(kMaxEdges) + 1; 368 int count = random->nextULessThan(kMaxEdges) + 1;
369 SkScalar edges[kMaxEdges * 3]; 369 SkScalar edges[kMaxEdges * 3];
370 for (int i = 0; i < 3 * count; ++i) { 370 for (int i = 0; i < 3 * count; ++i) {
371 edges[i] = random->nextSScalar1(); 371 edges[i] = random->nextSScalar1();
372 } 372 }
373 373
374 GrEffect* effect; 374 GrFragmentProcessor* fp;
375 do { 375 do {
376 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>( 376 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(
377 random->nextULessThan(kGrEffectEdgeTypeC nt)); 377 random->nextULessThan(kGrProcessorEdgeTy peCnt));
378 effect = GrConvexPolyEffect::Create(edgeType, count, edges); 378 fp = GrConvexPolyEffect::Create(edgeType, count, edges);
379 } while (NULL == effect); 379 } while (NULL == fp);
380 return effect; 380 return fp;
381 } 381 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrConvexPolyEffect.h ('k') | src/gpu/effects/GrConvolutionEffect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698