Let backend track transform state

This will be necessary to provide it to clients via wl_output.
This commit is contained in:
Drew DeVault 2017-06-06 11:48:30 -04:00
parent e240fb0518
commit 6f5c70ac69
5 changed files with 55 additions and 38 deletions

View File

@ -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, static bool wlr_drm_output_set_mode(struct wlr_output_state *output,
struct wlr_output_mode *mode) { struct wlr_output_mode *mode) {
struct wlr_backend_state *state = struct wlr_backend_state *state =
@ -251,26 +273,9 @@ error:
return false; return false;
} }
static void wlr_drm_output_enable(struct wlr_output_state *output, bool enable) { static void wlr_drm_output_transform(struct wlr_output_state *output,
struct wlr_backend_state *state = enum wl_output_transform transform) {
wl_container_of(output->renderer, state, renderer); output->wlr_output->transform = transform;
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_destroy(struct wlr_output_state *output) { 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 = { static struct wlr_output_impl output_impl = {
.set_mode = wlr_drm_output_set_mode,
.enable = wlr_drm_output_enable, .enable = wlr_drm_output_enable,
.set_mode = wlr_drm_output_set_mode,
.transform = wlr_drm_output_transform,
.destroy = wlr_drm_output_destroy, .destroy = wlr_drm_output_destroy,
}; };

View File

@ -1,4 +1,5 @@
#define _POSIX_C_SOURCE 199309L #define _POSIX_C_SOURCE 199309L
#define _XOPEN_SOURCE 500
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
@ -10,7 +11,7 @@
#include <wlr/backend.h> #include <wlr/backend.h>
#include <wlr/session.h> #include <wlr/session.h>
#include <wlr/types.h> #include <wlr/types.h>
#include <tgmath.h> #include <math.h>
static const GLchar vert_src[] = static const GLchar vert_src[] =
"#version 310 es\n" "#version 310 es\n"
@ -92,7 +93,6 @@ struct output_state {
struct wlr_output *output; struct wlr_output *output;
struct state *state; struct state *state;
struct wl_listener frame; struct wl_listener frame;
enum wl_output_transform transform;
}; };
struct output_config { struct output_config {
@ -177,7 +177,7 @@ static void output_frame(struct wl_listener *listener, void *data) {
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
// All of the odd numbered transformations involve a 90 or 270 degree rotation // 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; float tmp = width;
width = height; width = height;
height = tmp; height = tmp;
@ -199,7 +199,7 @@ static void output_frame(struct wl_listener *listener, void *data) {
glBindBuffer(GL_ARRAY_BUFFER, s->gl.vbo); glBindBuffer(GL_ARRAY_BUFFER, s->gl.vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vert_data), vert_data, GL_STATIC_DRAW); 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); glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
@ -214,7 +214,7 @@ static void output_frame(struct wl_listener *listener, void *data) {
s->last_frame = now; s->last_frame = now;
s->angle += ms / 200.0f; s->angle += ms / 200.0f;
if (s->angle > 6.28318530718f) { // 2 pi if (s->angle > 2 * M_PI) {
s->angle = 0.0f; s->angle = 0.0f;
} }
} }
@ -231,12 +231,11 @@ static void output_add(struct wl_listener *listener, void *data) {
ostate->output = output; ostate->output = output;
ostate->state = state; ostate->state = state;
ostate->frame.notify = output_frame; ostate->frame.notify = output_frame;
ostate->transform = WL_OUTPUT_TRANSFORM_NORMAL;
struct output_config *conf; struct output_config *conf;
wl_list_for_each(conf, &state->config, link) { wl_list_for_each(conf, &state->config, link) {
if (strcmp(conf->name, output->name) == 0) { if (strcmp(conf->name, output->name) == 0) {
ostate->transform = conf->transform; wlr_output_transform(ostate->output, conf->transform);
break; break;
} }
} }

View File

@ -6,8 +6,11 @@
#include <stdbool.h> #include <stdbool.h>
struct wlr_output_impl { 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); 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); void (*destroy)(struct wlr_output_state *state);
}; };

View File

@ -40,8 +40,11 @@ struct wlr_output {
} events; } 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); 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); void wlr_output_destroy(struct wlr_output *output);
#endif #endif

View File

@ -10,10 +10,24 @@ struct wlr_output *wlr_output_create(struct wlr_output_impl *impl,
output->impl = impl; output->impl = impl;
output->state = state; output->state = state;
output->modes = list_create(); output->modes = list_create();
output->transform = WL_OUTPUT_TRANSFORM_NORMAL;
wl_signal_init(&output->events.frame); wl_signal_init(&output->events.frame);
return output; 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) { void wlr_output_destroy(struct wlr_output *output) {
if (!output) return; if (!output) return;
output->impl->destroy(output->state); output->impl->destroy(output->state);
@ -25,11 +39,3 @@ void wlr_output_destroy(struct wlr_output *output) {
list_free(output->modes); list_free(output->modes);
free(output); 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);
}