blob: a9bc4cd3385d826f2a57fac0810699852ba45cd2 [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
17#ifndef ANDROID_HARDWARE_GRAPHICS_COMPOSER_V2_1_HWC_CLIENT_H
18#define ANDROID_HARDWARE_GRAPHICS_COMPOSER_V2_1_HWC_CLIENT_H
19
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
53class HwcClient : public IComposerClient {
54public:
55 HwcClient(HwcHal& hal);
56 virtual ~HwcClient();
57
58 void onHotplug(Display display, IComposerCallback::Connection connected);
59 void onRefresh(Display display);
60 void onVsync(Display display, int64_t timestamp);
61
62 // IComposerClient interface
63 Return<void> registerCallback(
64 const sp<IComposerCallback>& callback) override;
65 Return<uint32_t> getMaxVirtualDisplayCount() override;
66 Return<void> createVirtualDisplay(uint32_t width, uint32_t height,
67 PixelFormat formatHint, uint32_t outputBufferSlotCount,
68 createVirtualDisplay_cb hidl_cb) override;
69 Return<Error> destroyVirtualDisplay(Display display) override;
70 Return<void> createLayer(Display display, uint32_t bufferSlotCount,
71 createLayer_cb hidl_cb) override;
72 Return<Error> destroyLayer(Display display, Layer layer) override;
73 Return<void> getActiveConfig(Display display,
74 getActiveConfig_cb hidl_cb) override;
75 Return<Error> getClientTargetSupport(Display display,
76 uint32_t width, uint32_t height,
77 PixelFormat format, Dataspace dataspace) override;
78 Return<void> getColorModes(Display display,
79 getColorModes_cb hidl_cb) override;
80 Return<void> getDisplayAttribute(Display display,
81 Config config, Attribute attribute,
82 getDisplayAttribute_cb hidl_cb) override;
83 Return<void> getDisplayConfigs(Display display,
84 getDisplayConfigs_cb hidl_cb) override;
85 Return<void> getDisplayName(Display display,
86 getDisplayName_cb hidl_cb) override;
87 Return<void> getDisplayType(Display display,
88 getDisplayType_cb hidl_cb) override;
89 Return<void> getDozeSupport(Display display,
90 getDozeSupport_cb hidl_cb) override;
91 Return<void> getHdrCapabilities(Display display,
92 getHdrCapabilities_cb hidl_cb) override;
93 Return<Error> setActiveConfig(Display display, Config config) override;
94 Return<Error> setColorMode(Display display, ColorMode mode) override;
95 Return<Error> setPowerMode(Display display, PowerMode mode) override;
96 Return<Error> setVsyncEnabled(Display display, Vsync enabled) override;
97 Return<Error> setClientTargetSlotCount(Display display,
98 uint32_t clientTargetSlotCount) override;
99 Return<Error> setInputCommandQueue(
100 const MQDescriptorSync& descriptor) override;
101 Return<void> getOutputCommandQueue(
102 getOutputCommandQueue_cb hidl_cb) override;
103 Return<void> executeCommands(uint32_t inLength,
104 const hidl_vec<hidl_handle>& inHandles,
105 executeCommands_cb hidl_cb) override;
106
107private:
108 struct LayerBuffers {
109 std::vector<BufferClone> Buffers;
110 BufferClone SidebandStream;
111 };
112
113 struct DisplayData {
114 bool IsVirtual;
115
116 std::vector<BufferClone> ClientTargets;
117 std::vector<BufferClone> OutputBuffers;
118
119 std::unordered_map<Layer, LayerBuffers> Layers;
120
121 DisplayData(bool isVirtual) : IsVirtual(isVirtual) {}
122 };
123
124 class CommandReader : public CommandReaderBase {
125 public:
126 CommandReader(HwcClient& client);
127 Error parse();
128
129 private:
130 bool parseSelectDisplay(uint16_t length);
131 bool parseSelectLayer(uint16_t length);
132 bool parseSetColorTransform(uint16_t length);
133 bool parseSetClientTarget(uint16_t length);
134 bool parseSetOutputBuffer(uint16_t length);
135 bool parseValidateDisplay(uint16_t length);
136 bool parseAcceptDisplayChanges(uint16_t length);
137 bool parsePresentDisplay(uint16_t length);
138 bool parseSetLayerCursorPosition(uint16_t length);
139 bool parseSetLayerBuffer(uint16_t length);
140 bool parseSetLayerSurfaceDamage(uint16_t length);
141 bool parseSetLayerBlendMode(uint16_t length);
142 bool parseSetLayerColor(uint16_t length);
143 bool parseSetLayerCompositionType(uint16_t length);
144 bool parseSetLayerDataspace(uint16_t length);
145 bool parseSetLayerDisplayFrame(uint16_t length);
146 bool parseSetLayerPlaneAlpha(uint16_t length);
147 bool parseSetLayerSidebandStream(uint16_t length);
148 bool parseSetLayerSourceCrop(uint16_t length);
149 bool parseSetLayerTransform(uint16_t length);
150 bool parseSetLayerVisibleRegion(uint16_t length);
151 bool parseSetLayerZOrder(uint16_t length);
152
153 hwc_rect_t readRect();
154 std::vector<hwc_rect_t> readRegion(size_t count);
155 hwc_frect_t readFRect();
156
157 enum class BufferCache {
158 CLIENT_TARGETS,
159 OUTPUT_BUFFERS,
160 LAYER_BUFFERS,
161 LAYER_SIDEBAND_STREAMS,
162 };
163 Error lookupBuffer(BufferCache cache, uint32_t slot,
164 bool useCache, buffer_handle_t& handle);
165
166 Error lookupLayerSidebandStream(buffer_handle_t& handle)
167 {
168 return lookupBuffer(BufferCache::LAYER_SIDEBAND_STREAMS,
169 0, false, handle);
170 }
171
172 HwcClient& mClient;
173 HwcHal& mHal;
174 CommandWriter& mWriter;
175
176 Display mDisplay;
177 Layer mLayer;
178 };
179
180 HwcHal& mHal;
181
182 // 64KiB minus a small space for metadata such as read/write pointers
183 static constexpr size_t kWriterInitialSize =
184 64 * 1024 / sizeof(uint32_t) - 16;
185 std::mutex mCommandMutex;
186 CommandReader mReader;
187 CommandWriter mWriter;
188
189 sp<IComposerCallback> mCallback;
190
191 std::mutex mDisplayDataMutex;
192 std::unordered_map<Display, DisplayData> mDisplayData;
193};
194
195} // namespace implementation
196} // namespace V2_1
197} // namespace composer
198} // namespace graphics
199} // namespace hardware
200} // namespace android
201
202#endif // ANDROID_HARDWARE_GRAPHICS_COMPOSER_V2_1_HWC_CLIENT_H