blob: 2fa6388c5cf1a5a39e1cf9d95978aa0fd556ba9f [file] [log] [blame]
Sean Paul6a55e9f2015-04-30 15:31:06 -04001/*
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
Roman Stratiienkobde95662022-12-10 20:27:58 +020017#pragma once
Sean Paul6a55e9f2015-04-30 15:31:06 -040018
Sean Paul6a55e9f2015-04-30 15:31:06 -040019#include <xf86drmMode.h>
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030020
Roman Stratiienkoe78235c2021-12-23 17:36:12 +020021#include <cstdint>
Sean Paul6a55e9f2015-04-30 15:31:06 -040022#include <vector>
23
Roman Stratiienko13cc3662020-08-29 21:35:39 +030024#include "DrmCrtc.h"
25#include "DrmProperty.h"
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020026#include "compositor/LayerData.h"
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030027
Sean Paul6a55e9f2015-04-30 15:31:06 -040028namespace android {
29
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010030class DrmDevice;
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020031struct LayerData;
Sean Paul6a55e9f2015-04-30 15:31:06 -040032
Andrew Wolfersbf7d29a2024-12-12 17:43:46 +000033// NOLINTNEXTLINE(readability-identifier-naming)
34struct drm_plane_size_hint_local {
35 __u16 width;
36 __u16 height;
37};
38
Roman Stratiienkocad8e0c2022-01-31 16:40:16 +020039class DrmPlane : public PipelineBindable<DrmPlane> {
Sean Paul6a55e9f2015-04-30 15:31:06 -040040 public:
Zach Reiznerff30b522015-10-28 19:08:45 -070041 DrmPlane(const DrmPlane &) = delete;
42 DrmPlane &operator=(const DrmPlane &) = delete;
Sean Paul6a55e9f2015-04-30 15:31:06 -040043
Roman Stratiienkob671fab2022-01-29 00:50:22 +020044 static auto CreateInstance(DrmDevice &dev, uint32_t plane_id)
45 -> std::unique_ptr<DrmPlane>;
Sean Paul6a55e9f2015-04-30 15:31:06 -040046
Roman Stratiienkob671fab2022-01-29 00:50:22 +020047 bool IsCrtcSupported(const DrmCrtc &crtc) const;
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020048 bool IsValidForLayer(LayerData *layer);
Sean Paul6a55e9f2015-04-30 15:31:06 -040049
Roman Stratiienkob671fab2022-01-29 00:50:22 +020050 auto GetType() const {
51 return type_;
52 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040053
Roman Kovalivskyi859b6072020-03-26 05:03:39 +020054 bool IsFormatSupported(uint32_t format) const;
Matvii Zorin8338c342020-09-08 16:12:51 +030055 bool HasNonRgbFormat() const;
Roman Kovalivskyi859b6072020-03-26 05:03:39 +020056
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020057 auto AtomicSetState(drmModeAtomicReq &pset, LayerData &layer, uint32_t zpos,
Roman Stratiienko4e15bfc2025-01-23 01:55:21 +020058 uint32_t crtc_id, DstRectInfo &whole_display_rect) -> int;
Roman Stratiienko0dbe6392021-09-29 12:47:16 +030059 auto AtomicDisablePlane(drmModeAtomicReq &pset) -> int;
Roman Stratiienkob671fab2022-01-29 00:50:22 +020060 auto &GetZPosProperty() const {
61 return zpos_property_;
62 }
63
64 auto GetId() const {
65 return plane_->plane_id;
66 }
Sean Paul6a55e9f2015-04-30 15:31:06 -040067
Andrew Wolfers45cb3e82025-02-26 20:17:53 +000068 bool HasCursorSizeConstraints() const;
69
Sean Paul6a55e9f2015-04-30 15:31:06 -040070 private:
Roman Stratiienkob671fab2022-01-29 00:50:22 +020071 DrmPlane(DrmDevice &dev, DrmModePlaneUnique plane)
72 : drm_(&dev), plane_(std::move(plane)){};
73 DrmDevice *const drm_;
74 DrmModePlaneUnique plane_;
Sean Paul6a55e9f2015-04-30 15:31:06 -040075
Roman Stratiienko0b063882021-09-30 10:15:05 +030076 enum class Presence { kOptional, kMandatory };
77
Roman Stratiienkob671fab2022-01-29 00:50:22 +020078 auto Init() -> int;
Roman Stratiienko0b063882021-09-30 10:15:05 +030079 auto GetPlaneProperty(const char *prop_name, DrmProperty &property,
80 Presence presence = Presence::kMandatory) -> bool;
Andrew Wolfers45cb3e82025-02-26 20:17:53 +000081 bool IsBufferValidForCursorPlane(const BufferInfo &bi) const;
Roman Stratiienko0b063882021-09-30 10:15:05 +030082
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +020083 uint32_t type_{};
Sean Paul6a55e9f2015-04-30 15:31:06 -040084
Roman Kovalivskyi859b6072020-03-26 05:03:39 +020085 std::vector<uint32_t> formats_;
86
Sean Paul6a55e9f2015-04-30 15:31:06 -040087 DrmProperty crtc_property_;
88 DrmProperty fb_property_;
89 DrmProperty crtc_x_property_;
90 DrmProperty crtc_y_property_;
91 DrmProperty crtc_w_property_;
92 DrmProperty crtc_h_property_;
93 DrmProperty src_x_property_;
94 DrmProperty src_y_property_;
95 DrmProperty src_w_property_;
96 DrmProperty src_h_property_;
Alexandru Gheorgheea1c5e52018-09-17 10:48:54 +010097 DrmProperty zpos_property_;
Sean Paul1c4c3262015-07-14 15:51:52 -040098 DrmProperty rotation_property_;
Sean Pauld8aefb62015-10-15 15:17:31 -040099 DrmProperty alpha_property_;
Lowry Li9b6cafd2018-08-28 17:58:21 +0800100 DrmProperty blend_property_;
Robert Fossa09220c2016-09-30 10:27:23 -0400101 DrmProperty in_fence_fd_property_;
Andrew Wolfersc88294c2024-12-12 14:33:15 +0000102 DrmProperty color_encoding_property_;
Matvii Zorin8338c342020-09-08 16:12:51 +0300103 DrmProperty color_range_property_;
Andrew Wolfersbf7d29a2024-12-12 17:43:46 +0000104 DrmProperty size_hints_property_;
Roman Stratiienko4f1effa2021-09-29 12:47:26 +0300105
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200106 std::map<BufferBlendMode, uint64_t> blending_enum_map_;
107 std::map<BufferColorSpace, uint64_t> color_encoding_enum_map_;
108 std::map<BufferSampleRange, uint64_t> color_range_enum_map_;
Roman Stratiienkoda2fcf62025-01-23 17:47:03 +0200109 uint64_t transform_enum_mask_ = DRM_MODE_ROTATE_0;
Andrew Wolfersbf7d29a2024-12-12 17:43:46 +0000110 std::vector<drm_plane_size_hint_local> size_hints_;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400111};
Sean Paulf72cccd2018-08-27 13:59:08 -0400112} // namespace android