1 /**************************************************************************
3 * Copyright 2008 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #ifndef STW_FRAMEBUFFER_H
29 #define STW_FRAMEBUFFER_H
34 #include <GL/wglext.h>
36 #include "util/u_debug.h"
41 struct pipe_frontend_drawable;
42 struct stw_pixelformat_info;
43 struct pipe_frontend_screen;
45 enum stw_framebuffer_owner
47 /* WGL window framebuffers have no corresponding destroy, and therefore
48 * a window hook is needed to clean them up.
50 STW_FRAMEBUFFER_WGL_WINDOW,
51 /* PBuffers behave like WGL window framebuffers, except that the window
52 * lifetime is managed by us. We can explicitly clean up the window.
54 STW_FRAMEBUFFER_PBUFFER,
55 /* EGL window framebuffers do have a corresponding destroy, so they don't
56 * need to be registered in the global framebuffer list. This means they
57 * will only be cleaned up from a destroy, and don't need to live until the
60 STW_FRAMEBUFFER_EGL_WINDOW,
64 * Windows framebuffer.
66 struct stw_framebuffer
69 * This mutex has two purposes:
70 * - protect the access to the mutable data members below
71 * - prevent the framebuffer from being deleted while being accessed.
73 * Note: if both this mutex and the stw_device::fb_mutex need to be locked,
74 * the stw_device::fb_mutex needs to be locked first.
76 CRITICAL_SECTION mutex;
81 * Note that even access to immutable members implies acquiring the mutex
82 * above, to prevent the framebuffer from being destroyed.
87 const struct stw_pixelformat_info *pfi;
89 /* A pixel format that can be used by GDI */
90 int iDisplayablePixelFormat;
91 enum stw_framebuffer_owner owner;
93 struct pipe_frontend_drawable *drawable;
102 /* FIXME: Make this work for multiple contexts bound to the same framebuffer */
105 boolean minimized; /**< Is the window currently minimized? */
110 /** WGL_ARB_render_texture - set at Pbuffer creation time */
111 unsigned textureFormat; /**< WGL_NO_TEXTURE or WGL_TEXTURE_RGB[A]_ARB */
112 unsigned textureTarget; /**< WGL_NO_TEXTURE or WGL_TEXTURE_1D/2D/
114 boolean textureMipmap; /**< TRUE/FALSE */
115 /** WGL_ARB_render_texture - set with wglSetPbufferAttribARB() */
116 unsigned textureLevel;
117 unsigned textureFace; /**< [0..6] */
120 * Client area rectangle, relative to the window upper-left corner.
122 * @sa GLCBPRESENTBUFFERSDATA::rect.
126 HANDLE hSharedSurface;
127 struct stw_shared_surface *shared_surface;
129 struct stw_winsys_framebuffer *winsys_framebuffer;
131 /* For WGL_EXT_swap_control */
133 int64_t prev_swap_time;
136 * This is protected by stw_device::fb_mutex, not the mutex above.
138 * Deletions must be done by first acquiring stw_device::fb_mutex, and then
139 * acquiring the stw_framebuffer::mutex of the framebuffer to be deleted.
140 * This ensures that nobody else is reading/writing to the.
142 * It is not necessary to acquire the mutex above to navigate the linked list
143 * given that deletions are done with stw_device::fb_mutex held, so no other
146 struct stw_framebuffer *next;
150 * Create a new framebuffer object which will correspond to the given HDC.
152 * This function will acquire stw_framebuffer::mutex. stw_framebuffer_unlock
153 * must be called when done
155 struct stw_framebuffer *
156 stw_framebuffer_create(HWND hwnd, const struct stw_pixelformat_info *pfi, enum stw_framebuffer_owner owner,
157 struct pipe_frontend_screen *fscreen);
159 struct stw_framebuffer *
160 stw_pbuffer_create(const struct stw_pixelformat_info *pfi, int iWidth, int iHeight, struct pipe_frontend_screen *fscreen);
164 * Increase fb reference count. The referenced framebuffer should be locked.
166 * It's not necessary to hold stw_dev::fb_mutex global lock.
169 stw_framebuffer_reference_locked(struct stw_framebuffer *fb);
173 stw_framebuffer_release_locked(struct stw_framebuffer *fb,
174 struct st_context *st);
177 * Search a framebuffer with a matching HWND.
179 * This function will acquire stw_framebuffer::mutex. stw_framebuffer_unlock
180 * must be called when done
182 struct stw_framebuffer *
183 stw_framebuffer_from_hwnd(HWND hwnd);
186 * Search a framebuffer with a matching HDC.
188 * This function will acquire stw_framebuffer::mutex. stw_framebuffer_unlock
189 * must be called when done
191 struct stw_framebuffer *
192 stw_framebuffer_from_hdc(HDC hdc);
195 stw_framebuffer_present_locked(HDC hdc,
196 struct stw_framebuffer *fb,
197 struct pipe_resource *res);
200 stw_framebuffer_update(struct stw_framebuffer *fb);
203 stw_framebuffer_swap_locked(HDC hdc, struct stw_framebuffer *fb);
207 stw_framebuffer_lock(struct stw_framebuffer *fb)
210 EnterCriticalSection(&fb->mutex);
215 * Release stw_framebuffer::mutex lock. This framebuffer must not be accessed
216 * after calling this function, as it may have been deleted by another thread
220 stw_framebuffer_unlock(struct stw_framebuffer *fb);
224 * Cleanup any existing framebuffers when exiting application.
227 stw_framebuffer_cleanup(void);
230 static inline struct stw_st_framebuffer *
231 stw_st_framebuffer(struct pipe_frontend_drawable *drawable)
233 return (struct stw_st_framebuffer *) drawable;
237 static inline struct stw_framebuffer *
238 stw_framebuffer_from_HPBUFFERARB(HPBUFFERARB hPbuffer)
240 return (struct stw_framebuffer *) hPbuffer;
244 #endif /* STW_FRAMEBUFFER_H */