blob: e0f8d2bfbeec3c12e578bf4f04e0e7bb800424e0 [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
Lauri Peltonen902c8942015-03-02 19:10:04 +020020#include <stdbool.h>
21#include <stdint.h>
22
Sean Paulef8f1f92015-04-29 16:05:23 -040023#include <hardware/hardware.h>
24#include <hardware/hwcomposer.h>
Zach Reiznerff30b522015-10-28 19:08:45 -070025#include "autofd.h"
Haixia Shiaa2f4a52015-11-02 10:54:29 -080026#include "separate_rects.h"
Zach Reizner766518e2015-10-22 16:34:49 -070027#include "drmhwcgralloc.h"
28
29struct hwc_import_context;
30
31int hwc_import_init(struct hwc_import_context **ctx);
32int hwc_import_destroy(struct hwc_import_context *ctx);
33
34int hwc_import_bo_create(int fd, struct hwc_import_context *ctx,
35 buffer_handle_t buf, struct hwc_drm_bo *bo);
36bool hwc_import_bo_release(int fd, struct hwc_import_context *ctx,
37 struct hwc_drm_bo *bo);
Sean Paulef8f1f92015-04-29 16:05:23 -040038
Zach Reizner4a253652015-09-10 18:30:54 -070039namespace android {
40
41class Importer;
42
Zach Reizner4a253652015-09-10 18:30:54 -070043class 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 Reiznerfd6dc332015-10-13 21:12:48 -070065 operator bool() const {
Zach Reizner4a253652015-09-10 18:30:54 -070066 return importer_ != NULL;
67 }
68
Zach Reiznerf99d53f2015-10-09 13:02:55 -070069 const hwc_drm_bo *operator->() const;
Zach Reizner4a253652015-09-10 18:30:54 -070070
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
80class DrmHwcNativeHandle {
81 public:
82 DrmHwcNativeHandle() = default;
83
84 DrmHwcNativeHandle(const gralloc_module_t *gralloc, native_handle_t *handle)
85 : gralloc_(gralloc), handle_(handle) {
86 }
87
88 DrmHwcNativeHandle(DrmHwcNativeHandle &&rhs) {
89 gralloc_ = rhs.gralloc_;
90 rhs.gralloc_ = NULL;
91 handle_ = rhs.handle_;
92 rhs.handle_ = NULL;
93 }
94
95 ~DrmHwcNativeHandle();
96
97 DrmHwcNativeHandle &operator=(DrmHwcNativeHandle &&rhs) {
98 Clear();
99 gralloc_ = rhs.gralloc_;
100 rhs.gralloc_ = NULL;
101 handle_ = rhs.handle_;
102 rhs.handle_ = NULL;
103 return *this;
104 }
105
106 int CopyBufferHandle(buffer_handle_t handle, const gralloc_module_t *gralloc);
107
108 void Clear();
109
110 buffer_handle_t get() const {
111 return handle_;
112 }
113
114 private:
115 const gralloc_module_t *gralloc_ = NULL;
116 native_handle_t *handle_ = NULL;
117};
118
119template <typename T>
Haixia Shiaa2f4a52015-11-02 10:54:29 -0800120using DrmHwcRect = separate_rects::Rect<T>;
Zach Reizner4a253652015-09-10 18:30:54 -0700121
122enum class DrmHwcTransform : uint32_t {
123 kIdentity = 0,
124 kFlipH = HWC_TRANSFORM_FLIP_H,
125 kFlipV = HWC_TRANSFORM_FLIP_V,
126 kRotate90 = HWC_TRANSFORM_ROT_90,
127 kRotate180 = HWC_TRANSFORM_ROT_180,
128 kRotate270 = HWC_TRANSFORM_ROT_270,
129};
130
131enum class DrmHwcBlending : int32_t {
132 kNone = HWC_BLENDING_NONE,
133 kPreMult = HWC_BLENDING_PREMULT,
134 kCoverage = HWC_BLENDING_COVERAGE,
135};
136
137struct DrmHwcLayer {
138 buffer_handle_t sf_handle = NULL;
Zach Reizner36d7c6e2015-10-20 10:58:19 -0700139 int gralloc_buffer_usage = 0;
Zach Reizner4a253652015-09-10 18:30:54 -0700140 DrmHwcBuffer buffer;
141 DrmHwcNativeHandle handle;
142 DrmHwcTransform transform = DrmHwcTransform::kIdentity;
143 DrmHwcBlending blending = DrmHwcBlending::kNone;
144 uint8_t alpha = 0xff;
145 DrmHwcRect<float> source_crop;
146 DrmHwcRect<int> display_frame;
147 std::vector<DrmHwcRect<int>> source_damage;
148
149 UniqueFd acquire_fence;
150 OutputFd release_fence;
151
Zach Reizner4a253652015-09-10 18:30:54 -0700152 int InitFromHwcLayer(hwc_layer_1_t *sf_layer, Importer *importer,
153 const gralloc_module_t *gralloc);
Zach Reiznerf99d53f2015-10-09 13:02:55 -0700154
155 buffer_handle_t get_usable_handle() const {
156 return handle.get() != NULL ? handle.get() : sf_handle;
157 }
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700158
159 bool protected_usage() const {
160 return (gralloc_buffer_usage & GRALLOC_USAGE_PROTECTED) ==
161 GRALLOC_USAGE_PROTECTED;
162 }
Zach Reizner4a253652015-09-10 18:30:54 -0700163};
164
165struct DrmHwcDisplayContents {
166 OutputFd retire_fence;
167 std::vector<DrmHwcLayer> layers;
168};
169}
170
Sean Paulef8f1f92015-04-29 16:05:23 -0400171#endif