• 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 #ifndef RS_HDR_UTIL_H
17 #define RS_HDR_UTIL_H
18 
19 #include "params/rs_screen_render_params.h"
20 #include "pipeline/render_thread/rs_base_render_engine.h"
21 #include "pipeline/rs_paint_filter_canvas.h"
22 #include "pipeline/rs_screen_render_node.h"
23 #include "pipeline/rs_surface_render_node.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 class RSScreenManager;
28 
29 namespace RSHDRUtilConst {
30 #ifdef USE_VIDEO_PROCESSING_ENGINE
31     using namespace HDI::Display::Graphic::Common::V1_0;
32     const CM_ColorSpaceInfo HDR_CAST_IN_COLORSPACE = {
33         .primaries = COLORPRIMARIES_SRGB,
34         .transfunc = TRANSFUNC_SRGB,
35         .matrix = MATRIX_BT601_N,
36         .range = RANGE_FULL,
37     };
38     const CM_ColorSpaceInfo HDR_CAST_OUT_COLORSPACE = {
39         .primaries = COLORPRIMARIES_BT2020,
40         .transfunc = TRANSFUNC_HLG,
41         .matrix = MATRIX_BT2020,
42         .range = RANGE_FULL,
43     };
44     constexpr CM_ColorSpaceInfo HDR_CAPTURE_HDR_COLORSPACE = {
45         .primaries = COLORPRIMARIES_BT2020,
46         .transfunc = TRANSFUNC_SRGB,
47         .matrix = MATRIX_BT2020,
48         .range = RANGE_FULL,
49     };
50     constexpr CM_ColorSpaceInfo HDR_CAPTURE_SDR_COLORSPACE = {
51         .primaries = COLORPRIMARIES_P3_D65,
52         .transfunc = TRANSFUNC_SRGB,
53         .matrix = MATRIX_BT601_N,
54         .range = RANGE_FULL,
55     };
56 #endif
57 }
58 
59 class RSHdrUtil {
60 public:
61     RSHdrUtil() = default;
62     ~RSHdrUtil() = default;
63 
64     static HdrStatus CheckIsHdrSurface(const RSSurfaceRenderNode& surfaceNode);
65     static HdrStatus CheckIsHdrSurfaceBuffer(const sptr<SurfaceBuffer> surfaceBuffer);
66     static bool CheckIsSurfaceWithMetadata(const RSSurfaceRenderNode& surfaceNode);
67     static bool CheckIsSurfaceBufferWithMetadata(const sptr<SurfaceBuffer> surfaceBuffer);
68     static void UpdateSurfaceNodeLayerLinearMatrix(RSSurfaceRenderNode& surfaceNode, ScreenId screenId);
69     static void UpdatePixelFormatAfterHwcCalc(RSScreenRenderNode& node);
70     static void CheckPixelFormatWithSelfDrawingNode(RSSurfaceRenderNode& surfaceNode, RSScreenRenderNode& screenNode);
71     static void UpdateSurfaceNodeNit(RSSurfaceRenderNode& surfaceNode, ScreenId screenId);
72     static void SetHDRParam(RSScreenRenderNode& screenNode, RSSurfaceRenderNode& node, bool flag);
73     static void LuminanceChangeSetDirty(RSScreenRenderNode& node);
74     static bool GetRGBA1010108Enabled();
75     static void HandleVirtualScreenHDRStatus(RSScreenRenderNode& node, const sptr<RSScreenManager>& screenManager);
76     static void UpdateHDRCastProperties(RSScreenRenderNode& node, bool isNeedHDRCast, bool hdrCastColorGamut);
77     static bool IsHDRCast(RSScreenRenderParams* screenParams, BufferRequestConfig& renderFrameConfig);
78     static ScreenColorGamut GetScreenColorGamut(RSScreenRenderNode& node, const sptr<RSScreenManager>& screenManager);
79     static bool NeedUseF16Capture(const std::shared_ptr<RSSurfaceRenderNode>& surfaceNode);
80     std::shared_ptr<Drawing::ShaderEffect> MakeHdrHeadroomShader(float hrRatio,
81         std::shared_ptr<Drawing::ShaderEffect> imageShader);
82 #ifdef USE_VIDEO_PROCESSING_ENGINE
83     static bool HDRCastProcess(std::shared_ptr<Drawing::Image>& image, Drawing::Brush& paint,
84         const Drawing::SamplingOptions& sampling, std::shared_ptr<Drawing::Surface>& surface,
85         RSPaintFilterCanvas* canvas);
86     static bool SetHDRCastShader(std::shared_ptr<Drawing::Image>& image, Drawing::Brush& paint,
87         const Drawing::SamplingOptions& sampling);
88     static GSError SetMetadata(const HDI::Display::Graphic::Common::V1_0::CM_ColorSpaceInfo& colorspaceInfo,
89         std::unique_ptr<RSRenderFrame>& renderFrame);
90     static GSError SetMetadata(SurfaceBuffer* buffer,
91         const HDI::Display::Graphic::Common::V1_0::CM_ColorSpaceInfo& colorspaceInfo,
92         const HDI::Display::Graphic::Common::V1_0::CM_HDR_Metadata_Type& value);
93 #endif
94 };
95 
96 } // namespace Rosen
97 } // namespace OHOS
98 #endif // RS_HDR_UTIL_H