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