blob: fb6a8c3f130956e0fb91874d245e1a5c12ed16b8 [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
John Stultz9057a6f2018-04-26 12:05:55 -070021#include <log/log.h>
Sean Paul4c4646e2016-05-10 04:19:24 -040022
Roman Stratiienko13cc3662020-08-29 21:35:39 +030023#include "drm/DrmDevice.h"
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030024
Sean Paul4c4646e2016-05-10 04:19:24 -040025namespace android {
26
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020027std::unique_ptr<Planner> Planner::CreateInstance(DrmDevice * /*device*/) {
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030028 std::unique_ptr<Planner> planner(new Planner);
29 planner->AddStage<PlanStageGreedy>();
30 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
Lowry Li9b6cafd2018-08-28 17:58:21 +080046int Planner::PlanStage::ValidatePlane(DrmPlane *plane, DrmHwcLayer *layer) {
47 int ret = 0;
48 uint64_t blend;
49
50 if ((plane->rotation_property().id() == 0) &&
51 layer->transform != DrmHwcTransform::kIdentity) {
52 ALOGE("Rotation is not supported on plane %d", plane->id());
53 return -EINVAL;
54 }
55
56 if (plane->alpha_property().id() == 0 && layer->alpha != 0xffff) {
57 ALOGE("Alpha is not supported on plane %d", plane->id());
58 return -EINVAL;
59 }
60
61 if (plane->blend_property().id() == 0) {
62 if ((layer->blending != DrmHwcBlending::kNone) &&
63 (layer->blending != DrmHwcBlending::kPreMult)) {
64 ALOGE("Blending is not supported on plane %d", plane->id());
65 return -EINVAL;
66 }
67 } else {
68 switch (layer->blending) {
69 case DrmHwcBlending::kPreMult:
70 std::tie(blend, ret) = plane->blend_property().GetEnumValueWithName(
71 "Pre-multiplied");
72 break;
73 case DrmHwcBlending::kCoverage:
74 std::tie(blend, ret) = plane->blend_property().GetEnumValueWithName(
75 "Coverage");
76 break;
77 case DrmHwcBlending::kNone:
78 default:
79 std::tie(blend,
80 ret) = plane->blend_property().GetEnumValueWithName("None");
81 break;
82 }
83 if (ret)
84 ALOGE("Expected a valid blend mode on plane %d", plane->id());
85 }
86
Roman Kovalivskyi15a453a2020-09-10 12:07:37 +030087 uint32_t format = layer->buffer->format;
88 if (!plane->IsFormatSupported(format)) {
89 ALOGE("Plane %d does not supports %c%c%c%c format", plane->id(), format,
90 format >> 8, format >> 16, format >> 24);
91 return -EINVAL;
92 }
93
Lowry Li9b6cafd2018-08-28 17:58:21 +080094 return ret;
95}
96
Sean Paul4c4646e2016-05-10 04:19:24 -040097std::tuple<int, std::vector<DrmCompositionPlane>> Planner::ProvisionPlanes(
Rob Herringaf0d9752018-05-04 16:34:19 -050098 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
Sean Paul4c4646e2016-05-10 04:19:24 -040099 std::vector<DrmPlane *> *primary_planes,
100 std::vector<DrmPlane *> *overlay_planes) {
101 std::vector<DrmCompositionPlane> composition;
Sean Paulf72cccd2018-08-27 13:59:08 -0400102 std::vector<DrmPlane *> planes = GetUsablePlanes(crtc, primary_planes,
103 overlay_planes);
Sean Paul4c4646e2016-05-10 04:19:24 -0400104 if (planes.empty()) {
105 ALOGE("Display %d has no usable planes", crtc->display());
106 return std::make_tuple(-ENODEV, std::vector<DrmCompositionPlane>());
107 }
108
Sean Paul4c4646e2016-05-10 04:19:24 -0400109 // Go through the provisioning stages and provision planes
110 for (auto &i : stages_) {
111 int ret = i->ProvisionPlanes(&composition, layers, crtc, &planes);
112 if (ret) {
113 ALOGE("Failed provision stage with ret %d", ret);
114 return std::make_tuple(ret, std::vector<DrmCompositionPlane>());
115 }
116 }
117
Sean Paul4c4646e2016-05-10 04:19:24 -0400118 return std::make_tuple(0, std::move(composition));
119}
120
121int PlanStageProtected::ProvisionPlanes(
122 std::vector<DrmCompositionPlane> *composition,
123 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
124 std::vector<DrmPlane *> *planes) {
125 int ret;
Sean Paul4c4646e2016-05-10 04:19:24 -0400126 for (auto i = layers.begin(); i != layers.end();) {
127 if (!i->second->protected_usage()) {
128 ++i;
129 continue;
130 }
131
132 ret = Emplace(composition, planes, DrmCompositionPlane::Type::kLayer, crtc,
Lowry Li9b6cafd2018-08-28 17:58:21 +0800133 std::make_pair(i->first, i->second));
Alexandru Gheorghe2234d372018-10-09 16:25:28 +0100134 if (ret) {
Sean Paul4c4646e2016-05-10 04:19:24 -0400135 ALOGE("Failed to dedicate protected layer! Dropping it.");
Alexandru Gheorghe2234d372018-10-09 16:25:28 +0100136 return ret;
137 }
Sean Paul4c4646e2016-05-10 04:19:24 -0400138
Sean Paul4c4646e2016-05-10 04:19:24 -0400139 i = layers.erase(i);
140 }
141
Adrian Salido45002322017-04-10 21:44:21 -0700142 return 0;
143}
144
Sean Paul4c4646e2016-05-10 04:19:24 -0400145int PlanStageGreedy::ProvisionPlanes(
146 std::vector<DrmCompositionPlane> *composition,
147 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
148 std::vector<DrmPlane *> *planes) {
149 // Fill up the remaining planes
150 for (auto i = layers.begin(); i != layers.end(); i = layers.erase(i)) {
151 int ret = Emplace(composition, planes, DrmCompositionPlane::Type::kLayer,
Lowry Li9b6cafd2018-08-28 17:58:21 +0800152 crtc, std::make_pair(i->first, i->second));
Sean Paul4c4646e2016-05-10 04:19:24 -0400153 // We don't have any planes left
154 if (ret == -ENOENT)
155 break;
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200156
157 if (ret) {
Sean Paul4c4646e2016-05-10 04:19:24 -0400158 ALOGE("Failed to emplace layer %zu, dropping it", i->first);
Alexandru Gheorghe2234d372018-10-09 16:25:28 +0100159 return ret;
160 }
Sean Paul4c4646e2016-05-10 04:19:24 -0400161 }
162
Sean Paul4c4646e2016-05-10 04:19:24 -0400163 return 0;
164}
Sean Paulf72cccd2018-08-27 13:59:08 -0400165} // namespace android