softpipe: rework to use the llvmpipe winsys
[mesa.git] / src / gallium / winsys / gdi / gdi_softpipe_winsys.c
1 /**************************************************************************
2 *
3 * Copyright 2009 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 * LLVMpipe support.
32 *
33 * @author Jose Fonseca <jfonseca@vmware.com>
34 */
35
36
37 #include <windows.h>
38
39 #include "gdi_winsys.h"
40 #include "softpipe/sp_texture.h"
41
42
43 static struct pipe_screen *
44 gdi_softpipe_screen_create(void)
45 {
46 static struct softpipe_winsys *winsys;
47 struct pipe_screen *screen;
48
49 winsys = gdi_create_sw_winsys();
50 if(!winsys)
51 goto no_winsys;
52
53 screen = softpipe_create_screen(winsys);
54 if(!screen)
55 goto no_screen;
56
57 return screen;
58
59 no_screen:
60 FREE(winsys);
61 no_winsys:
62 return NULL;
63 }
64
65
66
67
68 static void
69 gdi_softpipe_present(struct pipe_screen *screen,
70 struct pipe_surface *surface,
71 HDC hDC)
72 {
73 struct softpipe_texture *texture;
74 struct gdi_softpipe_displaytarget *gdt;
75
76 texture = softpipe_texture(surface->texture);
77 gdt = gdi_softpipe_displaytarget(texture->dt);
78
79 StretchDIBits(hDC,
80 0, 0, gdt->width, gdt->height,
81 0, 0, gdt->width, gdt->height,
82 gdt->data, &gdt->bmi, 0, SRCCOPY);
83 }
84
85
86 static const struct stw_winsys stw_winsys = {
87 &gdi_softpipe_screen_create,
88 &gdi_softpipe_present,
89 NULL, /* get_adapter_luid */
90 NULL, /* shared_surface_open */
91 NULL, /* shared_surface_close */
92 NULL /* compose */
93 };
94
95
96 BOOL WINAPI
97 DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
98 {
99 switch (fdwReason) {
100 case DLL_PROCESS_ATTACH:
101 stw_init(&stw_winsys);
102 stw_init_thread();
103 break;
104
105 case DLL_THREAD_ATTACH:
106 stw_init_thread();
107 break;
108
109 case DLL_THREAD_DETACH:
110 stw_cleanup_thread();
111 break;
112
113 case DLL_PROCESS_DETACH:
114 stw_cleanup_thread();
115 stw_cleanup();
116 break;
117 }
118 return TRUE;
119 }