• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
54       private:
55         void cleanDisplayResources(int64_t display);
56 
57         IComposerHal* mHal;
58         IResourceManager* mResources;
59         const std::shared_ptr<IComposerCallback> mCallback;
60     };
61 
62     // composer3 interface
63     ndk::ScopedAStatus createLayer(int64_t display, int32_t bufferSlotCount,
64                                    int64_t* layer) override;
65     ndk::ScopedAStatus createVirtualDisplay(int32_t width, int32_t height,
66                                             AidlPixelFormat formatHint,
67                                             int32_t outputBufferSlotCount,
68                                             VirtualDisplay* display) override;
69     ndk::ScopedAStatus destroyLayer(int64_t display, int64_t layer) override;
70     ndk::ScopedAStatus destroyVirtualDisplay(int64_t display) override;
71     ndk::ScopedAStatus executeCommands(const std::vector<DisplayCommand>& commands,
72                                        std::vector<CommandResultPayload>* results) override;
73     ndk::ScopedAStatus getActiveConfig(int64_t display, int32_t* config) override;
74     ndk::ScopedAStatus getColorModes(int64_t display, std::vector<ColorMode>* colorModes) override;
75     ndk::ScopedAStatus getDataspaceSaturationMatrix(common::Dataspace dataspace,
76                                                     std::vector<float>* matrix) override;
77     ndk::ScopedAStatus getDisplayAttribute(int64_t display, int32_t config,
78                                            DisplayAttribute attribute, int32_t* value) override;
79     ndk::ScopedAStatus getDisplayCapabilities(int64_t display,
80                                               std::vector<DisplayCapability>* caps) override;
81     ndk::ScopedAStatus getDisplayConfigs(int64_t display, std::vector<int32_t>* configs) override;
82     ndk::ScopedAStatus getDisplayConnectionType(int64_t display,
83                                                 DisplayConnectionType* type) override;
84     ndk::ScopedAStatus getDisplayIdentificationData(int64_t display,
85                                                     DisplayIdentification* id) override;
86     ndk::ScopedAStatus getDisplayName(int64_t display, std::string* name) override;
87     ndk::ScopedAStatus getDisplayVsyncPeriod(int64_t display, int32_t* vsyncPeriod) override;
88     ndk::ScopedAStatus getDisplayedContentSample(int64_t display, int64_t maxFrames,
89                                                  int64_t timestamp,
90                                                  DisplayContentSample* samples) override;
91     ndk::ScopedAStatus getDisplayedContentSamplingAttributes(
92             int64_t display, DisplayContentSamplingAttributes* attrs) override;
93     ndk::ScopedAStatus getDisplayPhysicalOrientation(int64_t display,
94                                                      common::Transform* orientation) override;
95     ndk::ScopedAStatus getHdrCapabilities(int64_t display, HdrCapabilities* caps) override;
96     ndk::ScopedAStatus getOverlaySupport(OverlayProperties* caps) override;
97     ndk::ScopedAStatus getMaxVirtualDisplayCount(int32_t* count) override;
98     ndk::ScopedAStatus getPerFrameMetadataKeys(int64_t display,
99                                                std::vector<PerFrameMetadataKey>* keys) override;
100     ndk::ScopedAStatus getReadbackBufferAttributes(int64_t display,
101                                                    ReadbackBufferAttributes* attrs) override;
102     ndk::ScopedAStatus getReadbackBufferFence(int64_t display,
103                                               ndk::ScopedFileDescriptor* acquireFence) override;
104     ndk::ScopedAStatus getRenderIntents(int64_t display, ColorMode mode,
105                                         std::vector<RenderIntent>* intents) override;
106     ndk::ScopedAStatus getSupportedContentTypes(int64_t display,
107                                                 std::vector<ContentType>* types) override;
108     ndk::ScopedAStatus getDisplayDecorationSupport(
109             int64_t display, std::optional<common::DisplayDecorationSupport>* support) override;
110     ndk::ScopedAStatus registerCallback(
111             const std::shared_ptr<IComposerCallback>& callback) override;
112     ndk::ScopedAStatus setActiveConfig(int64_t display, int32_t config) override;
113     ndk::ScopedAStatus setActiveConfigWithConstraints(
114             int64_t display, int32_t config, const VsyncPeriodChangeConstraints& constraints,
115             VsyncPeriodChangeTimeline* timeline) override;
116     ndk::ScopedAStatus setBootDisplayConfig(int64_t display, int32_t config) override;
117     ndk::ScopedAStatus clearBootDisplayConfig(int64_t display) override;
118     ndk::ScopedAStatus getPreferredBootDisplayConfig(int64_t display, int32_t* config) override;
119     ndk::ScopedAStatus getHdrConversionCapabilities(
120             std::vector<common::HdrConversionCapability>*) override;
121     ndk::ScopedAStatus setHdrConversionStrategy(const common::HdrConversionStrategy&,
122                                                 common::Hdr* preferredHdrOutputType) override;
123     ndk::ScopedAStatus setAutoLowLatencyMode(int64_t display, bool on) override;
124     ndk::ScopedAStatus setClientTargetSlotCount(int64_t display, int32_t count) override;
125     ndk::ScopedAStatus setColorMode(int64_t display, ColorMode mode, RenderIntent intent) override;
126     ndk::ScopedAStatus setContentType(int64_t display, ContentType type) override;
127     ndk::ScopedAStatus setDisplayedContentSamplingEnabled(int64_t display, bool enable,
128                                                           FormatColorComponent componentMask,
129                                                           int64_t maxFrames) override;
130     ndk::ScopedAStatus setPowerMode(int64_t display, PowerMode mode) override;
131     ndk::ScopedAStatus setReadbackBuffer(int64_t display, const AidlNativeHandle& buffer,
132                                          const ndk::ScopedFileDescriptor& releaseFence) override;
133     ndk::ScopedAStatus setVsyncEnabled(int64_t display, bool enabled) override;
134     ndk::ScopedAStatus setIdleTimerEnabled(int64_t display, int32_t timeout) override;
135     ndk::ScopedAStatus setRefreshRateChangedCallbackDebugEnabled(int64_t /* display */,
136                                                                  bool /* enabled */) override;
137 
138 protected:
139     ::ndk::SpAIBinder createBinder() override;
140 
141 private:
142     void destroyResources();
143 
144     IComposerHal* mHal;
145     std::unique_ptr<IResourceManager> mResources;
146     std::function<void()> mOnClientDestroyed;
147     std::unique_ptr<HalEventCallback> mHalEventCallback;
148 };
149 
150 } // namespace aidl::android::hardware::graphics::composer3::impl
151 
152