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

Side by Side Diff: src/effects/gradients/SkGradientShaderPriv.h

Issue 22854005: GPU Gradients (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: reverted defer flag to true Created 7 years, 4 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 #ifndef SkGradientShaderPriv_DEFINED 8 #ifndef SkGradientShaderPriv_DEFINED
9 #define SkGradientShaderPriv_DEFINED 9 #define SkGradientShaderPriv_DEFINED
10 10
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 const SkMatrix& matrix, 243 const SkMatrix& matrix,
244 SkShader::TileMode tileMode); 244 SkShader::TileMode tileMode);
245 245
246 virtual ~GrGradientEffect(); 246 virtual ~GrGradientEffect();
247 247
248 bool useAtlas() const { return SkToBool(-1 != fRow); } 248 bool useAtlas() const { return SkToBool(-1 != fRow); }
249 SkScalar getYCoord() const { return fYCoord; }; 249 SkScalar getYCoord() const { return fYCoord; };
250 const SkMatrix& getMatrix() const { return fMatrix;} 250 const SkMatrix& getMatrix() const { return fMatrix;}
251 251
252 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE; 252 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE;
253
254 enum ColorType {
255 kTwo_ColorType,
256 kThree_ColorType,
257 kTexture_ColorType
258 };
259
260 inline ColorType getColorType() const {
reed1 2013/08/15 21:32:15 nit: not need for 'inline' in a class header when
dierk 2013/08/16 16:59:56 Done.
261 return fColorType;
262 }
263 const inline SkColor* getColors() const {
reed1 2013/08/15 21:32:15 1. same nit about not needing 'inline' here 2. ver
reed1 2013/08/15 21:32:15 API question: given that getColors is only valid f
dierk 2013/08/16 16:59:56 Done.
264 return &fColors[0];
265 }
253 266
254 protected: 267 protected:
255 268
256 /** Populates a pair of arrays with colors and stop info to construct a rand om gradient. 269 /** Populates a pair of arrays with colors and stop info to construct a rand om gradient.
257 The function decides whether stop values should be used or not. The retu rn value indicates 270 The function decides whether stop values should be used or not. The retu rn value indicates
258 the number of colors, which will be capped by kMaxRandomGradientColors. colors should be 271 the number of colors, which will be capped by kMaxRandomGradientColors. colors should be
259 sized to be at least kMaxRandomGradientColors. stops is a pointer to an array of at least 272 sized to be at least kMaxRandomGradientColors. stops is a pointer to an array of at least
260 size kMaxRandomGradientColors. It may be updated to NULL, indicating tha t NULL should be 273 size kMaxRandomGradientColors. It may be updated to NULL, indicating tha t NULL should be
261 passed to the gradient factory rather than the array. 274 passed to the gradient factory rather than the array.
262 */ 275 */
263 static const int kMaxRandomGradientColors = 4; 276 static const int kMaxRandomGradientColors = 4;
264 static int RandomGradientParams(SkMWCRandom* r, 277 static int RandomGradientParams(SkMWCRandom* r,
265 SkColor colors[kMaxRandomGradientColors], 278 SkColor colors[kMaxRandomGradientColors],
266 SkScalar** stops, 279 SkScalar** stops,
267 SkShader::TileMode* tm); 280 SkShader::TileMode* tm);
268 281
269 virtual bool onIsEqual(const GrEffect& effect) const SK_OVERRIDE; 282 virtual bool onIsEqual(const GrEffect& effect) const SK_OVERRIDE;
270 283
271 private: 284 private:
272 285
273 GrTextureAccess fTextureAccess; 286 GrTextureAccess fTextureAccess;
274 SkScalar fYCoord; 287 SkScalar fYCoord;
275 GrTextureStripAtlas* fAtlas; 288 GrTextureStripAtlas* fAtlas;
276 int fRow; 289 int fRow;
277 SkMatrix fMatrix; 290 SkMatrix fMatrix;
278 bool fIsOpaque; 291 bool fIsOpaque;
292 int fNumColors;
293 ColorType fColorType;
294 SkColor fColors[3];
reed1 2013/08/15 21:32:15 // Short comment on why [3] here or maybe an enum
dierk 2013/08/16 16:59:56 Done.
279 295
280 typedef GrEffect INHERITED; 296 typedef GrEffect INHERITED;
281 297
282 }; 298 };
283 299
284 /////////////////////////////////////////////////////////////////////////////// 300 ///////////////////////////////////////////////////////////////////////////////
285 301
286 // Base class for GL gradient effects 302 // Base class for GL gradient effects
287 class GrGLGradientEffect : public GrGLEffect { 303 class GrGLGradientEffect : public GrGLEffect {
288 public: 304 public:
289 GrGLGradientEffect(const GrBackendEffectFactory& factory); 305 GrGLGradientEffect(const GrBackendEffectFactory& factory);
290 virtual ~GrGLGradientEffect(); 306 virtual ~GrGLGradientEffect();
291 307
292 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE; 308 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE;
293 309
294 protected: 310 protected:
295 /** 311 /**
296 * Subclasses must reserve the lower kMatrixKeyBitCnt of their key for use b y 312 * Subclasses must reserve the lower kMatrixKeyBitCnt of their key for use b y
297 * GrGLGradientEffect. 313 * GrGLGradientEffect.
298 */ 314 */
299 enum { 315 enum {
300 kMatrixKeyBitCnt = GrGLEffectMatrix::kKeyBits, 316 kMatrixKeyBitCnt = GrGLEffectMatrix::kKeyBits,
301 kMatrixKeyMask = (1 << kMatrixKeyBitCnt) - 1, 317 kMatrixKeyMask = (1 << kMatrixKeyBitCnt) - 1,
318
319 kTwoColorKey = 2 << kMatrixKeyBitCnt,
320 kThreeColorKey = 3 << kMatrixKeyBitCnt,
321 kColorKeyMask = kTwoColorKey | kThreeColorKey
302 }; 322 };
303 323
324 static inline GrGradientEffect::ColorType getColorType(EffectKey key){
reed1 2013/08/15 21:32:15 again with the 'inline' :)
dierk 2013/08/16 16:59:56 Done.
325 if (kTwoColorKey == (key & kColorKeyMask)) {
326 return GrGradientEffect::kTwo_ColorType;
327 } else if (kThreeColorKey == (key & kColorKeyMask)) {
328 return GrGradientEffect::kThree_ColorType;
329 } else {return GrGradientEffect::kTexture_ColorType;}
330 }
331
304 /** 332 /**
305 * Subclasses must call this. It will return a value restricted to the lower kMatrixKeyBitCnt 333 * Subclasses must call this. It will return a value restricted to the lower kMatrixKeyBitCnt
306 * bits. 334 * bits.
307 */ 335 */
308 static EffectKey GenMatrixKey(const GrDrawEffect&); 336 static EffectKey GenBaseGradientKey(const GrDrawEffect&);
309 337
310 /** 338 /**
311 * Inserts code to implement the GrGradientEffect's matrix. This should be c alled before a 339 * Inserts code to implement the GrGradientEffect's matrix. This should be c alled before a
312 * subclass emits its own code. The name of the 2D coords is output via fsCo ordName and already 340 * subclass emits its own code. The name of the 2D coords is output via fsCo ordName and already
313 * incorporates any perspective division. The caller can also optionally ret rieve the name of 341 * incorporates any perspective division. The caller can also optionally ret rieve the name of
314 * the varying inserted in the VS and its type, which may be either vec2f or vec3f depending 342 * the varying inserted in the VS and its type, which may be either vec2f or vec3f depending
315 * upon whether the matrix has perspective or not. It is not necessary to ma sk the key before 343 * upon whether the matrix has perspective or not. It is not necessary to ma sk the key before
316 * calling. 344 * calling.
317 */ 345 */
318 void setupMatrix(GrGLShaderBuilder* builder, 346 void setupMatrix(GrGLShaderBuilder* builder,
319 EffectKey key, 347 EffectKey key,
320 const char** fsCoordName, 348 const char** fsCoordName,
321 const char** vsVaryingName = NULL, 349 const char** vsVaryingName = NULL,
322 GrSLType* vsVaryingType = NULL); 350 GrSLType* vsVaryingType = NULL);
323 351
324 // Emits the uniform used as the y-coord to texture samples in derived class es. Subclasses 352 // Emits the uniform used as the y-coord to texture samples in derived class es. Subclasses
325 // should call this method from their emitCode(). 353 // should call this method from their emitCode().
326 void emitYCoordUniform(GrGLShaderBuilder* builder); 354 void emitUniforms(GrGLShaderBuilder* builder, EffectKey key);
327 355
328 // emit code that gets a fragment's color from an expression for t; for now this always uses the 356
329 // texture, but for simpler cases we'll be able to lerp. Subclasses should c all this method from 357 // emit code that gets a fragment's color from an expression for t; Has bran ches for 3 separate
330 // their emitCode(). 358 // control flows inside -- 2 color gradients, 3 color symmetric gradients (b oth using
331 void emitColorLookup(GrGLShaderBuilder* builder, 359 // native GLSL mix), and 4+ color gradients that use the traditional texture lookup.
332 const char* gradientTValue, 360 void emitColor(GrGLShaderBuilder* builder,
333 const char* outputColor, 361 const char* gradientTValue,
334 const char* inputColor, 362 EffectKey key,
335 const GrGLShaderBuilder::TextureSampler&); 363 const char* outputColor,
364 const char* inputColor,
365 const GrGLShaderBuilder::TextureSamplerArray& samplers);
336 366
337 private: 367 private:
338 static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsType; 368 static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsType;
339 369
340 SkScalar fCachedYCoord; 370 SkScalar fCachedYCoord;
341 GrGLUniformManager::UniformHandle fFSYUni; 371 GrGLUniformManager::UniformHandle fFSYUni;
372 GrGLUniformManager::UniformHandle fColorStartUni;
373 GrGLUniformManager::UniformHandle fColorMidUni;
374 GrGLUniformManager::UniformHandle fColorEndUni;
342 GrGLEffectMatrix fEffectMatrix; 375 GrGLEffectMatrix fEffectMatrix;
343 376
344 typedef GrGLEffect INHERITED; 377 typedef GrGLEffect INHERITED;
345 }; 378 };
346 379
347 #endif 380 #endif
348 381
349 #endif 382 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698