blob: b38718e9a4e44dd60ceabb355ed67600faf5af48 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/* libs/graphics/animator/SkDrawShader.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#include "SkDrawShader.h"
19#include "SkDrawBitmap.h"
20#include "SkDrawMatrix.h"
21#include "SkDrawPaint.h"
22#include "SkTemplates.h"
23
24#if SK_USE_CONDENSED_INFO == 0
25
26const SkMemberInfo SkDrawShader::fInfo[] = {
27 SK_MEMBER(matrix, Matrix),
28 SK_MEMBER(tileMode, TileMode)
29};
30
31#endif
32
33DEFINE_GET_MEMBER(SkDrawShader);
34
35SkDrawShader::SkDrawShader() : matrix(NULL),
36 tileMode(SkShader::kClamp_TileMode) {
37}
38
39bool SkDrawShader::add() {
40 if (fPaint->shader != (SkDrawShader*) -1)
41 return true;
42 fPaint->shader = this;
43 fPaint->fOwnsShader = true;
44 return false;
45}
46
47void SkDrawShader::addPostlude(SkShader* shader) {
48 if (matrix)
49 shader->setLocalMatrix(matrix->getMatrix());
50}
51
52#if SK_USE_CONDENSED_INFO == 0
53
54const SkMemberInfo SkDrawBitmapShader::fInfo[] = {
55 SK_MEMBER_INHERITED,
56 SK_MEMBER(filterBitmap, Boolean),
57 SK_MEMBER(image, BaseBitmap)
58};
59
60#endif
61
62DEFINE_GET_MEMBER(SkDrawBitmapShader);
63
64SkDrawBitmapShader::SkDrawBitmapShader() : filterBitmap(-1), image(NULL) {}
65
66bool SkDrawBitmapShader::add() {
67 if (fPaint->shader != (SkDrawShader*) -1)
68 return true;
69 fPaint->shader = this;
70 fPaint->fOwnsShader = true;
71 return false;
72}
73
74SkShader* SkDrawBitmapShader::getShader() {
75 if (image == NULL)
76 return NULL;
77
78 // note: bitmap shader now supports independent tile modes for X and Y
79 // we pass the same to both, but later we should extend this flexibility
80 // to the xml (e.g. tileModeX="repeat" tileModeY="clmap")
81 //
82 // oops, bitmapshader no longer takes filterBitmap, but deduces it at
83 // draw-time from the paint
84 SkShader* shader = SkShader::CreateBitmapShader(image->fBitmap,
85 (SkShader::TileMode) tileMode,
86 (SkShader::TileMode) tileMode);
87 SkAutoTDelete<SkShader> autoDel(shader);
88 addPostlude(shader);
89 (void)autoDel.detach();
90 return shader;
91}