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

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

Issue 26190003: Potentially optimize some GrGLEffects for known input color values (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
« no previous file with comments | « src/gpu/GrAAConvexPathRenderer.cpp ('k') | src/gpu/GrOvalRenderer.cpp » ('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 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 class GLEffect : public GrGLVertexEffect { 43 class GLEffect : public GrGLVertexEffect {
44 public: 44 public:
45 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) 45 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
46 : INHERITED (factory) {} 46 : INHERITED (factory) {}
47 47
48 virtual void emitCode(GrGLFullShaderBuilder* builder, 48 virtual void emitCode(GrGLFullShaderBuilder* builder,
49 const GrDrawEffect& drawEffect, 49 const GrDrawEffect& drawEffect,
50 EffectKey key, 50 EffectKey key,
51 const char* outputColor, 51 const char* outputColor,
52 const char* inputColor, 52 const GrGLSLExpr4& inputColor,
53 const TransformedCoordsArray&, 53 const TransformedCoordsArray&,
54 const TextureSamplerArray& samplers) SK_OVERRIDE { 54 const TextureSamplerArray& samplers) SK_OVERRIDE {
55 // setup the varying for the Axis aligned rect effect 55 // setup the varying for the Axis aligned rect effect
56 // xy -> interpolated offset 56 // xy -> interpolated offset
57 // zw -> w/2+0.5, h/2+0.5 57 // zw -> w/2+0.5, h/2+0.5
58 const char *vsRectName, *fsRectName; 58 const char *vsRectName, *fsRectName;
59 builder->addVarying(kVec4f_GrSLType, "Rect", &vsRectName, &fsRectNam e); 59 builder->addVarying(kVec4f_GrSLType, "Rect", &vsRectName, &fsRectNam e);
60 const SkString* attr0Name = 60 const SkString* attr0Name =
61 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice s()[0]); 61 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice s()[0]);
62 builder->vsCodeAppendf("\t%s = %s;\n", vsRectName, attr0Name->c_str( )); 62 builder->vsCodeAppendf("\t%s = %s;\n", vsRectName, attr0Name->c_str( ));
(...skipping 16 matching lines...) Expand all
79 builder->fsCodeAppendf( 79 builder->fsCodeAppendf(
80 "\tfloat coverage = scaleW*clamp((%s.z-abs(%s.x))/spanW, 0.0, 1. 0);\n", fsRectName, 80 "\tfloat coverage = scaleW*clamp((%s.z-abs(%s.x))/spanW, 0.0, 1. 0);\n", fsRectName,
81 fsRectName); 81 fsRectName);
82 // Compute the coverage for the rect's height and merge with the wid th 82 // Compute the coverage for the rect's height and merge with the wid th
83 builder->fsCodeAppendf( 83 builder->fsCodeAppendf(
84 "\tcoverage = coverage*scaleH*clamp((%s.w-abs(%s.y))/spanH, 0.0, 1.0);\n", 84 "\tcoverage = coverage*scaleH*clamp((%s.w-abs(%s.y))/spanH, 0.0, 1.0);\n",
85 fsRectName, fsRectName); 85 fsRectName, fsRectName);
86 86
87 87
88 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, 88 builder->fsCodeAppendf("\t%s = %s;\n", outputColor,
89 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("cover age")).c_str()); 89 (inputColor * GrGLSLExpr1("coverage")).c_str( ));
90 } 90 }
91 91
92 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG LCaps&) { 92 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG LCaps&) {
93 return 0; 93 return 0;
94 } 94 }
95 95
96 virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect& ) SK_OVERRIDE {} 96 virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect& ) SK_OVERRIDE {}
97 97
98 private: 98 private:
99 typedef GrGLVertexEffect INHERITED; 99 typedef GrGLVertexEffect INHERITED;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 160
161 class GLEffect : public GrGLVertexEffect { 161 class GLEffect : public GrGLVertexEffect {
162 public: 162 public:
163 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) 163 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
164 : INHERITED (factory) {} 164 : INHERITED (factory) {}
165 165
166 virtual void emitCode(GrGLFullShaderBuilder* builder, 166 virtual void emitCode(GrGLFullShaderBuilder* builder,
167 const GrDrawEffect& drawEffect, 167 const GrDrawEffect& drawEffect,
168 EffectKey key, 168 EffectKey key,
169 const char* outputColor, 169 const char* outputColor,
170 const char* inputColor, 170 const GrGLSLExpr4& inputColor,
171 const TransformedCoordsArray&, 171 const TransformedCoordsArray&,
172 const TextureSamplerArray& samplers) SK_OVERRIDE { 172 const TextureSamplerArray& samplers) SK_OVERRIDE {
173 // setup the varying for the center point and the unit vector 173 // setup the varying for the center point and the unit vector
174 // that points down the height of the rect 174 // that points down the height of the rect
175 const char *vsRectEdgeName, *fsRectEdgeName; 175 const char *vsRectEdgeName, *fsRectEdgeName;
176 builder->addVarying(kVec4f_GrSLType, "RectEdge", 176 builder->addVarying(kVec4f_GrSLType, "RectEdge",
177 &vsRectEdgeName, &fsRectEdgeName); 177 &vsRectEdgeName, &fsRectEdgeName);
178 const SkString* attr0Name = 178 const SkString* attr0Name =
179 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice s()[0]); 179 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice s()[0]);
180 builder->vsCodeAppendf("\t%s = %s;\n", vsRectEdgeName, attr0Name->c_ str()); 180 builder->vsCodeAppendf("\t%s = %s;\n", vsRectEdgeName, attr0Name->c_ str());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 212
213 // Compute the coverage for the rect's height and merge with the wid th 213 // Compute the coverage for the rect's height and merge with the wid th
214 builder->fsCodeAppendf("\tperpDot = abs(dot(offset, %s.zw));\n", 214 builder->fsCodeAppendf("\tperpDot = abs(dot(offset, %s.zw));\n",
215 fsRectEdgeName); 215 fsRectEdgeName);
216 builder->fsCodeAppendf( 216 builder->fsCodeAppendf(
217 "\tcoverage = coverage*scaleH*clamp((%s.y-perpDot)/spanH, 0. 0, 1.0);\n", 217 "\tcoverage = coverage*scaleH*clamp((%s.y-perpDot)/spanH, 0. 0, 1.0);\n",
218 fsWidthHeightName); 218 fsWidthHeightName);
219 219
220 220
221 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, 221 builder->fsCodeAppendf("\t%s = %s;\n", outputColor,
222 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("cover age")).c_str()); 222 (inputColor * GrGLSLExpr1("coverage")).c_str( ));
223 } 223 }
224 224
225 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG LCaps&) { 225 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG LCaps&) {
226 return 0; 226 return 0;
227 } 227 }
228 228
229 virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect& ) SK_OVERRIDE {} 229 virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect& ) SK_OVERRIDE {}
230 230
231 private: 231 private:
232 typedef GrGLVertexEffect INHERITED; 232 typedef GrGLVertexEffect INHERITED;
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 // can't call mapRect for devInside since it calls sort 806 // can't call mapRect for devInside since it calls sort
807 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ; 807 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ;
808 808
809 if (devInside.isEmpty()) { 809 if (devInside.isEmpty()) {
810 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use VertexCoverage); 810 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use VertexCoverage);
811 return; 811 return;
812 } 812 }
813 813
814 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove rage); 814 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove rage);
815 } 815 }
OLDNEW
« no previous file with comments | « src/gpu/GrAAConvexPathRenderer.cpp ('k') | src/gpu/GrOvalRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698