• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_render_linear_gradient_blur_filter.h"
16 
17 #include "ge_visual_effect.h"
18 #include "ge_visual_effect_container.h"
19 #ifdef USE_M133_SKIA
20 #include "src/core/SkChecksum.h"
21 #else
22 #include "src/core/SkOpts.h"
23 #endif
24 
25 namespace OHOS {
26 namespace Rosen {
RSLinearGradientBlurShaderFilter(const std::shared_ptr<RSLinearGradientBlurPara> & para,const float geoWidth,const float geoHeight)27 RSLinearGradientBlurShaderFilter::RSLinearGradientBlurShaderFilter(
28     const std::shared_ptr<RSLinearGradientBlurPara>& para, const float geoWidth, const float geoHeight)
29     : RSRenderFilterParaBase(RSUIFilterType::LINEAR_GRADIENT_BLUR), linearGradientBlurPara_(para)
30 {
31     geoWidth_ = geoWidth;
32     geoHeight_ = geoHeight;
33 #ifdef USE_M133_SKIA
34     const auto hashFunc = SkChecksum::Hash32;
35 #else
36     const auto hashFunc = SkOpts::hash;
37 #endif
38     basicHash_ = hashFunc(&linearGradientBlurPara_, sizeof(linearGradientBlurPara_), 0);
39     hash_ = basicHash_;
40     hash_ = hashFunc(&geoWidth_, sizeof(geoWidth_), hash_);
41     hash_ = hashFunc(&geoHeight_, sizeof(geoHeight_), hash_);
42 }
43 
GenerateGEVisualEffect(std::shared_ptr<Drawing::GEVisualEffectContainer> visualEffectContainer)44 void RSLinearGradientBlurShaderFilter::GenerateGEVisualEffect(
45     std::shared_ptr<Drawing::GEVisualEffectContainer> visualEffectContainer)
46 {
47     auto gelinearGradientBlurFilter = std::make_shared<Drawing::GEVisualEffect>(
48         "LINEAR_GRADIENT_BLUR", Drawing::DrawingPaintType::BRUSH);
49     gelinearGradientBlurFilter->SetParam("BLURRADIUS", linearGradientBlurPara_->blurRadius_);
50     gelinearGradientBlurFilter->SetParam("GEOWIDTH", geoWidth_);
51     gelinearGradientBlurFilter->SetParam("GEOHEIGHT", geoHeight_);
52     gelinearGradientBlurFilter->SetParam("TRANX", tranX_);
53     gelinearGradientBlurFilter->SetParam("TRANY", tranY_);
54     gelinearGradientBlurFilter->SetParam("CANVASMAT", mat_);
55     gelinearGradientBlurFilter->SetParam("FRACTIONSTOPS", linearGradientBlurPara_->fractionStops_);
56     gelinearGradientBlurFilter->SetParam("DIRECTION", (int)linearGradientBlurPara_->direction_);
57     gelinearGradientBlurFilter->SetParam("ISOFFSCREEN", isOffscreenCanvas_);
58     gelinearGradientBlurFilter->SetParam("ISRADIUSGRADIENT", linearGradientBlurPara_->isRadiusGradient_);
59 
60     visualEffectContainer->AddToChainedFilter(gelinearGradientBlurFilter);
61 }
62 
GetLinearGradientBlurRadius() const63 float RSLinearGradientBlurShaderFilter::GetLinearGradientBlurRadius() const
64 {
65     if (linearGradientBlurPara_ == nullptr) {
66         return 0;
67     }
68     return linearGradientBlurPara_->blurRadius_;
69 }
70 
SetGeometry(Drawing::Canvas & canvas,float geoWidth,float geoHeight)71 void RSLinearGradientBlurShaderFilter::SetGeometry(Drawing::Canvas& canvas, float geoWidth, float geoHeight)
72 {
73     auto dst = canvas.GetDeviceClipBounds();
74     geoWidth_ = std::ceil(geoWidth);
75     geoHeight_ = std::ceil(geoHeight);
76     tranX_ = dst.GetLeft();
77     tranY_ = dst.GetTop();
78     mat_ = canvas.GetTotalMatrix();
79 #ifdef USE_M133_SKIA
80     const auto hashFunc = SkChecksum::Hash32;
81 #else
82     const auto hashFunc = SkOpts::hash;
83 #endif
84     hash_ = basicHash_;
85     hash_ = hashFunc(&geoWidth_, sizeof(geoWidth_), hash_);
86     hash_ = hashFunc(&geoHeight_, sizeof(geoHeight_), hash_);
87 }
88 } // namespace Rosen
89 } // namespace OHOS
90