epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2006 The Android Open Source Project |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | |
| 10 | #include "SkDrawShader.h" |
| 11 | #include "SkDrawBitmap.h" |
| 12 | #include "SkDrawMatrix.h" |
| 13 | #include "SkDrawPaint.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 14 | |
| 15 | #if SK_USE_CONDENSED_INFO == 0 |
| 16 | |
| 17 | const SkMemberInfo SkDrawShader::fInfo[] = { |
| 18 | SK_MEMBER(matrix, Matrix), |
| 19 | SK_MEMBER(tileMode, TileMode) |
| 20 | }; |
| 21 | |
| 22 | #endif |
| 23 | |
| 24 | DEFINE_GET_MEMBER(SkDrawShader); |
| 25 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 26 | SkDrawShader::SkDrawShader() : matrix(nullptr), |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 27 | tileMode(SkShader::kClamp_TileMode) { |
| 28 | } |
| 29 | |
| 30 | bool SkDrawShader::add() { |
| 31 | if (fPaint->shader != (SkDrawShader*) -1) |
| 32 | return true; |
| 33 | fPaint->shader = this; |
| 34 | fPaint->fOwnsShader = true; |
| 35 | return false; |
| 36 | } |
| 37 | |
commit-bot@chromium.org | 9c9005a | 2014-04-28 14:55:39 +0000 | [diff] [blame] | 38 | SkMatrix* SkDrawShader::getMatrix() { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 39 | return matrix ? &matrix->getMatrix() : nullptr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | #if SK_USE_CONDENSED_INFO == 0 |
| 43 | |
| 44 | const SkMemberInfo SkDrawBitmapShader::fInfo[] = { |
| 45 | SK_MEMBER_INHERITED, |
| 46 | SK_MEMBER(filterBitmap, Boolean), |
| 47 | SK_MEMBER(image, BaseBitmap) |
| 48 | }; |
| 49 | |
| 50 | #endif |
| 51 | |
| 52 | DEFINE_GET_MEMBER(SkDrawBitmapShader); |
| 53 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 54 | SkDrawBitmapShader::SkDrawBitmapShader() : filterBitmap(-1), image(nullptr) {} |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 55 | |
| 56 | bool SkDrawBitmapShader::add() { |
| 57 | if (fPaint->shader != (SkDrawShader*) -1) |
| 58 | return true; |
| 59 | fPaint->shader = this; |
| 60 | fPaint->fOwnsShader = true; |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | SkShader* SkDrawBitmapShader::getShader() { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 65 | if (image == nullptr) |
| 66 | return nullptr; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 67 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 68 | // note: bitmap shader now supports independent tile modes for X and Y |
| 69 | // we pass the same to both, but later we should extend this flexibility |
| 70 | // to the xml (e.g. tileModeX="repeat" tileModeY="clmap") |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 71 | // |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 72 | // oops, bitmapshader no longer takes filterBitmap, but deduces it at |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 73 | // draw-time from the paint |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 74 | return SkShader::MakeBitmapShader(image->fBitmap, |
bungeman | f3c15b7 | 2015-08-19 11:56:48 -0700 | [diff] [blame] | 75 | (SkShader::TileMode) tileMode, |
| 76 | (SkShader::TileMode) tileMode, |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 77 | getMatrix()).release(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 78 | } |