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
9
10 #include "SkDrawShader.h"
11 #include "SkDrawBitmap.h"
12 #include "SkDrawMatrix.h"
13 #include "SkDrawPaint.h"
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
SkDrawShader()26 SkDrawShader::SkDrawShader() : matrix(nullptr),
27 tileMode(SkShader::kClamp_TileMode) {
28 }
29
add()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
getMatrix()38 SkMatrix* SkDrawShader::getMatrix() {
39 return matrix ? &matrix->getMatrix() : nullptr;
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
SkDrawBitmapShader()54 SkDrawBitmapShader::SkDrawBitmapShader() : filterBitmap(-1), image(nullptr) {}
55
add()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
getShader()64 SkShader* SkDrawBitmapShader::getShader() {
65 if (image == nullptr)
66 return nullptr;
67
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")
71 //
72 // oops, bitmapshader no longer takes filterBitmap, but deduces it at
73 // draw-time from the paint
74 return SkShader::CreateBitmapShader(image->fBitmap,
75 (SkShader::TileMode) tileMode,
76 (SkShader::TileMode) tileMode,
77 getMatrix());
78 }
79