blob: 9fb91e7225920d3a0645935387a0fea55ac18123 [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 Stratiienkoaa3cd542020-08-29 11:26:16 +030023#include "drm/drmdevice.h"
24
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
81 return ret;
82}
83
Sean Paul4c4646e2016-05-10 04:19:24 -040084std::tuple<int, std::vector<DrmCompositionPlane>> Planner::ProvisionPlanes(
Rob Herringaf0d9752018-05-04 16:34:19 -050085 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
Sean Paul4c4646e2016-05-10 04:19:24 -040086 std::vector<DrmPlane *> *primary_planes,
87 std::vector<DrmPlane *> *overlay_planes) {
88 std::vector<DrmCompositionPlane> composition;
Sean Paulf72cccd2018-08-27 13:59:08 -040089 std::vector<DrmPlane *> planes = GetUsablePlanes(crtc, primary_planes,
90 overlay_planes);
Sean Paul4c4646e2016-05-10 04:19:24 -040091 if (planes.empty()) {
92 ALOGE("Display %d has no usable planes", crtc->display());
93 return std::make_tuple(-ENODEV, std::vector<DrmCompositionPlane>());
94 }
95
Sean Paul4c4646e2016-05-10 04:19:24 -040096 // Go through the provisioning stages and provision planes
97 for (auto &i : stages_) {
98 int ret = i->ProvisionPlanes(&composition, layers, crtc, &planes);
99 if (ret) {
100 ALOGE("Failed provision stage with ret %d", ret);
101 return std::make_tuple(ret, std::vector<DrmCompositionPlane>());
102 }
103 }
104
Sean Paul4c4646e2016-05-10 04:19:24 -0400105 return std::make_tuple(0, std::move(composition));
106}
107
108int PlanStageProtected::ProvisionPlanes(
109 std::vector<DrmCompositionPlane> *composition,
110 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
111 std::vector<DrmPlane *> *planes) {
112 int ret;
113 int protected_zorder = -1;
114 for (auto i = layers.begin(); i != layers.end();) {
115 if (!i->second->protected_usage()) {
116 ++i;
117 continue;
118 }
119
120 ret = Emplace(composition, planes, DrmCompositionPlane::Type::kLayer, crtc,
Lowry Li9b6cafd2018-08-28 17:58:21 +0800121 std::make_pair(i->first, i->second));
Alexandru Gheorghe2234d372018-10-09 16:25:28 +0100122 if (ret) {
Sean Paul4c4646e2016-05-10 04:19:24 -0400123 ALOGE("Failed to dedicate protected layer! Dropping it.");
Alexandru Gheorghe2234d372018-10-09 16:25:28 +0100124 return ret;
125 }
Sean Paul4c4646e2016-05-10 04:19:24 -0400126
127 protected_zorder = i->first;
128 i = layers.erase(i);
129 }
130
Adrian Salido45002322017-04-10 21:44:21 -0700131 return 0;
132}
133
Sean Paul4c4646e2016-05-10 04:19:24 -0400134int PlanStageGreedy::ProvisionPlanes(
135 std::vector<DrmCompositionPlane> *composition,
136 std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
137 std::vector<DrmPlane *> *planes) {
138 // Fill up the remaining planes
139 for (auto i = layers.begin(); i != layers.end(); i = layers.erase(i)) {
140 int ret = Emplace(composition, planes, DrmCompositionPlane::Type::kLayer,
Lowry Li9b6cafd2018-08-28 17:58:21 +0800141 crtc, std::make_pair(i->first, i->second));
Sean Paul4c4646e2016-05-10 04:19:24 -0400142 // We don't have any planes left
143 if (ret == -ENOENT)
144 break;
Alexandru Gheorghe2234d372018-10-09 16:25:28 +0100145 else if (ret) {
Sean Paul4c4646e2016-05-10 04:19:24 -0400146 ALOGE("Failed to emplace layer %zu, dropping it", i->first);
Alexandru Gheorghe2234d372018-10-09 16:25:28 +0100147 return ret;
148 }
Sean Paul4c4646e2016-05-10 04:19:24 -0400149 }
150
Sean Paul4c4646e2016-05-10 04:19:24 -0400151 return 0;
152}
Sean Paulf72cccd2018-08-27 13:59:08 -0400153} // namespace android