| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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_MAIN_PPAPI_INSTANCE_H_ | |
| 6 #define PPAPI_MAIN_PPAPI_INSTANCE_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "ppapi/c/pp_instance.h" | |
| 11 #include "ppapi/cpp/fullscreen.h" | |
| 12 #include "ppapi/cpp/instance.h" | |
| 13 #include "ppapi/cpp/message_loop.h" | |
| 14 #include "ppapi/cpp/mouse_lock.h" | |
| 15 | |
| 16 #include "ppapi/utility/completion_callback_factory.h" | |
| 17 | |
| 18 #include "ppapi_main/ppapi_event.h" | |
| 19 #include "ppapi_main/ppapi_queue.h" | |
| 20 | |
| 21 | |
| 22 typedef std::map<std::string, std::string> PropertyMap_t; | |
| 23 | |
| 24 class PPAPIInstance : public pp::Instance { | |
| 25 public: | |
| 26 PPAPIInstance(PP_Instance instance, const char *args[]); | |
| 27 virtual ~PPAPIInstance(); | |
| 28 | |
| 29 // | |
| 30 // Callback functions triggered by Pepepr | |
| 31 // | |
| 32 | |
| 33 // Called by the browser when the NaCl module is loaded and all ready to go. | |
| 34 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]); | |
| 35 | |
| 36 // Called whenever the in-browser window changes size. | |
| 37 virtual void DidChangeView(const pp::View& view); | |
| 38 | |
| 39 // Called by the browser when the NaCl canvas gets or loses focus. | |
| 40 virtual void DidChangeFocus(bool has_focus); | |
| 41 | |
| 42 // Called by the browser to handle the postMessage() call in Javascript. | |
| 43 virtual void HandleMessage(const pp::Var& message); | |
| 44 | |
| 45 // Called by the browser to handle incoming input events. | |
| 46 virtual bool HandleInputEvent(const pp::InputEvent& event); | |
| 47 | |
| 48 // Called when the graphics flush completes | |
| 49 virtual void Flushed(int result); | |
| 50 | |
| 51 // Called when we need to rebuild the Graphics device context. This usually | |
| 52 // happens as a result of DidChangeView. | |
| 53 virtual void BuildContext(int32_t result, const pp::Size& new_size); | |
| 54 | |
| 55 // Called with the current graphics context, current size and width, when | |
| 56 // the application is ready to render, either due to a newly build | |
| 57 // Context, or a successful Flush of the previous frame. | |
| 58 virtual void Render(PP_Resource ctx, uint32_t width, uint32_t height); | |
| 59 | |
| 60 // | |
| 61 // Thread entry points | |
| 62 // | |
| 63 virtual int MainThread(int argc, const char* argv[]); | |
| 64 virtual void* EventThread(); | |
| 65 | |
| 66 // | |
| 67 // Request API | |
| 68 // | |
| 69 bool ToggleFullscreen(); | |
| 70 virtual PPAPIEvent* AcquireInputEvent(); | |
| 71 virtual void ReleaseInputEvent(PPAPIEvent* event); | |
| 72 static PPAPIInstance* GetInstance(); | |
| 73 | |
| 74 protected: | |
| 75 // Called to run ppapi_main. | |
| 76 static void* MainThreadThunk(void *start_info); | |
| 77 | |
| 78 // Called if message processing and rendering happens off the main thread. | |
| 79 static void* EventThreadThunk(void *this_ptr); | |
| 80 | |
| 81 // Called by Init to processes default and embed tag arguments prior to | |
| 82 // launching the 'ppapi_main' thread. | |
| 83 virtual bool ProcessProperties(); | |
| 84 | |
| 85 // Returns value based on KEY or default. | |
| 86 const char* GetProperty(const char* key, const char* def = NULL); | |
| 87 | |
| 88 protected: | |
| 89 pp::MessageLoop main_loop_; | |
| 90 pp::Fullscreen fullscreen_; | |
| 91 pp::MessageLoop render_loop_; | |
| 92 pp::CompletionCallbackFactory<PPAPIInstance> callback_factory_; | |
| 93 | |
| 94 PropertyMap_t properties_; | |
| 95 PPAPIQueue event_queue_; | |
| 96 | |
| 97 pp::Size size_; | |
| 98 bool has_focus_; | |
| 99 bool is_context_bound_; | |
| 100 bool was_fullscreen_; | |
| 101 bool mouse_locked_; | |
| 102 bool use_main_thread_; | |
| 103 }; | |
| 104 | |
| 105 | |
| 106 #endif // PPAPI_MAIN_PPAPI_INSTANCE_H_ | |
| OLD | NEW |