-
Notifications
You must be signed in to change notification settings - Fork 0
/
drmcomposition.cpp
177 lines (153 loc) · 5.42 KB
/
drmcomposition.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "hwc-drm-composition"
#include "drmcomposition.h"
#include "drmcrtc.h"
#include "drmplane.h"
#include "drmresources.h"
#include "platform.h"
#include <stdlib.h>
#include <cutils/log.h>
#include <cutils/properties.h>
#include <sw_sync.h>
#include <sync/sync.h>
namespace android {
DrmComposition::DrmComposition(DrmResources *drm, Importer *importer,
Planner *planner)
: drm_(drm), importer_(importer), planner_(planner) {
char use_overlay_planes_prop[PROPERTY_VALUE_MAX];
property_get("hwc.drm.use_overlay_planes", use_overlay_planes_prop, "1");
bool use_overlay_planes = atoi(use_overlay_planes_prop);
for (auto &plane : drm->planes()) {
if (plane->type() == DRM_PLANE_TYPE_PRIMARY)
primary_planes_.push_back(plane.get());
else if (use_overlay_planes && plane->type() == DRM_PLANE_TYPE_OVERLAY)
overlay_planes_.push_back(plane.get());
else if (plane->type() == DRM_PLANE_TYPE_CURSOR)
cursor_planes_.push_back(plane.get());
}
}
int DrmComposition::Init(uint64_t frame_no) {
for (auto &conn : drm_->connectors()) {
int display = conn->display();
composition_map_[display].reset(new DrmDisplayComposition());
if (!composition_map_[display]) {
ALOGE("Failed to allocate new display composition\n");
return -ENOMEM;
}
// If the display hasn't been modeset yet, this will be NULL
DrmCrtc *crtc = drm_->GetCrtcForDisplay(display);
int ret = composition_map_[display]->Init(drm_, crtc, importer_, planner_,
frame_no);
if (ret) {
ALOGE("Failed to init display composition for %d", display);
return ret;
}
}
return 0;
}
int DrmComposition::SetLayers(size_t num_displays,
DrmCompositionDisplayLayersMap *maps) {
int ret = 0;
for (size_t display_index = 0; display_index < num_displays;
display_index++) {
DrmCompositionDisplayLayersMap &map = maps[display_index];
int display = map.display;
if (!drm_->GetConnectorForDisplay(display)) {
ALOGE("Invalid display given to SetLayers %d", display);
continue;
}
ret = composition_map_[display]->SetLayers(
map.layers.data(), map.layers.size(), map.geometry_changed);
if (ret)
return ret;
}
return 0;
}
int DrmComposition::SetDpmsMode(int display, uint32_t dpms_mode) {
return composition_map_[display]->SetDpmsMode(dpms_mode);
}
int DrmComposition::SetDisplayMode(int display, const DrmMode &display_mode) {
return composition_map_[display]->SetDisplayMode(display_mode);
}
std::unique_ptr<DrmDisplayComposition> DrmComposition::TakeDisplayComposition(
int display) {
return std::move(composition_map_[display]);
}
int DrmComposition::Plan(std::map<int, DrmDisplayCompositor> &compositor_map) {
int ret = 0;
for (auto &conn : drm_->connectors()) {
int display = conn->display();
DrmDisplayComposition *comp = GetDisplayComposition(display);
ret = comp->Plan(compositor_map[display].squash_state(), &primary_planes_,
&overlay_planes_, &cursor_planes_);
if (ret) {
ALOGE("Failed to plan composition for dislay %d", display);
return ret;
}
}
return 0;
}
int DrmComposition::DisableUnusedPlanes() {
for (auto &conn : drm_->connectors()) {
int display = conn->display();
DrmDisplayComposition *comp = GetDisplayComposition(display);
/*
* Leave empty compositions alone
* TODO: re-visit this and potentially disable leftover planes after the
* active compositions have gobbled up all they can
*/
if (comp->type() == DRM_COMPOSITION_TYPE_EMPTY ||
comp->type() == DRM_COMPOSITION_TYPE_MODESET)
continue;
DrmCrtc *crtc = drm_->GetCrtcForDisplay(display);
if (!crtc) {
ALOGE("Failed to find crtc for display %d", display);
continue;
}
for (std::vector<DrmPlane *>::iterator iter = primary_planes_.begin();
iter != primary_planes_.end(); ++iter) {
if ((*iter)->GetCrtcSupported(*crtc)) {
comp->AddPlaneDisable(*iter);
primary_planes_.erase(iter);
break;
}
}
for (std::vector<DrmPlane *>::iterator iter = overlay_planes_.begin();
iter != overlay_planes_.end();) {
if ((*iter)->GetCrtcSupported(*crtc)) {
comp->AddPlaneDisable(*iter);
iter = overlay_planes_.erase(iter);
} else {
iter++;
}
}
for (std::vector<DrmPlane *>::iterator iter = cursor_planes_.begin();
iter != cursor_planes_.end();) {
if ((*iter)->GetCrtcSupported(*crtc)) {
comp->AddPlaneDisable(*iter);
iter = cursor_planes_.erase(iter);
} else {
iter++;
}
}
}
return 0;
}
DrmDisplayComposition *DrmComposition::GetDisplayComposition(int display) {
return composition_map_[display].get();
}
}