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

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

Issue 207683004: Extract most of the mutable state of SkShader into a separate Context object. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase & cleanup Created 6 years, 8 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
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 int fCount; 94 int fCount;
95 SkShader::TileMode fTileMode; 95 SkShader::TileMode fTileMode;
96 SkUnitMapper* fMapper; 96 SkUnitMapper* fMapper;
97 uint32_t fFlags; 97 uint32_t fFlags;
98 }; 98 };
99 99
100 public: 100 public:
101 SkGradientShaderBase(const Descriptor& desc); 101 SkGradientShaderBase(const Descriptor& desc);
102 virtual ~SkGradientShaderBase(); 102 virtual ~SkGradientShaderBase();
103 103
104 virtual bool setContext(const SkBitmap&, const SkPaint&, const SkMatrix&) SK _OVERRIDE; 104 // The cache is initialized on-demand when getCache16/32 is called.
105 virtual uint32_t getFlags() SK_OVERRIDE { return fFlags; } 105 class GradientShaderCache {
106 public:
107 GradientShaderCache(U8CPU alpha);
108 ~GradientShaderCache();
109
110 const uint16_t* getCache16(const SkGradientShaderBase& shader);
111 const SkPMColor* getCache32(const SkGradientShaderBase& shader);
112
113 SkMallocPixelRef* getCache32PixelRef() const { return fCache32PixelRef; }
114 private:
115 uint16_t* fCache16; // working ptr. If this is NULL, we need to reco mpute the cache values
scroggo 2014/04/03 15:35:54 nit: over 100 chars
Dominik Grewe 2014/04/04 10:59:41 Done.
116 SkPMColor* fCache32; // working ptr. If this is NULL, we need to reco mpute the cache values
117
118 uint16_t* fCache16Storage; // storage for fCache16, allocated on de mand
119 SkMallocPixelRef* fCache32PixelRef;
120 unsigned fCacheAlpha; // the alpha value we used when we compu ted the cache.
121 // larger than 8bits so we can store uni nitialized value
122
123 static void Build16bitCache(uint16_t[], SkColor c0, SkColor c1, int coun t);
124 static void Build32bitCache(SkPMColor[], SkColor c0, SkColor c1, int cou nt,
125 U8CPU alpha, uint32_t gradFlags);
126 };
127
128 class GradientShaderBaseContext : public SkShader::Context {
129 public:
130 GradientShaderBaseContext(const SkGradientShaderBase& shader, const SkBi tmap& device,
131 const SkPaint& paint, const SkMatrix& matrix);
132 ~GradientShaderBaseContext() {}
133 protected:
134 SkMatrix fDstToIndex;
135 SkMatrix::MapXYProc fDstToIndexProc;
136 uint8_t fDstToIndexClass;
137 uint8_t fFlags;
138
139 GradientShaderCache fCache;
140
141 typedef SkShader::Context INHERITED;
142 };
143
106 virtual bool isOpaque() const SK_OVERRIDE; 144 virtual bool isOpaque() const SK_OVERRIDE;
107 145
108 void getGradientTableBitmap(SkBitmap*) const; 146 void getGradientTableBitmap(SkBitmap*) const;
109 147
110 enum { 148 enum {
111 /// Seems like enough for visual accuracy. TODO: if pos[] deserves 149 /// Seems like enough for visual accuracy. TODO: if pos[] deserves
112 /// it, use a larger cache. 150 /// it, use a larger cache.
113 kCache16Bits = 8, 151 kCache16Bits = 8,
114 kCache16Count = (1 << kCache16Bits), 152 kCache16Count = (1 << kCache16Bits),
115 kCache16Shift = 16 - kCache16Bits, 153 kCache16Shift = 16 - kCache16Bits,
(...skipping 13 matching lines...) Expand all
129 }; 167 };
130 168
131 169
132 protected: 170 protected:
133 SkGradientShaderBase(SkReadBuffer& ); 171 SkGradientShaderBase(SkReadBuffer& );
134 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; 172 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
135 SK_TO_STRING_OVERRIDE() 173 SK_TO_STRING_OVERRIDE()
136 174
137 SkUnitMapper* fMapper; 175 SkUnitMapper* fMapper;
138 SkMatrix fPtsToUnit; // set by subclass 176 SkMatrix fPtsToUnit; // set by subclass
139 SkMatrix fDstToIndex;
140 SkMatrix::MapXYProc fDstToIndexProc;
141 TileMode fTileMode; 177 TileMode fTileMode;
142 TileProc fTileProc; 178 TileProc fTileProc;
143 int fColorCount; 179 int fColorCount;
144 uint8_t fDstToIndexClass;
145 uint8_t fFlags;
146 uint8_t fGradFlags; 180 uint8_t fGradFlags;
147 181
148 struct Rec { 182 struct Rec {
149 SkFixed fPos; // 0...1 183 SkFixed fPos; // 0...1
150 uint32_t fScale; // (1 << 24) / range 184 uint32_t fScale; // (1 << 24) / range
151 }; 185 };
152 Rec* fRecs; 186 Rec* fRecs;
153 187
154 const uint16_t* getCache16() const;
155 const SkPMColor* getCache32() const;
156
157 void commonAsAGradient(GradientInfo*) const; 188 void commonAsAGradient(GradientInfo*) const;
158 189
159 private: 190 private:
160 enum { 191 enum {
161 kColorStorageCount = 4, // more than this many colors, and we'll use sk_ malloc for the space 192 kColorStorageCount = 4, // more than this many colors, and we'll use sk_ malloc for the space
162 193
163 kStorageSize = kColorStorageCount * (sizeof(SkColor) + sizeof(Rec)) 194 kStorageSize = kColorStorageCount * (sizeof(SkColor) + sizeof(Rec))
164 }; 195 };
165 SkColor fStorage[(kStorageSize + 3) >> 2]; 196 SkColor fStorage[(kStorageSize + 3) >> 2];
166 SkColor* fOrigColors; // original colors, before modulation by paint in s etContext 197 SkColor* fOrigColors; // original colors, before modulation by paint in s etContext
167 bool fColorsAreOpaque; 198 bool fColorsAreOpaque;
168 199
169 mutable uint16_t* fCache16; // working ptr. If this is NULL, we need to recompute the cache values
170 mutable SkPMColor* fCache32; // working ptr. If this is NULL, we need to recompute the cache values
171
172 mutable uint16_t* fCache16Storage; // storage for fCache16, allocated o n demand
173 mutable SkMallocPixelRef* fCache32PixelRef;
174 mutable unsigned fCacheAlpha; // the alpha value we used when we c omputed the cache. larger than 8bits so we can store uninitialized value
175
176 static void Build16bitCache(uint16_t[], SkColor c0, SkColor c1, int count);
177 static void Build32bitCache(SkPMColor[], SkColor c0, SkColor c1, int count,
178 U8CPU alpha, uint32_t gradFlags);
179 void setCacheAlpha(U8CPU alpha) const;
180 void initCommon(); 200 void initCommon();
181 201
182 typedef SkShader INHERITED; 202 typedef SkShader INHERITED;
183 }; 203 };
184 204
185 static inline int init_dither_toggle(int x, int y) { 205 static inline int init_dither_toggle(int x, int y) {
186 x &= 1; 206 x &= 1;
187 y = (y & 1) << 1; 207 y = (y & 1) << 1;
188 return (x | y) * SkGradientShaderBase::kDitherStride32; 208 return (x | y) * SkGradientShaderBase::kDitherStride32;
189 } 209 }
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 GrGLUniformManager::UniformHandle fColorStartUni; 401 GrGLUniformManager::UniformHandle fColorStartUni;
382 GrGLUniformManager::UniformHandle fColorMidUni; 402 GrGLUniformManager::UniformHandle fColorMidUni;
383 GrGLUniformManager::UniformHandle fColorEndUni; 403 GrGLUniformManager::UniformHandle fColorEndUni;
384 404
385 typedef GrGLEffect INHERITED; 405 typedef GrGLEffect INHERITED;
386 }; 406 };
387 407
388 #endif 408 #endif
389 409
390 #endif 410 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698