aboutsummaryrefslogtreecommitdiff
path: root/libgui/gui.c
diff options
context:
space:
mode:
authorMarvin Borner2020-08-25 21:14:47 +0200
committerMarvin Borner2020-08-25 21:14:47 +0200
commitd2017fca3efefdb4d514f2b356855a0fda1fccfd (patch)
treeebfddbbb5c6c30ae309085a6d3457b9146cd8e6c /libgui/gui.c
parent0724b54018c379850e672ad6571e05b3f848150d (diff)
Some optimizations or sth
Diffstat (limited to 'libgui/gui.c')
-rw-r--r--libgui/gui.c55
1 files changed, 32 insertions, 23 deletions
diff --git a/libgui/gui.c b/libgui/gui.c
index 118bd95..0759df6 100644
--- a/libgui/gui.c
+++ b/libgui/gui.c
@@ -4,6 +4,7 @@
#include <assert.h>
#include <bmp.h>
#include <gui.h>
+#include <mem.h>
#include <psf.h>
#include <str.h>
#include <sys.h>
@@ -13,9 +14,9 @@ struct font *font;
void gui_write_char(struct vbe *vbe, int x, int y, const u32 c[3], char ch)
{
- int bpl = vbe->bpp >> 3;
+ int bypp = vbe->bpp >> 3;
- int pos = x * bpl + y * vbe->pitch;
+ int pos = x * bypp + y * vbe->pitch;
char *draw = (char *)&vbe->fb[pos];
u32 stride = font->char_size / font->height;
@@ -24,9 +25,9 @@ void gui_write_char(struct vbe *vbe, int x, int y, const u32 c[3], char ch)
u8 bits = font->chars[ch * font->char_size + cy * stride + cx / 8];
u8 bit = bits >> (7 - cx % 8) & 1;
if (bit) {
- draw[bpl * cx] = c[2];
- draw[bpl * cx + 1] = c[1];
- draw[bpl * cx + 2] = c[0];
+ draw[bypp * cx] = c[2];
+ draw[bypp * cx + 1] = c[1];
+ draw[bypp * cx + 2] = c[0];
}
}
draw += vbe->pitch;
@@ -49,12 +50,12 @@ void gui_load_image(struct window *win, char *path, int x, int y)
// TODO: Support padding with odd widths
u8 *srcfb = bmp->data;
u8 *destfb = win->fb;
- int bpl = bmp->bpp >> 3;
+ int bypp = bmp->bpp >> 3;
for (u32 cy = 0; cy < bmp->height; cy++) {
for (u32 cx = 0; cx < bmp->width; cx++) {
- destfb[bpl * cx + 0] = srcfb[bpl * cx + 0];
- destfb[bpl * cx + 1] = srcfb[bpl * cx + 1];
- destfb[bpl * cx + 2] = srcfb[bpl * cx + 2];
+ destfb[bypp * cx + 0] = srcfb[bypp * cx + 0];
+ destfb[bypp * cx + 1] = srcfb[bypp * cx + 1];
+ destfb[bypp * cx + 2] = srcfb[bypp * cx + 2];
}
srcfb += bmp->pitch;
destfb += win->pitch;
@@ -66,16 +67,24 @@ void gui_load_wallpaper(struct window *win, char *path)
gui_load_image(win, path, 0, 0);
}
+// TODO: Optimize!
void gui_win_on_win(struct window *dest, struct window *src, int x, int y)
{
+ // Optimization?
+ /* if (src->width == dest->width && src->height == dest->height && src->x == 0 && */
+ /* dest->y == 0) { */
+ /* memcpy(dest->fb, src->fb, dest->pitch * dest->height); */
+ /* return; */
+ /* } */
+
+ int bypp = dest->bpp >> 3;
u8 *srcfb = src->fb;
- u8 *destfb = &dest->fb[x * (dest->bpp >> 3) + y * dest->pitch];
- int bpl = dest->bpp >> 3;
+ u8 *destfb = &dest->fb[x * bypp + y * dest->pitch];
for (u32 cy = 0; cy < src->height - 1; cy++) {
for (u32 cx = 0; cx < src->width - 1; cx++) {
- destfb[bpl * cx + 0] = srcfb[bpl * cx + 0];
- destfb[bpl * cx + 1] = srcfb[bpl * cx + 1];
- destfb[bpl * cx + 2] = srcfb[bpl * cx + 2];
+ destfb[bypp * cx + 0] = srcfb[bypp * cx + 0];
+ destfb[bypp * cx + 1] = srcfb[bypp * cx + 1];
+ destfb[bypp * cx + 2] = srcfb[bypp * cx + 2];
}
srcfb += src->pitch;
destfb += dest->pitch;
@@ -84,15 +93,15 @@ void gui_win_on_win(struct window *dest, struct window *src, int x, int y)
void gui_draw_rectangle(struct window *win, int x1, int y1, int x2, int y2, const u32 color[3])
{
- int bpl = win->bpp >> 3;
+ int bypp = win->bpp >> 3;
- int pos1 = x1 * bpl + y1 * win->pitch;
+ int pos1 = x1 * bypp + y1 * win->pitch;
u8 *draw = &win->fb[pos1];
for (int i = 0; i < y2 - y1; i++) {
for (int j = 0; j < x2 - x1; j++) {
- draw[bpl * j + 0] = color[2];
- draw[bpl * j + 1] = color[1];
- draw[bpl * j + 2] = color[0];
+ draw[bypp * j] = color[2];
+ draw[bypp * j + 1] = color[1];
+ draw[bypp * j + 2] = color[0];
}
draw += win->pitch;
}
@@ -108,16 +117,16 @@ void gui_border(struct window *win, const u32 color[3], u32 width)
if (width <= 0)
return;
- int bpl = win->bpp >> 3;
+ int bypp = win->bpp >> 3;
u8 *draw = win->fb;
for (u32 i = 0; i < win->height; i++) {
for (u32 j = 0; j < win->width; j++) {
if (j <= width - 1 || i <= width - 1 ||
j - win->width + width + 1 <= width ||
i - win->height + width + 1 <= width) {
- draw[bpl * j + 0] = color[2];
- draw[bpl * j + 1] = color[1];
- draw[bpl * j + 2] = color[0];
+ draw[bypp * j + 0] = color[2];
+ draw[bypp * j + 1] = color[1];
+ draw[bypp * j + 2] = color[0];
}
}
draw += win->pitch;