blob: 2868b9f4efe7c76c891e338eede568fb1eac8a00 [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"
reed@android.com8a1c16f2008-12-17 15:59:43 +000014
15#if SK_USE_CONDENSED_INFO == 0
16
17const SkMemberInfo SkDrawShader::fInfo[] = {
18 SK_MEMBER(matrix, Matrix),
19 SK_MEMBER(tileMode, TileMode)
20};
21
22#endif
23
24DEFINE_GET_MEMBER(SkDrawShader);
25
halcanary96fcdcc2015-08-27 07:41:13 -070026SkDrawShader::SkDrawShader() : matrix(nullptr),
reed@android.com8a1c16f2008-12-17 15:59:43 +000027 tileMode(SkShader::kClamp_TileMode) {
28}
29
30bool SkDrawShader::add() {
31 if (fPaint->shader != (SkDrawShader*) -1)
32 return true;
33 fPaint->shader = this;
34 fPaint->fOwnsShader = true;
35 return false;
36}
37
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +000038SkMatrix* SkDrawShader::getMatrix() {
halcanary96fcdcc2015-08-27 07:41:13 -070039 return matrix ? &matrix->getMatrix() : nullptr;
reed@android.com8a1c16f2008-12-17 15:59:43 +000040}
41
42#if SK_USE_CONDENSED_INFO == 0
43
44const SkMemberInfo SkDrawBitmapShader::fInfo[] = {
45 SK_MEMBER_INHERITED,
46 SK_MEMBER(filterBitmap, Boolean),
47 SK_MEMBER(image, BaseBitmap)
48};
49
50#endif
51
52DEFINE_GET_MEMBER(SkDrawBitmapShader);
53
halcanary96fcdcc2015-08-27 07:41:13 -070054SkDrawBitmapShader::SkDrawBitmapShader() : filterBitmap(-1), image(nullptr) {}
reed@android.com8a1c16f2008-12-17 15:59:43 +000055
56bool SkDrawBitmapShader::add() {
57 if (fPaint->shader != (SkDrawShader*) -1)
58 return true;
59 fPaint->shader = this;
60 fPaint->fOwnsShader = true;
61 return false;
62}
63
64SkShader* SkDrawBitmapShader::getShader() {
halcanary96fcdcc2015-08-27 07:41:13 -070065 if (image == nullptr)
66 return nullptr;
rmistry@google.comd6176b02012-08-23 18:14:13 +000067
reed@android.com8a1c16f2008-12-17 15:59:43 +000068 // 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")
rmistry@google.comd6176b02012-08-23 18:14:13 +000071 //
reed@android.com8a1c16f2008-12-17 15:59:43 +000072 // oops, bitmapshader no longer takes filterBitmap, but deduces it at
rmistry@google.comd6176b02012-08-23 18:14:13 +000073 // draw-time from the paint
reed8a21c9f2016-03-08 18:50:00 -080074 return SkShader::MakeBitmapShader(image->fBitmap,
bungemanf3c15b72015-08-19 11:56:48 -070075 (SkShader::TileMode) tileMode,
76 (SkShader::TileMode) tileMode,
reed8a21c9f2016-03-08 18:50:00 -080077 getMatrix()).release();
reed@android.com8a1c16f2008-12-17 15:59:43 +000078}