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

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

Issue 2397473003: Harden degenerate gradient context handling (Closed)
Patch Set: Created 4 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
« 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
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 private: 108 private:
109 enum { 109 enum {
110 kStorageCount = 16 110 kStorageCount = 16
111 }; 111 };
112 SkColor4f fColorStorage[kStorageCount]; 112 SkColor4f fColorStorage[kStorageCount];
113 SkScalar fPosStorage[kStorageCount]; 113 SkScalar fPosStorage[kStorageCount];
114 SkMatrix fLocalMatrixStorage; 114 SkMatrix fLocalMatrixStorage;
115 SkAutoMalloc fDynamicStorage; 115 SkAutoMalloc fDynamicStorage;
116 }; 116 };
117 117
118 public:
119 SkGradientShaderBase(const Descriptor& desc, const SkMatrix& ptsToUnit); 118 SkGradientShaderBase(const Descriptor& desc, const SkMatrix& ptsToUnit);
120 virtual ~SkGradientShaderBase(); 119 virtual ~SkGradientShaderBase();
121 120
122 // The cache is initialized on-demand when getCache32 is called. 121 // The cache is initialized on-demand when getCache32 is called.
123 class GradientShaderCache : public SkRefCnt { 122 class GradientShaderCache : public SkRefCnt {
124 public: 123 public:
125 GradientShaderCache(U8CPU alpha, bool dither, const SkGradientShaderBase & shader); 124 GradientShaderCache(U8CPU alpha, bool dither, const SkGradientShaderBase & shader);
126 ~GradientShaderCache(); 125 ~GradientShaderCache();
127 126
128 const SkPMColor* getCache32(); 127 const SkPMColor* getCache32();
(...skipping 23 matching lines...) Expand all
152 static void Build32bitCache(SkPMColor[], SkColor c0, SkColor c1, int cou nt, 151 static void Build32bitCache(SkPMColor[], SkColor c0, SkColor c1, int cou nt,
153 U8CPU alpha, uint32_t gradFlags, bool dither ); 152 U8CPU alpha, uint32_t gradFlags, bool dither );
154 }; 153 };
155 154
156 class GradientShaderBaseContext : public SkShader::Context { 155 class GradientShaderBaseContext : public SkShader::Context {
157 public: 156 public:
158 GradientShaderBaseContext(const SkGradientShaderBase& shader, const Cont extRec&); 157 GradientShaderBaseContext(const SkGradientShaderBase& shader, const Cont extRec&);
159 158
160 uint32_t getFlags() const override { return fFlags; } 159 uint32_t getFlags() const override { return fFlags; }
161 160
161 bool isValid() const;
162
162 protected: 163 protected:
163 SkMatrix fDstToIndex; 164 SkMatrix fDstToIndex;
164 SkMatrix::MapXYProc fDstToIndexProc; 165 SkMatrix::MapXYProc fDstToIndexProc;
165 uint8_t fDstToIndexClass; 166 uint8_t fDstToIndexClass;
166 uint8_t fFlags; 167 uint8_t fFlags;
167 bool fDither; 168 bool fDither;
168 169
169 SkAutoTUnref<GradientShaderCache> fCache; 170 SkAutoTUnref<GradientShaderCache> fCache;
170 171
171 private: 172 private:
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 * Takes in pointers to gradient color and Rec info as colorSrc and recSrc r espectively. 227 * Takes in pointers to gradient color and Rec info as colorSrc and recSrc r espectively.
227 * Count is the number of colors in the gradient 228 * Count is the number of colors in the gradient
228 * It will then flip all the color and rec information and return in their r espective Dst 229 * It will then flip all the color and rec information and return in their r espective Dst
229 * pointers. It is assumed that space has already been allocated for the Dst pointers. 230 * pointers. It is assumed that space has already been allocated for the Dst pointers.
230 * The rec src and dst are only assumed to be valid if count > 2 231 * The rec src and dst are only assumed to be valid if count > 2
231 */ 232 */
232 static void FlipGradientColors(SkColor* colorDst, Rec* recDst, 233 static void FlipGradientColors(SkColor* colorDst, Rec* recDst,
233 SkColor* colorSrc, Rec* recSrc, 234 SkColor* colorSrc, Rec* recSrc,
234 int count); 235 int count);
235 236
237 template <typename T, typename... Args>
238 static Context* CheckedCreateContext(void* storage, Args&&... args) {
239 auto* ctx = new (storage) T(std::forward<Args>(args)...);
240 if (!ctx->isValid()) {
241 ctx->~T();
242 return nullptr;
243 }
244 return ctx;
245 }
246
236 private: 247 private:
237 enum { 248 enum {
238 kColorStorageCount = 4, // more than this many colors, and we'll use sk_ malloc for the space 249 kColorStorageCount = 4, // more than this many colors, and we'll use sk_ malloc for the space
239 250
240 kStorageSize = kColorStorageCount * 251 kStorageSize = kColorStorageCount *
241 (sizeof(SkColor) + sizeof(SkScalar) + sizeof(Rec) + sizeo f(SkColor4f)) 252 (sizeof(SkColor) + sizeof(SkScalar) + sizeof(Rec) + sizeo f(SkColor4f))
242 }; 253 };
243 SkColor fStorage[(kStorageSize + 3) >> 2]; 254 SkColor fStorage[(kStorageSize + 3) >> 2];
244 public: 255 public:
245 SkColor* fOrigColors; // original colors, before modulation by paint in context. 256 SkColor* fOrigColors; // original colors, before modulation by paint in context.
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 GrGLSLProgramDataManager::UniformHandle fColorsUni; 508 GrGLSLProgramDataManager::UniformHandle fColorsUni;
498 GrGLSLProgramDataManager::UniformHandle fFSYUni; 509 GrGLSLProgramDataManager::UniformHandle fFSYUni;
499 GrGLSLProgramDataManager::UniformHandle fColorSpaceXformUni; 510 GrGLSLProgramDataManager::UniformHandle fColorSpaceXformUni;
500 511
501 typedef GrGLSLFragmentProcessor INHERITED; 512 typedef GrGLSLFragmentProcessor INHERITED;
502 }; 513 };
503 514
504 #endif 515 #endif
505 516
506 #endif 517 #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