-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdrmcomposition.cpp
129 lines (114 loc) · 3.88 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
/*
* 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 <stdlib.h>
#include <cutils/log.h>
#include <sw_sync.h>
#include <sync/sync.h>
namespace android {
static const bool kUseOverlayPlanes = true;
DrmComposition::DrmComposition(DrmResources *drm, Importer *importer)
: drm_(drm), importer_(importer) {
for (DrmResources::PlaneIter iter = drm_->begin_planes();
iter != drm_->end_planes(); ++iter) {
if ((*iter)->type() == DRM_PLANE_TYPE_PRIMARY)
primary_planes_.push_back(*iter);
else if (kUseOverlayPlanes && (*iter)->type() == DRM_PLANE_TYPE_OVERLAY)
overlay_planes_.push_back(*iter);
}
}
DrmComposition::~DrmComposition() {
}
int DrmComposition::Init() {
for (DrmResources::ConnectorIter iter = drm_->begin_connectors();
iter != drm_->end_connectors(); ++iter) {
int display = (*iter)->display();
composition_map_[display].reset(new DrmDisplayComposition());
if (!composition_map_[display]) {
ALOGE("Failed to allocate new display composition\n");
return -ENOMEM;
}
int ret = composition_map_[(*iter)->display()]->Init(drm_, importer_);
if (ret) {
ALOGE("Failed to init display composition for %d", (*iter)->display());
return ret;
}
}
return 0;
}
unsigned DrmComposition::GetRemainingLayers(int display,
unsigned num_needed) const {
DrmCrtc *crtc = drm_->GetCrtcForDisplay(display);
if (!crtc) {
ALOGE("Failed to find crtc for display %d", display);
return 0;
}
unsigned num_planes = 0;
for (std::vector<DrmPlane *>::const_iterator iter = primary_planes_.begin();
iter != primary_planes_.end(); ++iter) {
if ((*iter)->GetCrtcSupported(*crtc))
++num_planes;
}
for (std::deque<DrmPlane *>::const_iterator iter = overlay_planes_.begin();
iter != overlay_planes_.end(); ++iter) {
if ((*iter)->GetCrtcSupported(*crtc))
++num_planes;
}
return std::min(num_planes, num_needed);
}
int DrmComposition::AddLayer(int display, hwc_layer_1_t *layer,
hwc_drm_bo *bo) {
DrmCrtc *crtc = drm_->GetCrtcForDisplay(display);
if (!crtc) {
ALOGE("Failed to find crtc for display %d", display);
return -ENODEV;
}
// Find a plane for the layer
DrmPlane *plane = NULL;
for (std::vector<DrmPlane *>::iterator iter = primary_planes_.begin();
iter != primary_planes_.end(); ++iter) {
if ((*iter)->GetCrtcSupported(*crtc)) {
plane = *iter;
primary_planes_.erase(iter);
break;
}
}
for (std::deque<DrmPlane *>::iterator iter = overlay_planes_.begin();
!plane && iter != overlay_planes_.end(); ++iter) {
if ((*iter)->GetCrtcSupported(*crtc)) {
plane = *iter;
overlay_planes_.erase(iter);
break;
}
}
if (!plane) {
ALOGE("Failed to find plane for display %d", display);
return -ENOENT;
}
return composition_map_[display]->AddLayer(layer, bo, crtc, plane);
}
int DrmComposition::AddDpmsMode(int display, uint32_t dpms_mode) {
return composition_map_[display]->AddDpmsMode(dpms_mode);
}
std::unique_ptr<DrmDisplayComposition> DrmComposition::TakeDisplayComposition(
int display) {
return std::move(composition_map_[display]);
}
}