blob: 1aaf920136196c464e9442a7f0f60a659b6a1b4d [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"
Sean Paulaa18d912016-05-12 14:28:05 -040023#include "platform.h"
Sean Paulb386f1b2015-05-13 06:33:23 -070024
25#include <stdlib.h>
26
27#include <cutils/log.h>
Zach Reizner1946fa72015-08-14 11:14:38 -070028#include <cutils/properties.h>
Sean Paulb386f1b2015-05-13 06:33:23 -070029#include <sw_sync.h>
30#include <sync/sync.h>
31
32namespace android {
33
Sean Paulaa18d912016-05-12 14:28:05 -040034DrmComposition::DrmComposition(DrmResources *drm, Importer *importer,
35 Planner *planner)
36 : drm_(drm), importer_(importer), planner_(planner) {
Zach Reizner1946fa72015-08-14 11:14:38 -070037 char use_overlay_planes_prop[PROPERTY_VALUE_MAX];
38 property_get("hwc.drm.use_overlay_planes", use_overlay_planes_prop, "1");
39 bool use_overlay_planes = atoi(use_overlay_planes_prop);
40
Zach Reiznerff30b522015-10-28 19:08:45 -070041 for (auto &plane : drm->planes()) {
42 if (plane->type() == DRM_PLANE_TYPE_PRIMARY)
43 primary_planes_.push_back(plane.get());
44 else if (use_overlay_planes && plane->type() == DRM_PLANE_TYPE_OVERLAY)
45 overlay_planes_.push_back(plane.get());
Sean Paulb386f1b2015-05-13 06:33:23 -070046 }
47}
48
Sean Paulbdc67bf2015-09-21 10:04:02 -040049int DrmComposition::Init(uint64_t frame_no) {
Zach Reiznerff30b522015-10-28 19:08:45 -070050 for (auto &conn : drm_->connectors()) {
51 int display = conn->display();
Sean Paul98e73c82015-06-24 14:38:49 -070052 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
Sean Paulaa18d912016-05-12 14:28:05 -040061 int ret = composition_map_[display]->Init(drm_, crtc, importer_, planner_,
62 frame_no);
Sean Paul98e73c82015-06-24 14:38:49 -070063 if (ret) {
Zach Reizner7e88be92015-10-12 15:20:33 -070064 ALOGE("Failed to init display composition for %d", display);
Sean Paul98e73c82015-06-24 14:38:49 -070065 return ret;
66 }
Sean Paulb386f1b2015-05-13 06:33:23 -070067 }
Sean Paulb386f1b2015-05-13 06:33:23 -070068 return 0;
69}
70
Zach Reizner09807052015-08-13 14:53:41 -070071int DrmComposition::SetLayers(size_t num_displays,
Zach Reizner4a253652015-09-10 18:30:54 -070072 DrmCompositionDisplayLayersMap *maps) {
Zach Reizner09807052015-08-13 14:53:41 -070073 int ret = 0;
74 for (size_t display_index = 0; display_index < num_displays;
75 display_index++) {
Zach Reizner4a253652015-09-10 18:30:54 -070076 DrmCompositionDisplayLayersMap &map = maps[display_index];
Zach Reizner09807052015-08-13 14:53:41 -070077 int display = map.display;
78
Sean Paulc0b35482015-10-21 19:11:58 -040079 if (!drm_->GetConnectorForDisplay(display)) {
80 ALOGE("Invalid display given to SetLayers %d", display);
81 continue;
82 }
83
Zach Reizner5757e822015-10-16 19:06:31 -070084 ret = composition_map_[display]->SetLayers(
85 map.layers.data(), map.layers.size(), map.geometry_changed);
Zach Reizner09807052015-08-13 14:53:41 -070086 if (ret)
87 return ret;
88 }
89
Zach Reizner92f8e632015-10-12 17:47:13 -070090 return 0;
Sean Paulb386f1b2015-05-13 06:33:23 -070091}
92
Zach Reizner09807052015-08-13 14:53:41 -070093int DrmComposition::SetDpmsMode(int display, uint32_t dpms_mode) {
94 return composition_map_[display]->SetDpmsMode(dpms_mode);
Sean Pauldb7a17d2015-06-24 18:46:05 -070095}
96
Sean Paul57355412015-09-19 09:14:34 -040097int DrmComposition::SetDisplayMode(int display, const DrmMode &display_mode) {
98 return composition_map_[display]->SetDisplayMode(display_mode);
99}
100
Sean Paul98e73c82015-06-24 14:38:49 -0700101std::unique_ptr<DrmDisplayComposition> DrmComposition::TakeDisplayComposition(
102 int display) {
103 return std::move(composition_map_[display]);
Sean Paulb386f1b2015-05-13 06:33:23 -0700104}
Sean Paul2e46fbd2015-07-09 17:22:22 -0400105
Zach Reizner92f8e632015-10-12 17:47:13 -0700106int DrmComposition::Plan(std::map<int, DrmDisplayCompositor> &compositor_map) {
107 int ret = 0;
Zach Reiznerff30b522015-10-28 19:08:45 -0700108 for (auto &conn : drm_->connectors()) {
109 int display = conn->display();
Zach Reizner92f8e632015-10-12 17:47:13 -0700110 DrmDisplayComposition *comp = GetDisplayComposition(display);
111 ret = comp->Plan(compositor_map[display].squash_state(), &primary_planes_,
112 &overlay_planes_);
113 if (ret) {
114 ALOGE("Failed to plan composition for dislay %d", display);
115 return ret;
116 }
117 }
118
119 return 0;
120}
121
Sean Paul2e46fbd2015-07-09 17:22:22 -0400122int DrmComposition::DisableUnusedPlanes() {
Zach Reiznerff30b522015-10-28 19:08:45 -0700123 for (auto &conn : drm_->connectors()) {
124 int display = conn->display();
Sean Paul2e46fbd2015-07-09 17:22:22 -0400125 DrmDisplayComposition *comp = GetDisplayComposition(display);
126
127 /*
128 * Leave empty compositions alone
129 * TODO: re-visit this and potentially disable leftover planes after the
130 * active compositions have gobbled up all they can
131 */
Sean Paul57355412015-09-19 09:14:34 -0400132 if (comp->type() == DRM_COMPOSITION_TYPE_EMPTY ||
133 comp->type() == DRM_COMPOSITION_TYPE_MODESET)
Sean Paul2e46fbd2015-07-09 17:22:22 -0400134 continue;
135
136 DrmCrtc *crtc = drm_->GetCrtcForDisplay(display);
137 if (!crtc) {
138 ALOGE("Failed to find crtc for display %d", display);
139 continue;
140 }
141
142 for (std::vector<DrmPlane *>::iterator iter = primary_planes_.begin();
143 iter != primary_planes_.end(); ++iter) {
144 if ((*iter)->GetCrtcSupported(*crtc)) {
145 comp->AddPlaneDisable(*iter);
146 primary_planes_.erase(iter);
147 break;
148 }
149 }
150 for (std::vector<DrmPlane *>::iterator iter = overlay_planes_.begin();
151 iter != overlay_planes_.end();) {
152 if ((*iter)->GetCrtcSupported(*crtc)) {
153 comp->AddPlaneDisable(*iter);
154 iter = overlay_planes_.erase(iter);
155 } else {
156 iter++;
157 }
158 }
159 }
160 return 0;
161}
162
163DrmDisplayComposition *DrmComposition::GetDisplayComposition(int display) {
164 return composition_map_[display].get();
165}
Sean Paulb386f1b2015-05-13 06:33:23 -0700166}