blob: 11556976763ebc1683d6fa71d018ac4b6c40cd20 [file] [log] [blame]
Roman Stratiienko9362cef2022-02-02 09:53:50 +02001/*
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 Paul468a7542024-07-16 19:50:58 +000017#define LOG_TAG "drmhwc"
Roman Stratiienko9362cef2022-02-02 09:53:50 +020018
19#include "DrmKmsPlan.h"
20
21#include "drm/DrmDevice.h"
22#include "drm/DrmPlane.h"
23#include "utils/log.h"
24
25namespace android {
Andrew Wolfers5c530832024-12-03 16:30:26 +000026auto DrmKmsPlan::CreateDrmKmsPlan(
27 DrmDisplayPipeline &pipe, std::vector<LayerData> composition,
28 std::optional<LayerData> cursor_layer) -> std::unique_ptr<DrmKmsPlan> {
Roman Stratiienko9362cef2022-02-02 09:53:50 +020029 auto plan = std::make_unique<DrmKmsPlan>();
30
Andrew Wolfers7979d2a2025-02-27 14:44:41 +000031 auto [avail_planes, cursor_plane] = pipe.GetUsablePlanes();
Roman Stratiienko9362cef2022-02-02 09:53:50 +020032
33 int z_pos = 0;
Andrew Wolfers5c530832024-12-03 16:30:26 +000034 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 Stratiienko9362cef2022-02-02 09:53:50 +020048 for (auto &dhl : composition) {
49 std::shared_ptr<BindingOwner<DrmPlane>> plane;
Roman Stratiienko9362cef2022-02-02 09:53:50 +020050 /* 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