/* Copyright Statement: * * This software/firmware and related documentation ("MediaTek Software") are * protected under relevant copyright laws. The information contained herein is * confidential and proprietary to MediaTek Inc. and/or its licensors. Without * the prior written permission of MediaTek inc. and/or its licensors, any * reproduction, modification, use or disclosure of MediaTek Software, and * information contained herein, in whole or in part, shall be strictly * prohibited. * * MediaTek Inc. (C) 2022. All rights reserved. * * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER * ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, * INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK * SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE * RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE * MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE * CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. * * The following software/firmware and/or related documentation ("MediaTek * Software") have been modified by MediaTek Inc. All revisions are subject to * any receiver's applicable license agreements with MediaTek Inc. */ #pragma once #include #include #include #include "Scheduler/VsyncModulator.h" #define MTK_DURATION_PREFIX "vendor.debug.sf.dynamic_duration." #define MTK_DURATION_SF_EARLY MTK_DURATION_PREFIX "sf.early." #define MTK_DURATION_APP_EARLY MTK_DURATION_PREFIX "app.early." #define MTK_DURATION_SF_EARLYGL MTK_DURATION_PREFIX "sf.earlyGl." #define MTK_DURATION_APP_EARLYGL MTK_DURATION_PREFIX "app.earlyGl." #define MTK_DURATION_SF_LATE MTK_DURATION_PREFIX "sf.late." #define MTK_DURATION_APP_LATE MTK_DURATION_PREFIX "app.late." #define MTK_DURATION_SF_DECOUPLE MTK_DURATION_PREFIX "sf.decouple" #define MTK_DURATION_APP_DECOUPLE MTK_DURATION_PREFIX "app.decouple" namespace android { // --------------------------------------------------------------------------- class MtkDuration { private: MtkDuration(); const int DurationType_Unset = 0x0; const int DurationType_Decouple = 1; const int DurationType_Override = 1<<1; scheduler::VsyncConfig mDecoupleDuration; scheduler::VsyncConfig mOverrideDuration; const nsecs_t DEFAULT_MIN_VSYNC = 16666667; const nsecs_t DEFAULT_MAX_VSYNC = 8333333; int mType; std::mutex mTypeMutex; nsecs_t mVsyncPeriod; bool mIsExtraVsyncSupported; struct ExtraVsyncRequest { uint64_t disp_id; uint32_t count; ExtraVsyncRequest(uint64_t d, uint32_t c) { disp_id = d; count = c; } }; std::vector mRequestedExtraVsyncCounts; std::mutex mExtraVsyncMutex; bool mIsClientComposition; void updateDurations(); void updateDurationOffset(scheduler::VsyncConfig&); // Decouple mode - START static const nsecs_t MIN_TRANSACTION_FRAMES = 5; uint64_t mActiveDisplayId; struct DisplayMML{ uint64_t displayId; bool decoupleMode; int transactionFrames; bool transactionMode; DisplayMML(uint64_t dId, bool dMode, int tF, bool tM) { displayId = dId; decoupleMode = dMode; transactionFrames = tF; transactionMode = tM; } }; // we use an array to keep multiple display state. static const size_t INVALID_ACTIVE_DISPLAY_INDEX = 999; size_t mActiveDisplayIndex; std::vector mDispMML; bool mDecoupleModeSwitch; bool mDrawingDecoupleMode; std::mutex mDecoupleModeMutex; bool duringTransaction(size_t i); void decreTransactionFrames(); bool getDecoupleModeLocked(size_t i); size_t getActiveDisplayIndex(); bool isDecoupleModeChange(); bool isDecoupleModeAvailable(); // Decouple mode - END // Override mode - START bool mOverrideModeSwitch; bool mOverrideModeChange; std::mutex mOverrideModeMutex; bool isOverrideModeChange(); // Override mode - END public: static MtkDuration& getInstance() { static MtkDuration gInstance; return gInstance; } ~MtkDuration() {}; nsecs_t initMtkDuration(const char* type, nsecs_t vsync, nsecs_t /*default*/) const; bool isEnable(); bool usingMtkDuration(); scheduler::VsyncConfig getMtkDuration( scheduler::VsyncConfig&); void setVsyncPeriod(nsecs_t vsync); bool onDisplayRefresh(); std::chrono::nanoseconds getCurrentMtkPresentLatency( std::chrono::nanoseconds, std::chrono::nanoseconds); std::chrono::nanoseconds getDecoupleMtkPresentLatency( std::chrono::nanoseconds, std::chrono::nanoseconds); void dump(std::string& result); void setIsExtraVsyncSupported(bool); uint32_t setExtraVsyncCount(uint64_t, uint32_t); size_t getExtraVsyncCount(); void setIsClientComposition(bool); bool controlGpuBackpressure(bool); int getExtraBuffers(); // Decouple mode - START bool getDecoupleModeUpdate(); void setDecoupleMode(uint64_t id, bool mode); void updateActiveDisplayId(uint64_t id); void onNewInternalDisplay(uint64_t id); // Decouple mode - END // Override mode - START void setOverrideDuration(nsecs_t app, nsecs_t sf); // Override mode - END }; // --------------------------------------------------------------------------- }; // namespace android