blob: 58db2ea45aa213b1a87135e6c4e66a030e22a472 [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
Lowry Li9b6cafd2018-08-28 17:58:21 +080047int Planner::PlanStage::ValidatePlane(DrmPlane *plane, DrmHwcLayer *layer) {
48 int ret = 0;
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +020049 uint64_t blend = UINT64_MAX;
Lowry Li9b6cafd2018-08-28 17:58:21 +080050
51 if ((plane->rotation_property().id() == 0) &&
52 layer->transform != DrmHwcTransform::kIdentity) {
53 ALOGE("Rotation is not supported on plane %d", plane->id());
54 return -EINVAL;
55 }
56
57 if (plane->alpha_property().id() == 0 && layer->alpha != 0xffff) {
58 ALOGE("Alpha is not supported on plane %d", plane->id());
59 return -EINVAL;
60 }
61
62 if (plane->blend_property().id() == 0) {
63 if ((layer->blending != DrmHwcBlending::kNone) &&
64 (layer->blending != DrmHwcBlending::kPreMult)) {
65 ALOGE("Blending is not supported on plane %d", plane->id());
66 return -EINVAL;
67 }
68 } else {
69 switch (layer->blending) {
70 case DrmHwcBlending::kPreMult:
71 std::tie(blend, ret) = plane->blend_property().GetEnumValueWithName(
72 "Pre-multiplied");
73 break;
74 case DrmHwcBlending::kCoverage:
75 std::tie(blend, ret) = plane->blend_property().GetEnumValueWithName(
76 "Coverage");
77 break;
78 case DrmHwcBlending::kNone:
79 default:
80 std::tie(blend,
81 ret) = plane->blend_property().GetEnumValueWithName("None");
82 break;
83 }
84 if (ret)
85 ALOGE("Expected a valid blend mode on plane %d", plane->id());
86 }
87
Roman Kovalivskyi15a453a2020-09-10 12:07:37 +030088 uint32_t format = layer->buffer->format;
89 if (!plane->IsFormatSupported(format)) {
90 ALOGE("Plane %d does not supports %c%c%c%c format", plane->id(), format,
91 format >> 8, format >> 16, format >> 24);
92 return -EINVAL;
93 }
94
Lowry Li9b6cafd2018-08-28 17:58:21 +080095 return ret;
96}
97
Sean Paul4c4646e2016-05-10 04:19:24 -040098std::tuple<int, std::vector<DrmCompositionPlane>> Planner::ProvisionPlanes(
Rob Herringaf0d9752018-05-04 16:34:19 -050099 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
Sean Paul4c4646e2016-05-10 04:19:24 -0400100 std::vector<DrmPlane *> *primary_planes,
101 std::vector<DrmPlane *> *overlay_planes) {
102 std::vector<DrmCompositionPlane> composition;
Sean Paulf72cccd2018-08-27 13:59:08 -0400103 std::vector<DrmPlane *> planes = GetUsablePlanes(crtc, primary_planes,
104 overlay_planes);
Sean Paul4c4646e2016-05-10 04:19:24 -0400105 if (planes.empty()) {
106 ALOGE("Display %d has no usable planes", crtc->display());
107 return std::make_tuple(-ENODEV, std::vector<DrmCompositionPlane>());
108 }
109
Sean Paul4c4646e2016-05-10 04:19:24 -0400110 // Go through the provisioning stages and provision planes
111 for (auto &i : stages_) {
112 int ret = i->ProvisionPlanes(&composition, layers, crtc, &planes);
113 if (ret) {
114 ALOGE("Failed provision stage with ret %d", ret);
115 return std::make_tuple(ret, std::vector<DrmCompositionPlane>());
116 }
117 }
118
Sean Paul4c4646e2016-05-10 04:19:24 -0400119 return std::make_tuple(0, std::move(composition));
120}
121
122int PlanStageProtected::ProvisionPlanes(
123 std::vector<DrmCompositionPlane> *composition,
124 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
125 std::vector<DrmPlane *> *planes) {
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +0200126 int ret = 0;
Sean Paul4c4646e2016-05-10 04:19:24 -0400127 for (auto i = layers.begin(); i != layers.end();) {
128 if (!i->second->protected_usage()) {
129 ++i;
130 continue;
131 }
132
133 ret = Emplace(composition, planes, DrmCompositionPlane::Type::kLayer, crtc,
Lowry Li9b6cafd2018-08-28 17:58:21 +0800134 std::make_pair(i->first, i->second));
Alexandru Gheorghe2234d372018-10-09 16:25:28 +0100135 if (ret) {
Sean Paul4c4646e2016-05-10 04:19:24 -0400136 ALOGE("Failed to dedicate protected layer! Dropping it.");
Alexandru Gheorghe2234d372018-10-09 16:25:28 +0100137 return ret;
138 }
Sean Paul4c4646e2016-05-10 04:19:24 -0400139
Sean Paul4c4646e2016-05-10 04:19:24 -0400140 i = layers.erase(i);
141 }
142
Adrian Salido45002322017-04-10 21:44:21 -0700143 return 0;
144}
145
Sean Paul4c4646e2016-05-10 04:19:24 -0400146int PlanStageGreedy::ProvisionPlanes(
147 std::vector<DrmCompositionPlane> *composition,
148 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
149 std::vector<DrmPlane *> *planes) {
150 // Fill up the remaining planes
151 for (auto i = layers.begin(); i != layers.end(); i = layers.erase(i)) {
152 int ret = Emplace(composition, planes, DrmCompositionPlane::Type::kLayer,
Lowry Li9b6cafd2018-08-28 17:58:21 +0800153 crtc, std::make_pair(i->first, i->second));
Sean Paul4c4646e2016-05-10 04:19:24 -0400154 // We don't have any planes left
155 if (ret == -ENOENT)
156 break;
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200157
158 if (ret) {
Sean Paul4c4646e2016-05-10 04:19:24 -0400159 ALOGE("Failed to emplace layer %zu, dropping it", i->first);
Alexandru Gheorghe2234d372018-10-09 16:25:28 +0100160 return ret;
161 }
Sean Paul4c4646e2016-05-10 04:19:24 -0400162 }
163
Sean Paul4c4646e2016-05-10 04:19:24 -0400164 return 0;
165}
Sean Paulf72cccd2018-08-27 13:59:08 -0400166} // namespace android