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); |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 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 | |
| 46 | std::tuple<int, std::vector<DrmCompositionPlane>> Planner::ProvisionPlanes( |
Rob Herring | af0d975 | 2018-05-04 16:34:19 -0500 | [diff] [blame] | 47 | std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc, |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 48 | std::vector<DrmPlane *> *primary_planes, |
| 49 | std::vector<DrmPlane *> *overlay_planes) { |
| 50 | std::vector<DrmCompositionPlane> composition; |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 51 | std::vector<DrmPlane *> planes = GetUsablePlanes(crtc, primary_planes, |
| 52 | overlay_planes); |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 53 | if (planes.empty()) { |
| 54 | ALOGE("Display %d has no usable planes", crtc->display()); |
| 55 | return std::make_tuple(-ENODEV, std::vector<DrmCompositionPlane>()); |
| 56 | } |
| 57 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 58 | // Go through the provisioning stages and provision planes |
Roman Stratiienko | 9a6c9de | 2021-12-17 15:01:18 +0200 | [diff] [blame] | 59 | int ret = ProvisionPlanesInternal(&composition, layers, &planes); |
Roman Stratiienko | fc014f5 | 2021-12-23 19:04:29 +0200 | [diff] [blame^] | 60 | if (ret != 0) { |
Roman Stratiienko | 9a6c9de | 2021-12-17 15:01:18 +0200 | [diff] [blame] | 61 | ALOGV("Failed provision stage with ret %d", ret); |
| 62 | return std::make_tuple(ret, std::vector<DrmCompositionPlane>()); |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 63 | } |
| 64 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 65 | return std::make_tuple(0, std::move(composition)); |
| 66 | } |
| 67 | |
Roman Stratiienko | 9a6c9de | 2021-12-17 15:01:18 +0200 | [diff] [blame] | 68 | int Planner::ProvisionPlanesInternal( |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 69 | std::vector<DrmCompositionPlane> *composition, |
Roman Stratiienko | 67cebf5 | 2021-12-17 13:31:27 +0200 | [diff] [blame] | 70 | std::map<size_t, DrmHwcLayer *> &layers, std::vector<DrmPlane *> *planes) { |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 71 | // Fill up the remaining planes |
| 72 | for (auto i = layers.begin(); i != layers.end(); i = layers.erase(i)) { |
Roman Stratiienko | 67cebf5 | 2021-12-17 13:31:27 +0200 | [diff] [blame] | 73 | int ret = Emplace(composition, planes, std::make_pair(i->first, i->second)); |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 74 | // We don't have any planes left |
| 75 | if (ret == -ENOENT) |
| 76 | break; |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 77 | |
Roman Stratiienko | fc014f5 | 2021-12-23 19:04:29 +0200 | [diff] [blame^] | 78 | if (ret != 0) { |
John Stultz | 66763d5 | 2021-08-24 04:59:25 +0000 | [diff] [blame] | 79 | ALOGV("Failed to emplace layer %zu, dropping it", i->first); |
Alexandru Gheorghe | 2234d37 | 2018-10-09 16:25:28 +0100 | [diff] [blame] | 80 | return ret; |
| 81 | } |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 82 | } |
| 83 | |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 84 | return 0; |
| 85 | } |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 86 | } // namespace android |