• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "core/pipeline_ng/pipeline_context.h"
17 #include "core/components_ng/render/adapter/rosen_render_context.h"
18 #include "core/components_ng/render/adapter/drawing_decoration_painter.h"
19 #include "core/components/theme/blur_style_theme.h"
20 namespace OHOS::Ace::NG {
21 
22 namespace ROSEN_RENDER_MULTI_THREAD {
GetResourceColorMode(PipelineContext * pipeline)23 ColorMode GetResourceColorMode(PipelineContext* pipeline)
24 {
25     auto themeManager = pipeline->GetThemeManager();
26     CHECK_NULL_RETURN(themeManager, ColorMode::LIGHT);
27     auto themeConstants = themeManager->GetThemeConstants();
28     CHECK_NULL_RETURN(themeConstants, ColorMode::LIGHT);
29     auto resourceAdapter = themeConstants->GetResourceAdapter();
30     CHECK_NULL_RETURN(resourceAdapter, ColorMode::LIGHT);
31     return resourceAdapter->GetResourceColorMode();
32 }
33 
34 
CreateRSMaterialFilter(const BlurStyleOption & blurStyleOption,PipelineContext * pipeline,const SysOptions & sysOptions)35 std::shared_ptr<Rosen::RSFilter> CreateRSMaterialFilter(
36     const BlurStyleOption& blurStyleOption, PipelineContext* pipeline, const SysOptions& sysOptions)
37 {
38     auto blurStyleTheme = pipeline->GetTheme<BlurStyleTheme>();
39     if (!blurStyleTheme) {
40         LOGW("cannot find theme of blurStyle, create blurStyle failed");
41         return nullptr;
42     }
43     ThemeColorMode colorMode = blurStyleOption.colorMode;
44     if (blurStyleOption.colorMode == ThemeColorMode::SYSTEM) {
45         colorMode = GetResourceColorMode(pipeline) == ColorMode::DARK ?
46             ThemeColorMode::DARK : ThemeColorMode::LIGHT;
47     }
48     auto blurParam = blurStyleTheme->GetBlurParameter(blurStyleOption.blurStyle, colorMode);
49     CHECK_NULL_RETURN(blurParam, nullptr);
50     auto ratio = blurStyleOption.scale;
51     auto maskColor = blurParam->maskColor.BlendOpacity(ratio);
52     auto radiusPx = blurParam->radius * pipeline->GetDipScale();
53     auto radiusBlur = DrawingDecorationPainter::ConvertRadiusToSigma(radiusPx) * ratio;
54     auto saturation = (blurParam->saturation - 1) * ratio + 1.0;
55     auto brightness = (blurParam->brightness - 1) * ratio + 1.0;
56     return Rosen::RSFilter::CreateMaterialFilter(radiusBlur, saturation, brightness, maskColor.GetValue(),
57         static_cast<Rosen::BLUR_COLOR_MODE>(blurStyleOption.adaptiveColor), sysOptions.disableSystemAdaptation);
58 }
59 };
60 
NotifyHostTransformUpdatedMultiThread(bool changed)61 void RosenRenderContext::NotifyHostTransformUpdatedMultiThread(bool changed)
62 {
63     auto host = GetHost();
64     CHECK_NULL_VOID(host);
65     host->PostAfterAttachMainTreeTask([weak = WeakPtr<FrameNode>(host), changed]() {
66         auto node = weak.Upgrade();
67         CHECK_NULL_VOID(node);
68         node->NotifyTransformInfoChanged();
69         node->OnNodeTransformInfoUpdate(changed);
70         node->UpdateAccessibilityNodeRect();
71     });
72 }
73 
SetFrontBlurFilterMultiThread()74 void RosenRenderContext::SetFrontBlurFilterMultiThread()
75 {
76     auto node = GetHost();
77     CHECK_NULL_VOID(node);
78     auto task = [weakNode = WeakPtr<FrameNode>(node), rsNode = std::weak_ptr<Rosen::RSNode>(rsNode_),
79         weak = WeakClaim(this) ]() {
80         auto host = weak.Upgrade();
81         CHECK_NULL_VOID(host);
82         auto rsNodeUp = rsNode.lock();
83         CHECK_NULL_VOID(rsNodeUp);
84         auto node = weakNode.Upgrade();
85         CHECK_NULL_VOID(node);
86         auto context = node->GetContextWithCheck();
87         CHECK_NULL_VOID(context);
88         const auto& foreground = host->GetForeground();
89         CHECK_NULL_VOID(foreground);
90         const auto& blurStyleOption = foreground->propBlurStyleOption;
91         auto sysOptions = foreground->propSysOptionsForBlur.value_or(SysOptions());
92         std::shared_ptr<Rosen::RSFilter> frontFilter;
93         if (!blurStyleOption.has_value()) {
94             const auto& radius = foreground->propBlurRadius;
95             if (radius.has_value() && radius->IsValid()) {
96                 float radiusPx = context->NormalizeToPx(radius.value());
97                 float backblurRadius = DrawingDecorationPainter::ConvertRadiusToSigma(radiusPx);
98                 frontFilter = Rosen::RSFilter::CreateBlurFilter(backblurRadius, backblurRadius,
99                     sysOptions.disableSystemAdaptation);
100             }
101         } else {
102             frontFilter = ROSEN_RENDER_MULTI_THREAD::CreateRSMaterialFilter(blurStyleOption.value(),
103                 context, sysOptions);
104         }
105         rsNodeUp->SetFilter(frontFilter);
106     };
107     node->PostAfterAttachMainTreeTask(task);
108 }
109 
AnimateHoverEffectScaleMultiThread(bool isHovered)110 void RosenRenderContext::AnimateHoverEffectScaleMultiThread(bool isHovered)
111 {
112     auto host = GetHost();
113     CHECK_NULL_VOID(host);
114     host->PostAfterAttachMainTreeTask([weak = WeakClaim(this), isHovered]() {
115         auto renderContext = weak.Upgrade();
116         CHECK_NULL_VOID(renderContext);
117         renderContext->AnimateHoverEffectScale(isHovered);
118     });
119 }
120 
AnimateHoverEffectBoardMultiThread(bool isHovered)121 void RosenRenderContext::AnimateHoverEffectBoardMultiThread(bool isHovered)
122 {
123     auto host = GetHost();
124     CHECK_NULL_VOID(host);
125     host->PostAfterAttachMainTreeTask([weak = WeakClaim(this), isHovered]() {
126         auto renderContext = weak.Upgrade();
127         CHECK_NULL_VOID(renderContext);
128         renderContext->AnimateHoverEffectBoard(isHovered);
129     });
130 }
131 }