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

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

Issue 2337313002: (Some) gradients are gamma and gamut correct on GPU (Closed)
Patch Set: Rebase Created 4 years, 3 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
« no previous file with comments | « src/effects/gradients/SkGradientShader.cpp ('k') | src/effects/gradients/SkLinearGradient.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 #ifndef SkGradientShaderPriv_DEFINED 8 #ifndef SkGradientShaderPriv_DEFINED
9 #define SkGradientShaderPriv_DEFINED 9 #define SkGradientShaderPriv_DEFINED
10 10
11 #include "SkGradientBitmapCache.h" 11 #include "SkGradientBitmapCache.h"
12 #include "SkGradientShader.h" 12 #include "SkGradientShader.h"
13 #include "SkClampRange.h" 13 #include "SkClampRange.h"
14 #include "SkColorPriv.h" 14 #include "SkColorPriv.h"
15 #include "SkColorSpace.h"
15 #include "SkReadBuffer.h" 16 #include "SkReadBuffer.h"
16 #include "SkWriteBuffer.h" 17 #include "SkWriteBuffer.h"
17 #include "SkMallocPixelRef.h" 18 #include "SkMallocPixelRef.h"
18 #include "SkUtils.h" 19 #include "SkUtils.h"
19 #include "SkShader.h" 20 #include "SkShader.h"
20 #include "SkOnce.h" 21 #include "SkOnce.h"
21 22
22 #if SK_SUPPORT_GPU 23 #if SK_SUPPORT_GPU
23 #define GR_GL_USE_ACCURATE_HARD_STOP_GRADIENTS 1 24 #define GR_GL_USE_ACCURATE_HARD_STOP_GRADIENTS 1
24 #endif 25 #endif
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 77
77 class SkGradientShaderBase : public SkShader { 78 class SkGradientShaderBase : public SkShader {
78 public: 79 public:
79 struct Descriptor { 80 struct Descriptor {
80 Descriptor() { 81 Descriptor() {
81 sk_bzero(this, sizeof(*this)); 82 sk_bzero(this, sizeof(*this));
82 fTileMode = SkShader::kClamp_TileMode; 83 fTileMode = SkShader::kClamp_TileMode;
83 } 84 }
84 85
85 const SkMatrix* fLocalMatrix; 86 const SkMatrix* fLocalMatrix;
86 const SkColor* fColors; 87 const SkColor* fColors;
f(malita) 2016/09/14 23:32:23 Could we drop fColors from Descriptor? IIRC it's
88 const SkColor4f* fColors4f;
89 sk_sp<SkColorSpace> fColorSpace;
87 const SkScalar* fPos; 90 const SkScalar* fPos;
88 int fCount; 91 int fCount;
89 SkShader::TileMode fTileMode; 92 SkShader::TileMode fTileMode;
90 uint32_t fGradFlags; 93 uint32_t fGradFlags;
91 94
92 void flatten(SkWriteBuffer&) const; 95 void flatten(SkWriteBuffer&) const;
93 }; 96 };
94 97
95 class DescriptorScope : public Descriptor { 98 class DescriptorScope : public Descriptor {
96 public: 99 public:
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 * The rec src and dst are only assumed to be valid if count > 2 237 * The rec src and dst are only assumed to be valid if count > 2
235 */ 238 */
236 static void FlipGradientColors(SkColor* colorDst, Rec* recDst, 239 static void FlipGradientColors(SkColor* colorDst, Rec* recDst,
237 SkColor* colorSrc, Rec* recSrc, 240 SkColor* colorSrc, Rec* recSrc,
238 int count); 241 int count);
239 242
240 private: 243 private:
241 enum { 244 enum {
242 kColorStorageCount = 4, // more than this many colors, and we'll use sk_ malloc for the space 245 kColorStorageCount = 4, // more than this many colors, and we'll use sk_ malloc for the space
243 246
244 kStorageSize = kColorStorageCount * (sizeof(SkColor) + sizeof(SkScalar) + sizeof(Rec)) 247 kStorageSize = kColorStorageCount *
248 (sizeof(SkColor) + sizeof(SkScalar) + sizeof(Rec) + sizeo f(SkColor4f))
245 }; 249 };
246 SkColor fStorage[(kStorageSize + 3) >> 2]; 250 SkColor fStorage[(kStorageSize + 3) >> 2];
247 public: 251 public:
248 SkColor* fOrigColors; // original colors, before modulation by paint in c ontext. 252 SkColor* fOrigColors; // original colors, before modulation by paint in context.
249 SkScalar* fOrigPos; // original positions 253 SkColor4f* fOrigColors4f; // original colors, as linear floats
250 int fColorCount; 254 SkScalar* fOrigPos; // original positions
255 int fColorCount;
256 sk_sp<SkColorSpace> fColorSpace; // color space of gradient stops
251 257
252 bool colorsAreOpaque() const { return fColorsAreOpaque; } 258 bool colorsAreOpaque() const { return fColorsAreOpaque; }
253 259
254 TileMode getTileMode() const { return fTileMode; } 260 TileMode getTileMode() const { return fTileMode; }
255 Rec* getRecs() const { return fRecs; } 261 Rec* getRecs() const { return fRecs; }
256 262
257 private: 263 private:
258 bool fColorsAreOpaque; 264 bool fColorsAreOpaque;
259 265
260 GradientShaderCache* refCache(U8CPU alpha, bool dither) const; 266 GradientShaderCache* refCache(U8CPU alpha, bool dither) const;
261 mutable SkMutex fCacheMutex; 267 mutable SkMutex fCacheMutex;
262 mutable SkAutoTUnref<GradientShaderCache> fCache; 268 mutable SkAutoTUnref<GradientShaderCache> fCache;
263 269
264 void initCommon(); 270 void initCommon();
265 271
266 typedef SkShader INHERITED; 272 typedef SkShader INHERITED;
267 }; 273 };
268 274
(...skipping 12 matching lines...) Expand all
281 } 287 }
282 288
283 static inline int next_dither_toggle16(int toggle) { 289 static inline int next_dither_toggle16(int toggle) {
284 return toggle ^ SkGradientShaderBase::kDitherStride16; 290 return toggle ^ SkGradientShaderBase::kDitherStride16;
285 } 291 }
286 292
287 /////////////////////////////////////////////////////////////////////////////// 293 ///////////////////////////////////////////////////////////////////////////////
288 294
289 #if SK_SUPPORT_GPU 295 #if SK_SUPPORT_GPU
290 296
297 #include "GrColorSpaceXform.h"
291 #include "GrCoordTransform.h" 298 #include "GrCoordTransform.h"
292 #include "GrFragmentProcessor.h" 299 #include "GrFragmentProcessor.h"
293 #include "glsl/GrGLSLFragmentProcessor.h" 300 #include "glsl/GrGLSLFragmentProcessor.h"
294 #include "glsl/GrGLSLProgramDataManager.h" 301 #include "glsl/GrGLSLProgramDataManager.h"
295 302
296 class GrInvariantOutput; 303 class GrInvariantOutput;
297 304
298 /* 305 /*
299 * The interpretation of the texture matrix depends on the sample mode. The 306 * The interpretation of the texture matrix depends on the sample mode. The
300 * texture matrix is applied both when the texture coordinates are explicit 307 * texture matrix is applied both when the texture coordinates are explicit
(...skipping 19 matching lines...) Expand all
320 327
321 class GrTextureStripAtlas; 328 class GrTextureStripAtlas;
322 329
323 // Base class for Gr gradient effects 330 // Base class for Gr gradient effects
324 class GrGradientEffect : public GrFragmentProcessor { 331 class GrGradientEffect : public GrFragmentProcessor {
325 public: 332 public:
326 struct CreateArgs { 333 struct CreateArgs {
327 CreateArgs(GrContext* context, 334 CreateArgs(GrContext* context,
328 const SkGradientShaderBase* shader, 335 const SkGradientShaderBase* shader,
329 const SkMatrix* matrix, 336 const SkMatrix* matrix,
330 SkShader::TileMode tileMode) 337 SkShader::TileMode tileMode,
338 sk_sp<GrColorSpaceXform> colorSpaceXform,
339 bool gammaCorrect)
331 : fContext(context) 340 : fContext(context)
332 , fShader(shader) 341 , fShader(shader)
333 , fMatrix(matrix) 342 , fMatrix(matrix)
334 , fTileMode(tileMode) {} 343 , fTileMode(tileMode)
344 , fColorSpaceXform(std::move(colorSpaceXform))
345 , fGammaCorrect(gammaCorrect) {}
335 346
336 GrContext* fContext; 347 GrContext* fContext;
337 const SkGradientShaderBase* fShader; 348 const SkGradientShaderBase* fShader;
338 const SkMatrix* fMatrix; 349 const SkMatrix* fMatrix;
339 SkShader::TileMode fTileMode; 350 SkShader::TileMode fTileMode;
351 sk_sp<GrColorSpaceXform> fColorSpaceXform;
352 bool fGammaCorrect;
340 }; 353 };
341 354
342 class GLSLProcessor; 355 class GLSLProcessor;
343 356
344 GrGradientEffect(const CreateArgs&); 357 GrGradientEffect(const CreateArgs&);
345 358
346 virtual ~GrGradientEffect(); 359 virtual ~GrGradientEffect();
347 360
348 bool useAtlas() const { return SkToBool(-1 != fRow); } 361 bool useAtlas() const { return SkToBool(-1 != fRow); }
349 SkScalar getYCoord() const { return fYCoord; } 362 SkScalar getYCoord() const { return fYCoord; }
(...skipping 27 matching lines...) Expand all
377 }; 390 };
378 391
379 PremulType getPremulType() const { return fPremulType; } 392 PremulType getPremulType() const { return fPremulType; }
380 393
381 const SkColor* getColors(int pos) const { 394 const SkColor* getColors(int pos) const {
382 SkASSERT(fColorType != kTexture_ColorType); 395 SkASSERT(fColorType != kTexture_ColorType);
383 SkASSERT(pos < fColors.count()); 396 SkASSERT(pos < fColors.count());
384 return &fColors[pos]; 397 return &fColors[pos];
385 } 398 }
386 399
400 const SkColor4f* getColors4f(int pos) const {
401 SkASSERT(fColorType != kTexture_ColorType);
402 SkASSERT(pos < fColors4f.count());
403 return &fColors4f[pos];
404 }
405
387 protected: 406 protected:
388 /** Populates a pair of arrays with colors and stop info to construct a rand om gradient. 407 /** Populates a pair of arrays with colors and stop info to construct a rand om gradient.
389 The function decides whether stop values should be used or not. The retu rn value indicates 408 The function decides whether stop values should be used or not. The retu rn value indicates
390 the number of colors, which will be capped by kMaxRandomGradientColors. colors should be 409 the number of colors, which will be capped by kMaxRandomGradientColors. colors should be
391 sized to be at least kMaxRandomGradientColors. stops is a pointer to an array of at least 410 sized to be at least kMaxRandomGradientColors. stops is a pointer to an array of at least
392 size kMaxRandomGradientColors. It may be updated to nullptr, indicating that nullptr should 411 size kMaxRandomGradientColors. It may be updated to nullptr, indicating that nullptr should
393 be passed to the gradient factory rather than the array. 412 be passed to the gradient factory rather than the array.
394 */ 413 */
395 static const int kMaxRandomGradientColors = 4; 414 static const int kMaxRandomGradientColors = 4;
396 static int RandomGradientParams(SkRandom* r, 415 static int RandomGradientParams(SkRandom* r,
397 SkColor colors[kMaxRandomGradientColors], 416 SkColor colors[kMaxRandomGradientColors],
398 SkScalar** stops, 417 SkScalar** stops,
399 SkShader::TileMode* tm); 418 SkShader::TileMode* tm);
400 419
401 bool onIsEqual(const GrFragmentProcessor&) const override; 420 bool onIsEqual(const GrFragmentProcessor&) const override;
402 421
403 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; 422 void onComputeInvariantOutput(GrInvariantOutput* inout) const override;
404 423
405 const GrCoordTransform& getCoordTransform() const { return fCoordTransform; } 424 const GrCoordTransform& getCoordTransform() const { return fCoordTransform; }
406 425
407 private: 426 private:
408 static const GrCoordSet kCoordSet = kLocal_GrCoordSet; 427 static const GrCoordSet kCoordSet = kLocal_GrCoordSet;
409 428
410 SkTDArray<SkColor> fColors; 429 // If we're in legacy mode, then fColors will be populated. If we're gamma-c orrect, then
411 SkTDArray<SkScalar> fPositions; 430 // fColors4f and fColorSpaceXform will be populated.
reed1 2016/09/14 19:03:53 not specific to this CL... but you went from 2 mal
Brian Osman 2016/09/14 20:30:20 Probably. Although we still only have 2 (only one
412 SkShader::TileMode fTileMode; 431 SkTDArray<SkColor> fColors;
432
433 SkTDArray<SkColor4f> fColors4f;
434 sk_sp<GrColorSpaceXform> fColorSpaceXform;
435
436 SkTDArray<SkScalar> fPositions;
437 SkShader::TileMode fTileMode;
413 438
414 GrCoordTransform fCoordTransform; 439 GrCoordTransform fCoordTransform;
415 GrTextureAccess fTextureAccess; 440 GrTextureAccess fTextureAccess;
416 SkScalar fYCoord; 441 SkScalar fYCoord;
417 GrTextureStripAtlas* fAtlas; 442 GrTextureStripAtlas* fAtlas;
418 int fRow; 443 int fRow;
419 bool fIsOpaque; 444 bool fIsOpaque;
420 ColorType fColorType; 445 ColorType fColorType;
421 PremulType fPremulType; // This is already baked into the table for texture gradients, and 446 PremulType fPremulType; // This is already baked into the table for texture gradients, and
422 // only changes behavior for gradients that don't us e a texture. 447 // only changes behavior for gradients that don't us e a texture.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 SkScalar fCachedYCoord; 513 SkScalar fCachedYCoord;
489 GrGLSLProgramDataManager::UniformHandle fColorsUni; 514 GrGLSLProgramDataManager::UniformHandle fColorsUni;
490 GrGLSLProgramDataManager::UniformHandle fFSYUni; 515 GrGLSLProgramDataManager::UniformHandle fFSYUni;
491 516
492 typedef GrGLSLFragmentProcessor INHERITED; 517 typedef GrGLSLFragmentProcessor INHERITED;
493 }; 518 };
494 519
495 #endif 520 #endif
496 521
497 #endif 522 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkGradientShader.cpp ('k') | src/effects/gradients/SkLinearGradient.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698