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