• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 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 #ifndef LOG_TAG
20 #warning "ComposerClient.h included without LOG_TAG"
21 #endif
22 
23 #include <android/hardware/graphics/composer/2.3/IComposerClient.h>
24 #include <composer-hal/2.3/ComposerCommandEngine.h>
25 #include <composer-hal/2.3/ComposerHal.h>
26 #include <composer-resources/2.2/ComposerResources.h>
27 
28 namespace android {
29 namespace hardware {
30 namespace graphics {
31 namespace composer {
32 namespace V2_3 {
33 namespace hal {
34 
35 namespace detail {
36 
37 // ComposerClientImpl implements V2_*::IComposerClient on top of V2_*::ComposerHal
38 template <typename Interface, typename Hal>
39 class ComposerClientImpl : public V2_2::hal::detail::ComposerClientImpl<Interface, Hal> {
40    public:
getPerFrameMetadataKeys_2_3(Display display,IComposerClient::getPerFrameMetadataKeys_2_3_cb hidl_cb)41     Return<void> getPerFrameMetadataKeys_2_3(
42         Display display, IComposerClient::getPerFrameMetadataKeys_2_3_cb hidl_cb) override {
43         std::vector<IComposerClient::PerFrameMetadataKey> keys;
44         Error error = mHal->getPerFrameMetadataKeys_2_3(display, &keys);
45         hidl_cb(error, keys);
46         return Void();
47     }
48 
setColorMode_2_3(Display display,ColorMode mode,RenderIntent intent)49     Return<Error> setColorMode_2_3(Display display, ColorMode mode, RenderIntent intent) override {
50         return mHal->setColorMode_2_3(display, mode, intent);
51     }
52 
getRenderIntents_2_3(Display display,ColorMode mode,IComposerClient::getRenderIntents_2_3_cb hidl_cb)53     Return<void> getRenderIntents_2_3(Display display, ColorMode mode,
54                                       IComposerClient::getRenderIntents_2_3_cb hidl_cb) override {
55         std::vector<RenderIntent> intents;
56         Error err = mHal->getRenderIntents_2_3(display, mode, &intents);
57         hidl_cb(err, intents);
58         return Void();
59     }
60 
getColorModes_2_3(Display display,IComposerClient::getColorModes_2_3_cb hidl_cb)61     Return<void> getColorModes_2_3(Display display,
62                                    IComposerClient::getColorModes_2_3_cb hidl_cb) override {
63         hidl_vec<ColorMode> modes;
64         Error err = mHal->getColorModes_2_3(display, &modes);
65         hidl_cb(err, modes);
66         return Void();
67     }
68 
getReadbackBufferAttributes_2_3(Display display,IComposerClient::getReadbackBufferAttributes_2_3_cb hidl_cb)69     Return<void> getReadbackBufferAttributes_2_3(
70         Display display, IComposerClient::getReadbackBufferAttributes_2_3_cb hidl_cb) override {
71         PixelFormat format = PixelFormat::RGB_888;
72         Dataspace dataspace = Dataspace::UNKNOWN;
73         Error error = mHal->getReadbackBufferAttributes_2_3(display, &format, &dataspace);
74         hidl_cb(error, format, dataspace);
75         return Void();
76     }
77 
getHdrCapabilities_2_3(Display display,IComposerClient::getHdrCapabilities_2_3_cb hidl_cb)78     Return<void> getHdrCapabilities_2_3(
79         Display display, IComposerClient::getHdrCapabilities_2_3_cb hidl_cb) override {
80         hidl_vec<Hdr> types;
81         float max_lumi = 0.0f;
82         float max_avg_lumi = 0.0f;
83         float min_lumi = 0.0f;
84         Error err =
85             mHal->getHdrCapabilities_2_3(display, &types, &max_lumi, &max_avg_lumi, &min_lumi);
86         hidl_cb(err, types, max_lumi, max_avg_lumi, min_lumi);
87         return Void();
88     }
89 
getClientTargetSupport_2_3(Display display,uint32_t width,uint32_t height,PixelFormat format,Dataspace dataspace)90     Return<Error> getClientTargetSupport_2_3(Display display, uint32_t width, uint32_t height,
91                                              PixelFormat format, Dataspace dataspace) override {
92         Error err = mHal->getClientTargetSupport_2_3(display, width, height, format, dataspace);
93         return err;
94     }
95 
getDisplayCapabilities(Display display,IComposerClient::getDisplayCapabilities_cb hidl_cb)96     Return<void> getDisplayCapabilities(
97         Display display, IComposerClient::getDisplayCapabilities_cb hidl_cb) override {
98         std::vector<IComposerClient::DisplayCapability> capabilities;
99         Error error = mHal->getDisplayCapabilities(display, &capabilities);
100         hidl_cb(error, capabilities);
101         return Void();
102     }
103 
create(Hal * hal)104     static std::unique_ptr<ComposerClientImpl> create(Hal* hal) {
105         auto client = std::make_unique<ComposerClientImpl>(hal);
106         return client->init() ? std::move(client) : nullptr;
107     }
108 
ComposerClientImpl(Hal * hal)109     ComposerClientImpl(Hal* hal) : BaseType2_2(hal) {}
110 
111     // IComposerClient 2.3 interface
112 
getDisplayIdentificationData(Display display,IComposerClient::getDisplayIdentificationData_cb hidl_cb)113     Return<void> getDisplayIdentificationData(
114         Display display, IComposerClient::getDisplayIdentificationData_cb hidl_cb) override {
115         uint8_t port = 0;
116         std::vector<uint8_t> data;
117         Error error = mHal->getDisplayIdentificationData(display, &port, &data);
118         hidl_cb(error, port, data);
119         return Void();
120     }
121 
getDisplayedContentSamplingAttributes(uint64_t display,IComposerClient::getDisplayedContentSamplingAttributes_cb hidl_cb)122     Return<void> getDisplayedContentSamplingAttributes(
123         uint64_t display,
124         IComposerClient::getDisplayedContentSamplingAttributes_cb hidl_cb) override {
125         PixelFormat format;
126         common::V1_2::Dataspace dataspace;
127         hidl_bitfield<IComposerClient::FormatColorComponent> componentMask;
128         Error error =
129             mHal->getDisplayedContentSamplingAttributes(display, format, dataspace, componentMask);
130         hidl_cb(error, format, dataspace, componentMask);
131         return Void();
132     }
133 
setDisplayedContentSamplingEnabled(uint64_t display,IComposerClient::DisplayedContentSampling enable,hidl_bitfield<IComposerClient::FormatColorComponent> componentMask,uint64_t maxFrames)134     Return<Error> setDisplayedContentSamplingEnabled(
135         uint64_t display, IComposerClient::DisplayedContentSampling enable,
136         hidl_bitfield<IComposerClient::FormatColorComponent> componentMask,
137         uint64_t maxFrames) override {
138         return mHal->setDisplayedContentSamplingEnabled(display, enable, componentMask, maxFrames);
139     }
140 
getDisplayedContentSample(uint64_t display,uint64_t maxFrames,uint64_t timestamp,IComposerClient::getDisplayedContentSample_cb hidl_cb)141     Return<void> getDisplayedContentSample(
142         uint64_t display, uint64_t maxFrames, uint64_t timestamp,
143         IComposerClient::getDisplayedContentSample_cb hidl_cb) override {
144         uint64_t frameCount;
145         hidl_vec<uint64_t> sampleComponent0;
146         hidl_vec<uint64_t> sampleComponent1;
147         hidl_vec<uint64_t> sampleComponent2;
148         hidl_vec<uint64_t> sampleComponent3;
149 
150         Error error = mHal->getDisplayedContentSample(display, maxFrames, timestamp, frameCount,
151                                                       sampleComponent0, sampleComponent1,
152                                                       sampleComponent2, sampleComponent3);
153         hidl_cb(error, frameCount, sampleComponent0, sampleComponent1, sampleComponent2,
154                 sampleComponent3);
155         return Void();
156     }
157 
executeCommands_2_3(uint32_t inLength,const hidl_vec<hidl_handle> & inHandles,IComposerClient::executeCommands_2_2_cb hidl_cb)158     Return<void> executeCommands_2_3(uint32_t inLength, const hidl_vec<hidl_handle>& inHandles,
159                                      IComposerClient::executeCommands_2_2_cb hidl_cb) override {
160         std::lock_guard<std::mutex> lock(mCommandEngineMutex);
161         bool outChanged = false;
162         uint32_t outLength = 0;
163         hidl_vec<hidl_handle> outHandles;
164         Error error =
165             mCommandEngine->execute(inLength, inHandles, &outChanged, &outLength, &outHandles);
166 
167         hidl_cb(error, outChanged, outLength, outHandles);
168 
169         mCommandEngine->reset();
170 
171         return Void();
172     }
173 
getDisplayBrightnessSupport(Display display,IComposerClient::getDisplayBrightnessSupport_cb hidl_cb)174     Return<void> getDisplayBrightnessSupport(
175             Display display, IComposerClient::getDisplayBrightnessSupport_cb hidl_cb) override {
176         bool support = false;
177         Error error = mHal->getDisplayBrightnessSupport(display, &support);
178         hidl_cb(error, support);
179         return Void();
180     }
181 
setDisplayBrightness(Display display,float brightness)182     Return<Error> setDisplayBrightness(Display display, float brightness) override {
183         return mHal->setDisplayBrightness(display, brightness);
184     }
185 
186   protected:
187     using BaseType2_1 = V2_1::hal::detail::ComposerClientImpl<Interface, Hal>;
188     using BaseType2_1::mHal;
189     using BaseType2_1::mResources;
createCommandEngine()190     std::unique_ptr<V2_1::hal::ComposerCommandEngine> createCommandEngine() override {
191         return std::make_unique<ComposerCommandEngine>(
192             mHal, static_cast<V2_2::hal::ComposerResources*>(mResources.get()));
193     }
194 
195   private:
196     using BaseType2_2 = V2_2::hal::detail::ComposerClientImpl<Interface, Hal>;
197     using BaseType2_1::mCommandEngine;
198     using BaseType2_1::mCommandEngineMutex;
199 };
200 
201 }  // namespace detail
202 
203 using ComposerClient = detail::ComposerClientImpl<IComposerClient, ComposerHal>;
204 
205 }  // namespace hal
206 }  // namespace V2_3
207 }  // namespace composer
208 }  // namespace graphics
209 }  // namespace hardware
210 }  // namespace android
211