107 行
2.7 KiB

  1. // Copyright (c) 2011 The Native Client Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #pragma once
  5. #include <ppapi/cpp/instance.h>
  6. #include <ppapi/c/ppb_gamepad.h>
  7. #include <ppapi/cpp/input_event.h>
  8. #include "platform/nacl/opengl_context.h"
  9. #include "platform/nacl/opengl_context_ptrs.h"
  10. #include "input/input.h"
  11. #include "input/input_internal.h"
  12. namespace lol {
  13. class NaClInputData
  14. {
  15. friend class NaClInstance;
  16. private:
  17. void Tick(float seconds);
  18. bool IsViewportSizeValid() { return (m_app.x > 0.f && m_app.y > 0.f && m_screen.x > 0.f && m_screen.y > 0.f); }
  19. void InitViewportSize();
  20. static void SetMousePos(ivec2 position);
  21. NaClInputData()
  22. : m_mousecapture(false)
  23. {
  24. InitViewportSize();
  25. }
  26. array<class pp::InputEvent> m_input_events;
  27. class InputDeviceInternal* m_mouse;
  28. class InputDeviceInternal* m_keyboard;
  29. vec2 m_app;
  30. vec2 m_screen;
  31. bool m_mousecapture;
  32. };
  33. class NaClInstance : public pp::Instance
  34. {
  35. public:
  36. explicit NaClInstance(PP_Instance instance);
  37. // The dtor makes the 3D context current before deleting the cube view, then
  38. // destroys the 3D context both in the module and in the browser.
  39. virtual ~NaClInstance();
  40. // Called by the browser when the NaCl module is loaded and all ready to go.
  41. virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]);
  42. // Called whenever the in-browser window changes size.
  43. virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip);
  44. // Called by the browser to handle the postMessage() call in Javascript.
  45. virtual void HandleMessage(const pp::Var& message);
  46. // Bind and publish the module's methods to JavaScript.
  47. //void InitializeMethods(ScriptingBridge* bridge);
  48. // Called to draw the contents of the module's browser area.
  49. virtual bool HandleInputEvent(const pp::InputEvent& event);
  50. void DrawSelf();
  51. /* Communication with the application object */
  52. static void MainSignal();
  53. private:
  54. SharedOpenGLContext m_opengl_ctx;
  55. ivec2 m_size;
  56. static void TickCallback(void* data, int32_t result);
  57. static void * MainRun(void *data);
  58. /* Gamepad support */
  59. PPB_Gamepad const *m_pad_interface;
  60. //12/09/2013 : Should use new system.
  61. NaClInputData *m_input_data;
  62. /* Communication with the application object */
  63. struct Args
  64. {
  65. Args(int argc, char **argv, char **env)
  66. : m_argc(argc), m_argv(argv), m_env(env) {}
  67. Args() {}
  68. int m_argc;
  69. char **m_argv;
  70. char **m_env;
  71. };
  72. static mutex main_mutex;
  73. static queue<Args *, 1> main_queue;
  74. Thread *m_main_thread;
  75. };
  76. } // namespace lol