gintctl/src/perf/render.c

116 lines
2.3 KiB
C

#include <gint/keyboard.h>
#include <gint/display.h>
#include <gint/std/stdio.h>
#include <gintctl/util.h>
#include <gintctl/prof-contexts.h>
#include <gintctl/perf.h>
#include <libprof.h>
struct elapsed {
uint32_t clear;
uint32_t update;
uint32_t rect1, rect2, rect3;
};
static void run_test(struct elapsed *time)
{
#define test(ctx, out, command) { \
prof_clear(ctx); \
prof_enter(ctx); \
command; \
prof_leave(ctx); \
out = prof_time(ctx); \
}
test(PROFCTX_DUPDATE, time->update,
dupdate()
);
test(PROFCTX_DCLEAR, time->clear,
dclear(C_WHITE)
);
test(PROFCTX_DRECT1, time->rect1,
drect(0, 0, 31, 31, C_WHITE)
);
test(PROFCTX_DRECT2, time->rect2,
drect(1, 1, 32, 32, C_WHITE)
);
test(PROFCTX_DRECT3, time->rect3,
drect(0, 0, _(127,395), _(63,223), C_WHITE)
);
#undef test
}
char *printtime(uint32_t us)
{
static char str[20];
if(us < 1000) sprintf(str, "%d us", us);
else sprintf(str, "%.1j ms", us / 100);
return str;
}
/* gintctl_perf_render(): Profile the display primitives */
void gintctl_perf_render(void)
{
int key = 0, test = 0;
struct elapsed time = {};
while(key != KEY_EXIT)
{
dclear(C_WHITE);
#ifdef FX9860G
row_print(1, 1, "Rendering functions");
if(test)
{
row_print(2, 1, "dclear: %s", printtime(time.clear));
row_print(3, 1, "dupdate: %s", printtime(time.update));
row_print(4, 1, "rect1: %s", printtime(time.rect1));
row_print(5, 1, "rect2: %s", printtime(time.rect2));
row_print(6, 1, "rect3: %s", printtime(time.rect3));
}
extern image_t img_opt_perf_render;
dimage(0, 56, &img_opt_perf_render);
#endif
#ifdef FXCG50
row_title("Rendering functions");
row_print(1, 1, "This program measures the execution time of");
row_print(2, 1, "common drawing functions.");
row_print(4, 1, "Press F1 to start the test.");
if(test)
{
print(6, 90, "dclear:");
print(6, 105, "%s", printtime(time.clear));
print(83, 90, "dupdate:");
print(83, 105, "%s", printtime(time.update));
print(160, 90, "rect1:");
print(160, 105, "%s", printtime(time.rect1));
print(237, 90, "rect2:");
print(237, 105, "%s", printtime(time.rect2));
print(314, 90, "rect3:");
print(314, 105, "%s", printtime(time.rect3));
}
fkey_button(1, "START");
#endif
dupdate();
key = getkey().key;
if(key == KEY_F1) run_test(&time), test = 1;
}
}