gallium: rename st_framebuffer_iface -> pipe_frontend_drawable, etc.
[platform/upstream/mesa.git] / src / gallium / frontends / wgl / stw_framebuffer.c
1 /**************************************************************************
2  *
3  * Copyright 2008-2009 VMware, Inc.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27
28 #include "state_tracker/st_context.h"
29
30 #include <windows.h>
31
32 #include "pipe/p_screen.h"
33 #include "pipe/p_state.h"
34 #include "util/u_memory.h"
35 #include "hud/hud_context.h"
36 #include "util/os_time.h"
37 #include "frontend/api.h"
38
39 #include <GL/gl.h>
40 #include "gldrv.h"
41 #include "stw_framebuffer.h"
42 #include "stw_device.h"
43 #include "stw_winsys.h"
44 #include "stw_tls.h"
45 #include "stw_context.h"
46 #include "stw_st.h"
47
48
49 /**
50  * Search the framebuffer with the matching HWND while holding the
51  * stw_dev::fb_mutex global lock.
52  * If a stw_framebuffer is found, lock it and return the pointer.
53  * Else, return NULL.
54  */
55 static struct stw_framebuffer *
56 stw_framebuffer_from_hwnd_locked(HWND hwnd)
57 {
58    struct stw_framebuffer *fb;
59
60    for (fb = stw_dev->fb_head; fb != NULL; fb = fb->next)
61       if (fb->hWnd == hwnd) {
62          stw_framebuffer_lock(fb);
63
64          /* When running with Zink, during the Vulkan surface creation
65           * it's possible that the underlying Vulkan driver will try to
66           * access the HWND/HDC we passed in (see stw_st_fill_private_loader_data()).
67           * Because we create the Vulkan surface while holding the framebuffer
68           * lock, when the driver starts to look up properties,
69           * we'd end up double locking when looking up the framebuffer.
70           */
71          assert(stw_dev->zink || fb->mutex.RecursionCount == 1);
72          return fb;
73       }
74
75    return NULL;
76 }
77
78
79 /**
80  * Decrement the reference count on the given stw_framebuffer object.
81  * If the reference count hits zero, destroy the object.
82  *
83  * Note: Both stw_dev::fb_mutex and stw_framebuffer::mutex must already be
84  * locked.  After this function completes, the fb's mutex will be unlocked.
85  */
86 void
87 stw_framebuffer_release_locked(struct stw_framebuffer *fb,
88                                struct st_context *st)
89 {
90    struct stw_framebuffer **link;
91
92    assert(fb);
93    assert(stw_own_mutex(&fb->mutex));
94    assert(stw_own_mutex(&stw_dev->fb_mutex) || fb->owner == STW_FRAMEBUFFER_EGL_WINDOW);
95
96    /* check the reference count */
97    fb->refcnt--;
98    if (fb->refcnt) {
99       stw_framebuffer_unlock(fb);
100       return;
101    }
102
103    if (fb->owner != STW_FRAMEBUFFER_EGL_WINDOW) {
104       /* remove this stw_framebuffer from the device's linked list */
105       link = &stw_dev->fb_head;
106       while (*link != fb)
107          link = &(*link)->next;
108       assert(*link);
109       *link = fb->next;
110       fb->next = NULL;
111    }
112
113    if (fb->shared_surface)
114       stw_dev->stw_winsys->shared_surface_close(stw_dev->screen,
115                                                 fb->shared_surface);
116
117    if (fb->winsys_framebuffer)
118       fb->winsys_framebuffer->destroy(fb->winsys_framebuffer, st ? st->pipe : NULL);
119
120    stw_st_destroy_framebuffer_locked(fb->drawable);
121
122    stw_framebuffer_unlock(fb);
123
124    DeleteCriticalSection(&fb->mutex);
125
126    FREE( fb );
127 }
128
129
130 /**
131  * Query the size of the given framebuffer's on-screen window and update
132  * the stw_framebuffer's width/height.
133  */
134 static void
135 stw_framebuffer_get_size(struct stw_framebuffer *fb)
136 {
137    LONG width, height;
138    RECT client_rect;
139    RECT window_rect;
140    POINT client_pos;
141
142    /*
143     * Sanity checking.
144     */
145    assert(fb->hWnd);
146    assert(fb->width && fb->height);
147    assert(fb->client_rect.right  == fb->client_rect.left + fb->width);
148    assert(fb->client_rect.bottom == fb->client_rect.top  + fb->height);
149
150    /*
151     * Get the client area size.
152     */
153    if (!GetClientRect(fb->hWnd, &client_rect)) {
154       return;
155    }
156
157    assert(client_rect.left == 0);
158    assert(client_rect.top == 0);
159    width  = client_rect.right  - client_rect.left;
160    height = client_rect.bottom - client_rect.top;
161
162    fb->minimized = width == 0 || height == 0;
163
164    if (width <= 0 || height <= 0) {
165       /*
166        * When the window is minimized GetClientRect will return zeros.  Simply
167        * preserve the current window size, until the window is restored or
168        * maximized again.
169        */
170       return;
171    }
172
173    if (width != fb->width || height != fb->height) {
174       fb->must_resize = TRUE;
175       fb->width = width;
176       fb->height = height;
177    }
178
179    client_pos.x = 0;
180    client_pos.y = 0;
181    if (ClientToScreen(fb->hWnd, &client_pos) &&
182        GetWindowRect(fb->hWnd, &window_rect)) {
183       fb->client_rect.left = client_pos.x - window_rect.left;
184       fb->client_rect.top  = client_pos.y - window_rect.top;
185    }
186
187    fb->client_rect.right  = fb->client_rect.left + fb->width;
188    fb->client_rect.bottom = fb->client_rect.top  + fb->height;
189
190 #if 0
191    debug_printf("\n");
192    debug_printf("%s: hwnd = %p\n", __func__, fb->hWnd);
193    debug_printf("%s: client_position = (%li, %li)\n",
194                 __func__, client_pos.x, client_pos.y);
195    debug_printf("%s: window_rect = (%li, %li) - (%li, %li)\n",
196                 __func__,
197                 window_rect.left, window_rect.top,
198                 window_rect.right, window_rect.bottom);
199    debug_printf("%s: client_rect = (%li, %li) - (%li, %li)\n",
200                 __func__,
201                 fb->client_rect.left, fb->client_rect.top,
202                 fb->client_rect.right, fb->client_rect.bottom);
203 #endif
204 }
205
206
207 /**
208  * @sa http://msdn.microsoft.com/en-us/library/ms644975(VS.85).aspx
209  * @sa http://msdn.microsoft.com/en-us/library/ms644960(VS.85).aspx
210  */
211 LRESULT CALLBACK
212 stw_call_window_proc(int nCode, WPARAM wParam, LPARAM lParam)
213 {
214    struct stw_tls_data *tls_data;
215    PCWPSTRUCT pParams = (PCWPSTRUCT)lParam;
216    struct stw_framebuffer *fb;
217
218    tls_data = stw_tls_get_data();
219    if (!tls_data)
220       return 0;
221
222    if (nCode < 0 || !stw_dev)
223        return CallNextHookEx(tls_data->hCallWndProcHook, nCode, wParam, lParam);
224
225    /* We check that the stw_dev object is initialized before we try to do
226     * anything with it.  Otherwise, in multi-threaded programs there's a
227     * chance of executing this code before the stw_dev object is fully
228     * initialized.
229     */
230    if (stw_dev && stw_dev->initialized) {
231       if (pParams->message == WM_WINDOWPOSCHANGED) {
232          /* We handle WM_WINDOWPOSCHANGED instead of WM_SIZE because according
233           * to http://blogs.msdn.com/oldnewthing/archive/2008/01/15/7113860.aspx
234           * WM_SIZE is generated from WM_WINDOWPOSCHANGED by DefWindowProc so it
235           * can be masked out by the application.
236           */
237          LPWINDOWPOS lpWindowPos = (LPWINDOWPOS)pParams->lParam;
238          if ((lpWindowPos->flags & SWP_SHOWWINDOW) ||
239              !(lpWindowPos->flags & SWP_NOMOVE) ||
240              !(lpWindowPos->flags & SWP_NOSIZE)) {
241             fb = stw_framebuffer_from_hwnd( pParams->hwnd );
242             if (fb) {
243                /* Size in WINDOWPOS includes the window frame, so get the size
244                 * of the client area via GetClientRect.
245                 */
246                stw_framebuffer_get_size(fb);
247                stw_framebuffer_unlock(fb);
248             }
249          }
250       }
251       else if (pParams->message == WM_DESTROY) {
252          stw_lock_framebuffers(stw_dev);
253          fb = stw_framebuffer_from_hwnd_locked( pParams->hwnd );
254          if (fb) {
255             struct stw_context *current_context = stw_current_context();
256             struct st_context *st = current_context &&
257                current_context->current_framebuffer == fb ? current_context->st : NULL;
258             stw_framebuffer_release_locked(fb, st);
259          }
260          stw_unlock_framebuffers(stw_dev);
261       }
262    }
263
264    return CallNextHookEx(tls_data->hCallWndProcHook, nCode, wParam, lParam);
265 }
266
267
268 /**
269  * Create a new stw_framebuffer object which corresponds to the given
270  * HDC/window.  If successful, we return the new stw_framebuffer object
271  * with its mutex locked.
272  */
273 struct stw_framebuffer *
274 stw_framebuffer_create(HWND hWnd, const struct stw_pixelformat_info *pfi, enum stw_framebuffer_owner owner,
275                        struct pipe_frontend_screen *fscreen)
276 {
277    struct stw_framebuffer *fb;
278
279    fb = CALLOC_STRUCT( stw_framebuffer );
280    if (fb == NULL)
281       return NULL;
282
283    fb->hWnd = hWnd;
284
285    if (stw_dev->stw_winsys->create_framebuffer)
286       fb->winsys_framebuffer =
287          stw_dev->stw_winsys->create_framebuffer(stw_dev->screen, hWnd, pfi->iPixelFormat);
288
289    /*
290     * We often need a displayable pixel format to make GDI happy. Set it
291     * here (always 1, i.e., out first pixel format) where appropriate.
292     */
293    fb->iDisplayablePixelFormat = pfi->iPixelFormat <= stw_dev->pixelformat_count
294       ? pfi->iPixelFormat : 1;
295    fb->owner = owner;
296
297    fb->pfi = pfi;
298    fb->drawable = stw_st_create_framebuffer( fb, fscreen );
299    if (!fb->drawable) {
300       FREE( fb );
301       return NULL;
302    }
303
304    fb->refcnt = 1;
305
306    /* A -1 means defer to the global stw_dev->swap_interval */
307    fb->swap_interval = -1;
308
309    /*
310     * Windows can be sometimes have zero width and or height, but we ensure
311     * a non-zero framebuffer size at all times.
312     */
313
314    fb->must_resize = TRUE;
315    fb->width  = 1;
316    fb->height = 1;
317    fb->client_rect.left   = 0;
318    fb->client_rect.top    = 0;
319    fb->client_rect.right  = fb->client_rect.left + fb->width;
320    fb->client_rect.bottom = fb->client_rect.top  + fb->height;
321
322    stw_framebuffer_get_size(fb);
323
324    InitializeCriticalSection(&fb->mutex);
325
326    /* This is the only case where we lock the stw_framebuffer::mutex before
327     * stw_dev::fb_mutex, since no other thread can know about this framebuffer
328     * and we must prevent any other thread from destroying it before we return.
329     */
330    stw_framebuffer_lock(fb);
331
332    if (owner != STW_FRAMEBUFFER_EGL_WINDOW) {
333       stw_lock_framebuffers(stw_dev);
334       fb->next = stw_dev->fb_head;
335       stw_dev->fb_head = fb;
336       stw_unlock_framebuffers(stw_dev);
337    }
338
339    return fb;
340 }
341
342 /**
343  * Increase fb reference count.  The referenced framebuffer should be locked.
344  *
345  * It's not necessary to hold stw_dev::fb_mutex global lock.
346  */
347 void
348 stw_framebuffer_reference_locked(struct stw_framebuffer *fb)
349 {
350    if (fb) {
351       assert(stw_own_mutex(&fb->mutex));
352       fb->refcnt++;
353    }
354 }
355
356 /**
357  * Release stw_framebuffer::mutex lock. This framebuffer must not be accessed
358  * after calling this function, as it may have been deleted by another thread
359  * in the meanwhile.
360  */
361 void
362 stw_framebuffer_unlock(struct stw_framebuffer *fb)
363 {
364    assert(fb);
365    assert(stw_own_mutex(&fb->mutex));
366    LeaveCriticalSection(&fb->mutex);
367 }
368
369
370 /**
371  * Update the framebuffer's size if necessary.
372  */
373 void
374 stw_framebuffer_update(struct stw_framebuffer *fb)
375 {
376    assert(fb->drawable);
377    assert(fb->height);
378    assert(fb->width);
379
380    /* XXX: It would be nice to avoid checking the size again -- in theory
381     * stw_call_window_proc would have cought the resize and stored the right
382     * size already, but unfortunately threads created before the DllMain is
383     * called don't get a DLL_THREAD_ATTACH notification, and there is no way
384     * to know of their existing without using the not very portable PSAPI.
385     */
386    stw_framebuffer_get_size(fb);
387 }
388
389
390 /**
391  * Try to free all stw_framebuffer objects associated with the device.
392  */
393 void
394 stw_framebuffer_cleanup(void)
395 {
396    struct stw_framebuffer *fb;
397    struct stw_framebuffer *next;
398
399    if (!stw_dev)
400       return;
401
402    stw_lock_framebuffers(stw_dev);
403
404    fb = stw_dev->fb_head;
405    while (fb) {
406       next = fb->next;
407
408       stw_framebuffer_lock(fb);
409       stw_framebuffer_release_locked(fb, NULL);
410
411       fb = next;
412    }
413    stw_dev->fb_head = NULL;
414
415    stw_unlock_framebuffers(stw_dev);
416 }
417
418
419 /**
420  * Given an hdc, return the corresponding stw_framebuffer.
421  * The returned stw_framebuffer will have its mutex locked.
422  */
423 static struct stw_framebuffer *
424 stw_framebuffer_from_hdc_locked(HDC hdc)
425 {
426    HWND hwnd;
427
428    hwnd = WindowFromDC(hdc);
429    if (!hwnd) {
430       return NULL;
431    }
432
433    return stw_framebuffer_from_hwnd_locked(hwnd);
434 }
435
436
437 /**
438  * Given an HDC, return the corresponding stw_framebuffer.
439  * The returned stw_framebuffer will have its mutex locked.
440  */
441 struct stw_framebuffer *
442 stw_framebuffer_from_hdc(HDC hdc)
443 {
444    struct stw_framebuffer *fb;
445
446    if (!stw_dev)
447       return NULL;
448
449    stw_lock_framebuffers(stw_dev);
450    fb = stw_framebuffer_from_hdc_locked(hdc);
451    stw_unlock_framebuffers(stw_dev);
452
453    return fb;
454 }
455
456
457 /**
458  * Given an HWND, return the corresponding stw_framebuffer.
459  * The returned stw_framebuffer will have its mutex locked.
460  */
461 struct stw_framebuffer *
462 stw_framebuffer_from_hwnd(HWND hwnd)
463 {
464    struct stw_framebuffer *fb;
465
466    stw_lock_framebuffers(stw_dev);
467    fb = stw_framebuffer_from_hwnd_locked(hwnd);
468    stw_unlock_framebuffers(stw_dev);
469
470    return fb;
471 }
472
473
474 BOOL APIENTRY
475 DrvSetPixelFormat(HDC hdc, LONG iPixelFormat)
476 {
477    uint count;
478    uint index;
479    struct stw_framebuffer *fb;
480
481    if (!stw_dev)
482       return FALSE;
483
484    index = (uint) iPixelFormat - 1;
485    count = stw_pixelformat_get_count(hdc);
486    if (index >= count)
487       return FALSE;
488
489    fb = stw_framebuffer_from_hdc_locked(hdc);
490    if (fb) {
491       /*
492        * SetPixelFormat must be called only once.  However ignore
493        * pbuffers, for which the framebuffer object is created first.
494        */
495       boolean bPbuffer = fb->owner == STW_FRAMEBUFFER_PBUFFER;
496
497       stw_framebuffer_unlock( fb );
498
499       return bPbuffer;
500    }
501
502    const struct stw_pixelformat_info *pfi = stw_pixelformat_get_info(iPixelFormat);
503
504    fb = stw_framebuffer_create(WindowFromDC(hdc), pfi, STW_FRAMEBUFFER_WGL_WINDOW, stw_dev->fscreen);
505    if (!fb) {
506       return FALSE;
507    }
508
509    stw_framebuffer_unlock( fb );
510
511    /* Some applications mistakenly use the undocumented wglSetPixelFormat
512     * function instead of SetPixelFormat, so we call SetPixelFormat here to
513     * avoid opengl32.dll's wglCreateContext to fail */
514    if (GetPixelFormat(hdc) == 0) {
515       BOOL bRet = SetPixelFormat(hdc, iPixelFormat, NULL);
516       if (!bRet) {
517           debug_printf("SetPixelFormat failed\n");
518       }
519    }
520
521    return TRUE;
522 }
523
524
525 int
526 stw_pixelformat_get(HDC hdc)
527 {
528    int iPixelFormat = 0;
529    struct stw_framebuffer *fb;
530
531    fb = stw_framebuffer_from_hdc(hdc);
532    if (fb) {
533       iPixelFormat = fb->pfi->iPixelFormat;
534       stw_framebuffer_unlock(fb);
535    }
536
537    return iPixelFormat;
538 }
539
540
541 BOOL APIENTRY
542 DrvPresentBuffers(HDC hdc, LPPRESENTBUFFERS data)
543 {
544    struct stw_framebuffer *fb;
545    struct stw_context *ctx;
546    struct pipe_screen *screen;
547    struct pipe_context *pipe;
548    struct pipe_resource *res;
549
550    if (!stw_dev)
551       return FALSE;
552
553    fb = stw_framebuffer_from_hdc( hdc );
554    if (fb == NULL)
555       return FALSE;
556
557    screen = stw_dev->screen;
558    ctx = stw_current_context();
559    pipe = ctx ? ctx->st->pipe : NULL;
560
561    res = (struct pipe_resource *)data->pPrivData;
562
563    if (data->hSurface != fb->hSharedSurface) {
564       if (fb->shared_surface) {
565          stw_dev->stw_winsys->shared_surface_close(screen, fb->shared_surface);
566          fb->shared_surface = NULL;
567       }
568
569       fb->hSharedSurface = data->hSurface;
570
571       if (data->hSurface &&
572          stw_dev->stw_winsys->shared_surface_open) {
573          fb->shared_surface =
574             stw_dev->stw_winsys->shared_surface_open(screen,
575                                                      fb->hSharedSurface);
576       }
577    }
578
579    if (!fb->minimized) {
580       if (fb->shared_surface) {
581          stw_dev->stw_winsys->compose(screen,
582                                       res,
583                                       fb->shared_surface,
584                                       &fb->client_rect,
585                                       data->ullPresentToken);
586       }
587       else {
588          stw_dev->stw_winsys->present( screen, pipe, res, hdc );
589       }
590    }
591
592    stw_framebuffer_update(fb);
593    stw_notify_current_locked(fb);
594
595    stw_framebuffer_unlock(fb);
596
597    return TRUE;
598 }
599
600
601 /**
602  * Queue a composition.
603  *
604  * The stw_framebuffer object must have its mutex locked.  The mutex will
605  * be unlocked here before returning.
606  */
607 BOOL
608 stw_framebuffer_present_locked(HDC hdc,
609                                struct stw_framebuffer *fb,
610                                struct pipe_resource *res)
611 {
612    if (fb->winsys_framebuffer) {
613       int interval = fb->swap_interval == -1 ? stw_dev->swap_interval : fb->swap_interval;
614       BOOL result = fb->winsys_framebuffer->present(fb->winsys_framebuffer, interval);
615
616       stw_framebuffer_update(fb);
617       stw_notify_current_locked(fb);
618       stw_framebuffer_unlock(fb);
619
620       return result;
621    }
622    else if (stw_dev->callbacks.pfnPresentBuffers &&
623             stw_dev->stw_winsys->compose) {
624       PRESENTBUFFERSCB data;
625
626       memset(&data, 0, sizeof data);
627       data.nVersion = 2;
628       data.syncType = PRESCB_SYNCTYPE_NONE;
629       data.luidAdapter = stw_dev->AdapterLuid;
630       data.updateRect = fb->client_rect;
631       data.pPrivData = (void *)res;
632
633       stw_notify_current_locked(fb);
634       stw_framebuffer_unlock(fb);
635
636       return stw_dev->callbacks.pfnPresentBuffers(hdc, &data);
637    }
638    else {
639       struct pipe_screen *screen = stw_dev->screen;
640       struct stw_context *ctx = stw_current_context();
641       struct pipe_context *pipe = ctx ? ctx->st->pipe : NULL;
642
643       stw_dev->stw_winsys->present( screen, pipe, res, hdc );
644
645       stw_framebuffer_update(fb);
646       stw_notify_current_locked(fb);
647       stw_framebuffer_unlock(fb);
648
649       return TRUE;
650    }
651 }
652
653
654 /**
655  * This is called just before issuing the buffer swap/present.
656  * We query the current time and determine if we should sleep before
657  * issuing the swap/present.
658  * This is a bit of a hack and is certainly not very accurate but it
659  * basically works.
660  * This is for the WGL_ARB_swap_interval extension.
661  */
662 static void
663 wait_swap_interval(struct stw_framebuffer *fb, int interval)
664 {
665    /* Note: all time variables here are in units of microseconds */
666    int64_t cur_time = os_time_get_nano() / 1000;
667
668    if (fb->prev_swap_time != 0) {
669       /* Compute time since previous swap */
670       int64_t delta = cur_time - fb->prev_swap_time;
671       int64_t min_swap_period =
672          1.0e6 / stw_dev->refresh_rate * interval;
673
674       /* If time since last swap is less than wait period, wait.
675        * Note that it's possible for the delta to be negative because of
676        * rollover.  See https://bugs.freedesktop.org/show_bug.cgi?id=102241
677        */
678       if ((delta >= 0) && (delta < min_swap_period)) {
679          float fudge = 1.75f;  /* emperical fudge factor */
680          int64_t wait = (min_swap_period - delta) * fudge;
681          os_time_sleep(wait);
682       }
683    }
684
685    fb->prev_swap_time = cur_time;
686 }
687
688 BOOL
689 stw_framebuffer_swap_locked(HDC hdc, struct stw_framebuffer *fb)
690 {
691    struct stw_context *ctx;
692    if (!(fb->pfi->pfd.dwFlags & PFD_DOUBLEBUFFER)) {
693       stw_framebuffer_unlock(fb);
694       return TRUE;
695    }
696
697    ctx = stw_current_context();
698    if (ctx) {
699       if (ctx->hud) {
700          /* Display the HUD */
701          struct pipe_resource *back =
702             stw_get_framebuffer_resource(fb->drawable, ST_ATTACHMENT_BACK_LEFT);
703          if (back) {
704             hud_run(ctx->hud, NULL, back);
705          }
706       }
707
708       if (ctx->current_framebuffer == fb) {
709          /* flush current context */
710          stw_st_flush(ctx->st, fb->drawable, ST_FLUSH_END_OF_FRAME);
711       }
712    }
713
714    int interval = fb->swap_interval == -1 ? stw_dev->swap_interval : fb->swap_interval;
715    if (interval != 0 && !fb->winsys_framebuffer) {
716       wait_swap_interval(fb, interval);
717    }
718
719    return stw_st_swap_framebuffer_locked(hdc, ctx->st, fb->drawable);
720 }
721
722 BOOL APIENTRY
723 DrvSwapBuffers(HDC hdc)
724 {
725    struct stw_framebuffer *fb;
726
727    if (!stw_dev)
728       return FALSE;
729
730    fb = stw_framebuffer_from_hdc( hdc );
731    if (fb == NULL)
732       return FALSE;
733
734    return stw_framebuffer_swap_locked(hdc, fb);
735 }
736
737
738 BOOL APIENTRY
739 DrvSwapLayerBuffers(HDC hdc, UINT fuPlanes)
740 {
741    if (fuPlanes & WGL_SWAP_MAIN_PLANE)
742       return DrvSwapBuffers(hdc);
743
744    return FALSE;
745 }