OSDN Git Service

drm_hwcomposer: Mark tests as vendor, fix build
[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 "drmcrtc.h"
21 #include "drmhwcomposer.h"
22 #include "drmplane.h"
23 #include "glworker.h"
24
25 #include <sstream>
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 class Importer;
35 class Planner;
36 class SquashState;
37
38 enum DrmCompositionType {
39   DRM_COMPOSITION_TYPE_EMPTY,
40   DRM_COMPOSITION_TYPE_FRAME,
41   DRM_COMPOSITION_TYPE_DPMS,
42   DRM_COMPOSITION_TYPE_MODESET,
43 };
44
45 struct DrmCompositionDisplayLayersMap {
46   int display;
47   bool geometry_changed = true;
48   std::vector<DrmHwcLayer> layers;
49
50   DrmCompositionDisplayLayersMap() = default;
51   DrmCompositionDisplayLayersMap(DrmCompositionDisplayLayersMap &&rhs) =
52       default;
53 };
54
55 struct DrmCompositionRegion {
56   DrmHwcRect<int> frame;
57   std::vector<size_t> source_layers;
58 };
59
60 class DrmCompositionPlane {
61  public:
62   enum class Type : int32_t {
63     kDisable,
64     kLayer,
65     kPrecomp,
66     kSquash,
67   };
68
69   DrmCompositionPlane() = default;
70   DrmCompositionPlane(DrmCompositionPlane &&rhs) = default;
71   DrmCompositionPlane &operator=(DrmCompositionPlane &&other) = default;
72   DrmCompositionPlane(Type type, DrmPlane *plane, DrmCrtc *crtc)
73       : type_(type), plane_(plane), crtc_(crtc) {
74   }
75   DrmCompositionPlane(Type type, DrmPlane *plane, DrmCrtc *crtc,
76                       size_t source_layer)
77       : type_(type),
78         plane_(plane),
79         crtc_(crtc),
80         source_layers_(1, source_layer) {
81   }
82
83   Type type() const {
84     return type_;
85   }
86
87   DrmPlane *plane() const {
88     return plane_;
89   }
90   void set_plane(DrmPlane *plane) {
91     plane_ = plane;
92   }
93
94   DrmCrtc *crtc() const {
95     return crtc_;
96   }
97
98   std::vector<size_t> &source_layers() {
99     return source_layers_;
100   }
101
102   const std::vector<size_t> &source_layers() const {
103     return source_layers_;
104   }
105
106  private:
107   Type type_ = Type::kDisable;
108   DrmPlane *plane_ = NULL;
109   DrmCrtc *crtc_ = NULL;
110   std::vector<size_t> source_layers_;
111 };
112
113 class DrmDisplayComposition {
114  public:
115   DrmDisplayComposition() = default;
116   DrmDisplayComposition(const DrmDisplayComposition &) = delete;
117   ~DrmDisplayComposition();
118
119   int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer,
120            Planner *planner, uint64_t frame_no);
121
122   int SetLayers(DrmHwcLayer *layers, size_t num_layers, bool geometry_changed);
123   int AddPlaneComposition(DrmCompositionPlane plane);
124   int AddPlaneDisable(DrmPlane *plane);
125   int SetDpmsMode(uint32_t dpms_mode);
126   int SetDisplayMode(const DrmMode &display_mode);
127
128   int Plan(SquashState *squash, std::vector<DrmPlane *> *primary_planes,
129            std::vector<DrmPlane *> *overlay_planes);
130
131   int FinalizeComposition();
132
133   int CreateNextTimelineFence();
134   int SignalSquashDone() {
135     return IncreaseTimelineToPoint(timeline_squash_done_);
136   }
137   int SignalPreCompDone() {
138     return IncreaseTimelineToPoint(timeline_pre_comp_done_);
139   }
140   int SignalCompositionDone() {
141     return IncreaseTimelineToPoint(timeline_);
142   }
143
144   std::vector<DrmHwcLayer> &layers() {
145     return layers_;
146   }
147
148   std::vector<DrmCompositionRegion> &squash_regions() {
149     return squash_regions_;
150   }
151
152   std::vector<DrmCompositionRegion> &pre_comp_regions() {
153     return pre_comp_regions_;
154   }
155
156   std::vector<DrmCompositionPlane> &composition_planes() {
157     return composition_planes_;
158   }
159
160   bool geometry_changed() const {
161     return geometry_changed_;
162   }
163
164   uint64_t frame_no() const {
165     return frame_no_;
166   }
167
168   DrmCompositionType type() const {
169     return type_;
170   }
171
172   uint32_t dpms_mode() const {
173     return dpms_mode_;
174   }
175
176   const DrmMode &display_mode() const {
177     return display_mode_;
178   }
179
180   DrmCrtc *crtc() const {
181     return crtc_;
182   }
183
184   Importer *importer() const {
185     return importer_;
186   }
187
188   Planner *planner() const {
189     return planner_;
190   }
191
192   int take_out_fence() {
193     return out_fence_.Release();
194   }
195
196   void set_out_fence(int out_fence) {
197     out_fence_.Set(out_fence);
198   }
199
200   void Dump(std::ostringstream *out) const;
201
202  private:
203   bool validate_composition_type(DrmCompositionType desired);
204
205   int IncreaseTimelineToPoint(int point);
206
207   int FinalizeComposition(DrmHwcRect<int> *exclude_rects,
208                           size_t num_exclude_rects);
209   void SeparateLayers(DrmHwcRect<int> *exclude_rects, size_t num_exclude_rects);
210   int CreateAndAssignReleaseFences();
211
212   DrmResources *drm_ = NULL;
213   DrmCrtc *crtc_ = NULL;
214   Importer *importer_ = NULL;
215   Planner *planner_ = NULL;
216
217   DrmCompositionType type_ = DRM_COMPOSITION_TYPE_EMPTY;
218   uint32_t dpms_mode_ = DRM_MODE_DPMS_ON;
219   DrmMode display_mode_;
220
221   int timeline_fd_ = -1;
222   int timeline_ = 0;
223   int timeline_current_ = 0;
224   int timeline_squash_done_ = 0;
225   int timeline_pre_comp_done_ = 0;
226   UniqueFd out_fence_ = -1;
227
228   bool geometry_changed_;
229   std::vector<DrmHwcLayer> layers_;
230   std::vector<DrmCompositionRegion> squash_regions_;
231   std::vector<DrmCompositionRegion> pre_comp_regions_;
232   std::vector<DrmCompositionPlane> composition_planes_;
233
234   uint64_t frame_no_ = 0;
235 };
236 }
237
238 #endif  // ANDROID_DRM_DISPLAY_COMPOSITION_H_