entry_nacl.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright 2011-2013 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #include <bx/bx.h>
  6. #if BX_PLATFORM_NACL
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <pthread.h>
  10. #include <ppapi/c/pp_errors.h>
  11. #include <ppapi/c/pp_module.h>
  12. #include <ppapi/c/ppb.h>
  13. #include <ppapi/c/ppb_graphics_3d.h>
  14. #include <ppapi/c/ppb_instance.h>
  15. #include <ppapi/c/ppp.h>
  16. #include <ppapi/c/ppp_instance.h>
  17. #include <ppapi/gles2/gl2ext_ppapi.h>
  18. #include <bgfxplatform.h>
  19. #include "dbg.h"
  20. #include "entry.h"
  21. namespace entry
  22. {
  23. const Event* poll()
  24. {
  25. return NULL;
  26. }
  27. void release(const Event* _event)
  28. {
  29. }
  30. void setWindowSize(uint32_t _width, uint32_t _height)
  31. {
  32. }
  33. void toggleWindowFrame()
  34. {
  35. }
  36. void setMouseLock(bool _lock)
  37. {
  38. }
  39. } // namespace entry
  40. extern int _main_(int _argc, char** _argv);
  41. static void* _entry_(void*)
  42. {
  43. const char* argv[1] = { "nacl.nexe" };
  44. _main_(1, const_cast<char**>(argv) );
  45. return NULL;
  46. }
  47. struct NaclContext
  48. {
  49. NaclContext()
  50. : m_thread(0)
  51. {
  52. }
  53. const PPB_Instance* m_instInterface;
  54. const PPB_Graphics3D* m_graphicsInterface;
  55. pthread_t m_thread;
  56. PP_Module m_module;
  57. PP_Instance m_instance;
  58. };
  59. static NaclContext s_ctx;
  60. static PP_Bool naclInstanceDidCreate(PP_Instance _instance, uint32_t _argc, const char* _argn[], const char* _argv[])
  61. {
  62. s_ctx.m_instance = _instance;
  63. bgfx::naclSetIntefraces(s_ctx.m_instance, s_ctx.m_instInterface, s_ctx.m_graphicsInterface, NULL);
  64. pthread_create(&s_ctx.m_thread, NULL, _entry_, NULL);
  65. return PP_TRUE;
  66. }
  67. static void naclInstanceDidDestroy(PP_Instance _instance)
  68. {
  69. if (s_ctx.m_thread)
  70. {
  71. pthread_join(s_ctx.m_thread, NULL);
  72. }
  73. }
  74. static void naclInstanceDidChangeView(PP_Instance _instance, PP_Resource _view)
  75. {
  76. }
  77. static void naclInstanceDidChangeFocus(PP_Instance _instance, PP_Bool _focus)
  78. {
  79. }
  80. static PP_Bool naclInstanceHandleDocumentLoad(PP_Instance _instance, PP_Resource _urlLoader)
  81. {
  82. return PP_FALSE;
  83. }
  84. PP_EXPORT const void* PPP_GetInterface(const char* _name)
  85. {
  86. if (0 == strcmp(_name, PPP_INSTANCE_INTERFACE) )
  87. {
  88. static PPP_Instance instanceInterface =
  89. {
  90. &naclInstanceDidCreate,
  91. &naclInstanceDidDestroy,
  92. &naclInstanceDidChangeView,
  93. &naclInstanceDidChangeFocus,
  94. &naclInstanceHandleDocumentLoad,
  95. };
  96. return &instanceInterface;
  97. }
  98. return NULL;
  99. }
  100. template<typename Type>
  101. bool initializeInterface(const Type*& _result, PPB_GetInterface _interface, const char* _name)
  102. {
  103. _result = reinterpret_cast<const Type*>(_interface(_name) );
  104. return NULL != _result;
  105. }
  106. PP_EXPORT int32_t PPP_InitializeModule(PP_Module _module, PPB_GetInterface _interface)
  107. {
  108. s_ctx.m_module = _module;
  109. bool result = true;
  110. result &= initializeInterface(s_ctx.m_instInterface, _interface, PPB_INSTANCE_INTERFACE);
  111. result &= initializeInterface(s_ctx.m_graphicsInterface, _interface, PPB_GRAPHICS_3D_INTERFACE);
  112. result &= glInitializePPAPI(_interface);
  113. return result ? PP_OK : PP_ERROR_NOINTERFACE;
  114. }
  115. PP_EXPORT void PPP_ShutdownModule()
  116. {
  117. }
  118. #endif // BX_PLATFROM_NACL