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_DISPLAY_COMPOSITION_H_
18 #define ANDROID_DRM_DISPLAY_COMPOSITION_H_
20 #include "drm_hwcomposer.h"
28 #include <hardware/gralloc.h>
29 #include <hardware/hardware.h>
30 #include <hardware/hwcomposer.h>
34 enum DrmCompositionType {
35 DRM_COMPOSITION_TYPE_EMPTY,
36 DRM_COMPOSITION_TYPE_FRAME,
37 DRM_COMPOSITION_TYPE_DPMS,
40 struct DrmCompositionLayer {
42 DrmPlane *plane = NULL;
44 buffer_handle_t sf_handle = NULL;
46 DrmHwcNativeHandle handle;
47 DrmHwcTransform transform = DrmHwcTransform::kIdentity;
48 DrmHwcBlending blending = DrmHwcBlending::kNone;
50 DrmHwcRect<float> source_crop;
51 DrmHwcRect<int> display_frame;
52 std::vector<DrmHwcRect<int>> source_damage;
54 UniqueFd acquire_fence;
56 DrmCompositionLayer() = default;
57 DrmCompositionLayer(DrmCrtc *crtc, DrmHwcLayer &&l);
58 DrmCompositionLayer(DrmCompositionLayer &&l) = default;
60 DrmCompositionLayer &operator=(DrmCompositionLayer &&l) = default;
62 buffer_handle_t get_usable_handle() const {
63 return handle.get() != NULL ? handle.get() : sf_handle;
67 class DrmDisplayComposition {
69 DrmDisplayComposition();
70 ~DrmDisplayComposition();
72 int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer,
75 DrmCompositionType type() const;
77 int SetLayers(DrmHwcLayer *layers, size_t num_layers,
78 std::vector<DrmPlane *> *primary_planes,
79 std::vector<DrmPlane *> *overlay_planes);
80 int AddPlaneDisable(DrmPlane *plane);
81 int SetDpmsMode(uint32_t dpms_mode);
83 void RemoveNoPlaneLayers();
84 int SignalPreCompositionDone();
85 int FinishComposition();
87 std::vector<DrmCompositionLayer> *GetCompositionLayers();
88 int pre_composition_layer_index() const;
89 uint32_t dpms_mode() const;
91 uint64_t frame_no() const;
93 Importer *importer() const;
96 DrmDisplayComposition(const DrmDisplayComposition &) = delete;
98 bool validate_composition_type(DrmCompositionType desired);
100 int CreateNextTimelineFence();
101 int IncreaseTimelineToPoint(int point);
106 const gralloc_module_t *gralloc_;
107 EGLDisplay egl_display_;
109 DrmCompositionType type_;
113 int timeline_current_;
114 int timeline_pre_comp_done_;
116 std::vector<DrmCompositionLayer> layers_;
117 int pre_composition_layer_index_;
124 #endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_