blob: f43e314bd4c9f106137c5ed09267e05a3a3d46f9 [file] [log] [blame]
Sean Paul4c4646e2016-05-10 04:19:24 -04001/*
2 * Copyright (C) 2016 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-platform"
18
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030019#include "Planner.h"
Sean Paul4c4646e2016-05-10 04:19:24 -040020
Roman Stratiienkod21071f2021-03-09 21:56:50 +020021#include <algorithm>
Sean Paul4c4646e2016-05-10 04:19:24 -040022
Roman Stratiienko13cc3662020-08-29 21:35:39 +030023#include "drm/DrmDevice.h"
Roman Stratiienkod21071f2021-03-09 21:56:50 +020024#include "utils/log.h"
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030025
Sean Paul4c4646e2016-05-10 04:19:24 -040026namespace android {
27
28std::vector<DrmPlane *> Planner::GetUsablePlanes(
29 DrmCrtc *crtc, std::vector<DrmPlane *> *primary_planes,
30 std::vector<DrmPlane *> *overlay_planes) {
31 std::vector<DrmPlane *> usable_planes;
32 std::copy_if(primary_planes->begin(), primary_planes->end(),
33 std::back_inserter(usable_planes),
34 [=](DrmPlane *plane) { return plane->GetCrtcSupported(*crtc); });
35 std::copy_if(overlay_planes->begin(), overlay_planes->end(),
36 std::back_inserter(usable_planes),
37 [=](DrmPlane *plane) { return plane->GetCrtcSupported(*crtc); });
38 return usable_planes;
39}
40
41std::tuple<int, std::vector<DrmCompositionPlane>> Planner::ProvisionPlanes(
Rob Herringaf0d9752018-05-04 16:34:19 -050042 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
Sean Paul4c4646e2016-05-10 04:19:24 -040043 std::vector<DrmPlane *> *primary_planes,
44 std::vector<DrmPlane *> *overlay_planes) {
45 std::vector<DrmCompositionPlane> composition;
Sean Paulf72cccd2018-08-27 13:59:08 -040046 std::vector<DrmPlane *> planes = GetUsablePlanes(crtc, primary_planes,
47 overlay_planes);
Sean Paul4c4646e2016-05-10 04:19:24 -040048 if (planes.empty()) {
49 ALOGE("Display %d has no usable planes", crtc->display());
50 return std::make_tuple(-ENODEV, std::vector<DrmCompositionPlane>());
51 }
52
Sean Paul4c4646e2016-05-10 04:19:24 -040053 // Go through the provisioning stages and provision planes
Roman Stratiienko9a6c9de2021-12-17 15:01:18 +020054 int ret = ProvisionPlanesInternal(&composition, layers, &planes);
Roman Stratiienkofc014f52021-12-23 19:04:29 +020055 if (ret != 0) {
Roman Stratiienko9a6c9de2021-12-17 15:01:18 +020056 ALOGV("Failed provision stage with ret %d", ret);
57 return std::make_tuple(ret, std::vector<DrmCompositionPlane>());
Sean Paul4c4646e2016-05-10 04:19:24 -040058 }
59
Sean Paul4c4646e2016-05-10 04:19:24 -040060 return std::make_tuple(0, std::move(composition));
61}
62
Roman Stratiienko9a6c9de2021-12-17 15:01:18 +020063int Planner::ProvisionPlanesInternal(
Sean Paul4c4646e2016-05-10 04:19:24 -040064 std::vector<DrmCompositionPlane> *composition,
Roman Stratiienko67cebf52021-12-17 13:31:27 +020065 std::map<size_t, DrmHwcLayer *> &layers, std::vector<DrmPlane *> *planes) {
Sean Paul4c4646e2016-05-10 04:19:24 -040066 // Fill up the remaining planes
67 for (auto i = layers.begin(); i != layers.end(); i = layers.erase(i)) {
Roman Stratiienko67cebf52021-12-17 13:31:27 +020068 int ret = Emplace(composition, planes, std::make_pair(i->first, i->second));
Sean Paul4c4646e2016-05-10 04:19:24 -040069 // We don't have any planes left
70 if (ret == -ENOENT)
71 break;
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020072
Roman Stratiienkofc014f52021-12-23 19:04:29 +020073 if (ret != 0) {
John Stultz66763d52021-08-24 04:59:25 +000074 ALOGV("Failed to emplace layer %zu, dropping it", i->first);
Alexandru Gheorghe2234d372018-10-09 16:25:28 +010075 return ret;
76 }
Sean Paul4c4646e2016-05-10 04:19:24 -040077 }
78
Sean Paul4c4646e2016-05-10 04:19:24 -040079 return 0;
80}
Sean Paulf72cccd2018-08-27 13:59:08 -040081} // namespace android