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