• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
addPostlude(SkShader * shader)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 
SkDrawBitmapShader()56 SkDrawBitmapShader::SkDrawBitmapShader() : filterBitmap(-1), image(NULL) {}
57 
add()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 
getShader()66 SkShader* SkDrawBitmapShader::getShader() {
67     if (image == NULL)
68         return NULL;
69 
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")
73     //
74     // oops, bitmapshader no longer takes filterBitmap, but deduces it at
75     // draw-time from the paint
76     SkShader* shader  = SkShader::CreateBitmapShader(image->fBitmap,
77                                                     (SkShader::TileMode) tileMode,
78                                                     (SkShader::TileMode) tileMode);
79     SkAutoTDelete<SkShader> autoDel(shader);
80     addPostlude(shader);
81     (void)autoDel.detach();
82     return shader;
83 }
84