static void swap(struct gbm_winsys *winsys) { struct gbm_dev *dev = winsys->dev; struct gbm_context *context = winsys->context; struct gbm_bo *bo; uint32_t handle, stride; uint32_t width, height; uint32_t fb_id; eglSwapBuffers(context->edpy, context->egl_surface); bo = gbm_surface_lock_front_buffer(context->gbm_surface); width = gbm_bo_get_width(bo); height = gbm_bo_get_height(bo); stride = gbm_bo_get_stride(bo); handle = gbm_bo_get_handle(bo).u32; if (drmModeAddFB(dev->fd, width, height, 24, /* depth */ 32, /* bpp */ stride, handle, &fb_id)) { fprintf(stderr, "Failed to create new back buffer handle: %m\n"); } else { if (dev->saved_crtc == NULL && set_initial_crtc(dev, fb_id)) return; if (drmModePageFlip(dev->fd, dev->crtc, fb_id, DRM_MODE_PAGE_FLIP_EVENT, dev)) { fprintf(stderr, "Failed to page flip: %m\n"); return; } dev->pending_swap = 1; wait_swap(dev); free_current_bo(context); context->current_bo = bo; context->current_fb_id = fb_id; } }
static void stereo_cleanup_context(struct gbm_context *context) { restore_saved_crtc(context->dev); free_current_bo(context); eglMakeCurrent(context->edpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroyContext(context->edpy, context->egl_context); eglDestroySurface(context->edpy, context->egl_surface); gbm_surface_destroy(context->gbm_surface); eglTerminate(context->edpy); gbm_device_destroy(context->gbm); free(context); }
static void page_flip_handler (int fd, unsigned int frame, unsigned int sec, unsigned int usec, void *data) { CoglFlipKMS *flip = data; CoglOnscreen *onscreen = flip->onscreen; CoglOnscreenEGL *egl_onscreen = onscreen->winsys; CoglOnscreenKMS *kms_onscreen = egl_onscreen->platform; CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context; CoglDisplay *display = context->display; CoglDisplayEGL *egl_display = display->winsys; CoglDisplayKMS *kms_display = egl_display->platform; /* We're only ready to dispatch a swap notification once all outputs * have flipped... */ flip->pending--; if (flip->pending == 0) { /* We only want to notify that the swap is complete when the application * calls cogl_context_dispatch so instead of immediately notifying we'll * set a flag to remember to notify later */ kms_display->pending_swap_notify = TRUE; kms_onscreen->pending_swap_notify = TRUE; free_current_bo (onscreen); kms_onscreen->current_fb_id = kms_onscreen->next_fb_id; kms_onscreen->next_fb_id = 0; kms_onscreen->current_bo = kms_onscreen->next_bo; kms_onscreen->next_bo = NULL; cogl_object_unref (flip->onscreen); g_slice_free (CoglFlipKMS, flip); } }
static void _cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen) { CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen); CoglContext *context = framebuffer->context; CoglRenderer *renderer = context->display->renderer; CoglRendererEGL *egl_renderer = renderer->winsys; CoglOnscreenEGL *egl_onscreen = onscreen->winsys; CoglOnscreenKMS *kms_onscreen; /* If we never successfully allocated then there's nothing to do */ if (egl_onscreen == NULL) return; kms_onscreen = egl_onscreen->platform; /* flip state takes a reference on the onscreen so there should * never be outstanding flips when we reach here. */ g_return_if_fail (kms_onscreen->next_fb_id == 0); free_current_bo (onscreen); if (egl_onscreen->egl_surface != EGL_NO_SURFACE) { eglDestroySurface (egl_renderer->edpy, egl_onscreen->egl_surface); egl_onscreen->egl_surface = EGL_NO_SURFACE; } if (kms_onscreen->surface) { gbm_surface_destroy (kms_onscreen->surface); kms_onscreen->surface = NULL; } g_slice_free (CoglOnscreenKMS, kms_onscreen); g_slice_free (CoglOnscreenEGL, onscreen->winsys); onscreen->winsys = NULL; }
static void page_flip_handler (int fd, unsigned int frame, unsigned int sec, unsigned int usec, void *data) { CoglFlipKMS *flip = data; /* We're only ready to dispatch a swap notification once all outputs * have flipped... */ flip->pending--; if (flip->pending == 0) { CoglOnscreen *onscreen = flip->onscreen; CoglOnscreenEGL *egl_onscreen = onscreen->winsys; CoglOnscreenKMS *kms_onscreen = egl_onscreen->platform; CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context; CoglRenderer *renderer = context->display->renderer; CoglRendererEGL *egl_renderer = renderer->winsys; CoglRendererKMS *kms_renderer = egl_renderer->platform; queue_swap_notify_for_onscreen (onscreen); free_current_bo (onscreen); kms_onscreen->current_fb_id = kms_onscreen->next_fb_id; kms_onscreen->next_fb_id = 0; kms_onscreen->current_bo = kms_onscreen->next_bo; kms_onscreen->next_bo = NULL; cogl_object_unref (flip->onscreen); g_slice_free (CoglFlipKMS, flip); } }