2017-05-07 16:26:48 +00:00
|
|
|
#include <stdlib.h>
|
2017-06-07 04:43:57 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <tgmath.h>
|
2017-05-07 16:26:48 +00:00
|
|
|
#include <wayland-server.h>
|
2017-06-21 14:27:45 +00:00
|
|
|
#include <wlr/types/wlr_output.h>
|
|
|
|
#include <wlr/interfaces/wlr_output.h>
|
2017-06-21 16:10:07 +00:00
|
|
|
#include <wlr/util/list.h>
|
2017-05-07 16:26:48 +00:00
|
|
|
|
2017-06-07 04:43:57 +00:00
|
|
|
static const float transforms[][4] = {
|
|
|
|
[WL_OUTPUT_TRANSFORM_NORMAL] = {
|
|
|
|
1.0f, 0.0f,
|
2017-06-07 15:05:31 +00:00
|
|
|
0.0f, -1.0f,
|
2017-06-07 04:43:57 +00:00
|
|
|
},
|
|
|
|
[WL_OUTPUT_TRANSFORM_90] = {
|
|
|
|
0.0f, -1.0f,
|
2017-06-07 15:05:31 +00:00
|
|
|
-1.0f, 0.0f,
|
2017-06-07 04:43:57 +00:00
|
|
|
},
|
|
|
|
[WL_OUTPUT_TRANSFORM_180] = {
|
|
|
|
-1.0f, 0.0f,
|
2017-06-07 15:05:31 +00:00
|
|
|
0.0f, 1.0f,
|
2017-06-07 04:43:57 +00:00
|
|
|
},
|
|
|
|
[WL_OUTPUT_TRANSFORM_270] = {
|
|
|
|
0.0f, 1.0f,
|
2017-06-07 15:05:31 +00:00
|
|
|
1.0f, 0.0f,
|
2017-06-07 04:43:57 +00:00
|
|
|
},
|
|
|
|
[WL_OUTPUT_TRANSFORM_FLIPPED] = {
|
|
|
|
-1.0f, 0.0f,
|
2017-06-07 15:05:31 +00:00
|
|
|
0.0f, -1.0f,
|
2017-06-07 04:43:57 +00:00
|
|
|
},
|
|
|
|
[WL_OUTPUT_TRANSFORM_FLIPPED_90] = {
|
|
|
|
0.0f, 1.0f,
|
2017-06-07 15:05:31 +00:00
|
|
|
-1.0f, 0.0f,
|
2017-06-07 04:43:57 +00:00
|
|
|
},
|
|
|
|
[WL_OUTPUT_TRANSFORM_FLIPPED_180] = {
|
|
|
|
1.0f, 0.0f,
|
2017-06-07 15:05:31 +00:00
|
|
|
0.0f, 1.0f,
|
2017-06-07 04:43:57 +00:00
|
|
|
},
|
|
|
|
[WL_OUTPUT_TRANSFORM_FLIPPED_270] = {
|
|
|
|
0.0f, -1.0f,
|
2017-06-07 15:05:31 +00:00
|
|
|
1.0f, 0.0f,
|
2017-06-07 04:43:57 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Equivilent to glOrtho(0, width, 0, height, 1, -1) with the transform applied
|
|
|
|
static void set_matrix(float mat[static 16], int32_t width, int32_t height,
|
|
|
|
enum wl_output_transform transform) {
|
|
|
|
memset(mat, 0, sizeof(*mat) * 16);
|
|
|
|
|
|
|
|
const float *t = transforms[transform];
|
|
|
|
float x = 2.0f / width;
|
|
|
|
float y = 2.0f / height;
|
|
|
|
|
|
|
|
// Rotation + relection
|
|
|
|
mat[0] = x * t[0];
|
|
|
|
mat[1] = x * t[1];
|
|
|
|
mat[4] = y * t[2];
|
|
|
|
mat[5] = y * t[3];
|
|
|
|
|
|
|
|
// Translation
|
|
|
|
mat[3] = -copysign(1.0f, mat[0] + mat[1]);
|
|
|
|
mat[7] = -copysign(1.0f, mat[4] + mat[5]);
|
|
|
|
|
|
|
|
// Identity
|
|
|
|
mat[10] = 1.0f;
|
|
|
|
mat[15] = 1.0f;
|
|
|
|
}
|
|
|
|
|
2017-06-20 21:51:45 +00:00
|
|
|
void wlr_output_update_matrix(struct wlr_output *output) {
|
|
|
|
set_matrix(output->transform_matrix, output->width, output->height, output->transform);
|
|
|
|
}
|
|
|
|
|
2017-05-07 16:26:48 +00:00
|
|
|
struct wlr_output *wlr_output_create(struct wlr_output_impl *impl,
|
|
|
|
struct wlr_output_state *state) {
|
|
|
|
struct wlr_output *output = calloc(1, sizeof(struct wlr_output));
|
|
|
|
output->impl = impl;
|
|
|
|
output->state = state;
|
|
|
|
output->modes = list_create();
|
2017-06-06 15:48:30 +00:00
|
|
|
output->transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
2017-05-07 16:26:48 +00:00
|
|
|
wl_signal_init(&output->events.frame);
|
2017-06-20 21:51:45 +00:00
|
|
|
wl_signal_init(&output->events.resolution);
|
2017-05-07 16:26:48 +00:00
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2017-06-06 15:48:30 +00:00
|
|
|
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) {
|
2017-06-20 21:51:45 +00:00
|
|
|
if (!output->impl || !output->impl->set_mode) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-06-22 15:19:46 +00:00
|
|
|
bool result = output->impl->set_mode(output->state, mode);
|
|
|
|
if (result) {
|
|
|
|
wlr_output_update_matrix(output);
|
|
|
|
}
|
|
|
|
return result;
|
2017-06-06 15:48:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_output_transform(struct wlr_output *output,
|
|
|
|
enum wl_output_transform transform) {
|
2017-06-20 21:51:45 +00:00
|
|
|
wlr_output_update_matrix(output);
|
2017-06-06 15:48:30 +00:00
|
|
|
output->impl->transform(output->state, transform);
|
|
|
|
}
|
|
|
|
|
2017-06-16 19:38:34 +00:00
|
|
|
bool wlr_output_set_cursor(struct wlr_output *output,
|
|
|
|
const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height) {
|
2017-06-20 21:51:45 +00:00
|
|
|
if (!output->impl || !output->impl->set_cursor) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-06-16 19:38:34 +00:00
|
|
|
return output->impl->set_cursor(output->state, buf, stride, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wlr_output_move_cursor(struct wlr_output *output, int x, int y) {
|
2017-06-20 21:51:45 +00:00
|
|
|
if (!output->impl || !output->impl->move_cursor) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-06-16 19:38:34 +00:00
|
|
|
return output->impl->move_cursor(output->state, x, y);
|
|
|
|
}
|
|
|
|
|
2017-05-31 20:17:04 +00:00
|
|
|
void wlr_output_destroy(struct wlr_output *output) {
|
2017-05-07 16:26:48 +00:00
|
|
|
if (!output) return;
|
2017-05-31 20:17:04 +00:00
|
|
|
output->impl->destroy(output->state);
|
2017-05-07 16:26:48 +00:00
|
|
|
for (size_t i = 0; output->modes && i < output->modes->length; ++i) {
|
|
|
|
free(output->modes->items[i]);
|
|
|
|
}
|
|
|
|
list_free(output->modes);
|
|
|
|
free(output);
|
|
|
|
}
|
2017-06-08 01:35:07 +00:00
|
|
|
|
|
|
|
void wlr_output_effective_resolution(struct wlr_output *output,
|
|
|
|
int *width, int *height) {
|
|
|
|
// TODO: Scale factor
|
|
|
|
if (output->transform % 2 == 1) {
|
|
|
|
*width = output->height;
|
|
|
|
*height = output->width;
|
|
|
|
} else {
|
|
|
|
*width = output->width;
|
|
|
|
*height = output->height;
|
|
|
|
}
|
|
|
|
}
|