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

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

Issue 25474006: Move VertexBuilder to a GrGLFullShaderBuilder subclass (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
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/GrGLEffect.h" 10 #include "gl/GrGLEffect.h"
(...skipping 21 matching lines...) Expand all
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 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { 38 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE {
39 return GrTBackendEffectFactory<GrAlignedRectEffect>::getInstance(); 39 return GrTBackendEffectFactory<GrAlignedRectEffect>::getInstance();
40 } 40 }
41 41
42 class GLEffect : public GrGLEffect { 42 class GLEffect : public GrGLVertexEffect {
43 public: 43 public:
44 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) 44 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
45 : INHERITED (factory) {} 45 : INHERITED (factory) {}
46 46
47 virtual void emitCode(GrGLShaderBuilder* builder, 47 virtual void emitCode(GrGLFullShaderBuilder* builder,
48 const GrDrawEffect& drawEffect, 48 const GrDrawEffect& drawEffect,
49 EffectKey key, 49 EffectKey key,
50 const char* outputColor, 50 const char* outputColor,
51 const char* inputColor, 51 const char* inputColor,
52 const TransformedCoordsArray&, 52 const TransformedCoordsArray&,
53 const TextureSamplerArray& samplers) SK_OVERRIDE { 53 const TextureSamplerArray& samplers) SK_OVERRIDE {
54 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertex Builder();
55 SkASSERT(NULL != vertexBuilder);
56
57 // setup the varying for the Axis aligned rect effect 54 // setup the varying for the Axis aligned rect effect
58 // xy -> interpolated offset 55 // xy -> interpolated offset
59 // zw -> w/2+0.5, h/2+0.5 56 // zw -> w/2+0.5, h/2+0.5
60 const char *vsRectName, *fsRectName; 57 const char *vsRectName, *fsRectName;
61 vertexBuilder->addVarying(kVec4f_GrSLType, "Rect", &vsRectName, &fsR ectName); 58 builder->addVarying(kVec4f_GrSLType, "Rect", &vsRectName, &fsRectNam e);
62 const SkString* attr0Name = 59 const SkString* attr0Name =
63 vertexBuilder->getEffectAttributeName(drawEffect.getVertexAttrib Indices()[0]); 60 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice s()[0]);
64 vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsRectName, attr0Name-> c_str()); 61 builder->vsCodeAppendf("\t%s = %s;\n", vsRectName, attr0Name->c_str( ));
65 62
66 // TODO: compute all these offsets, spans, and scales in the VS 63 // TODO: compute all these offsets, spans, and scales in the VS
67 builder->fsCodeAppendf("\tfloat insetW = min(1.0, %s.z) - 0.5;\n", f sRectName); 64 builder->fsCodeAppendf("\tfloat insetW = min(1.0, %s.z) - 0.5;\n", f sRectName);
68 builder->fsCodeAppendf("\tfloat insetH = min(1.0, %s.w) - 0.5;\n", f sRectName); 65 builder->fsCodeAppendf("\tfloat insetH = min(1.0, %s.w) - 0.5;\n", f sRectName);
69 builder->fsCodeAppend("\tfloat outset = 0.5;\n"); 66 builder->fsCodeAppend("\tfloat outset = 0.5;\n");
70 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0 ). For rects 67 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0 ). For rects
71 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a 0 .. 1 range. 68 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a 0 .. 1 range.
72 builder->fsCodeAppend("\tfloat spanW = insetW + outset;\n"); 69 builder->fsCodeAppend("\tfloat spanW = insetW + outset;\n");
73 builder->fsCodeAppend("\tfloat spanH = insetH + outset;\n"); 70 builder->fsCodeAppend("\tfloat spanH = insetH + outset;\n");
74 // For rects < 1 pixel wide or tall, these scale factors are used to cap the maximum 71 // For rects < 1 pixel wide or tall, these scale factors are used to cap the maximum
(...skipping 16 matching lines...) Expand all
91 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str() ); 88 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str() );
92 } 89 }
93 90
94 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG LCaps&) { 91 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG LCaps&) {
95 return 0; 92 return 0;
96 } 93 }
97 94
98 virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect& ) SK_OVERRIDE {} 95 virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect& ) SK_OVERRIDE {}
99 96
100 private: 97 private:
101 typedef GrGLEffect INHERITED; 98 typedef GrGLVertexEffect INHERITED;
102 }; 99 };
103 100
104 101
105 private: 102 private:
106 GrAlignedRectEffect() : GrVertexEffect() { 103 GrAlignedRectEffect() : GrVertexEffect() {
107 this->addVertexAttrib(kVec4f_GrSLType); 104 this->addVertexAttrib(kVec4f_GrSLType);
108 } 105 }
109 106
110 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE { return true; } 107 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE { return true; }
111 108
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 150
154 virtual void getConstantColorComponents(GrColor* color, 151 virtual void getConstantColorComponents(GrColor* color,
155 uint32_t* validFlags) const SK_OVERR IDE { 152 uint32_t* validFlags) const SK_OVERR IDE {
156 *validFlags = 0; 153 *validFlags = 0;
157 } 154 }
158 155
159 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { 156 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE {
160 return GrTBackendEffectFactory<GrRectEffect>::getInstance(); 157 return GrTBackendEffectFactory<GrRectEffect>::getInstance();
161 } 158 }
162 159
163 class GLEffect : public GrGLEffect { 160 class GLEffect : public GrGLVertexEffect {
164 public: 161 public:
165 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) 162 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
166 : INHERITED (factory) {} 163 : INHERITED (factory) {}
167 164
168 virtual void emitCode(GrGLShaderBuilder* builder, 165 virtual void emitCode(GrGLFullShaderBuilder* builder,
169 const GrDrawEffect& drawEffect, 166 const GrDrawEffect& drawEffect,
170 EffectKey key, 167 EffectKey key,
171 const char* outputColor, 168 const char* outputColor,
172 const char* inputColor, 169 const char* inputColor,
173 const TransformedCoordsArray&, 170 const TransformedCoordsArray&,
174 const TextureSamplerArray& samplers) SK_OVERRIDE { 171 const TextureSamplerArray& samplers) SK_OVERRIDE {
175 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertex Builder();
176 SkASSERT(NULL != vertexBuilder);
177
178 // setup the varying for the center point and the unit vector 172 // setup the varying for the center point and the unit vector
179 // that points down the height of the rect 173 // that points down the height of the rect
180 const char *vsRectEdgeName, *fsRectEdgeName; 174 const char *vsRectEdgeName, *fsRectEdgeName;
181 vertexBuilder->addVarying(kVec4f_GrSLType, "RectEdge", 175 builder->addVarying(kVec4f_GrSLType, "RectEdge",
182 &vsRectEdgeName, &fsRectEdgeName); 176 &vsRectEdgeName, &fsRectEdgeName);
bsalomon 2013/10/03 14:44:52 can you realign the params?
Chris Dalton 2013/10/03 21:43:22 Done.
183 const SkString* attr0Name = 177 const SkString* attr0Name =
184 vertexBuilder->getEffectAttributeName(drawEffect.getVertexAttrib Indices()[0]); 178 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice s()[0]);
185 vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsRectEdgeName, attr0Na me->c_str()); 179 builder->vsCodeAppendf("\t%s = %s;\n", vsRectEdgeName, attr0Name->c_ str());
186 180
187 // setup the varying for width/2+.5 and height/2+.5 181 // setup the varying for width/2+.5 and height/2+.5
188 const char *vsWidthHeightName, *fsWidthHeightName; 182 const char *vsWidthHeightName, *fsWidthHeightName;
189 vertexBuilder->addVarying(kVec2f_GrSLType, "WidthHeight", 183 builder->addVarying(kVec2f_GrSLType, "WidthHeight",
190 &vsWidthHeightName, &fsWidthHeightName); 184 &vsWidthHeightName, &fsWidthHeightName);
191 const SkString* attr1Name = 185 const SkString* attr1Name =
192 vertexBuilder->getEffectAttributeName(drawEffect.getVertexAttrib Indices()[1]); 186 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice s()[1]);
193 vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsWidthHeightName, attr 1Name->c_str()); 187 builder->vsCodeAppendf("\t%s = %s;\n", vsWidthHeightName, attr1Name- >c_str());
194 188
195 // TODO: compute all these offsets, spans, and scales in the VS 189 // TODO: compute all these offsets, spans, and scales in the VS
196 builder->fsCodeAppendf("\tfloat insetW = min(1.0, %s.x) - 0.5;\n", f sWidthHeightName); 190 builder->fsCodeAppendf("\tfloat insetW = min(1.0, %s.x) - 0.5;\n", f sWidthHeightName);
197 builder->fsCodeAppendf("\tfloat insetH = min(1.0, %s.y) - 0.5;\n", f sWidthHeightName); 191 builder->fsCodeAppendf("\tfloat insetH = min(1.0, %s.y) - 0.5;\n", f sWidthHeightName);
198 builder->fsCodeAppend("\tfloat outset = 0.5;\n"); 192 builder->fsCodeAppend("\tfloat outset = 0.5;\n");
199 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0 ). For rects 193 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0 ). For rects
200 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a 0 .. 1 range. 194 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a 0 .. 1 range.
201 builder->fsCodeAppend("\tfloat spanW = insetW + outset;\n"); 195 builder->fsCodeAppend("\tfloat spanW = insetW + outset;\n");
202 builder->fsCodeAppend("\tfloat spanH = insetH + outset;\n"); 196 builder->fsCodeAppend("\tfloat spanH = insetH + outset;\n");
203 // For rects < 1 pixel wide or tall, these scale factors are used to cap the maximum 197 // For rects < 1 pixel wide or tall, these scale factors are used to cap the maximum
(...skipping 23 matching lines...) Expand all
227 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str() ); 221 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str() );
228 } 222 }
229 223
230 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG LCaps&) { 224 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG LCaps&) {
231 return 0; 225 return 0;
232 } 226 }
233 227
234 virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect& ) SK_OVERRIDE {} 228 virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect& ) SK_OVERRIDE {}
235 229
236 private: 230 private:
237 typedef GrGLEffect INHERITED; 231 typedef GrGLVertexEffect INHERITED;
238 }; 232 };
239 233
240 234
241 private: 235 private:
242 GrRectEffect() : GrVertexEffect() { 236 GrRectEffect() : GrVertexEffect() {
243 this->addVertexAttrib(kVec4f_GrSLType); 237 this->addVertexAttrib(kVec4f_GrSLType);
244 this->addVertexAttrib(kVec2f_GrSLType); 238 this->addVertexAttrib(kVec2f_GrSLType);
245 this->setWillReadFragmentPosition(); 239 this->setWillReadFragmentPosition();
246 } 240 }
247 241
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 // can't call mapRect for devInside since it calls sort 805 // can't call mapRect for devInside since it calls sort
812 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ; 806 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ;
813 807
814 if (devInside.isEmpty()) { 808 if (devInside.isEmpty()) {
815 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use VertexCoverage); 809 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use VertexCoverage);
816 return; 810 return;
817 } 811 }
818 812
819 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove rage); 813 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove rage);
820 } 814 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698