1 /* 2 * Copyright 2020 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 "ComposerCommandEngine.h included without LOG_TAG" 21 #endif 22 23 #include <composer-command-buffer/2.4/ComposerCommandBuffer.h> 24 #include <composer-hal/2.1/ComposerCommandEngine.h> 25 #include <composer-hal/2.3/ComposerCommandEngine.h> 26 #include <composer-hal/2.4/ComposerHal.h> 27 #include <composer-resources/2.2/ComposerResources.h> 28 29 namespace android { 30 namespace hardware { 31 namespace graphics { 32 namespace composer { 33 namespace V2_4 { 34 namespace hal { 35 36 class ComposerCommandEngine : public V2_3::hal::ComposerCommandEngine { 37 public: ComposerCommandEngine(ComposerHal * hal,V2_2::hal::ComposerResources * resources)38 ComposerCommandEngine(ComposerHal* hal, V2_2::hal::ComposerResources* resources) 39 : BaseType2_3(hal, resources), mHal(hal) {} 40 41 protected: createCommandWriter(size_t writerInitialSize)42 std::unique_ptr<V2_1::CommandWriterBase> createCommandWriter( 43 size_t writerInitialSize) override { 44 return std::make_unique<CommandWriterBase>(writerInitialSize); 45 } 46 47 private: 48 using BaseType2_1 = V2_1::hal::ComposerCommandEngine; 49 using BaseType2_3 = V2_3::hal::ComposerCommandEngine; 50 using BaseType2_1::mWriter; 51 executeValidateDisplayInternal()52 V2_1::Error executeValidateDisplayInternal() override { 53 std::vector<Layer> changedLayers; 54 std::vector<IComposerClient::Composition> compositionTypes; 55 uint32_t displayRequestMask = 0x0; 56 std::vector<Layer> requestedLayers; 57 std::vector<uint32_t> requestMasks; 58 IComposerClient::ClientTargetProperty clientTargetProperty{PixelFormat::RGBA_8888, 59 Dataspace::UNKNOWN}; 60 61 auto err = mHal->validateDisplay_2_4(mCurrentDisplay, &changedLayers, &compositionTypes, 62 &displayRequestMask, &requestedLayers, &requestMasks, 63 &clientTargetProperty); 64 mResources->setDisplayMustValidateState(mCurrentDisplay, false); 65 if (err == Error::NONE) { 66 mWriter->setChangedCompositionTypes(changedLayers, compositionTypes); 67 mWriter->setDisplayRequests(displayRequestMask, requestedLayers, requestMasks); 68 getWriter()->setClientTargetProperty(clientTargetProperty); 69 } else { 70 mWriter->setError(getCommandLoc(), static_cast<V2_1::Error>(err)); 71 } 72 return static_cast<V2_1::Error>(err); 73 } 74 getWriter()75 CommandWriterBase* getWriter() { return static_cast<CommandWriterBase*>(mWriter.get()); } 76 executeCommand(V2_1::IComposerClient::Command command,uint16_t length)77 bool executeCommand(V2_1::IComposerClient::Command command, uint16_t length) override { 78 switch (static_cast<IComposerClient::Command>(command)) { 79 case IComposerClient::Command::SET_LAYER_GENERIC_METADATA: 80 return executeSetLayerGenericMetadata(length); 81 default: 82 return BaseType2_3::executeCommand(command, length); 83 } 84 } 85 executeSetLayerGenericMetadata(uint16_t length)86 bool executeSetLayerGenericMetadata(uint16_t length) { 87 // We expect at least two buffer lengths and a mandatory flag 88 if (length < 3) { 89 return false; 90 } 91 92 const uint32_t keySize = read(); 93 std::string key; 94 key.resize(keySize); 95 readBlob(keySize, key.data()); 96 97 const bool mandatory = read(); 98 99 const uint32_t valueSize = read(); 100 std::vector<uint8_t> value(valueSize); 101 readBlob(valueSize, value.data()); 102 103 auto error = mHal->setLayerGenericMetadata(mCurrentDisplay, mCurrentLayer, key, mandatory, 104 value); 105 if (error != Error::NONE) { 106 // The error cast is safe because setLayerGenericMetadata doesn't 107 // return any of the new values added in V2_4::Error 108 mWriter->setError(getCommandLoc(), static_cast<V2_1::Error>(error)); 109 } 110 111 return true; 112 } 113 114 ComposerHal* mHal; 115 }; 116 117 } // namespace hal 118 } // namespace V2_4 119 } // namespace composer 120 } // namespace graphics 121 } // namespace hardware 122 } // namespace android 123