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