Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +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 | |
| 17 | #pragma once |
| 18 | |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 19 | #include <cmath> |
| 20 | #include <cstdbool> |
| 21 | #include <cstdint> |
| 22 | #include <optional> |
| 23 | #include <vector> |
| 24 | |
| 25 | #include "bufferinfo/BufferInfo.h" |
| 26 | #include "drm/DrmFbImporter.h" |
Roman Stratiienko | 7689278 | 2023-01-16 17:15:53 +0200 | [diff] [blame] | 27 | #include "utils/fd.h" |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | |
| 31 | class DrmFbIdHandle; |
| 32 | |
Roman Stratiienko | b9bd271 | 2023-10-15 01:52:00 +0300 | [diff] [blame] | 33 | /* Rotation is defined in the clockwise direction */ |
Roman Stratiienko | da2fcf6 | 2025-01-23 17:47:03 +0200 | [diff] [blame] | 34 | /* The flip is done before rotation */ |
| 35 | struct LayerTransform { |
| 36 | bool hflip; |
| 37 | bool vflip; |
| 38 | bool rotate90; |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 39 | }; |
| 40 | |
Roman Stratiienko | 4e15bfc | 2025-01-23 01:55:21 +0200 | [diff] [blame] | 41 | struct SrcRectInfo { |
| 42 | struct FRect { |
| 43 | float left; |
| 44 | float top; |
| 45 | float right; |
| 46 | float bottom; |
| 47 | }; |
| 48 | /* nullopt means the whole buffer */ |
| 49 | std::optional<FRect> f_rect; |
| 50 | }; |
| 51 | |
| 52 | struct DstRectInfo { |
| 53 | struct IRect { |
| 54 | int32_t left; |
| 55 | int32_t top; |
| 56 | int32_t right; |
| 57 | int32_t bottom; |
| 58 | }; |
| 59 | /* nullopt means the whole display */ |
| 60 | std::optional<IRect> i_rect; |
| 61 | }; |
| 62 | |
Roman Stratiienko | fb9fed5 | 2025-01-23 02:25:12 +0200 | [diff] [blame] | 63 | constexpr float kAlphaOpaque = 1.0F; |
| 64 | |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 65 | struct PresentInfo { |
| 66 | LayerTransform transform{}; |
Roman Stratiienko | fb9fed5 | 2025-01-23 02:25:12 +0200 | [diff] [blame] | 67 | float alpha = kAlphaOpaque; |
Roman Stratiienko | 4e15bfc | 2025-01-23 01:55:21 +0200 | [diff] [blame] | 68 | SrcRectInfo source_crop{}; |
| 69 | DstRectInfo display_frame{}; |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 70 | |
| 71 | bool RequireScalingOrPhasing() const { |
Roman Stratiienko | 4e15bfc | 2025-01-23 01:55:21 +0200 | [diff] [blame] | 72 | if (!source_crop.f_rect || !display_frame.i_rect) { |
| 73 | return false; |
| 74 | } |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 75 | |
Roman Stratiienko | 4e15bfc | 2025-01-23 01:55:21 +0200 | [diff] [blame] | 76 | const auto &src = *source_crop.f_rect; |
| 77 | const auto &dst = *display_frame.i_rect; |
| 78 | |
| 79 | const float src_width = src.right - src.left; |
| 80 | const float src_height = src.bottom - src.top; |
| 81 | |
| 82 | auto dest_width = float(dst.right - dst.left); |
| 83 | auto dest_height = float(dst.bottom - dst.top); |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 84 | |
Roman Stratiienko | a7913de | 2022-10-20 13:18:57 +0300 | [diff] [blame] | 85 | auto scaling = src_width != dest_width || src_height != dest_height; |
Roman Stratiienko | 4e15bfc | 2025-01-23 01:55:21 +0200 | [diff] [blame] | 86 | auto phasing = (src.left - std::floor(src.left) != 0) || |
| 87 | (src.top - std::floor(src.top) != 0); |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 88 | return scaling || phasing; |
| 89 | } |
| 90 | }; |
| 91 | |
| 92 | struct LayerData { |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 93 | std::optional<BufferInfo> bi; |
| 94 | std::shared_ptr<DrmFbIdHandle> fb; |
| 95 | PresentInfo pi; |
Roman Stratiienko | 7689278 | 2023-01-16 17:15:53 +0200 | [diff] [blame] | 96 | SharedFd acquire_fence; |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | } // namespace android |