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

Side by Side Diff: src/gpu/GrAARectRenderer.cpp

Issue 582963002: Solo gp (Closed) Base URL: https://skia.googlesource.com/skia.git@no_peb
Patch Set: fix 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
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 "GrAARectRenderer.h" 8 #include "GrAARectRenderer.h"
9 #include "GrGpu.h" 9 #include "GrGpu.h"
10 #include "gl/builders/GrGLFullProgramBuilder.h" 10 #include "gl/builders/GrGLFullProgramBuilder.h"
11 #include "gl/GrGLEffect.h" 11 #include "gl/GrGLProcessor.h"
12 #include "gl/GrGLGeometryProcessor.h" 12 #include "gl/GrGLGeometryProcessor.h"
13 #include "GrTBackendEffectFactory.h" 13 #include "GrTBackendProcessorFactory.h"
14 #include "SkColorPriv.h" 14 #include "SkColorPriv.h"
15 #include "effects/GrGeometryProcessor.h" 15 #include "GrGeometryProcessor.h"
16 16
17 /////////////////////////////////////////////////////////////////////////////// 17 ///////////////////////////////////////////////////////////////////////////////
18 class GrGLAlignedRectEffect; 18 class GrGLAlignedRectEffect;
19 19
20 // Axis Aligned special case 20 // Axis Aligned special case
21 class GrAlignedRectEffect : public GrGeometryProcessor { 21 class GrAlignedRectEffect : public GrGeometryProcessor {
22 public: 22 public:
23 static GrEffect* Create() { 23 static GrGeometryProcessor* Create() {
24 GR_CREATE_STATIC_EFFECT(gAlignedRectEffect, GrAlignedRectEffect, ()); 24 GR_CREATE_STATIC_GEOMETRY_PROCESSOR(gAlignedRectEffect, GrAlignedRectEff ect, ());
25 gAlignedRectEffect->ref(); 25 gAlignedRectEffect->ref();
26 return gAlignedRectEffect; 26 return gAlignedRectEffect;
27 } 27 }
28 28
29 virtual ~GrAlignedRectEffect() {} 29 virtual ~GrAlignedRectEffect() {}
30 30
31 static const char* Name() { return "AlignedRectEdge"; } 31 static const char* Name() { return "AlignedRectEdge"; }
32 32
33 virtual void getConstantColorComponents(GrColor* color, 33 virtual void getConstantColorComponents(GrColor* color,
34 uint32_t* validFlags) const SK_OVERR IDE { 34 uint32_t* validFlags) const SK_OVERR IDE {
35 *validFlags = 0; 35 *validFlags = 0;
36 } 36 }
37 37
38 const GrShaderVar& inRect() const { return fInRect; } 38 const GrShaderVar& inRect() const { return fInRect; }
39 39
40 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { 40 virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERR IDE {
41 return GrTBackendEffectFactory<GrAlignedRectEffect>::getInstance(); 41 return GrTBackendGeometryProcessorFactory<GrAlignedRectEffect>::getInsta nce();
42 } 42 }
43 43
44 class GLEffect : public GrGLGeometryProcessor { 44 class GLProcessor : public GrGLGeometryProcessor {
45 public: 45 public:
46 GLEffect(const GrBackendEffectFactory& factory, const GrEffect&) 46 GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor& )
47 : INHERITED (factory) {} 47 : INHERITED (factory) {}
48 48
49 virtual void emitCode(GrGLFullProgramBuilder* builder, 49 virtual void emitCode(GrGLFullProgramBuilder* builder,
50 const GrEffect& effect, 50 const GrGeometryProcessor& geometryProcessor,
51 const GrEffectKey& key, 51 const GrProcessorKey& key,
52 const char* outputColor, 52 const char* outputColor,
53 const char* inputColor, 53 const char* inputColor,
54 const TransformedCoordsArray&, 54 const TransformedCoordsArray&,
55 const TextureSamplerArray& samplers) SK_OVERRIDE { 55 const TextureSamplerArray& samplers) SK_OVERRIDE {
56 // setup the varying for the Axis aligned rect effect 56 // setup the varying for the Axis aligned rect effect
57 // xy -> interpolated offset 57 // xy -> interpolated offset
58 // zw -> w/2+0.5, h/2+0.5 58 // zw -> w/2+0.5, h/2+0.5
59 const char *vsRectName, *fsRectName; 59 const char *vsRectName, *fsRectName;
60 builder->addVarying(kVec4f_GrSLType, "Rect", &vsRectName, &fsRectNam e); 60 builder->addVarying(kVec4f_GrSLType, "Rect", &vsRectName, &fsRectNam e);
61 61
62 const GrShaderVar& inRect = effect.cast<GrAlignedRectEffect>().inRec t(); 62 const GrShaderVar& inRect = geometryProcessor.cast<GrAlignedRectEffe ct>().inRect();
63 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder (); 63 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder ();
64 vsBuilder->codeAppendf("\t%s = %s;\n", vsRectName, inRect.c_str()); 64 vsBuilder->codeAppendf("\t%s = %s;\n", vsRectName, inRect.c_str());
65 65
66 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBui lder(); 66 GrGLBaseFragmentShaderBuilder* fsBuilder = builder->getFragmentShade rBuilder();
67 // TODO: compute all these offsets, spans, and scales in the VS 67 // TODO: compute all these offsets, spans, and scales in the VS
68 fsBuilder->codeAppendf("\tfloat insetW = min(1.0, %s.z) - 0.5;\n", f sRectName); 68 fsBuilder->codeAppendf("\tfloat insetW = min(1.0, %s.z) - 0.5;\n", f sRectName);
69 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.w) - 0.5;\n", f sRectName); 69 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.w) - 0.5;\n", f sRectName);
70 fsBuilder->codeAppend("\tfloat outset = 0.5;\n"); 70 fsBuilder->codeAppend("\tfloat outset = 0.5;\n");
71 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0 ). For rects 71 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0 ). For rects
72 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a 0 .. 1 range. 72 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a 0 .. 1 range.
73 fsBuilder->codeAppend("\tfloat spanW = insetW + outset;\n"); 73 fsBuilder->codeAppend("\tfloat spanW = insetW + outset;\n");
74 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n"); 74 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n");
75 // For rects < 1 pixel wide or tall, these scale factors are used to cap the maximum 75 // For rects < 1 pixel wide or tall, these scale factors are used to cap the maximum
76 // value of coverage that is used. In other words it is the coverage that is 76 // value of coverage that is used. In other words it is the coverage that is
77 // used in the interior of the rect after the ramp. 77 // used in the interior of the rect after the ramp.
78 fsBuilder->codeAppend("\tfloat scaleW = min(1.0, 2.0*insetW/spanW);\ n"); 78 fsBuilder->codeAppend("\tfloat scaleW = min(1.0, 2.0*insetW/spanW);\ n");
79 fsBuilder->codeAppend("\tfloat scaleH = min(1.0, 2.0*insetH/spanH);\ n"); 79 fsBuilder->codeAppend("\tfloat scaleH = min(1.0, 2.0*insetH/spanH);\ n");
80 80
81 // Compute the coverage for the rect's width 81 // Compute the coverage for the rect's width
82 fsBuilder->codeAppendf( 82 fsBuilder->codeAppendf(
83 "\tfloat coverage = scaleW*clamp((%s.z-abs(%s.x))/spanW, 0.0, 1. 0);\n", fsRectName, 83 "\tfloat coverage = scaleW*clamp((%s.z-abs(%s.x))/spanW, 0.0, 1. 0);\n", fsRectName,
84 fsRectName); 84 fsRectName);
85 // Compute the coverage for the rect's height and merge with the wid th 85 // Compute the coverage for the rect's height and merge with the wid th
86 fsBuilder->codeAppendf( 86 fsBuilder->codeAppendf(
87 "\tcoverage = coverage*scaleH*clamp((%s.w-abs(%s.y))/spanH, 0.0, 1.0);\n", 87 "\tcoverage = coverage*scaleH*clamp((%s.w-abs(%s.y))/spanH, 0.0, 1.0);\n",
88 fsRectName, fsRectName); 88 fsRectName, fsRectName);
89 89
90 90
91 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, 91 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor,
92 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("cover age")).c_str()); 92 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("cover age")).c_str());
93 } 93 }
94 94
95 static void GenKey(const GrEffect&, const GrGLCaps&, GrEffectKeyBuilder* ) {} 95 static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBu ilder*) {}
96 96
97 virtual void setData(const GrGLProgramDataManager& pdman, const GrEffect &) SK_OVERRIDE {} 97 virtual void setData(const GrGLProgramDataManager& pdman, const GrProces sor&) SK_OVERRIDE {}
98 98
99 private: 99 private:
100 typedef GrGLGeometryProcessor INHERITED; 100 typedef GrGLGeometryProcessor INHERITED;
101 }; 101 };
102 102
103 103
104 private: 104 private:
105 GrAlignedRectEffect() 105 GrAlignedRectEffect()
106 : fInRect(this->addVertexAttrib(GrShaderVar("inRect", 106 : fInRect(this->addVertexAttrib(GrShaderVar("inRect",
107 kVec4f_GrSLType, 107 kVec4f_GrSLType,
108 GrShaderVar::kAttribute_Type Modifier))) { 108 GrShaderVar::kAttribute_Type Modifier))) {
109 } 109 }
110 110
111 const GrShaderVar& fInRect; 111 const GrShaderVar& fInRect;
112 112
113 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE { return true; } 113 virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE { return true; }
114 114
115 GR_DECLARE_EFFECT_TEST; 115 GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
116 116
117 typedef GrGeometryProcessor INHERITED; 117 typedef GrGeometryProcessor INHERITED;
118 }; 118 };
119 119
120 120
121 GR_DEFINE_EFFECT_TEST(GrAlignedRectEffect); 121 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrAlignedRectEffect);
122 122
123 GrEffect* GrAlignedRectEffect::TestCreate(SkRandom* random, 123 GrGeometryProcessor* GrAlignedRectEffect::TestCreate(SkRandom* random,
124 GrContext* context, 124 GrContext* context,
125 const GrDrawTargetCaps&, 125 const GrDrawTargetCaps&,
126 GrTexture* textures[]) { 126 GrTexture* textures[]) {
127 return GrAlignedRectEffect::Create(); 127 return GrAlignedRectEffect::Create();
128 } 128 }
129 129
130 /////////////////////////////////////////////////////////////////////////////// 130 ///////////////////////////////////////////////////////////////////////////////
131 class GrGLRectEffect; 131 class GrGLRectEffect;
132 132
133 /** 133 /**
134 * The output of this effect is a modulation of the input color and coverage 134 * The output of this effect is a modulation of the input color and coverage
135 * for an arbitrarily oriented rect. The rect is specified as: 135 * for an arbitrarily oriented rect. The rect is specified as:
136 * Center of the rect 136 * Center of the rect
137 * Unit vector point down the height of the rect 137 * Unit vector point down the height of the rect
138 * Half width + 0.5 138 * Half width + 0.5
139 * Half height + 0.5 139 * Half height + 0.5
140 * The center and vector are stored in a vec4 varying ("RectEdge") with the 140 * The center and vector are stored in a vec4 varying ("RectEdge") with the
141 * center in the xy components and the vector in the zw components. 141 * center in the xy components and the vector in the zw components.
142 * The munged width and height are stored in a vec2 varying ("WidthHeight") 142 * The munged width and height are stored in a vec2 varying ("WidthHeight")
143 * with the width in x and the height in y. 143 * with the width in x and the height in y.
144 */ 144 */
145 145
146 class GrRectEffect : public GrGeometryProcessor { 146 class GrRectEffect : public GrGeometryProcessor {
147 public: 147 public:
148 static GrEffect* Create() { 148 static GrGeometryProcessor* Create() {
149 GR_CREATE_STATIC_EFFECT(gRectEffect, GrRectEffect, ()); 149 GR_CREATE_STATIC_GEOMETRY_PROCESSOR(gRectEffect, GrRectEffect, ());
150 gRectEffect->ref(); 150 gRectEffect->ref();
151 return gRectEffect; 151 return gRectEffect;
152 } 152 }
153 153
154 virtual ~GrRectEffect() {} 154 virtual ~GrRectEffect() {}
155 155
156 static const char* Name() { return "RectEdge"; } 156 static const char* Name() { return "RectEdge"; }
157 157
158 virtual void getConstantColorComponents(GrColor* color, 158 virtual void getConstantColorComponents(GrColor* color,
159 uint32_t* validFlags) const SK_OVERR IDE { 159 uint32_t* validFlags) const SK_OVERR IDE {
160 *validFlags = 0; 160 *validFlags = 0;
161 } 161 }
162 162
163 const GrShaderVar& inRectEdge() const { return fInRectEdge; } 163 const GrShaderVar& inRectEdge() const { return fInRectEdge; }
164 const GrShaderVar& inWidthHeight() const { return fInWidthHeight; } 164 const GrShaderVar& inWidthHeight() const { return fInWidthHeight; }
165 165
166 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { 166 virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERR IDE {
167 return GrTBackendEffectFactory<GrRectEffect>::getInstance(); 167 return GrTBackendGeometryProcessorFactory<GrRectEffect>::getInstance();
168 } 168 }
169 169
170 class GLEffect : public GrGLGeometryProcessor { 170 class GLProcessor : public GrGLGeometryProcessor {
171 public: 171 public:
172 GLEffect(const GrBackendEffectFactory& factory, const GrEffect&) 172 GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor& )
173 : INHERITED (factory) {} 173 : INHERITED (factory) {}
174 174
175 virtual void emitCode(GrGLFullProgramBuilder* builder, 175 virtual void emitCode(GrGLFullProgramBuilder* builder,
176 const GrEffect& effect, 176 const GrGeometryProcessor& geometryProcessor,
177 const GrEffectKey& key, 177 const GrProcessorKey& key,
178 const char* outputColor, 178 const char* outputColor,
179 const char* inputColor, 179 const char* inputColor,
180 const TransformedCoordsArray&, 180 const TransformedCoordsArray&,
181 const TextureSamplerArray& samplers) SK_OVERRIDE { 181 const TextureSamplerArray& samplers) SK_OVERRIDE {
182 // setup the varying for the center point and the unit vector 182 // setup the varying for the center point and the unit vector
183 // that points down the height of the rect 183 // that points down the height of the rect
184 const char *vsRectEdgeName, *fsRectEdgeName; 184 const char *vsRectEdgeName, *fsRectEdgeName;
185 builder->addVarying(kVec4f_GrSLType, "RectEdge", 185 builder->addVarying(kVec4f_GrSLType, "RectEdge",
186 &vsRectEdgeName, &fsRectEdgeName); 186 &vsRectEdgeName, &fsRectEdgeName);
187 187
188 const GrRectEffect& rectEffect = effect.cast<GrRectEffect>(); 188 const GrRectEffect& rectEffect = geometryProcessor.cast<GrRectEffect >();
189 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder (); 189 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder ();
190 vsBuilder->codeAppendf("%s = %s;", vsRectEdgeName, rectEffect.inRect Edge().c_str()); 190 vsBuilder->codeAppendf("%s = %s;", vsRectEdgeName, rectEffect.inRect Edge().c_str());
191 191
192 // setup the varying for width/2+.5 and height/2+.5 192 // setup the varying for width/2+.5 and height/2+.5
193 const char *vsWidthHeightName, *fsWidthHeightName; 193 const char *vsWidthHeightName, *fsWidthHeightName;
194 builder->addVarying(kVec2f_GrSLType, "WidthHeight", 194 builder->addVarying(kVec2f_GrSLType, "WidthHeight",
195 &vsWidthHeightName, &fsWidthHeightName); 195 &vsWidthHeightName, &fsWidthHeightName);
196 vsBuilder->codeAppendf("%s = %s;", 196 vsBuilder->codeAppendf("%s = %s;",
197 vsWidthHeightName, 197 vsWidthHeightName,
198 rectEffect.inWidthHeight().c_str()); 198 rectEffect.inWidthHeight().c_str());
199 199
200 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBui lder(); 200 GrGLBaseFragmentShaderBuilder* fsBuilder = builder->getFragmentShade rBuilder();
201 // TODO: compute all these offsets, spans, and scales in the VS 201 // TODO: compute all these offsets, spans, and scales in the VS
202 fsBuilder->codeAppendf("\tfloat insetW = min(1.0, %s.x) - 0.5;\n", f sWidthHeightName); 202 fsBuilder->codeAppendf("\tfloat insetW = min(1.0, %s.x) - 0.5;\n", f sWidthHeightName);
203 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.y) - 0.5;\n", f sWidthHeightName); 203 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.y) - 0.5;\n", f sWidthHeightName);
204 fsBuilder->codeAppend("\tfloat outset = 0.5;\n"); 204 fsBuilder->codeAppend("\tfloat outset = 0.5;\n");
205 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0 ). For rects 205 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0 ). For rects
206 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a 0 .. 1 range. 206 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a 0 .. 1 range.
207 fsBuilder->codeAppend("\tfloat spanW = insetW + outset;\n"); 207 fsBuilder->codeAppend("\tfloat spanW = insetW + outset;\n");
208 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n"); 208 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n");
209 // For rects < 1 pixel wide or tall, these scale factors are used to cap the maximum 209 // For rects < 1 pixel wide or tall, these scale factors are used to cap the maximum
210 // value of coverage that is used. In other words it is the coverage that is 210 // value of coverage that is used. In other words it is the coverage that is
(...skipping 15 matching lines...) Expand all
226 fsRectEdgeName); 226 fsRectEdgeName);
227 fsBuilder->codeAppendf( 227 fsBuilder->codeAppendf(
228 "\tcoverage = coverage*scaleH*clamp((%s.y-perpDot)/spanH, 0. 0, 1.0);\n", 228 "\tcoverage = coverage*scaleH*clamp((%s.y-perpDot)/spanH, 0. 0, 1.0);\n",
229 fsWidthHeightName); 229 fsWidthHeightName);
230 230
231 231
232 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, 232 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor,
233 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("cover age")).c_str()); 233 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("cover age")).c_str());
234 } 234 }
235 235
236 static void GenKey(const GrEffect&, const GrGLCaps&, GrEffectKeyBuilder* ) {} 236 static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBu ilder*) {}
237 237
238 virtual void setData(const GrGLProgramDataManager& pdman, const GrEffect &) SK_OVERRIDE {} 238 virtual void setData(const GrGLProgramDataManager& pdman, const GrProces sor&) SK_OVERRIDE {}
239 239
240 private: 240 private:
241 typedef GrGLGeometryProcessor INHERITED; 241 typedef GrGLGeometryProcessor INHERITED;
242 }; 242 };
243 243
244 244
245 245
246 private: 246 private:
247 GrRectEffect() 247 GrRectEffect()
248 : fInRectEdge(this->addVertexAttrib(GrShaderVar("inRectEdge", 248 : fInRectEdge(this->addVertexAttrib(GrShaderVar("inRectEdge",
249 kVec4f_GrSLType, 249 kVec4f_GrSLType,
250 GrShaderVar::kAttribute_ TypeModifier))) 250 GrShaderVar::kAttribute_ TypeModifier)))
251 , fInWidthHeight(this->addVertexAttrib( 251 , fInWidthHeight(this->addVertexAttrib(
252 GrShaderVar("inWidthHeight", 252 GrShaderVar("inWidthHeight",
253 kVec2f_GrSLType, 253 kVec2f_GrSLType,
254 GrShaderVar::kAttribute_TypeModifier))) { 254 GrShaderVar::kAttribute_TypeModifier))) {
255 this->setWillReadFragmentPosition(); 255 this->setWillReadFragmentPosition();
256 } 256 }
257 257
258 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE { return true; } 258 virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE { return true; }
259 259
260 const GrShaderVar& fInRectEdge; 260 const GrShaderVar& fInRectEdge;
261 const GrShaderVar& fInWidthHeight; 261 const GrShaderVar& fInWidthHeight;
262 262
263 GR_DECLARE_EFFECT_TEST; 263 GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
264 264
265 typedef GrGeometryProcessor INHERITED; 265 typedef GrGeometryProcessor INHERITED;
266 }; 266 };
267 267
268 268
269 GR_DEFINE_EFFECT_TEST(GrRectEffect); 269 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrRectEffect);
270 270
271 GrEffect* GrRectEffect::TestCreate(SkRandom* random, 271 GrGeometryProcessor* GrRectEffect::TestCreate(SkRandom* random,
272 GrContext* context, 272 GrContext* context,
273 const GrDrawTargetCaps&, 273 const GrDrawTargetCaps&,
274 GrTexture* textures[]) { 274 GrTexture* textures[]) {
275 return GrRectEffect::Create(); 275 return GrRectEffect::Create();
276 } 276 }
277 277
278 /////////////////////////////////////////////////////////////////////////////// 278 ///////////////////////////////////////////////////////////////////////////////
279 279
280 namespace { 280 namespace {
281 extern const GrVertexAttrib gAARectAttribs[] = { 281 extern const GrVertexAttrib gAARectAttribs[] = {
282 {kVec2f_GrVertexAttribType, 0, kPosition_Gr VertexAttribBinding}, 282 {kVec2f_GrVertexAttribType, 0, kPosition_Gr VertexAttribBinding},
283 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer texAttribBinding}, 283 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer texAttribBinding},
284 {kVec4ub_GrVertexAttribType, sizeof(SkPoint) + sizeof(SkColor), kCoverage_Gr VertexAttribBinding}, 284 {kVec4ub_GrVertexAttribType, sizeof(SkPoint) + sizeof(SkColor), kCoverage_Gr VertexAttribBinding},
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 struct RectVertex { 604 struct RectVertex {
605 SkPoint fPos; 605 SkPoint fPos;
606 SkPoint fCenter; 606 SkPoint fCenter;
607 SkPoint fDir; 607 SkPoint fDir;
608 SkPoint fWidthHeight; 608 SkPoint fWidthHeight;
609 }; 609 };
610 610
611 // Rotated 611 // Rotated
612 extern const GrVertexAttrib gAARectVertexAttribs[] = { 612 extern const GrVertexAttrib gAARectVertexAttribs[] = {
613 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind ing }, 613 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind ing },
614 { kVec4f_GrVertexAttribType, sizeof(SkPoint), kEffect_GrVertexAttribBindin g }, 614 { kVec4f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexA ttribBinding },
615 { kVec2f_GrVertexAttribType, 3*sizeof(SkPoint), kEffect_GrVertexAttribBindin g } 615 { kVec2f_GrVertexAttribType, 3*sizeof(SkPoint), kGeometryProcessor_GrVertexA ttribBinding }
616 }; 616 };
617 617
618 // Axis Aligned 618 // Axis Aligned
619 struct AARectVertex { 619 struct AARectVertex {
620 SkPoint fPos; 620 SkPoint fPos;
621 SkPoint fOffset; 621 SkPoint fOffset;
622 SkPoint fWidthHeight; 622 SkPoint fWidthHeight;
623 }; 623 };
624 624
625 // Axis Aligned 625 // Axis Aligned
626 extern const GrVertexAttrib gAAAARectVertexAttribs[] = { 626 extern const GrVertexAttrib gAAAARectVertexAttribs[] = {
627 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind ing }, 627 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind ing },
628 { kVec4f_GrVertexAttribType, sizeof(SkPoint), kEffect_GrVertexAttribBindin g }, 628 { kVec4f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexA ttribBinding },
629 }; 629 };
630 630
631 }; 631 };
632 632
633 void GrAARectRenderer::shaderFillAARect(GrGpu* gpu, 633 void GrAARectRenderer::shaderFillAARect(GrGpu* gpu,
634 GrDrawTarget* target, 634 GrDrawTarget* target,
635 const SkRect& rect, 635 const SkRect& rect,
636 const SkMatrix& combinedMatrix) { 636 const SkMatrix& combinedMatrix) {
637 GrDrawState* drawState = target->drawState(); 637 GrDrawState* drawState = target->drawState();
638 638
(...skipping 16 matching lines...) Expand all
655 sizeof(RectVertex)); 655 sizeof(RectVertex));
656 656
657 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); 657 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0);
658 if (!geo.succeeded()) { 658 if (!geo.succeeded()) {
659 GrPrintf("Failed to get space for vertices!\n"); 659 GrPrintf("Failed to get space for vertices!\n");
660 return; 660 return;
661 } 661 }
662 662
663 RectVertex* verts = reinterpret_cast<RectVertex*>(geo.vertices()); 663 RectVertex* verts = reinterpret_cast<RectVertex*>(geo.vertices());
664 664
665 GrEffect* effect = GrRectEffect::Create(); 665 GrGeometryProcessor* gp = GrRectEffect::Create();
666 drawState->setGeometryProcessor(effect)->unref(); 666 drawState->setGeometryProcessor(gp)->unref();
667 667
668 for (int i = 0; i < 4; ++i) { 668 for (int i = 0; i < 4; ++i) {
669 verts[i].fCenter = center; 669 verts[i].fCenter = center;
670 verts[i].fDir = dir; 670 verts[i].fDir = dir;
671 verts[i].fWidthHeight.fX = newWidth; 671 verts[i].fWidthHeight.fX = newWidth;
672 verts[i].fWidthHeight.fY = newHeight; 672 verts[i].fWidthHeight.fY = newHeight;
673 } 673 }
674 674
675 SkRect devRect; 675 SkRect devRect;
676 combinedMatrix.mapRect(&devRect, rect); 676 combinedMatrix.mapRect(&devRect, rect);
(...skipping 26 matching lines...) Expand all
703 sizeof(AARectVertex)); 703 sizeof(AARectVertex));
704 704
705 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); 705 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0);
706 if (!geo.succeeded()) { 706 if (!geo.succeeded()) {
707 GrPrintf("Failed to get space for vertices!\n"); 707 GrPrintf("Failed to get space for vertices!\n");
708 return; 708 return;
709 } 709 }
710 710
711 AARectVertex* verts = reinterpret_cast<AARectVertex*>(geo.vertices()); 711 AARectVertex* verts = reinterpret_cast<AARectVertex*>(geo.vertices());
712 712
713 GrEffect* effect = GrAlignedRectEffect::Create(); 713 GrGeometryProcessor* gp = GrAlignedRectEffect::Create();
714 drawState->setGeometryProcessor(effect)->unref(); 714 drawState->setGeometryProcessor(gp)->unref();
715 715
716 SkRect devRect; 716 SkRect devRect;
717 combinedMatrix.mapRect(&devRect, rect); 717 combinedMatrix.mapRect(&devRect, rect);
718 718
719 SkRect devBounds = { 719 SkRect devBounds = {
720 devRect.fLeft - SK_ScalarHalf, 720 devRect.fLeft - SK_ScalarHalf,
721 devRect.fTop - SK_ScalarHalf, 721 devRect.fTop - SK_ScalarHalf,
722 devRect.fRight + SK_ScalarHalf, 722 devRect.fRight + SK_ScalarHalf,
723 devRect.fBottom + SK_ScalarHalf 723 devRect.fBottom + SK_ScalarHalf
724 }; 724 };
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 // can't call mapRect for devInside since it calls sort 963 // can't call mapRect for devInside since it calls sort
964 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ; 964 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ;
965 965
966 if (devInside.isEmpty()) { 966 if (devInside.isEmpty()) {
967 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside); 967 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside);
968 return; 968 return;
969 } 969 }
970 970
971 this->geometryStrokeAARect(gpu, target, devOutside, devOutsideAssist, devIns ide, true); 971 this->geometryStrokeAARect(gpu, target, devOutside, devOutsideAssist, devIns ide, true);
972 } 972 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698