• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_HWC_HOSTFRAMECOMPOSER_H
18 #define ANDROID_HWC_HOSTFRAMECOMPOSER_H
19 
20 #include <android-base/unique_fd.h>
21 
22 #include <optional>
23 #include <tuple>
24 
25 #include "Common.h"
26 #include "DrmClient.h"
27 #include "DrmSwapchain.h"
28 #include "FrameComposer.h"
29 #include "HostConnection.h"
30 
31 namespace aidl::android::hardware::graphics::composer3::impl {
32 
33 class HostFrameComposer : public FrameComposer {
34  public:
35   HostFrameComposer() = default;
36 
37   HostFrameComposer(const HostFrameComposer&) = delete;
38   HostFrameComposer& operator=(const HostFrameComposer&) = delete;
39 
40   HostFrameComposer(HostFrameComposer&&) = delete;
41   HostFrameComposer& operator=(HostFrameComposer&&) = delete;
42 
43   HWC3::Error init() override;
44 
45   HWC3::Error registerOnHotplugCallback(const HotplugCallback& cb) override;
46 
47   HWC3::Error unregisterOnHotplugCallback() override;
48 
49   HWC3::Error onDisplayCreate(Display* display) override;
50 
51   HWC3::Error onDisplayDestroy(Display* display) override;
52 
53   HWC3::Error onDisplayClientTargetSet(Display* display) override;
54 
55   // Determines if this composer can compose the given layers on the given
56   // display and requests changes for layers that can't not be composed.
57   HWC3::Error validateDisplay(Display* display,
58                               DisplayChanges* outChanges) override;
59 
60   // Performs the actual composition of layers and presents the composed result
61   // to the display.
62   HWC3::Error presentDisplay(
63       Display* display, ::android::base::unique_fd* outDisplayFence,
64       std::unordered_map<int64_t, ::android::base::unique_fd>* outLayerFences)
65       override;
66 
67   HWC3::Error onActiveConfigChange(Display* display) override;
68 
getDrmPresenter()69   const DrmClient* getDrmPresenter() const override {
70     if (mDrmClient) {
71       return &*mDrmClient;
72     }
73     return nullptr;
74   }
75 
76  private:
77   HWC3::Error createHostComposerDisplayInfo(Display* display,
78                                             uint32_t hostDisplayId);
79 
80   void post(HostConnection* hostCon, ExtendedRCEncoderContext* rcEnc,
81             buffer_handle_t h);
82 
83   bool mIsMinigbm = false;
84 
85   bool mUseAngle = false;
86 
87   int mSyncDeviceFd = -1;
88 
89   struct HostComposerDisplayInfo {
90     uint32_t hostDisplayId = 0;
91     std::unique_ptr<DrmSwapchain> swapchain = {};
92     // Drm info for the displays client target buffer.
93     std::shared_ptr<DrmBuffer> clientTargetDrmBuffer;
94   };
95 
96   std::unordered_map<int64_t, HostComposerDisplayInfo> mDisplayInfos;
97 
98   std::optional<DrmClient> mDrmClient;
99 };
100 
101 }  // namespace aidl::android::hardware::graphics::composer3::impl
102 
103 #endif
104