diff options
author | Jon Smirl <jonsmirl@gmail.com> | 2005-05-18 01:44:11 +0000 |
---|---|---|
committer | Jon Smirl <jonsmirl@gmail.com> | 2005-05-18 01:44:11 +0000 |
commit | 9a3da7ea7b61fcd71dd5caf9be9eaf485aa7947d (patch) | |
tree | 79a8261d54677d4456799f8a6faa21db0ee1351b | |
parent | 6e56f905d00f27257f252be3c2666dad52aeab45 (diff) |
Implement fbdev swapbuffers()
-rw-r--r-- | progs/egl/demo2.c | 8 | ||||
-rw-r--r-- | src/mesa/drivers/dri/fb/fb_egl.c | 47 |
2 files changed, 51 insertions, 4 deletions
diff --git a/progs/egl/demo2.c b/progs/egl/demo2.c index e8ace3da8e..4e0004d930 100644 --- a/progs/egl/demo2.c +++ b/progs/egl/demo2.c @@ -9,7 +9,7 @@ #include <GLES/egl.h> -#define FRONTBUFFER +//#define FRONTBUFFER static void _subset_Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) { @@ -22,7 +22,7 @@ static void _subset_Rectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) } -static void redraw(EGLDisplay dpy, int rot) +static void redraw(EGLDisplay dpy, EGLSurface surf, int rot) { printf("Redraw event\n"); @@ -51,7 +51,7 @@ static void redraw(EGLDisplay dpy, int rot) #ifdef FRONTBUFFER glFlush(); #else - EGLSwapBuffers( dpy, w ); + eglSwapBuffers( dpy, surf ); #endif glFinish(); } @@ -167,7 +167,7 @@ main(int argc, char *argv[]) glShadeModel( GL_FLAT ); for (i = 0; i < 6; i++) { - redraw(d, i*10 ); + redraw(d, screen_surf, i*10 ); printf("sleep(1)\n"); sleep(1); diff --git a/src/mesa/drivers/dri/fb/fb_egl.c b/src/mesa/drivers/dri/fb/fb_egl.c index 79640bbc61..9541f4f39d 100644 --- a/src/mesa/drivers/dri/fb/fb_egl.c +++ b/src/mesa/drivers/dri/fb/fb_egl.c @@ -757,6 +757,52 @@ err: } +/* If the backbuffer is on a videocard, this is extraordinarily slow! + */ +static EGLBoolean +fbSwapBuffers(_EGLDriver *drv, EGLDisplay dpy, EGLSurface draw) +{ + fbContext *context = (fbContext *)_eglGetCurrentContext(); + fbSurface *fs = Lookup_fbSurface(draw); + struct gl_renderbuffer * front_renderbuffer = fs->mesa_framebuffer->Attachment[BUFFER_FRONT_LEFT].Renderbuffer; + void *frontBuffer = front_renderbuffer->Data; + int currentPitch = ((driRenderbuffer *)front_renderbuffer)->pitch; + void *backBuffer = fs->mesa_framebuffer->Attachment[BUFFER_BACK_LEFT].Renderbuffer->Data; + + if (!_eglSwapBuffers(drv, dpy, draw)) + return EGL_FALSE; + + if (context) { + GLcontext *ctx = context->glCtx; + + if (ctx->Visual.doubleBufferMode) { + int i; + int offset = 0; + char *tmp = _mesa_malloc(currentPitch); + + _mesa_notifySwapBuffers( ctx ); /* flush pending rendering comands */ + + ASSERT(frontBuffer); + ASSERT(backBuffer); + + for (i = 0; i < fs->Base.Height; i++) { + _mesa_memcpy(tmp, (char *) backBuffer + offset, + currentPitch); + _mesa_memcpy((char *) frontBuffer + offset, tmp, + currentPitch); + offset += currentPitch; + } + + _mesa_free(tmp); + } + } + else { + /* XXX this shouldn't be an error but we can't handle it for now */ + _mesa_problem(NULL, "fbSwapBuffers: drawable has no context!\n"); + } +} + + /* * Just to silence warning */ @@ -793,6 +839,7 @@ _eglMain(NativeDisplayType dpy) fb->Base.DestroyContext = fbDestroyContext; fb->Base.CreateScreenSurfaceMESA = fbCreateScreenSurfaceMESA; fb->Base.ShowSurfaceMESA = fbShowSurfaceMESA; + fb->Base.SwapBuffers = fbSwapBuffers; /* enable supported extensions */ fb->Base.MESA_screen_surface = EGL_TRUE; |