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 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 23 | #include <hardware/hardware.h> |
| 24 | #include <hardware/hwcomposer.h> |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 25 | #include "autofd.h" |
Haixia Shi | aa2f4a5 | 2015-11-02 10:54:29 -0800 | [diff] [blame] | 26 | #include "separate_rects.h" |
Zach Reizner | 766518e | 2015-10-22 16:34:49 -0700 | [diff] [blame] | 27 | #include "drmhwcgralloc.h" |
| 28 | |
| 29 | struct hwc_import_context; |
| 30 | |
| 31 | int hwc_import_init(struct hwc_import_context **ctx); |
| 32 | int hwc_import_destroy(struct hwc_import_context *ctx); |
| 33 | |
| 34 | int hwc_import_bo_create(int fd, struct hwc_import_context *ctx, |
| 35 | buffer_handle_t buf, struct hwc_drm_bo *bo); |
| 36 | bool hwc_import_bo_release(int fd, struct hwc_import_context *ctx, |
| 37 | struct hwc_drm_bo *bo); |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 38 | |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 39 | namespace android { |
| 40 | |
| 41 | class Importer; |
| 42 | |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 43 | class DrmHwcBuffer { |
| 44 | public: |
| 45 | DrmHwcBuffer() = default; |
| 46 | DrmHwcBuffer(const hwc_drm_bo &bo, Importer *importer) |
| 47 | : bo_(bo), importer_(importer) { |
| 48 | } |
| 49 | DrmHwcBuffer(DrmHwcBuffer &&rhs) : bo_(rhs.bo_), importer_(rhs.importer_) { |
| 50 | rhs.importer_ = NULL; |
| 51 | } |
| 52 | |
| 53 | ~DrmHwcBuffer() { |
| 54 | Clear(); |
| 55 | } |
| 56 | |
| 57 | DrmHwcBuffer &operator=(DrmHwcBuffer &&rhs) { |
| 58 | Clear(); |
| 59 | importer_ = rhs.importer_; |
| 60 | rhs.importer_ = NULL; |
| 61 | bo_ = rhs.bo_; |
| 62 | return *this; |
| 63 | } |
| 64 | |
Zach Reizner | fd6dc33 | 2015-10-13 21:12:48 -0700 | [diff] [blame] | 65 | operator bool() const { |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 66 | return importer_ != NULL; |
| 67 | } |
| 68 | |
Zach Reizner | f99d53f | 2015-10-09 13:02:55 -0700 | [diff] [blame] | 69 | const hwc_drm_bo *operator->() const; |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 70 | |
| 71 | void Clear(); |
| 72 | |
| 73 | int ImportBuffer(buffer_handle_t handle, Importer *importer); |
| 74 | |
| 75 | private: |
| 76 | hwc_drm_bo bo_; |
| 77 | Importer *importer_ = NULL; |
| 78 | }; |
| 79 | |
| 80 | class DrmHwcNativeHandle { |
| 81 | public: |
| 82 | DrmHwcNativeHandle() = default; |
| 83 | |
Andrii Chepurnyi | dc1278c | 2018-03-20 19:41:18 +0200 | [diff] [blame^] | 84 | DrmHwcNativeHandle(native_handle_t *handle) : handle_(handle) { |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | DrmHwcNativeHandle(DrmHwcNativeHandle &&rhs) { |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 88 | handle_ = rhs.handle_; |
| 89 | rhs.handle_ = NULL; |
| 90 | } |
| 91 | |
| 92 | ~DrmHwcNativeHandle(); |
| 93 | |
| 94 | DrmHwcNativeHandle &operator=(DrmHwcNativeHandle &&rhs) { |
| 95 | Clear(); |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 96 | handle_ = rhs.handle_; |
| 97 | rhs.handle_ = NULL; |
| 98 | return *this; |
| 99 | } |
| 100 | |
Andrii Chepurnyi | dc1278c | 2018-03-20 19:41:18 +0200 | [diff] [blame^] | 101 | int CopyBufferHandle(buffer_handle_t handle); |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 102 | |
| 103 | void Clear(); |
| 104 | |
| 105 | buffer_handle_t get() const { |
| 106 | return handle_; |
| 107 | } |
| 108 | |
| 109 | private: |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 110 | native_handle_t *handle_ = NULL; |
| 111 | }; |
| 112 | |
| 113 | template <typename T> |
Haixia Shi | aa2f4a5 | 2015-11-02 10:54:29 -0800 | [diff] [blame] | 114 | using DrmHwcRect = separate_rects::Rect<T>; |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 115 | |
Sean Paul | 04b47ea | 2015-11-19 21:46:11 -0500 | [diff] [blame] | 116 | enum DrmHwcTransform { |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 117 | kIdentity = 0, |
Sean Paul | 04b47ea | 2015-11-19 21:46:11 -0500 | [diff] [blame] | 118 | kFlipH = 1 << 0, |
| 119 | kFlipV = 1 << 1, |
| 120 | kRotate90 = 1 << 2, |
| 121 | kRotate180 = 1 << 3, |
| 122 | kRotate270 = 1 << 4, |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | enum class DrmHwcBlending : int32_t { |
| 126 | kNone = HWC_BLENDING_NONE, |
| 127 | kPreMult = HWC_BLENDING_PREMULT, |
| 128 | kCoverage = HWC_BLENDING_COVERAGE, |
| 129 | }; |
| 130 | |
| 131 | struct DrmHwcLayer { |
| 132 | buffer_handle_t sf_handle = NULL; |
Zach Reizner | 36d7c6e | 2015-10-20 10:58:19 -0700 | [diff] [blame] | 133 | int gralloc_buffer_usage = 0; |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 134 | DrmHwcBuffer buffer; |
| 135 | DrmHwcNativeHandle handle; |
Sean Paul | 04b47ea | 2015-11-19 21:46:11 -0500 | [diff] [blame] | 136 | uint32_t transform; |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 137 | DrmHwcBlending blending = DrmHwcBlending::kNone; |
Stefan Schake | 025d0a6 | 2018-05-04 18:03:00 +0200 | [diff] [blame] | 138 | uint16_t alpha = 0xffff; |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 139 | DrmHwcRect<float> source_crop; |
| 140 | DrmHwcRect<int> display_frame; |
Zach Reizner | 4a25365 | 2015-09-10 18:30:54 -0700 | [diff] [blame] | 141 | |
| 142 | UniqueFd acquire_fence; |
| 143 | OutputFd release_fence; |
| 144 | |
Andrii Chepurnyi | dc1278c | 2018-03-20 19:41:18 +0200 | [diff] [blame^] | 145 | int ImportBuffer(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 | }; |
| 165 | } |
| 166 | |
Sean Paul | ef8f1f9 | 2015-04-29 16:05:23 -0400 | [diff] [blame] | 167 | #endif |