X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fstate_trackers%2Fwgl%2Fstw_framebuffer.c;h=259b22f22c73a1a13ab435fd31cd45428ede5f12;hb=db1689c23629d2cf66a7a35ed0e899006ef2af52;hp=4f1629de2f2c16ec55ee630bab48ccd4d384b83a;hpb=4fb2daf42c8171579cdc18605c5ceeb1963f8b31;p=mesa.git diff --git a/src/gallium/state_trackers/wgl/stw_framebuffer.c b/src/gallium/state_trackers/wgl/stw_framebuffer.c index 4f1629de2f2..259b22f22c7 100644 --- a/src/gallium/state_trackers/wgl/stw_framebuffer.c +++ b/src/gallium/state_trackers/wgl/stw_framebuffer.c @@ -27,18 +27,19 @@ #include -#include "main/context.h" #include "pipe/p_format.h" #include "pipe/p_screen.h" #include "util/u_format.h" -#include "state_tracker/st_context.h" -#include "state_tracker/st_public.h" +#include "util/u_memory.h" +#include "state_tracker/st_api.h" #include "stw_icd.h" #include "stw_framebuffer.h" #include "stw_device.h" #include "stw_winsys.h" #include "stw_tls.h" +#include "stw_context.h" +#include "stw_st.h" /** @@ -63,8 +64,8 @@ stw_framebuffer_from_hwnd_locked( /** * Destroy this framebuffer. Both stw_dev::fb_mutex and stw_framebuffer::mutex - * must be held, by this order. Obviously no further access to fb can be done - * after this. + * must be held, by this order. If there are still references to the + * framebuffer, nothing will happen. */ static INLINE void stw_framebuffer_destroy_locked( @@ -72,6 +73,13 @@ stw_framebuffer_destroy_locked( { struct stw_framebuffer **link; + /* check the reference count */ + fb->refcnt--; + if (fb->refcnt) { + pipe_mutex_unlock( fb->mutex ); + return; + } + link = &stw_dev->fb_head; while (*link != fb) link = &(*link)->next; @@ -82,7 +90,7 @@ stw_framebuffer_destroy_locked( if(fb->shared_surface) stw_dev->stw_winsys->shared_surface_close(stw_dev->screen, fb->shared_surface); - st_unreference_framebuffer(fb->stfb); + stw_st_destroy_framebuffer_locked(fb->stfb); pipe_mutex_unlock( fb->mutex ); @@ -230,9 +238,14 @@ stw_framebuffer_create( fb->iPixelFormat = iPixelFormat; fb->pfi = pfi = stw_pixelformat_get_info( iPixelFormat - 1 ); + fb->stfb = stw_st_create_framebuffer( fb ); + if (!fb->stfb) { + FREE( fb ); + return NULL; + } + + fb->refcnt = 1; - stw_pixelformat_visual(&fb->visual, pfi); - stw_framebuffer_get_size(fb); pipe_mutex_init( fb->mutex ); @@ -251,47 +264,31 @@ stw_framebuffer_create( return fb; } - -BOOL -stw_framebuffer_allocate( +/** + * Have ptr reference fb. The referenced framebuffer should be locked. + */ +void +stw_framebuffer_reference( + struct stw_framebuffer **ptr, struct stw_framebuffer *fb) { - assert(fb); - - if(!fb->stfb) { - const struct stw_pixelformat_info *pfi = fb->pfi; - enum pipe_format colorFormat, depthFormat, stencilFormat; + struct stw_framebuffer *old_fb = *ptr; - colorFormat = pfi->color_format; + if (old_fb == fb) + return; - if(util_format_get_component_bits(pfi->depth_stencil_format, UTIL_FORMAT_COLORSPACE_ZS, 0)) - depthFormat = pfi->depth_stencil_format; - else - depthFormat = PIPE_FORMAT_NONE; - - if(util_format_get_component_bits(pfi->depth_stencil_format, UTIL_FORMAT_COLORSPACE_ZS, 1)) - stencilFormat = pfi->depth_stencil_format; - else - stencilFormat = PIPE_FORMAT_NONE; - - assert(fb->must_resize); - assert(fb->width); - assert(fb->height); - - fb->stfb = st_create_framebuffer( - &fb->visual, - colorFormat, - depthFormat, - stencilFormat, - fb->width, - fb->height, - (void *) fb ); - - // to notify the context - fb->must_resize = TRUE; + if (fb) + fb->refcnt++; + if (old_fb) { + pipe_mutex_lock(stw_dev->fb_mutex); + + pipe_mutex_lock(old_fb->mutex); + stw_framebuffer_destroy_locked(old_fb); + + pipe_mutex_unlock(stw_dev->fb_mutex); } - - return fb->stfb ? TRUE : FALSE; + + *ptr = fb; } @@ -313,11 +310,6 @@ stw_framebuffer_update( * to know of their existing without using the not very portable PSAPI. */ stw_framebuffer_get_size(fb); - - if(fb->must_resize) { - st_resize_framebuffer(fb->stfb, fb->width, fb->height); - fb->must_resize = FALSE; - } } @@ -516,6 +508,7 @@ DrvPresentBuffers(HDC hdc, PGLPRESENTBUFFERSDATA data) } stw_framebuffer_update(fb); + stw_notify_current_locked(fb); stw_framebuffer_release(fb); @@ -544,6 +537,7 @@ stw_framebuffer_present_locked(HDC hdc, data.rect = fb->client_rect; data.pPrivateData = (void *)surface; + stw_notify_current_locked(fb); stw_framebuffer_release(fb); return stw_dev->callbacks.wglCbPresentBuffers(hdc, &data); @@ -554,7 +548,7 @@ stw_framebuffer_present_locked(HDC hdc, stw_dev->stw_winsys->present( screen, surface, hdc ); stw_framebuffer_update(fb); - + stw_notify_current_locked(fb); stw_framebuffer_release(fb); return TRUE; @@ -567,7 +561,6 @@ DrvSwapBuffers( HDC hdc ) { struct stw_framebuffer *fb; - struct pipe_surface *surface = NULL; if (!stw_dev) return FALSE; @@ -581,9 +574,9 @@ DrvSwapBuffers( return TRUE; } - st_swapbuffers(fb->stfb, &surface, NULL); + stw_flush_current_locked(fb); - return stw_framebuffer_present_locked(hdc, fb, surface); + return stw_st_swap_framebuffer_locked(fb->stfb); }