• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_RS_COMPOSER_ADAPTER_H
17 #define RS_CORE_PIPELINE_RS_COMPOSER_ADAPTER_H
18 
19 #include "hdi_backend.h"
20 
21 #include "pipeline/rs_display_render_node.h"
22 #include "pipeline/rs_surface_render_node.h"
23 #include "screen_manager/rs_screen_manager.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 struct ComposeInfo {
28     IRect srcRect;
29     IRect dstRect;
30     IRect visibleRect;
31     int32_t zOrder { 0 };
32     GraphicLayerAlpha alpha;
33     sptr<SurfaceBuffer> buffer;
34     sptr<SyncFence> fence = SyncFence::INVALID_FENCE;
35     GraphicBlendType blendType;
36     bool needClient;
37 };
38 
39 using FallbackCallback = std::function<void(const sptr<Surface>& surface, const std::vector<LayerInfoPtr>& layers)>;
40 
41 class RSComposerAdapter {
42 public:
43     RSComposerAdapter() = default;
44     ~RSComposerAdapter() noexcept = default;
45 
46     // noncopyable
47     RSComposerAdapter(const RSComposerAdapter&) = delete;
48     void operator=(const RSComposerAdapter&) = delete;
49 
50     bool Init(const ScreenInfo& screenInfo, int32_t offsetX, int32_t offsetY, float mirrorAdaptiveCoefficient,
51         const FallbackCallback& cb);
52 
53     LayerInfoPtr CreateLayer(RSSurfaceRenderNode& node);
54     LayerInfoPtr CreateLayer(RSDisplayRenderNode& node);
55     void CommitLayers(const std::vector<LayerInfoPtr>& layers);
56 
57 private:
58     // check if the node is out of the screen region.
59     bool IsOutOfScreenRegion(const ComposeInfo& info) const;
60     LayerInfoPtr CreateBufferLayer(RSSurfaceRenderNode& node) const;
61     LayerInfoPtr CreateTunnelLayer(RSSurfaceRenderNode& node) const;
62     ComposeInfo BuildComposeInfo(RSSurfaceRenderNode& node, bool isTunnelCheck = false) const;
63     ComposeInfo BuildComposeInfo(RSDisplayRenderNode& node) const;
64     static void SetComposeInfoToLayer(
65         const LayerInfoPtr& layer,
66         const ComposeInfo& info,
67         const sptr<Surface>& surface,
68         RSBaseRenderNode* node);
69     void DealWithNodeGravity(const RSSurfaceRenderNode& node, ComposeInfo& info) const;
70 
71     void LayerRotate(const LayerInfoPtr& layer, RSBaseRenderNode& node) const;
72     void LayerCrop(const LayerInfoPtr& layer) const;
73     static void LayerScaleDown(const LayerInfoPtr& layer);
74     static void LayerPresentTimestamp(const LayerInfoPtr& layer, const sptr<Surface>& surface);
75 
76     void OnPrepareComplete(sptr<Surface>& surface, const PrepareCompleteParam& param, void* data);
77     static void GetComposerInfoSrcRect(ComposeInfo &info, const RSSurfaceRenderNode& node);
78     bool GetComposerInfoNeedClient(const ComposeInfo &info, RSSurfaceRenderNode& node) const;
79     bool CheckStatusBeforeCreateLayer(RSSurfaceRenderNode& node, bool isTunnelCheck = false) const;
80     HdiBackend *hdiBackend_ = nullptr;
81     std::shared_ptr<HdiOutput> output_;
82     ScreenInfo screenInfo_;
83 
84     // The offset on dst screen for all layers.
85     int32_t offsetX_ = 0;
86     int32_t offsetY_ = 0;
87 
88     float mirrorAdaptiveCoefficient_ = 1.0f;
89     FallbackCallback fallbackCb_;
90 };
91 } // namespace Rosen
92 } // namespace OHOS
93 #endif // RS_CORE_PIPELINE_RS_COMPOSER_ADAPTER_H
94