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 <memory> 23 24 #include "impl/vr_hwc.h" 25 #include "impl/vr_composer_client.h" 26 27 namespace android { 28 namespace dvr { 29 30 using android::hardware::graphics::common::V1_0::PixelFormat; 31 using android::frameworks::vr::composer::V1_0::IVrComposerClient; 32 33 VrComposerClient::VrComposerClient(dvr::VrHwc& hal) 34 : ComposerClient(&hal), mVrHal(hal) { 35 if (!init()) { 36 LOG_ALWAYS_FATAL("failed to initialize VrComposerClient"); 37 } 38 } 39 40 VrComposerClient::~VrComposerClient() {} 41 42 std::unique_ptr<ComposerCommandEngine> 43 VrComposerClient::createCommandEngine() { 44 return std::make_unique<VrCommandEngine>(*this); 45 } 46 47 VrComposerClient::VrCommandEngine::VrCommandEngine(VrComposerClient& client) 48 : ComposerCommandEngine(client.mHal, client.mResources.get()), 49 mVrHal(client.mVrHal) {} 50 51 VrComposerClient::VrCommandEngine::~VrCommandEngine() {} 52 53 bool VrComposerClient::VrCommandEngine::executeCommand( 54 IComposerClient::Command command, uint16_t length) { 55 IVrComposerClient::VrCommand vrCommand = 56 static_cast<IVrComposerClient::VrCommand>(command); 57 switch (vrCommand) { 58 case IVrComposerClient::VrCommand::SET_LAYER_INFO: 59 return executeSetLayerInfo(length); 60 case IVrComposerClient::VrCommand::SET_CLIENT_TARGET_METADATA: 61 return executeSetClientTargetMetadata(length); 62 case IVrComposerClient::VrCommand::SET_LAYER_BUFFER_METADATA: 63 return executeSetLayerBufferMetadata(length); 64 default: 65 return ComposerCommandEngine::executeCommand(command, length); 66 } 67 } 68 69 bool VrComposerClient::VrCommandEngine::executeSetLayerInfo(uint16_t length) { 70 if (length != 2) { 71 return false; 72 } 73 74 auto err = mVrHal.setLayerInfo(mCurrentDisplay, mCurrentLayer, read(), read()); 75 if (err != Error::NONE) { 76 mWriter.setError(getCommandLoc(), err); 77 } 78 79 return true; 80 } 81 82 bool VrComposerClient::VrCommandEngine::executeSetClientTargetMetadata( 83 uint16_t length) { 84 if (length != 7) 85 return false; 86 87 auto err = mVrHal.setClientTargetMetadata(mCurrentDisplay, readBufferMetadata()); 88 if (err != Error::NONE) 89 mWriter.setError(getCommandLoc(), err); 90 91 return true; 92 } 93 94 bool VrComposerClient::VrCommandEngine::executeSetLayerBufferMetadata( 95 uint16_t length) { 96 if (length != 7) 97 return false; 98 99 auto err = mVrHal.setLayerBufferMetadata(mCurrentDisplay, mCurrentLayer, 100 readBufferMetadata()); 101 if (err != Error::NONE) 102 mWriter.setError(getCommandLoc(), err); 103 104 return true; 105 } 106 107 IVrComposerClient::BufferMetadata 108 VrComposerClient::VrCommandEngine::readBufferMetadata() { 109 IVrComposerClient::BufferMetadata metadata = { 110 .width = read(), 111 .height = read(), 112 .stride = read(), 113 .layerCount = read(), 114 .format = static_cast<PixelFormat>(readSigned()), 115 .usage = read64(), 116 }; 117 return metadata; 118 } 119 120 } // namespace dvr 121 } // namespace android 122