OSDN Git Service

drm_hwcomposer: reimplement Dump for DrmDisplayCompositor
[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 <sstream>
27 #include <vector>
28
29 #include <hardware/gralloc.h>
30 #include <hardware/hardware.h>
31 #include <hardware/hwcomposer.h>
32
33 namespace android {
34
35 struct SquashState;
36
37 enum DrmCompositionType {
38   DRM_COMPOSITION_TYPE_EMPTY,
39   DRM_COMPOSITION_TYPE_FRAME,
40   DRM_COMPOSITION_TYPE_DPMS,
41   DRM_COMPOSITION_TYPE_MODESET,
42 };
43
44 struct DrmCompositionRegion {
45   DrmHwcRect<int> frame;
46   std::vector<size_t> source_layers;
47 };
48
49 struct DrmCompositionPlane {
50   const static size_t kSourceNone = SIZE_MAX;
51   const static size_t kSourcePreComp = kSourceNone - 1;
52   const static size_t kSourceSquash = kSourcePreComp - 1;
53   const static size_t kSourceLayerMax = kSourceSquash - 1;
54   DrmPlane *plane;
55   DrmCrtc *crtc;
56   size_t source_layer;
57 };
58
59 class DrmDisplayComposition {
60  public:
61   DrmDisplayComposition() = default;
62   DrmDisplayComposition(const DrmDisplayComposition &) = delete;
63   ~DrmDisplayComposition();
64
65   int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer,
66            uint64_t frame_no);
67
68   int SetLayers(DrmHwcLayer *layers, size_t num_layers);
69   int AddPlaneDisable(DrmPlane *plane);
70   int SetDpmsMode(uint32_t dpms_mode);
71   int SetDisplayMode(const DrmMode &display_mode);
72
73   int Plan(SquashState *squash, std::vector<DrmPlane *> *primary_planes,
74            std::vector<DrmPlane *> *overlay_planes);
75
76   int CreateNextTimelineFence();
77   int SignalSquashDone() {
78     return IncreaseTimelineToPoint(timeline_squash_done_);
79   }
80   int SignalPreCompDone() {
81     return IncreaseTimelineToPoint(timeline_pre_comp_done_);
82   }
83   int SignalCompositionDone() {
84     return IncreaseTimelineToPoint(timeline_);
85   }
86
87   std::vector<DrmHwcLayer> &layers() {
88     return layers_;
89   }
90
91   std::vector<DrmCompositionRegion> &squash_regions() {
92     return squash_regions_;
93   }
94
95   std::vector<DrmCompositionRegion> &pre_comp_regions() {
96     return pre_comp_regions_;
97   }
98
99   std::vector<DrmCompositionPlane> &composition_planes() {
100     return composition_planes_;
101   }
102
103   uint64_t frame_no() const {
104     return frame_no_;
105   }
106
107   DrmCompositionType type() const {
108     return type_;
109   }
110
111   uint32_t dpms_mode() const {
112     return dpms_mode_;
113   }
114
115   const DrmMode &display_mode() const {
116     return display_mode_;
117   }
118
119   DrmCrtc *crtc() const {
120     return crtc_;
121   }
122
123   Importer *importer() const {
124     return importer_;
125   }
126
127   void Dump(std::ostringstream *out) const;
128
129  private:
130   bool validate_composition_type(DrmCompositionType desired);
131
132   int IncreaseTimelineToPoint(int point);
133
134   DrmResources *drm_ = NULL;
135   DrmCrtc *crtc_ = NULL;
136   Importer *importer_ = NULL;
137
138   DrmCompositionType type_ = DRM_COMPOSITION_TYPE_EMPTY;
139   uint32_t dpms_mode_ = DRM_MODE_DPMS_ON;
140   DrmMode display_mode_;
141
142   int timeline_fd_ = -1;
143   int timeline_ = 0;
144   int timeline_current_ = 0;
145   int timeline_squash_done_ = 0;
146   int timeline_pre_comp_done_ = 0;
147
148   std::vector<DrmHwcLayer> layers_;
149   std::vector<DrmCompositionRegion> squash_regions_;
150   std::vector<DrmCompositionRegion> pre_comp_regions_;
151   std::vector<DrmCompositionPlane> composition_planes_;
152
153   uint64_t frame_no_ = 0;
154 };
155 }
156
157 #endif  // ANDROID_DRM_DISPLAY_COMPOSITION_H_