Path: blob/21.2-virgl/src/mapi/glapi/glapi_nop.c
4560 views
/*1* Mesa 3-D graphics library2*3* Copyright (C) 1999-2008 Brian Paul All Rights Reserved.4* Copyright (C) 2010 VMware, Inc. All Rights Reserved.5*6* Permission is hereby granted, free of charge, to any person obtaining a7* copy of this software and associated documentation files (the "Software"),8* to deal in the Software without restriction, including without limitation9* the rights to use, copy, modify, merge, publish, distribute, sublicense,10* and/or sell copies of the Software, and to permit persons to whom the11* Software is furnished to do so, subject to the following conditions:12*13* The above copyright notice and this permission notice shall be included14* in all copies or substantial portions of the Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS17* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,18* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL19* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR20* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,21* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR22* OTHER DEALINGS IN THE SOFTWARE.23*/242526/**27* No-op dispatch table.28*29* This file defines a special dispatch table which is loaded with no-op30* functions.31*32* Mesa can register a "no-op handler function" which will be called in33* the event that a no-op function is called.34*35* In the past, the dispatch table was loaded with pointers to a single36* no-op function. But that broke on Windows because the GL entrypoints37* use __stdcall convention. __stdcall means the callee cleans up the38* stack. So one no-op function can't properly clean up the stack. This39* would lead to crashes.40*41* Another benefit of unique no-op functions is we can accurately report42* the function's name in an error message.43*/444546#include <stdlib.h>47#include <string.h>48#include "glapi/glapi_priv.h"495051void52_glapi_noop_enable_warnings(unsigned char enable)53{54}5556void57_glapi_set_warning_func(_glapi_proc func)58{59}606162/**63* We'll jump though this function pointer whenever a no-op function64* is called.65*/66static _glapi_nop_handler_proc nop_handler = NULL;676869/**70* Register the no-op handler call-back function.71*/72void73_glapi_set_nop_handler(_glapi_nop_handler_proc func)74{75nop_handler = func;76}777879/**80* Called by each of the no-op GL entrypoints.81*/82static void83nop(const char *func)84{85if (nop_handler)86nop_handler(func);87}888990/**91* This is called if the user somehow calls an unassigned GL dispatch function.92*/93static GLint94NoOpUnused(void)95{96nop("unused GL entry point");97return 0;98}99100/*101* Defines for the glapitemp.h functions.102*/103#define KEYWORD1 static104#define KEYWORD1_ALT static105#define KEYWORD2 GLAPIENTRY106#define NAME(func) NoOp##func107#define DISPATCH(func, args, msg) nop(#func);108#define RETURN_DISPATCH(func, args, msg) nop(#func); return 0109110111/*112* Defines for the table of no-op entry points.113*/114#define TABLE_ENTRY(name) (_glapi_proc) NoOp##name115#define DISPATCH_TABLE_NAME __glapi_noop_table116#define UNUSED_TABLE_NAME __unused_noop_functions117118#include "glapitemp.h"119120121/** Return pointer to new dispatch table filled with no-op functions */122struct _glapi_table *123_glapi_new_nop_table(unsigned num_entries)124{125struct _glapi_table *table = malloc(num_entries * sizeof(_glapi_proc));126if (table) {127memcpy(table, __glapi_noop_table,128num_entries * sizeof(_glapi_proc));129}130return table;131}132133134