Refactored renderer startup to function.

This commit is contained in:
Scott Anderson 2017-05-14 12:48:47 +12:00
parent ce8786721b
commit 7efdd3c9fc
3 changed files with 28 additions and 45 deletions

View file

@ -57,7 +57,7 @@ static void device_resumed(struct wl_listener *listener, void *data) {
for (size_t i = 0; i < drm->outputs->length; ++i) { for (size_t i = 0; i < drm->outputs->length; ++i) {
struct wlr_output_state *output = drm->outputs->items[i]; struct wlr_output_state *output = drm->outputs->items[i];
wlr_drm_output_draw_blank(output); wlr_drm_output_start_renderer(output);
} }
} }

View file

@ -113,23 +113,13 @@ void wlr_drm_output_end(struct wlr_output *output) {
_output->pageflip_pending = true; _output->pageflip_pending = true;
} }
static bool display_init_renderer(struct wlr_drm_renderer *renderer, void wlr_drm_output_start_renderer(struct wlr_output_state *output) {
struct wlr_output_state *output) { if (output->state != DRM_OUTPUT_CONNECTED) {
struct wlr_output_mode *mode = output->wlr_output->current_mode; return;
output->renderer = renderer;
output->gbm = gbm_surface_create(renderer->gbm, mode->width,
mode->height, GBM_FORMAT_XRGB8888, GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
if (!output->gbm) {
wlr_log(L_ERROR, "Failed to create GBM surface for %s: %s", output->name,
strerror(errno));
return false;
} }
output->egl = wlr_egl_create_surface(&renderer->egl, output->gbm); struct wlr_drm_renderer *renderer = output->renderer;
if (output->egl == EGL_NO_SURFACE) { struct wlr_output_mode *mode = output->wlr_output->current_mode;
wlr_log(L_ERROR, "Failed to create EGL surface for %s", output->name);
return false;
}
// Render black frame // Render black frame
eglMakeCurrent(renderer->egl.display, output->egl, output->egl, renderer->egl.context); eglMakeCurrent(renderer->egl.display, output->egl, output->egl, renderer->egl.context);
@ -149,6 +139,27 @@ static bool display_init_renderer(struct wlr_drm_renderer *renderer,
DRM_MODE_PAGE_FLIP_EVENT, output); DRM_MODE_PAGE_FLIP_EVENT, output);
gbm_surface_release_buffer(output->gbm, bo); gbm_surface_release_buffer(output->gbm, bo);
}
static bool display_init_renderer(struct wlr_drm_renderer *renderer,
struct wlr_output_state *output) {
struct wlr_output_mode *mode = output->wlr_output->current_mode;
output->renderer = renderer;
output->gbm = gbm_surface_create(renderer->gbm, mode->width,
mode->height, GBM_FORMAT_XRGB8888, GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
if (!output->gbm) {
wlr_log(L_ERROR, "Failed to create GBM surface for %s: %s", output->name,
strerror(errno));
return false;
}
output->egl = wlr_egl_create_surface(&renderer->egl, output->gbm);
if (output->egl == EGL_NO_SURFACE) {
wlr_log(L_ERROR, "Failed to create EGL surface for %s", output->name);
return false;
}
wlr_drm_output_start_renderer(output);
return true; return true;
} }
@ -474,31 +485,3 @@ void wlr_drm_output_dpms(int fd, struct wlr_output_state *output, bool screen_on
DRM_MODE_DPMS_STANDBY); DRM_MODE_DPMS_STANDBY);
} }
} }
void wlr_drm_output_draw_blank(struct wlr_output_state *output) {
if (output->state != DRM_OUTPUT_CONNECTED) {
return;
}
struct wlr_drm_renderer *renderer = output->renderer;
eglMakeCurrent(renderer->egl.display, output->egl, output->egl, renderer->egl.context);
glViewport(0, 0, output->width, output->height);
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
eglSwapBuffers(renderer->egl.display, output->egl);
struct gbm_bo *bo = gbm_surface_lock_front_buffer(output->gbm);
uint32_t fb_id = get_fb_for_bo(renderer->fd, bo);
drmModeSetCrtc(renderer->fd, output->crtc, fb_id, 0, 0,
&output->connector, 1, &output->wlr_output->current_mode->state->mode);
drmModePageFlip(renderer->fd, output->crtc, fb_id,
DRM_MODE_PAGE_FLIP_EVENT, output);
gbm_surface_release_buffer(output->gbm, bo);
wlr_log(L_INFO, "Drew blank frame");
}

View file

@ -60,6 +60,6 @@ void wlr_drm_output_dpms(int fd, struct wlr_output_state *output, bool screen_on
void wlr_drm_scan_connectors(struct wlr_backend_state *state); void wlr_drm_scan_connectors(struct wlr_backend_state *state);
int wlr_drm_event(int fd, uint32_t mask, void *data); int wlr_drm_event(int fd, uint32_t mask, void *data);
void wlr_drm_output_draw_blank(struct wlr_output_state *output); void wlr_drm_output_start_renderer(struct wlr_output_state *output);
#endif #endif