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 | |
| 19 | #include <hardware/hardware.h> |
| 20 | #include <hardware/hwcomposer.h> |
| 21 | |
| 22 | #include <cmath> |
| 23 | #include <cstdbool> |
| 24 | #include <cstdint> |
| 25 | #include <optional> |
| 26 | #include <vector> |
| 27 | |
| 28 | #include "bufferinfo/BufferInfo.h" |
| 29 | #include "drm/DrmFbImporter.h" |
Roman Stratiienko | 7689278 | 2023-01-16 17:15:53 +0200 | [diff] [blame] | 30 | #include "utils/fd.h" |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 31 | |
| 32 | namespace android { |
| 33 | |
| 34 | class DrmFbIdHandle; |
| 35 | |
Roman Stratiienko | b9bd271 | 2023-10-15 01:52:00 +0300 | [diff] [blame] | 36 | /* Rotation is defined in the clockwise direction */ |
Roman Stratiienko | da2fcf6 | 2025-01-23 17:47:03 +0200 | [diff] [blame] | 37 | /* The flip is done before rotation */ |
| 38 | struct LayerTransform { |
| 39 | bool hflip; |
| 40 | bool vflip; |
| 41 | bool rotate90; |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | struct PresentInfo { |
| 45 | LayerTransform transform{}; |
| 46 | uint16_t alpha = UINT16_MAX; |
| 47 | hwc_frect_t source_crop{}; |
| 48 | hwc_rect_t display_frame{}; |
| 49 | |
| 50 | bool RequireScalingOrPhasing() const { |
Roman Stratiienko | a7913de | 2022-10-20 13:18:57 +0300 | [diff] [blame] | 51 | const float src_width = source_crop.right - source_crop.left; |
| 52 | const float src_height = source_crop.bottom - source_crop.top; |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 53 | |
| 54 | auto dest_width = float(display_frame.right - display_frame.left); |
| 55 | auto dest_height = float(display_frame.bottom - display_frame.top); |
| 56 | |
Roman Stratiienko | a7913de | 2022-10-20 13:18:57 +0300 | [diff] [blame] | 57 | auto scaling = src_width != dest_width || src_height != dest_height; |
| 58 | auto phasing = (source_crop.left - std::floor(source_crop.left) != 0) || |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 59 | (source_crop.top - std::floor(source_crop.top) != 0); |
| 60 | return scaling || phasing; |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | struct LayerData { |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 65 | std::optional<BufferInfo> bi; |
| 66 | std::shared_ptr<DrmFbIdHandle> fb; |
| 67 | PresentInfo pi; |
Roman Stratiienko | 7689278 | 2023-01-16 17:15:53 +0200 | [diff] [blame] | 68 | SharedFd acquire_fence; |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | } // namespace android |