Path: blob/21.2-virgl/src/gallium/frontends/wgl/stw_framebuffer.h
4561 views
/**************************************************************************1*2* Copyright 2008 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627#ifndef STW_FRAMEBUFFER_H28#define STW_FRAMEBUFFER_H2930#include <windows.h>3132#include <GL/gl.h>33#include <GL/wglext.h>3435#include "util/u_debug.h"36#include "stw_st.h"373839struct pipe_resource;40struct st_framebuffer_iface;41struct stw_pixelformat_info;4243/**44* Windows framebuffer.45*/46struct stw_framebuffer47{48/**49* This mutex has two purposes:50* - protect the access to the mutable data members below51* - prevent the framebuffer from being deleted while being accessed.52*53* Note: if both this mutex and the stw_device::fb_mutex need to be locked,54* the stw_device::fb_mutex needs to be locked first.55*/56CRITICAL_SECTION mutex;5758/*59* Immutable members.60*61* Note that even access to immutable members implies acquiring the mutex62* above, to prevent the framebuffer from being destroyed.63*/6465HWND hWnd;6667int iPixelFormat;68const struct stw_pixelformat_info *pfi;6970/* A pixel format that can be used by GDI */71int iDisplayablePixelFormat;72boolean bPbuffer;7374struct st_framebuffer_iface *stfb;7576/*77* Mutable members.78*/7980unsigned refcnt;818283/* FIXME: Make this work for multiple contexts bound to the same framebuffer */84boolean must_resize;8586boolean minimized; /**< Is the window currently minimized? */8788unsigned width;89unsigned height;9091/** WGL_ARB_render_texture - set at Pbuffer creation time */92unsigned textureFormat; /**< WGL_NO_TEXTURE or WGL_TEXTURE_RGB[A]_ARB */93unsigned textureTarget; /**< WGL_NO_TEXTURE or WGL_TEXTURE_1D/2D/94CUBE_MAP_ARB */95boolean textureMipmap; /**< TRUE/FALSE */96/** WGL_ARB_render_texture - set with wglSetPbufferAttribARB() */97unsigned textureLevel;98unsigned textureFace; /**< [0..6] */99100/**101* Client area rectangle, relative to the window upper-left corner.102*103* @sa GLCBPRESENTBUFFERSDATA::rect.104*/105RECT client_rect;106107HANDLE hSharedSurface;108struct stw_shared_surface *shared_surface;109110struct stw_winsys_framebuffer *winsys_framebuffer;111112/* For WGL_EXT_swap_control */113int64_t prev_swap_time;114115/**116* This is protected by stw_device::fb_mutex, not the mutex above.117*118* Deletions must be done by first acquiring stw_device::fb_mutex, and then119* acquiring the stw_framebuffer::mutex of the framebuffer to be deleted.120* This ensures that nobody else is reading/writing to the.121*122* It is not necessary to acquire the mutex above to navigate the linked list123* given that deletions are done with stw_device::fb_mutex held, so no other124* thread can delete.125*/126struct stw_framebuffer *next;127};128129130/**131* Create a new framebuffer object which will correspond to the given HDC.132*133* This function will acquire stw_framebuffer::mutex. stw_framebuffer_unlock134* must be called when done135*/136struct stw_framebuffer *137stw_framebuffer_create(HDC hdc, int iPixelFormat);138139140/**141* Increase fb reference count. The referenced framebuffer should be locked.142*143* It's not necessary to hold stw_dev::fb_mutex global lock.144*/145static inline void146stw_framebuffer_reference_locked(struct stw_framebuffer *fb)147{148if (fb) {149assert(stw_own_mutex(&fb->mutex));150fb->refcnt++;151}152}153154155void156stw_framebuffer_release_locked(struct stw_framebuffer *fb,157struct st_context_iface *stctx);158159/**160* Search a framebuffer with a matching HWND.161*162* This function will acquire stw_framebuffer::mutex. stw_framebuffer_unlock163* must be called when done164*/165struct stw_framebuffer *166stw_framebuffer_from_hwnd(HWND hwnd);167168/**169* Search a framebuffer with a matching HDC.170*171* This function will acquire stw_framebuffer::mutex. stw_framebuffer_unlock172* must be called when done173*/174struct stw_framebuffer *175stw_framebuffer_from_hdc(HDC hdc);176177BOOL178stw_framebuffer_present_locked(HDC hdc,179struct stw_framebuffer *fb,180struct pipe_resource *res);181182void183stw_framebuffer_update(struct stw_framebuffer *fb);184185186static inline void187stw_framebuffer_lock(struct stw_framebuffer *fb)188{189assert(fb);190EnterCriticalSection(&fb->mutex);191}192193194/**195* Release stw_framebuffer::mutex lock. This framebuffer must not be accessed196* after calling this function, as it may have been deleted by another thread197* in the meanwhile.198*/199static inline void200stw_framebuffer_unlock(struct stw_framebuffer *fb)201{202assert(fb);203assert(stw_own_mutex(&fb->mutex));204LeaveCriticalSection(&fb->mutex);205}206207208/**209* Cleanup any existing framebuffers when exiting application.210*/211void212stw_framebuffer_cleanup(void);213214215static inline struct stw_st_framebuffer *216stw_st_framebuffer(struct st_framebuffer_iface *stfb)217{218return (struct stw_st_framebuffer *) stfb;219}220221222static inline struct stw_framebuffer *223stw_framebuffer_from_HPBUFFERARB(HPBUFFERARB hPbuffer)224{225return (struct stw_framebuffer *) hPbuffer;226}227228229#endif /* STW_FRAMEBUFFER_H */230231232