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_water_ripple_shader_filter.h"
16 
17 #include "platform/common/rs_log.h"
18 #include "effect/color_matrix.h"
19 #include "effect/runtime_shader_builder.h"
20 #include "include/gpu/GrDirectContext.h"
21 #include "platform/common/rs_system_properties.h"
22 #include "src/core/SkOpts.h"
23 #include "property/rs_properties.h"
24 
25 namespace OHOS {
26 namespace Rosen {
RSWaterRippleShaderFilter(const float progress,const uint32_t waveCount,const float rippleCenterX,const float rippleCenterY,const uint32_t rippleMode)27 RSWaterRippleShaderFilter::RSWaterRippleShaderFilter(
28     const float progress, const uint32_t waveCount, const float rippleCenterX, const float rippleCenterY,
29     const uint32_t rippleMode)
30 {
31     type_ = ShaderFilterType::WATER_RIPPLE;
32     progress_ = progress;
33     waveCount_ = waveCount;
34     rippleCenterX_ = rippleCenterX;
35     rippleCenterY_ = rippleCenterY;
36     rippleMode_ = rippleMode;
37     hash_ = SkOpts::hash(&progress_, sizeof(progress_), hash_);
38     hash_ = SkOpts::hash(&waveCount_, sizeof(waveCount_), hash_);
39     hash_ = SkOpts::hash(&rippleCenterX_, sizeof(rippleCenterX_), hash_);
40     hash_ = SkOpts::hash(&rippleCenterY_, sizeof(rippleCenterY_), hash_);
41     hash_ = SkOpts::hash(&rippleMode_, sizeof(rippleMode_), hash_);
42 }
43 
44 RSWaterRippleShaderFilter::~RSWaterRippleShaderFilter() = default;
45 
GetProgress() const46 float RSWaterRippleShaderFilter::GetProgress() const
47 {
48     return progress_;
49 }
50 
GetwaveCount() const51 uint32_t RSWaterRippleShaderFilter::GetwaveCount() const
52 {
53     return waveCount_;
54 }
55 
GetRippleCenterX() const56 float RSWaterRippleShaderFilter::GetRippleCenterX() const
57 {
58     return rippleCenterX_;
59 }
60 
GetRippleCenterY() const61 float RSWaterRippleShaderFilter::GetRippleCenterY() const
62 {
63     return rippleCenterY_;
64 }
65 
GetRippleMode() const66 uint32_t RSWaterRippleShaderFilter::GetRippleMode() const
67 {
68     return rippleMode_;
69 }
70 
GenerateGEVisualEffect(std::shared_ptr<Drawing::GEVisualEffectContainer> visualEffectContainer)71 void RSWaterRippleShaderFilter::GenerateGEVisualEffect(
72     std::shared_ptr<Drawing::GEVisualEffectContainer> visualEffectContainer)
73 {
74     auto waterRippleFilter = std::make_shared<Drawing::GEVisualEffect>
75         ("WATER_RIPPLE", Drawing::DrawingPaintType::BRUSH);
76     waterRippleFilter->SetParam(RS_FILTER_WATER_RIPPLE_PROGRESS, progress_);
77     waterRippleFilter->SetParam(RS_FILTER_WATER_RIPPLE_WAVE_NUM, waveCount_);
78     waterRippleFilter->SetParam(RS_FILTER_WATER_RIPPLE_RIPPLE_CENTER_X, rippleCenterX_);
79     waterRippleFilter->SetParam(RS_FILTER_WATER_RIPPLE_RIPPLE_CENTER_Y, rippleCenterY_);
80     waterRippleFilter->SetParam(RS_FILTER_WATER_RIPPLE_RIPPLE_MODE, rippleMode_);
81     visualEffectContainer->AddToChainedFilter(waterRippleFilter);
82 }
83 } // namespace Rosen
84 } // namespace OHOS