| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 159 |
| 160 static void Build16bitCache(uint16_t[], SkColor c0, SkColor c1, int coun
t); | 160 static void Build16bitCache(uint16_t[], SkColor c0, SkColor c1, int coun
t); |
| 161 static void Build32bitCache(SkPMColor[], SkColor c0, SkColor c1, int cou
nt, | 161 static void Build32bitCache(SkPMColor[], SkColor c0, SkColor c1, int cou
nt, |
| 162 U8CPU alpha, uint32_t gradFlags); | 162 U8CPU alpha, uint32_t gradFlags); |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 class GradientShaderBaseContext : public SkShader::Context { | 165 class GradientShaderBaseContext : public SkShader::Context { |
| 166 public: | 166 public: |
| 167 GradientShaderBaseContext(const SkGradientShaderBase& shader, const Cont
extRec&); | 167 GradientShaderBaseContext(const SkGradientShaderBase& shader, const Cont
extRec&); |
| 168 | 168 |
| 169 uint32_t getFlags() const SK_OVERRIDE { return fFlags; } | 169 uint32_t getFlags() const override { return fFlags; } |
| 170 | 170 |
| 171 protected: | 171 protected: |
| 172 SkMatrix fDstToIndex; | 172 SkMatrix fDstToIndex; |
| 173 SkMatrix::MapXYProc fDstToIndexProc; | 173 SkMatrix::MapXYProc fDstToIndexProc; |
| 174 uint8_t fDstToIndexClass; | 174 uint8_t fDstToIndexClass; |
| 175 uint8_t fFlags; | 175 uint8_t fFlags; |
| 176 | 176 |
| 177 SkAutoTUnref<GradientShaderCache> fCache; | 177 SkAutoTUnref<GradientShaderCache> fCache; |
| 178 | 178 |
| 179 private: | 179 private: |
| 180 typedef SkShader::Context INHERITED; | 180 typedef SkShader::Context INHERITED; |
| 181 }; | 181 }; |
| 182 | 182 |
| 183 bool isOpaque() const SK_OVERRIDE; | 183 bool isOpaque() const override; |
| 184 | 184 |
| 185 void getGradientTableBitmap(SkBitmap*) const; | 185 void getGradientTableBitmap(SkBitmap*) const; |
| 186 | 186 |
| 187 enum { | 187 enum { |
| 188 /// Seems like enough for visual accuracy. TODO: if pos[] deserves | 188 /// Seems like enough for visual accuracy. TODO: if pos[] deserves |
| 189 /// it, use a larger cache. | 189 /// it, use a larger cache. |
| 190 kCache16Bits = 8, | 190 kCache16Bits = 8, |
| 191 kCache16Count = (1 << kCache16Bits), | 191 kCache16Count = (1 << kCache16Bits), |
| 192 kCache16Shift = 16 - kCache16Bits, | 192 kCache16Shift = 16 - kCache16Bits, |
| 193 kSqrt16Shift = 8 - kCache16Bits, | 193 kSqrt16Shift = 8 - kCache16Bits, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 213 | 213 |
| 214 // Determines and returns the gradient is a two color gradient, symmetric th
ree color gradient | 214 // Determines and returns the gradient is a two color gradient, symmetric th
ree color gradient |
| 215 // or other (texture gradient). If it is two or symmetric three color, the c
olors array will | 215 // or other (texture gradient). If it is two or symmetric three color, the c
olors array will |
| 216 // also be filled with the gradient colors | 216 // also be filled with the gradient colors |
| 217 GpuColorType getGpuColorType(SkColor colors[3]) const; | 217 GpuColorType getGpuColorType(SkColor colors[3]) const; |
| 218 | 218 |
| 219 uint32_t getGradFlags() const { return fGradFlags; } | 219 uint32_t getGradFlags() const { return fGradFlags; } |
| 220 | 220 |
| 221 protected: | 221 protected: |
| 222 SkGradientShaderBase(SkReadBuffer& ); | 222 SkGradientShaderBase(SkReadBuffer& ); |
| 223 void flatten(SkWriteBuffer&) const SK_OVERRIDE; | 223 void flatten(SkWriteBuffer&) const override; |
| 224 SK_TO_STRING_OVERRIDE() | 224 SK_TO_STRING_OVERRIDE() |
| 225 | 225 |
| 226 const SkMatrix fPtsToUnit; | 226 const SkMatrix fPtsToUnit; |
| 227 TileMode fTileMode; | 227 TileMode fTileMode; |
| 228 TileProc fTileProc; | 228 TileProc fTileProc; |
| 229 int fColorCount; | 229 int fColorCount; |
| 230 uint8_t fGradFlags; | 230 uint8_t fGradFlags; |
| 231 | 231 |
| 232 struct Rec { | 232 struct Rec { |
| 233 SkFixed fPos; // 0...1 | 233 SkFixed fPos; // 0...1 |
| 234 uint32_t fScale; // (1 << 24) / range | 234 uint32_t fScale; // (1 << 24) / range |
| 235 }; | 235 }; |
| 236 Rec* fRecs; | 236 Rec* fRecs; |
| 237 | 237 |
| 238 void commonAsAGradient(GradientInfo*, bool flipGrad = false) const; | 238 void commonAsAGradient(GradientInfo*, bool flipGrad = false) const; |
| 239 | 239 |
| 240 bool onAsLuminanceColor(SkColor*) const SK_OVERRIDE; | 240 bool onAsLuminanceColor(SkColor*) const override; |
| 241 | 241 |
| 242 /* | 242 /* |
| 243 * Takes in pointers to gradient color and Rec info as colorSrc and recSrc r
espectively. | 243 * Takes in pointers to gradient color and Rec info as colorSrc and recSrc r
espectively. |
| 244 * Count is the number of colors in the gradient | 244 * Count is the number of colors in the gradient |
| 245 * It will then flip all the color and rec information and return in their r
espective Dst | 245 * It will then flip all the color and rec information and return in their r
espective Dst |
| 246 * pointers. It is assumed that space has already been allocated for the Dst
pointers. | 246 * pointers. It is assumed that space has already been allocated for the Dst
pointers. |
| 247 * The rec src and dst are only assumed to be valid if count > 2 | 247 * The rec src and dst are only assumed to be valid if count > 2 |
| 248 */ | 248 */ |
| 249 static void FlipGradientColors(SkColor* colorDst, Rec* recDst, | 249 static void FlipGradientColors(SkColor* colorDst, Rec* recDst, |
| 250 SkColor* colorSrc, Rec* recSrc, | 250 SkColor* colorSrc, Rec* recSrc, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 sized to be at least kMaxRandomGradientColors. stops is a pointer to an
array of at least | 361 sized to be at least kMaxRandomGradientColors. stops is a pointer to an
array of at least |
| 362 size kMaxRandomGradientColors. It may be updated to NULL, indicating tha
t NULL should be | 362 size kMaxRandomGradientColors. It may be updated to NULL, indicating tha
t NULL should be |
| 363 passed to the gradient factory rather than the array. | 363 passed to the gradient factory rather than the array. |
| 364 */ | 364 */ |
| 365 static const int kMaxRandomGradientColors = 4; | 365 static const int kMaxRandomGradientColors = 4; |
| 366 static int RandomGradientParams(SkRandom* r, | 366 static int RandomGradientParams(SkRandom* r, |
| 367 SkColor colors[kMaxRandomGradientColors], | 367 SkColor colors[kMaxRandomGradientColors], |
| 368 SkScalar** stops, | 368 SkScalar** stops, |
| 369 SkShader::TileMode* tm); | 369 SkShader::TileMode* tm); |
| 370 | 370 |
| 371 bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; | 371 bool onIsEqual(const GrFragmentProcessor&) const override; |
| 372 | 372 |
| 373 void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; | 373 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
| 374 | 374 |
| 375 const GrCoordTransform& getCoordTransform() const { return fCoordTransform;
} | 375 const GrCoordTransform& getCoordTransform() const { return fCoordTransform;
} |
| 376 | 376 |
| 377 private: | 377 private: |
| 378 static const GrCoordSet kCoordSet = kLocal_GrCoordSet; | 378 static const GrCoordSet kCoordSet = kLocal_GrCoordSet; |
| 379 | 379 |
| 380 GrCoordTransform fCoordTransform; | 380 GrCoordTransform fCoordTransform; |
| 381 GrTextureAccess fTextureAccess; | 381 GrTextureAccess fTextureAccess; |
| 382 SkScalar fYCoord; | 382 SkScalar fYCoord; |
| 383 GrTextureStripAtlas* fAtlas; | 383 GrTextureStripAtlas* fAtlas; |
| 384 int fRow; | 384 int fRow; |
| 385 bool fIsOpaque; | 385 bool fIsOpaque; |
| 386 SkGradientShaderBase::GpuColorType fColorType; | 386 SkGradientShaderBase::GpuColorType fColorType; |
| 387 SkColor fColors[3]; // More than 3 colors we use texture | 387 SkColor fColors[3]; // More than 3 colors we use texture |
| 388 PremulType fPremulType; // This only changes behavior for two and three colo
r special cases. | 388 PremulType fPremulType; // This only changes behavior for two and three colo
r special cases. |
| 389 // It is already baked into to the table for texture
gradients. | 389 // It is already baked into to the table for texture
gradients. |
| 390 typedef GrFragmentProcessor INHERITED; | 390 typedef GrFragmentProcessor INHERITED; |
| 391 | 391 |
| 392 }; | 392 }; |
| 393 | 393 |
| 394 /////////////////////////////////////////////////////////////////////////////// | 394 /////////////////////////////////////////////////////////////////////////////// |
| 395 | 395 |
| 396 // Base class for GL gradient effects | 396 // Base class for GL gradient effects |
| 397 class GrGLGradientEffect : public GrGLFragmentProcessor { | 397 class GrGLGradientEffect : public GrGLFragmentProcessor { |
| 398 public: | 398 public: |
| 399 GrGLGradientEffect(); | 399 GrGLGradientEffect(); |
| 400 virtual ~GrGLGradientEffect(); | 400 virtual ~GrGLGradientEffect(); |
| 401 | 401 |
| 402 void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE; | 402 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; |
| 403 | 403 |
| 404 protected: | 404 protected: |
| 405 /** | 405 /** |
| 406 * Subclasses must call this. It will return a key for the part of the shade
r code controlled | 406 * Subclasses must call this. It will return a key for the part of the shade
r code controlled |
| 407 * by the base class. The subclasses must stick it in their key and then pas
s it to the below | 407 * by the base class. The subclasses must stick it in their key and then pas
s it to the below |
| 408 * emit* functions from their emitCode function. | 408 * emit* functions from their emitCode function. |
| 409 */ | 409 */ |
| 410 static uint32_t GenBaseGradientKey(const GrProcessor&); | 410 static uint32_t GenBaseGradientKey(const GrProcessor&); |
| 411 | 411 |
| 412 // Emits the uniform used as the y-coord to texture samples in derived class
es. Subclasses | 412 // Emits the uniform used as the y-coord to texture samples in derived class
es. Subclasses |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 GrGLProgramDataManager::UniformHandle fColorStartUni; | 446 GrGLProgramDataManager::UniformHandle fColorStartUni; |
| 447 GrGLProgramDataManager::UniformHandle fColorMidUni; | 447 GrGLProgramDataManager::UniformHandle fColorMidUni; |
| 448 GrGLProgramDataManager::UniformHandle fColorEndUni; | 448 GrGLProgramDataManager::UniformHandle fColorEndUni; |
| 449 | 449 |
| 450 typedef GrGLFragmentProcessor INHERITED; | 450 typedef GrGLFragmentProcessor INHERITED; |
| 451 }; | 451 }; |
| 452 | 452 |
| 453 #endif | 453 #endif |
| 454 | 454 |
| 455 #endif | 455 #endif |
| OLD | NEW |