• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #include <android/hardware/graphics/composer3/ComposerServiceWriter.h>
20 #include <utils/Mutex.h>
21 
22 #include <memory>
23 
24 #include "include/IComposerHal.h"
25 #include "include/IResourceManager.h"
26 
27 namespace aidl::android::hardware::graphics::composer3::impl {
28 
29 class ComposerCommandEngine {
30   public:
ComposerCommandEngine(IComposerHal * hal,IResourceManager * resources)31       ComposerCommandEngine(IComposerHal* hal, IResourceManager* resources)
32             : mHal(hal), mResources(resources) {}
33       int32_t init();
34 
35       int32_t execute(const std::vector<DisplayCommand>& commands,
36                       std::vector<CommandResultPayload>* result);
37 
38       template <typename InputType, typename Functor>
39       void dispatchLayerCommand(int64_t display, int64_t layer, const std::string& funcName,
40                                 const InputType input, const Functor func);
41 
reset()42       void reset() {
43           mWriter->reset();
44       }
45 
46   private:
47       void dispatchDisplayCommand(const DisplayCommand& displayCommand);
48       void dispatchLayerCommand(int64_t display, const LayerCommand& displayCommand);
49 
50       void executeSetColorTransform(int64_t display, const std::vector<float>& matrix);
51       void executeSetClientTarget(int64_t display, const ClientTarget& command);
52       void executeSetDisplayBrightness(uint64_t display, const DisplayBrightness& command);
53       void executeSetOutputBuffer(uint64_t display, const Buffer& buffer);
54       void executeValidateDisplay(int64_t display,
55                                   const std::optional<ClockMonotonicTimestamp> expectedPresentTime);
56       void executePresentOrValidateDisplay(
57               int64_t display, const std::optional<ClockMonotonicTimestamp> expectedPresentTime);
58       void executeAcceptDisplayChanges(int64_t display);
59       int executePresentDisplay(int64_t display);
60 
61       void executeSetLayerCursorPosition(int64_t display, int64_t layer,
62                                          const common::Point& cursorPosition);
63       void executeSetLayerBuffer(int64_t display, int64_t layer, const Buffer& buffer);
64       void executeSetLayerSurfaceDamage(int64_t display, int64_t layer,
65                                         const std::vector<std::optional<common::Rect>>& damage);
66       void executeSetLayerBlendMode(int64_t display, int64_t layer,
67                                     const ParcelableBlendMode& blendMode);
68       void executeSetLayerColor(int64_t display, int64_t layer, const Color& color);
69       void executeSetLayerComposition(int64_t display, int64_t layer,
70                                       const ParcelableComposition& composition);
71       void executeSetLayerDataspace(int64_t display, int64_t layer,
72                                     const ParcelableDataspace& dataspace);
73       void executeSetLayerDisplayFrame(int64_t display, int64_t layer, const common::Rect& rect);
74       void executeSetLayerPlaneAlpha(int64_t display, int64_t layer, const PlaneAlpha& planeAlpha);
75       void executeSetLayerSidebandStream(int64_t display, int64_t layer,
76                                          const AidlNativeHandle& sidebandStream);
77       void executeSetLayerSourceCrop(int64_t display, int64_t layer,
78                                      const common::FRect& sourceCrop);
79       void executeSetLayerTransform(int64_t display, int64_t layer,
80                                     const ParcelableTransform& transform);
81       void executeSetLayerVisibleRegion(
82               int64_t display, int64_t layer,
83               const std::vector<std::optional<common::Rect>>& visibleRegion);
84       void executeSetLayerZOrder(int64_t display, int64_t layer, const ZOrder& zOrder);
85       void executeSetLayerPerFrameMetadata(
86               int64_t display, int64_t layer,
87               const std::vector<std::optional<PerFrameMetadata>>& perFrameMetadata);
88       void executeSetLayerColorTransform(int64_t display, int64_t layer,
89                                          const std::vector<float>& colorTransform);
90       void executeSetLayerPerFrameMetadataBlobs(int64_t display, int64_t layer,
91               const std::vector<std::optional<PerFrameMetadataBlob>>& perFrameMetadataBlob);
92       void executeSetLayerBrightness(int64_t display, int64_t layer,
93                                      const LayerBrightness& brightness);
94 
95       int32_t executeValidateDisplayInternal(int64_t display);
96       void executeSetExpectedPresentTimeInternal(
97               int64_t display, const std::optional<ClockMonotonicTimestamp> expectedPresentTime);
98 
99       IComposerHal* mHal;
100       IResourceManager* mResources;
101       std::unique_ptr<ComposerServiceWriter> mWriter;
102       int32_t mCommandIndex;
103 };
104 
105 template <typename InputType, typename Functor>
dispatchLayerCommand(int64_t display,int64_t layer,const std::string & funcName,const InputType input,const Functor func)106 void ComposerCommandEngine::dispatchLayerCommand(int64_t display, int64_t layer,
107                                                  const std::string& funcName, const InputType input,
108                                                  const Functor func) {
109     if (input) {
110         auto err = (mHal->*func)(display, layer, *input);
111         if (err) {
112             LOG(ERROR) << funcName << ": err " << err;
113             mWriter->setError(mCommandIndex, err);
114         }
115     }
116 };
117 
118 } // namespace aidl::android::hardware::graphics::composer3::impl
119 
120