1 /* 2 * Copyright 2021 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_HOSTCOMPOSER_H 18 #define ANDROID_HWC_HOSTCOMPOSER_H 19 20 #include "Common.h" 21 #include "Composer.h" 22 #include "DrmPresenter.h" 23 #include "HostConnection.h" 24 25 namespace android { 26 27 class HostComposer : public Composer { 28 public: 29 HostComposer() = default; 30 31 HostComposer(const HostComposer&) = delete; 32 HostComposer& operator=(const HostComposer&) = delete; 33 34 HostComposer(HostComposer&&) = delete; 35 HostComposer& operator=(HostComposer&&) = delete; 36 37 HWC2::Error init(const HotplugCallback& cb) override; 38 39 HWC2::Error createDisplays( 40 Device* device, 41 const AddDisplayToDeviceFunction& addDisplayToDeviceFn) override; 42 43 HWC2::Error createDisplay( 44 Device* device, uint32_t displayId, uint32_t width, uint32_t height, 45 uint32_t dpiX, uint32_t dpiY, uint32_t refreshRateHz, 46 const AddDisplayToDeviceFunction& addDisplayToDeviceFn) override; 47 48 HWC2::Error onDisplayDestroy(Display* display) override; 49 50 HWC2::Error onDisplayClientTargetSet(Display* display) override; 51 52 // Determines if this composer can compose the given layers on the given 53 // display and requests changes for layers that can't not be composed. 54 HWC2::Error validateDisplay( 55 Display* display, std::unordered_map<hwc2_layer_t, HWC2::Composition>* 56 outLayerCompositionChanges) override; 57 58 // Performs the actual composition of layers and presents the composed result 59 // to the display. 60 HWC2::Error presentDisplay(Display* display, 61 int32_t* outPresentFence) override; 62 63 private: 64 HWC2::Error createPrimaryDisplay( 65 Device* device, const AddDisplayToDeviceFunction& addDisplayToDeviceFn); 66 67 HWC2::Error createSecondaryDisplays( 68 Device* device, const AddDisplayToDeviceFunction& addDisplayToDeviceFn); 69 70 HWC2::Error createHostComposerDisplayInfo(Display* display, 71 uint32_t hostDisplayId); 72 73 void post(HostConnection* hostCon, ExtendedRCEncoderContext* rcEnc, 74 buffer_handle_t h); 75 76 bool mIsMinigbm = false; 77 78 int mSyncDeviceFd = -1; 79 80 struct HostComposerDisplayInfo { 81 uint32_t hostDisplayId = 0; 82 83 // Additional per display buffer for the composition result. 84 const native_handle_t* compositionResultBuffer = nullptr; 85 86 // Drm info for the additional composition result buffer. 87 std::unique_ptr<DrmBuffer> compositionResultDrmBuffer; 88 89 // Drm info for the displays client target buffer. 90 std::unique_ptr<DrmBuffer> clientTargetDrmBuffer; 91 }; 92 93 std::unordered_map<hwc2_display_t, HostComposerDisplayInfo> mDisplayInfos; 94 95 DrmPresenter mDrmPresenter; 96 }; 97 98 } // namespace android 99 100 #endif 101