Add lfbview tool: LFB viewer using SDL2
In theory, should work under X and Wayland. It won't work under Windows though because of used system calls.
This commit is contained in:
parent
53683cf146
commit
3345936052
1
.gitignore
vendored
1
.gitignore
vendored
@ -16,6 +16,7 @@ tools/gensamehash
|
||||
tools/mksamehash
|
||||
tools/mkfilepattern
|
||||
tools/lfbviewx
|
||||
tools/lfbview
|
||||
tools/randdir
|
||||
*.qcow2
|
||||
*.img
|
||||
|
40
README
40
README
@ -125,23 +125,35 @@ To load apps at 0 address.
|
||||
Links & Acknowledgements
|
||||
------------------------
|
||||
|
||||
[1] Filesystem in Userspace library
|
||||
https://github.com/libfuse/libfuse
|
||||
[ 1] Filesystem in Userspace
|
||||
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/fuse
|
||||
|
||||
[2] LodePNG by Lode Vandevenne
|
||||
https://lodev.org/lodepng/
|
||||
[ 2] Filesystem in Userspace library
|
||||
https://github.com/libfuse/libfuse
|
||||
|
||||
[3] Optparse by Christopher Wellons
|
||||
https://github.com/skeeto/optparse
|
||||
[ 3] LodePNG by Lode Vandevenne
|
||||
https://lodev.org/lodepng/
|
||||
|
||||
[4] Universal TUN/TAP device driver by Maxim Krasnyansky and others
|
||||
https://www.kernel.org/doc/html/v5.12/networking/tuntap.html
|
||||
[ 4] Optparse by Christopher Wellons
|
||||
https://github.com/skeeto/optparse
|
||||
|
||||
[5] Bestline by Justine Tunney
|
||||
https://github.com/jart/bestline
|
||||
[ 5] Universal TUN/TAP device driver by Maxim Krasnyansky and others
|
||||
https://www.kernel.org/doc/html/v5.12/networking/tuntap.html
|
||||
|
||||
[6] Miniz by Rich Geldreich
|
||||
https://github.com/richgel999/miniz
|
||||
[ 6] Bestline by Justine Tunney
|
||||
https://github.com/jart/bestline
|
||||
|
||||
[7] QEMU by Fabrice Bellard and others
|
||||
https://www.qemu.org
|
||||
[ 7] Miniz by Rich Geldreich
|
||||
https://github.com/richgel999/miniz
|
||||
|
||||
[ 8] qemu-nbd by Anthony Liguori and others
|
||||
https://www.qemu.org/docs/master/tools/qemu-nbd.html
|
||||
|
||||
[ 9] io_uring by Jens Axboe and others
|
||||
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/io_uring
|
||||
|
||||
[10] io_uring-by-example by Shuveb Hussain
|
||||
https://github.com/shuveb/io_uring-by-example
|
||||
|
||||
[11] Simple DirectMedia Layer library aka SDL2
|
||||
https://libsdl.org
|
||||
|
80
tools/lfbview.c
Normal file
80
tools/lfbview.c
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
UMKa - User-Mode KolibriOS developer tools
|
||||
lfbview - KolibriOS framebuffer viewer via SDL2
|
||||
|
||||
Copyright (C) 2023 Ivan Baravy <dunkaist@gmail.com>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/uio.h>
|
||||
#include <unistd.h>
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[]) {
|
||||
const char *usage = "usage: lfbview <pid> <address> <width> <height>";
|
||||
if (argc != 5) {
|
||||
puts(usage);
|
||||
exit(1);
|
||||
}
|
||||
int depth = 32;
|
||||
int umka_pid = strtol(argv[1], NULL, 0);
|
||||
uintptr_t umka_lfb_addr = strtol(argv[2], NULL, 0);
|
||||
size_t lfb_width = strtoul(argv[3], NULL, 0);
|
||||
size_t lfb_height = strtoul(argv[4], NULL, 0);
|
||||
|
||||
if(SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize the SDL2 library\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_Window *window = SDL_CreateWindow("LFB Viewer SDL2",
|
||||
SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED,
|
||||
400, 300,
|
||||
0);
|
||||
|
||||
if(!window)
|
||||
{
|
||||
fprintf(stderr, "Failed to create window\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_Surface *window_surface = SDL_GetWindowSurface(window);
|
||||
|
||||
if(!window_surface)
|
||||
{
|
||||
fprintf(stderr, "Failed to get the surface from the window\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t *lfb = (uint32_t*)malloc(lfb_width*lfb_height*sizeof(uint32_t));
|
||||
|
||||
struct iovec remote = {.iov_base = (void*)umka_lfb_addr,
|
||||
.iov_len = lfb_width*lfb_height*4};
|
||||
struct iovec local = {.iov_base = lfb,
|
||||
.iov_len = lfb_width*lfb_height*4};
|
||||
|
||||
|
||||
uint32_t *p = window_surface->pixels;
|
||||
while (1) {
|
||||
process_vm_readv(umka_pid, &local, 1, &remote, 1, 0);
|
||||
memcpy(window_surface->pixels, lfb, 400*300*4);
|
||||
SDL_LockSurface(window_surface);
|
||||
for (size_t y = 0; y < window_surface->h; y++) {
|
||||
for (size_t x = 0; x < window_surface->w; x++) {
|
||||
p[y*window_surface->pitch/4+x] = lfb[y*400+x];
|
||||
}
|
||||
}
|
||||
SDL_UnlockSurface(window_surface);
|
||||
SDL_UpdateWindowSurface(window);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -8,7 +8,7 @@ CFLAGS=$(WARNINGS) $(NOWARNINGS) -std=c11 -O2 \
|
||||
LDFLAGS=-no-pie
|
||||
|
||||
all: mkdirrange mkfilepattern lfbviewx randdir covpreproc mkdoubledirs \
|
||||
gensamehash mksamehash
|
||||
gensamehash mksamehash lfbview
|
||||
|
||||
gensamehash: gensamehash.c
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
|
||||
@ -28,6 +28,8 @@ mkfilepattern: mkfilepattern.c
|
||||
lfbviewx: lfbviewx.c
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ -lX11 -lXext -D_GNU_SOURCE
|
||||
|
||||
lfbview: lfbview.c
|
||||
$(CC) `sdl2-config --cflags --libs` -o $@ $< -D_GNU_SOURCE
|
||||
randdir: randdir.c
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
|
||||
|
||||
@ -38,4 +40,4 @@ covpreproc: covpreproc.c
|
||||
|
||||
clean:
|
||||
rm -f *.o mkdirrange mkfilepattern lfbviewx randdir covpreproc \
|
||||
mkdoubledirs gensamehash mksamehash
|
||||
mkdoubledirs gensamehash mksamehash lfbview
|
||||
|
Loading…
Reference in New Issue
Block a user