blob: c31417bcc7039133abd1195b6c3a83a6bea24fc2 [file] [log] [blame]
Daniel Nicoara51a0a562016-12-08 16:48:20 -05001/*
2 * Copyright 2016 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
Daniel Nicoara95a99a12017-03-21 15:30:45 -040017#include <android/frameworks/vr/composer/1.0/IVrComposerClient.h>
Daniel Nicoara51a0a562016-12-08 16:48:20 -050018#include <hardware/gralloc.h>
19#include <hardware/gralloc1.h>
20#include <log/log.h>
21
Daniel Nicoara4251e922017-04-13 15:19:15 -040022#include "impl/vr_hwc.h"
23#include "impl/vr_composer_client.h"
Daniel Nicoara51a0a562016-12-08 16:48:20 -050024
25namespace android {
26namespace dvr {
Daniel Nicoaraa50abc22017-05-15 10:34:08 -040027namespace {
Daniel Nicoara51a0a562016-12-08 16:48:20 -050028
29using android::hardware::graphics::common::V1_0::PixelFormat;
Daniel Nicoara95a99a12017-03-21 15:30:45 -040030using android::frameworks::vr::composer::V1_0::IVrComposerClient;
Daniel Nicoara51a0a562016-12-08 16:48:20 -050031
Daniel Nicoaraa50abc22017-05-15 10:34:08 -040032class ComposerClientImpl : public ComposerClient {
33 public:
34 ComposerClientImpl(android::dvr::VrHwc& hal);
35 virtual ~ComposerClientImpl();
36
37 private:
38 class VrCommandReader : public ComposerClient::CommandReader {
39 public:
40 VrCommandReader(ComposerClientImpl& client);
41 ~VrCommandReader() override;
42
43 bool parseCommand(IComposerClient::Command command,
44 uint16_t length) override;
45
46 private:
47 bool parseSetLayerInfo(uint16_t length);
48 bool parseSetClientTargetMetadata(uint16_t length);
49 bool parseSetLayerBufferMetadata(uint16_t length);
50
51 IVrComposerClient::BufferMetadata readBufferMetadata();
52
53 ComposerClientImpl& mVrClient;
54 android::dvr::VrHwc& mVrHal;
55
56 VrCommandReader(const VrCommandReader&) = delete;
57 void operator=(const VrCommandReader&) = delete;
58 };
59
60 std::unique_ptr<CommandReader> createCommandReader() override;
61
62 dvr::VrHwc& mVrHal;
63
64 ComposerClientImpl(const ComposerClientImpl&) = delete;
65 void operator=(const ComposerClientImpl&) = delete;
66};
67
68ComposerClientImpl::ComposerClientImpl(android::dvr::VrHwc& hal)
Daniel Nicoara51a0a562016-12-08 16:48:20 -050069 : ComposerClient(hal), mVrHal(hal) {}
70
Daniel Nicoaraa50abc22017-05-15 10:34:08 -040071ComposerClientImpl::~ComposerClientImpl() {}
Daniel Nicoara51a0a562016-12-08 16:48:20 -050072
73std::unique_ptr<ComposerClient::CommandReader>
Daniel Nicoaraa50abc22017-05-15 10:34:08 -040074ComposerClientImpl::createCommandReader() {
Daniel Nicoara51a0a562016-12-08 16:48:20 -050075 return std::unique_ptr<CommandReader>(new VrCommandReader(*this));
76}
77
Daniel Nicoaraa50abc22017-05-15 10:34:08 -040078ComposerClientImpl::VrCommandReader::VrCommandReader(ComposerClientImpl& client)
Daniel Nicoara51a0a562016-12-08 16:48:20 -050079 : CommandReader(client), mVrClient(client), mVrHal(client.mVrHal) {}
80
Daniel Nicoaraa50abc22017-05-15 10:34:08 -040081ComposerClientImpl::VrCommandReader::~VrCommandReader() {}
Daniel Nicoara51a0a562016-12-08 16:48:20 -050082
Daniel Nicoaraa50abc22017-05-15 10:34:08 -040083bool ComposerClientImpl::VrCommandReader::parseCommand(
Daniel Nicoara51a0a562016-12-08 16:48:20 -050084 IComposerClient::Command command, uint16_t length) {
85 IVrComposerClient::VrCommand vrCommand =
86 static_cast<IVrComposerClient::VrCommand>(command);
87 switch (vrCommand) {
88 case IVrComposerClient::VrCommand::SET_LAYER_INFO:
89 return parseSetLayerInfo(length);
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -040090 case IVrComposerClient::VrCommand::SET_CLIENT_TARGET_METADATA:
91 return parseSetClientTargetMetadata(length);
92 case IVrComposerClient::VrCommand::SET_LAYER_BUFFER_METADATA:
93 return parseSetLayerBufferMetadata(length);
Daniel Nicoara51a0a562016-12-08 16:48:20 -050094 default:
95 return CommandReader::parseCommand(command, length);
96 }
97}
98
Daniel Nicoaraa50abc22017-05-15 10:34:08 -040099bool ComposerClientImpl::VrCommandReader::parseSetLayerInfo(uint16_t length) {
Daniel Nicoara51a0a562016-12-08 16:48:20 -0500100 if (length != 2) {
101 return false;
102 }
103
104 auto err = mVrHal.setLayerInfo(mDisplay, mLayer, read(), read());
105 if (err != Error::NONE) {
106 mWriter.setError(getCommandLoc(), err);
107 }
108
109 return true;
110}
111
Daniel Nicoaraa50abc22017-05-15 10:34:08 -0400112bool ComposerClientImpl::VrCommandReader::parseSetClientTargetMetadata(
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -0400113 uint16_t length) {
114 if (length != 7)
115 return false;
116
117 auto err = mVrHal.setClientTargetMetadata(mDisplay, readBufferMetadata());
118 if (err != Error::NONE)
119 mWriter.setError(getCommandLoc(), err);
120
121 return true;
122}
123
Daniel Nicoaraa50abc22017-05-15 10:34:08 -0400124bool ComposerClientImpl::VrCommandReader::parseSetLayerBufferMetadata(
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -0400125 uint16_t length) {
126 if (length != 7)
127 return false;
128
129 auto err = mVrHal.setLayerBufferMetadata(mDisplay, mLayer,
130 readBufferMetadata());
131 if (err != Error::NONE)
132 mWriter.setError(getCommandLoc(), err);
133
134 return true;
135}
136
137IVrComposerClient::BufferMetadata
Daniel Nicoaraa50abc22017-05-15 10:34:08 -0400138ComposerClientImpl::VrCommandReader::readBufferMetadata() {
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -0400139 IVrComposerClient::BufferMetadata metadata = {
140 .width = read(),
141 .height = read(),
142 .stride = read(),
143 .layerCount = read(),
144 .format = static_cast<PixelFormat>(readSigned()),
145 .usage = read64(),
146 };
147 return metadata;
148}
149
Daniel Nicoaraa50abc22017-05-15 10:34:08 -0400150} // namespace
151
152VrComposerClient::VrComposerClient(dvr::VrHwc& hal)
153 : client_(new ComposerClientImpl(hal)) {
154 client_->initialize();
155}
156
157VrComposerClient::~VrComposerClient() {}
158
159void VrComposerClient::onHotplug(Display display,
160 IComposerCallback::Connection connected) {
161 client_->onHotplug(display, connected);
162}
163
164Return<void> VrComposerClient::registerCallback(
165 const sp<IComposerCallback>& callback) {
166 return client_->registerCallback(callback);
167}
168
169Return<uint32_t> VrComposerClient::getMaxVirtualDisplayCount() {
170 return client_->getMaxVirtualDisplayCount();
171}
172
173Return<void> VrComposerClient::createVirtualDisplay(uint32_t width,
174 uint32_t height, PixelFormat formatHint, uint32_t outputBufferSlotCount,
175 createVirtualDisplay_cb hidl_cb) {
176 return client_->createVirtualDisplay(
177 width, height, formatHint, outputBufferSlotCount, hidl_cb);
178}
179
180Return<Error> VrComposerClient::destroyVirtualDisplay(Display display) {
181 return client_->destroyVirtualDisplay(display);
182}
183
184Return<void> VrComposerClient::createLayer(Display display,
185 uint32_t bufferSlotCount, createLayer_cb hidl_cb) {
186 return client_->createLayer(display, bufferSlotCount, hidl_cb);
187}
188
189Return<Error> VrComposerClient::destroyLayer(Display display, Layer layer) {
190 return client_->destroyLayer(display, layer);
191}
192
193Return<void> VrComposerClient::getActiveConfig(Display display,
194 getActiveConfig_cb hidl_cb) {
195 return client_->getActiveConfig(display, hidl_cb);
196}
197
198Return<Error> VrComposerClient::getClientTargetSupport(Display display,
199 uint32_t width, uint32_t height, PixelFormat format, Dataspace dataspace) {
200 return client_->getClientTargetSupport(display, width, height, format,
201 dataspace);
202}
203
204Return<void> VrComposerClient::getColorModes(Display display,
205 getColorModes_cb hidl_cb) {
206 return client_->getColorModes(display, hidl_cb);
207}
208
209Return<void> VrComposerClient::getDisplayAttribute(Display display,
210 Config config, Attribute attribute, getDisplayAttribute_cb hidl_cb) {
211 return client_->getDisplayAttribute(display, config, attribute, hidl_cb);
212}
213
214Return<void> VrComposerClient::getDisplayConfigs(Display display,
215 getDisplayConfigs_cb hidl_cb) {
216 return client_->getDisplayConfigs(display, hidl_cb);
217}
218
219Return<void> VrComposerClient::getDisplayName(Display display,
220 getDisplayName_cb hidl_cb) {
221 return client_->getDisplayName(display, hidl_cb);
222}
223
224Return<void> VrComposerClient::getDisplayType(Display display,
225 getDisplayType_cb hidl_cb) {
226 return client_->getDisplayType(display, hidl_cb);
227}
228
229Return<void> VrComposerClient::getDozeSupport(
230 Display display, getDozeSupport_cb hidl_cb) {
231 return client_->getDozeSupport(display, hidl_cb);
232}
233
234Return<void> VrComposerClient::getHdrCapabilities(
235 Display display, getHdrCapabilities_cb hidl_cb) {
236 return client_->getHdrCapabilities(display, hidl_cb);
237}
238
239Return<Error> VrComposerClient::setActiveConfig(Display display,
240 Config config) {
241 return client_->setActiveConfig(display, config);
242}
243
244Return<Error> VrComposerClient::setColorMode(Display display, ColorMode mode) {
245 return client_->setColorMode(display, mode);
246}
247
248Return<Error> VrComposerClient::setPowerMode(Display display, PowerMode mode) {
249 return client_->setPowerMode(display, mode);
250}
251
252Return<Error> VrComposerClient::setVsyncEnabled(Display display,
253 Vsync enabled) {
254 return client_->setVsyncEnabled(display, enabled);
255}
256
257Return<Error> VrComposerClient::setClientTargetSlotCount(
258 Display display, uint32_t clientTargetSlotCount) {
259 return client_->setClientTargetSlotCount(display, clientTargetSlotCount);
260}
261
262Return<Error> VrComposerClient::setInputCommandQueue(
263 const hardware::MQDescriptorSync<uint32_t>& descriptor) {
264 return client_->setInputCommandQueue(descriptor);
265}
266
267Return<void> VrComposerClient::getOutputCommandQueue(
268 getOutputCommandQueue_cb hidl_cb) {
269 return client_->getOutputCommandQueue(hidl_cb);
270}
271
272Return<void> VrComposerClient::executeCommands(uint32_t inLength,
273 const hidl_vec<hidl_handle>& inHandles, executeCommands_cb hidl_cb) {
274 return client_->executeCommands(inLength, inHandles, hidl_cb);
275}
276
Daniel Nicoara51a0a562016-12-08 16:48:20 -0500277} // namespace dvr
278} // namespace android