github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/src/runtime/ppapi/ppapi_nacl.c (about)

     1  // Copyright 2014 The Go Authors.  All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  #include "../runtime.h"
     6  #include "../cgocall.h"
     7  #include "../../cmd/ld/textflag.h"
     8  #include "ppapi_GOOS.h"
     9  
    10  typedef void *(*PPB_GetInterface)(int8 *interface_name);
    11  
    12  // PPBInterface contains the PPAPI interface name and a pointer to the PPAPI
    13  // struct containing the function pointers for that interface.
    14  struct PPBInterface {
    15  	int8 *name;
    16  	void *ppb;
    17  };
    18  
    19  typedef int32 (*PPBFunction)(uintptr arg1, uintptr arg2, uintptr arg3);
    20  
    21  // PPPInterface specifies an interface for callbacks.
    22  struct PPPInterface {
    23  	int8 *name;
    24  	PPBFunction *functions;
    25  };
    26  
    27  // ppapi·module_id is the module identifier for the process instance.
    28  int32 ppapi·module_id;
    29  
    30  #pragma dataflag NOPTR
    31  struct PPBInterface ppapi·ppb_interfaces[] = {
    32  	{ "PPB_Audio;1.1" },
    33  	{ "PPB_AudioBuffer;0.1" },
    34  	{ "PPB_AudioConfig;1.1" },
    35  	{ "PPB_Console;1.0" },
    36  	{ "PPB_Core;1.0" },
    37  	{ "PPB_FileIO;1.1" },
    38  	{ "PPB_FileMapping;0.1" },
    39  	{ "PPB_FileRef;1.2" },
    40  	{ "PPB_FileSystem;1.0" },
    41  	{ "PPB_Fullscreen;1.0" },
    42  	{ "PPB_Gamepad;1.0" },
    43  	{ "PPB_Graphics2D;1.1" },
    44  	{ "PPB_Graphics3D;1.0" },
    45  	{ "PPB_HostResolver;1.0" },
    46  	{ "PPB_ImageData;1.0" },
    47  	{ "PPB_InputEvent;1.0" },
    48  	{ "PPB_MouseInputEvent;1.1" },
    49  	{ "PPB_WheelInputEvent;1.0" },
    50  	{ "PPB_KeyboardInputEvent;1.2" },
    51  	{ "PPB_TouchInputEvent;1.0" },
    52  	{ "PPB_IMEInputEvent;1.0" },
    53  	{ "PPB_Instance;1.0" },
    54  	{ "PPB_MediaStreamAudioTrack;0.1" },
    55  	{ "PPB_MediaStreamVideoTrack;0.1" },
    56  	{ "PPB_MessageLoop;1.0" },
    57  	{ "PPB_Messaging;1.0" },
    58  	{ "PPB_MouseCursor;1.0" },
    59  	{ "PPB_MouseLock;1.0" },
    60  	{ "PPB_NetAddress;1.0" },
    61  	{ "PPB_NetworkList;1.0" },
    62  	{ "PPB_NetworkMonitor;1.0" },
    63  	{ "PPB_NetworkProxy;1.0" },
    64  	{ "PPB_OpenGLES2;1.0" },
    65  	{ "PPB_TCPSocket;1.1" },
    66  	{ "PPB_TextInputController;1.0" },
    67  	{ "PPB_UDPSocket;1.0" },
    68  	{ "PPB_URLLoader;1.0" },
    69  	{ "PPB_URLRequestInfo;1.0" },
    70  	{ "PPB_URLResponseInfo;1.0" },
    71  	{ "PPB_Var;1.2" },
    72  	{ "PPB_VarArray;1.0" },
    73  	{ "PPB_VarArrayBuffer;1.0" },
    74  	{ "PPB_VarDictionary;1.0" },
    75  	{ "PPB_VideoFrame;0.1" },
    76  	{ "PPB_View;1.1" },
    77  	{ "PPB_WebSocket;1.0" },
    78  	{ 0 },
    79  };
    80  
    81  struct pp_Var {
    82  	int32 ty;
    83  	int32 pad;
    84  	int64 value;
    85  };
    86  
    87  void ppapi·start(void *arg);
    88  void ppapi·breakpoint(void);
    89  
    90  int32 ppapi·ppp_initialize_module_handler(int32 module_id, PPBFunction get_interface);
    91  void ppapi·ppp_shutdown_module_handler(void);
    92  void ppapi·ppp_get_interface_handler(int8 *interface_name);
    93  
    94  void ppapi·ppp_graphics3d_context_lost(int32 instance);
    95  int32 ppapi·ppp_handle_input_event(int32 instance, int32 event);
    96  int32 ppapi·ppp_did_create(int32 instance, int32 argc, int8 **argn, int8 **argv);
    97  void ppapi·ppp_did_destroy(int32 instance);
    98  void ppapi·ppp_did_change_view(int32 instance, int32 view);
    99  void ppapi·ppp_did_change_focus(int32 instance, int32 has_focus);
   100  int32 ppapi·ppp_handle_document_load(int32 instance, int32 url_loader);
   101  void ppapi·ppp_handle_message(int32 instance, struct pp_Var msg);
   102  void ppapi·ppp_mouse_lock_lost(int32 instance);
   103  void *ppapi·get_array_output_buffer(void *data, uint32 count, uint32 size);
   104  
   105  // PPP_Graphics3D callbacks.
   106  #pragma dataflag NOPTR
   107  static PPBFunction ppapi·ppp_graphics_3d[] = {
   108  	(PPBFunction) ppapi·ppp_graphics3d_context_lost,
   109  };
   110  
   111  // PPP_InputEvent callbacks.
   112  #pragma dataflag NOPTR
   113  static PPBFunction ppapi·ppp_input_event[] = {
   114  	(PPBFunction) ppapi·ppp_handle_input_event,
   115  };
   116  
   117  // PPP_Instance callbacks.
   118  #pragma dataflag NOPTR
   119  static PPBFunction ppapi·ppp_instance[] = {
   120  	(PPBFunction) ppapi·ppp_did_create,
   121  	(PPBFunction) ppapi·ppp_did_destroy,
   122  	(PPBFunction) ppapi·ppp_did_change_view,
   123  	(PPBFunction) ppapi·ppp_did_change_focus,
   124  	(PPBFunction) ppapi·ppp_handle_document_load,
   125  };
   126  
   127  // PPP_Messaging callbacks.
   128  #pragma dataflag NOPTR
   129  static PPBFunction ppapi·ppp_messaging[] = {
   130  	(PPBFunction) ppapi·ppp_handle_message,
   131  };
   132  
   133  // PPP_MouseLock callbacks.
   134  #pragma dataflag NOPTR
   135  static PPBFunction ppapi·ppp_mouse_lock[] = {
   136  	(PPBFunction) ppapi·ppp_mouse_lock_lost,
   137  };
   138  
   139  #pragma dataflag NOPTR
   140  static struct PPPInterface ppapi·ppp_interfaces[] = {
   141  	{ "PPP_Graphics_3D;1.0", ppapi·ppp_graphics_3d },
   142  	{ "PPP_InputEvent;0.1",  ppapi·ppp_input_event },
   143  	{ "PPP_Instance;1.1",    ppapi·ppp_instance },
   144  	{ "PPP_Messaging;1.0",   ppapi·ppp_messaging },
   145  	{ "PPP_MouseLock;1.0",   ppapi·ppp_mouse_lock },
   146  	{ 0 },
   147  };
   148  
   149  #pragma dataflag NOPTR
   150  PPBFunction ppapi·pp_start_functions[] = {
   151  	(PPBFunction) ppapi·ppp_initialize_module_handler,
   152  	(PPBFunction) ppapi·ppp_shutdown_module_handler,
   153  	(PPBFunction) ppapi·ppp_get_interface_handler,
   154  };
   155  
   156  #pragma textflag NOSPLIT
   157  void *ppapi·ppp_get_interface(int8 *interface_name) {
   158  	struct PPPInterface *intf;
   159  	for (intf = ppapi·ppp_interfaces; intf->name != 0; intf++) {
   160  		if (runtime·strcmp((byte *) intf->name, (byte *) interface_name) == 0) {
   161  			return intf->functions;
   162  		}
   163  	}
   164  	return 0;
   165  }
   166  
   167  // C array allocator.
   168  struct ppapi·ArrayOutput {
   169  	void *(*get_data_buffer)(void *user_data, uint32 count, uint32 size);
   170  	void *user_data;
   171  };
   172  
   173  #pragma textflag NOSPLIT
   174  void ·init_array_output(struct ppapi·ArrayOutput *aout, void *alloc) {
   175  	aout->get_data_buffer = ppapi·get_array_output_buffer;
   176  	aout->user_data = alloc;
   177  }