2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_DRM_HWCOMPOSER_H_
18 #define ANDROID_DRM_HWCOMPOSER_H_
23 #include <hardware/hardware.h>
24 #include <hardware/hwcomposer.h>
25 #include "seperate_rects.h"
27 struct hwc_import_context;
30 /* perform(const struct gralloc_module_t *mod,
33 * buffer_handle_t buffer,
34 * struct hwc_drm_bo *bo);
36 GRALLOC_MODULE_PERFORM_DRM_IMPORT = 0xffeeff00,
38 /* perform(const struct gralloc_module_t *mod,
40 * buffer_handle_t buffer,
41 * void (*free_callback)(void *),
44 GRALLOC_MODULE_PERFORM_SET_IMPORTER_PRIVATE = 0xffeeff01,
46 /* perform(const struct gralloc_module_t *mod,
48 * buffer_handle_t buffer,
49 * void (*free_callback)(void *),
52 GRALLOC_MODULE_PERFORM_GET_IMPORTER_PRIVATE = 0xffeeff02,
55 typedef struct hwc_drm_bo {
58 uint32_t format; /* DRM_FORMAT_* from drm_fourcc.h */
61 uint32_t gem_handles[4];
67 int hwc_import_init(struct hwc_import_context **ctx);
68 int hwc_import_destroy(struct hwc_import_context *ctx);
70 int hwc_import_bo_create(int fd, struct hwc_import_context *ctx,
71 buffer_handle_t buf, struct hwc_drm_bo *bo);
72 bool hwc_import_bo_release(int fd, struct hwc_import_context *ctx,
73 struct hwc_drm_bo *bo);
82 UniqueFd(int fd) : fd_(fd) {
84 UniqueFd(UniqueFd &&rhs) {
89 UniqueFd &operator=(UniqueFd &&rhs) {
127 OutputFd() = default;
128 OutputFd(int *fd) : fd_(fd) {
130 OutputFd(OutputFd &&rhs) {
135 OutputFd &operator=(OutputFd &&rhs);
154 DrmHwcBuffer() = default;
155 DrmHwcBuffer(const hwc_drm_bo &bo, Importer *importer)
156 : bo_(bo), importer_(importer) {
158 DrmHwcBuffer(DrmHwcBuffer &&rhs) : bo_(rhs.bo_), importer_(rhs.importer_) {
159 rhs.importer_ = NULL;
166 DrmHwcBuffer &operator=(DrmHwcBuffer &&rhs) {
168 importer_ = rhs.importer_;
169 rhs.importer_ = NULL;
175 return importer_ != NULL;
178 hwc_drm_bo *operator->();
182 int ImportBuffer(buffer_handle_t handle, Importer *importer);
186 Importer *importer_ = NULL;
189 class DrmHwcNativeHandle {
191 DrmHwcNativeHandle() = default;
193 DrmHwcNativeHandle(const gralloc_module_t *gralloc, native_handle_t *handle)
194 : gralloc_(gralloc), handle_(handle) {
197 DrmHwcNativeHandle(DrmHwcNativeHandle &&rhs) {
198 gralloc_ = rhs.gralloc_;
200 handle_ = rhs.handle_;
204 ~DrmHwcNativeHandle();
206 DrmHwcNativeHandle &operator=(DrmHwcNativeHandle &&rhs) {
208 gralloc_ = rhs.gralloc_;
210 handle_ = rhs.handle_;
215 int CopyBufferHandle(buffer_handle_t handle, const gralloc_module_t *gralloc);
219 buffer_handle_t get() const {
224 const gralloc_module_t *gralloc_ = NULL;
225 native_handle_t *handle_ = NULL;
228 template <typename T>
229 using DrmHwcRect = seperate_rects::Rect<T>;
231 enum class DrmHwcTransform : uint32_t {
233 kFlipH = HWC_TRANSFORM_FLIP_H,
234 kFlipV = HWC_TRANSFORM_FLIP_V,
235 kRotate90 = HWC_TRANSFORM_ROT_90,
236 kRotate180 = HWC_TRANSFORM_ROT_180,
237 kRotate270 = HWC_TRANSFORM_ROT_270,
240 enum class DrmHwcBlending : int32_t {
241 kNone = HWC_BLENDING_NONE,
242 kPreMult = HWC_BLENDING_PREMULT,
243 kCoverage = HWC_BLENDING_COVERAGE,
247 buffer_handle_t sf_handle = NULL;
249 DrmHwcNativeHandle handle;
250 DrmHwcTransform transform = DrmHwcTransform::kIdentity;
251 DrmHwcBlending blending = DrmHwcBlending::kNone;
252 uint8_t alpha = 0xff;
253 DrmHwcRect<float> source_crop;
254 DrmHwcRect<int> display_frame;
255 std::vector<DrmHwcRect<int>> source_damage;
257 UniqueFd acquire_fence;
258 OutputFd release_fence;
260 DrmHwcLayer() = default;
261 DrmHwcLayer(DrmHwcLayer &&rhs) = default;
263 int InitFromHwcLayer(hwc_layer_1_t *sf_layer, Importer *importer,
264 const gralloc_module_t *gralloc);
267 struct DrmHwcDisplayContents {
268 OutputFd retire_fence;
269 std::vector<DrmHwcLayer> layers;