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

Side by Side Diff: src/gpu/gl/GrGLSL.h

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/gl/GrGLProgramEffects.cpp ('k') | src/gpu/gl/GrGLSL_impl.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 2011 Google Inc. 2 * Copyright 2011 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 #ifndef GrGLSL_DEFINED 8 #ifndef GrGLSL_DEFINED
9 #define GrGLSL_DEFINED 9 #define GrGLSL_DEFINED
10 10
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } else if (v == 1) { 116 } else if (v == 1) {
117 fType = kOnes_ExprType; 117 fType = kOnes_ExprType;
118 } else { 118 } else {
119 fType = kFullExpr_ExprType; 119 fType = kFullExpr_ExprType;
120 fExpr.appendf(Self::CastIntStr(), v); 120 fExpr.appendf(Self::CastIntStr(), v);
121 } 121 }
122 } 122 }
123 123
124 /** Constructs an expression from a string. 124 /** Constructs an expression from a string.
125 * Argument expr is a simple expression or a parenthesized expression. */ 125 * Argument expr is a simple expression or a parenthesized expression. */
126 // TODO: make explicit once effects input Exprs. 126 explicit GrGLSLExpr(const char expr[]) {
127 GrGLSLExpr(const char expr[]) { 127 fType = kFullExpr_ExprType;
128 if (NULL == expr) { // TODO: remove this once effects input Exprs. 128 fExpr = expr;
129 fType = kOnes_ExprType; 129 SkASSERT(NULL != expr);
130 } else {
131 fType = kFullExpr_ExprType;
132 fExpr = expr;
133 }
134 SkASSERT(this->isValid());
135 } 130 }
136 131
137 /** Constructs an expression from a string. 132 /** Constructs an expression from a string.
138 * Argument expr is a simple expression or a parenthesized expression. */ 133 * Argument expr is a simple expression or a parenthesized expression. */
139 // TODO: make explicit once effects input Exprs. 134 explicit GrGLSLExpr(const SkString& expr) {
140 GrGLSLExpr(const SkString& expr) { 135 fType = kFullExpr_ExprType;
141 if (expr.isEmpty()) { // TODO: remove this once effects input Exprs. 136 fExpr = expr;
142 fType = kOnes_ExprType; 137 SkASSERT(!expr.isEmpty());
143 } else {
144 fType = kFullExpr_ExprType;
145 fExpr = expr;
146 }
147 SkASSERT(this->isValid());
148 } 138 }
149 139
150 /** Constructs an expression from a string with one substitution. */ 140 /** Constructs an expression from a string with one substitution. */
151 GrGLSLExpr(const char format[], const char in0[]) 141 GrGLSLExpr(const char format[], const char in0[])
152 : fType(kFullExpr_ExprType) { 142 : fType(kFullExpr_ExprType) {
153 fExpr.appendf(format, in0); 143 fExpr.appendf(format, in0);
154 } 144 }
155 145
156 /** Constructs an expression from a string with two substitutions. */ 146 /** Constructs an expression from a string with two substitutions. */
157 GrGLSLExpr(const char format[], const char in0[], const char in1[]) 147 GrGLSLExpr(const char format[], const char in0[], const char in1[])
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 enum ExprType { 195 enum ExprType {
206 kZeros_ExprType, 196 kZeros_ExprType,
207 kOnes_ExprType, 197 kOnes_ExprType,
208 kFullExpr_ExprType, 198 kFullExpr_ExprType,
209 }; 199 };
210 ExprType fType; 200 ExprType fType;
211 SkString fExpr; 201 SkString fExpr;
212 }; 202 };
213 203
214 class GrGLSLExpr1; 204 class GrGLSLExpr1;
205 class GrGLSLExpr3;
215 class GrGLSLExpr4; 206 class GrGLSLExpr4;
216 207
208 namespace GrGLSL {
209 GrGLSLExpr1 max(const GrGLSLExpr1& a, float b);
210
211 template<typename T>
212 T min(const T& a, const T& b);
213
214 template<typename T>
215 T max(const T& a, const T& b);
216 }
217
217 /** Class representing a float GLSL expression. */ 218 /** Class representing a float GLSL expression. */
218 class GrGLSLExpr1 : public GrGLSLExpr<GrGLSLExpr1> { 219 class GrGLSLExpr1 : public GrGLSLExpr<GrGLSLExpr1> {
219 public: 220 public:
220 GrGLSLExpr1() 221 GrGLSLExpr1()
221 : INHERITED() { 222 : INHERITED() {
222 } 223 }
223 explicit GrGLSLExpr1(int v) 224 explicit GrGLSLExpr1(int v)
224 : INHERITED(v) { 225 : INHERITED(v) {
225 } 226 }
226 GrGLSLExpr1(const char* expr) 227 explicit GrGLSLExpr1(const char* expr)
227 : INHERITED(expr) { 228 : INHERITED(expr) {
228 } 229 }
229 GrGLSLExpr1(const SkString& expr) 230 explicit GrGLSLExpr1(const SkString& expr)
230 : INHERITED(expr) { 231 : INHERITED(expr) {
231 } 232 }
232 233
233 static GrGLSLExpr1 VectorCast(const GrGLSLExpr1& expr); 234 static GrGLSLExpr1 VectorCast(const GrGLSLExpr1& expr);
234 235
235 private: 236 private:
236 GrGLSLExpr1(const char format[], const char in0[]) 237 GrGLSLExpr1(const char format[], const char in0[])
237 : INHERITED(format, in0) { 238 : INHERITED(format, in0) {
238 } 239 }
239 GrGLSLExpr1(const char format[], const char in0[], const char in1[]) 240 GrGLSLExpr1(const char format[], const char in0[], const char in1[])
240 : INHERITED(format, in0, in1) { 241 : INHERITED(format, in0, in1) {
241 } 242 }
242 243
243 static const char* ZerosStr(); 244 static const char* ZerosStr();
244 static const char* OnesStr(); 245 static const char* OnesStr();
245 static const char* CastStr(); 246 static const char* CastStr();
246 static const char* CastIntStr(); 247 static const char* CastIntStr();
247 248
248 friend GrGLSLExpr1 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1); 249 friend GrGLSLExpr1 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1);
249 friend GrGLSLExpr1 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1); 250 friend GrGLSLExpr1 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1);
250 friend GrGLSLExpr1 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1); 251 friend GrGLSLExpr1 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1);
251 252
253 template<typename T> friend T GrGLSL::min(const T& a, const T& b);
254 template<typename T> friend T GrGLSL::max(const T& a, const T& b);
255
252 friend class GrGLSLExpr<GrGLSLExpr1>; 256 friend class GrGLSLExpr<GrGLSLExpr1>;
257 friend class GrGLSLExpr<GrGLSLExpr3>;
258 friend class GrGLSLExpr<GrGLSLExpr4>;
259 typedef GrGLSLExpr<GrGLSLExpr1> INHERITED;
260 };
261
262 class GrGLSLExpr3 : public GrGLSLExpr<GrGLSLExpr3> {
263 public:
264 GrGLSLExpr3()
265 : INHERITED() {
266 }
267 explicit GrGLSLExpr3(int v)
268 : INHERITED(v) {
269 }
270 explicit GrGLSLExpr3(const char* expr)
271 : INHERITED(expr) {
272 }
273 explicit GrGLSLExpr3(const SkString& expr)
274 : INHERITED(expr) {
275 }
276
277 /** GLSL vec3 cast / constructor, eg vec3(floatv) -> vec3(floatv, floatv, fl oatv) */
278 static GrGLSLExpr3 VectorCast(const GrGLSLExpr1& expr);
279 static GrGLSLExpr3 VectorCast(const GrGLSLExpr3& expr);
280
281 GrGLSLExpr1 x() const;
282 GrGLSLExpr1 y() const;
283 GrGLSLExpr1 z() const;
284 GrGLSLExpr1 r() const;
285 GrGLSLExpr1 g() const;
286 GrGLSLExpr1 b() const;
287
288 private:
289 GrGLSLExpr3(const char format[], const char in0[]) : INHERITED(format, in0) { }
290 GrGLSLExpr3(const char format[], const char in0[], const char in1[]): INHERI TED(format, in0, in1) { }
291
292 static const char* ZerosStr();
293 static const char* OnesStr();
294 static const char* CastStr();
295 static const char* CastIntStr();
296
297 // The vector-by-scalar and scalar-by-vector binary operations.
298 friend GrGLSLExpr3 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr3&in1);
299 friend GrGLSLExpr3 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr3&in1);
300 friend GrGLSLExpr3 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr3&in1);
301 friend GrGLSLExpr3 operator*(const GrGLSLExpr3& in0, const GrGLSLExpr1&in1);
302 friend GrGLSLExpr3 operator+(const GrGLSLExpr3& in0, const GrGLSLExpr1&in1);
303 friend GrGLSLExpr3 operator-(const GrGLSLExpr3& in0, const GrGLSLExpr1&in1);
304
305 // The vector-by-vector, i.e. component-wise, binary operations.
306 friend GrGLSLExpr3 operator*(const GrGLSLExpr3& in0, const GrGLSLExpr3&in1);
307 friend GrGLSLExpr3 operator+(const GrGLSLExpr3& in0, const GrGLSLExpr3&in1);
308 friend GrGLSLExpr3 operator-(const GrGLSLExpr3& in0, const GrGLSLExpr3&in1);
309
310 template<typename T> friend T GrGLSL::min(const T& a, const T& b);
311 template<typename T> friend T GrGLSL::max(const T& a, const T& b);
312
313 friend class GrGLSLExpr<GrGLSLExpr3>;
253 friend class GrGLSLExpr<GrGLSLExpr4>; 314 friend class GrGLSLExpr<GrGLSLExpr4>;
254 315
255 typedef GrGLSLExpr<GrGLSLExpr1> INHERITED; 316 typedef GrGLSLExpr<GrGLSLExpr3> INHERITED;
256 }; 317 };
257 318
258 /** Class representing a float vector (vec4) GLSL expression. */ 319 /** Class representing a float vector (vec4) GLSL expression. */
259 class GrGLSLExpr4 : public GrGLSLExpr<GrGLSLExpr4> { 320 class GrGLSLExpr4 : public GrGLSLExpr<GrGLSLExpr4> {
260 public: 321 public:
261 GrGLSLExpr4() 322 GrGLSLExpr4()
262 : INHERITED() { 323 : INHERITED() {
263 } 324 }
264 explicit GrGLSLExpr4(int v) 325 explicit GrGLSLExpr4(int v)
265 : INHERITED(v) { 326 : INHERITED(v) {
266 } 327 }
267 GrGLSLExpr4(const char* expr) 328 explicit GrGLSLExpr4(const char* expr)
268 : INHERITED(expr) { 329 : INHERITED(expr) {
269 } 330 }
270 GrGLSLExpr4(const SkString& expr) 331 explicit GrGLSLExpr4(const SkString& expr)
271 : INHERITED(expr) { 332 : INHERITED(expr) {
272 } 333 }
273 334
335 GrGLSLExpr1 x() const;
336 GrGLSLExpr1 y() const;
337 GrGLSLExpr1 z() const;
338 GrGLSLExpr1 w() const;
339 GrGLSLExpr1 r() const;
340 GrGLSLExpr1 g() const;
341 GrGLSLExpr1 b() const;
274 typedef GrGLSLExpr1 AExpr; 342 typedef GrGLSLExpr1 AExpr;
275 AExpr a() const; 343 AExpr a() const;
276 344
345 GrGLSLExpr3 xyz() const;
346 GrGLSLExpr3 rgb() const;
347
277 /** GLSL vec4 cast / constructor, eg vec4(floatv) -> vec4(floatv, floatv, fl oatv, floatv) */ 348 /** GLSL vec4 cast / constructor, eg vec4(floatv) -> vec4(floatv, floatv, fl oatv, floatv) */
278 static GrGLSLExpr4 VectorCast(const GrGLSLExpr1& expr); 349 static GrGLSLExpr4 VectorCast(const GrGLSLExpr1& expr);
279 static GrGLSLExpr4 VectorCast(const GrGLSLExpr4& expr); 350 static GrGLSLExpr4 VectorCast(const GrGLSLExpr4& expr);
280 351
281 private: 352 private:
282 GrGLSLExpr4(const char format[], const char in0[]) 353 GrGLSLExpr4(const char format[], const char in0[])
283 : INHERITED(format, in0) { 354 : INHERITED(format, in0) {
284 } 355 }
285 GrGLSLExpr4(const char format[], const char in0[], const char in1[]) 356 GrGLSLExpr4(const char format[], const char in0[], const char in1[])
286 : INHERITED(format, in0, in1) { 357 : INHERITED(format, in0, in1) {
(...skipping 10 matching lines...) Expand all
297 friend GrGLSLExpr4 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr4&in1); 368 friend GrGLSLExpr4 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr4&in1);
298 friend GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr1&in1); 369 friend GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr1&in1);
299 friend GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr1&in1); 370 friend GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr1&in1);
300 friend GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr1&in1); 371 friend GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr1&in1);
301 372
302 // The vector-by-vector, i.e. component-wise, binary operations. 373 // The vector-by-vector, i.e. component-wise, binary operations.
303 friend GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1); 374 friend GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1);
304 friend GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1); 375 friend GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1);
305 friend GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1); 376 friend GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1);
306 377
378 template<typename T> friend T GrGLSL::min(const T& a, const T& b);
379 template<typename T> friend T GrGLSL::max(const T& a, const T& b);
380
307 friend class GrGLSLExpr<GrGLSLExpr4>; 381 friend class GrGLSLExpr<GrGLSLExpr4>;
308
309 typedef GrGLSLExpr<GrGLSLExpr4> INHERITED; 382 typedef GrGLSLExpr<GrGLSLExpr4> INHERITED;
310 }; 383 };
311 384
385
312 /** 386 /**
313 * Does an inplace mul, *=, of vec4VarName by mulFactor. 387 * Does an inplace mul, *=, of vec4VarName by mulFactor.
314 * A semicolon and newline are added after the assignment. 388 * A semicolon and newline are added after the assignment.
315 */ 389 */
316 void GrGLSLMulVarBy4f(SkString* outAppend, unsigned tabCnt, 390 void GrGLSLMulVarBy4f(SkString* outAppend, unsigned tabCnt,
317 const char* vec4VarName, const GrGLSLExpr4& mulFactor); 391 const char* vec4VarName, const GrGLSLExpr4& mulFactor);
318 392
319 #include "GrGLSL_impl.h" 393 #include "GrGLSL_impl.h"
320 394
321 #endif 395 #endif
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLProgramEffects.cpp ('k') | src/gpu/gl/GrGLSL_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698