Nader Jawad | fc42a99 | 2020-07-29 22:48:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include "SkImageFilter.h" |
| 20 | #include "SkShader.h" |
| 21 | #include "SkPaint.h" |
| 22 | #include "SkRefCnt.h" |
| 23 | |
| 24 | class SkMatrix; |
| 25 | |
| 26 | namespace android::uirenderer { |
| 27 | |
| 28 | /** |
| 29 | * Shader class that can optionally wrap an SkShader or SkImageFilter depending |
| 30 | * on the implementation |
| 31 | */ |
| 32 | class Shader: public SkRefCnt { |
| 33 | public: |
| 34 | /** |
Nader Jawad | 322cb9c | 2020-08-17 17:15:54 -0700 | [diff] [blame] | 35 | * Creates a Shader instance with an optional transformation matrix. The transformation matrix |
| 36 | * is copied internally and ownership is unchanged. It is the responsibility of the caller to |
| 37 | * deallocate it appropriately. |
Nader Jawad | fc42a99 | 2020-07-29 22:48:59 -0700 | [diff] [blame] | 38 | * @param matrix Optional matrix to transform the underlying SkShader or SkImageFilter |
| 39 | */ |
| 40 | Shader(const SkMatrix* matrix); |
| 41 | virtual ~Shader(); |
| 42 | |
| 43 | /** |
| 44 | * Create an SkShader from the current Shader instance or return a previously |
| 45 | * created instance. This can be null if no SkShader could be created from this |
| 46 | * Shader instance. |
| 47 | */ |
| 48 | sk_sp<SkShader> asSkShader(); |
| 49 | |
| 50 | /** |
| 51 | * Create an SkImageFilter from the current Shader instance or return a previously |
| 52 | * created instance. Unlike asSkShader, this method cannot return null. |
| 53 | */ |
| 54 | sk_sp<SkImageFilter> asSkImageFilter(); |
| 55 | |
| 56 | protected: |
| 57 | /** |
| 58 | * Create a new SkShader instance based on this Shader instance |
| 59 | */ |
| 60 | virtual sk_sp<SkShader> makeSkShader(); |
| 61 | |
| 62 | /** |
| 63 | * Create a new SkImageFilter instance based on this Shader instance. If no SkImageFilter |
| 64 | * can be created then return nullptr |
| 65 | */ |
| 66 | virtual sk_sp<SkImageFilter> makeSkImageFilter(); |
| 67 | |
| 68 | private: |
| 69 | /** |
| 70 | * Optional matrix transform |
| 71 | */ |
| 72 | const SkMatrix localMatrix; |
| 73 | |
| 74 | /** |
| 75 | * Cached SkShader instance to be returned on subsequent queries |
| 76 | */ |
| 77 | sk_sp<SkShader> skShader; |
| 78 | |
| 79 | /** |
| 80 | * Cached SkImageFilter instance to be returned on subsequent queries |
| 81 | */ |
| 82 | sk_sp<SkImageFilter> skImageFilter; |
| 83 | }; |
| 84 | } // namespace android::uirenderer |