xref: /aosp_15_r20/external/mesa3d/src/gallium/targets/d3d10umd/d3d10_gdi.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /**************************************************************************
2  *
3  * Copyright 2012-2021 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 #include "util/u_debug.h"
31 #include "target-helpers/inline_debug_helper.h"
32 #include "llvmpipe/lp_public.h"
33 #include "softpipe/sp_public.h"
34 #include "sw/gdi/gdi_sw_winsys.h"
35 
36 #include "winddk_compat.h"
37 #include <d3dkmthk.h>
38 
39 extern struct pipe_screen *
40 d3d10_create_screen(void);
41 
d3d10_gdi_acquire_hdc(void * winsys_drawable_handle)42 HDC d3d10_gdi_acquire_hdc(void *winsys_drawable_handle) {
43    D3DKMT_PRESENT *pPresentInfo = (D3DKMT_PRESENT *)winsys_drawable_handle;
44 
45    HWND hWnd = pPresentInfo->hWindow;
46    return GetDC(hWnd);
47 }
48 
d3d10_gdi_release_hdc(void * winsys_drawable_handle,HDC hDC)49 void d3d10_gdi_release_hdc(void *winsys_drawable_handle, HDC hDC) {
50    D3DKMT_PRESENT *pPresentInfo = (D3DKMT_PRESENT *)winsys_drawable_handle;
51 
52    HWND hWnd = pPresentInfo->hWindow;
53    ReleaseDC(hWnd, hDC);
54 }
55 
56 struct pipe_screen *
d3d10_create_screen(void)57 d3d10_create_screen(void)
58 {
59    const char *default_driver;
60    const char *driver;
61    struct pipe_screen *screen = NULL;
62    struct sw_winsys *winsys;
63 
64    winsys = gdi_create_sw_winsys(d3d10_gdi_acquire_hdc, d3d10_gdi_release_hdc);
65    if(!winsys)
66       goto no_winsys;
67 
68 #ifdef GALLIUM_LLVMPIPE
69    default_driver = "llvmpipe";
70 #else
71    default_driver = "softpipe";
72 #endif
73 
74    driver = debug_get_option("GALLIUM_DRIVER", default_driver);
75 
76 #ifdef GALLIUM_LLVMPIPE
77    if (strcmp(driver, "llvmpipe") == 0) {
78       screen = llvmpipe_create_screen( winsys );
79    }
80 #else
81    (void)driver;
82 #endif
83 
84    if (screen == NULL) {
85       screen = softpipe_create_screen( winsys );
86    }
87 
88    if (screen == NULL)
89       goto no_screen;
90 
91    return debug_screen_wrap( screen );
92 
93 no_screen:
94    winsys->destroy(winsys);
95 no_winsys:
96    return NULL;
97 }
98