blob: e3aa4da028f8058473d2b467a32816cfa35edfaa [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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.com8a1c16f2008-12-17 15:59:43 +00009
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
18const SkMemberInfo SkDrawShader::fInfo[] = {
19 SK_MEMBER(matrix, Matrix),
20 SK_MEMBER(tileMode, TileMode)
21};
22
23#endif
24
25DEFINE_GET_MEMBER(SkDrawShader);
26
rmistry@google.comd6176b02012-08-23 18:14:13 +000027SkDrawShader::SkDrawShader() : matrix(NULL),
reed@android.com8a1c16f2008-12-17 15:59:43 +000028 tileMode(SkShader::kClamp_TileMode) {
29}
30
31bool SkDrawShader::add() {
32 if (fPaint->shader != (SkDrawShader*) -1)
33 return true;
34 fPaint->shader = this;
35 fPaint->fOwnsShader = true;
36 return false;
37}
38
39void SkDrawShader::addPostlude(SkShader* shader) {
40 if (matrix)
41 shader->setLocalMatrix(matrix->getMatrix());
42}
43
44#if SK_USE_CONDENSED_INFO == 0
45
46const SkMemberInfo SkDrawBitmapShader::fInfo[] = {
47 SK_MEMBER_INHERITED,
48 SK_MEMBER(filterBitmap, Boolean),
49 SK_MEMBER(image, BaseBitmap)
50};
51
52#endif
53
54DEFINE_GET_MEMBER(SkDrawBitmapShader);
55
56SkDrawBitmapShader::SkDrawBitmapShader() : filterBitmap(-1), image(NULL) {}
57
58bool SkDrawBitmapShader::add() {
59 if (fPaint->shader != (SkDrawShader*) -1)
60 return true;
61 fPaint->shader = this;
62 fPaint->fOwnsShader = true;
63 return false;
64}
65
66SkShader* SkDrawBitmapShader::getShader() {
67 if (image == NULL)
68 return NULL;
rmistry@google.comd6176b02012-08-23 18:14:13 +000069
reed@android.com8a1c16f2008-12-17 15:59:43 +000070 // 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.comd6176b02012-08-23 18:14:13 +000073 //
reed@android.com8a1c16f2008-12-17 15:59:43 +000074 // oops, bitmapshader no longer takes filterBitmap, but deduces it at
rmistry@google.comd6176b02012-08-23 18:14:13 +000075 // draw-time from the paint
76 SkShader* shader = SkShader::CreateBitmapShader(image->fBitmap,
reed@android.com8a1c16f2008-12-17 15:59:43 +000077 (SkShader::TileMode) tileMode,
78 (SkShader::TileMode) tileMode);
79 SkAutoTDelete<SkShader> autoDel(shader);
80 addPostlude(shader);
81 (void)autoDel.detach();
82 return shader;
83}