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 #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 
SkDrawShader()27 SkDrawShader::SkDrawShader() : matrix(NULL),
28     tileMode(SkShader::kClamp_TileMode) {
29 }
30 
add()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 
getMatrix()39 SkMatrix* SkDrawShader::getMatrix() {
40     return matrix ? &matrix->getMatrix() : NULL;
41 }
42 
43 #if SK_USE_CONDENSED_INFO == 0
44 
45 const SkMemberInfo SkDrawBitmapShader::fInfo[] = {
46     SK_MEMBER_INHERITED,
47     SK_MEMBER(filterBitmap, Boolean),
48     SK_MEMBER(image, BaseBitmap)
49 };
50 
51 #endif
52 
53 DEFINE_GET_MEMBER(SkDrawBitmapShader);
54 
SkDrawBitmapShader()55 SkDrawBitmapShader::SkDrawBitmapShader() : filterBitmap(-1), image(NULL) {}
56 
add()57 bool SkDrawBitmapShader::add() {
58     if (fPaint->shader != (SkDrawShader*) -1)
59         return true;
60     fPaint->shader = this;
61     fPaint->fOwnsShader = true;
62     return false;
63 }
64 
getShader()65 SkShader* SkDrawBitmapShader::getShader() {
66     if (image == NULL)
67         return NULL;
68 
69     // note: bitmap shader now supports independent tile modes for X and Y
70     // we pass the same to both, but later we should extend this flexibility
71     // to the xml (e.g. tileModeX="repeat" tileModeY="clmap")
72     //
73     // oops, bitmapshader no longer takes filterBitmap, but deduces it at
74     // draw-time from the paint
75     SkShader* shader  = SkShader::CreateBitmapShader(image->fBitmap,
76                                                     (SkShader::TileMode) tileMode,
77                                                     (SkShader::TileMode) tileMode,
78                                                     getMatrix());
79     SkAutoTDelete<SkShader> autoDel(shader);
80     (void)autoDel.detach();
81     return shader;
82 }
83