blob: 962141fdd6548440cf8c6559760a4f7aa2ce2f6f [file] [log] [blame]
Roman Stratiienko4b2cc482022-02-21 14:53:58 +02001/*
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 Stratiienko4b2cc482022-02-21 14:53:58 +020019#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 Stratiienko76892782023-01-16 17:15:53 +020027#include "utils/fd.h"
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020028
29namespace android {
30
31class DrmFbIdHandle;
32
Roman Stratiienkob9bd2712023-10-15 01:52:00 +030033/* Rotation is defined in the clockwise direction */
Roman Stratiienkoda2fcf62025-01-23 17:47:03 +020034/* The flip is done before rotation */
35struct LayerTransform {
36 bool hflip;
37 bool vflip;
38 bool rotate90;
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020039};
40
Roman Stratiienko4e15bfc2025-01-23 01:55:21 +020041struct 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
52struct 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 Stratiienkofb9fed52025-01-23 02:25:12 +020063constexpr float kAlphaOpaque = 1.0F;
64
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020065struct PresentInfo {
66 LayerTransform transform{};
Roman Stratiienkofb9fed52025-01-23 02:25:12 +020067 float alpha = kAlphaOpaque;
Roman Stratiienko4e15bfc2025-01-23 01:55:21 +020068 SrcRectInfo source_crop{};
69 DstRectInfo display_frame{};
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020070
71 bool RequireScalingOrPhasing() const {
Roman Stratiienko4e15bfc2025-01-23 01:55:21 +020072 if (!source_crop.f_rect || !display_frame.i_rect) {
73 return false;
74 }
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020075
Roman Stratiienko4e15bfc2025-01-23 01:55:21 +020076 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 Stratiienko4b2cc482022-02-21 14:53:58 +020084
Roman Stratiienkoa7913de2022-10-20 13:18:57 +030085 auto scaling = src_width != dest_width || src_height != dest_height;
Roman Stratiienko4e15bfc2025-01-23 01:55:21 +020086 auto phasing = (src.left - std::floor(src.left) != 0) ||
87 (src.top - std::floor(src.top) != 0);
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020088 return scaling || phasing;
89 }
90};
91
92struct LayerData {
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020093 std::optional<BufferInfo> bi;
94 std::shared_ptr<DrmFbIdHandle> fb;
95 PresentInfo pi;
Roman Stratiienko76892782023-01-16 17:15:53 +020096 SharedFd acquire_fence;
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020097};
98
99} // namespace android