From 51a80930a9bc25fae0728994cab1e0df3b63ef48 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Tue, 27 Apr 2021 23:01:51 +0200 Subject: Huge compositor, timer and yielding improvements --- libs/libc/crt/crt0.c | 6 +++--- libs/libc/inc/sys.h | 9 +++++++++ libs/libgui/gfx.c | 13 +++++++------ libs/libgui/gfx.h | 7 +++++-- libs/libgui/gui.c | 13 ++++++------- 5 files changed, 30 insertions(+), 18 deletions(-) (limited to 'libs') diff --git a/libs/libc/crt/crt0.c b/libs/libc/crt/crt0.c index 3ab7ed4..9e41ae2 100644 --- a/libs/libc/crt/crt0.c +++ b/libs/libc/crt/crt0.c @@ -15,9 +15,9 @@ int main(int, char **); int _start(int argc, char **argv); int _start(int argc, char **argv) { - u32 stamp = 0; - assert(io_read(IO_TIMER, &stamp, 0, sizeof(stamp)) == sizeof(stamp) && stamp); - srand(stamp); + struct timer timer = { 0 }; + assert(io_read(IO_TIMER, &timer, 0, sizeof(timer)) == sizeof(timer)); + srand(timer.rtc + timer.time); __stack_chk_guard = rand(); exit(main(argc, argv)); diff --git a/libs/libc/inc/sys.h b/libs/libc/inc/sys.h index f65e020..7d81f33 100644 --- a/libs/libc/inc/sys.h +++ b/libs/libc/inc/sys.h @@ -75,6 +75,15 @@ struct event_mouse { } but; }; +struct timer { + u32 rtc; + struct { + u32 user; + u32 kernel; + } ticks; + u32 time; +}; + struct stat { u32 dev_id; u32 mode; diff --git a/libs/libgui/gfx.c b/libs/libgui/gfx.c index c26f59a..bddd5ed 100644 --- a/libs/libgui/gfx.c +++ b/libs/libgui/gfx.c @@ -93,6 +93,7 @@ static void write_char(struct context *ctx, vec2 pos, struct font *font, u32 c, static void draw_rectangle(struct context *ctx, vec2 pos1, vec2 pos2, u32 c) { + assert(pos1.x <= pos2.x && pos1.y <= pos2.y); int bypp = ctx->bpp >> 3; u8 *draw = &ctx->fb[pos1.x * bypp + pos1.y * ctx->pitch]; for (u32 i = 0; i < pos2.y - pos1.y; i++) { @@ -230,13 +231,13 @@ void gfx_copy(struct context *dest, struct context *src, vec2 pos, vec2 size) // TODO: Support alpha values other than 0x0 and 0xff (blending) // TODO: Optimize! -void gfx_ctx_on_ctx(struct context *dest, struct context *src, vec2 pos) +void gfx_ctx_on_ctx(struct context *dest, struct context *src, vec2 pos, u8 alpha) { // TODO: Some kind of alpha-acknowledging memcpy? - /* if (src->size.x == dest->size.x && src->size.y == dest->size.y) { */ - /* memcpy(dest->fb, src->fb, dest->pitch * dest->size.y); */ - /* return; */ - /* } */ + if (!alpha && src->size.x == dest->size.x && src->size.y == dest->size.y) { + memcpy(dest->fb, src->fb, dest->pitch * dest->size.y); + return; + } if (src->size.x > dest->size.x || src->size.y > dest->size.y) return; @@ -248,7 +249,7 @@ void gfx_ctx_on_ctx(struct context *dest, struct context *src, vec2 pos) for (u32 cy = 0; cy < src->size.y && cy + pos.y < dest->size.y; cy++) { int diff = 0; for (u32 cx = 0; cx < src->size.x && cx + pos.x < dest->size.x; cx++) { - if (srcfb[bypp - 1]) + if (!alpha || srcfb[bypp - 1]) memcpy(destfb, srcfb, bypp); srcfb += bypp; diff --git a/libs/libgui/gfx.h b/libs/libgui/gfx.h index c3fe5d3..5cf12f8 100644 --- a/libs/libgui/gfx.h +++ b/libs/libgui/gfx.h @@ -43,7 +43,10 @@ #define WF_NO_RESIZE (1 << 2) #define WF_NO_FB (1 << 3) #define WF_NO_WINDOW (1 << 4) -/* #define WF_RELATIVE (1 << 4) */ +#define WF_ALPHA (1 << 5) + +#define GFX_NON_ALPHA 0 +#define GFX_ALPHA 1 enum font_type { FONT_8, FONT_12, FONT_16, FONT_24, FONT_32, FONT_64 }; enum gfx_filter { @@ -78,7 +81,7 @@ void gfx_load_image_filter(struct context *ctx, vec2 pos, enum gfx_filter filter const char *path) NONNULL; void gfx_load_wallpaper(struct context *ctx, const char *path) NONNULL; void gfx_copy(struct context *dest, struct context *src, vec2 pos, vec2 size) NONNULL; -void gfx_ctx_on_ctx(struct context *dest, struct context *src, vec2 pos) NONNULL; +void gfx_ctx_on_ctx(struct context *dest, struct context *src, vec2 pos, u8 alpha) NONNULL; void gfx_draw_rectangle(struct context *ctx, vec2 pos1, vec2 pos2, u32 c) NONNULL; void gfx_fill(struct context *ctx, u32 c) NONNULL; void gfx_border(struct context *ctx, u32 c, u32 width) NONNULL; diff --git a/libs/libgui/gui.c b/libs/libgui/gui.c index ef99d92..046e8bf 100644 --- a/libs/libgui/gui.c +++ b/libs/libgui/gui.c @@ -110,7 +110,6 @@ static u32 wm_conn = 0; static void gui_connect_wm(void) { if (wm_conn) { - // TODO: Fix assert(msg_connect_conn(wm_conn) == EOK); } else { assert(msg_connect_bus("wm", &wm_conn) == EOK); @@ -244,8 +243,8 @@ static res gui_sync_sub_widgets(struct gui_widget *widget) struct node *iterator = widget->children->head; while (iterator) { struct gui_widget *w = iterator->data; - gfx_ctx_on_ctx(&widget->bg, &w->bg, w->pos); - gfx_ctx_on_ctx(&widget->fg, &w->fg, w->pos); + gfx_ctx_on_ctx(&widget->bg, &w->bg, w->pos, GFX_ALPHA); + gfx_ctx_on_ctx(&widget->fg, &w->fg, w->pos, GFX_ALPHA); iterator = iterator->next; } @@ -260,8 +259,8 @@ static res gui_sync_widget(u32 win_id, u32 widget_id) return_errno(ENOENT); gui_sync_sub_widgets(widget); - gfx_ctx_on_ctx(&win->ctx, &widget->bg, widget->pos); - gfx_ctx_on_ctx(&win->ctx, &widget->fg, widget->pos); + gfx_ctx_on_ctx(&win->ctx, &widget->bg, widget->pos, GFX_ALPHA); + gfx_ctx_on_ctx(&win->ctx, &widget->fg, widget->pos, GFX_ALPHA); return_errno(EOK); } @@ -279,8 +278,8 @@ static res gui_sync_widgets(u32 win_id) while (iterator) { struct gui_widget *widget = iterator->data; gui_sync_sub_widgets(widget); - gfx_ctx_on_ctx(&win->ctx, &widget->bg, widget->pos); - gfx_ctx_on_ctx(&win->ctx, &widget->fg, widget->pos); + gfx_ctx_on_ctx(&win->ctx, &widget->bg, widget->pos, GFX_ALPHA); + gfx_ctx_on_ctx(&win->ctx, &widget->fg, widget->pos, GFX_ALPHA); iterator = iterator->next; } -- cgit v1.2.3