OLD | NEW |
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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 SkColor fColorStorage[kStorageCount]; | 110 SkColor fColorStorage[kStorageCount]; |
111 SkScalar fPosStorage[kStorageCount]; | 111 SkScalar fPosStorage[kStorageCount]; |
112 SkMatrix fLocalMatrixStorage; | 112 SkMatrix fLocalMatrixStorage; |
113 SkAutoMalloc fDynamicStorage; | 113 SkAutoMalloc fDynamicStorage; |
114 }; | 114 }; |
115 | 115 |
116 public: | 116 public: |
117 SkGradientShaderBase(const Descriptor& desc, const SkMatrix& ptsToUnit); | 117 SkGradientShaderBase(const Descriptor& desc, const SkMatrix& ptsToUnit); |
118 virtual ~SkGradientShaderBase(); | 118 virtual ~SkGradientShaderBase(); |
119 | 119 |
120 // The cache is initialized on-demand when getCache16/32 is called. | 120 // The cache is initialized on-demand when getCache32 is called. |
121 class GradientShaderCache : public SkRefCnt { | 121 class GradientShaderCache : public SkRefCnt { |
122 public: | 122 public: |
123 GradientShaderCache(U8CPU alpha, bool dither, const SkGradientShaderBase
& shader); | 123 GradientShaderCache(U8CPU alpha, bool dither, const SkGradientShaderBase
& shader); |
124 ~GradientShaderCache(); | 124 ~GradientShaderCache(); |
125 | 125 |
126 const uint16_t* getCache16(); | |
127 const SkPMColor* getCache32(); | 126 const SkPMColor* getCache32(); |
128 | 127 |
129 SkMallocPixelRef* getCache32PixelRef() const { return fCache32PixelRef;
} | 128 SkMallocPixelRef* getCache32PixelRef() const { return fCache32PixelRef;
} |
130 | 129 |
131 unsigned getAlpha() const { return fCacheAlpha; } | 130 unsigned getAlpha() const { return fCacheAlpha; } |
132 bool getDither() const { return fCacheDither; } | 131 bool getDither() const { return fCacheDither; } |
133 | 132 |
134 private: | 133 private: |
135 // Working pointers. If either is nullptr, we need to recompute the corr
esponding | 134 // Working pointer. If it's nullptr, we need to recompute the cache valu
es. |
136 // cache values. | |
137 uint16_t* fCache16; | |
138 SkPMColor* fCache32; | 135 SkPMColor* fCache32; |
139 | 136 |
140 uint16_t* fCache16Storage; // Storage for fCache16, allocated
on demand. | |
141 SkMallocPixelRef* fCache32PixelRef; | 137 SkMallocPixelRef* fCache32PixelRef; |
142 const unsigned fCacheAlpha; // The alpha value we used when we
computed the cache. | 138 const unsigned fCacheAlpha; // The alpha value we used when we
computed the cache. |
143 // Larger than 8bits so we can sto
re uninitialized | 139 // Larger than 8bits so we can sto
re uninitialized |
144 // value. | 140 // value. |
145 const bool fCacheDither; // The dither flag used when we co
mputed the cache. | 141 const bool fCacheDither; // The dither flag used when we co
mputed the cache. |
146 | 142 |
147 const SkGradientShaderBase& fShader; | 143 const SkGradientShaderBase& fShader; |
148 | 144 |
149 // Make sure we only initialize the caches once. | 145 // Make sure we only initialize the cache once. |
150 SkOnce fCache16InitOnce, | 146 SkOnce fCache32InitOnce; |
151 fCache32InitOnce; | |
152 | 147 |
153 static void initCache16(GradientShaderCache* cache); | |
154 static void initCache32(GradientShaderCache* cache); | 148 static void initCache32(GradientShaderCache* cache); |
155 | 149 |
156 static void Build16bitCache(uint16_t[], SkColor c0, SkColor c1, int coun
t, bool dither); | |
157 static void Build32bitCache(SkPMColor[], SkColor c0, SkColor c1, int cou
nt, | 150 static void Build32bitCache(SkPMColor[], SkColor c0, SkColor c1, int cou
nt, |
158 U8CPU alpha, uint32_t gradFlags, bool dither
); | 151 U8CPU alpha, uint32_t gradFlags, bool dither
); |
159 }; | 152 }; |
160 | 153 |
161 class GradientShaderBaseContext : public SkShader::Context { | 154 class GradientShaderBaseContext : public SkShader::Context { |
162 public: | 155 public: |
163 GradientShaderBaseContext(const SkGradientShaderBase& shader, const Cont
extRec&); | 156 GradientShaderBaseContext(const SkGradientShaderBase& shader, const Cont
extRec&); |
164 | 157 |
165 uint32_t getFlags() const override { return fFlags; } | 158 uint32_t getFlags() const override { return fFlags; } |
166 | 159 |
(...skipping 10 matching lines...) Expand all Loading... |
177 typedef SkShader::Context INHERITED; | 170 typedef SkShader::Context INHERITED; |
178 }; | 171 }; |
179 | 172 |
180 bool isOpaque() const override; | 173 bool isOpaque() const override; |
181 | 174 |
182 void getGradientTableBitmap(SkBitmap*) const; | 175 void getGradientTableBitmap(SkBitmap*) const; |
183 | 176 |
184 enum { | 177 enum { |
185 /// Seems like enough for visual accuracy. TODO: if pos[] deserves | 178 /// Seems like enough for visual accuracy. TODO: if pos[] deserves |
186 /// it, use a larger cache. | 179 /// it, use a larger cache. |
187 kCache16Bits = 8, | |
188 kCache16Count = (1 << kCache16Bits), | |
189 kCache16Shift = 16 - kCache16Bits, | |
190 kSqrt16Shift = 8 - kCache16Bits, | |
191 | |
192 /// Seems like enough for visual accuracy. TODO: if pos[] deserves | |
193 /// it, use a larger cache. | |
194 kCache32Bits = 8, | 180 kCache32Bits = 8, |
195 kCache32Count = (1 << kCache32Bits), | 181 kCache32Count = (1 << kCache32Bits), |
196 kCache32Shift = 16 - kCache32Bits, | 182 kCache32Shift = 16 - kCache32Bits, |
197 kSqrt32Shift = 8 - kCache32Bits, | 183 kSqrt32Shift = 8 - kCache32Bits, |
198 | 184 |
199 /// This value is used to *read* the dither cache; it may be 0 | 185 /// This value is used to *read* the dither cache; it may be 0 |
200 /// if dithering is disabled. | 186 /// if dithering is disabled. |
201 kDitherStride32 = kCache32Count, | 187 kDitherStride32 = kCache32Count, |
202 kDitherStride16 = kCache16Count, | |
203 }; | 188 }; |
204 | 189 |
205 uint32_t getGradFlags() const { return fGradFlags; } | 190 uint32_t getGradFlags() const { return fGradFlags; } |
206 | 191 |
207 protected: | 192 protected: |
208 class GradientShaderBase4fContext; | 193 class GradientShaderBase4fContext; |
209 | 194 |
210 SkGradientShaderBase(SkReadBuffer& ); | 195 SkGradientShaderBase(SkReadBuffer& ); |
211 void flatten(SkWriteBuffer&) const override; | 196 void flatten(SkWriteBuffer&) const override; |
212 SK_TO_STRING_OVERRIDE() | 197 SK_TO_STRING_OVERRIDE() |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 static inline int init_dither_toggle(int x, int y) { | 254 static inline int init_dither_toggle(int x, int y) { |
270 x &= 1; | 255 x &= 1; |
271 y = (y & 1) << 1; | 256 y = (y & 1) << 1; |
272 return (x | y) * SkGradientShaderBase::kDitherStride32; | 257 return (x | y) * SkGradientShaderBase::kDitherStride32; |
273 } | 258 } |
274 | 259 |
275 static inline int next_dither_toggle(int toggle) { | 260 static inline int next_dither_toggle(int toggle) { |
276 return toggle ^ SkGradientShaderBase::kDitherStride32; | 261 return toggle ^ SkGradientShaderBase::kDitherStride32; |
277 } | 262 } |
278 | 263 |
279 static inline int init_dither_toggle16(int x, int y) { | |
280 return ((x ^ y) & 1) * SkGradientShaderBase::kDitherStride16; | |
281 } | |
282 | |
283 static inline int next_dither_toggle16(int toggle) { | |
284 return toggle ^ SkGradientShaderBase::kDitherStride16; | |
285 } | |
286 | |
287 /////////////////////////////////////////////////////////////////////////////// | 264 /////////////////////////////////////////////////////////////////////////////// |
288 | 265 |
289 #if SK_SUPPORT_GPU | 266 #if SK_SUPPORT_GPU |
290 | 267 |
291 #include "GrCoordTransform.h" | 268 #include "GrCoordTransform.h" |
292 #include "GrFragmentProcessor.h" | 269 #include "GrFragmentProcessor.h" |
293 #include "glsl/GrGLSLFragmentProcessor.h" | 270 #include "glsl/GrGLSLFragmentProcessor.h" |
294 #include "glsl/GrGLSLProgramDataManager.h" | 271 #include "glsl/GrGLSLProgramDataManager.h" |
295 | 272 |
296 class GrInvariantOutput; | 273 class GrInvariantOutput; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 SkScalar fCachedYCoord; | 465 SkScalar fCachedYCoord; |
489 GrGLSLProgramDataManager::UniformHandle fColorsUni; | 466 GrGLSLProgramDataManager::UniformHandle fColorsUni; |
490 GrGLSLProgramDataManager::UniformHandle fFSYUni; | 467 GrGLSLProgramDataManager::UniformHandle fFSYUni; |
491 | 468 |
492 typedef GrGLSLFragmentProcessor INHERITED; | 469 typedef GrGLSLFragmentProcessor INHERITED; |
493 }; | 470 }; |
494 | 471 |
495 #endif | 472 #endif |
496 | 473 |
497 #endif | 474 #endif |
OLD | NEW |