diff options
-rw-r--r-- | backend/drm/drm.c | 48 | ||||
-rw-r--r-- | example/rotation.c | 13 | ||||
-rw-r--r-- | include/types.h | 5 | ||||
-rw-r--r-- | include/wlr/types.h | 5 | ||||
-rw-r--r-- | types/wlr_output.c | 22 |
5 files changed, 55 insertions, 38 deletions
diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 6f753af2..6ab66033 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -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, }; diff --git a/example/rotation.c b/example/rotation.c index 7233db74..90b0ab9b 100644 --- a/example/rotation.c +++ b/example/rotation.c @@ -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; } } diff --git a/include/types.h b/include/types.h index 5513e936..d2c8d008 100644 --- a/include/types.h +++ b/include/types.h @@ -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); }; diff --git a/include/wlr/types.h b/include/wlr/types.h index 8014974a..5de80a60 100644 --- a/include/wlr/types.h +++ b/include/wlr/types.h @@ -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 diff --git a/types/wlr_output.c b/types/wlr_output.c index 826404a1..00975c3a 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -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); -} |