optimize x11

This commit is contained in:
Freya Murphy 2023-04-24 00:18:20 -04:00
parent 1a686e0248
commit 0e1fc86d08

View file

@ -44,6 +44,9 @@ static void init_x() {
key_count = dpy->max_keycode - dpy->min_keycode;
key_state = malloc(sizeof(bool) * key_count);
key_checked = malloc(sizeof(bool) * key_count);
memset(key_state, 0, sizeof(bool) * key_count);
memset(key_checked, 0, sizeof(bool) * key_count);
}
static Window create_window(int x, int y, int w, int h, int d) {
@ -54,7 +57,7 @@ static Window create_window(int x, int y, int w, int h, int d) {
exit(EXIT_FAILURE);
}
Visual* visual = vis_info.visual;;
Visual* visual = vis_info.visual;
XSetWindowAttributes xwa;
xwa.background_pixel = 0;
@ -69,14 +72,14 @@ static Window create_window(int x, int y, int w, int h, int d) {
return window;
}
static XImage* create_image(int width, int height) {
static XImage* create_image(int width, int height, void* data) {
return XCreateImage(
dpy,
CopyFromParent,
bit_depth,
ZPixmap,
0,
malloc(width * height * bit_depth / 8),
data,
width,
height,
bit_depth,
@ -118,7 +121,7 @@ void init_screen(struct Screen* screen, uint16_t width, uint16_t height) {
state->height = xwa.height;
screen->internal = state;
XImage* image = create_image(state->width, state->height);
XImage* image = create_image(state->width, state->height, screen->pixels);
state->image = image;
count++;
@ -145,22 +148,6 @@ static void update_delta(struct Screen* screen) {
static void draw_screen(struct Screen* screen) {
WindowState* state = (WindowState*) screen->internal;
uint32_t* src = screen->pixels;
uint32_t* dst = (uint32_t*) state->image->data;
float x_step = screen->width / (float) state->width;
float y_step = screen->height / (float) state->height;
for (int x = 0; x < state->width; x++) {
int px = (int) (x * x_step);
for (int y = 0; y < state->height; y++) {
int py = (int) (y * y_step);
dst[x + y * state->width] = src[px + py * screen->width];
}
}
XPutImage(
dpy,
state->window,
@ -199,9 +186,6 @@ static void handle_event(WindowState* state) {
state->width = xce.width;
state->height = xce.height;
XDestroyImage(state->image);
state->image = create_image(state->width, state->height);
break;
}