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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
| 115 private: |
| 116 // Working pointers. If either is NULL, we need to recompute the corresp
onding cache values. |
| 117 uint16_t* fCache16; |
| 118 SkPMColor* fCache32; |
| 119 |
| 120 uint16_t* fCache16Storage; // Storage for fCache16, allocated on de
mand. |
| 121 SkMallocPixelRef* fCache32PixelRef; |
| 122 unsigned fCacheAlpha; // The alpha value we used when we compu
ted the cache. |
| 123 // Larger than 8bits so we can store uni
nitialized value. |
| 124 |
| 125 static void Build16bitCache(uint16_t[], SkColor c0, SkColor c1, int coun
t); |
| 126 static void Build32bitCache(SkPMColor[], SkColor c0, SkColor c1, int cou
nt, |
| 127 U8CPU alpha, uint32_t gradFlags); |
| 128 }; |
| 129 |
| 130 class GradientShaderBaseContext : public SkShader::Context { |
| 131 public: |
| 132 GradientShaderBaseContext(const SkGradientShaderBase& shader, const SkBi
tmap& device, |
| 133 const SkPaint& paint, const SkMatrix& matrix); |
| 134 ~GradientShaderBaseContext() {} |
| 135 |
| 136 protected: |
| 137 SkMatrix fDstToIndex; |
| 138 SkMatrix::MapXYProc fDstToIndexProc; |
| 139 uint8_t fDstToIndexClass; |
| 140 uint8_t fFlags; |
| 141 |
| 142 GradientShaderCache fCache; |
| 143 |
| 144 private: |
| 145 typedef SkShader::Context INHERITED; |
| 146 }; |
| 147 |
106 virtual bool isOpaque() const SK_OVERRIDE; | 148 virtual bool isOpaque() const SK_OVERRIDE; |
107 | 149 |
108 void getGradientTableBitmap(SkBitmap*) const; | 150 void getGradientTableBitmap(SkBitmap*) const; |
109 | 151 |
110 enum { | 152 enum { |
111 /// Seems like enough for visual accuracy. TODO: if pos[] deserves | 153 /// Seems like enough for visual accuracy. TODO: if pos[] deserves |
112 /// it, use a larger cache. | 154 /// it, use a larger cache. |
113 kCache16Bits = 8, | 155 kCache16Bits = 8, |
114 kCache16Count = (1 << kCache16Bits), | 156 kCache16Count = (1 << kCache16Bits), |
115 kCache16Shift = 16 - kCache16Bits, | 157 kCache16Shift = 16 - kCache16Bits, |
116 kSqrt16Shift = 8 - kCache16Bits, | 158 kSqrt16Shift = 8 - kCache16Bits, |
117 | 159 |
118 /// Seems like enough for visual accuracy. TODO: if pos[] deserves | 160 /// Seems like enough for visual accuracy. TODO: if pos[] deserves |
119 /// it, use a larger cache. | 161 /// it, use a larger cache. |
120 kCache32Bits = 8, | 162 kCache32Bits = 8, |
121 kCache32Count = (1 << kCache32Bits), | 163 kCache32Count = (1 << kCache32Bits), |
122 kCache32Shift = 16 - kCache32Bits, | 164 kCache32Shift = 16 - kCache32Bits, |
123 kSqrt32Shift = 8 - kCache32Bits, | 165 kSqrt32Shift = 8 - kCache32Bits, |
124 | 166 |
125 /// This value is used to *read* the dither cache; it may be 0 | 167 /// This value is used to *read* the dither cache; it may be 0 |
126 /// if dithering is disabled. | 168 /// if dithering is disabled. |
127 kDitherStride32 = kCache32Count, | 169 kDitherStride32 = kCache32Count, |
128 kDitherStride16 = kCache16Count, | 170 kDitherStride16 = kCache16Count, |
129 }; | 171 }; |
130 | 172 |
131 | |
132 protected: | 173 protected: |
133 SkGradientShaderBase(SkReadBuffer& ); | 174 SkGradientShaderBase(SkReadBuffer& ); |
134 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; | 175 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
135 SK_TO_STRING_OVERRIDE() | 176 SK_TO_STRING_OVERRIDE() |
136 | 177 |
137 SkUnitMapper* fMapper; | 178 SkUnitMapper* fMapper; |
138 SkMatrix fPtsToUnit; // set by subclass | 179 SkMatrix fPtsToUnit; // set by subclass |
139 SkMatrix fDstToIndex; | |
140 SkMatrix::MapXYProc fDstToIndexProc; | |
141 TileMode fTileMode; | 180 TileMode fTileMode; |
142 TileProc fTileProc; | 181 TileProc fTileProc; |
143 int fColorCount; | 182 int fColorCount; |
144 uint8_t fDstToIndexClass; | |
145 uint8_t fFlags; | |
146 uint8_t fGradFlags; | 183 uint8_t fGradFlags; |
147 | 184 |
148 struct Rec { | 185 struct Rec { |
149 SkFixed fPos; // 0...1 | 186 SkFixed fPos; // 0...1 |
150 uint32_t fScale; // (1 << 24) / range | 187 uint32_t fScale; // (1 << 24) / range |
151 }; | 188 }; |
152 Rec* fRecs; | 189 Rec* fRecs; |
153 | 190 |
154 const uint16_t* getCache16() const; | |
155 const SkPMColor* getCache32() const; | |
156 | |
157 void commonAsAGradient(GradientInfo*) const; | 191 void commonAsAGradient(GradientInfo*) const; |
158 | 192 |
159 private: | 193 private: |
160 enum { | 194 enum { |
161 kColorStorageCount = 4, // more than this many colors, and we'll use sk_
malloc for the space | 195 kColorStorageCount = 4, // more than this many colors, and we'll use sk_
malloc for the space |
162 | 196 |
163 kStorageSize = kColorStorageCount * (sizeof(SkColor) + sizeof(Rec)) | 197 kStorageSize = kColorStorageCount * (sizeof(SkColor) + sizeof(Rec)) |
164 }; | 198 }; |
165 SkColor fStorage[(kStorageSize + 3) >> 2]; | 199 SkColor fStorage[(kStorageSize + 3) >> 2]; |
166 SkColor* fOrigColors; // original colors, before modulation by paint in s
etContext | 200 SkColor* fOrigColors; // original colors, before modulation by paint in c
ontext. |
167 bool fColorsAreOpaque; | 201 bool fColorsAreOpaque; |
168 | 202 |
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(); | 203 void initCommon(); |
181 | 204 |
182 typedef SkShader INHERITED; | 205 typedef SkShader INHERITED; |
183 }; | 206 }; |
184 | 207 |
185 static inline int init_dither_toggle(int x, int y) { | 208 static inline int init_dither_toggle(int x, int y) { |
186 x &= 1; | 209 x &= 1; |
187 y = (y & 1) << 1; | 210 y = (y & 1) << 1; |
188 return (x | y) * SkGradientShaderBase::kDitherStride32; | 211 return (x | y) * SkGradientShaderBase::kDitherStride32; |
189 } | 212 } |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 GrGLUniformManager::UniformHandle fColorStartUni; | 404 GrGLUniformManager::UniformHandle fColorStartUni; |
382 GrGLUniformManager::UniformHandle fColorMidUni; | 405 GrGLUniformManager::UniformHandle fColorMidUni; |
383 GrGLUniformManager::UniformHandle fColorEndUni; | 406 GrGLUniformManager::UniformHandle fColorEndUni; |
384 | 407 |
385 typedef GrGLEffect INHERITED; | 408 typedef GrGLEffect INHERITED; |
386 }; | 409 }; |
387 | 410 |
388 #endif | 411 #endif |
389 | 412 |
390 #endif | 413 #endif |
OLD | NEW |