• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
30 #include "utils/UniqueFd.h"
31 
32 namespace android {
33 
34 class DrmFbIdHandle;
35 
36 enum LayerTransform : uint32_t {
37   kIdentity = 0,
38   kFlipH = 1 << 0,
39   kFlipV = 1 << 1,
40   kRotate90 = 1 << 2,
41   kRotate180 = 1 << 3,
42   kRotate270 = 1 << 4,
43 };
44 
45 struct PresentInfo {
46   LayerTransform transform{};
47   uint16_t alpha = UINT16_MAX;
48   hwc_frect_t source_crop{};
49   hwc_rect_t display_frame{};
50 
RequireScalingOrPhasingPresentInfo51   bool RequireScalingOrPhasing() const {
52     float src_width = source_crop.right - source_crop.left;
53     float src_height = source_crop.bottom - source_crop.top;
54 
55     auto dest_width = float(display_frame.right - display_frame.left);
56     auto dest_height = float(display_frame.bottom - display_frame.top);
57 
58     bool scaling = src_width != dest_width || src_height != dest_height;
59     bool phasing = (source_crop.left - std::floor(source_crop.left) != 0) ||
60                    (source_crop.top - std::floor(source_crop.top) != 0);
61     return scaling || phasing;
62   }
63 };
64 
65 struct LayerData {
CloneLayerData66   auto Clone() {
67     LayerData clonned;
68     clonned.bi = bi;
69     clonned.fb = fb;
70     clonned.pi = pi;
71     clonned.acquire_fence = std::move(acquire_fence);
72     return clonned;
73   }
74 
75   std::optional<BufferInfo> bi;
76   std::shared_ptr<DrmFbIdHandle> fb;
77   PresentInfo pi;
78   UniqueFd acquire_fence;
79 };
80 
81 }  // namespace android
82