Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 1 | /* |
| 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 Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 19 | #include "Planner.h" |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 20 | |
Roman Stratiienko | d21071f | 2021-03-09 21:56:50 +0200 | [diff] [blame^] | 21 | #include <algorithm> |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 22 | |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 23 | #include "drm/DrmDevice.h" |
Roman Stratiienko | d21071f | 2021-03-09 21:56:50 +0200 | [diff] [blame^] | 24 | #include "utils/log.h" |
Roman Stratiienko | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 25 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 26 | namespace android { |
| 27 | |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 28 | std::unique_ptr<Planner> Planner::CreateInstance(DrmDevice * /*device*/) { |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 29 | std::unique_ptr<Planner> planner(new Planner); |
| 30 | planner->AddStage<PlanStageGreedy>(); |
| 31 | return planner; |
| 32 | } |
| 33 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 34 | std::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 Li | 9b6cafd | 2018-08-28 17:58:21 +0800 | [diff] [blame] | 47 | int Planner::PlanStage::ValidatePlane(DrmPlane *plane, DrmHwcLayer *layer) { |
| 48 | int ret = 0; |
Roman Stratiienko | b3b5c1e | 2021-02-15 13:44:19 +0200 | [diff] [blame] | 49 | uint64_t blend = UINT64_MAX; |
Lowry Li | 9b6cafd | 2018-08-28 17:58:21 +0800 | [diff] [blame] | 50 | |
| 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 Kovalivskyi | 15a453a | 2020-09-10 12:07:37 +0300 | [diff] [blame] | 88 | 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 Li | 9b6cafd | 2018-08-28 17:58:21 +0800 | [diff] [blame] | 95 | return ret; |
| 96 | } |
| 97 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 98 | std::tuple<int, std::vector<DrmCompositionPlane>> Planner::ProvisionPlanes( |
Rob Herring | af0d975 | 2018-05-04 16:34:19 -0500 | [diff] [blame] | 99 | std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc, |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 100 | std::vector<DrmPlane *> *primary_planes, |
| 101 | std::vector<DrmPlane *> *overlay_planes) { |
| 102 | std::vector<DrmCompositionPlane> composition; |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 103 | std::vector<DrmPlane *> planes = GetUsablePlanes(crtc, primary_planes, |
| 104 | overlay_planes); |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 105 | 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 Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 110 | // 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 Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 119 | return std::make_tuple(0, std::move(composition)); |
| 120 | } |
| 121 | |
| 122 | int PlanStageProtected::ProvisionPlanes( |
| 123 | std::vector<DrmCompositionPlane> *composition, |
| 124 | std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc, |
| 125 | std::vector<DrmPlane *> *planes) { |
Roman Stratiienko | b3b5c1e | 2021-02-15 13:44:19 +0200 | [diff] [blame] | 126 | int ret = 0; |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 127 | 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 Li | 9b6cafd | 2018-08-28 17:58:21 +0800 | [diff] [blame] | 134 | std::make_pair(i->first, i->second)); |
Alexandru Gheorghe | 2234d37 | 2018-10-09 16:25:28 +0100 | [diff] [blame] | 135 | if (ret) { |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 136 | ALOGE("Failed to dedicate protected layer! Dropping it."); |
Alexandru Gheorghe | 2234d37 | 2018-10-09 16:25:28 +0100 | [diff] [blame] | 137 | return ret; |
| 138 | } |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 139 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 140 | i = layers.erase(i); |
| 141 | } |
| 142 | |
Adrian Salido | 4500232 | 2017-04-10 21:44:21 -0700 | [diff] [blame] | 143 | return 0; |
| 144 | } |
| 145 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 146 | int 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 Li | 9b6cafd | 2018-08-28 17:58:21 +0800 | [diff] [blame] | 153 | crtc, std::make_pair(i->first, i->second)); |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 154 | // We don't have any planes left |
| 155 | if (ret == -ENOENT) |
| 156 | break; |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 157 | |
| 158 | if (ret) { |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 159 | ALOGE("Failed to emplace layer %zu, dropping it", i->first); |
Alexandru Gheorghe | 2234d37 | 2018-10-09 16:25:28 +0100 | [diff] [blame] | 160 | return ret; |
| 161 | } |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 162 | } |
| 163 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 164 | return 0; |
| 165 | } |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 166 | } // namespace android |