191 lines
6.6 KiB
C++
Executable File
191 lines
6.6 KiB
C++
Executable File
/* 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) 2010. 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.
|
|
*/
|
|
|
|
#include <dlfcn.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include "utils/Log.h"
|
|
#include <gui/TraceUtils.h>
|
|
|
|
static int inited = false;
|
|
int g_HWUI_sbe_frame_hint = 0;
|
|
int g_HWUI_sbe_skip_frame_hint = 0;
|
|
// SBE_MASK
|
|
int SBE_FRAME_RESCUE_HINT = 1 << 0;
|
|
int SBE_FRAME_HINT = 1<< 1;
|
|
int SBE_SKIP_FRAME_HINT = 1<< 2;
|
|
int SBE_DEBUG = 1<< 3;
|
|
int frameEndHint = 0;
|
|
int skipFrameCount = 0;
|
|
int skipFrameIdMask = -1;
|
|
unsigned long long last_skip_frame = 0;
|
|
|
|
static void *handle = NULL;
|
|
static int (*fbcNotifySwapBuffers)(void) = NULL;
|
|
static int (*fbcNotifySbeRescue)(int, int, int, unsigned long long) = NULL;
|
|
static int (*fbcNotifyHintFrame)(int32_t, int32_t, unsigned long long,
|
|
int32_t, const char *, int32_t) = NULL;
|
|
|
|
typedef int (*notify_swap_buffers)(void);
|
|
typedef int (*notify_sbe_rescue)(int, int, int, unsigned long long);
|
|
typedef int (*notify_hint_frame)(int32_t, int32_t, unsigned long long,
|
|
int32_t, const char *, int32_t);
|
|
|
|
#define LIB_FULL_NAME "libperfctl.so"
|
|
|
|
static pthread_mutex_t mMutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
static void init()
|
|
{
|
|
void *func = NULL;
|
|
|
|
pthread_mutex_lock(&mMutex);
|
|
if (inited) {
|
|
pthread_mutex_unlock(&mMutex);
|
|
return;
|
|
}
|
|
|
|
// only enter once
|
|
inited = true;
|
|
|
|
handle = dlopen(LIB_FULL_NAME, RTLD_NOW);
|
|
if (handle == NULL) {
|
|
ALOGE("Can't load library: %s", dlerror());
|
|
pthread_mutex_unlock(&mMutex);
|
|
return;
|
|
}
|
|
|
|
func = dlsym(handle, "fbcNotifySwapBuffers");
|
|
fbcNotifySwapBuffers = reinterpret_cast<notify_swap_buffers>(func);
|
|
|
|
if (fbcNotifySwapBuffers == NULL) {
|
|
ALOGE("fbcNotifySwapBuffers error: %s", dlerror());
|
|
}
|
|
|
|
func = dlsym(handle, "fbcNotifySbeRescue");
|
|
fbcNotifySbeRescue = reinterpret_cast<notify_sbe_rescue>(func);
|
|
|
|
if (fbcNotifySbeRescue == NULL) {
|
|
ALOGE("fbcNotifySbeRescue error: %s", dlerror());
|
|
}
|
|
|
|
func = dlsym(handle, "fbcNotifyHintFrame");
|
|
fbcNotifyHintFrame = reinterpret_cast<notify_hint_frame>(func);
|
|
|
|
if (fbcNotifyHintFrame == NULL) {
|
|
ALOGE("fbcNotifyHintFrame error: %s", dlerror());
|
|
fbcNotifyHintFrame = NULL;
|
|
}
|
|
|
|
pthread_mutex_unlock(&mMutex);
|
|
}
|
|
|
|
int notifySwapBuffers(void)
|
|
{
|
|
if (!inited)
|
|
init();
|
|
|
|
// ALOGE("MTKfbc swap buffers");
|
|
if (fbcNotifySwapBuffers) {
|
|
//ALOGE("MTKfbc swap buffers 1");
|
|
return fbcNotifySwapBuffers();
|
|
}
|
|
else {
|
|
//ALOGE("MTKfbc swap buffers 2");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int notifyFrameEnd(int tid, unsigned long long frame_id) {
|
|
if ((g_HWUI_sbe_frame_hint & SBE_DEBUG) != 0) {
|
|
ATRACE_CALL();
|
|
}
|
|
fbcNotifyHintFrame(tid, 1/*frame_end*/, frame_id, 1, NULL, 0);
|
|
return 0;
|
|
}
|
|
|
|
int notifyFpsgoSBERescue(int tid, int start, int enhance, unsigned long long frame_id) {
|
|
if ((g_HWUI_sbe_frame_hint & SBE_DEBUG) != 0) {
|
|
ATRACE_CALL();
|
|
}
|
|
fbcNotifySbeRescue(tid, start, enhance, frame_id);
|
|
return 0;
|
|
}
|
|
|
|
int notifySbeRescue(int tid, int start, int enhance, long long frame_id)
|
|
{
|
|
if (!inited)
|
|
init();
|
|
// ALOGE("MTKfbc notifySbeRescue %d %d %llu", tid, g_HWUI_sbe_frame_hint, frame_id);
|
|
if (fbcNotifySbeRescue && (g_HWUI_sbe_frame_hint & SBE_FRAME_RESCUE_HINT) != 0) {
|
|
notifyFpsgoSBERescue(tid, start, enhance, (frame_id < 0 ? 0 : frame_id));
|
|
}
|
|
//check should start frameEndHint or not
|
|
if (!frameEndHint) {
|
|
frameEndHint = (g_HWUI_sbe_frame_hint & SBE_FRAME_HINT) != 0 ;
|
|
}
|
|
if (frameEndHint && g_HWUI_sbe_skip_frame_hint
|
|
&& last_skip_frame != frame_id && frame_id > 0) {
|
|
// 1. if skip frame is 0, get skip frame count first
|
|
if (skipFrameCount <= 0) {
|
|
skipFrameCount = (g_HWUI_sbe_skip_frame_hint & 0xF);
|
|
skipFrameIdMask = (g_HWUI_sbe_skip_frame_hint >> 4);
|
|
}
|
|
// 2. if skip frame is not 0, check skip or not
|
|
if (skipFrameIdMask == ((int)(frame_id % 1000)) && skipFrameCount-- > 0) {
|
|
frameEndHint = 0;
|
|
}
|
|
// 3. check should reset skip frame hint or not
|
|
if (skipFrameCount == 0) {
|
|
g_HWUI_sbe_skip_frame_hint = 0;
|
|
last_skip_frame = frame_id;
|
|
}
|
|
}
|
|
if (fbcNotifyHintFrame && frameEndHint) {
|
|
skipFrameIdMask = -1;
|
|
skipFrameCount = 0;
|
|
last_skip_frame = 0;
|
|
notifyFrameEnd(tid, frame_id);
|
|
}
|
|
if (frameEndHint) {
|
|
//at last check should end frameEndHint or not
|
|
frameEndHint = (g_HWUI_sbe_frame_hint & SBE_FRAME_HINT) != 0 ;
|
|
}
|
|
return 0;
|
|
}
|