2017-05-07 16:26:48 +00:00
|
|
|
#define _POSIX_C_SOURCE 199309L
|
2017-06-13 01:53:41 +00:00
|
|
|
#include <string.h>
|
2017-05-07 16:26:48 +00:00
|
|
|
#include <stdio.h>
|
2017-04-25 19:06:58 +00:00
|
|
|
#include <stdlib.h>
|
2017-05-07 16:26:48 +00:00
|
|
|
#include <time.h>
|
2017-06-07 12:39:40 +00:00
|
|
|
#include <inttypes.h>
|
2017-04-25 19:06:58 +00:00
|
|
|
#include <wayland-server.h>
|
2017-06-23 15:38:45 +00:00
|
|
|
#include <GLES2/gl2.h>
|
2017-05-31 19:38:26 +00:00
|
|
|
#include <wlr/backend.h>
|
2017-07-11 07:18:34 +00:00
|
|
|
#include <wlr/backend/session.h>
|
2017-06-21 14:27:45 +00:00
|
|
|
#include <wlr/types/wlr_output.h>
|
2017-09-24 18:12:56 +00:00
|
|
|
#include <wlr/util/log.h>
|
2017-06-13 01:53:41 +00:00
|
|
|
#include <xkbcommon/xkbcommon.h>
|
2017-11-01 19:47:58 +00:00
|
|
|
#include "support/shared.h"
|
2017-04-25 19:06:58 +00:00
|
|
|
|
2017-06-13 14:13:11 +00:00
|
|
|
struct sample_state {
|
2017-05-07 16:26:48 +00:00
|
|
|
float color[3];
|
|
|
|
int dec;
|
|
|
|
};
|
|
|
|
|
2017-06-13 14:13:11 +00:00
|
|
|
void handle_output_frame(struct output_state *output, struct timespec *ts) {
|
|
|
|
struct compositor_state *state = output->compositor;
|
|
|
|
struct sample_state *sample = state->data;
|
2017-05-07 16:26:48 +00:00
|
|
|
|
2017-06-13 14:13:11 +00:00
|
|
|
long ms = (ts->tv_sec - state->last_frame.tv_sec) * 1000 +
|
|
|
|
(ts->tv_nsec - state->last_frame.tv_nsec) / 1000000;
|
|
|
|
int inc = (sample->dec + 1) % 3;
|
2017-05-07 16:26:48 +00:00
|
|
|
|
2017-06-13 14:13:11 +00:00
|
|
|
sample->color[inc] += ms / 2000.0f;
|
|
|
|
sample->color[sample->dec] -= ms / 2000.0f;
|
2017-05-07 16:26:48 +00:00
|
|
|
|
2017-06-13 14:13:11 +00:00
|
|
|
if (sample->color[sample->dec] < 0.0f) {
|
|
|
|
sample->color[inc] = 1.0f;
|
|
|
|
sample->color[sample->dec] = 0.0f;
|
|
|
|
sample->dec = inc;
|
2017-05-07 16:26:48 +00:00
|
|
|
}
|
|
|
|
|
2017-06-26 05:34:15 +00:00
|
|
|
wlr_output_make_current(output->output);
|
|
|
|
|
2017-06-13 14:13:11 +00:00
|
|
|
glClearColor(sample->color[0], sample->color[1], sample->color[2], 1.0);
|
2017-05-07 16:26:48 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2017-06-26 05:34:15 +00:00
|
|
|
|
2018-01-19 13:08:47 +00:00
|
|
|
wlr_output_swap_buffers(output->output, NULL, NULL);
|
2017-05-07 16:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2018-01-16 03:51:00 +00:00
|
|
|
wlr_log_init(L_DEBUG, NULL);
|
2017-06-13 14:13:11 +00:00
|
|
|
struct sample_state state = {
|
2017-05-07 16:26:48 +00:00
|
|
|
.color = { 1.0, 0.0, 0.0 },
|
|
|
|
.dec = 0,
|
|
|
|
};
|
2017-06-20 19:29:27 +00:00
|
|
|
struct compositor_state compositor = { 0,
|
|
|
|
.data = &state,
|
|
|
|
.output_frame_cb = handle_output_frame,
|
|
|
|
};
|
2017-06-13 14:13:11 +00:00
|
|
|
compositor_init(&compositor);
|
2017-09-24 18:12:56 +00:00
|
|
|
if (!wlr_backend_start(compositor.backend)) {
|
|
|
|
wlr_log(L_ERROR, "Failed to start backend");
|
|
|
|
wlr_backend_destroy(compositor.backend);
|
|
|
|
exit(1);
|
|
|
|
}
|
2017-08-19 07:26:25 +00:00
|
|
|
wl_display_run(compositor.display);
|
|
|
|
compositor_fini(&compositor);
|
2017-04-25 19:06:58 +00:00
|
|
|
}
|