blob: 9db03c36e99c5187aec204020bb5945faff63cba [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
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020028std::unique_ptr<Planner> Planner::CreateInstance(DrmDevice * /*device*/) {
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030029 std::unique_ptr<Planner> planner(new Planner);
30 planner->AddStage<PlanStageGreedy>();
31 return planner;
32}
33
Sean Paul4c4646e2016-05-10 04:19:24 -040034std::vector<DrmPlane *> Planner::GetUsablePlanes(
35 DrmCrtc *crtc, std::vector<DrmPlane *> *primary_planes,
36 std::vector<DrmPlane *> *overlay_planes) {
37 std::vector<DrmPlane *> usable_planes;
38 std::copy_if(primary_planes->begin(), primary_planes->end(),
39 std::back_inserter(usable_planes),
40 [=](DrmPlane *plane) { return plane->GetCrtcSupported(*crtc); });
41 std::copy_if(overlay_planes->begin(), overlay_planes->end(),
42 std::back_inserter(usable_planes),
43 [=](DrmPlane *plane) { return plane->GetCrtcSupported(*crtc); });
44 return usable_planes;
45}
46
47std::tuple<int, std::vector<DrmCompositionPlane>> Planner::ProvisionPlanes(
Rob Herringaf0d9752018-05-04 16:34:19 -050048 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
Sean Paul4c4646e2016-05-10 04:19:24 -040049 std::vector<DrmPlane *> *primary_planes,
50 std::vector<DrmPlane *> *overlay_planes) {
51 std::vector<DrmCompositionPlane> composition;
Sean Paulf72cccd2018-08-27 13:59:08 -040052 std::vector<DrmPlane *> planes = GetUsablePlanes(crtc, primary_planes,
53 overlay_planes);
Sean Paul4c4646e2016-05-10 04:19:24 -040054 if (planes.empty()) {
55 ALOGE("Display %d has no usable planes", crtc->display());
56 return std::make_tuple(-ENODEV, std::vector<DrmCompositionPlane>());
57 }
58
Sean Paul4c4646e2016-05-10 04:19:24 -040059 // Go through the provisioning stages and provision planes
60 for (auto &i : stages_) {
Matvii Zorinf0757c22021-01-18 15:54:22 +020061 int ret = i->ProvisionPlanes(&composition, layers, &planes);
Sean Paul4c4646e2016-05-10 04:19:24 -040062 if (ret) {
John Stultz66763d52021-08-24 04:59:25 +000063 ALOGV("Failed provision stage with ret %d", ret);
Sean Paul4c4646e2016-05-10 04:19:24 -040064 return std::make_tuple(ret, std::vector<DrmCompositionPlane>());
65 }
66 }
67
Sean Paul4c4646e2016-05-10 04:19:24 -040068 return std::make_tuple(0, std::move(composition));
69}
70
71int PlanStageProtected::ProvisionPlanes(
72 std::vector<DrmCompositionPlane> *composition,
Matvii Zorinf0757c22021-01-18 15:54:22 +020073 std::map<size_t, DrmHwcLayer *> &layers,
Sean Paul4c4646e2016-05-10 04:19:24 -040074 std::vector<DrmPlane *> *planes) {
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +020075 int ret = 0;
Sean Paul4c4646e2016-05-10 04:19:24 -040076 for (auto i = layers.begin(); i != layers.end();) {
77 if (!i->second->protected_usage()) {
78 ++i;
79 continue;
80 }
81
Matvii Zorinf0757c22021-01-18 15:54:22 +020082 ret = Emplace(composition, planes, DrmCompositionPlane::Type::kLayer,
Lowry Li9b6cafd2018-08-28 17:58:21 +080083 std::make_pair(i->first, i->second));
Alexandru Gheorghe2234d372018-10-09 16:25:28 +010084 if (ret) {
Sean Paul4c4646e2016-05-10 04:19:24 -040085 ALOGE("Failed to dedicate protected layer! Dropping it.");
Alexandru Gheorghe2234d372018-10-09 16:25:28 +010086 return ret;
87 }
Sean Paul4c4646e2016-05-10 04:19:24 -040088
Sean Paul4c4646e2016-05-10 04:19:24 -040089 i = layers.erase(i);
90 }
91
Adrian Salido45002322017-04-10 21:44:21 -070092 return 0;
93}
94
Sean Paul4c4646e2016-05-10 04:19:24 -040095int PlanStageGreedy::ProvisionPlanes(
96 std::vector<DrmCompositionPlane> *composition,
Matvii Zorinf0757c22021-01-18 15:54:22 +020097 std::map<size_t, DrmHwcLayer *> &layers,
Sean Paul4c4646e2016-05-10 04:19:24 -040098 std::vector<DrmPlane *> *planes) {
99 // Fill up the remaining planes
100 for (auto i = layers.begin(); i != layers.end(); i = layers.erase(i)) {
101 int ret = Emplace(composition, planes, DrmCompositionPlane::Type::kLayer,
Matvii Zorinf0757c22021-01-18 15:54:22 +0200102 std::make_pair(i->first, i->second));
Sean Paul4c4646e2016-05-10 04:19:24 -0400103 // We don't have any planes left
104 if (ret == -ENOENT)
105 break;
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200106
107 if (ret) {
John Stultz66763d52021-08-24 04:59:25 +0000108 ALOGV("Failed to emplace layer %zu, dropping it", i->first);
Alexandru Gheorghe2234d372018-10-09 16:25:28 +0100109 return ret;
110 }
Sean Paul4c4646e2016-05-10 04:19:24 -0400111 }
112
Sean Paul4c4646e2016-05-10 04:19:24 -0400113 return 0;
114}
Sean Paulf72cccd2018-08-27 13:59:08 -0400115} // namespace android