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" |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 20 | #include "drmdevice.h" |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 21 | |
John Stultz | 9057a6f | 2018-04-26 12:05:55 -0700 | [diff] [blame] | 22 | #include <log/log.h> |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | std::vector<DrmPlane *> Planner::GetUsablePlanes( |
| 27 | DrmCrtc *crtc, std::vector<DrmPlane *> *primary_planes, |
| 28 | std::vector<DrmPlane *> *overlay_planes) { |
| 29 | std::vector<DrmPlane *> usable_planes; |
| 30 | std::copy_if(primary_planes->begin(), primary_planes->end(), |
| 31 | std::back_inserter(usable_planes), |
| 32 | [=](DrmPlane *plane) { return plane->GetCrtcSupported(*crtc); }); |
| 33 | std::copy_if(overlay_planes->begin(), overlay_planes->end(), |
| 34 | std::back_inserter(usable_planes), |
| 35 | [=](DrmPlane *plane) { return plane->GetCrtcSupported(*crtc); }); |
| 36 | return usable_planes; |
| 37 | } |
| 38 | |
Lowry Li | 9b6cafd | 2018-08-28 17:58:21 +0800 | [diff] [blame] | 39 | int Planner::PlanStage::ValidatePlane(DrmPlane *plane, DrmHwcLayer *layer) { |
| 40 | int ret = 0; |
| 41 | uint64_t blend; |
| 42 | |
| 43 | if ((plane->rotation_property().id() == 0) && |
| 44 | layer->transform != DrmHwcTransform::kIdentity) { |
| 45 | ALOGE("Rotation is not supported on plane %d", plane->id()); |
| 46 | return -EINVAL; |
| 47 | } |
| 48 | |
| 49 | if (plane->alpha_property().id() == 0 && layer->alpha != 0xffff) { |
| 50 | ALOGE("Alpha is not supported on plane %d", plane->id()); |
| 51 | return -EINVAL; |
| 52 | } |
| 53 | |
| 54 | if (plane->blend_property().id() == 0) { |
| 55 | if ((layer->blending != DrmHwcBlending::kNone) && |
| 56 | (layer->blending != DrmHwcBlending::kPreMult)) { |
| 57 | ALOGE("Blending is not supported on plane %d", plane->id()); |
| 58 | return -EINVAL; |
| 59 | } |
| 60 | } else { |
| 61 | switch (layer->blending) { |
| 62 | case DrmHwcBlending::kPreMult: |
| 63 | std::tie(blend, ret) = plane->blend_property().GetEnumValueWithName( |
| 64 | "Pre-multiplied"); |
| 65 | break; |
| 66 | case DrmHwcBlending::kCoverage: |
| 67 | std::tie(blend, ret) = plane->blend_property().GetEnumValueWithName( |
| 68 | "Coverage"); |
| 69 | break; |
| 70 | case DrmHwcBlending::kNone: |
| 71 | default: |
| 72 | std::tie(blend, |
| 73 | ret) = plane->blend_property().GetEnumValueWithName("None"); |
| 74 | break; |
| 75 | } |
| 76 | if (ret) |
| 77 | ALOGE("Expected a valid blend mode on plane %d", plane->id()); |
| 78 | } |
| 79 | |
| 80 | return ret; |
| 81 | } |
| 82 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 83 | std::tuple<int, std::vector<DrmCompositionPlane>> Planner::ProvisionPlanes( |
Rob Herring | af0d975 | 2018-05-04 16:34:19 -0500 | [diff] [blame] | 84 | std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc, |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 85 | std::vector<DrmPlane *> *primary_planes, |
| 86 | std::vector<DrmPlane *> *overlay_planes) { |
| 87 | std::vector<DrmCompositionPlane> composition; |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 88 | std::vector<DrmPlane *> planes = GetUsablePlanes(crtc, primary_planes, |
| 89 | overlay_planes); |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 90 | if (planes.empty()) { |
| 91 | ALOGE("Display %d has no usable planes", crtc->display()); |
| 92 | return std::make_tuple(-ENODEV, std::vector<DrmCompositionPlane>()); |
| 93 | } |
| 94 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 95 | // Go through the provisioning stages and provision planes |
| 96 | for (auto &i : stages_) { |
| 97 | int ret = i->ProvisionPlanes(&composition, layers, crtc, &planes); |
| 98 | if (ret) { |
| 99 | ALOGE("Failed provision stage with ret %d", ret); |
| 100 | return std::make_tuple(ret, std::vector<DrmCompositionPlane>()); |
| 101 | } |
| 102 | } |
| 103 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 104 | return std::make_tuple(0, std::move(composition)); |
| 105 | } |
| 106 | |
| 107 | int PlanStageProtected::ProvisionPlanes( |
| 108 | std::vector<DrmCompositionPlane> *composition, |
| 109 | std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc, |
| 110 | std::vector<DrmPlane *> *planes) { |
| 111 | int ret; |
| 112 | int protected_zorder = -1; |
| 113 | for (auto i = layers.begin(); i != layers.end();) { |
| 114 | if (!i->second->protected_usage()) { |
| 115 | ++i; |
| 116 | continue; |
| 117 | } |
| 118 | |
| 119 | ret = Emplace(composition, planes, DrmCompositionPlane::Type::kLayer, crtc, |
Lowry Li | 9b6cafd | 2018-08-28 17:58:21 +0800 | [diff] [blame] | 120 | std::make_pair(i->first, i->second)); |
Alexandru Gheorghe | 2234d37 | 2018-10-09 16:25:28 +0100 | [diff] [blame] | 121 | if (ret) { |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 122 | ALOGE("Failed to dedicate protected layer! Dropping it."); |
Alexandru Gheorghe | 2234d37 | 2018-10-09 16:25:28 +0100 | [diff] [blame] | 123 | return ret; |
| 124 | } |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 125 | |
| 126 | protected_zorder = i->first; |
| 127 | i = layers.erase(i); |
| 128 | } |
| 129 | |
Adrian Salido | 4500232 | 2017-04-10 21:44:21 -0700 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 133 | int PlanStageGreedy::ProvisionPlanes( |
| 134 | std::vector<DrmCompositionPlane> *composition, |
| 135 | std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc, |
| 136 | std::vector<DrmPlane *> *planes) { |
| 137 | // Fill up the remaining planes |
| 138 | for (auto i = layers.begin(); i != layers.end(); i = layers.erase(i)) { |
| 139 | int ret = Emplace(composition, planes, DrmCompositionPlane::Type::kLayer, |
Lowry Li | 9b6cafd | 2018-08-28 17:58:21 +0800 | [diff] [blame] | 140 | crtc, std::make_pair(i->first, i->second)); |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 141 | // We don't have any planes left |
| 142 | if (ret == -ENOENT) |
| 143 | break; |
Alexandru Gheorghe | 2234d37 | 2018-10-09 16:25:28 +0100 | [diff] [blame] | 144 | else if (ret) { |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 145 | ALOGE("Failed to emplace layer %zu, dropping it", i->first); |
Alexandru Gheorghe | 2234d37 | 2018-10-09 16:25:28 +0100 | [diff] [blame] | 146 | return ret; |
| 147 | } |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 148 | } |
| 149 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 150 | return 0; |
| 151 | } |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 152 | } // namespace android |