#include <windows.h>
-#include "main/context.h"
#include "pipe/p_format.h"
#include "pipe/p_screen.h"
-#include "state_tracker/st_context.h"
-#include "state_tracker/st_public.h"
-
-#ifdef DEBUG
-#include "trace/tr_screen.h"
-#include "trace/tr_texture.h"
-#endif
+#include "util/u_format.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"
/**
/**
* 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(
{
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;
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 );
if(!tls_data)
return 0;
- if (nCode < 0)
+ if (nCode < 0 || !stw_dev)
return CallNextHookEx(tls_data->hCallWndProcHook, nCode, wParam, lParam);
if (pParams->message == WM_WINDOWPOSCHANGED) {
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 );
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;
-
- assert(pf_layout( pfi->depth_stencil_format ) == PIPE_FORMAT_LAYOUT_RGBAZS );
-
- if(pf_get_component_bits( pfi->depth_stencil_format, PIPE_FORMAT_COMP_Z ))
- depthFormat = pfi->depth_stencil_format;
- else
- depthFormat = PIPE_FORMAT_NONE;
-
- if(pf_get_component_bits( pfi->depth_stencil_format, PIPE_FORMAT_COMP_S ))
- 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 (old_fb == fb)
+ return;
+
+ 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;
}
* 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;
- }
}
struct stw_framebuffer *fb;
struct stw_framebuffer *next;
+ if (!stw_dev)
+ return;
+
pipe_mutex_lock( stw_dev->fb_mutex );
fb = stw_dev->fb_head;
{
struct stw_framebuffer *fb;
+ if (!stw_dev)
+ return NULL;
+
pipe_mutex_lock( stw_dev->fb_mutex );
fb = stw_framebuffer_from_hdc_locked(hdc);
pipe_mutex_unlock( stw_dev->fb_mutex );
uint index;
struct stw_framebuffer *fb;
+ if (!stw_dev)
+ return FALSE;
+
index = (uint) iPixelFormat - 1;
count = stw_pixelformat_get_extended_count();
if (index >= count)
struct stw_framebuffer *fb;
struct pipe_screen *screen;
struct pipe_surface *surface;
- unsigned surface_index;
- BOOL ret = FALSE;
+
+ if (!stw_dev)
+ return FALSE;
fb = stw_framebuffer_from_hdc( hdc );
if (fb == NULL)
screen = stw_dev->screen;
- surface_index = (unsigned)(uintptr_t)data->pPrivateData;
- if(!st_get_framebuffer_surface( fb->stfb, surface_index, &surface ))
- goto fail;
-
-#ifdef DEBUG
- if(stw_dev->trace_running) {
- screen = trace_screen(screen)->screen;
- surface = trace_surface(surface)->surface;
- }
-#endif
+ surface = (struct pipe_surface *)data->pPrivateData;
if(data->hSharedSurface != fb->hSharedSurface) {
if(fb->shared_surface) {
stw_dev->stw_winsys->present( screen, surface, hdc );
}
- ret = TRUE;
-
-fail:
-
stw_framebuffer_update(fb);
+ stw_notify_current_locked(fb);
stw_framebuffer_release(fb);
- return ret;
+ return TRUE;
}
BOOL
stw_framebuffer_present_locked(HDC hdc,
struct stw_framebuffer *fb,
- unsigned surface_index)
+ struct pipe_surface *surface)
{
if(stw_dev->callbacks.wglCbPresentBuffers &&
stw_dev->stw_winsys->compose) {
data.magic2 = 0;
data.AdapterLuid = stw_dev->AdapterLuid;
data.rect = fb->client_rect;
- data.pPrivateData = (void *)(uintptr_t)surface_index;
+ data.pPrivateData = (void *)surface;
+ stw_notify_current_locked(fb);
stw_framebuffer_release(fb);
return stw_dev->callbacks.wglCbPresentBuffers(hdc, &data);
}
else {
struct pipe_screen *screen = stw_dev->screen;
- struct pipe_surface *surface;
-
- if(!st_get_framebuffer_surface( fb->stfb, surface_index, &surface )) {
- /* FIXME: this shouldn't happen, but does on glean */
- stw_framebuffer_release(fb);
- return FALSE;
- }
-
-#ifdef DEBUG
- if(stw_dev->trace_running) {
- screen = trace_screen(screen)->screen;
- surface = trace_surface(surface)->surface;
- }
-#endif
stw_dev->stw_winsys->present( screen, surface, hdc );
stw_framebuffer_update(fb);
-
+ stw_notify_current_locked(fb);
stw_framebuffer_release(fb);
return TRUE;
{
struct stw_framebuffer *fb;
+ if (!stw_dev)
+ return FALSE;
+
fb = stw_framebuffer_from_hdc( hdc );
if (fb == NULL)
return FALSE;
return TRUE;
}
- /* If we're swapping the buffer associated with the current context
- * we have to flush any pending rendering commands first.
- */
- st_notify_swapbuffers( fb->stfb );
+ stw_flush_current_locked(fb);
- return stw_framebuffer_present_locked(hdc, fb, ST_SURFACE_BACK_LEFT);
+ return stw_st_swap_framebuffer_locked(fb->stfb);
}