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 <cmath> 20 #include <cstdbool> 21 #include <cstdint> 22 #include <optional> 23 #include <vector> 24 25 #include "bufferinfo/BufferInfo.h" 26 #include "drm/DrmFbImporter.h" 27 #include "utils/fd.h" 28 29 namespace android { 30 31 class DrmFbIdHandle; 32 33 using ILayerId = int64_t; 34 35 /* Rotation is defined in the clockwise direction */ 36 /* The flip is done before rotation */ 37 struct LayerTransform { 38 bool hflip; 39 bool vflip; 40 bool rotate90; 41 }; 42 43 struct 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 54 struct 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 65 constexpr float kAlphaOpaque = 1.0F; 66 67 struct PresentInfo { 68 LayerTransform transform{}; 69 float alpha = kAlphaOpaque; 70 SrcRectInfo source_crop{}; 71 DstRectInfo display_frame{}; 72 RequireScalingOrPhasingPresentInfo73 bool RequireScalingOrPhasing() const { 74 if (!source_crop.f_rect || !display_frame.i_rect) { 75 return false; 76 } 77 78 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); 86 87 auto scaling = src_width != dest_width || src_height != dest_height; 88 auto phasing = (src.left - std::floor(src.left) != 0) || 89 (src.top - std::floor(src.top) != 0); 90 return scaling || phasing; 91 } 92 }; 93 94 struct LayerData { 95 std::optional<BufferInfo> bi; 96 std::shared_ptr<DrmFbIdHandle> fb; 97 PresentInfo pi; 98 SharedFd acquire_fence; 99 }; 100 101 } // namespace android 102