blob: a5003982dc8cd73026b50bb6568ad54538025cbc [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
Sean Paul4c4646e2016-05-10 04:19:24 -040019#include "platform.h"
20
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
27std::vector<DrmPlane *> Planner::GetUsablePlanes(
28 DrmCrtc *crtc, std::vector<DrmPlane *> *primary_planes,
29 std::vector<DrmPlane *> *overlay_planes) {
30 std::vector<DrmPlane *> usable_planes;
31 std::copy_if(primary_planes->begin(), primary_planes->end(),
32 std::back_inserter(usable_planes),
33 [=](DrmPlane *plane) { return plane->GetCrtcSupported(*crtc); });
34 std::copy_if(overlay_planes->begin(), overlay_planes->end(),
35 std::back_inserter(usable_planes),
36 [=](DrmPlane *plane) { return plane->GetCrtcSupported(*crtc); });
37 return usable_planes;
38}
39
Lowry Li9b6cafd2018-08-28 17:58:21 +080040int Planner::PlanStage::ValidatePlane(DrmPlane *plane, DrmHwcLayer *layer) {
41 int ret = 0;
42 uint64_t blend;
43
44 if ((plane->rotation_property().id() == 0) &&
45 layer->transform != DrmHwcTransform::kIdentity) {
46 ALOGE("Rotation is not supported on plane %d", plane->id());
47 return -EINVAL;
48 }
49
50 if (plane->alpha_property().id() == 0 && layer->alpha != 0xffff) {
51 ALOGE("Alpha is not supported on plane %d", plane->id());
52 return -EINVAL;
53 }
54
55 if (plane->blend_property().id() == 0) {
56 if ((layer->blending != DrmHwcBlending::kNone) &&
57 (layer->blending != DrmHwcBlending::kPreMult)) {
58 ALOGE("Blending is not supported on plane %d", plane->id());
59 return -EINVAL;
60 }
61 } else {
62 switch (layer->blending) {
63 case DrmHwcBlending::kPreMult:
64 std::tie(blend, ret) = plane->blend_property().GetEnumValueWithName(
65 "Pre-multiplied");
66 break;
67 case DrmHwcBlending::kCoverage:
68 std::tie(blend, ret) = plane->blend_property().GetEnumValueWithName(
69 "Coverage");
70 break;
71 case DrmHwcBlending::kNone:
72 default:
73 std::tie(blend,
74 ret) = plane->blend_property().GetEnumValueWithName("None");
75 break;
76 }
77 if (ret)
78 ALOGE("Expected a valid blend mode on plane %d", plane->id());
79 }
80
Roman Kovalivskyi15a453a2020-09-10 12:07:37 +030081 uint32_t format = layer->buffer->format;
82 if (!plane->IsFormatSupported(format)) {
83 ALOGE("Plane %d does not supports %c%c%c%c format", plane->id(), format,
84 format >> 8, format >> 16, format >> 24);
85 return -EINVAL;
86 }
87
Lowry Li9b6cafd2018-08-28 17:58:21 +080088 return ret;
89}
90
Sean Paul4c4646e2016-05-10 04:19:24 -040091std::tuple<int, std::vector<DrmCompositionPlane>> Planner::ProvisionPlanes(
Rob Herringaf0d9752018-05-04 16:34:19 -050092 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
Sean Paul4c4646e2016-05-10 04:19:24 -040093 std::vector<DrmPlane *> *primary_planes,
94 std::vector<DrmPlane *> *overlay_planes) {
95 std::vector<DrmCompositionPlane> composition;
Sean Paulf72cccd2018-08-27 13:59:08 -040096 std::vector<DrmPlane *> planes = GetUsablePlanes(crtc, primary_planes,
97 overlay_planes);
Sean Paul4c4646e2016-05-10 04:19:24 -040098 if (planes.empty()) {
99 ALOGE("Display %d has no usable planes", crtc->display());
100 return std::make_tuple(-ENODEV, std::vector<DrmCompositionPlane>());
101 }
102
Sean Paul4c4646e2016-05-10 04:19:24 -0400103 // Go through the provisioning stages and provision planes
104 for (auto &i : stages_) {
105 int ret = i->ProvisionPlanes(&composition, layers, crtc, &planes);
106 if (ret) {
107 ALOGE("Failed provision stage with ret %d", ret);
108 return std::make_tuple(ret, std::vector<DrmCompositionPlane>());
109 }
110 }
111
Sean Paul4c4646e2016-05-10 04:19:24 -0400112 return std::make_tuple(0, std::move(composition));
113}
114
115int PlanStageProtected::ProvisionPlanes(
116 std::vector<DrmCompositionPlane> *composition,
117 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
118 std::vector<DrmPlane *> *planes) {
119 int ret;
120 int protected_zorder = -1;
121 for (auto i = layers.begin(); i != layers.end();) {
122 if (!i->second->protected_usage()) {
123 ++i;
124 continue;
125 }
126
127 ret = Emplace(composition, planes, DrmCompositionPlane::Type::kLayer, crtc,
Lowry Li9b6cafd2018-08-28 17:58:21 +0800128 std::make_pair(i->first, i->second));
Alexandru Gheorghe2234d372018-10-09 16:25:28 +0100129 if (ret) {
Sean Paul4c4646e2016-05-10 04:19:24 -0400130 ALOGE("Failed to dedicate protected layer! Dropping it.");
Alexandru Gheorghe2234d372018-10-09 16:25:28 +0100131 return ret;
132 }
Sean Paul4c4646e2016-05-10 04:19:24 -0400133
134 protected_zorder = i->first;
135 i = layers.erase(i);
136 }
137
Adrian Salido45002322017-04-10 21:44:21 -0700138 return 0;
139}
140
Sean Paul4c4646e2016-05-10 04:19:24 -0400141int PlanStageGreedy::ProvisionPlanes(
142 std::vector<DrmCompositionPlane> *composition,
143 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
144 std::vector<DrmPlane *> *planes) {
145 // Fill up the remaining planes
146 for (auto i = layers.begin(); i != layers.end(); i = layers.erase(i)) {
147 int ret = Emplace(composition, planes, DrmCompositionPlane::Type::kLayer,
Lowry Li9b6cafd2018-08-28 17:58:21 +0800148 crtc, std::make_pair(i->first, i->second));
Sean Paul4c4646e2016-05-10 04:19:24 -0400149 // We don't have any planes left
150 if (ret == -ENOENT)
151 break;
Alexandru Gheorghe2234d372018-10-09 16:25:28 +0100152 else if (ret) {
Sean Paul4c4646e2016-05-10 04:19:24 -0400153 ALOGE("Failed to emplace layer %zu, dropping it", i->first);
Alexandru Gheorghe2234d372018-10-09 16:25:28 +0100154 return ret;
155 }
Sean Paul4c4646e2016-05-10 04:19:24 -0400156 }
157
Sean Paul4c4646e2016-05-10 04:19:24 -0400158 return 0;
159}
Sean Paulf72cccd2018-08-27 13:59:08 -0400160} // namespace android