• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ROSEN_ENGINE_CORE_RENDER_RS_FILTER_H
17 #define ROSEN_ENGINE_CORE_RENDER_RS_FILTER_H
18 
19 #include <memory>
20 
21 #include "common/rs_macros.h"
22 
23 namespace OHOS {
24 namespace Rosen {
25 enum BLUR_COLOR_MODE : int {
26     PRE_DEFINED = 0,           // use the pre-defined mask color
27     AVERAGE     = 1,           // use the average color of the blurred area as mask color
28     DEFAULT     = PRE_DEFINED
29 };
30 
31 class RSB_EXPORT RSFilter : public std::enable_shared_from_this<RSFilter> {
32 public:
33     virtual ~RSFilter();
34     static std::shared_ptr<RSFilter> CreateBlurFilter(float blurRadiusX, float blurRadiusY);
35     static std::shared_ptr<RSFilter> CreateMaterialFilter(int style, float dipScale, BLUR_COLOR_MODE mode = DEFAULT);
36 
37     enum FilterType {
38         NONE = 0,
39         BLUR,
40         MATERIAL,
41     };
GetFilterType()42     FilterType GetFilterType() const
43     {
44         return type_;
45     }
IsValid()46     bool IsValid() const
47     {
48         return type_ != FilterType::NONE;
49     }
50 
51 protected:
52     FilterType type_;
53     RSFilter();
Add(const std::shared_ptr<RSFilter> & rhs)54     virtual std::shared_ptr<RSFilter> Add(const std::shared_ptr<RSFilter>& rhs) { return nullptr; }
Sub(const std::shared_ptr<RSFilter> & rhs)55     virtual std::shared_ptr<RSFilter> Sub(const std::shared_ptr<RSFilter>& rhs) { return nullptr; }
Multiply(float rhs)56     virtual std::shared_ptr<RSFilter> Multiply(float rhs) { return nullptr; }
Negate()57     virtual std::shared_ptr<RSFilter> Negate() { return nullptr; }
58     friend RSB_EXPORT std::shared_ptr<RSFilter> operator+(const std::shared_ptr<RSFilter>& lhs,
59                                                          const std::shared_ptr<RSFilter>& rhs);
60     friend RSB_EXPORT std::shared_ptr<RSFilter> operator-(const std::shared_ptr<RSFilter>& lhs,
61                                                          const std::shared_ptr<RSFilter>& rhs);
62     friend RSB_EXPORT std::shared_ptr<RSFilter> operator*(const std::shared_ptr<RSFilter>& lhs, float rhs);
63 };
64 } // namespace Rosen
65 } // namespace OHOS
66 
67 #endif // ROSEN_ENGINE_CORE_RENDER_RS_FILTER_H
68