mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2024-11-21 14:42:25 +00:00
examples: convert to new rendering API
Left out multi-pointer (will be removed) and quads (requires arbitrary rotation).
This commit is contained in:
parent
8fe29e6bd1
commit
8e81b4bb42
@ -47,7 +47,7 @@ struct fullscreen_output {
|
||||
|
||||
struct render_data {
|
||||
struct wlr_output *output;
|
||||
struct wlr_renderer *renderer;
|
||||
struct wlr_render_pass *render_pass;
|
||||
struct timespec *when;
|
||||
};
|
||||
|
||||
@ -68,13 +68,14 @@ static void render_surface(struct wlr_surface *surface,
|
||||
.height = surface->current.height * output->scale,
|
||||
};
|
||||
|
||||
float matrix[9];
|
||||
enum wl_output_transform transform =
|
||||
wlr_output_transform_invert(surface->current.transform);
|
||||
wlr_matrix_project_box(matrix, &box, transform, 0,
|
||||
output->transform_matrix);
|
||||
enum wl_output_transform transform = wlr_output_transform_invert(surface->current.transform);
|
||||
transform = wlr_output_transform_compose(transform, output->transform);
|
||||
|
||||
wlr_render_texture_with_matrix(rdata->renderer, texture, matrix, 1);
|
||||
wlr_render_pass_add_texture(rdata->render_pass, &(struct wlr_render_texture_options){
|
||||
.texture = texture,
|
||||
.dst_box = box,
|
||||
.transform = transform,
|
||||
});
|
||||
|
||||
wlr_surface_send_frame_done(surface, rdata->when);
|
||||
}
|
||||
@ -82,33 +83,35 @@ static void render_surface(struct wlr_surface *surface,
|
||||
static void output_handle_frame(struct wl_listener *listener, void *data) {
|
||||
struct fullscreen_output *output =
|
||||
wl_container_of(listener, output, frame);
|
||||
struct wlr_renderer *renderer = output->server->renderer;
|
||||
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
int width, height;
|
||||
wlr_output_effective_resolution(output->wlr_output, &width, &height);
|
||||
|
||||
if (!wlr_output_attach_render(output->wlr_output, NULL)) {
|
||||
struct wlr_output_state state = {0};
|
||||
struct wlr_render_pass *pass = wlr_output_begin_render_pass(output->wlr_output, &state, NULL);
|
||||
if (pass == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
wlr_renderer_begin(renderer, width, height);
|
||||
|
||||
float color[4] = {0.3, 0.3, 0.3, 1.0};
|
||||
wlr_renderer_clear(renderer, color);
|
||||
wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){
|
||||
.color = { 0.3, 0.3, 0.3, 1.0 },
|
||||
.box = { .width = width, .height = height },
|
||||
});
|
||||
|
||||
if (output->surface != NULL) {
|
||||
struct render_data rdata = {
|
||||
.output = output->wlr_output,
|
||||
.renderer = renderer,
|
||||
.render_pass = pass,
|
||||
.when = &now,
|
||||
};
|
||||
wlr_surface_for_each_surface(output->surface, render_surface, &rdata);
|
||||
}
|
||||
|
||||
wlr_renderer_end(renderer);
|
||||
wlr_output_commit(output->wlr_output);
|
||||
wlr_render_pass_submit(pass);
|
||||
wlr_output_commit_state(output->wlr_output, &state);
|
||||
wlr_output_state_finish(&state);
|
||||
}
|
||||
|
||||
static void output_set_surface(struct fullscreen_output *output,
|
||||
|
@ -64,7 +64,6 @@ struct output {
|
||||
|
||||
static void output_handle_frame(struct wl_listener *listener, void *data) {
|
||||
struct output *output = wl_container_of(listener, output, frame);
|
||||
struct wlr_renderer *renderer = output->server->renderer;
|
||||
|
||||
struct wl_array layers_arr = {0};
|
||||
struct output_surface *output_surface;
|
||||
@ -91,15 +90,16 @@ static void output_handle_frame(struct wl_listener *listener, void *data) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!wlr_output_attach_render(output->wlr_output, NULL)) {
|
||||
wlr_log(WLR_ERROR, "wlr_output_attach_render() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
int width, height;
|
||||
wlr_output_effective_resolution(output->wlr_output, &width, &height);
|
||||
wlr_renderer_begin(renderer, width, height);
|
||||
wlr_renderer_clear(renderer, (float[4]){ 0.3, 0.3, 0.3, 1.0 });
|
||||
|
||||
struct wlr_output_state output_state = {0};
|
||||
struct wlr_render_pass *pass = wlr_output_begin_render_pass(output->wlr_output, &output_state, NULL);
|
||||
|
||||
wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){
|
||||
.box = { .width = width, .height = height },
|
||||
.color = { 0.3, 0.3, 0.3, 1 },
|
||||
});
|
||||
|
||||
size_t i = 0;
|
||||
struct wlr_output_layer_state *layers = layers_arr.data;
|
||||
@ -118,13 +118,16 @@ static void output_handle_frame(struct wl_listener *listener, void *data) {
|
||||
continue;
|
||||
}
|
||||
|
||||
wlr_render_texture(renderer, texture, output->wlr_output->transform_matrix,
|
||||
output_surface->x, output_surface->y, 1.0);
|
||||
wlr_render_pass_add_texture(pass, &(struct wlr_render_texture_options){
|
||||
.texture = texture,
|
||||
.dst_box = { .x = output_surface->x, .y = output_surface->y },
|
||||
});
|
||||
}
|
||||
|
||||
wlr_renderer_end(renderer);
|
||||
wlr_render_pass_submit(pass);
|
||||
|
||||
wlr_output_commit(output->wlr_output);
|
||||
wlr_output_commit_state(output->wlr_output, &output_state);
|
||||
wlr_output_state_finish(&output_state);
|
||||
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
|
@ -112,14 +112,15 @@ static void animate_cat(struct sample_state *sample,
|
||||
static void output_frame_notify(struct wl_listener *listener, void *data) {
|
||||
struct sample_output *output = wl_container_of(listener, output, frame);
|
||||
struct sample_state *sample = output->sample;
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
|
||||
struct wlr_output *wlr_output = output->output;
|
||||
|
||||
wlr_output_attach_render(wlr_output, NULL);
|
||||
wlr_renderer_begin(sample->renderer, wlr_output->width, wlr_output->height);
|
||||
wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1});
|
||||
struct wlr_output_state output_state = {0};
|
||||
struct wlr_render_pass *pass = wlr_output_begin_render_pass(wlr_output, &output_state, NULL);
|
||||
|
||||
wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){
|
||||
.box = { .width = wlr_output->width, .height = wlr_output->height },
|
||||
.color = { 0.25, 0.25, 0.25, 1 },
|
||||
});
|
||||
|
||||
animate_cat(sample, output->output);
|
||||
|
||||
@ -134,12 +135,15 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
|
||||
wlr_output_layout_output_coords(sample->layout, output->output,
|
||||
&local_x, &local_y);
|
||||
|
||||
wlr_render_texture(sample->renderer, sample->cat_texture,
|
||||
wlr_output->transform_matrix, local_x, local_y, 1.0f);
|
||||
wlr_render_pass_add_texture(pass, &(struct wlr_render_texture_options){
|
||||
.texture = sample->cat_texture,
|
||||
.dst_box = box,
|
||||
});
|
||||
}
|
||||
|
||||
wlr_renderer_end(sample->renderer);
|
||||
wlr_output_commit(wlr_output);
|
||||
wlr_render_pass_submit(pass);
|
||||
wlr_output_commit_state(wlr_output, &output_state);
|
||||
wlr_output_state_finish(&output_state);
|
||||
}
|
||||
|
||||
static void update_velocities(struct sample_state *sample,
|
||||
|
@ -101,12 +101,21 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
|
||||
struct wlr_renderer *renderer = state->renderer;
|
||||
assert(renderer);
|
||||
|
||||
wlr_output_attach_render(wlr_output, NULL);
|
||||
wlr_renderer_begin(renderer, wlr_output->width, wlr_output->height);
|
||||
wlr_renderer_clear(renderer, state->clear_color);
|
||||
wlr_output_render_software_cursors(wlr_output, NULL);
|
||||
wlr_renderer_end(renderer);
|
||||
wlr_output_commit(wlr_output);
|
||||
struct wlr_output_state output_state = {0};
|
||||
struct wlr_render_pass *pass = wlr_output_begin_render_pass(wlr_output, &output_state, NULL);
|
||||
wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){
|
||||
.box = { .width = wlr_output->width, .height = wlr_output->height },
|
||||
.color = {
|
||||
state->clear_color[0],
|
||||
state->clear_color[1],
|
||||
state->clear_color[2],
|
||||
state->clear_color[3],
|
||||
},
|
||||
});
|
||||
wlr_output_add_software_cursors_to_render_pass(wlr_output, pass, NULL);
|
||||
wlr_render_pass_submit(pass);
|
||||
wlr_output_commit_state(wlr_output, &output_state);
|
||||
wlr_output_state_finish(&output_state);
|
||||
}
|
||||
|
||||
static void handle_cursor_motion(struct wl_listener *listener, void *data) {
|
||||
|
@ -59,19 +59,27 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
|
||||
int32_t width, height;
|
||||
wlr_output_effective_resolution(wlr_output, &width, &height);
|
||||
|
||||
wlr_output_attach_render(wlr_output, NULL);
|
||||
wlr_renderer_begin(sample->renderer, wlr_output->width, wlr_output->height);
|
||||
wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1});
|
||||
struct wlr_output_state output_state = {0};
|
||||
struct wlr_render_pass *pass = wlr_output_begin_render_pass(wlr_output, &output_state, NULL);
|
||||
|
||||
wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){
|
||||
.box = { .width = wlr_output->width, .height = wlr_output->height },
|
||||
.color = { 0.25, 0.25, 0.25, 1 },
|
||||
});
|
||||
|
||||
for (int y = -128 + (int)sample_output->y_offs; y < height; y += 128) {
|
||||
for (int x = -128 + (int)sample_output->x_offs; x < width; x += 128) {
|
||||
wlr_render_texture(sample->renderer, sample->cat_texture,
|
||||
wlr_output->transform_matrix, x, y, 1.0f);
|
||||
wlr_render_pass_add_texture(pass, &(struct wlr_render_texture_options){
|
||||
.texture = sample->cat_texture,
|
||||
.dst_box = { .x = x, .y = y },
|
||||
.transform = wlr_output->transform,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
wlr_renderer_end(sample->renderer);
|
||||
wlr_output_commit(wlr_output);
|
||||
wlr_render_pass_submit(pass);
|
||||
wlr_output_commit_state(wlr_output, &output_state);
|
||||
wlr_output_state_finish(&output_state);
|
||||
|
||||
long ms = (now.tv_sec - sample->last_frame.tv_sec) * 1000 +
|
||||
(now.tv_nsec - sample->last_frame.tv_nsec) / 1000000;
|
||||
|
@ -62,14 +62,21 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
|
||||
sample->dec = inc;
|
||||
}
|
||||
|
||||
wlr_output_attach_render(wlr_output, NULL);
|
||||
struct wlr_output_state state = {0};
|
||||
struct wlr_render_pass *pass = wlr_output_begin_render_pass(wlr_output, &state, NULL);
|
||||
wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){
|
||||
.box = { .width = wlr_output->width, .height = wlr_output->height },
|
||||
.color = {
|
||||
.r = sample->color[0],
|
||||
.g = sample->color[1],
|
||||
.b = sample->color[2],
|
||||
.a = sample->color[3],
|
||||
},
|
||||
});
|
||||
wlr_render_pass_submit(pass);
|
||||
|
||||
struct wlr_renderer *renderer = sample->renderer;
|
||||
wlr_renderer_begin(renderer, wlr_output->width, wlr_output->height);
|
||||
wlr_renderer_clear(renderer, sample->color);
|
||||
wlr_renderer_end(renderer);
|
||||
|
||||
wlr_output_commit(wlr_output);
|
||||
wlr_output_commit_state(wlr_output, &state);
|
||||
wlr_output_state_finish(&state);
|
||||
sample->last_frame = now;
|
||||
}
|
||||
|
||||
|
@ -87,9 +87,13 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
|
||||
int32_t width, height;
|
||||
wlr_output_effective_resolution(wlr_output, &width, &height);
|
||||
|
||||
wlr_output_attach_render(wlr_output, NULL);
|
||||
wlr_renderer_begin(sample->renderer, wlr_output->width, wlr_output->height);
|
||||
wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1});
|
||||
struct wlr_output_state output_state = {0};
|
||||
struct wlr_render_pass *pass = wlr_output_begin_render_pass(wlr_output, &output_state, NULL);
|
||||
|
||||
wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){
|
||||
.box = { .width = wlr_output->width, .height = wlr_output->height },
|
||||
.color = { 0.25, 0.25, 0.25, 1 },
|
||||
});
|
||||
|
||||
float distance = 0.8f * (1 - sample->distance);
|
||||
float tool_color[4] = { distance, distance, distance, 1 };
|
||||
@ -108,6 +112,20 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
|
||||
};
|
||||
wlr_render_rect(sample->renderer, &box, sample->pad_color,
|
||||
wlr_output->transform_matrix);
|
||||
wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){
|
||||
.box = {
|
||||
.x = left,
|
||||
.y = top,
|
||||
.width = pad_width,
|
||||
.height = pad_height,
|
||||
},
|
||||
.color = {
|
||||
sample->pad_color[0],
|
||||
sample->pad_color[1],
|
||||
sample->pad_color[2],
|
||||
sample->pad_color[3],
|
||||
},
|
||||
});
|
||||
|
||||
if (sample->proximity) {
|
||||
struct wlr_box box = {
|
||||
@ -116,21 +134,36 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
|
||||
.width = 16 * (sample->pressure + 1),
|
||||
.height = 16 * (sample->pressure + 1),
|
||||
};
|
||||
float matrix[9];
|
||||
wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL,
|
||||
sample->ring, wlr_output->transform_matrix);
|
||||
wlr_render_quad_with_matrix(sample->renderer, tool_color, matrix);
|
||||
|
||||
// TODO: use sample->ring
|
||||
wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){
|
||||
.box = box,
|
||||
.color = {
|
||||
tool_color[0],
|
||||
tool_color[1],
|
||||
tool_color[2],
|
||||
tool_color[3],
|
||||
},
|
||||
});
|
||||
|
||||
box.x += sample->x_tilt;
|
||||
box.y += sample->y_tilt;
|
||||
box.width /= 2;
|
||||
box.height /= 2;
|
||||
wlr_render_rect(sample->renderer, &box, tool_color,
|
||||
wlr_output->transform_matrix);
|
||||
wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){
|
||||
.box = box,
|
||||
.color = {
|
||||
tool_color[0],
|
||||
tool_color[1],
|
||||
tool_color[2],
|
||||
tool_color[3],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
wlr_renderer_end(sample->renderer);
|
||||
wlr_output_commit(wlr_output);
|
||||
wlr_render_pass_submit(pass);
|
||||
wlr_output_commit_state(wlr_output, &output_state);
|
||||
wlr_output_state_finish(&output_state);
|
||||
sample->last_frame = now;
|
||||
}
|
||||
|
||||
|
@ -76,20 +76,26 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
|
||||
int32_t width, height;
|
||||
wlr_output_effective_resolution(wlr_output, &width, &height);
|
||||
|
||||
wlr_output_attach_render(wlr_output, NULL);
|
||||
wlr_renderer_begin(sample->renderer, wlr_output->width, wlr_output->height);
|
||||
wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1});
|
||||
struct wlr_output_state output_state = {0};
|
||||
struct wlr_render_pass *pass = wlr_output_begin_render_pass(wlr_output, &output_state, NULL);
|
||||
wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){
|
||||
.box = { .width = width, .height = height },
|
||||
.color = { 0.25, 0.25, 0.25, 1 },
|
||||
});
|
||||
|
||||
struct touch_point *p;
|
||||
wl_list_for_each(p, &sample->touch_points, link) {
|
||||
int x = (int)(p->x * width) - sample->cat_texture->width / 2;
|
||||
int y = (int)(p->y * height) - sample->cat_texture->height / 2;
|
||||
wlr_render_texture(sample->renderer, sample->cat_texture,
|
||||
wlr_output->transform_matrix, x, y, 1.0f);
|
||||
wlr_render_pass_add_texture(pass, &(struct wlr_render_texture_options){
|
||||
.texture = sample->cat_texture,
|
||||
.dst_box = { .x = x, .y = y },
|
||||
});
|
||||
}
|
||||
|
||||
wlr_renderer_end(sample->renderer);
|
||||
wlr_output_commit(wlr_output);
|
||||
wlr_render_pass_submit(pass);
|
||||
wlr_output_commit_state(wlr_output, &output_state);
|
||||
wlr_output_state_finish(&output_state);
|
||||
sample->last_frame = now;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user