-
Notifications
You must be signed in to change notification settings - Fork 0
/
drmcomposition.cpp
executable file
·204 lines (175 loc) · 6.73 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
* Copyright (C) 2018 Fuzhou Rockchip Electronics Co.Ltd.
*
* Modification based on code covered by the Apache License, Version 2.0 (the "License").
* You may not use this software except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS TO YOU ON AN "AS IS" BASIS
* AND ANY AND ALL WARRANTIES AND REPRESENTATIONS WITH RESPECT TO SUCH SOFTWARE, WHETHER EXPRESS,
* IMPLIED, STATUTORY OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF TITLE,
* NON-INFRINGEMENT, MERCHANTABILITY, SATISFACTROY QUALITY, ACCURACY OR FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED.
*
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 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 "hwc_rockchip.h"
#ifdef ANDROID_P
#include <log/log.h>
#include <libsync/sw_sync.h>
#else
#include <cutils/log.h>
#include <sw_sync.h>
#endif
#include <cutils/properties.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( PROPERTY_TYPE ".hwc.drm.use_overlay_planes", use_overlay_planes_prop, "1");
bool use_overlay_planes = atoi(use_overlay_planes_prop);
for (auto &plane : drm->sort_planes()) {
if (plane->type() == DRM_PLANE_TYPE_PRIMARY)
primary_planes_.push_back(plane);
else if (use_overlay_planes && (plane->type() == DRM_PLANE_TYPE_OVERLAY ||
plane->type() == DRM_PLANE_TYPE_CURSOR))
overlay_planes_.push_back(plane);
}
}
int DrmComposition::Init(uint64_t frame_no) {
int i;
for (i = 0; i < HWC_NUM_PHYSICAL_DISPLAY_TYPES; i++) {
composition_map_[i].reset(new DrmDisplayComposition());
if (!composition_map_[i]) {
ALOGE("Failed to allocate new display composition\n");
return -ENOMEM;
}
DrmConnector *c = drm_->GetConnectorFromType(i);
if (!c || c->state() != DRM_MODE_CONNECTED)
continue;
DrmCrtc *crtc = drm_->GetCrtcFromConnector(c);
if (!crtc)
continue;
int ret = composition_map_[i]->Init(drm_, crtc, importer_, planner_, frame_no);
if (ret) {
ALOGE("Failed to init display composition for %d", c->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 (!composition_map_[display]->crtc())
continue;
ret = composition_map_[display]->SetLayers(
map.layers.data(), map.layers.size(), map.geometry_changed);
if (ret)
return ret;
}
return 0;
}
int DrmComposition::SetMode3D(int display, Mode3D mode) {
return composition_map_[display]->SetMode3D(mode);
}
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);
}
int DrmComposition::SetCompPlanes(int display, std::vector<DrmCompositionPlane>& composition_planes) {
return composition_map_[display]->SetCompPlanes(composition_planes);
}
std::unique_ptr<DrmDisplayComposition> DrmComposition::TakeDisplayComposition(
int display) {
return std::move(composition_map_[display]);
}
int DrmComposition::Plan(std::map<int, DrmDisplayCompositor> &compositor_map, int display) {
int ret = 0;
if (!composition_map_[display]->crtc())
{
ALOGE("%s: crtc is null", __FUNCTION__);
return 0;
}
DrmDisplayComposition *comp = GetDisplayComposition(display);
ret = comp->Plan(compositor_map[display].squash_state(), &primary_planes_,
&overlay_planes_);
if (ret) {
ALOGE("Failed to plan composition for dislay %d", display);
return ret;
}
return 0;
}
int DrmComposition::DisableUnusedPlanes(int display) {
std::vector<PlaneGroup *>& plane_groups = drm_->GetPlaneGroups();
DrmCrtc *crtc = composition_map_[display]->crtc();
if (!crtc)
{
ALOGE("%s: crtc is null", __FUNCTION__);
return 0;
}
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)
{
return 0;
}
//loop plane groups.
for (std::vector<PlaneGroup *> ::const_iterator iter = plane_groups.begin();
iter != plane_groups.end(); ++iter) {
//loop plane
for(std::vector<DrmPlane*> ::const_iterator iter_plane=(*iter)->planes.begin();
!(*iter)->planes.empty() && iter_plane != (*iter)->planes.end(); ++iter_plane) {
if ((*iter_plane)->GetCrtcSupported(*crtc) && !(*iter_plane)->is_use()) {
ALOGD_IF(log_level(DBG_DEBUG),"DisableUnusedPlanes plane_groups plane id=%d",(*iter_plane)->id());
comp->AddPlaneDisable(*iter_plane);
// break;
}
}
}
return 0;
}
DrmDisplayComposition *DrmComposition::GetDisplayComposition(int display) {
return composition_map_[display].get();
}
}