stw_framebuffer.h revision 4c7001462607e6e99e474d6271dd481d3f8f201c
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 "os/os_thread.h" 34 35struct pipe_resource; 36struct st_framebuffer_iface; 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 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 67 struct st_framebuffer_iface *stfb; 68 69 /* 70 * Mutable members. 71 */ 72 73 unsigned refcnt; 74 75 76 /* FIXME: Make this work for multiple contexts bound to the same framebuffer */ 77 boolean must_resize; 78 79 unsigned width; 80 unsigned height; 81 82 /** 83 * Client area rectangle, relative to the window upper-left corner. 84 * 85 * @sa GLCBPRESENTBUFFERSDATA::rect. 86 */ 87 RECT client_rect; 88 89 HANDLE hSharedSurface; 90 struct stw_shared_surface *shared_surface; 91 92 /** 93 * This is protected by stw_device::fb_mutex, not the mutex above. 94 * 95 * Deletions must be done by first acquiring stw_device::fb_mutex, and then 96 * acquiring the stw_framebuffer::mutex of the framebuffer to be deleted. 97 * This ensures that nobody else is reading/writing to the. 98 * 99 * It is not necessary to aquire the mutex above to navigate the linked list 100 * given that deletions are done with stw_device::fb_mutex held, so no other 101 * thread can delete. 102 */ 103 struct stw_framebuffer *next; 104}; 105 106 107/** 108 * Create a new framebuffer object which will correspond to the given HDC. 109 * 110 * This function will acquire stw_framebuffer::mutex. stw_framebuffer_release 111 * must be called when done 112 */ 113struct stw_framebuffer * 114stw_framebuffer_create( 115 HDC hdc, 116 int iPixelFormat ); 117 118void 119stw_framebuffer_reference( 120 struct stw_framebuffer **ptr, 121 struct stw_framebuffer *fb); 122 123/** 124 * Search a framebuffer with a matching HWND. 125 * 126 * This function will acquire stw_framebuffer::mutex. stw_framebuffer_release 127 * must be called when done 128 */ 129struct stw_framebuffer * 130stw_framebuffer_from_hwnd( 131 HWND hwnd ); 132 133/** 134 * Search a framebuffer with a matching HDC. 135 * 136 * This function will acquire stw_framebuffer::mutex. stw_framebuffer_release 137 * must be called when done 138 */ 139struct stw_framebuffer * 140stw_framebuffer_from_hdc( 141 HDC hdc ); 142 143BOOL 144stw_framebuffer_present_locked(HDC hdc, 145 struct stw_framebuffer *fb, 146 struct pipe_resource *res); 147 148void 149stw_framebuffer_update( 150 struct stw_framebuffer *fb); 151 152/** 153 * Release stw_framebuffer::mutex lock. This framebuffer must not be accessed 154 * after calling this function, as it may have been deleted by another thread 155 * in the meanwhile. 156 */ 157void 158stw_framebuffer_release( 159 struct stw_framebuffer *fb); 160 161/** 162 * Cleanup any existing framebuffers when exiting application. 163 */ 164void 165stw_framebuffer_cleanup(void); 166 167#endif /* STW_FRAMEBUFFER_H */ 168