blob: fd9678c8cef921b245b99beed2f567f3522cf708 [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,
Roman Stratiienko67cebf52021-12-17 13:31:27 +020073 std::map<size_t, DrmHwcLayer *> &layers, std::vector<DrmPlane *> *planes) {
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +020074 int ret = 0;
Sean Paul4c4646e2016-05-10 04:19:24 -040075 for (auto i = layers.begin(); i != layers.end();) {
76 if (!i->second->protected_usage()) {
77 ++i;
78 continue;
79 }
80
Roman Stratiienko67cebf52021-12-17 13:31:27 +020081 ret = Emplace(composition, planes, std::make_pair(i->first, i->second));
Alexandru Gheorghe2234d372018-10-09 16:25:28 +010082 if (ret) {
Sean Paul4c4646e2016-05-10 04:19:24 -040083 ALOGE("Failed to dedicate protected layer! Dropping it.");
Alexandru Gheorghe2234d372018-10-09 16:25:28 +010084 return ret;
85 }
Sean Paul4c4646e2016-05-10 04:19:24 -040086
Sean Paul4c4646e2016-05-10 04:19:24 -040087 i = layers.erase(i);
88 }
89
Adrian Salido45002322017-04-10 21:44:21 -070090 return 0;
91}
92
Sean Paul4c4646e2016-05-10 04:19:24 -040093int PlanStageGreedy::ProvisionPlanes(
94 std::vector<DrmCompositionPlane> *composition,
Roman Stratiienko67cebf52021-12-17 13:31:27 +020095 std::map<size_t, DrmHwcLayer *> &layers, std::vector<DrmPlane *> *planes) {
Sean Paul4c4646e2016-05-10 04:19:24 -040096 // Fill up the remaining planes
97 for (auto i = layers.begin(); i != layers.end(); i = layers.erase(i)) {
Roman Stratiienko67cebf52021-12-17 13:31:27 +020098 int ret = Emplace(composition, planes, std::make_pair(i->first, i->second));
Sean Paul4c4646e2016-05-10 04:19:24 -040099 // We don't have any planes left
100 if (ret == -ENOENT)
101 break;
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200102
103 if (ret) {
John Stultz66763d52021-08-24 04:59:25 +0000104 ALOGV("Failed to emplace layer %zu, dropping it", i->first);
Alexandru Gheorghe2234d372018-10-09 16:25:28 +0100105 return ret;
106 }
Sean Paul4c4646e2016-05-10 04:19:24 -0400107 }
108
Sean Paul4c4646e2016-05-10 04:19:24 -0400109 return 0;
110}
Sean Paulf72cccd2018-08-27 13:59:08 -0400111} // namespace android