1 /* 2 * Copyright 2019 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 #pragma once 18 19 #ifndef LOG_TAG 20 #warning "ComposerCommandBuffer.h included without LOG_TAG" 21 #endif 22 23 //#define LOG_NDEBUG 0 24 25 #include <android/hardware/graphics/composer/2.4/IComposer.h> 26 #include <android/hardware/graphics/composer/2.4/IComposerClient.h> 27 #include <composer-command-buffer/2.3/ComposerCommandBuffer.h> 28 29 namespace android { 30 namespace hardware { 31 namespace graphics { 32 namespace composer { 33 namespace V2_4 { 34 35 using android::hardware::MessageQueue; 36 using android::hardware::graphics::composer::V2_4::Error; 37 using android::hardware::graphics::composer::V2_4::IComposerClient; 38 39 // This class helps build a command queue. Note that all sizes/lengths are in 40 // units of uint32_t's. 41 class CommandWriterBase : public V2_3::CommandWriterBase { 42 public: 43 static constexpr uint16_t kSetClientTargetPropertyLength = 2; 44 CommandWriterBase(uint32_t initialMaxSize)45 CommandWriterBase(uint32_t initialMaxSize) : V2_3::CommandWriterBase(initialMaxSize) {} 46 setClientTargetProperty(const IComposerClient::ClientTargetProperty & clientTargetProperty)47 void setClientTargetProperty( 48 const IComposerClient::ClientTargetProperty& clientTargetProperty) { 49 beginCommand(IComposerClient::Command::SET_CLIENT_TARGET_PROPERTY, 50 kSetClientTargetPropertyLength); 51 writeSigned(static_cast<int32_t>(clientTargetProperty.pixelFormat)); 52 writeSigned(static_cast<int32_t>(clientTargetProperty.dataspace)); 53 endCommand(); 54 } 55 setLayerGenericMetadata(const hidl_string & key,const bool mandatory,const hidl_vec<uint8_t> & value)56 void setLayerGenericMetadata(const hidl_string& key, const bool mandatory, 57 const hidl_vec<uint8_t>& value) { 58 const size_t commandSize = 3 + sizeToElements(key.size()) + sizeToElements(value.size()); 59 if (commandSize > std::numeric_limits<uint16_t>::max()) { 60 LOG_FATAL("Too much generic metadata (%zu elements)", commandSize); 61 return; 62 } 63 64 beginCommand(IComposerClient::Command::SET_LAYER_GENERIC_METADATA, 65 static_cast<uint16_t>(commandSize)); 66 write(static_cast<uint32_t>(key.size())); 67 writeBlob(static_cast<uint32_t>(key.size()), 68 reinterpret_cast<const unsigned char*>(key.c_str())); 69 write(mandatory); 70 write(static_cast<uint32_t>(value.size())); 71 writeBlob(static_cast<uint32_t>(value.size()), value.data()); 72 endCommand(); 73 } 74 75 protected: sizeToElements(size_t size)76 uint32_t sizeToElements(size_t size) { return static_cast<uint32_t>((size + 3) / 4); } 77 }; 78 79 // This class helps parse a command queue. Note that all sizes/lengths are in 80 // units of uint32_t's. 81 class CommandReaderBase : public V2_3::CommandReaderBase { 82 public: CommandReaderBase()83 CommandReaderBase() : V2_3::CommandReaderBase() {} 84 }; 85 86 } // namespace V2_4 87 } // namespace composer 88 } // namespace graphics 89 } // namespace hardware 90 } // namespace android 91