blob: d351cfb788a2bcee22db1451060f077b9088770d [file] [log] [blame]
Chia-I Wubb61a722016-10-24 15:40:20 +08001/*
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
Daniel Nicoara0a60e4b2017-01-09 12:51:06 -050017#ifndef ANDROID_HARDWARE_GRAPHICS_COMPOSER_V2_1_COMPOSER_CLIENT_H
18#define ANDROID_HARDWARE_GRAPHICS_COMPOSER_V2_1_COMPOSER_CLIENT_H
Chia-I Wubb61a722016-10-24 15:40:20 +080019
20#include <mutex>
21#include <unordered_map>
22#include <vector>
23
24#include "Hwc.h"
25#include "IComposerCommandBuffer.h"
26
27namespace android {
28namespace hardware {
29namespace graphics {
30namespace composer {
31namespace V2_1 {
32namespace implementation {
33
34class BufferClone {
35public:
36 BufferClone();
37 BufferClone(BufferClone&& other);
38
39 BufferClone(const BufferClone& other) = delete;
40 BufferClone& operator=(const BufferClone& other) = delete;
41
42 BufferClone& operator=(buffer_handle_t handle);
43 ~BufferClone();
44
45 operator buffer_handle_t() const { return mHandle; }
46
47private:
48 void clear();
49
50 buffer_handle_t mHandle;
51};
52
Daniel Nicoara0a60e4b2017-01-09 12:51:06 -050053class ComposerClient : public IComposerClient {
Chia-I Wubb61a722016-10-24 15:40:20 +080054public:
Daniel Nicoara0a60e4b2017-01-09 12:51:06 -050055 ComposerClient(ComposerBase& hal);
56 virtual ~ComposerClient();
57
58 void initialize();
Chia-I Wubb61a722016-10-24 15:40:20 +080059
60 void onHotplug(Display display, IComposerCallback::Connection connected);
61 void onRefresh(Display display);
62 void onVsync(Display display, int64_t timestamp);
63
64 // IComposerClient interface
65 Return<void> registerCallback(
66 const sp<IComposerCallback>& callback) override;
67 Return<uint32_t> getMaxVirtualDisplayCount() override;
68 Return<void> createVirtualDisplay(uint32_t width, uint32_t height,
69 PixelFormat formatHint, uint32_t outputBufferSlotCount,
70 createVirtualDisplay_cb hidl_cb) override;
71 Return<Error> destroyVirtualDisplay(Display display) override;
72 Return<void> createLayer(Display display, uint32_t bufferSlotCount,
73 createLayer_cb hidl_cb) override;
74 Return<Error> destroyLayer(Display display, Layer layer) override;
75 Return<void> getActiveConfig(Display display,
76 getActiveConfig_cb hidl_cb) override;
77 Return<Error> getClientTargetSupport(Display display,
78 uint32_t width, uint32_t height,
79 PixelFormat format, Dataspace dataspace) override;
80 Return<void> getColorModes(Display display,
81 getColorModes_cb hidl_cb) override;
82 Return<void> getDisplayAttribute(Display display,
83 Config config, Attribute attribute,
84 getDisplayAttribute_cb hidl_cb) override;
85 Return<void> getDisplayConfigs(Display display,
86 getDisplayConfigs_cb hidl_cb) override;
87 Return<void> getDisplayName(Display display,
88 getDisplayName_cb hidl_cb) override;
89 Return<void> getDisplayType(Display display,
90 getDisplayType_cb hidl_cb) override;
91 Return<void> getDozeSupport(Display display,
92 getDozeSupport_cb hidl_cb) override;
93 Return<void> getHdrCapabilities(Display display,
94 getHdrCapabilities_cb hidl_cb) override;
95 Return<Error> setActiveConfig(Display display, Config config) override;
96 Return<Error> setColorMode(Display display, ColorMode mode) override;
97 Return<Error> setPowerMode(Display display, PowerMode mode) override;
98 Return<Error> setVsyncEnabled(Display display, Vsync enabled) override;
99 Return<Error> setClientTargetSlotCount(Display display,
100 uint32_t clientTargetSlotCount) override;
101 Return<Error> setInputCommandQueue(
Hridya Valsaraju33351da2016-12-27 12:40:01 -0800102 const MQDescriptorSync<uint32_t>& descriptor) override;
Chia-I Wubb61a722016-10-24 15:40:20 +0800103 Return<void> getOutputCommandQueue(
104 getOutputCommandQueue_cb hidl_cb) override;
105 Return<void> executeCommands(uint32_t inLength,
106 const hidl_vec<hidl_handle>& inHandles,
107 executeCommands_cb hidl_cb) override;
108
Daniel Nicoara0a60e4b2017-01-09 12:51:06 -0500109protected:
Chia-I Wubb61a722016-10-24 15:40:20 +0800110 struct LayerBuffers {
111 std::vector<BufferClone> Buffers;
112 BufferClone SidebandStream;
113 };
114
115 struct DisplayData {
116 bool IsVirtual;
117
118 std::vector<BufferClone> ClientTargets;
119 std::vector<BufferClone> OutputBuffers;
120
121 std::unordered_map<Layer, LayerBuffers> Layers;
122
123 DisplayData(bool isVirtual) : IsVirtual(isVirtual) {}
124 };
125
126 class CommandReader : public CommandReaderBase {
127 public:
Daniel Nicoara0a60e4b2017-01-09 12:51:06 -0500128 CommandReader(ComposerClient& client);
129 virtual ~CommandReader();
130
Chia-I Wubb61a722016-10-24 15:40:20 +0800131 Error parse();
132
Daniel Nicoara0a60e4b2017-01-09 12:51:06 -0500133 protected:
134 virtual bool parseCommand(IComposerClient::Command command,
135 uint16_t length);
136
Chia-I Wubb61a722016-10-24 15:40:20 +0800137 bool parseSelectDisplay(uint16_t length);
138 bool parseSelectLayer(uint16_t length);
139 bool parseSetColorTransform(uint16_t length);
140 bool parseSetClientTarget(uint16_t length);
141 bool parseSetOutputBuffer(uint16_t length);
142 bool parseValidateDisplay(uint16_t length);
143 bool parseAcceptDisplayChanges(uint16_t length);
144 bool parsePresentDisplay(uint16_t length);
145 bool parseSetLayerCursorPosition(uint16_t length);
146 bool parseSetLayerBuffer(uint16_t length);
147 bool parseSetLayerSurfaceDamage(uint16_t length);
148 bool parseSetLayerBlendMode(uint16_t length);
149 bool parseSetLayerColor(uint16_t length);
150 bool parseSetLayerCompositionType(uint16_t length);
151 bool parseSetLayerDataspace(uint16_t length);
152 bool parseSetLayerDisplayFrame(uint16_t length);
153 bool parseSetLayerPlaneAlpha(uint16_t length);
154 bool parseSetLayerSidebandStream(uint16_t length);
155 bool parseSetLayerSourceCrop(uint16_t length);
156 bool parseSetLayerTransform(uint16_t length);
157 bool parseSetLayerVisibleRegion(uint16_t length);
158 bool parseSetLayerZOrder(uint16_t length);
159
160 hwc_rect_t readRect();
161 std::vector<hwc_rect_t> readRegion(size_t count);
162 hwc_frect_t readFRect();
163
164 enum class BufferCache {
165 CLIENT_TARGETS,
166 OUTPUT_BUFFERS,
167 LAYER_BUFFERS,
168 LAYER_SIDEBAND_STREAMS,
169 };
170 Error lookupBuffer(BufferCache cache, uint32_t slot,
171 bool useCache, buffer_handle_t& handle);
172
173 Error lookupLayerSidebandStream(buffer_handle_t& handle)
174 {
175 return lookupBuffer(BufferCache::LAYER_SIDEBAND_STREAMS,
176 0, false, handle);
177 }
178
Daniel Nicoara0a60e4b2017-01-09 12:51:06 -0500179 ComposerClient& mClient;
180 ComposerBase& mHal;
Daniel Nicoarabd82b812017-01-17 11:15:26 -0500181 CommandWriterBase& mWriter;
Chia-I Wubb61a722016-10-24 15:40:20 +0800182
183 Display mDisplay;
184 Layer mLayer;
185 };
186
Daniel Nicoara0a60e4b2017-01-09 12:51:06 -0500187 virtual std::unique_ptr<CommandReader> createCommandReader();
188
189 ComposerBase& mHal;
Chia-I Wubb61a722016-10-24 15:40:20 +0800190
191 // 64KiB minus a small space for metadata such as read/write pointers
192 static constexpr size_t kWriterInitialSize =
193 64 * 1024 / sizeof(uint32_t) - 16;
194 std::mutex mCommandMutex;
Daniel Nicoara0a60e4b2017-01-09 12:51:06 -0500195 std::unique_ptr<CommandReader> mReader;
Daniel Nicoarabd82b812017-01-17 11:15:26 -0500196 CommandWriterBase mWriter;
Chia-I Wubb61a722016-10-24 15:40:20 +0800197
198 sp<IComposerCallback> mCallback;
199
200 std::mutex mDisplayDataMutex;
201 std::unordered_map<Display, DisplayData> mDisplayData;
202};
203
204} // namespace implementation
205} // namespace V2_1
206} // namespace composer
207} // namespace graphics
208} // namespace hardware
209} // namespace android
210
Daniel Nicoara0a60e4b2017-01-09 12:51:06 -0500211#endif // ANDROID_HARDWARE_GRAPHICS_COMPOSER_V2_1_COMPOSER_CLIENT_H