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

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

Issue 1391303002: Optional gradient dithering (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: table-based approach Created 5 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') | no next file » | 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 SkAutoMalloc fDynamicStorage; 119 SkAutoMalloc fDynamicStorage;
120 }; 120 };
121 121
122 public: 122 public:
123 SkGradientShaderBase(const Descriptor& desc, const SkMatrix& ptsToUnit); 123 SkGradientShaderBase(const Descriptor& desc, const SkMatrix& ptsToUnit);
124 virtual ~SkGradientShaderBase(); 124 virtual ~SkGradientShaderBase();
125 125
126 // The cache is initialized on-demand when getCache16/32 is called. 126 // The cache is initialized on-demand when getCache16/32 is called.
127 class GradientShaderCache : public SkRefCnt { 127 class GradientShaderCache : public SkRefCnt {
128 public: 128 public:
129 GradientShaderCache(U8CPU alpha, const SkGradientShaderBase& shader); 129 GradientShaderCache(U8CPU alpha, bool dither, const SkGradientShaderBase & shader);
130 ~GradientShaderCache(); 130 ~GradientShaderCache();
131 131
132 const uint16_t* getCache16(); 132 const uint16_t* getCache16();
133 const SkPMColor* getCache32(); 133 const SkPMColor* getCache32();
134 134
135 SkMallocPixelRef* getCache32PixelRef() const { return fCache32PixelRef; } 135 SkMallocPixelRef* getCache32PixelRef() const { return fCache32PixelRef; }
136 136
137 unsigned getAlpha() const { return fCacheAlpha; } 137 unsigned getAlpha() const { return fCacheAlpha; }
138 bool getDither() const { return fCacheDither; }
138 139
139 private: 140 private:
140 // Working pointers. If either is nullptr, we need to recompute the corr esponding cache values. 141 // Working pointers. If either is nullptr, we need to recompute the corr esponding cache values.
141 uint16_t* fCache16; 142 uint16_t* fCache16;
142 SkPMColor* fCache32; 143 SkPMColor* fCache32;
143 144
144 uint16_t* fCache16Storage; // Storage for fCache16, allocated on demand. 145 uint16_t* fCache16Storage; // Storage for fCache16, allocated on demand.
145 SkMallocPixelRef* fCache32PixelRef; 146 SkMallocPixelRef* fCache32PixelRef;
146 const unsigned fCacheAlpha; // The alpha value we used when we computed the cache. 147 const unsigned fCacheAlpha; // The alpha value we used when we computed the cache.
147 // Larger than 8bits so we can sto re uninitialized 148 // Larger than 8bits so we can sto re uninitialized
148 // value. 149 // value.
150 const bool fCacheDither; // The dither flag used when we co mputed the cache.
149 151
150 const SkGradientShaderBase& fShader; 152 const SkGradientShaderBase& fShader;
151 153
152 // Make sure we only initialize the caches once. 154 // Make sure we only initialize the caches once.
153 bool fCache16Inited, fCache32Inited; 155 bool fCache16Inited, fCache32Inited;
154 SkMutex fCache16Mutex, fCache32Mutex; 156 SkMutex fCache16Mutex, fCache32Mutex;
155 157
156 static void initCache16(GradientShaderCache* cache); 158 static void initCache16(GradientShaderCache* cache);
157 static void initCache32(GradientShaderCache* cache); 159 static void initCache32(GradientShaderCache* cache);
158 160
159 static void Build16bitCache(uint16_t[], SkColor c0, SkColor c1, int coun t); 161 static void Build16bitCache(uint16_t[], SkColor c0, SkColor c1, int coun t, bool dither);
160 static void Build32bitCache(SkPMColor[], SkColor c0, SkColor c1, int cou nt, 162 static void Build32bitCache(SkPMColor[], SkColor c0, SkColor c1, int cou nt,
161 U8CPU alpha, uint32_t gradFlags); 163 U8CPU alpha, uint32_t gradFlags, bool dither );
162 }; 164 };
163 165
164 class GradientShaderBaseContext : public SkShader::Context { 166 class GradientShaderBaseContext : public SkShader::Context {
165 public: 167 public:
166 GradientShaderBaseContext(const SkGradientShaderBase& shader, const Cont extRec&); 168 GradientShaderBaseContext(const SkGradientShaderBase& shader, const Cont extRec&);
167 169
168 uint32_t getFlags() const override { return fFlags; } 170 uint32_t getFlags() const override { return fFlags; }
169 171
170 protected: 172 protected:
171 SkMatrix fDstToIndex; 173 SkMatrix fDstToIndex;
172 SkMatrix::MapXYProc fDstToIndexProc; 174 SkMatrix::MapXYProc fDstToIndexProc;
173 uint8_t fDstToIndexClass; 175 uint8_t fDstToIndexClass;
174 uint8_t fFlags; 176 uint8_t fFlags;
177 bool fDither;
175 178
176 SkAutoTUnref<GradientShaderCache> fCache; 179 SkAutoTUnref<GradientShaderCache> fCache;
177 180
178 private: 181 private:
179 typedef SkShader::Context INHERITED; 182 typedef SkShader::Context INHERITED;
180 }; 183 };
181 184
182 bool isOpaque() const override; 185 bool isOpaque() const override;
183 186
184 void getGradientTableBitmap(SkBitmap*) const; 187 void getGradientTableBitmap(SkBitmap*) const;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 enum { 256 enum {
254 kColorStorageCount = 4, // more than this many colors, and we'll use sk_ malloc for the space 257 kColorStorageCount = 4, // more than this many colors, and we'll use sk_ malloc for the space
255 258
256 kStorageSize = kColorStorageCount * (sizeof(SkColor) + sizeof(SkScalar) + sizeof(Rec)) 259 kStorageSize = kColorStorageCount * (sizeof(SkColor) + sizeof(SkScalar) + sizeof(Rec))
257 }; 260 };
258 SkColor fStorage[(kStorageSize + 3) >> 2]; 261 SkColor fStorage[(kStorageSize + 3) >> 2];
259 SkColor* fOrigColors; // original colors, before modulation by paint in c ontext. 262 SkColor* fOrigColors; // original colors, before modulation by paint in c ontext.
260 SkScalar* fOrigPos; // original positions 263 SkScalar* fOrigPos; // original positions
261 bool fColorsAreOpaque; 264 bool fColorsAreOpaque;
262 265
263 GradientShaderCache* refCache(U8CPU alpha) const; 266 GradientShaderCache* refCache(U8CPU alpha, bool dither) const;
264 mutable SkMutex fCacheMutex; 267 mutable SkMutex fCacheMutex;
265 mutable SkAutoTUnref<GradientShaderCache> fCache; 268 mutable SkAutoTUnref<GradientShaderCache> fCache;
266 269
267 void initCommon(); 270 void initCommon();
268 271
269 typedef SkShader INHERITED; 272 typedef SkShader INHERITED;
270 }; 273 };
271 274
272 static inline int init_dither_toggle(int x, int y) { 275 static inline int init_dither_toggle(int x, int y) {
273 x &= 1; 276 x &= 1;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 GrGLProgramDataManager::UniformHandle fColorStartUni; 449 GrGLProgramDataManager::UniformHandle fColorStartUni;
447 GrGLProgramDataManager::UniformHandle fColorMidUni; 450 GrGLProgramDataManager::UniformHandle fColorMidUni;
448 GrGLProgramDataManager::UniformHandle fColorEndUni; 451 GrGLProgramDataManager::UniformHandle fColorEndUni;
449 452
450 typedef GrGLFragmentProcessor INHERITED; 453 typedef GrGLFragmentProcessor INHERITED;
451 }; 454 };
452 455
453 #endif 456 #endif
454 457
455 #endif 458 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkGradientShader.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698