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
22 namespace OHOS {
23 namespace Rosen {
RSFilter()24 RSFilter::RSFilter()
25 : type_(FilterType::NONE)
26 {}
27
~RSFilter()28 RSFilter::~RSFilter() {}
29
CreateBlurFilter(float blurRadiusX,float blurRadiusY)30 std::shared_ptr<RSFilter> RSFilter::CreateBlurFilter(float blurRadiusX, float blurRadiusY)
31 {
32 return std::make_shared<RSBlurFilter>(blurRadiusX, blurRadiusY);
33 }
34
CreateMaterialFilter(int style,float dipScale,BLUR_COLOR_MODE mode)35 std::shared_ptr<RSFilter> RSFilter::CreateMaterialFilter(int style, float dipScale, BLUR_COLOR_MODE mode)
36 {
37 return std::make_shared<RSMaterialFilter>(style, dipScale, mode);
38 }
39
operator +(const std::shared_ptr<RSFilter> & lhs,const std::shared_ptr<RSFilter> & rhs)40 std::shared_ptr<RSFilter> operator+(const std::shared_ptr<RSFilter>& lhs, const std::shared_ptr<RSFilter>& rhs)
41 {
42 if (lhs == nullptr) {
43 return rhs;
44 }
45 if (rhs == nullptr) {
46 return lhs;
47 }
48 return lhs->Add(rhs);
49 }
50
operator -(const std::shared_ptr<RSFilter> & lhs,const std::shared_ptr<RSFilter> & rhs)51 std::shared_ptr<RSFilter> operator-(const std::shared_ptr<RSFilter>& lhs, const std::shared_ptr<RSFilter>& rhs)
52 {
53 if (rhs == nullptr) {
54 return lhs;
55 }
56 if (lhs == nullptr) {
57 return rhs->Negate();
58 }
59 return lhs->Sub(rhs);
60 }
61
operator *(const std::shared_ptr<RSFilter> & lhs,float rhs)62 std::shared_ptr<RSFilter> operator*(const std::shared_ptr<RSFilter>& lhs, float rhs)
63 {
64 if (lhs == nullptr) {
65 return nullptr;
66 }
67 return lhs->Multiply(rhs);
68 }
69 } // namespace Rosen
70 } // namespace OHOS
71