src/video/directfb/SDL_DirectFB_opengl.c
changeset 4636 b196d2758026
parent 3697 f7b03b6838cb
child 5199 164f20ba08eb
     1.1 --- a/src/video/directfb/SDL_DirectFB_opengl.c	Sat Aug 14 12:28:43 2010 -0700
     1.2 +++ b/src/video/directfb/SDL_DirectFB_opengl.c	Mon Aug 16 09:04:55 2010 -0700
     1.3 @@ -30,6 +30,10 @@
     1.4      int gl_active;              /* to stop switching drivers while we have a valid context */
     1.5      int initialized;
     1.6      DirectFB_GLContext *firstgl;        /* linked list */
     1.7 +    
     1.8 +    /* OpenGL */
     1.9 +    void (*glFinish) (void);
    1.10 +    void (*glFlush) (void);
    1.11  };
    1.12  
    1.13  #define OPENGL_REQUIRS_DLOPEN
    1.14 @@ -94,7 +98,7 @@
    1.15  int
    1.16  DirectFB_GL_LoadLibrary(_THIS, const char *path)
    1.17  {
    1.18 -    SDL_DFB_DEVICEDATA(_this);
    1.19 +    //SDL_DFB_DEVICEDATA(_this);
    1.20  
    1.21      void *handle = NULL;
    1.22  
    1.23 @@ -122,9 +126,6 @@
    1.24  
    1.25      SDL_DFB_DEBUG("Loaded library: %s\n", path);
    1.26  
    1.27 -    /* Unload the old driver and reset the pointers */
    1.28 -    DirectFB_GL_UnloadLibrary(_this);
    1.29 -
    1.30      _this->gl_config.dll_handle = handle;
    1.31      _this->gl_config.driver_loaded = 1;
    1.32      if (path) {
    1.33 @@ -134,8 +135,8 @@
    1.34          *_this->gl_config.driver_path = '\0';
    1.35      }
    1.36  
    1.37 -    devdata->glFinish = DirectFB_GL_GetProcAddress(_this, "glFinish");
    1.38 -    devdata->glFlush = DirectFB_GL_GetProcAddress(_this, "glFlush");
    1.39 +    _this->gl_data->glFinish = DirectFB_GL_GetProcAddress(_this, "glFinish");
    1.40 +    _this->gl_data->glFlush = DirectFB_GL_GetProcAddress(_this, "glFlush");
    1.41  
    1.42      return 0;
    1.43  }
    1.44 @@ -143,6 +144,7 @@
    1.45  static void
    1.46  DirectFB_GL_UnloadLibrary(_THIS)
    1.47  {
    1.48 + #if 0
    1.49      int ret;
    1.50  
    1.51      if (_this->gl_config.driver_loaded) {
    1.52 @@ -153,6 +155,10 @@
    1.53          _this->gl_config.dll_handle = NULL;
    1.54          _this->gl_config.driver_loaded = 0;
    1.55      }
    1.56 +#endif
    1.57 +    /* Free OpenGL memory */
    1.58 +    SDL_free(_this->gl_data);
    1.59 +    _this->gl_data = NULL;
    1.60  }
    1.61  
    1.62  void *
    1.63 @@ -167,11 +173,11 @@
    1.64  SDL_GLContext
    1.65  DirectFB_GL_CreateContext(_THIS, SDL_Window * window)
    1.66  {
    1.67 +    //SDL_DFB_DEVICEDATA(_this);
    1.68      SDL_DFB_WINDOWDATA(window);
    1.69      DirectFB_GLContext *context;
    1.70 -    int ret;
    1.71  
    1.72 -    SDL_DFB_CALLOC(context, 1, sizeof(*context));
    1.73 +    SDL_DFB_CALLOC(context, 1, sizeof(DirectFB_GLContext));
    1.74  
    1.75      SDL_DFB_CHECKERR(windata->surface->GetGL(windata->surface,
    1.76                                               &context->context));
    1.77 @@ -179,11 +185,14 @@
    1.78      if (!context->context)
    1.79          return NULL;
    1.80  
    1.81 -    SDL_DFB_CHECKERR(context->context->Unlock(context->context));
    1.82 -
    1.83 +    context->is_locked = 0;
    1.84 +    context->sdl_window = window;
    1.85 +    
    1.86      context->next = _this->gl_data->firstgl;
    1.87      _this->gl_data->firstgl = context;
    1.88  
    1.89 +    SDL_DFB_CHECK(context->context->Unlock(context->context));
    1.90 +
    1.91      if (DirectFB_GL_MakeCurrent(_this, window, context) < 0) {
    1.92          DirectFB_GL_DeleteContext(_this, context);
    1.93          return NULL;
    1.94 @@ -198,28 +207,24 @@
    1.95  int
    1.96  DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
    1.97  {
    1.98 -    SDL_DFB_WINDOWDATA(window);
    1.99 +    //SDL_DFB_WINDOWDATA(window);
   1.100      DirectFB_GLContext *ctx = (DirectFB_GLContext *) context;
   1.101      DirectFB_GLContext *p;
   1.102  
   1.103 -    int ret;
   1.104 -
   1.105      for (p = _this->gl_data->firstgl; p; p = p->next)
   1.106 -        p->context->Unlock(p->context);
   1.107 -
   1.108 -    if (windata) {
   1.109 -        windata->gl_context = NULL;
   1.110 -        /* Everything is unlocked, check for a resize */
   1.111 -        DirectFB_AdjustWindowSurface(window);
   1.112 +    {
   1.113 +       if (p->is_locked) {
   1.114 +         SDL_DFB_CHECKERR(p->context->Unlock(p->context));
   1.115 +         p->is_locked = 0;
   1.116 +       }
   1.117 +        
   1.118      }
   1.119  
   1.120      if (ctx != NULL) {
   1.121          SDL_DFB_CHECKERR(ctx->context->Lock(ctx->context));
   1.122 +        ctx->is_locked = 1;
   1.123      }
   1.124  
   1.125 -    if (windata)
   1.126 -        windata->gl_context = ctx;
   1.127 -
   1.128      return 0;
   1.129    error:
   1.130      return -1;
   1.131 @@ -242,28 +247,36 @@
   1.132  void
   1.133  DirectFB_GL_SwapWindow(_THIS, SDL_Window * window)
   1.134  {
   1.135 -    SDL_DFB_DEVICEDATA(_this);
   1.136 +    //SDL_DFB_DEVICEDATA(_this);
   1.137      SDL_DFB_WINDOWDATA(window);
   1.138 -    int ret;
   1.139      DFBRegion region;
   1.140 +    DirectFB_GLContext *p;
   1.141  
   1.142      region.x1 = 0;
   1.143      region.y1 = 0;
   1.144      region.x2 = window->w;
   1.145      region.y2 = window->h;
   1.146  
   1.147 +#if 0
   1.148      if (devdata->glFinish)
   1.149          devdata->glFinish();
   1.150      else if (devdata->glFlush)
   1.151          devdata->glFlush();
   1.152 +#endif
   1.153  
   1.154 -    if (1 || windata->gl_context) {
   1.155 -        /* SDL_DFB_CHECKERR(windata->gl_context->context->Unlock(windata->gl_context->context)); */
   1.156 -        SDL_DFB_CHECKERR(windata->surface->Flip(windata->surface, &region,
   1.157 -                                                DSFLIP_ONSYNC));
   1.158 -        /* SDL_DFB_CHECKERR(windata->gl_context->context->Lock(windata->gl_context->context)); */
   1.159 +  	for (p = _this->gl_data->firstgl; p != NULL; p = p->next)
   1.160 +        if (p->sdl_window == window && p->is_locked)
   1.161 +        {
   1.162 +            SDL_DFB_CHECKERR(p->context->Unlock(p->context));
   1.163 +            p->is_locked = 0;
   1.164 +        }            
   1.165  
   1.166 -    }
   1.167 +    SDL_DFB_CHECKERR(windata->window_surface->Flip(windata->window_surface,NULL,  DSFLIP_PIPELINE |DSFLIP_BLIT | DSFLIP_ONSYNC ));
   1.168 +
   1.169 +    //if (windata->gl_context) {
   1.170 +        //SDL_DFB_CHECKERR(windata->surface->Flip(windata->surface,NULL, DSFLIP_ONSYNC)); 
   1.171 +        //SDL_DFB_CHECKERR(windata->gl_context->context->Lock(windata->gl_context->context));
   1.172 +    //}
   1.173  
   1.174      return;
   1.175    error:
   1.176 @@ -276,19 +289,58 @@
   1.177      DirectFB_GLContext *ctx = (DirectFB_GLContext *) context;
   1.178      DirectFB_GLContext *p;
   1.179  
   1.180 -    ctx->context->Unlock(ctx->context);
   1.181 -    ctx->context->Release(ctx->context);
   1.182 +    if (ctx->is_locked)
   1.183 +        SDL_DFB_CHECK(ctx->context->Unlock(ctx->context));
   1.184 +    SDL_DFB_RELEASE(ctx->context);
   1.185  
   1.186 -    p = _this->gl_data->firstgl;
   1.187 -    while (p && p->next != ctx)
   1.188 -        p = p->next;
   1.189 +    for (p = _this->gl_data->firstgl; p && p->next != ctx; p = p->next)
   1.190 +        ;
   1.191      if (p)
   1.192          p->next = ctx->next;
   1.193      else
   1.194          _this->gl_data->firstgl = ctx->next;
   1.195  
   1.196      SDL_DFB_FREE(ctx);
   1.197 +}
   1.198  
   1.199 +void
   1.200 +DirectFB_GL_FreeWindowContexts(_THIS, SDL_Window * window)
   1.201 +{
   1.202 +    DirectFB_GLContext *p;
   1.203 +    
   1.204 +	for (p = _this->gl_data->firstgl; p != NULL; p = p->next)
   1.205 +	    if (p->sdl_window == window)
   1.206 +	    {
   1.207 +	    	if (p->is_locked)
   1.208 +	        	SDL_DFB_CHECK(p->context->Unlock(p->context));
   1.209 +	        SDL_DFB_RELEASE(p->context);
   1.210 +	    }
   1.211 +}
   1.212 +
   1.213 +void
   1.214 +DirectFB_GL_ReAllocWindowContexts(_THIS, SDL_Window * window)
   1.215 +{
   1.216 +    DirectFB_GLContext *p;
   1.217 +
   1.218 +	for (p = _this->gl_data->firstgl; p != NULL; p = p->next)
   1.219 +	    if (p->sdl_window == window)
   1.220 +	    {
   1.221 +            SDL_DFB_WINDOWDATA(window);
   1.222 +			SDL_DFB_CHECK(windata->surface->GetGL(windata->surface,
   1.223 +	                                         &p->context));
   1.224 +    		if (p->is_locked)
   1.225 +            	SDL_DFB_CHECK(p->context->Lock(p->context));
   1.226 +	        }
   1.227 +}
   1.228 +
   1.229 +void
   1.230 +DirectFB_GL_DestroyWindowContexts(_THIS, SDL_Window * window)
   1.231 +{
   1.232 +    DirectFB_GLContext *p;
   1.233 +
   1.234 +	for (p = _this->gl_data->firstgl; p != NULL; p = p->next)
   1.235 +		if (p->sdl_window == window)
   1.236 +			DirectFB_GL_DeleteContext(_this, p);
   1.237  }
   1.238  
   1.239  #endif