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"
35 UniqueFd(int fd) : fd_(fd) {
37 UniqueFd(UniqueFd &&rhs) {
42 UniqueFd &operator=(UniqueFd &&rhs) {
81 OutputFd(int *fd) : fd_(fd) {
83 OutputFd(OutputFd &&rhs) {
88 OutputFd &operator=(OutputFd &&rhs);
107 DrmHwcBuffer() = default;
108 DrmHwcBuffer(const hwc_drm_bo &bo, Importer *importer)
109 : bo_(bo), importer_(importer) {
111 DrmHwcBuffer(DrmHwcBuffer &&rhs) : bo_(rhs.bo_), importer_(rhs.importer_) {
112 rhs.importer_ = NULL;
119 DrmHwcBuffer &operator=(DrmHwcBuffer &&rhs) {
121 importer_ = rhs.importer_;
122 rhs.importer_ = NULL;
127 operator bool() const {
128 return importer_ != NULL;
131 const hwc_drm_bo *operator->() const;
135 int ImportBuffer(buffer_handle_t handle, Importer *importer);
139 Importer *importer_ = NULL;
142 class DrmHwcNativeHandle {
144 DrmHwcNativeHandle() = default;
146 DrmHwcNativeHandle(const gralloc_module_t *gralloc, native_handle_t *handle)
147 : gralloc_(gralloc), handle_(handle) {
150 DrmHwcNativeHandle(DrmHwcNativeHandle &&rhs) {
151 gralloc_ = rhs.gralloc_;
153 handle_ = rhs.handle_;
157 ~DrmHwcNativeHandle();
159 DrmHwcNativeHandle &operator=(DrmHwcNativeHandle &&rhs) {
161 gralloc_ = rhs.gralloc_;
163 handle_ = rhs.handle_;
168 int CopyBufferHandle(buffer_handle_t handle, const gralloc_module_t *gralloc);
172 buffer_handle_t get() const {
177 const gralloc_module_t *gralloc_ = NULL;
178 native_handle_t *handle_ = NULL;
181 template <typename T>
182 using DrmHwcRect = seperate_rects::Rect<T>;
184 enum class DrmHwcTransform : uint32_t {
186 kFlipH = HWC_TRANSFORM_FLIP_H,
187 kFlipV = HWC_TRANSFORM_FLIP_V,
188 kRotate90 = HWC_TRANSFORM_ROT_90,
189 kRotate180 = HWC_TRANSFORM_ROT_180,
190 kRotate270 = HWC_TRANSFORM_ROT_270,
193 enum class DrmHwcBlending : int32_t {
194 kNone = HWC_BLENDING_NONE,
195 kPreMult = HWC_BLENDING_PREMULT,
196 kCoverage = HWC_BLENDING_COVERAGE,
200 buffer_handle_t sf_handle = NULL;
202 DrmHwcNativeHandle handle;
203 DrmHwcTransform transform = DrmHwcTransform::kIdentity;
204 DrmHwcBlending blending = DrmHwcBlending::kNone;
205 uint8_t alpha = 0xff;
206 DrmHwcRect<float> source_crop;
207 DrmHwcRect<int> display_frame;
208 std::vector<DrmHwcRect<int>> source_damage;
210 UniqueFd acquire_fence;
211 OutputFd release_fence;
213 int InitFromHwcLayer(hwc_layer_1_t *sf_layer, Importer *importer,
214 const gralloc_module_t *gralloc);
216 buffer_handle_t get_usable_handle() const {
217 return handle.get() != NULL ? handle.get() : sf_handle;
221 struct DrmHwcDisplayContents {
222 OutputFd retire_fence;
223 std::vector<DrmHwcLayer> layers;