Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium 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 | |
| 5 #ifndef PPAPI_SIMPLE_PS_INSTANCE_H_ | |
| 6 #define PPAPI_SIMPLE_PS_INSTANCE_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "ppapi/c/pp_instance.h" | |
| 11 #include "ppapi/c/pp_stdint.h" | |
| 12 #include "ppapi/c/ppb_core.h" | |
| 13 #include "ppapi/c/ppb_var.h" | |
| 14 #include "ppapi/c/ppb_view.h" | |
| 15 | |
| 16 #include "ppapi/cpp/fullscreen.h" | |
| 17 #include "ppapi/cpp/instance.h" | |
| 18 #include "ppapi/cpp/message_loop.h" | |
| 19 #include "ppapi/cpp/mouse_lock.h" | |
| 20 | |
| 21 #include "ppapi/utility/completion_callback_factory.h" | |
| 22 | |
| 23 #include "ppapi_simple/ps_event.h" | |
| 24 #include "ppapi_simple/ps_main.h" | |
| 25 | |
| 26 #include "utils/thread_safe_queue.h" | |
| 27 | |
| 28 | |
| 29 typedef std::map<std::string, std::string> PropertyMap_t; | |
| 30 | |
| 31 class PSInstance : public pp::Instance { | |
| 32 public: | |
| 33 enum Verbosity { | |
| 34 PSV_SILENT, | |
| 35 PSV_ERROR, | |
| 36 PSV_WARN, | |
| 37 PSV_LOG, | |
| 38 }; | |
| 39 | |
| 40 // Returns a pointer to the global instance | |
| 41 static PSInstance* GetInstance(); | |
| 42 | |
| 43 PSInstance(PP_Instance inst, const char *argv[]); | |
| 44 virtual ~PSInstance(); | |
| 45 | |
| 46 // Set a function which will be called on a new thread once initialized. | |
| 47 // NOTE: This must be called by the Factory, once Init is called, this | |
| 48 // function will have no effect. | |
| 49 void SetMain(PSMainFunc_t func); | |
| 50 | |
| 51 // Returns value based on KEY or default. | |
| 52 const char* GetProperty(const char* key, const char* def = NULL); | |
| 53 | |
| 54 // Started on Init, a thread which can be safely blocked. | |
| 55 virtual int MainThread(int argc, const char* argv[]); | |
|
binji
2013/05/30 05:07:50
private/protected? Nothing should call this except
noelallen1
2013/05/30 18:07:19
Done.
| |
| 56 | |
| 57 // Logging F | |
| 58 void SetVerbosity(Verbosity verbosity); | |
| 59 void Log(const char *fmt, ...); | |
| 60 void Warn(const char *fmt, ...); | |
| 61 void Error(const char *fmt, ...); | |
| 62 | |
| 63 // Event Functions | |
| 64 void SetEnabledEvents(uint32_t mask); | |
| 65 void PostEvent(PSEventType type); | |
| 66 void PostEvent(PSEventType type, PP_Bool bool_value); | |
| 67 void PostEvent(PSEventType type, PP_Resource resource); | |
| 68 void PostEvent(PSEventType type, const PP_Var& var); | |
| 69 | |
| 70 PSEvent* TryAcquireEvent(); | |
| 71 PSEvent* WaitAcquireEvent(); | |
| 72 void ReleaseEvent(PSEvent* event); | |
| 73 // | |
|
binji
2013/05/30 05:07:50
remove //
noelallen1
2013/05/30 18:07:19
Done.
| |
| 74 protected: | |
| 75 // | |
| 76 // Callback functions triggered by Pepepr | |
|
binji
2013/05/30 05:07:50
sp: Pepper
noelallen1
2013/05/30 18:07:19
Done.
| |
| 77 // | |
| 78 // These functions are called on the main pepper thread, so they must | |
| 79 // not block. | |
| 80 // | |
| 81 // Called by the browser when the NaCl module is loaded and all ready to go. | |
| 82 // This function will create a new thread which will run the pseudo main. | |
| 83 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]); | |
| 84 | |
| 85 // Called whenever the in-browser window changes size, it will pass a | |
| 86 // context change request to whichever thread is handling rendering. | |
| 87 virtual void DidChangeView(const pp::View& view); | |
| 88 | |
| 89 // Called by the browser when the NaCl canvas gets or loses focus. | |
| 90 virtual void DidChangeFocus(bool has_focus); | |
| 91 | |
| 92 // Called by the browser to handle the postMessage() call in Javascript. | |
| 93 virtual void HandleMessage(const pp::Var& message); | |
| 94 | |
| 95 // Called by the browser to handle incoming input events. Events are Q'd | |
| 96 // and can later be processed on a sperate processing thread. | |
| 97 virtual bool HandleInputEvent(const pp::InputEvent& event); | |
| 98 | |
| 99 // Called by Init to processes default and embed tag arguments prior to | |
| 100 // launching the 'ppapi_main' thread. | |
| 101 virtual bool ProcessProperties(); | |
| 102 | |
| 103 static void* MainThreadThunk(void *start_info); | |
| 104 | |
| 105 | |
| 106 protected: | |
| 107 pp::MessageLoop* main_loop_; | |
| 108 | |
| 109 PropertyMap_t properties_; | |
| 110 ThreadSafeQueue<PSEvent> event_queue_; | |
| 111 uint32_t events_enabled_; | |
| 112 uint32_t verbosity_; | |
|
binji
2013/05/30 05:07:50
Why not Verbosity verbosity_
noelallen1
2013/05/30 18:07:19
Done.
| |
| 113 | |
| 114 PSMainFunc_t main_cb_; | |
| 115 | |
| 116 const PPB_Core* ppb_core_; | |
| 117 const PPB_Var* ppb_var_; | |
| 118 const PPB_View* ppb_view_; | |
| 119 }; | |
| 120 | |
| 121 #endif // PPAPI_MAIN_PS_INSTANCE_H_ | |
| 122 | |
| OLD | NEW |