mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2024-11-21 22:52:20 +00:00
Let backend track transform state
This will be necessary to provide it to clients via wl_output.
This commit is contained in:
parent
e240fb0518
commit
6f5c70ac69
@ -178,6 +178,28 @@ static int find_id(const void *item, const void *cmp_to) {
|
||||
}
|
||||
}
|
||||
|
||||
static void wlr_drm_output_enable(struct wlr_output_state *output, bool enable) {
|
||||
struct wlr_backend_state *state =
|
||||
wl_container_of(output->renderer, state, renderer);
|
||||
if (output->state != DRM_OUTPUT_CONNECTED) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enable) {
|
||||
drmModeConnectorSetProperty(state->fd, output->connector, output->props.dpms,
|
||||
DRM_MODE_DPMS_ON);
|
||||
|
||||
// Start rendering loop again by drawing a black frame
|
||||
wlr_drm_output_begin(output);
|
||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
wlr_drm_output_end(output);
|
||||
} else {
|
||||
drmModeConnectorSetProperty(state->fd, output->connector, output->props.dpms,
|
||||
DRM_MODE_DPMS_STANDBY);
|
||||
}
|
||||
}
|
||||
|
||||
static bool wlr_drm_output_set_mode(struct wlr_output_state *output,
|
||||
struct wlr_output_mode *mode) {
|
||||
struct wlr_backend_state *state =
|
||||
@ -251,26 +273,9 @@ error:
|
||||
return false;
|
||||
}
|
||||
|
||||
static void wlr_drm_output_enable(struct wlr_output_state *output, bool enable) {
|
||||
struct wlr_backend_state *state =
|
||||
wl_container_of(output->renderer, state, renderer);
|
||||
if (output->state != DRM_OUTPUT_CONNECTED) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enable) {
|
||||
drmModeConnectorSetProperty(state->fd, output->connector, output->props.dpms,
|
||||
DRM_MODE_DPMS_ON);
|
||||
|
||||
// Start rendering loop again by drawing a black frame
|
||||
wlr_drm_output_begin(output);
|
||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
wlr_drm_output_end(output);
|
||||
} else {
|
||||
drmModeConnectorSetProperty(state->fd, output->connector, output->props.dpms,
|
||||
DRM_MODE_DPMS_STANDBY);
|
||||
}
|
||||
static void wlr_drm_output_transform(struct wlr_output_state *output,
|
||||
enum wl_output_transform transform) {
|
||||
output->wlr_output->transform = transform;
|
||||
}
|
||||
|
||||
static void wlr_drm_output_destroy(struct wlr_output_state *output) {
|
||||
@ -279,8 +284,9 @@ static void wlr_drm_output_destroy(struct wlr_output_state *output) {
|
||||
}
|
||||
|
||||
static struct wlr_output_impl output_impl = {
|
||||
.set_mode = wlr_drm_output_set_mode,
|
||||
.enable = wlr_drm_output_enable,
|
||||
.set_mode = wlr_drm_output_set_mode,
|
||||
.transform = wlr_drm_output_transform,
|
||||
.destroy = wlr_drm_output_destroy,
|
||||
};
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#define _POSIX_C_SOURCE 199309L
|
||||
#define _XOPEN_SOURCE 500
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
@ -10,7 +11,7 @@
|
||||
#include <wlr/backend.h>
|
||||
#include <wlr/session.h>
|
||||
#include <wlr/types.h>
|
||||
#include <tgmath.h>
|
||||
#include <math.h>
|
||||
|
||||
static const GLchar vert_src[] =
|
||||
"#version 310 es\n"
|
||||
@ -92,7 +93,6 @@ struct output_state {
|
||||
struct wlr_output *output;
|
||||
struct state *state;
|
||||
struct wl_listener frame;
|
||||
enum wl_output_transform transform;
|
||||
};
|
||||
|
||||
struct output_config {
|
||||
@ -177,7 +177,7 @@ static void output_frame(struct wl_listener *listener, void *data) {
|
||||
glViewport(0, 0, width, height);
|
||||
|
||||
// All of the odd numbered transformations involve a 90 or 270 degree rotation
|
||||
if (ostate->transform % 2 == 1) {
|
||||
if (ostate->output->transform % 2 == 1) {
|
||||
float tmp = width;
|
||||
width = height;
|
||||
height = tmp;
|
||||
@ -199,7 +199,7 @@ static void output_frame(struct wl_listener *listener, void *data) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, s->gl.vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vert_data), vert_data, GL_STATIC_DRAW);
|
||||
|
||||
glUniformMatrix2fv(0, 1, GL_FALSE, transforms[ostate->transform]);
|
||||
glUniformMatrix2fv(0, 1, GL_FALSE, transforms[ostate->output->transform]);
|
||||
|
||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
@ -214,7 +214,7 @@ static void output_frame(struct wl_listener *listener, void *data) {
|
||||
|
||||
s->last_frame = now;
|
||||
s->angle += ms / 200.0f;
|
||||
if (s->angle > 6.28318530718f) { // 2 pi
|
||||
if (s->angle > 2 * M_PI) {
|
||||
s->angle = 0.0f;
|
||||
}
|
||||
}
|
||||
@ -231,12 +231,11 @@ static void output_add(struct wl_listener *listener, void *data) {
|
||||
ostate->output = output;
|
||||
ostate->state = state;
|
||||
ostate->frame.notify = output_frame;
|
||||
ostate->transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
||||
|
||||
struct output_config *conf;
|
||||
wl_list_for_each(conf, &state->config, link) {
|
||||
if (strcmp(conf->name, output->name) == 0) {
|
||||
ostate->transform = conf->transform;
|
||||
wlr_output_transform(ostate->output, conf->transform);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,11 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
struct wlr_output_impl {
|
||||
bool (*set_mode)(struct wlr_output_state *state, struct wlr_output_mode *mode);
|
||||
void (*enable)(struct wlr_output_state *state, bool enable);
|
||||
bool (*set_mode)(struct wlr_output_state *state,
|
||||
struct wlr_output_mode *mode);
|
||||
void (*transform)(struct wlr_output_state *state,
|
||||
enum wl_output_transform transform);
|
||||
void (*destroy)(struct wlr_output_state *state);
|
||||
};
|
||||
|
||||
|
@ -40,8 +40,11 @@ struct wlr_output {
|
||||
} events;
|
||||
};
|
||||
|
||||
bool wlr_output_set_mode(struct wlr_output *output, struct wlr_output_mode *mode);
|
||||
void wlr_output_enable(struct wlr_output *output, bool enable);
|
||||
bool wlr_output_set_mode(struct wlr_output *output,
|
||||
struct wlr_output_mode *mode);
|
||||
void wlr_output_transform(struct wlr_output *output,
|
||||
enum wl_output_transform transform);
|
||||
void wlr_output_destroy(struct wlr_output *output);
|
||||
|
||||
#endif
|
||||
|
@ -10,10 +10,24 @@ struct wlr_output *wlr_output_create(struct wlr_output_impl *impl,
|
||||
output->impl = impl;
|
||||
output->state = state;
|
||||
output->modes = list_create();
|
||||
output->transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
||||
wl_signal_init(&output->events.frame);
|
||||
return output;
|
||||
}
|
||||
|
||||
void wlr_output_enable(struct wlr_output *output, bool enable) {
|
||||
output->impl->enable(output->state, enable);
|
||||
}
|
||||
|
||||
bool wlr_output_set_mode(struct wlr_output *output, struct wlr_output_mode *mode) {
|
||||
return output->impl->set_mode(output->state, mode);
|
||||
}
|
||||
|
||||
void wlr_output_transform(struct wlr_output *output,
|
||||
enum wl_output_transform transform) {
|
||||
output->impl->transform(output->state, transform);
|
||||
}
|
||||
|
||||
void wlr_output_destroy(struct wlr_output *output) {
|
||||
if (!output) return;
|
||||
output->impl->destroy(output->state);
|
||||
@ -25,11 +39,3 @@ void wlr_output_destroy(struct wlr_output *output) {
|
||||
list_free(output->modes);
|
||||
free(output);
|
||||
}
|
||||
|
||||
bool wlr_output_set_mode(struct wlr_output *output, struct wlr_output_mode *mode) {
|
||||
return output->impl->set_mode(output->state, mode);
|
||||
}
|
||||
|
||||
void wlr_output_enable(struct wlr_output *output, bool enable) {
|
||||
output->impl->enable(output->state, enable);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user