• 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_surface_render_node.h"
26 #include "render_thread/rs_base_render_engine.h"
27 
28 namespace OHOS {
29 namespace Rosen {
30 class RSRcdSurfaceRenderNode;
31 #ifdef RS_ENABLE_GPU
32 class RSDisplayRenderParams;
33 #endif
34 class RSSurfaceRenderParams;
35 namespace DrawableV2 {
36 class RSDisplayRenderNodeDrawable;
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(RSDisplayRenderNode& 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 ProcessDisplaySurface(RSDisplayRenderNode& node) = 0;
57     virtual void PostProcess() = 0;
58     virtual void ProcessRcdSurface(RSRcdSurfaceRenderNode& node) = 0;
59 
60     virtual bool InitForRenderThread(DrawableV2::RSDisplayRenderNodeDrawable& displayDrawable, ScreenId mirroredId,
61         std::shared_ptr<RSBaseRenderEngine> renderEngine);
CreateLayerForRenderThread(DrawableV2::RSSurfaceRenderNodeDrawable & surfaceDrawable)62     virtual void CreateLayerForRenderThread(DrawableV2::RSSurfaceRenderNodeDrawable& surfaceDrawable) {}
ProcessDisplaySurfaceForRenderThread(DrawableV2::RSDisplayRenderNodeDrawable & displayDrawable)63     virtual void ProcessDisplaySurfaceForRenderThread(DrawableV2::RSDisplayRenderNodeDrawable& displayDrawable) {}
ProcessSurfaceForRenderThread(DrawableV2::RSSurfaceRenderNodeDrawable & surfaceDrawable)64     virtual void ProcessSurfaceForRenderThread(DrawableV2::RSSurfaceRenderNodeDrawable& surfaceDrawable) {}
ProcessRcdSurfaceForRenderThread(DrawableV2::RSRcdSurfaceRenderNodeDrawable & rcdDrawable)65     virtual void ProcessRcdSurfaceForRenderThread(DrawableV2::RSRcdSurfaceRenderNodeDrawable& rcdDrawable) {}
66 
67     void SetSecurityDisplay(bool isSecurityDisplay);
68     void SetDisplayHasSecSurface(bool displayHasSecSurface);
69 
GetScreenTransformMatrix()70     const Drawing::Matrix& GetScreenTransformMatrix() const
71     {
72         return screenTransformMatrix_;
73     }
74 
75     // type-safe reinterpret_cast
76     template<typename T>
IsInstanceOf()77     bool IsInstanceOf() const
78     {
79         constexpr auto targetType = static_cast<uint32_t>(T::Type);
80         return (static_cast<uint32_t>(GetType()) & targetType) == targetType;
81     }
82     template<typename T>
ReinterpretCast(std::shared_ptr<RSProcessor> processer)83     static std::shared_ptr<T> ReinterpretCast(std::shared_ptr<RSProcessor> processer)
84     {
85         return processer ? processer->ReinterpretCastTo<T>() : nullptr;
86     }
87     template<typename T>
ReinterpretCastTo()88     std::shared_ptr<T> ReinterpretCastTo()
89     {
90         return (IsInstanceOf<T>()) ? std::static_pointer_cast<T>(shared_from_this()) : nullptr;
91     }
92     template<typename T>
ReinterpretCastTo()93     std::shared_ptr<const T> ReinterpretCastTo() const
94     {
95         return (IsInstanceOf<T>()) ? std::static_pointer_cast<const T>(shared_from_this()) : nullptr;
96     }
97 
98 protected:
99     void CalculateMirrorAdaptiveCoefficient(float curWidth, float curHeight,
100         float mirroredWidth, float mirroredHeight);
101     void CalculateScreenTransformMatrix(const RSDisplayRenderNode& node);
102     void SetMirrorScreenSwap(const RSDisplayRenderNode& node);
103     void CalculateMirrorAdaptiveMatrix();
104 
105     void RequestPerf(uint32_t layerLevel, bool onOffTag);
106 #ifdef FRAME_AWARE_TRACE
107     bool FrameAwareTraceBoost(size_t layerNum);
108 #endif
109 
110     ScreenInfo screenInfo_;
111     int32_t offsetX_ = 0;
112     int32_t offsetY_ = 0;
113     ScreenId mirroredId_ = INVALID_SCREEN_ID;
114     ScreenInfo mirroredScreenInfo_;
115     float mirrorAdaptiveCoefficient_ = 1.0f;
116     std::shared_ptr<RSBaseRenderEngine> renderEngine_;
117     Drawing::Matrix screenTransformMatrix_;
118     Drawing::Matrix mirrorAdaptiveMatrix_;
119     BufferRequestConfig renderFrameConfig_ {};
120     bool isSecurityDisplay_ = false;
121     bool displayHasSecSurface_ = false;
122 };
123 } // namespace Rosen
124 } // namespace OHOS
125 #endif // RS_CORE_PIPELINE_PROCESSOR_H
126