• 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 "DrmPresenter.h"
27 #include "FrameComposer.h"
28 #include "HostConnection.h"
29 
30 namespace aidl::android::hardware::graphics::composer3::impl {
31 
32 class HostFrameComposer : public FrameComposer {
33  public:
34   HostFrameComposer() = default;
35 
36   HostFrameComposer(const HostFrameComposer&) = delete;
37   HostFrameComposer& operator=(const HostFrameComposer&) = delete;
38 
39   HostFrameComposer(HostFrameComposer&&) = delete;
40   HostFrameComposer& operator=(HostFrameComposer&&) = delete;
41 
42   HWC3::Error init() override;
43 
44   HWC3::Error registerOnHotplugCallback(const HotplugCallback& cb) override;
45 
46   HWC3::Error unregisterOnHotplugCallback() override;
47 
48   HWC3::Error onDisplayCreate(Display* display) override;
49 
50   HWC3::Error onDisplayDestroy(Display* display) override;
51 
52   HWC3::Error onDisplayClientTargetSet(Display* display) override;
53 
54   // Determines if this composer can compose the given layers on the given
55   // display and requests changes for layers that can't not be composed.
56   HWC3::Error validateDisplay(Display* display,
57                               DisplayChanges* outChanges) override;
58 
59   // Performs the actual composition of layers and presents the composed result
60   // to the display.
61   HWC3::Error presentDisplay(
62       Display* display, ::android::base::unique_fd* outDisplayFence,
63       std::unordered_map<int64_t, ::android::base::unique_fd>* outLayerFences)
64       override;
65 
66   HWC3::Error onActiveConfigChange(Display* display) override;
67 
getDrmPresenter()68   const DrmPresenter* getDrmPresenter() const override {
69     if (mDrmPresenter) {
70       return &*mDrmPresenter;
71     }
72     return nullptr;
73   }
74 
75  private:
76   HWC3::Error createHostComposerDisplayInfo(Display* display,
77                                             uint32_t hostDisplayId);
78 
79   void post(HostConnection* hostCon, ExtendedRCEncoderContext* rcEnc,
80             buffer_handle_t h);
81 
82   bool mIsMinigbm = false;
83 
84   bool mUseAngle = false;
85 
86   int mSyncDeviceFd = -1;
87 
88   struct HostComposerDisplayInfo {
89     uint32_t hostDisplayId = 0;
90 
91     // Additional per display buffer for the composition result.
92     const native_handle_t* compositionResultBuffer = nullptr;
93 
94     // Drm info for the additional composition result buffer.
95     std::shared_ptr<DrmBuffer> compositionResultDrmBuffer;
96 
97     // Drm info for the displays client target buffer.
98     std::shared_ptr<DrmBuffer> clientTargetDrmBuffer;
99   };
100 
101   std::unordered_map<int64_t, HostComposerDisplayInfo> mDisplayInfos;
102 
103   std::optional<DrmPresenter> mDrmPresenter;
104 };
105 
106 }  // namespace aidl::android::hardware::graphics::composer3::impl
107 
108 #endif
109