2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define LOG_TAG "hwc-drm-composition"
19 #include "drmcomposition.h"
22 #include "drmresources.h"
26 #include <cutils/log.h>
28 #include <sync/sync.h>
32 static const bool kUseOverlayPlanes = true;
34 DrmComposition::DrmComposition(DrmResources *drm, Importer *importer)
35 : drm_(drm), importer_(importer) {
36 for (DrmResources::PlaneIter iter = drm_->begin_planes();
37 iter != drm_->end_planes(); ++iter) {
38 if ((*iter)->type() == DRM_PLANE_TYPE_PRIMARY)
39 primary_planes_.push_back(*iter);
40 else if (kUseOverlayPlanes && (*iter)->type() == DRM_PLANE_TYPE_OVERLAY)
41 overlay_planes_.push_back(*iter);
45 DrmComposition::~DrmComposition() {
48 int DrmComposition::Init() {
49 for (DrmResources::ConnectorIter iter = drm_->begin_connectors();
50 iter != drm_->end_connectors(); ++iter) {
51 int display = (*iter)->display();
52 composition_map_[display].reset(new DrmDisplayComposition());
53 if (!composition_map_[display]) {
54 ALOGE("Failed to allocate new display composition\n");
57 int ret = composition_map_[(*iter)->display()]->Init(drm_, importer_);
59 ALOGE("Failed to init display composition for %d", (*iter)->display());
66 unsigned DrmComposition::GetRemainingLayers(int display,
67 unsigned num_needed) const {
68 DrmCrtc *crtc = drm_->GetCrtcForDisplay(display);
70 ALOGE("Failed to find crtc for display %d", display);
74 unsigned num_planes = 0;
75 for (std::vector<DrmPlane *>::const_iterator iter = primary_planes_.begin();
76 iter != primary_planes_.end(); ++iter) {
77 if ((*iter)->GetCrtcSupported(*crtc))
80 for (std::deque<DrmPlane *>::const_iterator iter = overlay_planes_.begin();
81 iter != overlay_planes_.end(); ++iter) {
82 if ((*iter)->GetCrtcSupported(*crtc))
85 return std::min(num_planes, num_needed);
88 int DrmComposition::AddLayer(int display, hwc_layer_1_t *layer,
90 DrmCrtc *crtc = drm_->GetCrtcForDisplay(display);
92 ALOGE("Failed to find crtc for display %d", display);
96 // Find a plane for the layer
97 DrmPlane *plane = NULL;
98 for (std::vector<DrmPlane *>::iterator iter = primary_planes_.begin();
99 iter != primary_planes_.end(); ++iter) {
100 if ((*iter)->GetCrtcSupported(*crtc)) {
102 primary_planes_.erase(iter);
106 for (std::deque<DrmPlane *>::iterator iter = overlay_planes_.begin();
107 !plane && iter != overlay_planes_.end(); ++iter) {
108 if ((*iter)->GetCrtcSupported(*crtc)) {
110 overlay_planes_.erase(iter);
115 ALOGE("Failed to find plane for display %d", display);
118 return composition_map_[display]->AddLayer(layer, bo, crtc, plane);
121 std::unique_ptr<DrmDisplayComposition> DrmComposition::TakeDisplayComposition(
123 return std::move(composition_map_[display]);