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 | |
| 19 | #include "drmresources.h" |
| 20 | #include "platform.h" |
| 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 | |
| 39 | std::tuple<int, std::vector<DrmCompositionPlane>> Planner::ProvisionPlanes( |
Rob Herring | af0d975 | 2018-05-04 16:34:19 -0500 | [diff] [blame] | 40 | std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc, |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 41 | std::vector<DrmPlane *> *primary_planes, |
| 42 | std::vector<DrmPlane *> *overlay_planes) { |
| 43 | std::vector<DrmCompositionPlane> composition; |
| 44 | std::vector<DrmPlane *> planes = |
| 45 | GetUsablePlanes(crtc, primary_planes, overlay_planes); |
| 46 | if (planes.empty()) { |
| 47 | ALOGE("Display %d has no usable planes", crtc->display()); |
| 48 | return std::make_tuple(-ENODEV, std::vector<DrmCompositionPlane>()); |
| 49 | } |
| 50 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 51 | // Go through the provisioning stages and provision planes |
| 52 | for (auto &i : stages_) { |
| 53 | int ret = i->ProvisionPlanes(&composition, layers, crtc, &planes); |
| 54 | if (ret) { |
| 55 | ALOGE("Failed provision stage with ret %d", ret); |
| 56 | return std::make_tuple(ret, std::vector<DrmCompositionPlane>()); |
| 57 | } |
| 58 | } |
| 59 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 60 | return std::make_tuple(0, std::move(composition)); |
| 61 | } |
| 62 | |
| 63 | int PlanStageProtected::ProvisionPlanes( |
| 64 | std::vector<DrmCompositionPlane> *composition, |
| 65 | std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc, |
| 66 | std::vector<DrmPlane *> *planes) { |
| 67 | int ret; |
| 68 | int protected_zorder = -1; |
| 69 | for (auto i = layers.begin(); i != layers.end();) { |
| 70 | if (!i->second->protected_usage()) { |
| 71 | ++i; |
| 72 | continue; |
| 73 | } |
| 74 | |
| 75 | ret = Emplace(composition, planes, DrmCompositionPlane::Type::kLayer, crtc, |
| 76 | i->first); |
| 77 | if (ret) |
| 78 | ALOGE("Failed to dedicate protected layer! Dropping it."); |
| 79 | |
| 80 | protected_zorder = i->first; |
| 81 | i = layers.erase(i); |
| 82 | } |
| 83 | |
Adrian Salido | 4500232 | 2017-04-10 21:44:21 -0700 | [diff] [blame] | 84 | return 0; |
| 85 | } |
| 86 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 87 | int PlanStageGreedy::ProvisionPlanes( |
| 88 | std::vector<DrmCompositionPlane> *composition, |
| 89 | std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc, |
| 90 | std::vector<DrmPlane *> *planes) { |
| 91 | // Fill up the remaining planes |
| 92 | for (auto i = layers.begin(); i != layers.end(); i = layers.erase(i)) { |
| 93 | int ret = Emplace(composition, planes, DrmCompositionPlane::Type::kLayer, |
| 94 | crtc, i->first); |
| 95 | // We don't have any planes left |
| 96 | if (ret == -ENOENT) |
| 97 | break; |
| 98 | else if (ret) |
| 99 | ALOGE("Failed to emplace layer %zu, dropping it", i->first); |
| 100 | } |
| 101 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 102 | return 0; |
| 103 | } |
| 104 | } |