Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 1 | /* |
| 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 Stratiienko | bde9566 | 2022-12-10 20:27:58 +0200 | [diff] [blame] | 17 | #pragma once |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 18 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 19 | #include <xf86drmMode.h> |
Roman Stratiienko | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 20 | |
Roman Stratiienko | e78235c | 2021-12-23 17:36:12 +0200 | [diff] [blame] | 21 | #include <cstdint> |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 24 | #include "DrmCrtc.h" |
| 25 | #include "DrmProperty.h" |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 26 | #include "compositor/LayerData.h" |
Roman Stratiienko | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 27 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 28 | namespace android { |
| 29 | |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame] | 30 | class DrmDevice; |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 31 | struct LayerData; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 32 | |
Andrew Wolfers | bf7d29a | 2024-12-12 17:43:46 +0000 | [diff] [blame] | 33 | // NOLINTNEXTLINE(readability-identifier-naming) |
| 34 | struct drm_plane_size_hint_local { |
| 35 | __u16 width; |
| 36 | __u16 height; |
| 37 | }; |
| 38 | |
Roman Stratiienko | cad8e0c | 2022-01-31 16:40:16 +0200 | [diff] [blame] | 39 | class DrmPlane : public PipelineBindable<DrmPlane> { |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 40 | public: |
Zach Reizner | ff30b52 | 2015-10-28 19:08:45 -0700 | [diff] [blame] | 41 | DrmPlane(const DrmPlane &) = delete; |
| 42 | DrmPlane &operator=(const DrmPlane &) = delete; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 43 | |
Roman Stratiienko | b671fab | 2022-01-29 00:50:22 +0200 | [diff] [blame] | 44 | static auto CreateInstance(DrmDevice &dev, uint32_t plane_id) |
| 45 | -> std::unique_ptr<DrmPlane>; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 46 | |
Roman Stratiienko | b671fab | 2022-01-29 00:50:22 +0200 | [diff] [blame] | 47 | bool IsCrtcSupported(const DrmCrtc &crtc) const; |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 48 | bool IsValidForLayer(LayerData *layer); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 49 | |
Roman Stratiienko | b671fab | 2022-01-29 00:50:22 +0200 | [diff] [blame] | 50 | auto GetType() const { |
| 51 | return type_; |
| 52 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 53 | |
Roman Kovalivskyi | 859b607 | 2020-03-26 05:03:39 +0200 | [diff] [blame] | 54 | bool IsFormatSupported(uint32_t format) const; |
Matvii Zorin | 8338c34 | 2020-09-08 16:12:51 +0300 | [diff] [blame] | 55 | bool HasNonRgbFormat() const; |
Roman Kovalivskyi | 859b607 | 2020-03-26 05:03:39 +0200 | [diff] [blame] | 56 | |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 57 | auto AtomicSetState(drmModeAtomicReq &pset, LayerData &layer, uint32_t zpos, |
Roman Stratiienko | 4e15bfc | 2025-01-23 01:55:21 +0200 | [diff] [blame] | 58 | uint32_t crtc_id, DstRectInfo &whole_display_rect) -> int; |
Roman Stratiienko | 0dbe639 | 2021-09-29 12:47:16 +0300 | [diff] [blame] | 59 | auto AtomicDisablePlane(drmModeAtomicReq &pset) -> int; |
Roman Stratiienko | b671fab | 2022-01-29 00:50:22 +0200 | [diff] [blame] | 60 | auto &GetZPosProperty() const { |
| 61 | return zpos_property_; |
| 62 | } |
| 63 | |
| 64 | auto GetId() const { |
| 65 | return plane_->plane_id; |
| 66 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 67 | |
Andrew Wolfers | 45cb3e8 | 2025-02-26 20:17:53 +0000 | [diff] [blame] | 68 | bool HasCursorSizeConstraints() const; |
| 69 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 70 | private: |
Roman Stratiienko | b671fab | 2022-01-29 00:50:22 +0200 | [diff] [blame] | 71 | DrmPlane(DrmDevice &dev, DrmModePlaneUnique plane) |
| 72 | : drm_(&dev), plane_(std::move(plane)){}; |
| 73 | DrmDevice *const drm_; |
| 74 | DrmModePlaneUnique plane_; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 75 | |
Roman Stratiienko | 0b06388 | 2021-09-30 10:15:05 +0300 | [diff] [blame] | 76 | enum class Presence { kOptional, kMandatory }; |
| 77 | |
Roman Stratiienko | b671fab | 2022-01-29 00:50:22 +0200 | [diff] [blame] | 78 | auto Init() -> int; |
Roman Stratiienko | 0b06388 | 2021-09-30 10:15:05 +0300 | [diff] [blame] | 79 | auto GetPlaneProperty(const char *prop_name, DrmProperty &property, |
| 80 | Presence presence = Presence::kMandatory) -> bool; |
Andrew Wolfers | 45cb3e8 | 2025-02-26 20:17:53 +0000 | [diff] [blame] | 81 | bool IsBufferValidForCursorPlane(const BufferInfo &bi) const; |
Roman Stratiienko | 0b06388 | 2021-09-30 10:15:05 +0300 | [diff] [blame] | 82 | |
Roman Stratiienko | b3b5c1e | 2021-02-15 13:44:19 +0200 | [diff] [blame] | 83 | uint32_t type_{}; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 84 | |
Roman Kovalivskyi | 859b607 | 2020-03-26 05:03:39 +0200 | [diff] [blame] | 85 | std::vector<uint32_t> formats_; |
| 86 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 87 | 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 Gheorghe | ea1c5e5 | 2018-09-17 10:48:54 +0100 | [diff] [blame] | 97 | DrmProperty zpos_property_; |
Sean Paul | 1c4c326 | 2015-07-14 15:51:52 -0400 | [diff] [blame] | 98 | DrmProperty rotation_property_; |
Sean Paul | d8aefb6 | 2015-10-15 15:17:31 -0400 | [diff] [blame] | 99 | DrmProperty alpha_property_; |
Lowry Li | 9b6cafd | 2018-08-28 17:58:21 +0800 | [diff] [blame] | 100 | DrmProperty blend_property_; |
Robert Foss | a09220c | 2016-09-30 10:27:23 -0400 | [diff] [blame] | 101 | DrmProperty in_fence_fd_property_; |
Andrew Wolfers | c88294c | 2024-12-12 14:33:15 +0000 | [diff] [blame] | 102 | DrmProperty color_encoding_property_; |
Matvii Zorin | 8338c34 | 2020-09-08 16:12:51 +0300 | [diff] [blame] | 103 | DrmProperty color_range_property_; |
Andrew Wolfers | bf7d29a | 2024-12-12 17:43:46 +0000 | [diff] [blame] | 104 | DrmProperty size_hints_property_; |
Roman Stratiienko | 4f1effa | 2021-09-29 12:47:26 +0300 | [diff] [blame] | 105 | |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 106 | 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 Stratiienko | da2fcf6 | 2025-01-23 17:47:03 +0200 | [diff] [blame] | 109 | uint64_t transform_enum_mask_ = DRM_MODE_ROTATE_0; |
Andrew Wolfers | bf7d29a | 2024-12-12 17:43:46 +0000 | [diff] [blame] | 110 | std::vector<drm_plane_size_hint_local> size_hints_; |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 111 | }; |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 112 | } // namespace android |