mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-12-29 11:08:22 -05:00
Clean up Wayland backend GL context and such
This commit is contained in:
parent
51f35e7af0
commit
c9d5a0b2fb
8 changed files with 48 additions and 44 deletions
|
|
@ -110,22 +110,22 @@ int main(int argc, char *argv[]) {
|
|||
.default_color = { 0.25f, 0.25f, 0.25f, 1 },
|
||||
.clear_color = { 0.25f, 0.25f, 0.25f, 1 }
|
||||
};
|
||||
struct compositor_state compositor;
|
||||
|
||||
struct compositor_state compositor = { 0,
|
||||
.data = &state,
|
||||
.output_add_cb = handle_output_add,
|
||||
.output_frame_cb = handle_output_frame,
|
||||
.keyboard_key_cb = handle_keyboard_key,
|
||||
.pointer_motion_cb = handle_pointer_motion,
|
||||
.pointer_button_cb = handle_pointer_button,
|
||||
.pointer_axis_cb = handle_pointer_axis,
|
||||
};
|
||||
compositor_init(&compositor);
|
||||
compositor.output_add_cb = handle_output_add;
|
||||
compositor.output_frame_cb = handle_output_frame;
|
||||
compositor.keyboard_key_cb = handle_keyboard_key;
|
||||
compositor.pointer_motion_cb = handle_pointer_motion;
|
||||
compositor.pointer_button_cb = handle_pointer_button;
|
||||
compositor.pointer_axis_cb = handle_pointer_axis;
|
||||
|
||||
state.renderer = wlr_gles3_renderer_init();
|
||||
state.cat_texture = wlr_render_surface_init(state.renderer);
|
||||
wlr_surface_attach_pixels(state.cat_texture, GL_RGBA,
|
||||
cat_tex.width, cat_tex.height, cat_tex.pixel_data);
|
||||
|
||||
compositor.data = &state;
|
||||
compositor_run(&compositor);
|
||||
|
||||
wlr_surface_destroy(state.cat_texture);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
#include <wayland-server.h>
|
||||
#include <wayland-server-protocol.h>
|
||||
|
|
@ -193,22 +194,23 @@ static void parse_args(int argc, char *argv[], struct wl_list *config) {
|
|||
|
||||
int main(int argc, char *argv[]) {
|
||||
struct sample_state state = { 0 };
|
||||
struct compositor_state compositor;
|
||||
wl_list_init(&state.config);
|
||||
parse_args(argc, argv, &state.config);
|
||||
|
||||
struct compositor_state compositor = { 0,
|
||||
.data = &state,
|
||||
.output_add_cb = handle_output_add,
|
||||
.output_remove_cb = handle_output_remove,
|
||||
.output_frame_cb = handle_output_frame,
|
||||
.keyboard_key_cb = handle_keyboard_key,
|
||||
};
|
||||
compositor_init(&compositor);
|
||||
compositor.output_add_cb = handle_output_add;
|
||||
compositor.output_remove_cb = handle_output_remove;
|
||||
compositor.output_frame_cb = handle_output_frame;
|
||||
compositor.keyboard_key_cb = handle_keyboard_key;
|
||||
|
||||
state.renderer = wlr_gles3_renderer_init();
|
||||
state.cat_texture = wlr_render_surface_init(state.renderer);
|
||||
wlr_surface_attach_pixels(state.cat_texture, GL_RGBA,
|
||||
cat_tex.width, cat_tex.height, cat_tex.pixel_data);
|
||||
|
||||
compositor.data = &state;
|
||||
compositor_run(&compositor);
|
||||
|
||||
wlr_surface_destroy(state.cat_texture);
|
||||
|
|
|
|||
|
|
@ -418,8 +418,6 @@ static void output_remove_notify(struct wl_listener *listener, void *data) {
|
|||
}
|
||||
|
||||
void compositor_init(struct compositor_state *state) {
|
||||
memset(state, 0, sizeof(struct compositor_state));
|
||||
|
||||
state->display = wl_display_create();
|
||||
state->event_loop = wl_display_get_event_loop(state->display);
|
||||
state->session = wlr_session_start(state->display);
|
||||
|
|
@ -457,14 +455,14 @@ void compositor_init(struct compositor_state *state) {
|
|||
state->backend = wlr;
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &state->last_frame);
|
||||
}
|
||||
|
||||
void compositor_run(struct compositor_state *state) {
|
||||
if (!wlr_backend_init(state->backend)) {
|
||||
fprintf(stderr, "Failed to initialize backend\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void compositor_run(struct compositor_state *state) {
|
||||
while (!state->exit) {
|
||||
wl_event_loop_dispatch(state->event_loop, 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,11 +50,11 @@ int main() {
|
|||
.color = { 1.0, 0.0, 0.0 },
|
||||
.dec = 0,
|
||||
};
|
||||
struct compositor_state compositor;
|
||||
|
||||
struct compositor_state compositor = { 0,
|
||||
.data = &state,
|
||||
.output_frame_cb = handle_output_frame,
|
||||
.keyboard_key_cb = handle_keyboard_key,
|
||||
};
|
||||
compositor_init(&compositor);
|
||||
compositor.output_frame_cb = handle_output_frame;
|
||||
compositor.keyboard_key_cb = handle_keyboard_key;
|
||||
compositor.data = &state;
|
||||
compositor_run(&compositor);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -145,19 +145,19 @@ int main(int argc, char *argv[]) {
|
|||
.tool_color = { 1, 1, 1, 1 },
|
||||
.pad_color = { 0.75, 0.75, 0.75, 1.0 }
|
||||
};
|
||||
struct compositor_state compositor;
|
||||
|
||||
struct compositor_state compositor = { 0,
|
||||
.data = &state,
|
||||
.output_frame_cb = handle_output_frame,
|
||||
.keyboard_key_cb = handle_keyboard_key,
|
||||
.tool_axis_cb = handle_tool_axis,
|
||||
.tool_proximity_cb = handle_tool_proximity,
|
||||
.tool_button_cb = handle_tool_button,
|
||||
.pad_button_cb = handle_pad_button,
|
||||
};
|
||||
compositor_init(&compositor);
|
||||
compositor.output_frame_cb = handle_output_frame;
|
||||
compositor.keyboard_key_cb = handle_keyboard_key;
|
||||
compositor.tool_axis_cb = handle_tool_axis;
|
||||
compositor.tool_proximity_cb = handle_tool_proximity;
|
||||
compositor.tool_button_cb = handle_tool_button;
|
||||
compositor.pad_button_cb = handle_pad_button;
|
||||
|
||||
state.renderer = wlr_gles3_renderer_init();
|
||||
|
||||
compositor.data = &state;
|
||||
compositor_run(&compositor);
|
||||
|
||||
wlr_renderer_destroy(state.renderer);
|
||||
|
|
|
|||
|
|
@ -100,21 +100,21 @@ int main(int argc, char *argv[]) {
|
|||
struct sample_state state = {
|
||||
.touch_points = list_create()
|
||||
};
|
||||
struct compositor_state compositor;
|
||||
|
||||
struct compositor_state compositor = { 0,
|
||||
.data = &state,
|
||||
.output_frame_cb = handle_output_frame,
|
||||
.keyboard_key_cb = handle_keyboard_key,
|
||||
.touch_down_cb = handle_touch_down,
|
||||
.touch_up_cb = handle_touch_up,
|
||||
.touch_motion_cb = handle_touch_motion,
|
||||
};
|
||||
compositor_init(&compositor);
|
||||
compositor.output_frame_cb = handle_output_frame;
|
||||
compositor.keyboard_key_cb = handle_keyboard_key;
|
||||
compositor.touch_down_cb = handle_touch_down;
|
||||
compositor.touch_up_cb = handle_touch_up;
|
||||
compositor.touch_motion_cb = handle_touch_motion;
|
||||
|
||||
state.renderer = wlr_gles3_renderer_init();
|
||||
state.cat_texture = wlr_render_surface_init(state.renderer);
|
||||
wlr_surface_attach_pixels(state.cat_texture, GL_RGBA,
|
||||
cat_tex.width, cat_tex.height, cat_tex.pixel_data);
|
||||
|
||||
compositor.data = &state;
|
||||
compositor_run(&compositor);
|
||||
|
||||
wlr_surface_destroy(state.cat_texture);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue