blob: 0c0f394bf794612bf32300062bf1c27e733eaa01 [file] [log] [blame]
Sean Paulb386f1b2015-05-13 06:33:23 -07001/*
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#define LOG_TAG "hwc-drm-composition"
18
19#include "drmcomposition.h"
20#include "drmcrtc.h"
21#include "drmplane.h"
22#include "drmresources.h"
23
24#include <stdlib.h>
25
26#include <cutils/log.h>
27#include <sw_sync.h>
28#include <sync/sync.h>
29
30namespace android {
31
Sean Paulc51b0c52015-06-10 14:32:51 -040032static const bool kUseOverlayPlanes = true;
Sean Paulb386f1b2015-05-13 06:33:23 -070033
Sean Paul98e73c82015-06-24 14:38:49 -070034DrmComposition::DrmComposition(DrmResources *drm, Importer *importer)
35 : drm_(drm), importer_(importer) {
Sean Paulb386f1b2015-05-13 06:33:23 -070036 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);
42 }
43}
44
Sean Paulb386f1b2015-05-13 06:33:23 -070045int DrmComposition::Init() {
Sean Paul98e73c82015-06-24 14:38:49 -070046 for (DrmResources::ConnectorIter iter = drm_->begin_connectors();
47 iter != drm_->end_connectors(); ++iter) {
48 int display = (*iter)->display();
49 composition_map_[display].reset(new DrmDisplayComposition());
50 if (!composition_map_[display]) {
51 ALOGE("Failed to allocate new display composition\n");
52 return -ENOMEM;
53 }
Zach Reizner09807052015-08-13 14:53:41 -070054 DrmCrtc *crtc = drm_->GetCrtcForDisplay(display);
55 if (!crtc) {
56 ALOGE("Failed to find crtc for display %d", display);
57 return -ENODEV;
58 }
59 int ret = composition_map_[(*iter)->display()]->Init(drm_, crtc, importer_);
Sean Paul98e73c82015-06-24 14:38:49 -070060 if (ret) {
61 ALOGE("Failed to init display composition for %d", (*iter)->display());
62 return ret;
63 }
Sean Paulb386f1b2015-05-13 06:33:23 -070064 }
Sean Paulb386f1b2015-05-13 06:33:23 -070065 return 0;
66}
67
Zach Reizner09807052015-08-13 14:53:41 -070068int DrmComposition::SetLayers(size_t num_displays,
69 const DrmCompositionDisplayLayersMap *maps) {
70 int ret = 0;
71 for (size_t display_index = 0; display_index < num_displays;
72 display_index++) {
73 const DrmCompositionDisplayLayersMap &map = maps[display_index];
74 int display = map.display;
75
76 ret = composition_map_[display]->SetLayers(
77 map.layers, map.num_layers, map.layer_indices, &primary_planes_,
78 &overlay_planes_);
79 if (ret)
80 return ret;
81 }
82
83 return DisableUnusedPlanes();
Sean Paulb386f1b2015-05-13 06:33:23 -070084}
85
Zach Reizner09807052015-08-13 14:53:41 -070086int DrmComposition::SetDpmsMode(int display, uint32_t dpms_mode) {
87 return composition_map_[display]->SetDpmsMode(dpms_mode);
Sean Pauldb7a17d2015-06-24 18:46:05 -070088}
89
Sean Paul98e73c82015-06-24 14:38:49 -070090std::unique_ptr<DrmDisplayComposition> DrmComposition::TakeDisplayComposition(
91 int display) {
92 return std::move(composition_map_[display]);
Sean Paulb386f1b2015-05-13 06:33:23 -070093}
Sean Paul2e46fbd2015-07-09 17:22:22 -040094
95int DrmComposition::DisableUnusedPlanes() {
96 for (DrmResources::ConnectorIter iter = drm_->begin_connectors();
97 iter != drm_->end_connectors(); ++iter) {
98 int display = (*iter)->display();
99 DrmDisplayComposition *comp = GetDisplayComposition(display);
100
101 /*
102 * Leave empty compositions alone
103 * TODO: re-visit this and potentially disable leftover planes after the
104 * active compositions have gobbled up all they can
105 */
106 if (comp->type() == DRM_COMPOSITION_TYPE_EMPTY)
107 continue;
108
109 DrmCrtc *crtc = drm_->GetCrtcForDisplay(display);
110 if (!crtc) {
111 ALOGE("Failed to find crtc for display %d", display);
112 continue;
113 }
114
115 for (std::vector<DrmPlane *>::iterator iter = primary_planes_.begin();
116 iter != primary_planes_.end(); ++iter) {
117 if ((*iter)->GetCrtcSupported(*crtc)) {
118 comp->AddPlaneDisable(*iter);
119 primary_planes_.erase(iter);
120 break;
121 }
122 }
123 for (std::vector<DrmPlane *>::iterator iter = overlay_planes_.begin();
124 iter != overlay_planes_.end();) {
125 if ((*iter)->GetCrtcSupported(*crtc)) {
126 comp->AddPlaneDisable(*iter);
127 iter = overlay_planes_.erase(iter);
128 } else {
129 iter++;
130 }
131 }
132 }
133 return 0;
134}
135
136DrmDisplayComposition *DrmComposition::GetDisplayComposition(int display) {
137 return composition_map_[display].get();
138}
Sean Paulb386f1b2015-05-13 06:33:23 -0700139}