blob: e090dc619e1c29fb2e8e57dd85e0aa68bff0c60e [file] [log] [blame]
Sean Paulcd36a9e2015-01-22 18:01:18 -05001/*
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 Paulef8f1f92015-04-29 16:05:23 -040017#ifndef ANDROID_DRM_HWCOMPOSER_H_
18#define ANDROID_DRM_HWCOMPOSER_H_
19
Roman Stratiienko8666dc92021-02-09 17:49:55 +020020#include <hardware/hardware.h>
21#include <hardware/hwcomposer.h>
Lauri Peltonen902c8942015-03-02 19:10:04 +020022#include <stdbool.h>
23#include <stdint.h>
24
Rob Herringcff7b1e2018-05-09 15:18:36 -050025#include <vector>
26
Zach Reiznerff30b522015-10-28 19:08:45 -070027#include "autofd.h"
Roman Stratiienko8666dc92021-02-09 17:49:55 +020028#include "drm/DrmFbImporter.h"
Zach Reizner766518e2015-10-22 16:34:49 -070029#include "drmhwcgralloc.h"
30
Roman Stratiienko8666dc92021-02-09 17:49:55 +020031class DrmFbIdHandle;
Zach Reizner766518e2015-10-22 16:34:49 -070032struct hwc_import_context;
33
34int hwc_import_init(struct hwc_import_context **ctx);
35int hwc_import_destroy(struct hwc_import_context *ctx);
36
37int hwc_import_bo_create(int fd, struct hwc_import_context *ctx,
38 buffer_handle_t buf, struct hwc_drm_bo *bo);
39bool hwc_import_bo_release(int fd, struct hwc_import_context *ctx,
40 struct hwc_drm_bo *bo);
Sean Paulef8f1f92015-04-29 16:05:23 -040041
Zach Reizner4a253652015-09-10 18:30:54 -070042namespace android {
43
Zach Reizner4a253652015-09-10 18:30:54 -070044class DrmHwcBuffer {
45 public:
46 DrmHwcBuffer() = default;
Roman Stratiienko8666dc92021-02-09 17:49:55 +020047 DrmHwcBuffer(const hwc_drm_bo &bo, DrmDevice *drmDevice)
48 : bo_(bo), mDrmDevice(drmDevice) {
Zach Reizner4a253652015-09-10 18:30:54 -070049 }
Roman Stratiienko8666dc92021-02-09 17:49:55 +020050 DrmHwcBuffer(DrmHwcBuffer &&rhs) : bo_(rhs.bo_), mDrmDevice(rhs.mDrmDevice) {
51 rhs.mDrmDevice = nullptr;
52 FbIdHandle.swap(rhs.FbIdHandle);
Zach Reizner4a253652015-09-10 18:30:54 -070053 }
54
55 ~DrmHwcBuffer() {
Zach Reizner4a253652015-09-10 18:30:54 -070056 }
57
58 DrmHwcBuffer &operator=(DrmHwcBuffer &&rhs) {
Roman Stratiienko8666dc92021-02-09 17:49:55 +020059 FbIdHandle.swap(rhs.FbIdHandle);
60 mDrmDevice = rhs.mDrmDevice;
61 rhs.mDrmDevice = nullptr;
Zach Reizner4a253652015-09-10 18:30:54 -070062 bo_ = rhs.bo_;
63 return *this;
64 }
65
Zach Reiznerfd6dc332015-10-13 21:12:48 -070066 operator bool() const {
Roman Stratiienko8666dc92021-02-09 17:49:55 +020067 return mDrmDevice != NULL;
Zach Reizner4a253652015-09-10 18:30:54 -070068 }
69
Zach Reiznerf99d53f2015-10-09 13:02:55 -070070 const hwc_drm_bo *operator->() const;
Zach Reizner4a253652015-09-10 18:30:54 -070071
72 void Clear();
73
Roman Stratiienko8666dc92021-02-09 17:49:55 +020074 std::shared_ptr<DrmFbIdHandle> FbIdHandle;
75
76 int ImportBuffer(buffer_handle_t handle, DrmDevice *drmDevice);
Zach Reizner4a253652015-09-10 18:30:54 -070077
78 private:
79 hwc_drm_bo bo_;
Roman Stratiienko8666dc92021-02-09 17:49:55 +020080 DrmDevice *mDrmDevice;
Zach Reizner4a253652015-09-10 18:30:54 -070081};
82
83class DrmHwcNativeHandle {
84 public:
85 DrmHwcNativeHandle() = default;
86
Andrii Chepurnyidc1278c2018-03-20 19:41:18 +020087 DrmHwcNativeHandle(native_handle_t *handle) : handle_(handle) {
Zach Reizner4a253652015-09-10 18:30:54 -070088 }
89
90 DrmHwcNativeHandle(DrmHwcNativeHandle &&rhs) {
Zach Reizner4a253652015-09-10 18:30:54 -070091 handle_ = rhs.handle_;
92 rhs.handle_ = NULL;
93 }
94
95 ~DrmHwcNativeHandle();
96
97 DrmHwcNativeHandle &operator=(DrmHwcNativeHandle &&rhs) {
98 Clear();
Zach Reizner4a253652015-09-10 18:30:54 -070099 handle_ = rhs.handle_;
100 rhs.handle_ = NULL;
101 return *this;
102 }
103
Roman Stratiienkoadd24cb2020-10-23 22:28:38 +0300104 int CopyBufferHandle(buffer_handle_t handle);
Zach Reizner4a253652015-09-10 18:30:54 -0700105
106 void Clear();
107
108 buffer_handle_t get() const {
109 return handle_;
110 }
111
112 private:
Zach Reizner4a253652015-09-10 18:30:54 -0700113 native_handle_t *handle_ = NULL;
114};
115
Sean Paul04b47ea2015-11-19 21:46:11 -0500116enum DrmHwcTransform {
Zach Reizner4a253652015-09-10 18:30:54 -0700117 kIdentity = 0,
Sean Paul04b47ea2015-11-19 21:46:11 -0500118 kFlipH = 1 << 0,
119 kFlipV = 1 << 1,
120 kRotate90 = 1 << 2,
121 kRotate180 = 1 << 3,
122 kRotate270 = 1 << 4,
Zach Reizner4a253652015-09-10 18:30:54 -0700123};
124
125enum class DrmHwcBlending : int32_t {
126 kNone = HWC_BLENDING_NONE,
127 kPreMult = HWC_BLENDING_PREMULT,
128 kCoverage = HWC_BLENDING_COVERAGE,
129};
130
131struct DrmHwcLayer {
132 buffer_handle_t sf_handle = NULL;
Zach Reizner36d7c6e2015-10-20 10:58:19 -0700133 int gralloc_buffer_usage = 0;
Zach Reizner4a253652015-09-10 18:30:54 -0700134 DrmHwcBuffer buffer;
135 DrmHwcNativeHandle handle;
Sean Paul04b47ea2015-11-19 21:46:11 -0500136 uint32_t transform;
Zach Reizner4a253652015-09-10 18:30:54 -0700137 DrmHwcBlending blending = DrmHwcBlending::kNone;
Stefan Schake025d0a62018-05-04 18:03:00 +0200138 uint16_t alpha = 0xffff;
Rob Herringcff7b1e2018-05-09 15:18:36 -0500139 hwc_frect_t source_crop;
140 hwc_rect_t display_frame;
Matvii Zorin8338c342020-09-08 16:12:51 +0300141 android_dataspace_t dataspace;
Zach Reizner4a253652015-09-10 18:30:54 -0700142
143 UniqueFd acquire_fence;
144 OutputFd release_fence;
145
Roman Stratiienko8666dc92021-02-09 17:49:55 +0200146 int ImportBuffer(DrmDevice *drmDevice);
147 int InitFromDrmHwcLayer(DrmHwcLayer *layer, DrmDevice *drmDevice);
Sean Paul80b1a5d2016-03-10 15:35:13 -0500148
149 void SetTransform(int32_t sf_transform);
Zach Reiznerf99d53f2015-10-09 13:02:55 -0700150
151 buffer_handle_t get_usable_handle() const {
152 return handle.get() != NULL ? handle.get() : sf_handle;
153 }
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700154
155 bool protected_usage() const {
156 return (gralloc_buffer_usage & GRALLOC_USAGE_PROTECTED) ==
157 GRALLOC_USAGE_PROTECTED;
158 }
Zach Reizner4a253652015-09-10 18:30:54 -0700159};
160
Sean Paulf72cccd2018-08-27 13:59:08 -0400161} // namespace android
Zach Reizner4a253652015-09-10 18:30:54 -0700162
Sean Paulef8f1f92015-04-29 16:05:23 -0400163#endif