OSDN Git Service

drm_hwcomposer: Process modesets via compositor
[android-x86/external-drm_hwcomposer.git] / drmdisplaycomposition.h
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef ANDROID_DRM_DISPLAY_COMPOSITION_H_
18 #define ANDROID_DRM_DISPLAY_COMPOSITION_H_
19
20 #include "drm_hwcomposer.h"
21 #include "drmcrtc.h"
22 #include "drmplane.h"
23 #include "glworker.h"
24 #include "importer.h"
25
26 #include <vector>
27
28 #include <hardware/gralloc.h>
29 #include <hardware/hardware.h>
30 #include <hardware/hwcomposer.h>
31
32 namespace android {
33
34 enum DrmCompositionType {
35   DRM_COMPOSITION_TYPE_EMPTY,
36   DRM_COMPOSITION_TYPE_FRAME,
37   DRM_COMPOSITION_TYPE_DPMS,
38   DRM_COMPOSITION_TYPE_MODESET,
39 };
40
41 struct DrmCompositionLayer {
42   DrmCrtc *crtc = NULL;
43   DrmPlane *plane = NULL;
44
45   buffer_handle_t sf_handle = NULL;
46   DrmHwcBuffer buffer;
47   DrmHwcNativeHandle handle;
48   DrmHwcTransform transform = DrmHwcTransform::kIdentity;
49   DrmHwcBlending blending = DrmHwcBlending::kNone;
50   uint8_t alpha = 0xff;
51   DrmHwcRect<float> source_crop;
52   DrmHwcRect<int> display_frame;
53   std::vector<DrmHwcRect<int>> source_damage;
54
55   UniqueFd acquire_fence;
56
57   DrmCompositionLayer() = default;
58   DrmCompositionLayer(DrmCrtc *crtc, DrmHwcLayer &&l);
59   DrmCompositionLayer(DrmCompositionLayer &&l) = default;
60
61   DrmCompositionLayer &operator=(DrmCompositionLayer &&l) = default;
62
63   buffer_handle_t get_usable_handle() const {
64     return handle.get() != NULL ? handle.get() : sf_handle;
65   }
66 };
67
68 class DrmDisplayComposition {
69  public:
70   DrmDisplayComposition();
71   ~DrmDisplayComposition();
72
73   int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer,
74            uint64_t frame_no);
75
76   DrmCompositionType type() const;
77
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);
84
85   void RemoveNoPlaneLayers();
86   int SignalPreCompositionDone();
87   int FinishComposition();
88
89   std::vector<DrmCompositionLayer> *GetCompositionLayers();
90   int pre_composition_layer_index() const;
91   uint32_t dpms_mode() const;
92   const DrmMode &display_mode() const;
93
94   uint64_t frame_no() const;
95
96   Importer *importer() const;
97
98  private:
99   DrmDisplayComposition(const DrmDisplayComposition &) = delete;
100
101   bool validate_composition_type(DrmCompositionType desired);
102
103   int CreateNextTimelineFence();
104   int IncreaseTimelineToPoint(int point);
105
106   DrmResources *drm_;
107   DrmCrtc *crtc_;
108   Importer *importer_;
109   const gralloc_module_t *gralloc_;
110   EGLDisplay egl_display_;
111
112   DrmCompositionType type_;
113
114   int timeline_fd_;
115   int timeline_;
116   int timeline_current_;
117   int timeline_pre_comp_done_;
118
119   std::vector<DrmCompositionLayer> layers_;
120   int pre_composition_layer_index_;
121   uint32_t dpms_mode_;
122   DrmMode display_mode_;
123
124   uint64_t frame_no_;
125 };
126 }
127
128 #endif  // ANDROID_DRM_DISPLAY_COMPOSITION_H_