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" |
| 14 | #include "SkTemplates.h" |
| 15 | |
| 16 | #if SK_USE_CONDENSED_INFO == 0 |
| 17 | |
| 18 | const SkMemberInfo SkDrawShader::fInfo[] = { |
| 19 | SK_MEMBER(matrix, Matrix), |
| 20 | SK_MEMBER(tileMode, TileMode) |
| 21 | }; |
| 22 | |
| 23 | #endif |
| 24 | |
| 25 | DEFINE_GET_MEMBER(SkDrawShader); |
| 26 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 27 | SkDrawShader::SkDrawShader() : matrix(NULL), |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | tileMode(SkShader::kClamp_TileMode) { |
| 29 | } |
| 30 | |
| 31 | bool SkDrawShader::add() { |
| 32 | if (fPaint->shader != (SkDrawShader*) -1) |
| 33 | return true; |
| 34 | fPaint->shader = this; |
| 35 | fPaint->fOwnsShader = true; |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | void SkDrawShader::addPostlude(SkShader* shader) { |
| 40 | if (matrix) |
| 41 | shader->setLocalMatrix(matrix->getMatrix()); |
| 42 | } |
| 43 | |
| 44 | #if SK_USE_CONDENSED_INFO == 0 |
| 45 | |
| 46 | const SkMemberInfo SkDrawBitmapShader::fInfo[] = { |
| 47 | SK_MEMBER_INHERITED, |
| 48 | SK_MEMBER(filterBitmap, Boolean), |
| 49 | SK_MEMBER(image, BaseBitmap) |
| 50 | }; |
| 51 | |
| 52 | #endif |
| 53 | |
| 54 | DEFINE_GET_MEMBER(SkDrawBitmapShader); |
| 55 | |
| 56 | SkDrawBitmapShader::SkDrawBitmapShader() : filterBitmap(-1), image(NULL) {} |
| 57 | |
| 58 | bool SkDrawBitmapShader::add() { |
| 59 | if (fPaint->shader != (SkDrawShader*) -1) |
| 60 | return true; |
| 61 | fPaint->shader = this; |
| 62 | fPaint->fOwnsShader = true; |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | SkShader* SkDrawBitmapShader::getShader() { |
| 67 | if (image == NULL) |
| 68 | return NULL; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 69 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 70 | // note: bitmap shader now supports independent tile modes for X and Y |
| 71 | // we pass the same to both, but later we should extend this flexibility |
| 72 | // to the xml (e.g. tileModeX="repeat" tileModeY="clmap") |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 73 | // |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 74 | // oops, bitmapshader no longer takes filterBitmap, but deduces it at |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 75 | // draw-time from the paint |
| 76 | SkShader* shader = SkShader::CreateBitmapShader(image->fBitmap, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 77 | (SkShader::TileMode) tileMode, |
| 78 | (SkShader::TileMode) tileMode); |
| 79 | SkAutoTDelete<SkShader> autoDel(shader); |
| 80 | addPostlude(shader); |
| 81 | (void)autoDel.detach(); |
| 82 | return shader; |
| 83 | } |