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

Side by Side Diff: src/gpu/gl/GrGLSL_impl.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/GrGLSL.h ('k') | src/gpu/gl/GrGLShaderBuilder.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 2013 Google Inc. 2 * Copyright 2013 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_impl_DEFINED 8 #ifndef GrGLSL_impl_DEFINED
9 #define GrGLSL_impl_DEFINED 9 #define GrGLSL_impl_DEFINED
10 10
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 101 }
102 102
103 inline GrGLSLExpr1 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) { 103 inline GrGLSLExpr1 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) {
104 return GrGLSLExpr1::Add(in0, in1); 104 return GrGLSLExpr1::Add(in0, in1);
105 } 105 }
106 106
107 inline GrGLSLExpr1 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) { 107 inline GrGLSLExpr1 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) {
108 return GrGLSLExpr1::Sub(in0, in1); 108 return GrGLSLExpr1::Sub(in0, in1);
109 } 109 }
110 110
111 inline GrGLSLExpr3 GrGLSLExpr3::VectorCast(const GrGLSLExpr1& expr) {
112 return INHERITED::VectorCastImpl(expr);
113 }
114
115 inline GrGLSLExpr3 GrGLSLExpr3::VectorCast(const GrGLSLExpr3& expr) {
116 return expr;
117 }
118
119 inline const char* GrGLSLExpr3::ZerosStr() {
120 return "vec3(0)";
121 }
122
123 inline const char* GrGLSLExpr3::OnesStr() {
124 return "vec3(1)";
125 }
126
127 inline const char* GrGLSLExpr3::CastStr() {
128 return "vec3(%s)";
129 }
130
131 inline const char* GrGLSLExpr3::CastIntStr() {
132 return "vec3(%d)";
133 }
134
135 inline GrGLSLExpr3 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr3& in1) {
136 return GrGLSLExpr3::Mul(in0, in1);
137 }
138
139 inline GrGLSLExpr3 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr3& in1) {
140 return GrGLSLExpr3::Add(in0, in1);
141 }
142
143 inline GrGLSLExpr3 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr3& in1) {
144 return GrGLSLExpr3::Sub(in0, in1);
145 }
146
147 inline GrGLSLExpr3 operator*(const GrGLSLExpr3& in0, const GrGLSLExpr1& in1) {
148 return GrGLSLExpr3::Mul(in0, in1);
149 }
150
151 inline GrGLSLExpr3 operator+(const GrGLSLExpr3& in0, const GrGLSLExpr1& in1) {
152 return GrGLSLExpr3::Add(in0, in1);
153 }
154
155 inline GrGLSLExpr3 operator-(const GrGLSLExpr3& in0, const GrGLSLExpr1& in1) {
156 return GrGLSLExpr3::Sub(in0, in1);
157 }
158
159 inline GrGLSLExpr3 operator*(const GrGLSLExpr3& in0, const GrGLSLExpr3& in1) {
160 return GrGLSLExpr3::Mul(in0, in1);
161 }
162
163 inline GrGLSLExpr3 operator+(const GrGLSLExpr3& in0, const GrGLSLExpr3& in1) {
164 return GrGLSLExpr3::Add(in0, in1);
165 }
166
167 inline GrGLSLExpr3 operator-(const GrGLSLExpr3& in0, const GrGLSLExpr3& in1) {
168 return GrGLSLExpr3::Sub(in0, in1);
169 }
170
111 inline const char* GrGLSLExpr4::ZerosStr() { 171 inline const char* GrGLSLExpr4::ZerosStr() {
112 return "vec4(0)"; 172 return "vec4(0)";
113 } 173 }
114 174
115 inline const char* GrGLSLExpr4::OnesStr() { 175 inline const char* GrGLSLExpr4::OnesStr() {
116 return "vec4(1)"; 176 return "vec4(1)";
117 } 177 }
118 178
119 inline const char* GrGLSLExpr4::CastStr() { 179 inline const char* GrGLSLExpr4::CastStr() {
120 return "vec4(%s)"; 180 return "vec4(%s)";
121 } 181 }
122 182
123 inline const char* GrGLSLExpr4::CastIntStr() { 183 inline const char* GrGLSLExpr4::CastIntStr() {
124 return "vec4(%d)"; 184 return "vec4(%d)";
125 } 185 }
126 186
127 inline GrGLSLExpr4 GrGLSLExpr4::VectorCast(const GrGLSLExpr1& expr) { 187 inline GrGLSLExpr4 GrGLSLExpr4::VectorCast(const GrGLSLExpr1& expr) {
128 return INHERITED::VectorCastImpl(expr); 188 return INHERITED::VectorCastImpl(expr);
129 } 189 }
130 190
131 inline GrGLSLExpr4 GrGLSLExpr4::VectorCast(const GrGLSLExpr4& expr) { 191 inline GrGLSLExpr4 GrGLSLExpr4::VectorCast(const GrGLSLExpr4& expr) {
132 return expr; 192 return expr;
133 } 193 }
134 194
195 inline GrGLSLExpr1 GrGLSLExpr4::x() const { return this->extractComponents<GrGLS LExpr1>("%s.x"); }
196 inline GrGLSLExpr1 GrGLSLExpr4::y() const { return this->extractComponents<GrGLS LExpr1>("%s.y"); }
197 inline GrGLSLExpr1 GrGLSLExpr4::z() const { return this->extractComponents<GrGLS LExpr1>("%s.z"); }
198 inline GrGLSLExpr1 GrGLSLExpr4::w() const { return this->extractComponents<GrGLS LExpr1>("%s.w"); }
199 inline GrGLSLExpr1 GrGLSLExpr4::r() const { return this->extractComponents<GrGLS LExpr1>("%s.r"); }
200 inline GrGLSLExpr1 GrGLSLExpr4::g() const { return this->extractComponents<GrGLS LExpr1>("%s.g"); }
201 inline GrGLSLExpr1 GrGLSLExpr4::b() const { return this->extractComponents<GrGLS LExpr1>("%s.b"); }
202
135 inline GrGLSLExpr4::AExpr GrGLSLExpr4::a() const { 203 inline GrGLSLExpr4::AExpr GrGLSLExpr4::a() const {
136 return this->extractComponents<GrGLSLExpr4::AExpr>("%s.a"); 204 return this->extractComponents<GrGLSLExpr4::AExpr>("%s.a");
137 } 205 }
138 206
207 inline GrGLSLExpr3 GrGLSLExpr4::xyz() const { return this->extractComponents<GrG LSLExpr3>("%s.xyz"); }
208 inline GrGLSLExpr3 GrGLSLExpr4::rgb() const { return this->extractComponents<GrG LSLExpr3>("%s.rgb"); }
209
210
211
139 inline GrGLSLExpr4 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) { 212 inline GrGLSLExpr4 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) {
140 return GrGLSLExpr4::Mul(in0, in1); 213 return GrGLSLExpr4::Mul(in0, in1);
141 } 214 }
142 215
143 inline GrGLSLExpr4 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) { 216 inline GrGLSLExpr4 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) {
144 return GrGLSLExpr4::Add(in0, in1); 217 return GrGLSLExpr4::Add(in0, in1);
145 } 218 }
146 219
147 inline GrGLSLExpr4 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) { 220 inline GrGLSLExpr4 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) {
148 return GrGLSLExpr4::Sub(in0, in1); 221 return GrGLSLExpr4::Sub(in0, in1);
(...skipping 16 matching lines...) Expand all
165 } 238 }
166 239
167 inline GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) { 240 inline GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) {
168 return GrGLSLExpr4::Add(in0, in1); 241 return GrGLSLExpr4::Add(in0, in1);
169 } 242 }
170 243
171 inline GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) { 244 inline GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) {
172 return GrGLSLExpr4::Sub(in0, in1); 245 return GrGLSLExpr4::Sub(in0, in1);
173 } 246 }
174 247
248 namespace GrGLSL {
249 inline GrGLSLExpr1 max(const GrGLSLExpr1& a, float b) {
250 if (a.isOnes()) {
251 if (b > 1) {
252 return GrGLSLExpr1(b);
253 }
254 return a;
255 } else if (a.isZeros()) {
256 if (b > 0) {
257 return GrGLSLExpr1(b);
258 }
259 return a;
260 }
261 SkString r;
262 r.printf("max(%s, %f)", a.c_str(), b);
263 return GrGLSLExpr1(r);
264 }
265
266 template<typename T>
267 inline T min(const T& a, const T& b) {
268 if (a.isOnes()) {
269 if (b.isOnes()) {
270 return a;
271 }
272 if (b.isZeros()) {
273 return b;
274 }
275 }
276 if (a.isZeros()) {
277 if (b.isOnes()) {
278 return a;
279 }
280 if (b.isZeros()) {
281 return a;
282 }
283 }
284 return T("min(%s, %s)", a.c_str(), b.c_str());
285 }
286
287 template<typename T>
288 inline T max(const T& a, const T& b) {
289 if (a.isOnes()) {
290 if (b.isOnes()) {
291 return a;
292 }
293 if (b.isZeros()) {
294 return a;
295 }
296 }
297 if (a.isZeros()) {
298 if (b.isOnes()) {
299 return b;
300 }
301 if (b.isZeros()) {
302 return a;
303 }
304 }
305 return T("max(%s, %s)", a.c_str(), b.c_str());
306 }
307 }
308
175 #endif 309 #endif
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLSL.h ('k') | src/gpu/gl/GrGLShaderBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698