stw_device.c revision 0e471ac45771393ea74178eb98f41b904168cf64
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#include <windows.h> 29 30#include "pipe/p_debug.h" 31#include "pipe/p_winsys.h" 32#include "pipe/p_screen.h" 33 34#include "stw_device.h" 35#include "stw_winsys.h" 36#include "stw_pixelformat.h" 37 38 39struct stw_device *stw_dev = NULL; 40 41 42/** 43 * XXX: Dispatch pipe_winsys::flush_front_buffer to our 44 * stw_winsys::flush_front_buffer. 45 */ 46static void 47st_flush_frontbuffer(struct pipe_winsys *ws, 48 struct pipe_surface *surf, 49 void *context_private ) 50{ 51 const struct stw_winsys *stw_winsys = stw_dev->stw_winsys; 52 struct pipe_winsys *winsys = stw_dev->screen->winsys; 53 HDC hdc = (HDC)context_private; 54 55 stw_winsys->flush_frontbuffer(winsys, surf, hdc); 56} 57 58 59boolean 60st_init(const struct stw_winsys *stw_winsys) 61{ 62 static struct stw_device stw_dev_storage; 63 64 assert(!stw_dev); 65 66 stw_dev = &stw_dev_storage; 67 memset(stw_dev, 0, sizeof(*stw_dev)); 68 69 stw_dev->stw_winsys = stw_winsys; 70 71 stw_dev->screen = stw_winsys->create_screen(); 72 if(!stw_dev->screen) 73 goto error1; 74 75 /* XXX: pipe_winsys::flush_frontbuffer should go away */ 76 stw_dev->screen->winsys->flush_frontbuffer = st_flush_frontbuffer; 77 78 pixelformat_init(); 79 80 return TRUE; 81 82error1: 83 stw_dev = NULL; 84 return FALSE; 85} 86 87 88void 89st_cleanup(void) 90{ 91 DHGLRC dhglrc; 92 93 if(!stw_dev) 94 return; 95 96 /* Ensure all contexts are destroyed */ 97 for (dhglrc = 1; dhglrc <= DRV_CONTEXT_MAX; dhglrc++) 98 if (stw_dev->ctx_array[dhglrc - 1].hglrc) 99 DrvDeleteContext( dhglrc ); 100 101 stw_dev = NULL; 102} 103