blob: 4b293ee7912128e40b4a6bb1b545362e49f2f0ec [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>
Zach Reizner1946fa72015-08-14 11:14:38 -070027#include <cutils/properties.h>
Sean Paulb386f1b2015-05-13 06:33:23 -070028#include <sw_sync.h>
29#include <sync/sync.h>
30
31namespace android {
32
Sean Paul98e73c82015-06-24 14:38:49 -070033DrmComposition::DrmComposition(DrmResources *drm, Importer *importer)
34 : drm_(drm), importer_(importer) {
Zach Reizner1946fa72015-08-14 11:14:38 -070035 char use_overlay_planes_prop[PROPERTY_VALUE_MAX];
36 property_get("hwc.drm.use_overlay_planes", use_overlay_planes_prop, "1");
37 bool use_overlay_planes = atoi(use_overlay_planes_prop);
38
Sean Paulb386f1b2015-05-13 06:33:23 -070039 for (DrmResources::PlaneIter iter = drm_->begin_planes();
40 iter != drm_->end_planes(); ++iter) {
41 if ((*iter)->type() == DRM_PLANE_TYPE_PRIMARY)
42 primary_planes_.push_back(*iter);
Zach Reizner1946fa72015-08-14 11:14:38 -070043 else if (use_overlay_planes && (*iter)->type() == DRM_PLANE_TYPE_OVERLAY)
Sean Paulb386f1b2015-05-13 06:33:23 -070044 overlay_planes_.push_back(*iter);
45 }
46}
47
Sean Paulbdc67bf2015-09-21 10:04:02 -040048int DrmComposition::Init(uint64_t frame_no) {
Sean Paul98e73c82015-06-24 14:38:49 -070049 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");
55 return -ENOMEM;
56 }
Sean Paul2143d3b2015-09-04 01:33:06 -040057
58 // If the display hasn't been modeset yet, this will be NULL
Zach Reizner09807052015-08-13 14:53:41 -070059 DrmCrtc *crtc = drm_->GetCrtcForDisplay(display);
Sean Paul2143d3b2015-09-04 01:33:06 -040060
Zach Reizner7e88be92015-10-12 15:20:33 -070061 int ret = composition_map_[display]->Init(drm_, crtc, importer_, frame_no);
Sean Paul98e73c82015-06-24 14:38:49 -070062 if (ret) {
Zach Reizner7e88be92015-10-12 15:20:33 -070063 ALOGE("Failed to init display composition for %d", display);
Sean Paul98e73c82015-06-24 14:38:49 -070064 return ret;
65 }
Sean Paulb386f1b2015-05-13 06:33:23 -070066 }
Sean Paulb386f1b2015-05-13 06:33:23 -070067 return 0;
68}
69
Zach Reizner09807052015-08-13 14:53:41 -070070int DrmComposition::SetLayers(size_t num_displays,
Zach Reizner4a253652015-09-10 18:30:54 -070071 DrmCompositionDisplayLayersMap *maps) {
Zach Reizner09807052015-08-13 14:53:41 -070072 int ret = 0;
73 for (size_t display_index = 0; display_index < num_displays;
74 display_index++) {
Zach Reizner4a253652015-09-10 18:30:54 -070075 DrmCompositionDisplayLayersMap &map = maps[display_index];
Zach Reizner09807052015-08-13 14:53:41 -070076 int display = map.display;
77
78 ret = composition_map_[display]->SetLayers(
Zach Reizner4a253652015-09-10 18:30:54 -070079 map.layers.data(), map.layers.size(), &primary_planes_,
Zach Reizner09807052015-08-13 14:53:41 -070080 &overlay_planes_);
81 if (ret)
82 return ret;
83 }
84
85 return DisableUnusedPlanes();
Sean Paulb386f1b2015-05-13 06:33:23 -070086}
87
Zach Reizner09807052015-08-13 14:53:41 -070088int DrmComposition::SetDpmsMode(int display, uint32_t dpms_mode) {
89 return composition_map_[display]->SetDpmsMode(dpms_mode);
Sean Pauldb7a17d2015-06-24 18:46:05 -070090}
91
Sean Paul57355412015-09-19 09:14:34 -040092int DrmComposition::SetDisplayMode(int display, const DrmMode &display_mode) {
93 return composition_map_[display]->SetDisplayMode(display_mode);
94}
95
Sean Paul98e73c82015-06-24 14:38:49 -070096std::unique_ptr<DrmDisplayComposition> DrmComposition::TakeDisplayComposition(
97 int display) {
98 return std::move(composition_map_[display]);
Sean Paulb386f1b2015-05-13 06:33:23 -070099}
Sean Paul2e46fbd2015-07-09 17:22:22 -0400100
101int DrmComposition::DisableUnusedPlanes() {
102 for (DrmResources::ConnectorIter iter = drm_->begin_connectors();
103 iter != drm_->end_connectors(); ++iter) {
104 int display = (*iter)->display();
105 DrmDisplayComposition *comp = GetDisplayComposition(display);
106
107 /*
108 * Leave empty compositions alone
109 * TODO: re-visit this and potentially disable leftover planes after the
110 * active compositions have gobbled up all they can
111 */
Sean Paul57355412015-09-19 09:14:34 -0400112 if (comp->type() == DRM_COMPOSITION_TYPE_EMPTY ||
113 comp->type() == DRM_COMPOSITION_TYPE_MODESET)
Sean Paul2e46fbd2015-07-09 17:22:22 -0400114 continue;
115
116 DrmCrtc *crtc = drm_->GetCrtcForDisplay(display);
117 if (!crtc) {
118 ALOGE("Failed to find crtc for display %d", display);
119 continue;
120 }
121
122 for (std::vector<DrmPlane *>::iterator iter = primary_planes_.begin();
123 iter != primary_planes_.end(); ++iter) {
124 if ((*iter)->GetCrtcSupported(*crtc)) {
125 comp->AddPlaneDisable(*iter);
126 primary_planes_.erase(iter);
127 break;
128 }
129 }
130 for (std::vector<DrmPlane *>::iterator iter = overlay_planes_.begin();
131 iter != overlay_planes_.end();) {
132 if ((*iter)->GetCrtcSupported(*crtc)) {
133 comp->AddPlaneDisable(*iter);
134 iter = overlay_planes_.erase(iter);
135 } else {
136 iter++;
137 }
138 }
139 }
140 return 0;
141}
142
143DrmDisplayComposition *DrmComposition::GetDisplayComposition(int display) {
144 return composition_map_[display].get();
145}
Sean Paulb386f1b2015-05-13 06:33:23 -0700146}