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 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 19 | #include "platform.h" |
| 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 | |
| 27 | std::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 Li | 9b6cafd | 2018-08-28 17:58:21 +0800 | [diff] [blame] | 40 | int 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 Kovalivskyi | 15a453a | 2020-09-10 12:07:37 +0300 | [diff] [blame] | 81 | 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 Li | 9b6cafd | 2018-08-28 17:58:21 +0800 | [diff] [blame] | 88 | return ret; |
| 89 | } |
| 90 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 91 | std::tuple<int, std::vector<DrmCompositionPlane>> Planner::ProvisionPlanes( |
Rob Herring | af0d975 | 2018-05-04 16:34:19 -0500 | [diff] [blame] | 92 | std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc, |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 93 | std::vector<DrmPlane *> *primary_planes, |
| 94 | std::vector<DrmPlane *> *overlay_planes) { |
| 95 | std::vector<DrmCompositionPlane> composition; |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 96 | std::vector<DrmPlane *> planes = GetUsablePlanes(crtc, primary_planes, |
| 97 | overlay_planes); |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 98 | 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 Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 103 | // 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 Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 112 | return std::make_tuple(0, std::move(composition)); |
| 113 | } |
| 114 | |
| 115 | int 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 Li | 9b6cafd | 2018-08-28 17:58:21 +0800 | [diff] [blame] | 128 | std::make_pair(i->first, i->second)); |
Alexandru Gheorghe | 2234d37 | 2018-10-09 16:25:28 +0100 | [diff] [blame] | 129 | if (ret) { |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 130 | ALOGE("Failed to dedicate protected layer! Dropping it."); |
Alexandru Gheorghe | 2234d37 | 2018-10-09 16:25:28 +0100 | [diff] [blame] | 131 | return ret; |
| 132 | } |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 133 | |
| 134 | protected_zorder = i->first; |
| 135 | i = layers.erase(i); |
| 136 | } |
| 137 | |
Adrian Salido | 4500232 | 2017-04-10 21:44:21 -0700 | [diff] [blame] | 138 | return 0; |
| 139 | } |
| 140 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 141 | int 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 Li | 9b6cafd | 2018-08-28 17:58:21 +0800 | [diff] [blame] | 148 | crtc, std::make_pair(i->first, i->second)); |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 149 | // We don't have any planes left |
| 150 | if (ret == -ENOENT) |
| 151 | break; |
Alexandru Gheorghe | 2234d37 | 2018-10-09 16:25:28 +0100 | [diff] [blame] | 152 | else if (ret) { |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 153 | ALOGE("Failed to emplace layer %zu, dropping it", i->first); |
Alexandru Gheorghe | 2234d37 | 2018-10-09 16:25:28 +0100 | [diff] [blame] | 154 | return ret; |
| 155 | } |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 156 | } |
| 157 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 158 | return 0; |
| 159 | } |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 160 | } // namespace android |