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_
25 #include <hardware/hardware.h>
26 #include <hardware/hwcomposer.h>
28 #include "drmhwcgralloc.h"
30 struct hwc_import_context;
32 int hwc_import_init(struct hwc_import_context **ctx);
33 int hwc_import_destroy(struct hwc_import_context *ctx);
35 int hwc_import_bo_create(int fd, struct hwc_import_context *ctx,
36 buffer_handle_t buf, struct hwc_drm_bo *bo);
37 bool hwc_import_bo_release(int fd, struct hwc_import_context *ctx,
38 struct hwc_drm_bo *bo);
46 DrmHwcBuffer() = default;
47 DrmHwcBuffer(const hwc_drm_bo &bo, Importer *importer)
48 : bo_(bo), importer_(importer) {
50 DrmHwcBuffer(DrmHwcBuffer &&rhs) : bo_(rhs.bo_), importer_(rhs.importer_) {
58 DrmHwcBuffer &operator=(DrmHwcBuffer &&rhs) {
60 importer_ = rhs.importer_;
66 operator bool() const {
67 return importer_ != NULL;
70 const hwc_drm_bo *operator->() const;
74 int ImportBuffer(buffer_handle_t handle, Importer *importer);
78 Importer *importer_ = NULL;
81 class DrmHwcNativeHandle {
83 DrmHwcNativeHandle() = default;
85 DrmHwcNativeHandle(native_handle_t *handle) : handle_(handle) {
88 DrmHwcNativeHandle(DrmHwcNativeHandle &&rhs) {
89 handle_ = rhs.handle_;
93 ~DrmHwcNativeHandle();
95 DrmHwcNativeHandle &operator=(DrmHwcNativeHandle &&rhs) {
97 handle_ = rhs.handle_;
102 int CopyBufferHandle(buffer_handle_t handle);
106 buffer_handle_t get() const {
111 native_handle_t *handle_ = NULL;
114 enum DrmHwcTransform {
123 enum class DrmHwcBlending : int32_t {
124 kNone = HWC_BLENDING_NONE,
125 kPreMult = HWC_BLENDING_PREMULT,
126 kCoverage = HWC_BLENDING_COVERAGE,
130 buffer_handle_t sf_handle = NULL;
131 int gralloc_buffer_usage = 0;
133 DrmHwcNativeHandle handle;
135 DrmHwcBlending blending = DrmHwcBlending::kNone;
136 uint16_t alpha = 0xffff;
137 hwc_frect_t source_crop;
138 hwc_rect_t display_frame;
139 android_dataspace_t dataspace;
141 UniqueFd acquire_fence;
142 OutputFd release_fence;
144 int ImportBuffer(Importer *importer);
145 int InitFromDrmHwcLayer(DrmHwcLayer *layer, Importer *importer);
147 void SetTransform(int32_t sf_transform);
148 void SetSourceCrop(hwc_frect_t const &crop);
149 void SetDisplayFrame(hwc_rect_t const &frame);
151 buffer_handle_t get_usable_handle() const {
152 return handle.get() != NULL ? handle.get() : sf_handle;
155 bool protected_usage() const {
156 return (gralloc_buffer_usage & GRALLOC_USAGE_PROTECTED) ==
157 GRALLOC_USAGE_PROTECTED;
161 } // namespace android