More efficient screen blitting

This commit is contained in:
K. Lange 2018-03-17 13:04:02 +09:00 committed by Kevin Lange
parent 52680f802d
commit d56c9801ab

View File

@ -43,6 +43,19 @@ typedef struct {
void * next;
} _clip_t;
static int _is_in_clip(gfx_context_t * ctx, int32_t y) {
if (!ctx->clips) return 1;
_clip_t * clip = ctx->clips;
while (clip) {
if (y >= clip->start && y <= clip->end) {
return 1;
}
clip = (_clip_t *)clip->next;
}
return 0;
}
void gfx_add_clip(gfx_context_t * ctx, int32_t x, int32_t y, int32_t w, int32_t h) {
_clip_t * clip = malloc(sizeof(_clip_t));
clip->start = max(y,0);
@ -64,9 +77,14 @@ void gfx_clear_clip(gfx_context_t * ctx) {
/* Pointer to graphics memory */
void flip(gfx_context_t * ctx) {
if (ctx->clips) {
/// do this differently
for (size_t i = 0; i < ctx->height; ++i) {
if (_is_in_clip(ctx,i)) {
memcpy(&ctx->buffer[i*ctx->width*4], &ctx->backbuffer[i*ctx->width*4], 4 * ctx->width);
}
}
} else {
memcpy(ctx->buffer, ctx->backbuffer, ctx->size);
}
memcpy(ctx->buffer, ctx->backbuffer, ctx->size);
}
void clearbuffer(gfx_context_t * ctx) {
@ -544,18 +562,6 @@ _cleanup_sprite:
free(bufferb);
}
static int _is_in_clip(gfx_context_t * ctx, int32_t y) {
if (!ctx->clips) return 1;
_clip_t * clip = ctx->clips;
while (clip) {
if (y >= clip->start && y <= clip->end) {
return 1;
}
clip = (_clip_t *)clip->next;
}
return 0;
}
void draw_sprite(gfx_context_t * ctx, sprite_t * sprite, int32_t x, int32_t y) {
int32_t _left = max(x, 0);
int32_t _top = max(y, 0);