Example #1
0
EGLBoolean
haiku_make_current(_EGLDriver* drv, _EGLDisplay* dpy, _EGLSurface *dsurf,
		  _EGLSurface *rsurf, _EGLContext *ctx)
{
	struct haiku_egl_context* cont=haiku_egl_context(ctx);
	struct haiku_egl_surface* surf=haiku_egl_surface(dsurf);
	_EGLContext *old_ctx;
    _EGLSurface *old_dsurf, *old_rsurf;
	_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf);
	//cont->ctx.DrawSurface=&surf->surf;
	surf->gl->LockGL();
	return EGL_TRUE;
}
static EGLBoolean
egl_g3d_make_current(_EGLDriver *drv, _EGLDisplay *dpy,
                     _EGLSurface *draw, _EGLSurface *read, _EGLContext *ctx)
{
   struct egl_g3d_context *gctx = egl_g3d_context(ctx);
   struct egl_g3d_surface *gdraw = egl_g3d_surface(draw);
   struct egl_g3d_surface *gread = egl_g3d_surface(read);
   struct egl_g3d_context *old_gctx;
   _EGLContext *old_ctx;
   _EGLSurface *old_draw, *old_read;
   EGLBoolean ok = EGL_TRUE;

   /* make new bindings */
   if (!_eglBindContext(ctx, draw, read, &old_ctx, &old_draw, &old_read))
      return EGL_FALSE;

   old_gctx = egl_g3d_context(old_ctx);
   if (old_gctx) {
      /* flush old context */
      old_gctx->stctxi->flush(old_gctx->stctxi, ST_FLUSH_FRONT, NULL);
   }

   if (gctx) {
      ok = gctx->stapi->make_current(gctx->stapi, gctx->stctxi,
            (gdraw) ? gdraw->stfbi : NULL, (gread) ? gread->stfbi : NULL);
      if (ok) {
         if (gdraw) {
            if (gdraw->base.Type == EGL_WINDOW_BIT) {
               gctx->base.WindowRenderBuffer =
                  (gdraw->stvis.render_buffer == ST_ATTACHMENT_FRONT_LEFT) ?
                  EGL_SINGLE_BUFFER : EGL_BACK_BUFFER;
            }
         }
      }
   }
   else if (old_gctx) {
      ok = old_gctx->stapi->make_current(old_gctx->stapi, NULL, NULL, NULL);
      if (ok)
         old_gctx->base.WindowRenderBuffer = EGL_NONE;
   }

   if (ok) {
      if (_eglPutContext(old_ctx))
         destroy_context(dpy, old_ctx);
      if (_eglPutSurface(old_draw))
         destroy_surface(dpy, old_draw);
      if (_eglPutSurface(old_read))
         destroy_surface(dpy, old_read);
   }
   else {
      /* undo the previous _eglBindContext */
      _eglBindContext(old_ctx, old_draw, old_read, &ctx, &draw, &read);
      assert(&gctx->base == ctx &&
             &gdraw->base == draw &&
             &gread->base == read);

      _eglPutSurface(draw);
      _eglPutSurface(read);
      _eglPutContext(ctx);

      _eglPutSurface(old_draw);
      _eglPutSurface(old_read);
      _eglPutContext(old_ctx);
   }

   return ok;
}