stw_wgl_context.c File Reference

Include dependency graph for stw_wgl_context.c:

Go to the source code of this file.

Functions

WINGDIAPI BOOL APIENTRY wglCopyContext (HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
WINGDIAPI HGLRC APIENTRY wglCreateContext (HDC hdc)
WINGDIAPI HGLRC APIENTRY wglCreateLayerContext (HDC hdc, int iLayerPlane)
WINGDIAPI BOOL APIENTRY wglDeleteContext (HGLRC hglrc)
static void get_window_size (HDC hdc, GLuint *width, GLuint *height)
WINGDIAPI HGLRC APIENTRY wglGetCurrentContext (VOID)
WINGDIAPI HDC APIENTRY wglGetCurrentDC (VOID)
WINGDIAPI BOOL APIENTRY wglMakeCurrent (HDC hdc, HGLRC hglrc)
struct wgl_contextwgl_context_from_hdc (HDC hdc)

Variables

static struct wgl_contextctx_head = NULL
static HDC current_hdc = NULL
static HGLRC current_hrc = NULL


Function Documentation

static void get_window_size ( HDC  hdc,
GLuint *  width,
GLuint *  height 
) [static]

Definition at line 183 of file stw_wgl_context.c.

00184 {
00185    if (WindowFromDC( hdc )) {
00186       RECT rect;
00187 
00188       GetClientRect( WindowFromDC( hdc ), &rect );
00189       *width = rect.right - rect.left;
00190       *height = rect.bottom - rect.top;
00191    }
00192    else {
00193       *width = GetDeviceCaps( hdc, HORZRES );
00194       *height = GetDeviceCaps( hdc, VERTRES );
00195    }
00196 }

struct wgl_context* wgl_context_from_hdc ( HDC  hdc  )  [read]

Definition at line 278 of file stw_wgl_context.c.

References wgl_context::hdc, and wgl_context::next.

00280 {
00281    struct wgl_context *ctx = ctx_head;
00282 
00283    while (ctx != NULL) {
00284       if (ctx->hdc == hdc)
00285          return ctx;
00286       ctx = ctx->next;
00287    }
00288    return NULL;
00289 }

WINGDIAPI BOOL APIENTRY wglCopyContext ( HGLRC  hglrcSrc,
HGLRC  hglrcDst,
UINT  mask 
)

Definition at line 50 of file stw_wgl_context.c.

References FALSE.

00054 {
00055    (void) hglrcSrc;
00056    (void) hglrcDst;
00057    (void) mask;
00058 
00059    return FALSE;
00060 }

WINGDIAPI HGLRC APIENTRY wglCreateContext ( HDC  hdc  ) 

Definition at line 63 of file stw_wgl_context.c.

References pixelformat_info::alpha, pixelformat_alpha_info::alphabits, pixelformat_color_info::bluebits, CALLOC_STRUCT, pixelformat_info::color, wgl_context::color_bits, stw_winsys::create_context, st_context::ctx, pixelformat_info::depth, pixelformat_depth_info::depthbits, pipe_context::destroy, pixelformat_info::flags, FREE, pixelformat_color_info::greenbits, wgl_context::hdc, wgl_context::next, PF_FLAG_DOUBLEBUFFER, PF_FLAG_MULTISAMPLED, pixelformat_get_info(), pixelformat_color_info::redbits, stw_device::screen, wgl_context::st, st_create_context(), pixelformat_depth_info::stencilbits, stw_dev, stw_device::stw_winsys, wgl_query_samples(), and wglGetPixelFormat().

00065 {
00066    uint pfi;
00067    const struct pixelformat_info *pf;
00068    struct wgl_context *ctx;
00069    GLvisual *visual;
00070    struct pipe_context *pipe;
00071 
00072    pfi = wglGetPixelFormat( hdc );
00073    if (pfi == 0)
00074       return NULL;
00075 
00076    pf = pixelformat_get_info( pfi - 1 );
00077 
00078    ctx = CALLOC_STRUCT( wgl_context );
00079    if (ctx == NULL)
00080       return NULL;
00081 
00082    ctx->hdc = hdc;
00083    ctx->color_bits = GetDeviceCaps( ctx->hdc, BITSPIXEL );
00084 
00085    /* Create visual based on flags
00086     */
00087    visual = _mesa_create_visual(
00088       GL_TRUE,
00089       (pf->flags & PF_FLAG_DOUBLEBUFFER) ? GL_TRUE : GL_FALSE,
00090       GL_FALSE,
00091       pf->color.redbits,
00092       pf->color.greenbits,
00093       pf->color.bluebits,
00094       pf->alpha.alphabits,
00095       0,
00096       pf->depth.depthbits,
00097       pf->depth.stencilbits,
00098       0,
00099       0,
00100       0,
00101       0,
00102       (pf->flags & PF_FLAG_MULTISAMPLED) ? wgl_query_samples() : 0 );
00103    if (visual == NULL) {
00104       FREE( ctx );
00105       return NULL;
00106    }
00107 
00108    pipe = stw_dev->stw_winsys->create_context( stw_dev->screen );
00109    if (!pipe) {
00110       _mesa_destroy_visual( visual );
00111       FREE( ctx );
00112       return NULL;
00113    }
00114 
00115    ctx->st = st_create_context( pipe, visual, NULL );
00116    if (ctx->st == NULL) {
00117       pipe->destroy( pipe );
00118       _mesa_destroy_visual( visual );
00119       FREE( ctx );
00120       return NULL;
00121    }
00122    ctx->st->ctx->DriverCtx = ctx;
00123 
00124    ctx->next = ctx_head;
00125    ctx_head = ctx;
00126 
00127    return (HGLRC) ctx;
00128 }

WINGDIAPI HGLRC APIENTRY wglCreateLayerContext ( HDC  hdc,
int  iLayerPlane 
)

Definition at line 131 of file stw_wgl_context.c.

00134 {
00135    (void) hdc;
00136    (void) iLayerPlane;
00137 
00138    return NULL;
00139 }

WINGDIAPI BOOL APIENTRY wglDeleteContext ( HGLRC  hglrc  ) 

Definition at line 142 of file stw_wgl_context.c.

References st_context::ctx, FALSE, framebuffer_destroy(), framebuffer_from_hdc(), FREE, wgl_context::hdc, wgl_context::next, wgl_context::st, st_destroy_context(), st_make_current(), and TRUE.

00144 {
00145    struct wgl_context **link = &ctx_head;
00146    struct wgl_context *ctx = ctx_head;
00147 
00148    while (ctx != NULL) {
00149       if (ctx == (struct wgl_context *) hglrc) {
00150          GLcontext *glctx = ctx->st->ctx;
00151          GET_CURRENT_CONTEXT( glcurctx );
00152          struct stw_framebuffer *fb;
00153 
00154          /* Unbind current if deleting current context.
00155           */
00156          if (glcurctx == glctx)
00157             st_make_current( NULL, NULL, NULL );
00158 
00159          fb = framebuffer_from_hdc( ctx->hdc );
00160          if (fb)
00161             framebuffer_destroy( fb );
00162 
00163          if (WindowFromDC( ctx->hdc ) != NULL)
00164             ReleaseDC( WindowFromDC( ctx->hdc ), ctx->hdc );
00165 
00166          st_destroy_context( ctx->st );
00167 
00168          *link = ctx->next;
00169          FREE( ctx );
00170          return TRUE;
00171       }
00172 
00173       link = &ctx->next;
00174       ctx = ctx->next;
00175    }
00176 
00177    return FALSE;
00178 }

WINGDIAPI HGLRC APIENTRY wglGetCurrentContext ( VOID   ) 

Definition at line 199 of file stw_wgl_context.c.

References current_hrc.

00200 {
00201    return current_hrc;
00202 }

WINGDIAPI HDC APIENTRY wglGetCurrentDC ( VOID   ) 

Definition at line 205 of file stw_wgl_context.c.

References current_hdc.

00206 {
00207     return current_hdc;
00208 }

WINGDIAPI BOOL APIENTRY wglMakeCurrent ( HDC  hdc,
HGLRC  hglrc 
)

Definition at line 211 of file stw_wgl_context.c.

References st_context::ctx, current_hdc, current_hrc, stw_framebuffer::dib_hDC, FALSE, framebuffer_create(), framebuffer_from_hdc(), framebuffer_resize(), get_window_size(), stw_framebuffer::hbmDIB, wgl_context::hdc, wgl_context::next, stw_framebuffer::pbPixels, wgl_context::st, st_make_current(), stw_framebuffer::stfb, and TRUE.

00214 {
00215    struct wgl_context *ctx = ctx_head;
00216    GET_CURRENT_CONTEXT( glcurctx );
00217    struct stw_framebuffer *fb;
00218    GLuint width = 0;
00219    GLuint height = 0;
00220 
00221    current_hdc = hdc;
00222    current_hrc = hglrc;
00223 
00224    if (hdc == NULL || hglrc == NULL) {
00225       st_make_current( NULL, NULL, NULL );
00226       return TRUE;
00227    }
00228 
00229    while (ctx != NULL) {
00230       if (ctx == (struct wgl_context *) hglrc)
00231          break;
00232       ctx = ctx->next;
00233    }
00234    if (ctx == NULL)
00235       return FALSE;
00236 
00237    /* Return if already current.
00238     */
00239    if (glcurctx != NULL) {
00240       struct wgl_context *curctx = (struct wgl_context *) glcurctx->DriverCtx;
00241 
00242       if (curctx != NULL && curctx == ctx && ctx->hdc == hdc)
00243          return TRUE;
00244    }
00245 
00246    fb = framebuffer_from_hdc( hdc );
00247 
00248    if (hdc != NULL)
00249       get_window_size( hdc, &width, &height );
00250 
00251    /* Lazy creation of framebuffers.
00252     */
00253    if (fb == NULL && ctx != NULL && hdc != NULL) {
00254       GLvisual *visual = &ctx->st->ctx->Visual;
00255 
00256       fb = framebuffer_create( hdc, visual, width, height );
00257       if (fb == NULL)
00258          return FALSE;
00259 
00260       fb->dib_hDC = CreateCompatibleDC( hdc );
00261       fb->hbmDIB = NULL;
00262       fb->pbPixels = NULL;
00263    }
00264 
00265    if (ctx && fb) {
00266       st_make_current( ctx->st, fb->stfb, fb->stfb );
00267       framebuffer_resize( fb, width, height );
00268    }
00269    else {
00270       /* Detach */
00271       st_make_current( NULL, NULL, NULL );
00272    }
00273 
00274    return TRUE;
00275 }


Variable Documentation

struct wgl_context* ctx_head = NULL [static]

Definition at line 44 of file stw_wgl_context.c.

HDC current_hdc = NULL [static]

Definition at line 46 of file stw_wgl_context.c.

HGLRC current_hrc = NULL [static]

Definition at line 47 of file stw_wgl_context.c.


Generated on Tue Sep 29 06:25:56 2009 for Gallium3D by  doxygen 1.5.4