• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_CORE_PIPELINE_PROCESSOR_H
17 #define RS_CORE_PIPELINE_PROCESSOR_H
18 
19 #include <memory>
20 
21 #include "params/rs_surface_render_params.h"
22 #include "utils/matrix.h"
23 
24 #include "drawable/rs_surface_render_node_drawable.h"
25 #include "rs_base_render_engine.h"
26 #include "pipeline/rs_surface_render_node.h"
27 
28 namespace OHOS {
29 namespace Rosen {
30 class RSRcdSurfaceRenderNode;
31 class RSDisplayRenderParams;
32 class RSSurfaceRenderParams;
33 class RSProcessor : public std::enable_shared_from_this<RSProcessor> {
34 public:
35     static inline constexpr RSProcessorType Type = RSProcessorType::RS_PROCESSOR;
GetType()36     virtual RSProcessorType GetType() const
37     {
38         return Type;
39     }
40 
41     RSProcessor() = default;
42     virtual ~RSProcessor() noexcept = default;
43 
44     RSProcessor(const RSProcessor&) = delete;
45     void operator=(const RSProcessor&) = delete;
46 
47     virtual bool Init(RSDisplayRenderNode& node, int32_t offsetX, int32_t offsetY, ScreenId mirroredId,
48         std::shared_ptr<RSBaseRenderEngine> renderEngine);
CreateLayer(RSSurfaceRenderNode & node,RSSurfaceRenderParams & params)49     virtual void CreateLayer(RSSurfaceRenderNode& node, RSSurfaceRenderParams& params) {}
CreateUIFirstLayer(DrawableV2::RSSurfaceRenderNodeDrawable & drawable,RSSurfaceRenderParams & params)50     virtual void CreateUIFirstLayer(DrawableV2::RSSurfaceRenderNodeDrawable& drawable,
51         RSSurfaceRenderParams& params) {}
52     virtual void ProcessSurface(RSSurfaceRenderNode& node) = 0;
53     virtual void ProcessDisplaySurface(RSDisplayRenderNode& node) = 0;
54     virtual void PostProcess() = 0;
55     virtual void ProcessRcdSurface(RSRcdSurfaceRenderNode& node) = 0;
56 
57     virtual bool InitForRenderThread(DrawableV2::RSDisplayRenderNodeDrawable& displayDrawable, ScreenId mirroredId,
58         std::shared_ptr<RSBaseRenderEngine> renderEngine);
CreateLayerForRenderThread(DrawableV2::RSSurfaceRenderNodeDrawable & surfaceDrawable)59     virtual void CreateLayerForRenderThread(DrawableV2::RSSurfaceRenderNodeDrawable& surfaceDrawable) {}
ProcessDisplaySurfaceForRenderThread(DrawableV2::RSDisplayRenderNodeDrawable & displayDrawable)60     virtual void ProcessDisplaySurfaceForRenderThread(DrawableV2::RSDisplayRenderNodeDrawable& displayDrawable) {}
ProcessSurfaceForRenderThread(DrawableV2::RSSurfaceRenderNodeDrawable & surfaceDrawable)61     virtual void ProcessSurfaceForRenderThread(DrawableV2::RSSurfaceRenderNodeDrawable& surfaceDrawable) {}
62 
63     void SetSecurityDisplay(bool isSecurityDisplay);
64     void SetDisplayHasSecSurface(bool displayHasSecSurface);
65     void MirrorScenePerf();
66 
GetScreenTransformMatrix()67     const Drawing::Matrix& GetScreenTransformMatrix() const
68     {
69         return screenTransformMatrix_;
70     }
71 
72     // type-safe reinterpret_cast
73     template<typename T>
IsInstanceOf()74     bool IsInstanceOf() const
75     {
76         constexpr auto targetType = static_cast<uint32_t>(T::Type);
77         return (static_cast<uint32_t>(GetType()) & targetType) == targetType;
78     }
79     template<typename T>
ReinterpretCast(std::shared_ptr<RSProcessor> processer)80     static std::shared_ptr<T> ReinterpretCast(std::shared_ptr<RSProcessor> processer)
81     {
82         return processer ? processer->ReinterpretCastTo<T>() : nullptr;
83     }
84     template<typename T>
ReinterpretCastTo()85     std::shared_ptr<T> ReinterpretCastTo()
86     {
87         return (IsInstanceOf<T>()) ? std::static_pointer_cast<T>(shared_from_this()) : nullptr;
88     }
89     template<typename T>
ReinterpretCastTo()90     std::shared_ptr<const T> ReinterpretCastTo() const
91     {
92         return (IsInstanceOf<T>()) ? std::static_pointer_cast<const T>(shared_from_this()) : nullptr;
93     }
94 
95 protected:
96     void CalculateMirrorAdaptiveCoefficient(float curWidth, float curHeight,
97         float mirroredWidth, float mirroredHeight);
98     void CalculateScreenTransformMatrix(const RSDisplayRenderNode& node);
99     void SetMirrorScreenSwap(const RSDisplayRenderNode& node);
100     void CalculateMirrorAdaptiveMatrix();
101 
102     void MultiLayersPerf(size_t layerNum);
103     void RequestPerf(uint32_t layerLevel, bool onOffTag);
104 #ifdef FRAME_AWARE_TRACE
105     bool FrameAwareTraceBoost(size_t layerNum);
106 #endif
107 
108     ScreenInfo screenInfo_;
109     int32_t offsetX_ = 0;
110     int32_t offsetY_ = 0;
111     ScreenId mirroredId_ = INVALID_SCREEN_ID;
112     ScreenInfo mirroredScreenInfo_;
113     float mirrorAdaptiveCoefficient_ = 1.0f;
114     std::shared_ptr<RSBaseRenderEngine> renderEngine_;
115     Drawing::Matrix screenTransformMatrix_;
116     Drawing::Matrix mirrorAdaptiveMatrix_;
117     BufferRequestConfig renderFrameConfig_ {};
118     bool isSecurityDisplay_ = false;
119     bool displayHasSecSurface_ = false;
120     static bool needDisableMultiLayersPerf_;
121 };
122 } // namespace Rosen
123 } // namespace OHOS
124 #endif // RS_CORE_PIPELINE_PROCESSOR_H
125