Have backend manage opengl context

This commit is contained in:
Drew DeVault 2017-05-31 15:15:42 -04:00
parent 66e02e97ec
commit 03c9b46034
3 changed files with 16 additions and 25 deletions

View File

@ -94,23 +94,21 @@ static uint32_t get_fb_for_bo(int fd, struct gbm_bo *bo) {
return *id; return *id;
} }
void wlr_drm_output_begin(struct wlr_output *output) { static void wlr_drm_output_begin(struct wlr_output_state *output) {
struct wlr_output_state *_output = output->state; struct wlr_drm_renderer *renderer = output->renderer;
struct wlr_drm_renderer *renderer = _output->renderer; eglMakeCurrent(renderer->egl.display, output->egl,
eglMakeCurrent(renderer->egl.display, _output->egl, output->egl, renderer->egl.context);
_output->egl, renderer->egl.context);
} }
void wlr_drm_output_end(struct wlr_output *output) { static void wlr_drm_output_end(struct wlr_output_state *output) {
struct wlr_output_state *_output = output->state; struct wlr_drm_renderer *renderer = output->renderer;
struct wlr_drm_renderer *renderer = _output->renderer;
eglSwapBuffers(renderer->egl.display, _output->egl); eglSwapBuffers(renderer->egl.display, output->egl);
struct gbm_bo *bo = gbm_surface_lock_front_buffer(_output->gbm); struct gbm_bo *bo = gbm_surface_lock_front_buffer(output->gbm);
uint32_t fb_id = get_fb_for_bo(renderer->fd, bo); uint32_t fb_id = get_fb_for_bo(renderer->fd, bo);
drmModePageFlip(renderer->fd, _output->crtc, fb_id, DRM_MODE_PAGE_FLIP_EVENT, _output); drmModePageFlip(renderer->fd, output->crtc, fb_id, DRM_MODE_PAGE_FLIP_EVENT, output);
gbm_surface_release_buffer(_output->gbm, bo); gbm_surface_release_buffer(output->gbm, bo);
_output->pageflip_pending = true; output->pageflip_pending = true;
} }
static bool display_init_renderer(struct wlr_drm_renderer *renderer, static bool display_init_renderer(struct wlr_drm_renderer *renderer,
@ -396,7 +394,9 @@ static void page_flip_handler(int fd, unsigned seq,
output->pageflip_pending = false; output->pageflip_pending = false;
if (output->state == DRM_OUTPUT_CONNECTED) { if (output->state == DRM_OUTPUT_CONNECTED) {
wlr_drm_output_begin(output);
wl_signal_emit(&output->wlr_output->events.frame, output->wlr_output); wl_signal_emit(&output->wlr_output->events.frame, output->wlr_output);
wlr_drm_output_end(output);
} }
} }
@ -465,10 +465,10 @@ void wlr_drm_output_dpms(int fd, struct wlr_output_state *output, bool screen_on
DRM_MODE_DPMS_ON); DRM_MODE_DPMS_ON);
// Start rendering loop again by drawing a black frame // Start rendering loop again by drawing a black frame
wlr_drm_output_begin(output->wlr_output); wlr_drm_output_begin(output);
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);
wlr_drm_output_end(output->wlr_output); wlr_drm_output_end(output);
} else { } else {
drmModeConnectorSetProperty(fd, output->connector, output->props.dpms, drmModeConnectorSetProperty(fd, output->connector, output->props.dpms,
DRM_MODE_DPMS_STANDBY); DRM_MODE_DPMS_STANDBY);

View File

@ -24,9 +24,7 @@ struct output_state {
}; };
void output_frame(struct wl_listener *listener, void *data) { void output_frame(struct wl_listener *listener, void *data) {
struct wlr_output *output = data; struct output_state *ostate = wl_container_of(listener, ostate, frame);
struct output_state *ostate = wl_container_of(
listener, ostate, frame);
struct state *s = ostate->state; struct state *s = ostate->state;
struct timespec now; struct timespec now;
@ -48,12 +46,8 @@ void output_frame(struct wl_listener *listener, void *data) {
s->last_frame = now; s->last_frame = now;
wlr_drm_output_begin(output);
glClearColor(s->color[0], s->color[1], s->color[2], 1.0); glClearColor(s->color[0], s->color[1], s->color[2], 1.0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
wlr_drm_output_end(output);
} }
void output_add(struct wl_listener *listener, void *data) { void output_add(struct wl_listener *listener, void *data) {

View File

@ -12,7 +12,4 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
void wlr_drm_backend_dpms(struct wlr_backend *backend, bool screen_on); void wlr_drm_backend_dpms(struct wlr_backend *backend, bool screen_on);
void wlr_drm_output_begin(struct wlr_output *out);
void wlr_drm_output_end(struct wlr_output *out);
#endif #endif