mirror of
https://github.com/VincentWei/MiniGUI.git
synced 2026-02-07 11:01:57 +08:00
tune shadow and drm video engines to show FPS
This commit is contained in:
@@ -47,6 +47,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// #define _DEBUG
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#ifdef _MGGAL_DRM
|
||||
@@ -1135,7 +1137,7 @@ static int open_drm_device(GAL_VideoDevice *device)
|
||||
int auth_result;
|
||||
|
||||
if (drmGetMagic(fd, &magic)) {
|
||||
_DBG_PRINTF("failed to call drmGetMagic: %m\n");
|
||||
_ERR_PRINTF("failed to call drmGetMagic: %m\n");
|
||||
return -errno;
|
||||
}
|
||||
|
||||
@@ -2507,11 +2509,11 @@ static void update_real_screen_memcpy(_THIS)
|
||||
int real_pitch = real_buff->pitch;
|
||||
size_t count = cpp * RECTWP(update_rect);
|
||||
|
||||
#if 0 // def _DEBUG
|
||||
_DBG_PRINTF("Copy pixels to real screen (pitch: %u, count: %u, %d x %d)\n",
|
||||
(unsigned)real_buff->pitch, (unsigned)count,
|
||||
RECTWP(update_rect), RECTHP(update_rect));
|
||||
|
||||
#ifdef _DEBUG
|
||||
struct timespec ts_start;
|
||||
clock_gettime(CLOCK_REALTIME, &ts_start);
|
||||
#endif
|
||||
@@ -2539,7 +2541,7 @@ static void update_real_screen_memcpy(_THIS)
|
||||
}
|
||||
drm_dmabuf_end(real_buff);
|
||||
|
||||
#ifdef _DEBUG
|
||||
#if 0 // def _DEBUG
|
||||
double elapsed = get_elapsed_seconds(&ts_start, NULL);
|
||||
_MG_PRINTF("Cosumed time to update real screen: %f (seconds)\n", elapsed);
|
||||
#endif
|
||||
@@ -2562,7 +2564,6 @@ static void* task_do_update(void *data)
|
||||
(this->hidden->crtc_idx << DRM_VBLANK_HIGH_CRTC_SHIFT);
|
||||
vbl.request.sequence = 1;
|
||||
vbl.request.signal = 0;
|
||||
_DBG_PRINTF("VBL type: 0x%08x\n", vbl.request.type);
|
||||
if (drmWaitVBlank(this->hidden->dev_fd, &vbl)) {
|
||||
_WRN_PRINTF("Failed drmWaitVBlank(%d): %m\n", this->hidden->crtc_idx);
|
||||
}
|
||||
@@ -2574,6 +2575,10 @@ static void* task_do_update(void *data)
|
||||
this->hidden->updater_ready = 1;
|
||||
sem_post(&this->hidden->sync_sem);
|
||||
|
||||
#ifdef _DEBUG
|
||||
clock_gettime(CLOCK_REALTIME, &this->hidden->ts_start);
|
||||
#endif
|
||||
|
||||
do {
|
||||
|
||||
if (vbl_ok) {
|
||||
@@ -2584,13 +2589,15 @@ static void* task_do_update(void *data)
|
||||
vbl.request.sequence = 1;
|
||||
vbl.request.signal = 0;
|
||||
drmWaitVBlank(this->hidden->dev_fd, &vbl);
|
||||
_DBG_PRINTF("Got a VBlank, it's time to update real screen. (%ld.%06ld)\n",
|
||||
vbl.reply.tval_sec, vbl.reply.tval_usec);
|
||||
}
|
||||
else {
|
||||
usleep(this->hidden->update_interval * 1000);
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
this->hidden->frames++;
|
||||
#endif
|
||||
|
||||
sem_wait(this->hidden->update_lock);
|
||||
if (RECTH(this->hidden->update_rect)) {
|
||||
update_real_screen_memcpy(this);
|
||||
@@ -2648,6 +2655,10 @@ static void cancel_async_updater(_THIS)
|
||||
if (this->hidden->updater_ready) {
|
||||
pthread_cancel(this->hidden->update_thd);
|
||||
pthread_join(this->hidden->update_thd, NULL);
|
||||
#ifdef _DEBUG
|
||||
double elapsed = get_elapsed_seconds(&this->hidden->ts_start, NULL);
|
||||
_DBG_PRINTF("Frames per second: %f\n", this->hidden->frames / elapsed);
|
||||
#endif
|
||||
|
||||
sem_destroy(&this->hidden->sync_sem);
|
||||
}
|
||||
@@ -2656,7 +2667,6 @@ static void cancel_async_updater(_THIS)
|
||||
static int DRM_LockHWSurface(_THIS, GAL_Surface *surface)
|
||||
{
|
||||
if (surface == this->screen && this->hidden->updater_ready) {
|
||||
_DBG_PRINTF("called\n");
|
||||
sem_wait(this->hidden->update_lock);
|
||||
return 0;
|
||||
}
|
||||
@@ -2667,7 +2677,6 @@ static int DRM_LockHWSurface(_THIS, GAL_Surface *surface)
|
||||
static void DRM_UnlockHWSurface(_THIS, GAL_Surface *surface)
|
||||
{
|
||||
if (surface == this->screen && this->hidden->updater_ready) {
|
||||
_DBG_PRINTF("called\n");
|
||||
sem_post(this->hidden->update_lock);
|
||||
}
|
||||
}
|
||||
@@ -3812,8 +3821,7 @@ static BOOL DRM_SyncUpdate(_THIS)
|
||||
this->hidden->driver_ops->flush_driver(this->hidden->driver);
|
||||
}
|
||||
|
||||
_DBG_PRINTF("called: %d, %d, %d, %d\n",
|
||||
bound.left, bound.top,
|
||||
_DBG_PRINTF("called: %d, %d, %d, %d\n", bound.left, bound.top,
|
||||
bound.right, bound.bottom);
|
||||
|
||||
{
|
||||
|
||||
@@ -122,6 +122,12 @@ typedef struct GAL_PrivateVideoData {
|
||||
RECT update_rect;
|
||||
pthread_t update_thd;
|
||||
sem_t sync_sem;
|
||||
|
||||
#ifdef _DEBUG
|
||||
struct timespec ts_start;
|
||||
unsigned frames;
|
||||
#endif
|
||||
|
||||
} DrmVideoData;
|
||||
|
||||
#endif /* _NEWGAL_DRIVIDEO_H */
|
||||
|
||||
@@ -56,6 +56,8 @@
|
||||
#include <error.h>
|
||||
#include <time.h>
|
||||
|
||||
#define _DEBUG
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#if __LINUX__
|
||||
@@ -137,7 +139,7 @@ static void refresh_ccw_32bpp(ShadowFBHeader* shadowfb_header,
|
||||
int dst_width, dst_height;
|
||||
int x, y;
|
||||
|
||||
#ifdef _DEBUG
|
||||
#if 0 // def _DEBUG
|
||||
struct timespec ts_start;
|
||||
clock_gettime(CLOCK_REALTIME, &ts_start);
|
||||
#endif
|
||||
@@ -171,7 +173,7 @@ static void refresh_ccw_32bpp(ShadowFBHeader* shadowfb_header,
|
||||
dst_line -= realfb_info->pitch;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
#if 0 // def _DEBUG
|
||||
double elapsed = get_elapsed_seconds(&ts_start, NULL);
|
||||
_MG_PRINTF("Cosumed time to rotate dirty rect (ccw): %f (seconds)\n", elapsed);
|
||||
#endif
|
||||
@@ -187,7 +189,7 @@ static void refresh_cw_32bpp(ShadowFBHeader* shadowfb_header,
|
||||
int dst_width, dst_height;
|
||||
int x, y;
|
||||
|
||||
#ifdef _DEBUG
|
||||
#if 0 // def _DEBUG
|
||||
struct timespec ts_start;
|
||||
clock_gettime(CLOCK_REALTIME, &ts_start);
|
||||
#endif
|
||||
@@ -204,48 +206,59 @@ static void refresh_cw_32bpp(ShadowFBHeader* shadowfb_header,
|
||||
dst_line = (BYTE *)realfb_info->fb + dst_update.top *
|
||||
realfb_info->pitch;
|
||||
|
||||
int src_pitch = shadowfb_header->pitch / 4;
|
||||
int dst_pitch = realfb_info->pitch / 4;
|
||||
for (x = 0; x < dst_height; x++) {
|
||||
/* Copy the bits from vertical line to horizontal line */
|
||||
const BYTE* ver_bits = src_bits;
|
||||
BYTE* hor_bits = line_pixels;
|
||||
const Uint32 *src_pixels = (const Uint32 *)src_bits;
|
||||
Uint32 *dst_pixels = (Uint32 *)dst_line;
|
||||
dst_pixels += dst_update.left;
|
||||
|
||||
for (y = 0; y < dst_width; y++) {
|
||||
*(Uint32 *)hor_bits = *(Uint32 *)ver_bits;
|
||||
ver_bits -= shadowfb_header->pitch;
|
||||
hor_bits += 4;
|
||||
*dst_pixels = *src_pixels;
|
||||
src_pixels -= src_pitch;
|
||||
dst_pixels += 1;
|
||||
}
|
||||
|
||||
memcpy(dst_line + (dst_update.left << 2), line_pixels,
|
||||
dst_width << 2);
|
||||
src_bits += 4;
|
||||
dst_line += realfb_info->pitch;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
#if 0 // def _DEBUG
|
||||
double elapsed = get_elapsed_seconds(&ts_start, NULL);
|
||||
_MG_PRINTF("Cosumed time to rotate dirty rect (cw): %f (seconds)\n", elapsed);
|
||||
#endif
|
||||
}
|
||||
|
||||
extern void refresh_normal_msb_left (ShadowFBHeader * shadowfb_header, RealFBInfo *realfb_info, void* update);
|
||||
extern void refresh_normal_msb_left (ShadowFBHeader * shadowfb_header,
|
||||
RealFBInfo *realfb_info, void* update);
|
||||
|
||||
extern void refresh_cw_msb_left (ShadowFBHeader *shadowfb_header, RealFBInfo *realfb_info, void* update);
|
||||
extern void refresh_cw_msb_left (ShadowFBHeader *shadowfb_header,
|
||||
RealFBInfo *realfb_info, void* update);
|
||||
|
||||
extern void refresh_ccw_msb_left (ShadowFBHeader* shadowfb_header, RealFBInfo* realfb_info, void* update);
|
||||
extern void refresh_ccw_msb_left (ShadowFBHeader* shadowfb_header,
|
||||
RealFBInfo* realfb_info, void* update);
|
||||
|
||||
extern void refresh_hflip_msb_left (ShadowFBHeader* shadowfb_header, RealFBInfo* realfb_info, void* update);
|
||||
extern void refresh_hflip_msb_left (ShadowFBHeader* shadowfb_header,
|
||||
RealFBInfo* realfb_info, void* update);
|
||||
|
||||
extern void refresh_vflip_msb_left (ShadowFBHeader* shadowfb_header, RealFBInfo* realfb_info, void* update);
|
||||
extern void refresh_vflip_msb_left (ShadowFBHeader* shadowfb_header,
|
||||
RealFBInfo* realfb_info, void* update);
|
||||
|
||||
extern void refresh_normal_msb_right (ShadowFBHeader * shadowfb_header, RealFBInfo *realfb_info, void* update);
|
||||
extern void refresh_normal_msb_right (ShadowFBHeader * shadowfb_header,
|
||||
RealFBInfo *realfb_info, void* update);
|
||||
|
||||
extern void refresh_cw_msb_right (ShadowFBHeader *shadowfb_header, RealFBInfo *realfb_info, void* update);
|
||||
extern void refresh_cw_msb_right (ShadowFBHeader *shadowfb_header,
|
||||
RealFBInfo *realfb_info, void* update);
|
||||
|
||||
extern void refresh_ccw_msb_right (ShadowFBHeader* shadowfb_header, RealFBInfo* realfb_info, void* update);
|
||||
extern void refresh_ccw_msb_right (ShadowFBHeader* shadowfb_header,
|
||||
RealFBInfo* realfb_info, void* update);
|
||||
|
||||
extern void refresh_hflip_msb_right (ShadowFBHeader* shadowfb_header, RealFBInfo* realfb_info, void* update);
|
||||
extern void refresh_hflip_msb_right (ShadowFBHeader* shadowfb_header,
|
||||
RealFBInfo* realfb_info, void* update);
|
||||
|
||||
extern void refresh_vflip_msb_right (ShadowFBHeader* shadowfb_header, RealFBInfo* realfb_info, void* update);
|
||||
extern void refresh_vflip_msb_right (ShadowFBHeader* shadowfb_header,
|
||||
RealFBInfo* realfb_info, void* update);
|
||||
|
||||
/* Initialization/Query functions */
|
||||
static int SHADOW_VideoInit (_THIS, GAL_PixelFormat *vformat);
|
||||
@@ -550,7 +563,6 @@ static int SHADOW_LockHWSurface(_THIS, GAL_Surface *surface)
|
||||
if (pthread_mutex_lock(&this->hidden->update_lock))
|
||||
_ERR_PRINTF("Failed pthread_mutex_lock(): %m\n");
|
||||
#endif
|
||||
_DBG_PRINTF("locked\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -567,7 +579,6 @@ static void SHADOW_UnlockHWSurface(_THIS, GAL_Surface *surface)
|
||||
if (pthread_mutex_unlock(&this->hidden->update_lock))
|
||||
_ERR_PRINTF("Failed pthread_mutex_unlock(): %m\n");
|
||||
#endif
|
||||
_DBG_PRINTF("unlocked\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -627,6 +638,10 @@ static void *task_do_update(void *data)
|
||||
this->hidden->async_update = 1;
|
||||
sem_post(&this->hidden->sync_sem);
|
||||
|
||||
#ifdef _DEBUG
|
||||
clock_gettime(CLOCK_REALTIME, &this->hidden->ts_start);
|
||||
#endif
|
||||
|
||||
do {
|
||||
GAL_VideoDevice *real_device;
|
||||
real_device = this->hidden->realfb_info->real_device;
|
||||
@@ -638,6 +653,10 @@ static void *task_do_update(void *data)
|
||||
usleep(this->hidden->update_interval * 1000);
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
this->hidden->frames++;
|
||||
#endif
|
||||
|
||||
#if USE_UPDATE_SEM
|
||||
if (sem_wait(&this->hidden->update_sem))
|
||||
_ERR_PRINTF("Failed sem_wait(): %m\n");
|
||||
@@ -645,7 +664,6 @@ static void *task_do_update(void *data)
|
||||
if (pthread_mutex_lock(&this->hidden->update_lock))
|
||||
_ERR_PRINTF("Failed pthread_mutex_lock(): %m\n");
|
||||
#endif
|
||||
_DBG_PRINTF("locked\n");
|
||||
|
||||
if (RECTH(this->hidden->update_rect)) {
|
||||
|
||||
@@ -693,7 +711,6 @@ static void *task_do_update(void *data)
|
||||
if (pthread_mutex_unlock(&this->hidden->update_lock))
|
||||
_ERR_PRINTF("Failed pthread_mutex_unlock(): %m\n");
|
||||
#endif
|
||||
_DBG_PRINTF("unlocked\n");
|
||||
|
||||
} while (1);
|
||||
|
||||
@@ -752,6 +769,10 @@ static void cancel_async_updater(_THIS)
|
||||
if (this->hidden->async_update) {
|
||||
pthread_cancel(this->hidden->update_thd);
|
||||
pthread_join(this->hidden->update_thd, NULL);
|
||||
#ifdef _DEBUG
|
||||
double elapsed = get_elapsed_seconds(&this->hidden->ts_start, NULL);
|
||||
_DBG_PRINTF("Frames per second: %f\n", this->hidden->frames / elapsed);
|
||||
#endif
|
||||
|
||||
#if USE_UPDATE_SEM
|
||||
sem_destroy(&this->hidden->update_sem);
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -119,6 +120,11 @@ struct GAL_PrivateVideoData {
|
||||
#else
|
||||
pthread_mutex_t update_lock;
|
||||
#endif
|
||||
|
||||
#ifdef _DEBUG
|
||||
struct timespec ts_start;
|
||||
unsigned frames;
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef struct _ShadowFBOps {
|
||||
|
||||
Reference in New Issue
Block a user