| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 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 | 8 |
| 9 #ifndef SkShader_DEFINED | 9 #ifndef SkShader_DEFINED |
| 10 #define SkShader_DEFINED | 10 #define SkShader_DEFINED |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * | 23 * |
| 24 * Shaders specify the source color(s) for what is being drawn. If a paint | 24 * Shaders specify the source color(s) for what is being drawn. If a paint |
| 25 * has no shader, then the paint's color is used. If the paint has a | 25 * has no shader, then the paint's color is used. If the paint has a |
| 26 * shader, then the shader's color(s) are use instead, but they are | 26 * shader, then the shader's color(s) are use instead, but they are |
| 27 * modulated by the paint's alpha. This makes it easy to create a shader | 27 * modulated by the paint's alpha. This makes it easy to create a shader |
| 28 * once (e.g. bitmap tiling or gradient) and then change its transparency | 28 * once (e.g. bitmap tiling or gradient) and then change its transparency |
| 29 * w/o having to modify the original shader... only the paint's alpha needs | 29 * w/o having to modify the original shader... only the paint's alpha needs |
| 30 * to be modified. | 30 * to be modified. |
| 31 */ | 31 */ |
| 32 class SK_API SkShader : public SkFlattenable { | 32 class SK_API SkShader : public SkFlattenable { |
| 33 typedef SkFlattenable INHERITED; |
| 34 |
| 33 public: | 35 public: |
| 34 SK_DECLARE_INST_COUNT(SkShader) | 36 SK_DECLARE_INST_COUNT(SkShader) |
| 35 | 37 |
| 36 SkShader(); | 38 SkShader(); |
| 37 virtual ~SkShader(); | 39 virtual ~SkShader(); |
| 38 | 40 |
| 39 /** | 41 /** |
| 40 * Returns true if the local matrix is not an identity matrix. | 42 * Returns true if the local matrix is not an identity matrix. |
| 41 */ | 43 */ |
| 42 bool hasLocalMatrix() const { return !fLocalMatrix.isIdentity(); } | 44 bool hasLocalMatrix() const { return !fLocalMatrix.isIdentity(); } |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 * @param src The bitmap to use inside the shader | 339 * @param src The bitmap to use inside the shader |
| 338 * @param tmx The tiling mode to use when sampling the bitmap in the x-dir
ection. | 340 * @param tmx The tiling mode to use when sampling the bitmap in the x-dir
ection. |
| 339 * @param tmy The tiling mode to use when sampling the bitmap in the y-dir
ection. | 341 * @param tmy The tiling mode to use when sampling the bitmap in the y-dir
ection. |
| 340 * @return Returns a new shader object. Note: this function never retur
ns null. | 342 * @return Returns a new shader object. Note: this function never retur
ns null. |
| 341 */ | 343 */ |
| 342 static SkShader* CreateBitmapShader(const SkBitmap& src, | 344 static SkShader* CreateBitmapShader(const SkBitmap& src, |
| 343 TileMode tmx, TileMode tmy); | 345 TileMode tmx, TileMode tmy); |
| 344 | 346 |
| 345 SkDEVCODE(virtual void toString(SkString* str) const;) | 347 SkDEVCODE(virtual void toString(SkString* str) const;) |
| 346 | 348 |
| 349 SK_DEFINE_FLATTENABLE_TYPE(SkShader) |
| 350 |
| 347 protected: | 351 protected: |
| 348 enum MatrixClass { | 352 enum MatrixClass { |
| 349 kLinear_MatrixClass, // no perspective | 353 kLinear_MatrixClass, // no perspective |
| 350 kFixedStepInX_MatrixClass, // fast perspective, need to call fixedS
tepInX() each scanline | 354 kFixedStepInX_MatrixClass, // fast perspective, need to call fixedS
tepInX() each scanline |
| 351 kPerspective_MatrixClass // slow perspective, need to mappoints e
ach pixel | 355 kPerspective_MatrixClass // slow perspective, need to mappoints e
ach pixel |
| 352 }; | 356 }; |
| 353 static MatrixClass ComputeMatrixClass(const SkMatrix&); | 357 static MatrixClass ComputeMatrixClass(const SkMatrix&); |
| 354 | 358 |
| 355 // These can be called by your subclass after setContext() has been called | 359 // These can be called by your subclass after setContext() has been called |
| 356 uint8_t getPaintAlpha() const { return fPaintAlpha; } | 360 uint8_t getPaintAlpha() const { return fPaintAlpha; } |
| 357 SkBitmap::Config getDeviceConfig() const { return (SkBitmap::Config)fDevi
ceConfig; } | 361 SkBitmap::Config getDeviceConfig() const { return (SkBitmap::Config)fDevi
ceConfig; } |
| 358 const SkMatrix& getTotalInverse() const { return fTotalInverse; } | 362 const SkMatrix& getTotalInverse() const { return fTotalInverse; } |
| 359 MatrixClass getInverseClass() const { return (MatrixClass)fTotalInve
rseClass; } | 363 MatrixClass getInverseClass() const { return (MatrixClass)fTotalInve
rseClass; } |
| 360 | 364 |
| 361 SkShader(SkFlattenableReadBuffer& ); | 365 SkShader(SkFlattenableReadBuffer& ); |
| 362 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; | 366 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; |
| 363 private: | 367 private: |
| 364 SkMatrix fLocalMatrix; | 368 SkMatrix fLocalMatrix; |
| 365 SkMatrix fTotalInverse; | 369 SkMatrix fTotalInverse; |
| 366 uint8_t fPaintAlpha; | 370 uint8_t fPaintAlpha; |
| 367 uint8_t fDeviceConfig; | 371 uint8_t fDeviceConfig; |
| 368 uint8_t fTotalInverseClass; | 372 uint8_t fTotalInverseClass; |
| 369 SkDEBUGCODE(SkBool8 fInSetContext;) | 373 SkDEBUGCODE(SkBool8 fInSetContext;) |
| 370 | 374 |
| 371 static SkShader* CreateBitmapShader(const SkBitmap& src, | 375 static SkShader* CreateBitmapShader(const SkBitmap& src, |
| 372 TileMode, TileMode, | 376 TileMode, TileMode, |
| 373 void* storage, size_t storageSize); | 377 void* storage, size_t storageSize); |
| 374 friend class SkAutoBitmapShaderInstall; | 378 friend class SkAutoBitmapShaderInstall; |
| 375 typedef SkFlattenable INHERITED; | |
| 376 }; | 379 }; |
| 377 | 380 |
| 378 #endif | 381 #endif |
| OLD | NEW |