blob: 90ae7becdd5c0c2501fafce26d97a3d403afe5f7 [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 Stratiienkoee6d8432025-02-14 06:25:30 +020033using ILayerId = int64_t;
34
Roman Stratiienkob9bd2712023-10-15 01:52:00 +030035/* Rotation is defined in the clockwise direction */
Roman Stratiienkoda2fcf62025-01-23 17:47:03 +020036/* The flip is done before rotation */
37struct LayerTransform {
38 bool hflip;
39 bool vflip;
40 bool rotate90;
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020041};
42
Roman Stratiienko4e15bfc2025-01-23 01:55:21 +020043struct SrcRectInfo {
44 struct FRect {
45 float left;
46 float top;
47 float right;
48 float bottom;
49 };
50 /* nullopt means the whole buffer */
51 std::optional<FRect> f_rect;
52};
53
54struct DstRectInfo {
55 struct IRect {
56 int32_t left;
57 int32_t top;
58 int32_t right;
59 int32_t bottom;
60 };
61 /* nullopt means the whole display */
62 std::optional<IRect> i_rect;
63};
64
Roman Stratiienkofb9fed52025-01-23 02:25:12 +020065constexpr float kAlphaOpaque = 1.0F;
66
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020067struct PresentInfo {
68 LayerTransform transform{};
Roman Stratiienkofb9fed52025-01-23 02:25:12 +020069 float alpha = kAlphaOpaque;
Roman Stratiienko4e15bfc2025-01-23 01:55:21 +020070 SrcRectInfo source_crop{};
71 DstRectInfo display_frame{};
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020072
73 bool RequireScalingOrPhasing() const {
Roman Stratiienko4e15bfc2025-01-23 01:55:21 +020074 if (!source_crop.f_rect || !display_frame.i_rect) {
75 return false;
76 }
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020077
Roman Stratiienko4e15bfc2025-01-23 01:55:21 +020078 const auto &src = *source_crop.f_rect;
79 const auto &dst = *display_frame.i_rect;
80
81 const float src_width = src.right - src.left;
82 const float src_height = src.bottom - src.top;
83
84 auto dest_width = float(dst.right - dst.left);
85 auto dest_height = float(dst.bottom - dst.top);
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020086
Roman Stratiienkoa7913de2022-10-20 13:18:57 +030087 auto scaling = src_width != dest_width || src_height != dest_height;
Roman Stratiienko4e15bfc2025-01-23 01:55:21 +020088 auto phasing = (src.left - std::floor(src.left) != 0) ||
89 (src.top - std::floor(src.top) != 0);
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020090 return scaling || phasing;
91 }
92};
93
94struct LayerData {
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020095 std::optional<BufferInfo> bi;
96 std::shared_ptr<DrmFbIdHandle> fb;
97 PresentInfo pi;
Roman Stratiienko76892782023-01-16 17:15:53 +020098 SharedFd acquire_fence;
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020099};
100
101} // namespace android