stw_framebuffer.h revision 4e5ed05b025b9b6a1a6dabba72fce3d918e77044
1/**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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#ifndef STW_FRAMEBUFFER_H
29#define STW_FRAMEBUFFER_H
30
31#include <windows.h>
32
33#include "main/mtypes.h"
34
35#include "pipe/p_thread.h"
36
37struct stw_pixelformat_info;
38
39/**
40 * Windows framebuffer, derived from gl_framebuffer.
41 */
42struct stw_framebuffer
43{
44   /**
45    * This mutex has two purposes:
46    * - protect the access to the mutable data members below
47    * - prevent the the framebuffer from being deleted while being accessed.
48    *
49    * It is OK to lock this mutex while holding the stw_device::fb_mutex lock,
50    * but the opposite must never happen.
51    */
52   pipe_mutex mutex;
53
54   /*
55    * Immutable members.
56    *
57    * Note that even access to immutable members implies acquiring the mutex
58    * above, to prevent the framebuffer from being destroyed.
59    */
60
61   HDC hDC;
62   HWND hWnd;
63
64   int iPixelFormat;
65   const struct stw_pixelformat_info *pfi;
66   GLvisual visual;
67
68   /*
69    * Mutable members.
70    */
71
72   struct st_framebuffer *stfb;
73
74   /* FIXME: Make this work for multiple contexts bound to the same framebuffer */
75   boolean must_resize;
76
77   unsigned width;
78   unsigned height;
79
80   /**
81    * Client area rectangle, relative to the window upper-left corner.
82    *
83    * @sa GLCBPRESENTBUFFERSDATA::rect.
84    */
85   RECT client_rect;
86
87   HANDLE hSharedSurface;
88   struct stw_shared_surface *shared_surface;
89
90   /**
91    * This is protected by stw_device::fb_mutex, not the mutex above.
92    *
93    * Deletions must be done by first acquiring stw_device::fb_mutex, and then
94    * acquiring the stw_framebuffer::mutex of the framebuffer to be deleted.
95    * This ensures that nobody else is reading/writing to the.
96    *
97    * It is not necessary to aquire the mutex above to navigate the linked list
98    * given that deletions are done with stw_device::fb_mutex held, so no other
99    * thread can delete.
100    */
101   struct stw_framebuffer *next;
102};
103
104
105/**
106 * Create a new framebuffer object which will correspond to the given HDC.
107 *
108 * This function will acquire stw_framebuffer::mutex. stw_framebuffer_release
109 * must be called when done
110 */
111struct stw_framebuffer *
112stw_framebuffer_create(
113   HDC hdc,
114   int iPixelFormat );
115
116/**
117 * Search a framebuffer with a matching HWND.
118 *
119 * This function will acquire stw_framebuffer::mutex. stw_framebuffer_release
120 * must be called when done
121 */
122struct stw_framebuffer *
123stw_framebuffer_from_hwnd(
124   HWND hwnd );
125
126/**
127 * Search a framebuffer with a matching HDC.
128 *
129 * This function will acquire stw_framebuffer::mutex. stw_framebuffer_release
130 * must be called when done
131 */
132struct stw_framebuffer *
133stw_framebuffer_from_hdc(
134   HDC hdc );
135
136BOOL
137stw_framebuffer_allocate(
138   struct stw_framebuffer *fb );
139
140BOOL
141stw_framebuffer_present_locked(HDC hdc,
142                               struct stw_framebuffer *fb,
143                               unsigned surface_index);
144
145void
146stw_framebuffer_update(
147   struct stw_framebuffer *fb);
148
149/**
150 * Release stw_framebuffer::mutex lock. This framebuffer must not be accessed
151 * after calling this function, as it may have been deleted by another thread
152 * in the meanwhile.
153 */
154void
155stw_framebuffer_release(
156   struct stw_framebuffer *fb);
157
158/**
159 * Cleanup any existing framebuffers when exiting application.
160 */
161void
162stw_framebuffer_cleanup(void);
163
164#endif /* STW_FRAMEBUFFER_H */
165