1 /*
2 * Copyright (c) 2024 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 #include "render/rs_grey_shader_filter.h"
16
17 #include "pipeline/rs_paint_filter_canvas.h"
18
19
20 namespace OHOS {
21 namespace Rosen {
RSGreyShaderFilter(float greyCoefLow,float greyCoefHigh)22 RSGreyShaderFilter::RSGreyShaderFilter(float greyCoefLow, float greyCoefHigh)
23 : greyCoefLow_(greyCoefLow), greyCoefHigh_(greyCoefHigh)
24 {
25 type_ = ShaderFilterType::GREY;
26 hash_ = SkOpts::hash(&greyCoefLow_, sizeof(greyCoefLow_), hash_);
27 hash_ = SkOpts::hash(&greyCoefHigh_, sizeof(greyCoefHigh_), hash_);
28 }
29
~RSGreyShaderFilter()30 RSGreyShaderFilter::~RSGreyShaderFilter() {};
31
GetGreyCoefLow() const32 float RSGreyShaderFilter::GetGreyCoefLow() const
33 {
34 return greyCoefLow_;
35 }
36
GetGreyCoefHigh() const37 float RSGreyShaderFilter::GetGreyCoefHigh() const
38 {
39 return greyCoefHigh_;
40 }
41
GenerateGEVisualEffect(std::shared_ptr<Drawing::GEVisualEffectContainer> visualEffectContainer)42 void RSGreyShaderFilter::GenerateGEVisualEffect(std::shared_ptr<Drawing::GEVisualEffectContainer> visualEffectContainer)
43 {
44 auto greyFilter = std::make_shared<Drawing::GEVisualEffect>("GREY", Drawing::DrawingPaintType::BRUSH);
45 greyFilter->SetParam("GREY_COEF_1", greyCoefLow_);
46 greyFilter->SetParam("GREY_COEF_2", greyCoefHigh_);
47 visualEffectContainer->AddToChainedFilter(greyFilter);
48 }
49 } // namespace Rosen
50 } // namespace OHOS