Merge "Automatic mk -> bp."
[android/platform-hardware-interfaces.git] / graphics / composer / 2.1 / default / Hwc.h
1 /*
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  */
17 #ifndef ANDROID_HARDWARE_GRAPHICS_COMPOSER_V2_1_HWC_H
18 #define ANDROID_HARDWARE_GRAPHICS_COMPOSER_V2_1_HWC_H
20 #include <atomic>
21 #include <condition_variable>
22 #include <memory>
23 #include <mutex>
24 #include <unordered_set>
25 #include <vector>
27 #include <android/hardware/graphics/composer/2.1/IComposer.h>
28 #define HWC2_INCLUDE_STRINGIFICATION
29 #define HWC2_USE_CPP11
30 #include <hardware/hwcomposer2.h>
31 #undef HWC2_INCLUDE_STRINGIFICATION
32 #undef HWC2_USE_CPP11
33 #include "ComposerBase.h"
35 namespace android {
36     class HWC2On1Adapter;
37     class HWC2OnFbAdapter;
38 }
40 namespace android {
41 namespace hardware {
42 namespace graphics {
43 namespace composer {
44 namespace V2_1 {
45 namespace implementation {
47 using android::hardware::graphics::common::V1_0::PixelFormat;
48 using android::hardware::graphics::common::V1_0::Transform;
49 using android::hardware::graphics::common::V1_0::Dataspace;
50 using android::hardware::graphics::common::V1_0::ColorMode;
51 using android::hardware::graphics::common::V1_0::ColorTransform;
52 using android::hardware::graphics::common::V1_0::Hdr;
54 class ComposerClient;
56 class HwcHal : public IComposer, public ComposerBase {
57 public:
58     HwcHal(const hw_module_t* module);
59     virtual ~HwcHal();
61     bool hasCapability(Capability capability) const;
63     // IComposer interface
64     Return<void> getCapabilities(getCapabilities_cb hidl_cb) override;
65     Return<void> dumpDebugInfo(dumpDebugInfo_cb hidl_cb) override;
66     Return<void> createClient(createClient_cb hidl_cb) override;
68     // ComposerBase interface
69     void removeClient() override;
70     void enableCallback(bool enable) override;
71     uint32_t getMaxVirtualDisplayCount() override;
72     Error createVirtualDisplay(uint32_t width, uint32_t height,
73         PixelFormat* format, Display* outDisplay) override;
74     Error destroyVirtualDisplay(Display display) override;
76     Error createLayer(Display display, Layer* outLayer) override;
77     Error destroyLayer(Display display, Layer layer) override;
79     Error getActiveConfig(Display display, Config* outConfig) override;
80     Error getClientTargetSupport(Display display,
81             uint32_t width, uint32_t height,
82             PixelFormat format, Dataspace dataspace) override;
83     Error getColorModes(Display display,
84             hidl_vec<ColorMode>* outModes) override;
85     Error getDisplayAttribute(Display display, Config config,
86             IComposerClient::Attribute attribute, int32_t* outValue) override;
87     Error getDisplayConfigs(Display display,
88             hidl_vec<Config>* outConfigs) override;
89     Error getDisplayName(Display display, hidl_string* outName) override;
90     Error getDisplayType(Display display,
91             IComposerClient::DisplayType* outType) override;
92     Error getDozeSupport(Display display, bool* outSupport) override;
93     Error getHdrCapabilities(Display display, hidl_vec<Hdr>* outTypes,
94             float* outMaxLuminance, float* outMaxAverageLuminance,
95             float* outMinLuminance) override;
97     Error setActiveConfig(Display display, Config config) override;
98     Error setColorMode(Display display, ColorMode mode) override;
99     Error setPowerMode(Display display,
100             IComposerClient::PowerMode mode) override;
101     Error setVsyncEnabled(Display display,
102             IComposerClient::Vsync enabled) override;
104     Error setColorTransform(Display display, const float* matrix,
105             int32_t hint) override;
106     Error setClientTarget(Display display, buffer_handle_t target,
107             int32_t acquireFence, int32_t dataspace,
108             const std::vector<hwc_rect_t>& damage) override;
109     Error setOutputBuffer(Display display, buffer_handle_t buffer,
110             int32_t releaseFence) override;
111     Error validateDisplay(Display display,
112             std::vector<Layer>* outChangedLayers,
113             std::vector<IComposerClient::Composition>* outCompositionTypes,
114             uint32_t* outDisplayRequestMask,
115             std::vector<Layer>* outRequestedLayers,
116             std::vector<uint32_t>* outRequestMasks) override;
117     Error acceptDisplayChanges(Display display) override;
118     Error presentDisplay(Display display, int32_t* outPresentFence,
119             std::vector<Layer>* outLayers,
120             std::vector<int32_t>* outReleaseFences) override;
122     Error setLayerCursorPosition(Display display, Layer layer,
123             int32_t x, int32_t y) override;
124     Error setLayerBuffer(Display display, Layer layer,
125             buffer_handle_t buffer, int32_t acquireFence) override;
126     Error setLayerSurfaceDamage(Display display, Layer layer,
127             const std::vector<hwc_rect_t>& damage) override;
128     Error setLayerBlendMode(Display display, Layer layer,
129             int32_t mode) override;
130     Error setLayerColor(Display display, Layer layer,
131             IComposerClient::Color color) override;
132     Error setLayerCompositionType(Display display, Layer layer,
133             int32_t type) override;
134     Error setLayerDataspace(Display display, Layer layer,
135             int32_t dataspace) override;
136     Error setLayerDisplayFrame(Display display, Layer layer,
137             const hwc_rect_t& frame) override;
138     Error setLayerPlaneAlpha(Display display, Layer layer,
139             float alpha) override;
140     Error setLayerSidebandStream(Display display, Layer layer,
141             buffer_handle_t stream) override;
142     Error setLayerSourceCrop(Display display, Layer layer,
143             const hwc_frect_t& crop) override;
144     Error setLayerTransform(Display display, Layer layer,
145             int32_t transform) override;
146     Error setLayerVisibleRegion(Display display, Layer layer,
147             const std::vector<hwc_rect_t>& visible) override;
148     Error setLayerZOrder(Display display, Layer layer, uint32_t z) override;
150 private:
151     uint32_t initWithHwc(const hw_module_t* module);
152     uint32_t initWithFb(const hw_module_t* module);
154     void initCapabilities();
156     template<typename T>
157     void initDispatch(hwc2_function_descriptor_t desc, T* outPfn);
158     void initDispatch();
160     sp<ComposerClient> getClient();
162     static void hotplugHook(hwc2_callback_data_t callbackData,
163         hwc2_display_t display, int32_t connected);
164     static void refreshHook(hwc2_callback_data_t callbackData,
165         hwc2_display_t display);
166     static void vsyncHook(hwc2_callback_data_t callbackData,
167         hwc2_display_t display, int64_t timestamp);
169     hwc2_device_t* mDevice;
171     std::unordered_set<Capability> mCapabilities;
173     struct {
174         HWC2_PFN_ACCEPT_DISPLAY_CHANGES acceptDisplayChanges;
175         HWC2_PFN_CREATE_LAYER createLayer;
176         HWC2_PFN_CREATE_VIRTUAL_DISPLAY createVirtualDisplay;
177         HWC2_PFN_DESTROY_LAYER destroyLayer;
178         HWC2_PFN_DESTROY_VIRTUAL_DISPLAY destroyVirtualDisplay;
179         HWC2_PFN_DUMP dump;
180         HWC2_PFN_GET_ACTIVE_CONFIG getActiveConfig;
181         HWC2_PFN_GET_CHANGED_COMPOSITION_TYPES getChangedCompositionTypes;
182         HWC2_PFN_GET_CLIENT_TARGET_SUPPORT getClientTargetSupport;
183         HWC2_PFN_GET_COLOR_MODES getColorModes;
184         HWC2_PFN_GET_DISPLAY_ATTRIBUTE getDisplayAttribute;
185         HWC2_PFN_GET_DISPLAY_CONFIGS getDisplayConfigs;
186         HWC2_PFN_GET_DISPLAY_NAME getDisplayName;
187         HWC2_PFN_GET_DISPLAY_REQUESTS getDisplayRequests;
188         HWC2_PFN_GET_DISPLAY_TYPE getDisplayType;
189         HWC2_PFN_GET_DOZE_SUPPORT getDozeSupport;
190         HWC2_PFN_GET_HDR_CAPABILITIES getHdrCapabilities;
191         HWC2_PFN_GET_MAX_VIRTUAL_DISPLAY_COUNT getMaxVirtualDisplayCount;
192         HWC2_PFN_GET_RELEASE_FENCES getReleaseFences;
193         HWC2_PFN_PRESENT_DISPLAY presentDisplay;
194         HWC2_PFN_REGISTER_CALLBACK registerCallback;
195         HWC2_PFN_SET_ACTIVE_CONFIG setActiveConfig;
196         HWC2_PFN_SET_CLIENT_TARGET setClientTarget;
197         HWC2_PFN_SET_COLOR_MODE setColorMode;
198         HWC2_PFN_SET_COLOR_TRANSFORM setColorTransform;
199         HWC2_PFN_SET_CURSOR_POSITION setCursorPosition;
200         HWC2_PFN_SET_LAYER_BLEND_MODE setLayerBlendMode;
201         HWC2_PFN_SET_LAYER_BUFFER setLayerBuffer;
202         HWC2_PFN_SET_LAYER_COLOR setLayerColor;
203         HWC2_PFN_SET_LAYER_COMPOSITION_TYPE setLayerCompositionType;
204         HWC2_PFN_SET_LAYER_DATASPACE setLayerDataspace;
205         HWC2_PFN_SET_LAYER_DISPLAY_FRAME setLayerDisplayFrame;
206         HWC2_PFN_SET_LAYER_PLANE_ALPHA setLayerPlaneAlpha;
207         HWC2_PFN_SET_LAYER_SIDEBAND_STREAM setLayerSidebandStream;
208         HWC2_PFN_SET_LAYER_SOURCE_CROP setLayerSourceCrop;
209         HWC2_PFN_SET_LAYER_SURFACE_DAMAGE setLayerSurfaceDamage;
210         HWC2_PFN_SET_LAYER_TRANSFORM setLayerTransform;
211         HWC2_PFN_SET_LAYER_VISIBLE_REGION setLayerVisibleRegion;
212         HWC2_PFN_SET_LAYER_Z_ORDER setLayerZOrder;
213         HWC2_PFN_SET_OUTPUT_BUFFER setOutputBuffer;
214         HWC2_PFN_SET_POWER_MODE setPowerMode;
215         HWC2_PFN_SET_VSYNC_ENABLED setVsyncEnabled;
216         HWC2_PFN_VALIDATE_DISPLAY validateDisplay;
217     } mDispatch;
219     std::mutex mClientMutex;
220     std::condition_variable mClientDestroyedWait;
221     wp<ComposerClient> mClient;
223     std::atomic<bool> mMustValidateDisplay;
225     // If the HWC implementation version is < 2.0, use an adapter to interface
226     // between HWC 2.0 <-> HWC 1.X.
227     std::unique_ptr<HWC2On1Adapter> mAdapter;
229     // If there is no HWC implementation, use an adapter to interface between
230     // HWC 2.0 <-> FB HAL.
231     std::unique_ptr<HWC2OnFbAdapter> mFbAdapter;
232 };
234 extern "C" IComposer* HIDL_FETCH_IComposer(const char* name);
236 } // namespace implementation
237 } // namespace V2_1
238 } // namespace composer
239 } // namespace graphics
240 } // namespace hardware
241 } // namespace android
243 #endif  // ANDROID_HARDWARE_GRAPHICS_COMPOSER_V2_1_HWC_H