Daniel Nicoara | 51a0a56 | 2016-12-08 16:48:20 -0500 | [diff] [blame] | 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 | |
Daniel Nicoara | 95a99a1 | 2017-03-21 15:30:45 -0400 | [diff] [blame] | 17 | #include <android/frameworks/vr/composer/1.0/IVrComposerClient.h> |
Daniel Nicoara | 51a0a56 | 2016-12-08 16:48:20 -0500 | [diff] [blame] | 18 | #include <hardware/gralloc.h> |
| 19 | #include <hardware/gralloc1.h> |
| 20 | #include <log/log.h> |
| 21 | |
| 22 | #include "vr_hwc.h" |
| 23 | #include "vr_composer_client.h" |
| 24 | |
| 25 | namespace android { |
| 26 | namespace dvr { |
| 27 | |
| 28 | using android::hardware::graphics::common::V1_0::PixelFormat; |
Daniel Nicoara | 95a99a1 | 2017-03-21 15:30:45 -0400 | [diff] [blame] | 29 | using android::frameworks::vr::composer::V1_0::IVrComposerClient; |
Daniel Nicoara | 51a0a56 | 2016-12-08 16:48:20 -0500 | [diff] [blame] | 30 | |
| 31 | VrComposerClient::VrComposerClient(dvr::VrHwc& hal) |
| 32 | : ComposerClient(hal), mVrHal(hal) {} |
| 33 | |
| 34 | VrComposerClient::~VrComposerClient() {} |
| 35 | |
| 36 | std::unique_ptr<ComposerClient::CommandReader> |
| 37 | VrComposerClient::createCommandReader() { |
| 38 | return std::unique_ptr<CommandReader>(new VrCommandReader(*this)); |
| 39 | } |
| 40 | |
| 41 | VrComposerClient::VrCommandReader::VrCommandReader(VrComposerClient& client) |
| 42 | : CommandReader(client), mVrClient(client), mVrHal(client.mVrHal) {} |
| 43 | |
| 44 | VrComposerClient::VrCommandReader::~VrCommandReader() {} |
| 45 | |
| 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); |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame^] | 53 | case IVrComposerClient::VrCommand::SET_CLIENT_TARGET_METADATA: |
| 54 | return parseSetClientTargetMetadata(length); |
| 55 | case IVrComposerClient::VrCommand::SET_LAYER_BUFFER_METADATA: |
| 56 | return parseSetLayerBufferMetadata(length); |
Daniel Nicoara | 51a0a56 | 2016-12-08 16:48:20 -0500 | [diff] [blame] | 57 | default: |
| 58 | return CommandReader::parseCommand(command, length); |
| 59 | } |
| 60 | } |
| 61 | |
| 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 | |
Daniel Nicoara | 1f42e3a | 2017-04-10 13:27:32 -0400 | [diff] [blame^] | 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 | |
| 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 |
| 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 | |
Daniel Nicoara | 51a0a56 | 2016-12-08 16:48:20 -0500 | [diff] [blame] | 113 | } // namespace dvr |
| 114 | } // namespace android |