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,
38 DRM_COMPOSITION_TYPE_MODESET,
41 struct DrmCompositionLayer {
43 DrmPlane *plane = NULL;
45 buffer_handle_t sf_handle = NULL;
47 DrmHwcNativeHandle handle;
48 DrmHwcTransform transform = DrmHwcTransform::kIdentity;
49 DrmHwcBlending blending = DrmHwcBlending::kNone;
51 DrmHwcRect<float> source_crop;
52 DrmHwcRect<int> display_frame;
53 std::vector<DrmHwcRect<int>> source_damage;
55 UniqueFd acquire_fence;
57 DrmCompositionLayer() = default;
58 DrmCompositionLayer(DrmCrtc *crtc, DrmHwcLayer &&l);
59 DrmCompositionLayer(DrmCompositionLayer &&l) = default;
61 DrmCompositionLayer &operator=(DrmCompositionLayer &&l) = default;
63 buffer_handle_t get_usable_handle() const {
64 return handle.get() != NULL ? handle.get() : sf_handle;
68 class DrmDisplayComposition {
70 DrmDisplayComposition();
71 ~DrmDisplayComposition();
73 int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer,
76 DrmCompositionType type() const;
78 int SetLayers(DrmHwcLayer *layers, size_t num_layers,
79 std::vector<DrmPlane *> *primary_planes,
80 std::vector<DrmPlane *> *overlay_planes);
81 int AddPlaneDisable(DrmPlane *plane);
82 int SetDpmsMode(uint32_t dpms_mode);
83 int SetDisplayMode(const DrmMode &display_mode);
85 void RemoveNoPlaneLayers();
86 int SignalPreCompositionDone();
87 int FinishComposition();
89 std::vector<DrmCompositionLayer> *GetCompositionLayers();
90 int pre_composition_layer_index() const;
91 uint32_t dpms_mode() const;
92 const DrmMode &display_mode() const;
94 uint64_t frame_no() const;
96 Importer *importer() const;
99 DrmDisplayComposition(const DrmDisplayComposition &) = delete;
101 bool validate_composition_type(DrmCompositionType desired);
103 int CreateNextTimelineFence();
104 int IncreaseTimelineToPoint(int point);
109 const gralloc_module_t *gralloc_;
110 EGLDisplay egl_display_;
112 DrmCompositionType type_;
116 int timeline_current_;
117 int timeline_pre_comp_done_;
119 std::vector<DrmCompositionLayer> layers_;
120 int pre_composition_layer_index_;
122 DrmMode display_mode_;
128 #endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_