1 /*
2 * Copyright © Microsoft Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "state_tracker/st_interop.h"
25 #include "stw_ext_interop.h"
26
27 #include "stw_context.h"
28 #include "stw_device.h"
29
30 int
wglMesaGLInteropQueryDeviceInfo(HDC dpy,HGLRC context,struct mesa_glinterop_device_info * out)31 wglMesaGLInteropQueryDeviceInfo(HDC dpy, HGLRC context,
32 struct mesa_glinterop_device_info *out)
33 {
34 DHGLRC dhglrc = 0;
35
36 if (stw_dev && stw_dev->callbacks.pfnGetDhglrc) {
37 /* Convert HGLRC to DHGLRC */
38 dhglrc = stw_dev->callbacks.pfnGetDhglrc(context);
39 } else {
40 /* not using ICD */
41 dhglrc = (DHGLRC)(INT_PTR)context;
42 }
43
44 struct stw_context *ctx = stw_lookup_context(dhglrc);
45 if (!ctx)
46 return MESA_GLINTEROP_INVALID_CONTEXT;
47
48 return stw_interop_query_device_info(ctx, out);
49 }
50
51 int
stw_interop_query_device_info(struct stw_context * ctx,struct mesa_glinterop_device_info * out)52 stw_interop_query_device_info(struct stw_context *ctx,
53 struct mesa_glinterop_device_info *out)
54 {
55 return st_interop_query_device_info(ctx->st, out);
56 }
57
58 int
wglMesaGLInteropExportObject(HDC dpy,HGLRC context,struct mesa_glinterop_export_in * in,struct mesa_glinterop_export_out * out)59 wglMesaGLInteropExportObject(HDC dpy, HGLRC context,
60 struct mesa_glinterop_export_in *in,
61 struct mesa_glinterop_export_out *out)
62 {
63 DHGLRC dhglrc = 0;
64
65 if (stw_dev && stw_dev->callbacks.pfnGetDhglrc) {
66 /* Convert HGLRC to DHGLRC */
67 dhglrc = stw_dev->callbacks.pfnGetDhglrc(context);
68 } else {
69 /* not using ICD */
70 dhglrc = (DHGLRC)(INT_PTR)context;
71 }
72
73 struct stw_context *ctx = stw_lookup_context(dhglrc);
74 if (!ctx)
75 return MESA_GLINTEROP_INVALID_CONTEXT;
76
77 return stw_interop_export_object(ctx, in, out);
78 }
79
80 int
stw_interop_export_object(struct stw_context * ctx,struct mesa_glinterop_export_in * in,struct mesa_glinterop_export_out * out)81 stw_interop_export_object(struct stw_context *ctx,
82 struct mesa_glinterop_export_in *in,
83 struct mesa_glinterop_export_out *out)
84 {
85 return st_interop_export_object(ctx->st, in, out);
86 }
87
88 int
wglMesaGLInteropFlushObjects(HDC dpy,HGLRC context,unsigned count,struct mesa_glinterop_export_in * resources,struct mesa_glinterop_flush_out * out)89 wglMesaGLInteropFlushObjects(HDC dpy, HGLRC context,
90 unsigned count, struct mesa_glinterop_export_in *resources,
91 struct mesa_glinterop_flush_out *out)
92 {
93 DHGLRC dhglrc = 0;
94
95 if (stw_dev && stw_dev->callbacks.pfnGetDhglrc) {
96 /* Convert HGLRC to DHGLRC */
97 dhglrc = stw_dev->callbacks.pfnGetDhglrc(context);
98 } else {
99 /* not using ICD */
100 dhglrc = (DHGLRC)(INT_PTR)context;
101 }
102
103 struct stw_context *ctx = stw_lookup_context(dhglrc);
104 if (!ctx)
105 return MESA_GLINTEROP_INVALID_CONTEXT;
106
107 return stw_interop_flush_objects(ctx, count, resources, out);
108 }
109
110 int
stw_interop_flush_objects(struct stw_context * ctx,unsigned count,struct mesa_glinterop_export_in * objects,struct mesa_glinterop_flush_out * out)111 stw_interop_flush_objects(struct stw_context *ctx,
112 unsigned count, struct mesa_glinterop_export_in *objects,
113 struct mesa_glinterop_flush_out *out)
114 {
115 return st_interop_flush_objects(ctx->st, count, objects, out);
116 }
117
118