blob: 14da1f808fe23f5ccc494a8c57217821475b7ace [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
Chia-I Wu41a1c152017-03-09 15:41:59 -080034class BufferCacheEntry {
Chia-I Wubb61a722016-10-24 15:40:20 +080035public:
Chia-I Wu41a1c152017-03-09 15:41:59 -080036 BufferCacheEntry();
37 BufferCacheEntry(BufferCacheEntry&& other);
Chia-I Wubb61a722016-10-24 15:40:20 +080038
Chia-I Wu41a1c152017-03-09 15:41:59 -080039 BufferCacheEntry(const BufferCacheEntry& other) = delete;
40 BufferCacheEntry& operator=(const BufferCacheEntry& other) = delete;
Chia-I Wubb61a722016-10-24 15:40:20 +080041
Chia-I Wu41a1c152017-03-09 15:41:59 -080042 BufferCacheEntry& operator=(buffer_handle_t handle);
43 ~BufferCacheEntry();
Chia-I Wubb61a722016-10-24 15:40:20 +080044
Chia-I Wu41a1c152017-03-09 15:41:59 -080045 buffer_handle_t getHandle() const { return mHandle; }
Chia-I Wubb61a722016-10-24 15:40:20 +080046
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 {
Chia-I Wu41a1c152017-03-09 15:41:59 -0800111 std::vector<BufferCacheEntry> Buffers;
112 BufferCacheEntry SidebandStream;
Chia-I Wubb61a722016-10-24 15:40:20 +0800113 };
114
115 struct DisplayData {
116 bool IsVirtual;
117
Chia-I Wu41a1c152017-03-09 15:41:59 -0800118 std::vector<BufferCacheEntry> ClientTargets;
119 std::vector<BufferCacheEntry> OutputBuffers;
Chia-I Wubb61a722016-10-24 15:40:20 +0800120
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 };
Chia-I Wu41a1c152017-03-09 15:41:59 -0800170 Error lookupBufferCacheEntryLocked(BufferCache cache, uint32_t slot,
171 BufferCacheEntry** outEntry);
Chia-I Wubb61a722016-10-24 15:40:20 +0800172 Error lookupBuffer(BufferCache cache, uint32_t slot,
Chia-I Wu41a1c152017-03-09 15:41:59 -0800173 bool useCache, buffer_handle_t handle,
174 buffer_handle_t* outHandle);
175 void updateBuffer(BufferCache cache, uint32_t slot,
176 bool useCache, buffer_handle_t handle);
Chia-I Wubb61a722016-10-24 15:40:20 +0800177
Chia-I Wu41a1c152017-03-09 15:41:59 -0800178 Error lookupLayerSidebandStream(buffer_handle_t handle,
179 buffer_handle_t* outHandle)
Chia-I Wubb61a722016-10-24 15:40:20 +0800180 {
181 return lookupBuffer(BufferCache::LAYER_SIDEBAND_STREAMS,
Chia-I Wu41a1c152017-03-09 15:41:59 -0800182 0, false, handle, outHandle);
183 }
184 void updateLayerSidebandStream(buffer_handle_t handle)
185 {
186 updateBuffer(BufferCache::LAYER_SIDEBAND_STREAMS,
Chia-I Wubb61a722016-10-24 15:40:20 +0800187 0, false, handle);
188 }
189
Daniel Nicoara0a60e4b2017-01-09 12:51:06 -0500190 ComposerClient& mClient;
191 ComposerBase& mHal;
Daniel Nicoarabd82b812017-01-17 11:15:26 -0500192 CommandWriterBase& mWriter;
Chia-I Wubb61a722016-10-24 15:40:20 +0800193
194 Display mDisplay;
195 Layer mLayer;
196 };
197
Daniel Nicoara0a60e4b2017-01-09 12:51:06 -0500198 virtual std::unique_ptr<CommandReader> createCommandReader();
199
200 ComposerBase& mHal;
Chia-I Wubb61a722016-10-24 15:40:20 +0800201
202 // 64KiB minus a small space for metadata such as read/write pointers
203 static constexpr size_t kWriterInitialSize =
204 64 * 1024 / sizeof(uint32_t) - 16;
205 std::mutex mCommandMutex;
Daniel Nicoara0a60e4b2017-01-09 12:51:06 -0500206 std::unique_ptr<CommandReader> mReader;
Daniel Nicoarabd82b812017-01-17 11:15:26 -0500207 CommandWriterBase mWriter;
Chia-I Wubb61a722016-10-24 15:40:20 +0800208
209 sp<IComposerCallback> mCallback;
210
211 std::mutex mDisplayDataMutex;
212 std::unordered_map<Display, DisplayData> mDisplayData;
213};
214
215} // namespace implementation
216} // namespace V2_1
217} // namespace composer
218} // namespace graphics
219} // namespace hardware
220} // namespace android
221
Daniel Nicoara0a60e4b2017-01-09 12:51:06 -0500222#endif // ANDROID_HARDWARE_GRAPHICS_COMPOSER_V2_1_COMPOSER_CLIENT_H