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 static boolean use_llvmpipe
= FALSE
;
58 static struct pipe_screen
*
59 gdi_screen_create(void)
61 const char *default_driver
;
63 struct pipe_screen
*screen
= NULL
;
64 struct sw_winsys
*winsys
;
66 winsys
= gdi_create_sw_winsys();
71 default_driver
= "llvmpipe";
73 default_driver
= "softpipe";
76 driver
= debug_get_option("GALLIUM_DRIVER", default_driver
);
79 if (strcmp(driver
, "llvmpipe") == 0) {
80 screen
= llvmpipe_create_screen( winsys
);
87 screen
= softpipe_create_screen( winsys
);
98 winsys
->destroy(winsys
);
105 gdi_present(struct pipe_screen
*screen
,
106 struct pipe_resource
*res
,
109 /* This will fail if any interposing layer (trace, debug, etc) has
110 * been introduced between the state-trackers and the pipe driver.
112 * Ideally this would get replaced with a call to
113 * pipe_screen::flush_frontbuffer().
115 * Failing that, it may be necessary for intervening layers to wrap
116 * other structs such as this stw_winsys as well...
119 struct sw_winsys
*winsys
= NULL
;
120 struct sw_displaytarget
*dt
= NULL
;
124 winsys
= llvmpipe_screen(screen
)->winsys
;
125 dt
= llvmpipe_resource(res
)->dt
;
126 gdi_sw_display(winsys
, dt
, hDC
);
131 winsys
= softpipe_screen(screen
)->winsys
,
132 dt
= softpipe_resource(res
)->dt
,
133 gdi_sw_display(winsys
, dt
, hDC
);
137 static const struct stw_winsys stw_winsys
= {
140 NULL
, /* get_adapter_luid */
141 NULL
, /* shared_surface_open */
142 NULL
, /* shared_surface_close */
148 DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
);
152 DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
155 case DLL_PROCESS_ATTACH
:
156 stw_init(&stw_winsys
);
160 case DLL_THREAD_ATTACH
:
164 case DLL_THREAD_DETACH
:
165 stw_cleanup_thread();
168 case DLL_PROCESS_DETACH
:
169 if (lpvReserved
== NULL
) {
170 // We're being unloaded from the process.
171 stw_cleanup_thread();
174 // Process itself is terminating, and all threads and modules are
177 // The order threads (including llvmpipe rasterizer threads) are
178 // destroyed can not be relied up, so it's not safe to cleanup.
180 // However global destructors (e.g., LLVM's) will still be called, and
181 // if Microsoft OPENGL32.DLL's DllMain is called after us, it will
182 // still try to invoke DrvDeleteContext to destroys all outstanding,
183 // so set stw_dev to NULL to return immediately if that happens.