blob: 2d24499c74dddebeb2a632fe9e45aca0238b114a [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);
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030030 return planner;
31}
32
Sean Paul4c4646e2016-05-10 04:19:24 -040033std::vector<DrmPlane *> Planner::GetUsablePlanes(
34 DrmCrtc *crtc, std::vector<DrmPlane *> *primary_planes,
35 std::vector<DrmPlane *> *overlay_planes) {
36 std::vector<DrmPlane *> usable_planes;
37 std::copy_if(primary_planes->begin(), primary_planes->end(),
38 std::back_inserter(usable_planes),
39 [=](DrmPlane *plane) { return plane->GetCrtcSupported(*crtc); });
40 std::copy_if(overlay_planes->begin(), overlay_planes->end(),
41 std::back_inserter(usable_planes),
42 [=](DrmPlane *plane) { return plane->GetCrtcSupported(*crtc); });
43 return usable_planes;
44}
45
46std::tuple<int, std::vector<DrmCompositionPlane>> Planner::ProvisionPlanes(
Rob Herringaf0d9752018-05-04 16:34:19 -050047 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
Sean Paul4c4646e2016-05-10 04:19:24 -040048 std::vector<DrmPlane *> *primary_planes,
49 std::vector<DrmPlane *> *overlay_planes) {
50 std::vector<DrmCompositionPlane> composition;
Sean Paulf72cccd2018-08-27 13:59:08 -040051 std::vector<DrmPlane *> planes = GetUsablePlanes(crtc, primary_planes,
52 overlay_planes);
Sean Paul4c4646e2016-05-10 04:19:24 -040053 if (planes.empty()) {
54 ALOGE("Display %d has no usable planes", crtc->display());
55 return std::make_tuple(-ENODEV, std::vector<DrmCompositionPlane>());
56 }
57
Sean Paul4c4646e2016-05-10 04:19:24 -040058 // Go through the provisioning stages and provision planes
Roman Stratiienko9a6c9de2021-12-17 15:01:18 +020059 int ret = ProvisionPlanesInternal(&composition, layers, &planes);
Roman Stratiienkofc014f52021-12-23 19:04:29 +020060 if (ret != 0) {
Roman Stratiienko9a6c9de2021-12-17 15:01:18 +020061 ALOGV("Failed provision stage with ret %d", ret);
62 return std::make_tuple(ret, std::vector<DrmCompositionPlane>());
Sean Paul4c4646e2016-05-10 04:19:24 -040063 }
64
Sean Paul4c4646e2016-05-10 04:19:24 -040065 return std::make_tuple(0, std::move(composition));
66}
67
Roman Stratiienko9a6c9de2021-12-17 15:01:18 +020068int Planner::ProvisionPlanesInternal(
Sean Paul4c4646e2016-05-10 04:19:24 -040069 std::vector<DrmCompositionPlane> *composition,
Roman Stratiienko67cebf52021-12-17 13:31:27 +020070 std::map<size_t, DrmHwcLayer *> &layers, std::vector<DrmPlane *> *planes) {
Sean Paul4c4646e2016-05-10 04:19:24 -040071 // Fill up the remaining planes
72 for (auto i = layers.begin(); i != layers.end(); i = layers.erase(i)) {
Roman Stratiienko67cebf52021-12-17 13:31:27 +020073 int ret = Emplace(composition, planes, std::make_pair(i->first, i->second));
Sean Paul4c4646e2016-05-10 04:19:24 -040074 // We don't have any planes left
75 if (ret == -ENOENT)
76 break;
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020077
Roman Stratiienkofc014f52021-12-23 19:04:29 +020078 if (ret != 0) {
John Stultz66763d52021-08-24 04:59:25 +000079 ALOGV("Failed to emplace layer %zu, dropping it", i->first);
Alexandru Gheorghe2234d372018-10-09 16:25:28 +010080 return ret;
81 }
Sean Paul4c4646e2016-05-10 04:19:24 -040082 }
83
Sean Paul4c4646e2016-05-10 04:19:24 -040084 return 0;
85}
Sean Paulf72cccd2018-08-27 13:59:08 -040086} // namespace android