freedreno/a4xx: frag-depth fixes
[mesa.git] / src / gallium / targets / libgl-gdi / libgl_gdi.c
1 /**************************************************************************
2 *
3 * Copyright 2009-2010 VMware, Inc.
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 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.
21 *
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
24 * of the Software.
25 *
26 *
27 **************************************************************************/
28
29 /**
30 * @file
31 * Softpipe/LLVMpipe support.
32 *
33 * @author Jose Fonseca <jfonseca@vmware.com>
34 */
35
36
37 #include <windows.h>
38
39 #include "util/u_debug.h"
40 #include "stw_winsys.h"
41 #include "gdi/gdi_sw_winsys.h"
42
43 #include "softpipe/sp_texture.h"
44 #include "softpipe/sp_screen.h"
45 #include "softpipe/sp_public.h"
46
47 #ifdef HAVE_LLVMPIPE
48 #include "llvmpipe/lp_texture.h"
49 #include "llvmpipe/lp_screen.h"
50 #include "llvmpipe/lp_public.h"
51 #endif
52
53
54 static boolean use_llvmpipe = FALSE;
55
56
57 static struct pipe_screen *
58 gdi_screen_create(void)
59 {
60 const char *default_driver;
61 const char *driver;
62 struct pipe_screen *screen = NULL;
63 struct sw_winsys *winsys;
64
65 winsys = gdi_create_sw_winsys();
66 if(!winsys)
67 goto no_winsys;
68
69 #ifdef HAVE_LLVMPIPE
70 default_driver = "llvmpipe";
71 #else
72 default_driver = "softpipe";
73 #endif
74
75 driver = debug_get_option("GALLIUM_DRIVER", default_driver);
76
77 #ifdef HAVE_LLVMPIPE
78 if (strcmp(driver, "llvmpipe") == 0) {
79 screen = llvmpipe_create_screen( winsys );
80 }
81 #else
82 (void) driver;
83 #endif
84
85 if (screen == NULL) {
86 screen = softpipe_create_screen( winsys );
87 } else {
88 use_llvmpipe = TRUE;
89 }
90
91 if(!screen)
92 goto no_screen;
93
94 return screen;
95
96 no_screen:
97 winsys->destroy(winsys);
98 no_winsys:
99 return NULL;
100 }
101
102
103 static void
104 gdi_present(struct pipe_screen *screen,
105 struct pipe_resource *res,
106 HDC hDC)
107 {
108 /* This will fail if any interposing layer (trace, debug, etc) has
109 * been introduced between the state-trackers and the pipe driver.
110 *
111 * Ideally this would get replaced with a call to
112 * pipe_screen::flush_frontbuffer().
113 *
114 * Failing that, it may be necessary for intervening layers to wrap
115 * other structs such as this stw_winsys as well...
116 */
117
118 struct sw_winsys *winsys = NULL;
119 struct sw_displaytarget *dt = NULL;
120
121 #ifdef HAVE_LLVMPIPE
122 if (use_llvmpipe) {
123 winsys = llvmpipe_screen(screen)->winsys;
124 dt = llvmpipe_resource(res)->dt;
125 gdi_sw_display(winsys, dt, hDC);
126 return;
127 }
128 #endif
129
130 winsys = softpipe_screen(screen)->winsys,
131 dt = softpipe_resource(res)->dt,
132 gdi_sw_display(winsys, dt, hDC);
133 }
134
135
136 static const struct stw_winsys stw_winsys = {
137 &gdi_screen_create,
138 &gdi_present,
139 NULL, /* get_adapter_luid */
140 NULL, /* shared_surface_open */
141 NULL, /* shared_surface_close */
142 NULL /* compose */
143 };
144
145
146 BOOL WINAPI
147 DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
148 {
149 switch (fdwReason) {
150 case DLL_PROCESS_ATTACH:
151 stw_init(&stw_winsys);
152 stw_init_thread();
153 break;
154
155 case DLL_THREAD_ATTACH:
156 stw_init_thread();
157 break;
158
159 case DLL_THREAD_DETACH:
160 stw_cleanup_thread();
161 break;
162
163 case DLL_PROCESS_DETACH:
164 if (lpReserved == NULL) {
165 stw_cleanup_thread();
166 stw_cleanup();
167 }
168 break;
169 }
170 return TRUE;
171 }