• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
24 #include <sstream>
25 #include <vector>
26 
27 #include <hardware/hardware.h>
28 #include <hardware/hwcomposer.h>
29 
30 namespace android {
31 
32 class Importer;
33 class Planner;
34 class SquashState;
35 
36 enum DrmCompositionType {
37   DRM_COMPOSITION_TYPE_EMPTY,
38   DRM_COMPOSITION_TYPE_FRAME,
39   DRM_COMPOSITION_TYPE_DPMS,
40   DRM_COMPOSITION_TYPE_MODESET,
41 };
42 
43 struct DrmCompositionDisplayLayersMap {
44   int display;
45   bool geometry_changed = true;
46   std::vector<DrmHwcLayer> layers;
47 
48   DrmCompositionDisplayLayersMap() = default;
49   DrmCompositionDisplayLayersMap(DrmCompositionDisplayLayersMap &&rhs) =
50       default;
51 };
52 
53 struct DrmCompositionRegion {
54   std::vector<size_t> source_layers;
55 };
56 
57 class DrmCompositionPlane {
58  public:
59   enum class Type : int32_t {
60     kDisable,
61     kLayer,
62   };
63 
64   DrmCompositionPlane() = default;
65   DrmCompositionPlane(DrmCompositionPlane &&rhs) = default;
66   DrmCompositionPlane &operator=(DrmCompositionPlane &&other) = default;
DrmCompositionPlane(Type type,DrmPlane * plane,DrmCrtc * crtc)67   DrmCompositionPlane(Type type, DrmPlane *plane, DrmCrtc *crtc)
68       : type_(type), plane_(plane), crtc_(crtc) {
69   }
DrmCompositionPlane(Type type,DrmPlane * plane,DrmCrtc * crtc,size_t source_layer)70   DrmCompositionPlane(Type type, DrmPlane *plane, DrmCrtc *crtc,
71                       size_t source_layer)
72       : type_(type),
73         plane_(plane),
74         crtc_(crtc),
75         source_layers_(1, source_layer) {
76   }
77 
type()78   Type type() const {
79     return type_;
80   }
81 
plane()82   DrmPlane *plane() const {
83     return plane_;
84   }
set_plane(DrmPlane * plane)85   void set_plane(DrmPlane *plane) {
86     plane_ = plane;
87   }
88 
crtc()89   DrmCrtc *crtc() const {
90     return crtc_;
91   }
92 
source_layers()93   std::vector<size_t> &source_layers() {
94     return source_layers_;
95   }
96 
source_layers()97   const std::vector<size_t> &source_layers() const {
98     return source_layers_;
99   }
100 
101  private:
102   Type type_ = Type::kDisable;
103   DrmPlane *plane_ = NULL;
104   DrmCrtc *crtc_ = NULL;
105   std::vector<size_t> source_layers_;
106 };
107 
108 class DrmDisplayComposition {
109  public:
110   DrmDisplayComposition() = default;
111   DrmDisplayComposition(const DrmDisplayComposition &) = delete;
112   ~DrmDisplayComposition();
113 
114   int Init(DrmDevice *drm, DrmCrtc *crtc, Importer *importer, Planner *planner,
115            uint64_t frame_no);
116 
117   int SetLayers(DrmHwcLayer *layers, size_t num_layers, bool geometry_changed);
118   int AddPlaneComposition(DrmCompositionPlane plane);
119   int AddPlaneDisable(DrmPlane *plane);
120   int SetDpmsMode(uint32_t dpms_mode);
121   int SetDisplayMode(const DrmMode &display_mode);
122 
123   int Plan(std::vector<DrmPlane *> *primary_planes,
124            std::vector<DrmPlane *> *overlay_planes);
125 
layers()126   std::vector<DrmHwcLayer> &layers() {
127     return layers_;
128   }
129 
composition_planes()130   std::vector<DrmCompositionPlane> &composition_planes() {
131     return composition_planes_;
132   }
133 
geometry_changed()134   bool geometry_changed() const {
135     return geometry_changed_;
136   }
137 
frame_no()138   uint64_t frame_no() const {
139     return frame_no_;
140   }
141 
type()142   DrmCompositionType type() const {
143     return type_;
144   }
145 
dpms_mode()146   uint32_t dpms_mode() const {
147     return dpms_mode_;
148   }
149 
display_mode()150   const DrmMode &display_mode() const {
151     return display_mode_;
152   }
153 
crtc()154   DrmCrtc *crtc() const {
155     return crtc_;
156   }
157 
importer()158   Importer *importer() const {
159     return importer_;
160   }
161 
planner()162   Planner *planner() const {
163     return planner_;
164   }
165 
take_out_fence()166   int take_out_fence() {
167     return out_fence_.Release();
168   }
169 
set_out_fence(int out_fence)170   void set_out_fence(int out_fence) {
171     out_fence_.Set(out_fence);
172   }
173 
174   void Dump(std::ostringstream *out) const;
175 
176  private:
177   bool validate_composition_type(DrmCompositionType desired);
178 
179   DrmDevice *drm_ = NULL;
180   DrmCrtc *crtc_ = NULL;
181   Importer *importer_ = NULL;
182   Planner *planner_ = NULL;
183 
184   DrmCompositionType type_ = DRM_COMPOSITION_TYPE_EMPTY;
185   uint32_t dpms_mode_ = DRM_MODE_DPMS_ON;
186   DrmMode display_mode_;
187 
188   UniqueFd out_fence_ = -1;
189 
190   bool geometry_changed_;
191   std::vector<DrmHwcLayer> layers_;
192   std::vector<DrmCompositionPlane> composition_planes_;
193 
194   uint64_t frame_no_ = 0;
195 };
196 }  // namespace android
197 
198 #endif  // ANDROID_DRM_DISPLAY_COMPOSITION_H_
199