1*0a9764feSAndroid Build Coastguard Worker /* 2*0a9764feSAndroid Build Coastguard Worker * Copyright (C) 2022 The Android Open Source Project 3*0a9764feSAndroid Build Coastguard Worker * 4*0a9764feSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*0a9764feSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*0a9764feSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*0a9764feSAndroid Build Coastguard Worker * 8*0a9764feSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*0a9764feSAndroid Build Coastguard Worker * 10*0a9764feSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*0a9764feSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*0a9764feSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*0a9764feSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*0a9764feSAndroid Build Coastguard Worker * limitations under the License. 15*0a9764feSAndroid Build Coastguard Worker */ 16*0a9764feSAndroid Build Coastguard Worker 17*0a9764feSAndroid Build Coastguard Worker #pragma once 18*0a9764feSAndroid Build Coastguard Worker 19*0a9764feSAndroid Build Coastguard Worker #include <hardware/hardware.h> 20*0a9764feSAndroid Build Coastguard Worker #include <hardware/hwcomposer.h> 21*0a9764feSAndroid Build Coastguard Worker 22*0a9764feSAndroid Build Coastguard Worker #include <cmath> 23*0a9764feSAndroid Build Coastguard Worker #include <cstdbool> 24*0a9764feSAndroid Build Coastguard Worker #include <cstdint> 25*0a9764feSAndroid Build Coastguard Worker #include <optional> 26*0a9764feSAndroid Build Coastguard Worker #include <vector> 27*0a9764feSAndroid Build Coastguard Worker 28*0a9764feSAndroid Build Coastguard Worker #include "bufferinfo/BufferInfo.h" 29*0a9764feSAndroid Build Coastguard Worker #include "drm/DrmFbImporter.h" 30*0a9764feSAndroid Build Coastguard Worker #include "utils/fd.h" 31*0a9764feSAndroid Build Coastguard Worker 32*0a9764feSAndroid Build Coastguard Worker namespace android { 33*0a9764feSAndroid Build Coastguard Worker 34*0a9764feSAndroid Build Coastguard Worker class DrmFbIdHandle; 35*0a9764feSAndroid Build Coastguard Worker 36*0a9764feSAndroid Build Coastguard Worker /* Rotation is defined in the clockwise direction */ 37*0a9764feSAndroid Build Coastguard Worker enum LayerTransform : uint32_t { 38*0a9764feSAndroid Build Coastguard Worker kIdentity = 0, 39*0a9764feSAndroid Build Coastguard Worker kFlipH = 1 << 0, 40*0a9764feSAndroid Build Coastguard Worker kFlipV = 1 << 1, 41*0a9764feSAndroid Build Coastguard Worker kRotate90 = 1 << 2, 42*0a9764feSAndroid Build Coastguard Worker kRotate180 = 1 << 3, 43*0a9764feSAndroid Build Coastguard Worker kRotate270 = 1 << 4, 44*0a9764feSAndroid Build Coastguard Worker }; 45*0a9764feSAndroid Build Coastguard Worker 46*0a9764feSAndroid Build Coastguard Worker struct PresentInfo { 47*0a9764feSAndroid Build Coastguard Worker LayerTransform transform{}; 48*0a9764feSAndroid Build Coastguard Worker uint16_t alpha = UINT16_MAX; 49*0a9764feSAndroid Build Coastguard Worker hwc_frect_t source_crop{}; 50*0a9764feSAndroid Build Coastguard Worker hwc_rect_t display_frame{}; 51*0a9764feSAndroid Build Coastguard Worker RequireScalingOrPhasingPresentInfo52*0a9764feSAndroid Build Coastguard Worker bool RequireScalingOrPhasing() const { 53*0a9764feSAndroid Build Coastguard Worker const float src_width = source_crop.right - source_crop.left; 54*0a9764feSAndroid Build Coastguard Worker const float src_height = source_crop.bottom - source_crop.top; 55*0a9764feSAndroid Build Coastguard Worker 56*0a9764feSAndroid Build Coastguard Worker auto dest_width = float(display_frame.right - display_frame.left); 57*0a9764feSAndroid Build Coastguard Worker auto dest_height = float(display_frame.bottom - display_frame.top); 58*0a9764feSAndroid Build Coastguard Worker 59*0a9764feSAndroid Build Coastguard Worker auto scaling = src_width != dest_width || src_height != dest_height; 60*0a9764feSAndroid Build Coastguard Worker auto phasing = (source_crop.left - std::floor(source_crop.left) != 0) || 61*0a9764feSAndroid Build Coastguard Worker (source_crop.top - std::floor(source_crop.top) != 0); 62*0a9764feSAndroid Build Coastguard Worker return scaling || phasing; 63*0a9764feSAndroid Build Coastguard Worker } 64*0a9764feSAndroid Build Coastguard Worker }; 65*0a9764feSAndroid Build Coastguard Worker 66*0a9764feSAndroid Build Coastguard Worker struct LayerData { 67*0a9764feSAndroid Build Coastguard Worker std::optional<BufferInfo> bi; 68*0a9764feSAndroid Build Coastguard Worker std::shared_ptr<DrmFbIdHandle> fb; 69*0a9764feSAndroid Build Coastguard Worker PresentInfo pi; 70*0a9764feSAndroid Build Coastguard Worker SharedFd acquire_fence; 71*0a9764feSAndroid Build Coastguard Worker }; 72*0a9764feSAndroid Build Coastguard Worker 73*0a9764feSAndroid Build Coastguard Worker } // namespace android 74