xref: /third_party/mesa3d/src/mapi/glapi/glapi_nop.c (revision bf215546)
1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Mesa 3-D graphics library
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
5bf215546Sopenharmony_ci * Copyright (C) 2010  VMware, Inc.  All Rights Reserved.
6bf215546Sopenharmony_ci *
7bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
8bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
9bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
10bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
12bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included
15bf215546Sopenharmony_ci * in all copies or substantial portions of the Software.
16bf215546Sopenharmony_ci *
17bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21bf215546Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23bf215546Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
24bf215546Sopenharmony_ci */
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci/**
28bf215546Sopenharmony_ci * No-op dispatch table.
29bf215546Sopenharmony_ci *
30bf215546Sopenharmony_ci * This file defines a special dispatch table which is loaded with no-op
31bf215546Sopenharmony_ci * functions.
32bf215546Sopenharmony_ci *
33bf215546Sopenharmony_ci * Mesa can register a "no-op handler function" which will be called in
34bf215546Sopenharmony_ci * the event that a no-op function is called.
35bf215546Sopenharmony_ci *
36bf215546Sopenharmony_ci * In the past, the dispatch table was loaded with pointers to a single
37bf215546Sopenharmony_ci * no-op function.  But that broke on Windows because the GL entrypoints
38bf215546Sopenharmony_ci * use __stdcall convention.  __stdcall means the callee cleans up the
39bf215546Sopenharmony_ci * stack.  So one no-op function can't properly clean up the stack.  This
40bf215546Sopenharmony_ci * would lead to crashes.
41bf215546Sopenharmony_ci *
42bf215546Sopenharmony_ci * Another benefit of unique no-op functions is we can accurately report
43bf215546Sopenharmony_ci * the function's name in an error message.
44bf215546Sopenharmony_ci */
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_ci#include <stdlib.h>
48bf215546Sopenharmony_ci#include <string.h>
49bf215546Sopenharmony_ci#include "glapi/glapi_priv.h"
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ci
52bf215546Sopenharmony_civoid
53bf215546Sopenharmony_ci_glapi_noop_enable_warnings(unsigned char enable)
54bf215546Sopenharmony_ci{
55bf215546Sopenharmony_ci}
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_civoid
58bf215546Sopenharmony_ci_glapi_set_warning_func(_glapi_proc func)
59bf215546Sopenharmony_ci{
60bf215546Sopenharmony_ci}
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ci/**
64bf215546Sopenharmony_ci * We'll jump though this function pointer whenever a no-op function
65bf215546Sopenharmony_ci * is called.
66bf215546Sopenharmony_ci */
67bf215546Sopenharmony_cistatic _glapi_nop_handler_proc nop_handler = NULL;
68bf215546Sopenharmony_ci
69bf215546Sopenharmony_ci
70bf215546Sopenharmony_ci/**
71bf215546Sopenharmony_ci * Register the no-op handler call-back function.
72bf215546Sopenharmony_ci */
73bf215546Sopenharmony_civoid
74bf215546Sopenharmony_ci_glapi_set_nop_handler(_glapi_nop_handler_proc func)
75bf215546Sopenharmony_ci{
76bf215546Sopenharmony_ci   nop_handler = func;
77bf215546Sopenharmony_ci}
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci
80bf215546Sopenharmony_ci/**
81bf215546Sopenharmony_ci * Called by each of the no-op GL entrypoints.
82bf215546Sopenharmony_ci */
83bf215546Sopenharmony_cistatic void
84bf215546Sopenharmony_cinop(const char *func)
85bf215546Sopenharmony_ci{
86bf215546Sopenharmony_ci   if (nop_handler)
87bf215546Sopenharmony_ci      nop_handler(func);
88bf215546Sopenharmony_ci}
89bf215546Sopenharmony_ci
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_ci/**
92bf215546Sopenharmony_ci * This is called if the user somehow calls an unassigned GL dispatch function.
93bf215546Sopenharmony_ci */
94bf215546Sopenharmony_cistatic GLint
95bf215546Sopenharmony_ciNoOpUnused(void)
96bf215546Sopenharmony_ci{
97bf215546Sopenharmony_ci   nop("unused GL entry point");
98bf215546Sopenharmony_ci   return 0;
99bf215546Sopenharmony_ci}
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_ci/*
102bf215546Sopenharmony_ci * Defines for the glapitemp.h functions.
103bf215546Sopenharmony_ci */
104bf215546Sopenharmony_ci#define KEYWORD1 static
105bf215546Sopenharmony_ci#define KEYWORD1_ALT static
106bf215546Sopenharmony_ci#define KEYWORD2 GLAPIENTRY
107bf215546Sopenharmony_ci#define NAME(func)  NoOp##func
108bf215546Sopenharmony_ci#define DISPATCH(func, args, msg)  nop(#func);
109bf215546Sopenharmony_ci#define RETURN_DISPATCH(func, args, msg)  nop(#func); return 0
110bf215546Sopenharmony_ci
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_ci/*
113bf215546Sopenharmony_ci * Defines for the table of no-op entry points.
114bf215546Sopenharmony_ci */
115bf215546Sopenharmony_ci#define TABLE_ENTRY(name) (_glapi_proc) NoOp##name
116bf215546Sopenharmony_ci#define DISPATCH_TABLE_NAME __glapi_noop_table
117bf215546Sopenharmony_ci#define UNUSED_TABLE_NAME __unused_noop_functions
118bf215546Sopenharmony_ci
119bf215546Sopenharmony_ci#include "glapitemp.h"
120bf215546Sopenharmony_ci
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_ci/** Return pointer to new dispatch table filled with no-op functions */
123bf215546Sopenharmony_cistruct _glapi_table *
124bf215546Sopenharmony_ci_glapi_new_nop_table(unsigned num_entries)
125bf215546Sopenharmony_ci{
126bf215546Sopenharmony_ci   struct _glapi_table *table = malloc(num_entries * sizeof(_glapi_proc));
127bf215546Sopenharmony_ci   if (table) {
128bf215546Sopenharmony_ci      memcpy(table, __glapi_noop_table,
129bf215546Sopenharmony_ci             num_entries * sizeof(_glapi_proc));
130bf215546Sopenharmony_ci   }
131bf215546Sopenharmony_ci   return table;
132bf215546Sopenharmony_ci}
133