• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 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.3/ComposerCommandBuffer.h>
24 #include <composer-hal/2.1/ComposerCommandEngine.h>
25 #include <composer-hal/2.2/ComposerCommandEngine.h>
26 #include <composer-hal/2.3/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_3 {
34 namespace hal {
35 
36 class ComposerCommandEngine : public V2_2::hal::ComposerCommandEngine {
37    public:
ComposerCommandEngine(ComposerHal * hal,V2_2::hal::ComposerResources * resources)38     ComposerCommandEngine(ComposerHal* hal, V2_2::hal::ComposerResources* resources)
39         : BaseType2_2(hal, resources), mHal(hal) {}
40 
41    protected:
executeCommand(V2_1::IComposerClient::Command command,uint16_t length)42     bool executeCommand(V2_1::IComposerClient::Command command, uint16_t length) override {
43         switch (static_cast<IComposerClient::Command>(command)) {
44             case IComposerClient::Command::SET_LAYER_COLOR_TRANSFORM:
45                 return executeSetLayerColorTransform(length);
46             case IComposerClient::Command::SET_LAYER_PER_FRAME_METADATA_BLOBS:
47                 return executeSetLayerPerFrameMetadataBlobs(length);
48             default:
49                 return BaseType2_2::executeCommand(command, length);
50         }
51     }
52 
createCommandWriter(size_t writerInitialSize)53     std::unique_ptr<V2_1::CommandWriterBase> createCommandWriter(
54             size_t writerInitialSize) override {
55         return std::make_unique<CommandWriterBase>(writerInitialSize);
56     }
57 
executeSetLayerColorTransform(uint16_t length)58     bool executeSetLayerColorTransform(uint16_t length) {
59         if (length != CommandWriterBase::kSetLayerColorTransformLength) {
60             return false;
61         }
62 
63         float matrix[16];
64         for (int i = 0; i < 16; i++) {
65             matrix[i] = readFloat();
66         }
67         auto err = mHal->setLayerColorTransform(mCurrentDisplay, mCurrentLayer, matrix);
68         if (err != Error::NONE) {
69             mWriter->setError(getCommandLoc(), err);
70         }
71 
72         return true;
73     }
74 
executeSetLayerPerFrameMetadataBlobs(uint16_t length)75     bool executeSetLayerPerFrameMetadataBlobs(uint16_t length) {
76         if (length == 0) {
77             return false;
78         }
79 
80         uint32_t numBlobs = read();
81         length--;
82 
83         std::vector<IComposerClient::PerFrameMetadataBlob> metadata;
84 
85         for (size_t i = 0; i < numBlobs && length >= 2; i++) {
86             IComposerClient::PerFrameMetadataKey key =
87                 static_cast<IComposerClient::PerFrameMetadataKey>(readSigned());
88             uint32_t blobSize = read();
89 
90             length -= 2;
91 
92             if (length * sizeof(uint32_t) < blobSize) {
93                 return false;
94             }
95 
96             metadata.push_back({key, std::vector<uint8_t>()});
97             IComposerClient::PerFrameMetadataBlob& metadataBlob = metadata.back();
98             metadataBlob.blob.resize(blobSize);
99             readBlob(blobSize, metadataBlob.blob.data());
100         }
101         auto err = mHal->setLayerPerFrameMetadataBlobs(mCurrentDisplay, mCurrentLayer, metadata);
102         if (err != Error::NONE) {
103             mWriter->setError(getCommandLoc(), err);
104         }
105         return true;
106     }
107 
readBlob(uint32_t size,void * blob)108     void readBlob(uint32_t size, void* blob) {
109         memcpy(blob, &mData[mDataRead], size);
110         uint32_t numElements = size / sizeof(uint32_t);
111         mDataRead += numElements;
112         mDataRead += (size - numElements * sizeof(uint32_t) != 0) ? 1 : 0;
113     }
114 
115    private:
116     using BaseType2_1 = V2_1::hal::ComposerCommandEngine;
117     using BaseType2_2 = V2_2::hal::ComposerCommandEngine;
118     using BaseType2_1::mWriter;
119 
120     ComposerHal* mHal;
121 };
122 
123 }  // namespace hal
124 }  // namespace V2_3
125 }  // namespace composer
126 }  // namespace graphics
127 }  // namespace hardware
128 }  // namespace android
129