• 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 #include "render/rs_filter.h"
17 
18 #include "platform/common/rs_log.h"
19 #include "render/rs_blur_filter.h"
20 #include "render/rs_material_filter.h"
21 #include "render/rs_light_up_effect_filter.h"
22 
23 namespace OHOS {
24 namespace Rosen {
RSFilter()25 RSFilter::RSFilter()
26     : type_(FilterType::NONE)
27 {}
28 
~RSFilter()29 RSFilter::~RSFilter() {}
30 
31 std::function<void(std::weak_ptr<RSFilter::RSFilterTask>)> RSFilter::postTask = nullptr;
32 std::function<void()> RSFilter::clearGpuContext = nullptr;
33 
GetDescription()34 std::string RSFilter::GetDescription()
35 {
36     return "RSFilter " + std::to_string(type_);
37 }
38 
CreateBlurFilter(float blurRadiusX,float blurRadiusY)39 std::shared_ptr<RSFilter> RSFilter::CreateBlurFilter(float blurRadiusX, float blurRadiusY)
40 {
41     return std::make_shared<RSBlurFilter>(blurRadiusX, blurRadiusY);
42 }
43 
CreateMaterialFilter(int style,float dipScale,BLUR_COLOR_MODE mode,float ratio)44 std::shared_ptr<RSFilter> RSFilter::CreateMaterialFilter(int style, float dipScale, BLUR_COLOR_MODE mode, float ratio)
45 {
46     return std::make_shared<RSMaterialFilter>(style, dipScale, mode, ratio);
47 }
48 
CreateMaterialFilter(float radius,float saturation,float brightness,uint32_t colorValue,BLUR_COLOR_MODE mode)49 std::shared_ptr<RSFilter> RSFilter::CreateMaterialFilter(float radius, float saturation,
50     float brightness, uint32_t colorValue, BLUR_COLOR_MODE mode)
51 {
52     MaterialParam materialParam = {radius, saturation, brightness, Color::FromArgbInt(colorValue)};
53     return std::make_shared<RSMaterialFilter>(materialParam, mode);
54 }
55 
CreateLightUpEffectFilter(float lightUpDegree)56 std::shared_ptr<RSFilter> RSFilter::CreateLightUpEffectFilter(float lightUpDegree)
57 {
58     return std::make_shared<RSLightUpEffectFilter>(lightUpDegree);
59 }
60 
operator +(const std::shared_ptr<RSFilter> & lhs,const std::shared_ptr<RSFilter> & rhs)61 std::shared_ptr<RSFilter> operator+(const std::shared_ptr<RSFilter>& lhs, const std::shared_ptr<RSFilter>& rhs)
62 {
63     if (lhs == nullptr) {
64         return rhs;
65     }
66     if (rhs == nullptr) {
67         return lhs;
68     }
69     return lhs->Add(rhs);
70 }
71 
operator -(const std::shared_ptr<RSFilter> & lhs,const std::shared_ptr<RSFilter> & rhs)72 std::shared_ptr<RSFilter> operator-(const std::shared_ptr<RSFilter>& lhs, const std::shared_ptr<RSFilter>& rhs)
73 {
74     if (rhs == nullptr) {
75         return lhs;
76     }
77     if (lhs == nullptr) {
78         return rhs->Negate();
79     }
80     return lhs->Sub(rhs);
81 }
82 
operator *(const std::shared_ptr<RSFilter> & lhs,float rhs)83 std::shared_ptr<RSFilter> operator*(const std::shared_ptr<RSFilter>& lhs, float rhs)
84 {
85     if (lhs == nullptr) {
86         return nullptr;
87     }
88     return lhs->Multiply(rhs);
89 }
90 } // namespace Rosen
91 } // namespace OHOS
92