• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2006 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 #include "include/core/SkShader.h"
8 
9 #include "include/core/SkMatrix.h"
10 #include "include/core/SkRefCnt.h"
11 #include "src/shaders/SkColorFilterShader.h"
12 #include "src/shaders/SkLocalMatrixShader.h"
13 #include "src/shaders/SkShaderBase.h"
14 #include "src/shaders/SkWorkingColorSpaceShader.h"
15 
16 #include <utility>
17 
18 class SkColorFilter;
19 class SkImage;
20 enum class SkTileMode;
21 
isAImage(SkMatrix * localMatrix,SkTileMode xy[2]) const22 SkImage* SkShader::isAImage(SkMatrix* localMatrix, SkTileMode xy[2]) const {
23     return as_SB(this)->onIsAImage(localMatrix, xy);
24 }
25 
makeWithLocalMatrix(const SkMatrix & localMatrix) const26 sk_sp<SkShader> SkShader::makeWithLocalMatrix(const SkMatrix& localMatrix) const {
27     const SkMatrix* lm = &localMatrix;
28 
29     sk_sp<SkShader> baseShader;
30     SkMatrix otherLocalMatrix;
31     sk_sp<SkShader> proxy = as_SB(this)->makeAsALocalMatrixShader(&otherLocalMatrix);
32     if (proxy) {
33         otherLocalMatrix = SkShaderBase::ConcatLocalMatrices(localMatrix, otherLocalMatrix);
34         lm = &otherLocalMatrix;
35         baseShader = proxy;
36     } else {
37         baseShader = sk_ref_sp(const_cast<SkShader*>(this));
38     }
39 
40     return sk_make_sp<SkLocalMatrixShader>(std::move(baseShader), *lm);
41 }
42 
makeWithColorFilter(sk_sp<SkColorFilter> filter) const43 sk_sp<SkShader> SkShader::makeWithColorFilter(sk_sp<SkColorFilter> filter) const {
44     SkShader* base = const_cast<SkShader*>(this);
45     if (!filter) {
46         return sk_ref_sp(base);
47     }
48     return sk_make_sp<SkColorFilterShader>(sk_ref_sp(base), 1.0f, std::move(filter));
49 }
50 
makeWithWorkingColorSpace(sk_sp<SkColorSpace> workingSpace) const51 sk_sp<SkShader> SkShader::makeWithWorkingColorSpace(sk_sp<SkColorSpace> workingSpace) const {
52     SkShader* base = const_cast<SkShader*>(this);
53     if (!workingSpace) {
54         return sk_ref_sp(base);
55     }
56     return sk_make_sp<SkWorkingColorSpaceShader>(sk_ref_sp(base), std::move(workingSpace));
57 }
58