blob: 8794ec9f9c9dda7161b7b027cbd73518587a5eba [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:
Chia-I Wu69f8fb72018-01-30 12:39:00 -080038 class VrCommandEngine : public ComposerCommandEngine {
Daniel Nicoaraa50abc22017-05-15 10:34:08 -040039 public:
Chia-I Wu69f8fb72018-01-30 12:39:00 -080040 VrCommandEngine(ComposerClientImpl& client);
41 ~VrCommandEngine() override;
Daniel Nicoaraa50abc22017-05-15 10:34:08 -040042
Chia-I Wu69f8fb72018-01-30 12:39:00 -080043 bool executeCommand(IComposerClient::Command command,
44 uint16_t length) override;
Daniel Nicoaraa50abc22017-05-15 10:34:08 -040045
46 private:
Chia-I Wu69f8fb72018-01-30 12:39:00 -080047 bool executeSetLayerInfo(uint16_t length);
48 bool executeSetClientTargetMetadata(uint16_t length);
49 bool executeSetLayerBufferMetadata(uint16_t length);
Daniel Nicoaraa50abc22017-05-15 10:34:08 -040050
51 IVrComposerClient::BufferMetadata readBufferMetadata();
52
53 ComposerClientImpl& mVrClient;
54 android::dvr::VrHwc& mVrHal;
55
Chia-I Wu69f8fb72018-01-30 12:39:00 -080056 VrCommandEngine(const VrCommandEngine&) = delete;
57 void operator=(const VrCommandEngine&) = delete;
Daniel Nicoaraa50abc22017-05-15 10:34:08 -040058 };
59
Chia-I Wu69f8fb72018-01-30 12:39:00 -080060 std::unique_ptr<ComposerCommandEngine> createCommandEngine() override;
Daniel Nicoaraa50abc22017-05-15 10:34:08 -040061
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
Chia-I Wu69f8fb72018-01-30 12:39:00 -080073std::unique_ptr<ComposerCommandEngine>
74ComposerClientImpl::createCommandEngine() {
75 return std::unique_ptr<VrCommandEngine>(new VrCommandEngine(*this));
Daniel Nicoara51a0a562016-12-08 16:48:20 -050076}
77
Chia-I Wu69f8fb72018-01-30 12:39:00 -080078ComposerClientImpl::VrCommandEngine::VrCommandEngine(ComposerClientImpl& client)
79 : ComposerCommandEngine(&client.mHal, client.mResources.get()), mVrClient(client),
80 mVrHal(client.mVrHal) {}
Daniel Nicoara51a0a562016-12-08 16:48:20 -050081
Chia-I Wu69f8fb72018-01-30 12:39:00 -080082ComposerClientImpl::VrCommandEngine::~VrCommandEngine() {}
Daniel Nicoara51a0a562016-12-08 16:48:20 -050083
Chia-I Wu69f8fb72018-01-30 12:39:00 -080084bool ComposerClientImpl::VrCommandEngine::executeCommand(
Daniel Nicoara51a0a562016-12-08 16:48:20 -050085 IComposerClient::Command command, uint16_t length) {
86 IVrComposerClient::VrCommand vrCommand =
87 static_cast<IVrComposerClient::VrCommand>(command);
88 switch (vrCommand) {
89 case IVrComposerClient::VrCommand::SET_LAYER_INFO:
Chia-I Wu69f8fb72018-01-30 12:39:00 -080090 return executeSetLayerInfo(length);
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -040091 case IVrComposerClient::VrCommand::SET_CLIENT_TARGET_METADATA:
Chia-I Wu69f8fb72018-01-30 12:39:00 -080092 return executeSetClientTargetMetadata(length);
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -040093 case IVrComposerClient::VrCommand::SET_LAYER_BUFFER_METADATA:
Chia-I Wu69f8fb72018-01-30 12:39:00 -080094 return executeSetLayerBufferMetadata(length);
Daniel Nicoara51a0a562016-12-08 16:48:20 -050095 default:
Chia-I Wu69f8fb72018-01-30 12:39:00 -080096 return ComposerCommandEngine::executeCommand(command, length);
Daniel Nicoara51a0a562016-12-08 16:48:20 -050097 }
98}
99
Chia-I Wu69f8fb72018-01-30 12:39:00 -0800100bool ComposerClientImpl::VrCommandEngine::executeSetLayerInfo(uint16_t length) {
Daniel Nicoara51a0a562016-12-08 16:48:20 -0500101 if (length != 2) {
102 return false;
103 }
104
Chia-I Wu69f8fb72018-01-30 12:39:00 -0800105 auto err = mVrHal.setLayerInfo(mCurrentDisplay, mCurrentLayer, read(), read());
Daniel Nicoara51a0a562016-12-08 16:48:20 -0500106 if (err != Error::NONE) {
107 mWriter.setError(getCommandLoc(), err);
108 }
109
110 return true;
111}
112
Chia-I Wu69f8fb72018-01-30 12:39:00 -0800113bool ComposerClientImpl::VrCommandEngine::executeSetClientTargetMetadata(
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -0400114 uint16_t length) {
115 if (length != 7)
116 return false;
117
Chia-I Wu69f8fb72018-01-30 12:39:00 -0800118 auto err = mVrHal.setClientTargetMetadata(mCurrentDisplay, readBufferMetadata());
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -0400119 if (err != Error::NONE)
120 mWriter.setError(getCommandLoc(), err);
121
122 return true;
123}
124
Chia-I Wu69f8fb72018-01-30 12:39:00 -0800125bool ComposerClientImpl::VrCommandEngine::executeSetLayerBufferMetadata(
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -0400126 uint16_t length) {
127 if (length != 7)
128 return false;
129
Chia-I Wu69f8fb72018-01-30 12:39:00 -0800130 auto err = mVrHal.setLayerBufferMetadata(mCurrentDisplay, mCurrentLayer,
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -0400131 readBufferMetadata());
132 if (err != Error::NONE)
133 mWriter.setError(getCommandLoc(), err);
134
135 return true;
136}
137
138IVrComposerClient::BufferMetadata
Chia-I Wu69f8fb72018-01-30 12:39:00 -0800139ComposerClientImpl::VrCommandEngine::readBufferMetadata() {
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -0400140 IVrComposerClient::BufferMetadata metadata = {
141 .width = read(),
142 .height = read(),
143 .stride = read(),
144 .layerCount = read(),
145 .format = static_cast<PixelFormat>(readSigned()),
146 .usage = read64(),
147 };
148 return metadata;
149}
150
Daniel Nicoaraa50abc22017-05-15 10:34:08 -0400151} // namespace
152
153VrComposerClient::VrComposerClient(dvr::VrHwc& hal)
154 : client_(new ComposerClientImpl(hal)) {
155 client_->initialize();
156}
157
158VrComposerClient::~VrComposerClient() {}
159
160void VrComposerClient::onHotplug(Display display,
161 IComposerCallback::Connection connected) {
162 client_->onHotplug(display, connected);
163}
164
Daniel Nicoara8fc98222017-08-09 18:10:44 -0400165void VrComposerClient::onRefresh(Display display) {
166 client_->onRefresh(display);
167}
168
Daniel Nicoaraa50abc22017-05-15 10:34:08 -0400169Return<void> VrComposerClient::registerCallback(
170 const sp<IComposerCallback>& callback) {
171 return client_->registerCallback(callback);
172}
173
174Return<uint32_t> VrComposerClient::getMaxVirtualDisplayCount() {
175 return client_->getMaxVirtualDisplayCount();
176}
177
178Return<void> VrComposerClient::createVirtualDisplay(uint32_t width,
179 uint32_t height, PixelFormat formatHint, uint32_t outputBufferSlotCount,
180 createVirtualDisplay_cb hidl_cb) {
181 return client_->createVirtualDisplay(
182 width, height, formatHint, outputBufferSlotCount, hidl_cb);
183}
184
185Return<Error> VrComposerClient::destroyVirtualDisplay(Display display) {
186 return client_->destroyVirtualDisplay(display);
187}
188
189Return<void> VrComposerClient::createLayer(Display display,
190 uint32_t bufferSlotCount, createLayer_cb hidl_cb) {
191 return client_->createLayer(display, bufferSlotCount, hidl_cb);
192}
193
194Return<Error> VrComposerClient::destroyLayer(Display display, Layer layer) {
195 return client_->destroyLayer(display, layer);
196}
197
198Return<void> VrComposerClient::getActiveConfig(Display display,
199 getActiveConfig_cb hidl_cb) {
200 return client_->getActiveConfig(display, hidl_cb);
201}
202
203Return<Error> VrComposerClient::getClientTargetSupport(Display display,
204 uint32_t width, uint32_t height, PixelFormat format, Dataspace dataspace) {
205 return client_->getClientTargetSupport(display, width, height, format,
206 dataspace);
207}
208
209Return<void> VrComposerClient::getColorModes(Display display,
210 getColorModes_cb hidl_cb) {
211 return client_->getColorModes(display, hidl_cb);
212}
213
214Return<void> VrComposerClient::getDisplayAttribute(Display display,
215 Config config, Attribute attribute, getDisplayAttribute_cb hidl_cb) {
216 return client_->getDisplayAttribute(display, config, attribute, hidl_cb);
217}
218
219Return<void> VrComposerClient::getDisplayConfigs(Display display,
220 getDisplayConfigs_cb hidl_cb) {
221 return client_->getDisplayConfigs(display, hidl_cb);
222}
223
224Return<void> VrComposerClient::getDisplayName(Display display,
225 getDisplayName_cb hidl_cb) {
226 return client_->getDisplayName(display, hidl_cb);
227}
228
229Return<void> VrComposerClient::getDisplayType(Display display,
230 getDisplayType_cb hidl_cb) {
231 return client_->getDisplayType(display, hidl_cb);
232}
233
234Return<void> VrComposerClient::getDozeSupport(
235 Display display, getDozeSupport_cb hidl_cb) {
236 return client_->getDozeSupport(display, hidl_cb);
237}
238
239Return<void> VrComposerClient::getHdrCapabilities(
240 Display display, getHdrCapabilities_cb hidl_cb) {
241 return client_->getHdrCapabilities(display, hidl_cb);
242}
243
244Return<Error> VrComposerClient::setActiveConfig(Display display,
245 Config config) {
246 return client_->setActiveConfig(display, config);
247}
248
249Return<Error> VrComposerClient::setColorMode(Display display, ColorMode mode) {
250 return client_->setColorMode(display, mode);
251}
252
253Return<Error> VrComposerClient::setPowerMode(Display display, PowerMode mode) {
254 return client_->setPowerMode(display, mode);
255}
256
257Return<Error> VrComposerClient::setVsyncEnabled(Display display,
258 Vsync enabled) {
259 return client_->setVsyncEnabled(display, enabled);
260}
261
262Return<Error> VrComposerClient::setClientTargetSlotCount(
263 Display display, uint32_t clientTargetSlotCount) {
264 return client_->setClientTargetSlotCount(display, clientTargetSlotCount);
265}
266
267Return<Error> VrComposerClient::setInputCommandQueue(
268 const hardware::MQDescriptorSync<uint32_t>& descriptor) {
269 return client_->setInputCommandQueue(descriptor);
270}
271
272Return<void> VrComposerClient::getOutputCommandQueue(
273 getOutputCommandQueue_cb hidl_cb) {
274 return client_->getOutputCommandQueue(hidl_cb);
275}
276
277Return<void> VrComposerClient::executeCommands(uint32_t inLength,
278 const hidl_vec<hidl_handle>& inHandles, executeCommands_cb hidl_cb) {
279 return client_->executeCommands(inLength, inHandles, hidl_cb);
280}
281
Daniel Nicoara51a0a562016-12-08 16:48:20 -0500282} // namespace dvr
283} // namespace android