summaryrefslogtreecommitdiff
path: root/src/user/lib
diff options
context:
space:
mode:
authordzwdz2022-08-08 21:13:36 +0200
committerdzwdz2022-08-08 21:13:36 +0200
commit2f6f3ea54ad01f02e68a23345565c34eb47ad365 (patch)
tree5f5c97eca9ab1e6b61a2511d4864803f8bd11557 /src/user/lib
parentcb04eada02bedc5b748e01b09a899dc139c4970f (diff)
user: drawmouse for demoing mouse/graphic support
Diffstat (limited to 'src/user/lib')
-rw-r--r--src/user/lib/draw/draw.c34
-rw-r--r--src/user/lib/draw/draw.h5
2 files changed, 38 insertions, 1 deletions
diff --git a/src/user/lib/draw/draw.c b/src/user/lib/draw/draw.c
index c4508da..27c1d33 100644
--- a/src/user/lib/draw/draw.c
+++ b/src/user/lib/draw/draw.c
@@ -40,11 +40,43 @@ int fb_setup(struct framebuf *fb, const char *base) {
fb->height = strtol(spec, &spec, 0);
if (*spec++ != 'x') return -EINVAL;
fb->bpp = strtol(spec, &spec, 0);
+ if (fb->bpp != 32) return -EINVAL;
+
fb->len = _syscall_getsize(fb->fd);
fb->pitch = fb->len / fb->height;
fb->b = malloc(fb->len);
- if (fb->bpp != 32) return -EINVAL;
+ _syscall_read(fb->fd, fb->b, fb->len, 0);
return 0;
}
+
+int fb_anon(struct framebuf *fb, size_t w, size_t h) {
+ fb->width = w;
+ fb->height = h;
+ fb->bpp = 32;
+ fb->pitch = fb->width * fb->bpp / 8;
+ fb->len = fb->pitch * fb->height;
+ fb->b = malloc(fb->len);
+ fb->fd = -1;
+ return 0;
+}
+
+uint32_t *fb_pixel(struct framebuf *fb, uint32_t x, uint32_t y) {
+ if (x < fb->width && y < fb->height)
+ return (void*)fb->b + fb->pitch * y + 4 * x;
+ return NULL;
+}
+
+void fb_cpy(
+ struct framebuf *dest, const struct framebuf *src,
+ size_t xd, size_t yd, size_t xs, size_t ys, size_t w, size_t h)
+{
+ for (size_t y = 0; y < h; y++) {
+ memcpy(
+ fb_pixel( dest, xd, yd + y),
+ fb_pixel((void*)src, xs, ys + y),
+ w * 4
+ );
+ }
+}
diff --git a/src/user/lib/draw/draw.h b/src/user/lib/draw/draw.h
index ba15840..98316fe 100644
--- a/src/user/lib/draw/draw.h
+++ b/src/user/lib/draw/draw.h
@@ -17,3 +17,8 @@ void dirty_mark(struct rect *d, uint32_t x, uint32_t y);
void dirty_flush(struct rect *d, struct framebuf *fb);
int fb_setup(struct framebuf *fb, const char *base);
+int fb_anon(struct framebuf *fb, size_t w, size_t h);
+uint32_t *fb_pixel(struct framebuf *fb, uint32_t x, uint32_t y);
+void fb_cpy(
+ struct framebuf *dest, const struct framebuf *src,
+ size_t xd, size_t yd, size_t xs, size_t ys, size_t w, size_t h);