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