• 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 "pipeline/rs_screen_render_node.h"
26 #include "pipeline/rs_surface_render_node.h"
27 #include "render_thread/rs_base_render_engine.h"
28 
29 namespace OHOS {
30 namespace Rosen {
31 class RSRcdSurfaceRenderNode;
32 #ifdef RS_ENABLE_GPU
33 class RSScreenRenderParams;
34 #endif
35 class RSSurfaceRenderParams;
36 namespace DrawableV2 {
37 class RSSurfaceRenderNodeDrawable;
38 }
39 class RSProcessor : public std::enable_shared_from_this<RSProcessor> {
40 public:
41     static inline constexpr RSProcessorType Type = RSProcessorType::RS_PROCESSOR;
GetType()42     virtual RSProcessorType GetType() const
43     {
44         return Type;
45     }
46 
47     RSProcessor() = default;
48     virtual ~RSProcessor() noexcept = default;
49 
50     RSProcessor(const RSProcessor&) = delete;
51     void operator=(const RSProcessor&) = delete;
52     virtual bool Init(RSScreenRenderNode& node, int32_t offsetX, int32_t offsetY, ScreenId mirroredId,
53         std::shared_ptr<RSBaseRenderEngine> renderEngine);
CreateLayer(const RSSurfaceRenderNode & node,RSSurfaceRenderParams & params)54     virtual void CreateLayer(const RSSurfaceRenderNode& node, RSSurfaceRenderParams& params) {}
55     virtual void ProcessSurface(RSSurfaceRenderNode& node) = 0;
56     virtual void ProcessScreenSurface(RSScreenRenderNode& node) = 0;
57     virtual void PostProcess() = 0;
58     virtual void ProcessRcdSurface(RSRcdSurfaceRenderNode& node) = 0;
59 
60     virtual bool InitForRenderThread(DrawableV2::RSScreenRenderNodeDrawable& screenDrawable,
61         std::shared_ptr<RSBaseRenderEngine> renderEngine);
62     virtual bool UpdateMirrorInfo(DrawableV2::RSLogicalDisplayRenderNodeDrawable& displayDrawable);
CreateLayerForRenderThread(DrawableV2::RSSurfaceRenderNodeDrawable & surfaceDrawable)63     virtual void CreateLayerForRenderThread(DrawableV2::RSSurfaceRenderNodeDrawable& surfaceDrawable) {}
ProcessScreenSurfaceForRenderThread(DrawableV2::RSScreenRenderNodeDrawable & screenDrawable)64     virtual void ProcessScreenSurfaceForRenderThread(DrawableV2::RSScreenRenderNodeDrawable& screenDrawable) {}
ProcessSurfaceForRenderThread(DrawableV2::RSSurfaceRenderNodeDrawable & surfaceDrawable)65     virtual void ProcessSurfaceForRenderThread(DrawableV2::RSSurfaceRenderNodeDrawable& surfaceDrawable) {}
ProcessRcdSurfaceForRenderThread(DrawableV2::RSRcdSurfaceRenderNodeDrawable & rcdDrawable)66     virtual void ProcessRcdSurfaceForRenderThread(DrawableV2::RSRcdSurfaceRenderNodeDrawable& rcdDrawable) {}
67 
68     void SetSecurityDisplay(bool isSecurityDisplay);
69     void SetDisplayHasSecSurface(bool displayHasSecSurface);
70 
GetScreenTransformMatrix()71     const Drawing::Matrix& GetScreenTransformMatrix() const
72     {
73         return screenTransformMatrix_;
74     }
75 
76     // type-safe reinterpret_cast
77     template<typename T>
IsInstanceOf()78     bool IsInstanceOf() const
79     {
80         constexpr auto targetType = static_cast<uint32_t>(T::Type);
81         return (static_cast<uint32_t>(GetType()) & targetType) == targetType;
82     }
83     template<typename T>
ReinterpretCast(std::shared_ptr<RSProcessor> processer)84     static std::shared_ptr<T> ReinterpretCast(std::shared_ptr<RSProcessor> processer)
85     {
86         return processer ? processer->ReinterpretCastTo<T>() : nullptr;
87     }
88     template<typename T>
ReinterpretCastTo()89     std::shared_ptr<T> ReinterpretCastTo()
90     {
91         return (IsInstanceOf<T>()) ? std::static_pointer_cast<T>(shared_from_this()) : nullptr;
92     }
93     template<typename T>
ReinterpretCastTo()94     std::shared_ptr<const T> ReinterpretCastTo() const
95     {
96         return (IsInstanceOf<T>()) ? std::static_pointer_cast<const T>(shared_from_this()) : nullptr;
97     }
98 
99     // hpae offline
ProcessOfflineLayer(std::shared_ptr<DrawableV2::RSSurfaceRenderNodeDrawable> & surfaceDrawable,bool async)100     virtual bool ProcessOfflineLayer(std::shared_ptr<DrawableV2::RSSurfaceRenderNodeDrawable>& surfaceDrawable,
101         bool async) { return false; }
ProcessOfflineLayer(std::shared_ptr<RSSurfaceRenderNode> & node)102     virtual bool ProcessOfflineLayer(std::shared_ptr<RSSurfaceRenderNode>& node) { return false; }
103 
104 protected:
105     void CalculateMirrorAdaptiveCoefficient(float curWidth, float curHeight,
106         float mirroredWidth, float mirroredHeight);
107     void CalculateScreenTransformMatrix(const RSScreenRenderNode& node);
108     void SetMirrorScreenSwap(const RSScreenRenderNode& node);
109     void CalculateMirrorAdaptiveMatrix();
110 
111     void RequestPerf(uint32_t layerLevel, bool onOffTag);
112 #ifdef FRAME_AWARE_TRACE
113     bool FrameAwareTraceBoost(size_t layerNum);
114 #endif
115 
116     ScreenInfo screenInfo_;
117     int32_t offsetX_ = 0;
118     int32_t offsetY_ = 0;
119     ScreenId mirroredId_ = INVALID_SCREEN_ID;
120     ScreenInfo mirroredScreenInfo_;
121     float mirrorAdaptiveCoefficient_ = 1.0f;
122     std::shared_ptr<RSBaseRenderEngine> renderEngine_;
123     Drawing::Matrix screenTransformMatrix_;
124     Drawing::Matrix mirrorAdaptiveMatrix_;
125     BufferRequestConfig renderFrameConfig_ {};
126     bool isSecurityDisplay_ = false;
127     bool displayHasSecSurface_ = false;
128     bool isMirror_ = false;
129 };
130 } // namespace Rosen
131 } // namespace OHOS
132 #endif // RS_CORE_PIPELINE_PROCESSOR_H
133