1 /* 2 * Copyright (C) 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 #pragma once 18 19 #include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h> 20 #include <aidl/android/hardware/graphics/composer3/BnComposerClient.h> 21 #include <utils/Mutex.h> 22 23 #include <memory> 24 25 #include "ComposerCommandEngine.h" 26 #include "include/IComposerHal.h" 27 #include "include/IResourceManager.h" 28 29 namespace aidl::android::hardware::graphics::composer3::impl { 30 31 class ComposerClient : public BnComposerClient { 32 public: ComposerClient(IComposerHal * hal)33 ComposerClient(IComposerHal* hal) : mHal(hal) {} 34 virtual ~ComposerClient(); 35 bool init(); setOnClientDestroyed(std::function<void ()> onClientDestroyed)36 void setOnClientDestroyed(std::function<void()> onClientDestroyed) { 37 mOnClientDestroyed = onClientDestroyed; 38 } 39 40 class HalEventCallback : public IComposerHal::EventCallback { 41 public: HalEventCallback(IComposerHal * hal,IResourceManager * resources,const std::shared_ptr<IComposerCallback> & callback)42 HalEventCallback(IComposerHal* hal, IResourceManager* resources, 43 const std::shared_ptr<IComposerCallback>& callback) 44 : mHal(hal), mResources(resources), mCallback(callback) {} 45 void onHotplug(int64_t display, bool connected) override; 46 void onRefresh(int64_t display) override; 47 void onVsync(int64_t display, int64_t timestamp, int32_t vsyncPeriodNanos) override; 48 void onVsyncPeriodTimingChanged(int64_t display, 49 const VsyncPeriodChangeTimeline& timeline) override; 50 void onVsyncIdle(int64_t display) override; 51 void onSeamlessPossible(int64_t display) override; 52 void onRefreshRateChangedDebug(const RefreshRateChangedDebugData& data) override; 53 void onHotplugEvent(int64_t display, common::DisplayHotplugEvent event) override; 54 void onHdcpLevelsChanged(int64_t display, drm::HdcpLevels event) override; 55 56 private: 57 void processDisplayResources(int64_t display, bool connected); 58 void cleanDisplayResources(int64_t display); 59 60 IComposerHal* mHal; 61 IResourceManager* mResources; 62 const std::shared_ptr<IComposerCallback> mCallback; 63 }; 64 65 // composer3 interface 66 ndk::ScopedAStatus createLayer(int64_t display, int32_t bufferSlotCount, 67 int64_t* layer) override; 68 ndk::ScopedAStatus createVirtualDisplay(int32_t width, int32_t height, 69 AidlPixelFormat formatHint, 70 int32_t outputBufferSlotCount, 71 VirtualDisplay* display) override; 72 ndk::ScopedAStatus destroyLayer(int64_t display, int64_t layer) override; 73 ndk::ScopedAStatus destroyVirtualDisplay(int64_t display) override; 74 ndk::ScopedAStatus executeCommands(const std::vector<DisplayCommand>& commands, 75 std::vector<CommandResultPayload>* results) override; 76 ndk::ScopedAStatus getActiveConfig(int64_t display, int32_t* config) override; 77 ndk::ScopedAStatus getColorModes(int64_t display, std::vector<ColorMode>* colorModes) override; 78 ndk::ScopedAStatus getDataspaceSaturationMatrix(common::Dataspace dataspace, 79 std::vector<float>* matrix) override; 80 ndk::ScopedAStatus getDisplayAttribute(int64_t display, int32_t config, 81 DisplayAttribute attribute, int32_t* value) override; 82 ndk::ScopedAStatus getDisplayCapabilities(int64_t display, 83 std::vector<DisplayCapability>* caps) override; 84 ndk::ScopedAStatus getDisplayConfigs(int64_t display, std::vector<int32_t>* configs) override; 85 ndk::ScopedAStatus getDisplayConnectionType(int64_t display, 86 DisplayConnectionType* type) override; 87 ndk::ScopedAStatus getDisplayIdentificationData(int64_t display, 88 DisplayIdentification* id) override; 89 ndk::ScopedAStatus getDisplayName(int64_t display, std::string* name) override; 90 ndk::ScopedAStatus getDisplayVsyncPeriod(int64_t display, int32_t* vsyncPeriod) override; 91 ndk::ScopedAStatus getDisplayedContentSample(int64_t display, int64_t maxFrames, 92 int64_t timestamp, 93 DisplayContentSample* samples) override; 94 ndk::ScopedAStatus getDisplayedContentSamplingAttributes( 95 int64_t display, DisplayContentSamplingAttributes* attrs) override; 96 ndk::ScopedAStatus getDisplayPhysicalOrientation(int64_t display, 97 common::Transform* orientation) override; 98 ndk::ScopedAStatus getHdrCapabilities(int64_t display, HdrCapabilities* caps) override; 99 ndk::ScopedAStatus getOverlaySupport(OverlayProperties* caps) override; 100 ndk::ScopedAStatus getMaxVirtualDisplayCount(int32_t* count) override; 101 ndk::ScopedAStatus getPerFrameMetadataKeys(int64_t display, 102 std::vector<PerFrameMetadataKey>* keys) override; 103 ndk::ScopedAStatus getReadbackBufferAttributes(int64_t display, 104 ReadbackBufferAttributes* attrs) override; 105 ndk::ScopedAStatus getReadbackBufferFence(int64_t display, 106 ndk::ScopedFileDescriptor* acquireFence) override; 107 ndk::ScopedAStatus getRenderIntents(int64_t display, ColorMode mode, 108 std::vector<RenderIntent>* intents) override; 109 ndk::ScopedAStatus getSupportedContentTypes(int64_t display, 110 std::vector<ContentType>* types) override; 111 ndk::ScopedAStatus getDisplayDecorationSupport( 112 int64_t display, std::optional<common::DisplayDecorationSupport>* support) override; 113 ndk::ScopedAStatus registerCallback( 114 const std::shared_ptr<IComposerCallback>& callback) override; 115 ndk::ScopedAStatus setActiveConfig(int64_t display, int32_t config) override; 116 ndk::ScopedAStatus setActiveConfigWithConstraints( 117 int64_t display, int32_t config, const VsyncPeriodChangeConstraints& constraints, 118 VsyncPeriodChangeTimeline* timeline) override; 119 ndk::ScopedAStatus setBootDisplayConfig(int64_t display, int32_t config) override; 120 ndk::ScopedAStatus clearBootDisplayConfig(int64_t display) override; 121 ndk::ScopedAStatus getPreferredBootDisplayConfig(int64_t display, int32_t* config) override; 122 ndk::ScopedAStatus getHdrConversionCapabilities( 123 std::vector<common::HdrConversionCapability>*) override; 124 ndk::ScopedAStatus setHdrConversionStrategy(const common::HdrConversionStrategy&, 125 common::Hdr* preferredHdrOutputType) override; 126 ndk::ScopedAStatus setAutoLowLatencyMode(int64_t display, bool on) override; 127 ndk::ScopedAStatus setClientTargetSlotCount(int64_t display, int32_t count) override; 128 ndk::ScopedAStatus setColorMode(int64_t display, ColorMode mode, RenderIntent intent) override; 129 ndk::ScopedAStatus setContentType(int64_t display, ContentType type) override; 130 ndk::ScopedAStatus setDisplayedContentSamplingEnabled(int64_t display, bool enable, 131 FormatColorComponent componentMask, 132 int64_t maxFrames) override; 133 ndk::ScopedAStatus setPowerMode(int64_t display, PowerMode mode) override; 134 ndk::ScopedAStatus setReadbackBuffer(int64_t display, const AidlNativeHandle& buffer, 135 const ndk::ScopedFileDescriptor& releaseFence) override; 136 ndk::ScopedAStatus setVsyncEnabled(int64_t display, bool enabled) override; 137 ndk::ScopedAStatus setIdleTimerEnabled(int64_t display, int32_t timeout) override; 138 ndk::ScopedAStatus setRefreshRateChangedCallbackDebugEnabled(int64_t /* display */, 139 bool /* enabled */) override; 140 ndk::ScopedAStatus getDisplayConfigurations( 141 int64_t display, int32_t maxFrameIntervalNs, 142 std::vector<DisplayConfiguration>* configs) override; 143 ndk::ScopedAStatus notifyExpectedPresent(int64_t display, 144 const ClockMonotonicTimestamp& expectedPresentTime, 145 int32_t frameIntervalNs) override; 146 ndk::ScopedAStatus getMaxLayerPictureProfiles(int64_t display, 147 int32_t* outMaxProfiles) override; 148 ndk::ScopedAStatus startHdcpNegotiation(int64_t display, 149 const drm::HdcpLevels& levels) override; 150 ndk::ScopedAStatus getLuts(int64_t display, const std::vector<Buffer>&, 151 std::vector<Luts>*) override; 152 153 protected: 154 ::ndk::SpAIBinder createBinder() override; 155 156 private: 157 void destroyResources(); 158 159 IComposerHal* mHal; 160 std::unique_ptr<IResourceManager> mResources; 161 std::function<void()> mOnClientDestroyed; 162 std::unique_ptr<HalEventCallback> mHalEventCallback; 163 }; 164 165 } // namespace aidl::android::hardware::graphics::composer3::impl 166 167