1 /**************************************************************************
3 * Copyright 2009-2010 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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
27 **************************************************************************/
31 * Softpipe/LLVMpipe support.
33 * @author Jose Fonseca <jfonseca@vmware.com>
39 #include "util/u_debug.h"
40 #include "stw_winsys.h"
41 #include "stw_device.h"
42 #include "gdi/gdi_sw_winsys.h"
44 #include "softpipe/sp_texture.h"
45 #include "softpipe/sp_screen.h"
46 #include "softpipe/sp_public.h"
49 #include "llvmpipe/lp_texture.h"
50 #include "llvmpipe/lp_screen.h"
51 #include "llvmpipe/lp_public.h"
55 #include "swr/swr_public.h"
58 static boolean use_llvmpipe
= FALSE
;
59 static boolean use_swr
= FALSE
;
61 static struct pipe_screen
*
62 gdi_screen_create(void)
64 const char *default_driver
;
66 struct pipe_screen
*screen
= NULL
;
67 struct sw_winsys
*winsys
;
69 winsys
= gdi_create_sw_winsys();
74 default_driver
= "llvmpipe";
76 default_driver
= "swr";
78 default_driver
= "softpipe";
81 driver
= debug_get_option("GALLIUM_DRIVER", default_driver
);
84 if (strcmp(driver
, "llvmpipe") == 0) {
85 screen
= llvmpipe_create_screen( winsys
);
91 if (strcmp(driver
, "swr") == 0) {
92 screen
= swr_create_screen( winsys
);
100 screen
= softpipe_create_screen( winsys
);
109 winsys
->destroy(winsys
);
116 gdi_present(struct pipe_screen
*screen
,
117 struct pipe_resource
*res
,
120 /* This will fail if any interposing layer (trace, debug, etc) has
121 * been introduced between the state-trackers and the pipe driver.
123 * Ideally this would get replaced with a call to
124 * pipe_screen::flush_frontbuffer().
126 * Failing that, it may be necessary for intervening layers to wrap
127 * other structs such as this stw_winsys as well...
130 struct sw_winsys
*winsys
= NULL
;
131 struct sw_displaytarget
*dt
= NULL
;
135 winsys
= llvmpipe_screen(screen
)->winsys
;
136 dt
= llvmpipe_resource(res
)->dt
;
137 gdi_sw_display(winsys
, dt
, hDC
);
144 swr_gdi_swap(screen
, res
, hDC
);
149 winsys
= softpipe_screen(screen
)->winsys
,
150 dt
= softpipe_resource(res
)->dt
,
151 gdi_sw_display(winsys
, dt
, hDC
);
155 static const struct stw_winsys stw_winsys
= {
158 NULL
, /* get_adapter_luid */
159 NULL
, /* shared_surface_open */
160 NULL
, /* shared_surface_close */
166 DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
);
170 DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
173 case DLL_PROCESS_ATTACH
:
174 stw_init(&stw_winsys
);
178 case DLL_THREAD_ATTACH
:
182 case DLL_THREAD_DETACH
:
183 stw_cleanup_thread();
186 case DLL_PROCESS_DETACH
:
187 if (lpvReserved
== NULL
) {
188 // We're being unloaded from the process.
189 stw_cleanup_thread();
192 // Process itself is terminating, and all threads and modules are
195 // The order threads (including llvmpipe rasterizer threads) are
196 // destroyed can not be relied up, so it's not safe to cleanup.
198 // However global destructors (e.g., LLVM's) will still be called, and
199 // if Microsoft OPENGL32.DLL's DllMain is called after us, it will
200 // still try to invoke DrvDeleteContext to destroys all outstanding,
201 // so set stw_dev to NULL to return immediately if that happens.