| 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 |
| 11 | 11 |
| 12 #include "SkBitmap.h" | 12 #include "SkBitmap.h" |
| 13 #include "SkFlattenable.h" | 13 #include "SkFlattenable.h" |
| 14 #include "SkMask.h" | 14 #include "SkMask.h" |
| 15 #include "SkMatrix.h" | 15 #include "SkMatrix.h" |
| 16 #include "SkPaint.h" | 16 #include "SkPaint.h" |
| 17 | 17 |
| 18 class SkPath; | 18 class SkPath; |
| 19 class SkPicture; | |
| 20 class GrContext; | 19 class GrContext; |
| 21 class GrEffectRef; | 20 class GrEffectRef; |
| 22 | 21 |
| 23 /** \class SkShader | 22 /** \class SkShader |
| 24 * | 23 * |
| 25 * 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 |
| 26 * 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 |
| 27 * 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 |
| 28 * 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 |
| 29 * 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 |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 * the paint. | 338 * the paint. |
| 340 * | 339 * |
| 341 * @param src The bitmap to use inside the shader | 340 * @param src The bitmap to use inside the shader |
| 342 * @param tmx The tiling mode to use when sampling the bitmap in the x-dir
ection. | 341 * @param tmx The tiling mode to use when sampling the bitmap in the x-dir
ection. |
| 343 * @param tmy The tiling mode to use when sampling the bitmap in the y-dir
ection. | 342 * @param tmy The tiling mode to use when sampling the bitmap in the y-dir
ection. |
| 344 * @return Returns a new shader object. Note: this function never retur
ns null. | 343 * @return Returns a new shader object. Note: this function never retur
ns null. |
| 345 */ | 344 */ |
| 346 static SkShader* CreateBitmapShader(const SkBitmap& src, | 345 static SkShader* CreateBitmapShader(const SkBitmap& src, |
| 347 TileMode tmx, TileMode tmy); | 346 TileMode tmx, TileMode tmy); |
| 348 | 347 |
| 349 /** Call this to create a new shader that will draw with the specified pictu
re. | |
| 350 * | |
| 351 * @param src The picture to use inside the shader (if not NULL, its ref c
ount | |
| 352 * is incremented). | |
| 353 * @param tmx The tiling mode to use when sampling the bitmap in the x-dir
ection. | |
| 354 * @param tmy The tiling mode to use when sampling the bitmap in the y-dir
ection. | |
| 355 * @return Returns a new shader object. Note: this function never retur
ns null. | |
| 356 */ | |
| 357 static SkShader* CreatePictureShader(SkPicture* src, TileMode tmx, TileMode
tmy); | |
| 358 | |
| 359 SK_TO_STRING_VIRT() | 348 SK_TO_STRING_VIRT() |
| 360 SK_DEFINE_FLATTENABLE_TYPE(SkShader) | 349 SK_DEFINE_FLATTENABLE_TYPE(SkShader) |
| 361 | 350 |
| 362 protected: | 351 protected: |
| 363 enum MatrixClass { | 352 enum MatrixClass { |
| 364 kLinear_MatrixClass, // no perspective | 353 kLinear_MatrixClass, // no perspective |
| 365 kFixedStepInX_MatrixClass, // fast perspective, need to call fixedS
tepInX() each scanline | 354 kFixedStepInX_MatrixClass, // fast perspective, need to call fixedS
tepInX() each scanline |
| 366 kPerspective_MatrixClass // slow perspective, need to mappoints e
ach pixel | 355 kPerspective_MatrixClass // slow perspective, need to mappoints e
ach pixel |
| 367 }; | 356 }; |
| 368 static MatrixClass ComputeMatrixClass(const SkMatrix&); | 357 static MatrixClass ComputeMatrixClass(const SkMatrix&); |
| 369 | 358 |
| 370 // 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 |
| 371 uint8_t getPaintAlpha() const { return fPaintAlpha; } | 360 uint8_t getPaintAlpha() const { return fPaintAlpha; } |
| 372 const SkMatrix& getTotalInverse() const { return fTotalInverse; } | 361 const SkMatrix& getTotalInverse() const { return fTotalInverse; } |
| 373 MatrixClass getInverseClass() const { return (MatrixClass)fTotalInve
rseClass; } | 362 MatrixClass getInverseClass() const { return (MatrixClass)fTotalInve
rseClass; } |
| 374 | 363 |
| 375 SkShader(SkReadBuffer& ); | 364 SkShader(SkReadBuffer& ); |
| 376 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; | 365 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
| 377 private: | 366 private: |
| 378 SkMatrix fLocalMatrix; | 367 SkMatrix fLocalMatrix; |
| 379 SkMatrix fTotalInverse; | 368 SkMatrix fTotalInverse; |
| 380 uint8_t fPaintAlpha; | 369 uint8_t fPaintAlpha; |
| 381 uint8_t fTotalInverseClass; | 370 uint8_t fTotalInverseClass; |
| 382 SkDEBUGCODE(SkBool8 fInSetContext;) | 371 SkDEBUGCODE(SkBool8 fInSetContext;) |
| 383 | 372 |
| 384 typedef SkFlattenable INHERITED; | 373 typedef SkFlattenable INHERITED; |
| 385 }; | 374 }; |
| 386 | 375 |
| 387 #endif | 376 #endif |
| OLD | NEW |