Sean Paul | cd36a9e | 2015-01-22 18:01:18 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 17 | #ifndef ANDROID_DRM_HWCOMPOSER_H_ |
| 18 | #define ANDROID_DRM_HWCOMPOSER_H_ |
| 19 | |
Lauri Peltonen | 902c894 | 2015-03-02 19:10:04 +0200 | [diff] [blame] | 20 | #include <stdbool.h> |
| 21 | #include <stdint.h> |
| 22 | |
Rob Herring | cff7b1e | 2018-05-09 15:18:36 -0500 | [diff] [blame] | 23 | #include <vector> |
| 24 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 25 | #include <hardware/hardware.h> |
| 26 | #include <hardware/hwcomposer.h> |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 27 | #include "autofd.h" |
Zach Reizner | 766518e | 2015-10-22 16:34:49 -0700 | [diff] [blame] | 28 | #include "drmhwcgralloc.h" |
| 29 | |
| 30 | struct hwc_import_context; |
| 31 | |
| 32 | int hwc_import_init(struct hwc_import_context **ctx); |
| 33 | int hwc_import_destroy(struct hwc_import_context *ctx); |
| 34 | |
| 35 | int hwc_import_bo_create(int fd, struct hwc_import_context *ctx, |
| 36 | buffer_handle_t buf, struct hwc_drm_bo *bo); |
| 37 | bool hwc_import_bo_release(int fd, struct hwc_import_context *ctx, |
| 38 | struct hwc_drm_bo *bo); |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 39 | |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 40 | namespace android { |
| 41 | |
| 42 | class Importer; |
| 43 | |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 44 | class DrmHwcBuffer { |
| 45 | public: |
| 46 | DrmHwcBuffer() = default; |
| 47 | DrmHwcBuffer(const hwc_drm_bo &bo, Importer *importer) |
| 48 | : bo_(bo), importer_(importer) { |
| 49 | } |
| 50 | DrmHwcBuffer(DrmHwcBuffer &&rhs) : bo_(rhs.bo_), importer_(rhs.importer_) { |
| 51 | rhs.importer_ = NULL; |
| 52 | } |
| 53 | |
| 54 | ~DrmHwcBuffer() { |
| 55 | Clear(); |
| 56 | } |
| 57 | |
| 58 | DrmHwcBuffer &operator=(DrmHwcBuffer &&rhs) { |
| 59 | Clear(); |
| 60 | importer_ = rhs.importer_; |
| 61 | rhs.importer_ = NULL; |
| 62 | bo_ = rhs.bo_; |
| 63 | return *this; |
| 64 | } |
| 65 | |
Zach Reizner | fd6dc33 | 2015-10-13 21:12:48 -0700 | [diff] [blame] | 66 | operator bool() const { |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 67 | return importer_ != NULL; |
| 68 | } |
| 69 | |
Zach Reizner | f99d53f | 2015-10-09 13:02:55 -0700 | [diff] [blame] | 70 | const hwc_drm_bo *operator->() const; |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 71 | |
| 72 | void Clear(); |
| 73 | |
| 74 | int ImportBuffer(buffer_handle_t handle, Importer *importer); |
| 75 | |
| 76 | private: |
| 77 | hwc_drm_bo bo_; |
| 78 | Importer *importer_ = NULL; |
| 79 | }; |
| 80 | |
| 81 | class DrmHwcNativeHandle { |
| 82 | public: |
| 83 | DrmHwcNativeHandle() = default; |
| 84 | |
Andrii Chepurnyi | dc1278c | 2018-03-20 19:41:18 +0200 | [diff] [blame] | 85 | DrmHwcNativeHandle(native_handle_t *handle) : handle_(handle) { |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | DrmHwcNativeHandle(DrmHwcNativeHandle &&rhs) { |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 89 | handle_ = rhs.handle_; |
| 90 | rhs.handle_ = NULL; |
| 91 | } |
| 92 | |
| 93 | ~DrmHwcNativeHandle(); |
| 94 | |
| 95 | DrmHwcNativeHandle &operator=(DrmHwcNativeHandle &&rhs) { |
| 96 | Clear(); |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 97 | handle_ = rhs.handle_; |
| 98 | rhs.handle_ = NULL; |
| 99 | return *this; |
| 100 | } |
| 101 | |
John Stultz | fb3599c | 2018-08-21 11:21:56 -0700 | [diff] [blame] | 102 | int CopyBufferHandle(buffer_handle_t handle, int width, int height, |
| 103 | int layerCount, int format, int usage, int stride); |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 104 | |
| 105 | void Clear(); |
| 106 | |
| 107 | buffer_handle_t get() const { |
| 108 | return handle_; |
| 109 | } |
| 110 | |
| 111 | private: |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 112 | native_handle_t *handle_ = NULL; |
| 113 | }; |
| 114 | |
Sean Paul | 04b47ea | 2015-11-19 21:46:11 -0500 | [diff] [blame] | 115 | enum DrmHwcTransform { |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 116 | kIdentity = 0, |
Sean Paul | 04b47ea | 2015-11-19 21:46:11 -0500 | [diff] [blame] | 117 | kFlipH = 1 << 0, |
| 118 | kFlipV = 1 << 1, |
| 119 | kRotate90 = 1 << 2, |
| 120 | kRotate180 = 1 << 3, |
| 121 | kRotate270 = 1 << 4, |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | enum class DrmHwcBlending : int32_t { |
| 125 | kNone = HWC_BLENDING_NONE, |
| 126 | kPreMult = HWC_BLENDING_PREMULT, |
| 127 | kCoverage = HWC_BLENDING_COVERAGE, |
| 128 | }; |
| 129 | |
| 130 | struct DrmHwcLayer { |
| 131 | buffer_handle_t sf_handle = NULL; |
Zach Reizner | 36d7c6e | 2015-10-20 10:58:19 -0700 | [diff] [blame] | 132 | int gralloc_buffer_usage = 0; |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 133 | DrmHwcBuffer buffer; |
| 134 | DrmHwcNativeHandle handle; |
Sean Paul | 04b47ea | 2015-11-19 21:46:11 -0500 | [diff] [blame] | 135 | uint32_t transform; |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 136 | DrmHwcBlending blending = DrmHwcBlending::kNone; |
Stefan Schake | 025d0a6 | 2018-05-04 18:03:00 +0200 | [diff] [blame] | 137 | uint16_t alpha = 0xffff; |
Rob Herring | cff7b1e | 2018-05-09 15:18:36 -0500 | [diff] [blame] | 138 | hwc_frect_t source_crop; |
| 139 | hwc_rect_t display_frame; |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 140 | |
| 141 | UniqueFd acquire_fence; |
| 142 | OutputFd release_fence; |
| 143 | |
Andrii Chepurnyi | dc1278c | 2018-03-20 19:41:18 +0200 | [diff] [blame] | 144 | int ImportBuffer(Importer *importer); |
Alexandru Gheorghe | b6a675e | 2018-03-27 16:10:55 +0100 | [diff] [blame] | 145 | int InitFromDrmHwcLayer(DrmHwcLayer *layer, Importer *importer); |
Sean Paul | 80b1a5d | 2016-03-10 15:35:13 -0500 | [diff] [blame] | 146 | |
| 147 | void SetTransform(int32_t sf_transform); |
| 148 | void SetSourceCrop(hwc_frect_t const &crop); |
| 149 | void SetDisplayFrame(hwc_rect_t const &frame); |
Zach Reizner | f99d53f | 2015-10-09 13:02:55 -0700 | [diff] [blame] | 150 | |
| 151 | buffer_handle_t get_usable_handle() const { |
| 152 | return handle.get() != NULL ? handle.get() : sf_handle; |
| 153 | } |
Zach Reizner | db81fce | 2015-10-27 16:18:06 -0700 | [diff] [blame] | 154 | |
| 155 | bool protected_usage() const { |
| 156 | return (gralloc_buffer_usage & GRALLOC_USAGE_PROTECTED) == |
| 157 | GRALLOC_USAGE_PROTECTED; |
| 158 | } |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | struct DrmHwcDisplayContents { |
| 162 | OutputFd retire_fence; |
| 163 | std::vector<DrmHwcLayer> layers; |
| 164 | }; |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 165 | } // namespace android |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 166 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 167 | #endif |