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>
26 #include "separate_rects.h"
27 #include "drmhwcgralloc.h"
29 struct hwc_import_context;
31 int hwc_import_init(struct hwc_import_context **ctx);
32 int hwc_import_destroy(struct hwc_import_context *ctx);
34 int hwc_import_bo_create(int fd, struct hwc_import_context *ctx,
35 buffer_handle_t buf, struct hwc_drm_bo *bo);
36 bool hwc_import_bo_release(int fd, struct hwc_import_context *ctx,
37 struct hwc_drm_bo *bo);
45 DrmHwcBuffer() = default;
46 DrmHwcBuffer(const hwc_drm_bo &bo, Importer *importer)
47 : bo_(bo), importer_(importer) {
49 DrmHwcBuffer(DrmHwcBuffer &&rhs) : bo_(rhs.bo_), importer_(rhs.importer_) {
57 DrmHwcBuffer &operator=(DrmHwcBuffer &&rhs) {
59 importer_ = rhs.importer_;
65 operator bool() const {
66 return importer_ != NULL;
69 const hwc_drm_bo *operator->() const;
73 int ImportBuffer(buffer_handle_t handle, Importer *importer);
77 Importer *importer_ = NULL;
80 class DrmHwcNativeHandle {
82 DrmHwcNativeHandle() = default;
84 DrmHwcNativeHandle(const gralloc_module_t *gralloc, native_handle_t *handle)
85 : gralloc_(gralloc), handle_(handle) {
88 DrmHwcNativeHandle(DrmHwcNativeHandle &&rhs) {
89 gralloc_ = rhs.gralloc_;
91 handle_ = rhs.handle_;
95 ~DrmHwcNativeHandle();
97 DrmHwcNativeHandle &operator=(DrmHwcNativeHandle &&rhs) {
99 gralloc_ = rhs.gralloc_;
101 handle_ = rhs.handle_;
106 int CopyBufferHandle(buffer_handle_t handle, const gralloc_module_t *gralloc);
110 buffer_handle_t get() const {
115 const gralloc_module_t *gralloc_ = NULL;
116 native_handle_t *handle_ = NULL;
119 template <typename T>
120 using DrmHwcRect = separate_rects::Rect<T>;
122 enum DrmHwcTransform {
131 enum class DrmHwcBlending : int32_t {
132 kNone = HWC_BLENDING_NONE,
133 kPreMult = HWC_BLENDING_PREMULT,
134 kCoverage = HWC_BLENDING_COVERAGE,
138 buffer_handle_t sf_handle = NULL;
139 int gralloc_buffer_usage = 0;
141 DrmHwcNativeHandle handle;
143 DrmHwcBlending blending = DrmHwcBlending::kNone;
144 uint8_t alpha = 0xff;
145 DrmHwcRect<float> source_crop;
146 DrmHwcRect<int> display_frame;
148 UniqueFd acquire_fence;
149 OutputFd release_fence;
151 int InitFromHwcLayer(hwc_layer_1_t *sf_layer, Importer *importer,
152 const gralloc_module_t *gralloc);
153 int ImportBuffer(Importer *importer, const gralloc_module_t *gralloc);
155 void SetTransform(int32_t sf_transform);
156 void SetSourceCrop(hwc_frect_t const &crop);
157 void SetDisplayFrame(hwc_rect_t const &frame);
159 buffer_handle_t get_usable_handle() const {
160 return handle.get() != NULL ? handle.get() : sf_handle;
163 bool protected_usage() const {
164 return (gralloc_buffer_usage & GRALLOC_USAGE_PROTECTED) ==
165 GRALLOC_USAGE_PROTECTED;
169 struct DrmHwcDisplayContents {
170 OutputFd retire_fence;
171 std::vector<DrmHwcLayer> layers;