Roman Stratiienko | 9362cef | 2022-02-02 09:53:50 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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 | |
Sean Paul | 468a754 | 2024-07-16 19:50:58 +0000 | [diff] [blame] | 17 | #define LOG_TAG "drmhwc" |
Roman Stratiienko | 9362cef | 2022-02-02 09:53:50 +0200 | [diff] [blame] | 18 | |
| 19 | #include "DrmKmsPlan.h" |
| 20 | |
| 21 | #include "drm/DrmDevice.h" |
| 22 | #include "drm/DrmPlane.h" |
| 23 | #include "utils/log.h" |
| 24 | |
| 25 | namespace android { |
Andrew Wolfers | 5c53083 | 2024-12-03 16:30:26 +0000 | [diff] [blame] | 26 | auto DrmKmsPlan::CreateDrmKmsPlan( |
| 27 | DrmDisplayPipeline &pipe, std::vector<LayerData> composition, |
| 28 | std::optional<LayerData> cursor_layer) -> std::unique_ptr<DrmKmsPlan> { |
Roman Stratiienko | 9362cef | 2022-02-02 09:53:50 +0200 | [diff] [blame] | 29 | auto plan = std::make_unique<DrmKmsPlan>(); |
| 30 | |
Andrew Wolfers | 7979d2a | 2025-02-27 14:44:41 +0000 | [diff] [blame] | 31 | auto [avail_planes, cursor_plane] = pipe.GetUsablePlanes(); |
Roman Stratiienko | 9362cef | 2022-02-02 09:53:50 +0200 | [diff] [blame] | 32 | |
| 33 | int z_pos = 0; |
Andrew Wolfers | 5c53083 | 2024-12-03 16:30:26 +0000 | [diff] [blame] | 34 | if (cursor_layer.has_value()) { |
| 35 | if (cursor_plane && |
| 36 | cursor_plane->Get()->IsValidForLayer(&cursor_layer.value())) { |
| 37 | plan->plan.emplace_back( |
| 38 | LayerToPlaneJoining{.layer = std::move(cursor_layer.value()), |
| 39 | .plane = cursor_plane, |
| 40 | .z_pos = z_pos++}); |
| 41 | } else { |
| 42 | // Cursor layer can't use cursor plane, so let it match normally with |
| 43 | // others. |
| 44 | composition.push_back(std::move(cursor_layer.value())); |
| 45 | } |
| 46 | } |
| 47 | |
Roman Stratiienko | 9362cef | 2022-02-02 09:53:50 +0200 | [diff] [blame] | 48 | for (auto &dhl : composition) { |
| 49 | std::shared_ptr<BindingOwner<DrmPlane>> plane; |
Roman Stratiienko | 9362cef | 2022-02-02 09:53:50 +0200 | [diff] [blame] | 50 | /* Skip unsupported planes */ |
| 51 | do { |
| 52 | if (avail_planes.empty()) { |
| 53 | return {}; |
| 54 | } |
| 55 | |
| 56 | plane = *avail_planes.begin(); |
| 57 | avail_planes.erase(avail_planes.begin()); |
| 58 | } while (!plane->Get()->IsValidForLayer(&dhl)); |
| 59 | |
| 60 | LayerToPlaneJoining joining = { |
| 61 | .layer = std::move(dhl), |
| 62 | .plane = plane, |
| 63 | .z_pos = z_pos++, |
| 64 | }; |
| 65 | |
| 66 | plan->plan.emplace_back(std::move(joining)); |
| 67 | } |
| 68 | |
| 69 | return plan; |
| 70 | } |
| 71 | |
| 72 | } // namespace android |