xref: /aosp_15_r20/external/mesa3d/src/glx/apple/apple_glapi.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * GLX implementation that uses Apple's OpenGL.framework
3  *
4  * Copyright (c) 2007-2011 Apple Inc.
5  * Copyright (c) 2004 Torrey T. Lyons. All Rights Reserved.
6  * Copyright (c) 2002 Greg Parker. All Rights Reserved.
7  *
8  * Portions of this file are copied from Mesa's xf86glx.c,
9  * which contains the following copyright:
10  *
11  * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
12  * All Rights Reserved.
13  *
14  * Permission is hereby granted, free of charge, to any person obtaining a
15  * copy of this software and associated documentation files (the "Software"),
16  * to deal in the Software without restriction, including without limitation
17  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18  * and/or sell copies of the Software, and to permit persons to whom the
19  * Software is furnished to do so, subject to the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be included in
22  * all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27  * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
28  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
29  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30  * DEALINGS IN THE SOFTWARE.
31  */
32 
33 #include <assert.h>
34 #include <dlfcn.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <stdio.h>
38 
39 #include <GL/gl.h>
40 
41 #include "glapi.h"
42 #include "glapitable.h"
43 
44 #include "apple_glx.h"
45 #include "apple_xgl_api.h"
46 #include "apple_cgl.h"
47 
48 struct _glapi_table * __ogl_framework_api = NULL;
49 struct _glapi_table * __applegl_api = NULL;
50 
_apple_glapi_create_table(void)51 static void _apple_glapi_create_table(void) {
52     if (__applegl_api)
53         return;
54 
55     __ogl_framework_api = _glapi_create_table_from_handle(apple_cgl_get_dl_handle(), "gl");
56     assert(__ogl_framework_api);
57 
58     __applegl_api = malloc(sizeof(struct _glapi_table));
59     assert(__applegl_api);
60     memcpy(__applegl_api, __ogl_framework_api, sizeof(struct _glapi_table));
61 
62     _glapi_table_patch(__applegl_api, "ReadPixels", __applegl_glReadPixels);
63     _glapi_table_patch(__applegl_api, "CopyPixels", __applegl_glCopyPixels);
64     _glapi_table_patch(__applegl_api, "CopyColorTable", __applegl_glCopyColorTable);
65     _glapi_table_patch(__applegl_api, "DrawBuffers", __applegl_glDrawBuffer);
66     _glapi_table_patch(__applegl_api, "Viewport", __applegl_glViewport);
67 }
68 
apple_glapi_set_dispatch(void)69 void apple_glapi_set_dispatch(void) {
70     _apple_glapi_create_table();
71     _glapi_set_dispatch(__applegl_api);
72 }
73 
apple_glapi_oglfw_viewport_scissor(GLint x,GLint y,GLsizei width,GLsizei height)74 void apple_glapi_oglfw_viewport_scissor(GLint x, GLint y, GLsizei width, GLsizei height) {
75     _apple_glapi_create_table();
76     __ogl_framework_api->Viewport(x, y, width, height);
77     __ogl_framework_api->Scissor(x, y, width, height);
78 }
79