Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
|
binji
2013/05/23 18:06:49
2013
noelallen1
2013/05/23 22:01:24
Done.
| |
| 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_PPAPI_SIMPLE_INSTANCE_H_ | |
| 6 #define PPAPI_SIMPLE_PPAPI_SIMPLE_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/ppapi_event.h" | |
| 24 #include "ppapi_simple/ppapi_simple_main.h" | |
| 25 | |
| 26 #include "utils/pointer_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 PS_SILENT_VERBOSITY, | |
| 35 PS_ERROR_VERBOSITY, | |
| 36 PS_WARN_VERBOSITY, | |
| 37 PS_LOG_VERBOSITY, | |
| 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[]); | |
| 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* AcquireEvent(bool block); | |
|
binji
2013/05/23 18:06:49
use an enum for this, it's clearer at the call sit
noelallen1
2013/05/23 22:01:24
Done.
| |
| 71 void ReleaseEvent(PSEvent* event); | |
| 72 // | |
| 73 protected: | |
| 74 // | |
| 75 // Callback functions triggered by Pepepr | |
| 76 // | |
| 77 // These functions are called on the main pepper thread, so they must | |
| 78 // not block. | |
| 79 // | |
| 80 // Called by the browser when the NaCl module is loaded and all ready to go. | |
| 81 // This function will create a new thread which will run the pseudo main. | |
| 82 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]); | |
| 83 | |
| 84 // Called whenever the in-browser window changes size, it will pass a | |
| 85 // context change request to whichever thread is handling rendering. | |
| 86 virtual void DidChangeView(const pp::View& view); | |
| 87 | |
| 88 // Called by the browser when the NaCl canvas gets or loses focus. | |
| 89 virtual void DidChangeFocus(bool has_focus); | |
| 90 | |
| 91 // Called by the browser to handle the postMessage() call in Javascript. | |
| 92 virtual void HandleMessage(const pp::Var& message); | |
| 93 | |
| 94 // Called by the browser to handle incoming input events. Events are Q'd | |
| 95 // and can later be processed on a sperate processing thread. | |
| 96 virtual bool HandleInputEvent(const pp::InputEvent& event); | |
| 97 | |
| 98 // Called by Init to processes default and embed tag arguments prior to | |
| 99 // launching the 'ppapi_main' thread. | |
| 100 virtual bool ProcessProperties(); | |
| 101 | |
| 102 static void* MainThreadThunk(void *start_info); | |
| 103 | |
| 104 | |
| 105 protected: | |
| 106 pp::MessageLoop* main_loop_; | |
| 107 | |
| 108 PropertyMap_t properties_; | |
| 109 PointerQueue<PSEvent> event_queue_; | |
| 110 uint32_t events_enabled_; | |
| 111 uint32_t verbosity_; | |
| 112 | |
| 113 PSMainFunc_t main_cb_; | |
| 114 | |
| 115 const PPB_Core* ppb_core_; | |
| 116 const PPB_Var* ppb_var_; | |
| 117 const PPB_View* ppb_view_; | |
| 118 }; | |
| 119 | |
| 120 #endif // PPAPI_MAIN_PPAPI_INSTANCE_H_ | |
| 121 | |
| OLD | NEW |