blob: b6c39d05a3a1115ffb696a51d6c75b0fe15651ef [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
19#include "drmresources.h"
20#include "platform.h"
21
John Stultz9057a6f2018-04-26 12:05:55 -070022#include <log/log.h>
Sean Paul4c4646e2016-05-10 04:19:24 -040023
24namespace android {
25
26std::vector<DrmPlane *> Planner::GetUsablePlanes(
27 DrmCrtc *crtc, std::vector<DrmPlane *> *primary_planes,
28 std::vector<DrmPlane *> *overlay_planes) {
29 std::vector<DrmPlane *> usable_planes;
30 std::copy_if(primary_planes->begin(), primary_planes->end(),
31 std::back_inserter(usable_planes),
32 [=](DrmPlane *plane) { return plane->GetCrtcSupported(*crtc); });
33 std::copy_if(overlay_planes->begin(), overlay_planes->end(),
34 std::back_inserter(usable_planes),
35 [=](DrmPlane *plane) { return plane->GetCrtcSupported(*crtc); });
36 return usable_planes;
37}
38
39std::tuple<int, std::vector<DrmCompositionPlane>> Planner::ProvisionPlanes(
Rob Herringaf0d9752018-05-04 16:34:19 -050040 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
Sean Paul4c4646e2016-05-10 04:19:24 -040041 std::vector<DrmPlane *> *primary_planes,
42 std::vector<DrmPlane *> *overlay_planes) {
43 std::vector<DrmCompositionPlane> composition;
44 std::vector<DrmPlane *> planes =
45 GetUsablePlanes(crtc, primary_planes, overlay_planes);
46 if (planes.empty()) {
47 ALOGE("Display %d has no usable planes", crtc->display());
48 return std::make_tuple(-ENODEV, std::vector<DrmCompositionPlane>());
49 }
50
Sean Paul4c4646e2016-05-10 04:19:24 -040051 // Go through the provisioning stages and provision planes
52 for (auto &i : stages_) {
53 int ret = i->ProvisionPlanes(&composition, layers, crtc, &planes);
54 if (ret) {
55 ALOGE("Failed provision stage with ret %d", ret);
56 return std::make_tuple(ret, std::vector<DrmCompositionPlane>());
57 }
58 }
59
Sean Paul4c4646e2016-05-10 04:19:24 -040060 return std::make_tuple(0, std::move(composition));
61}
62
63int PlanStageProtected::ProvisionPlanes(
64 std::vector<DrmCompositionPlane> *composition,
65 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
66 std::vector<DrmPlane *> *planes) {
67 int ret;
68 int protected_zorder = -1;
69 for (auto i = layers.begin(); i != layers.end();) {
70 if (!i->second->protected_usage()) {
71 ++i;
72 continue;
73 }
74
75 ret = Emplace(composition, planes, DrmCompositionPlane::Type::kLayer, crtc,
76 i->first);
77 if (ret)
78 ALOGE("Failed to dedicate protected layer! Dropping it.");
79
80 protected_zorder = i->first;
81 i = layers.erase(i);
82 }
83
Adrian Salido45002322017-04-10 21:44:21 -070084 return 0;
85}
86
Sean Paul4c4646e2016-05-10 04:19:24 -040087int PlanStageGreedy::ProvisionPlanes(
88 std::vector<DrmCompositionPlane> *composition,
89 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
90 std::vector<DrmPlane *> *planes) {
91 // Fill up the remaining planes
92 for (auto i = layers.begin(); i != layers.end(); i = layers.erase(i)) {
93 int ret = Emplace(composition, planes, DrmCompositionPlane::Type::kLayer,
94 crtc, i->first);
95 // We don't have any planes left
96 if (ret == -ENOENT)
97 break;
98 else if (ret)
99 ALOGE("Failed to emplace layer %zu, dropping it", i->first);
100 }
101
Sean Paul4c4646e2016-05-10 04:19:24 -0400102 return 0;
103}
104}