blob: e571b26210f3d5687b374499b0bc8484057c091e [file] [log] [blame]
Sean Paul98e73c82015-06-24 14:38:49 -07001/*
2 * Copyright (C) 2015 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-drm-display-composition"
18
Roman Stratiienko13cc3662020-08-29 21:35:39 +030019#include "DrmDisplayComposition.h"
Sean Paul98e73c82015-06-24 14:38:49 -070020
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030021#include <sync/sync.h>
22#include <xf86drmMode.h>
Sean Paul98e73c82015-06-24 14:38:49 -070023
Zach Reizner92f8e632015-10-12 17:47:13 -070024#include <algorithm>
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020025#include <cstdlib>
Zach Reizner92f8e632015-10-12 17:47:13 -070026#include <unordered_set>
27
Roman Stratiienko13cc3662020-08-29 21:35:39 +030028#include "DrmDisplayCompositor.h"
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030029#include "Planner.h"
Roman Stratiienko13cc3662020-08-29 21:35:39 +030030#include "drm/DrmDevice.h"
Roman Stratiienkod21071f2021-03-09 21:56:50 +020031#include "utils/log.h"
Sean Paul98e73c82015-06-24 14:38:49 -070032
33namespace android {
34
Roman Stratiienko753d1072021-12-30 18:05:27 +020035DrmDisplayComposition::DrmDisplayComposition(DrmCrtc *crtc)
36 : crtc_(crtc) // Can be NULL if we haven't modeset yet
37{
Sean Paul98e73c82015-06-24 14:38:49 -070038}
39
Roman Stratiienko36a7f282021-10-05 18:17:53 +030040int DrmDisplayComposition::SetLayers(DrmHwcLayer *layers, size_t num_layers) {
Zach Reizner92f8e632015-10-12 17:47:13 -070041 for (size_t layer_index = 0; layer_index < num_layers; layer_index++) {
42 layers_.emplace_back(std::move(layers[layer_index]));
43 }
44
Zach Reizner92f8e632015-10-12 17:47:13 -070045 return 0;
46}
47
Sean Paul4f4ef692016-05-03 16:40:59 -070048int DrmDisplayComposition::AddPlaneComposition(DrmCompositionPlane plane) {
49 composition_planes_.emplace_back(std::move(plane));
50 return 0;
51}
52
Rob Herringaf0d9752018-05-04 16:34:19 -050053int DrmDisplayComposition::Plan(std::vector<DrmPlane *> *primary_planes,
Zach Reizner5757e822015-10-16 19:06:31 -070054 std::vector<DrmPlane *> *overlay_planes) {
Sean Paulaa18d912016-05-12 14:28:05 -040055 std::map<size_t, DrmHwcLayer *> to_composite;
Zach Reizner5757e822015-10-16 19:06:31 -070056
Rob Herringaf0d9752018-05-04 16:34:19 -050057 for (size_t i = 0; i < layers_.size(); ++i)
58 to_composite.emplace(std::make_pair(i, &layers_[i]));
Zach Reizner5757e822015-10-16 19:06:31 -070059
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +020060 int ret = 0;
Roman Stratiienko753d1072021-12-30 18:05:27 +020061 std::tie(ret, composition_planes_) = Planner::ProvisionPlanes(to_composite,
62 crtc_,
63 primary_planes,
64 overlay_planes);
Sean Paulaa18d912016-05-12 14:28:05 -040065 if (ret) {
John Stultz66763d52021-08-24 04:59:25 +000066 ALOGV("Planner failed provisioning planes ret=%d", ret);
Sean Paulaa18d912016-05-12 14:28:05 -040067 return ret;
68 }
69
70 // Remove the planes we used from the pool before returning. This ensures they
71 // won't be reused by another display in the composition.
72 for (auto &i : composition_planes_) {
73 if (!i.plane())
Zach Reizner5757e822015-10-16 19:06:31 -070074 continue;
Zach Reizner5757e822015-10-16 19:06:31 -070075
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +020076 std::vector<DrmPlane *> *container = nullptr;
Roman Stratiienkofc014f52021-12-23 19:04:29 +020077 if (i.plane()->GetType() == DRM_PLANE_TYPE_PRIMARY)
Sean Paulaa18d912016-05-12 14:28:05 -040078 container = primary_planes;
79 else
80 container = overlay_planes;
81 for (auto j = container->begin(); j != container->end(); ++j) {
82 if (*j == i.plane()) {
83 container->erase(j);
84 break;
85 }
Zach Reiznerdb81fce2015-10-27 16:18:06 -070086 }
87 }
Zach Reizner5757e822015-10-16 19:06:31 -070088
Rob Herringaf0d9752018-05-04 16:34:19 -050089 return 0;
Zach Reizner5757e822015-10-16 19:06:31 -070090}
91
Sean Paulf72cccd2018-08-27 13:59:08 -040092} // namespace android