1 /*
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
17 #include <android/frameworks/vr/composer/1.0/IVrComposerClient.h>
18 #include <hardware/gralloc.h>
19 #include <hardware/gralloc1.h>
20 #include <log/log.h>
21
22 #include "impl/vr_hwc.h"
23 #include "impl/vr_composer_client.h"
24
25 namespace android {
26 namespace dvr {
27
28 using android::hardware::graphics::common::V1_0::PixelFormat;
29 using android::frameworks::vr::composer::V1_0::IVrComposerClient;
30
VrComposerClient(dvr::VrHwc & hal)31 VrComposerClient::VrComposerClient(dvr::VrHwc& hal)
32 : ComposerClient(hal), mVrHal(hal) {}
33
~VrComposerClient()34 VrComposerClient::~VrComposerClient() {}
35
36 std::unique_ptr<ComposerClient::CommandReader>
createCommandReader()37 VrComposerClient::createCommandReader() {
38 return std::unique_ptr<CommandReader>(new VrCommandReader(*this));
39 }
40
VrCommandReader(VrComposerClient & client)41 VrComposerClient::VrCommandReader::VrCommandReader(VrComposerClient& client)
42 : CommandReader(client), mVrClient(client), mVrHal(client.mVrHal) {}
43
~VrCommandReader()44 VrComposerClient::VrCommandReader::~VrCommandReader() {}
45
parseCommand(IComposerClient::Command command,uint16_t length)46 bool VrComposerClient::VrCommandReader::parseCommand(
47 IComposerClient::Command command, uint16_t length) {
48 IVrComposerClient::VrCommand vrCommand =
49 static_cast<IVrComposerClient::VrCommand>(command);
50 switch (vrCommand) {
51 case IVrComposerClient::VrCommand::SET_LAYER_INFO:
52 return parseSetLayerInfo(length);
53 case IVrComposerClient::VrCommand::SET_CLIENT_TARGET_METADATA:
54 return parseSetClientTargetMetadata(length);
55 case IVrComposerClient::VrCommand::SET_LAYER_BUFFER_METADATA:
56 return parseSetLayerBufferMetadata(length);
57 default:
58 return CommandReader::parseCommand(command, length);
59 }
60 }
61
parseSetLayerInfo(uint16_t length)62 bool VrComposerClient::VrCommandReader::parseSetLayerInfo(uint16_t length) {
63 if (length != 2) {
64 return false;
65 }
66
67 auto err = mVrHal.setLayerInfo(mDisplay, mLayer, read(), read());
68 if (err != Error::NONE) {
69 mWriter.setError(getCommandLoc(), err);
70 }
71
72 return true;
73 }
74
parseSetClientTargetMetadata(uint16_t length)75 bool VrComposerClient::VrCommandReader::parseSetClientTargetMetadata(
76 uint16_t length) {
77 if (length != 7)
78 return false;
79
80 auto err = mVrHal.setClientTargetMetadata(mDisplay, readBufferMetadata());
81 if (err != Error::NONE)
82 mWriter.setError(getCommandLoc(), err);
83
84 return true;
85 }
86
parseSetLayerBufferMetadata(uint16_t length)87 bool VrComposerClient::VrCommandReader::parseSetLayerBufferMetadata(
88 uint16_t length) {
89 if (length != 7)
90 return false;
91
92 auto err = mVrHal.setLayerBufferMetadata(mDisplay, mLayer,
93 readBufferMetadata());
94 if (err != Error::NONE)
95 mWriter.setError(getCommandLoc(), err);
96
97 return true;
98 }
99
100 IVrComposerClient::BufferMetadata
readBufferMetadata()101 VrComposerClient::VrCommandReader::readBufferMetadata() {
102 IVrComposerClient::BufferMetadata metadata = {
103 .width = read(),
104 .height = read(),
105 .stride = read(),
106 .layerCount = read(),
107 .format = static_cast<PixelFormat>(readSigned()),
108 .usage = read64(),
109 };
110 return metadata;
111 }
112
113 } // namespace dvr
114 } // namespace android
115