OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <cmath> | 5 #include <cmath> |
6 #include <stdarg.h> | 6 #include <stdarg.h> |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include "ppapi/c/dev/ppb_console_dev.h" | 9 #include "ppapi/c/ppb_console.h" |
10 #include "ppapi/c/ppb_input_event.h" | 10 #include "ppapi/c/ppb_input_event.h" |
11 #include "ppapi/cpp/graphics_2d.h" | 11 #include "ppapi/cpp/graphics_2d.h" |
12 #include "ppapi/cpp/image_data.h" | 12 #include "ppapi/cpp/image_data.h" |
13 #include "ppapi/cpp/input_event.h" | 13 #include "ppapi/cpp/input_event.h" |
14 #include "ppapi/cpp/instance.h" | 14 #include "ppapi/cpp/instance.h" |
15 #include "ppapi/cpp/logging.h" | 15 #include "ppapi/cpp/logging.h" |
16 #include "ppapi/cpp/module.h" | 16 #include "ppapi/cpp/module.h" |
17 #include "ppapi/cpp/mouse_lock.h" | 17 #include "ppapi/cpp/mouse_lock.h" |
18 #include "ppapi/cpp/private/flash_fullscreen.h" | 18 #include "ppapi/cpp/private/flash_fullscreen.h" |
19 #include "ppapi/cpp/rect.h" | 19 #include "ppapi/cpp/rect.h" |
(...skipping 10 matching lines...) Expand all Loading... |
30 mouse_locked_(false), | 30 mouse_locked_(false), |
31 pending_paint_(false), | 31 pending_paint_(false), |
32 waiting_for_flush_completion_(false), | 32 waiting_for_flush_completion_(false), |
33 callback_factory_(this), | 33 callback_factory_(this), |
34 console_(NULL), | 34 console_(NULL), |
35 flash_fullscreen_(this) { | 35 flash_fullscreen_(this) { |
36 } | 36 } |
37 virtual ~MyInstance() {} | 37 virtual ~MyInstance() {} |
38 | 38 |
39 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { | 39 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { |
40 console_ = reinterpret_cast<const PPB_Console_Dev*>( | 40 console_ = reinterpret_cast<const PPB_Console*>( |
41 pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_DEV_INTERFACE)); | 41 pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_INTERFACE)); |
42 if (!console_) | 42 if (!console_) |
43 return false; | 43 return false; |
44 | 44 |
45 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | | 45 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | |
46 PP_INPUTEVENT_CLASS_KEYBOARD); | 46 PP_INPUTEVENT_CLASS_KEYBOARD); |
47 return true; | 47 return true; |
48 } | 48 } |
49 | 49 |
50 virtual bool HandleInputEvent(const pp::InputEvent& event) { | 50 virtual bool HandleInputEvent(const pp::InputEvent& event) { |
51 switch (event.GetType()) { | 51 switch (event.GetType()) { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 | 219 |
220 return image; | 220 return image; |
221 } | 221 } |
222 | 222 |
223 double GetDistance(int point_1_x, int point_1_y, | 223 double GetDistance(int point_1_x, int point_1_y, |
224 int point_2_x, int point_2_y) { | 224 int point_2_x, int point_2_y) { |
225 return sqrt(pow(static_cast<double>(point_1_x - point_2_x), 2) + | 225 return sqrt(pow(static_cast<double>(point_1_x - point_2_x), 2) + |
226 pow(static_cast<double>(point_1_y - point_2_y), 2)); | 226 pow(static_cast<double>(point_1_y - point_2_y), 2)); |
227 } | 227 } |
228 | 228 |
229 void Log(PP_LogLevel_Dev level, const char* format, ...) { | 229 void Log(PP_LogLevel level, const char* format, ...) { |
230 va_list args; | 230 va_list args; |
231 va_start(args, format); | 231 va_start(args, format); |
232 char buf[512]; | 232 char buf[512]; |
233 vsnprintf(buf, sizeof(buf) - 1, format, args); | 233 vsnprintf(buf, sizeof(buf) - 1, format, args); |
234 buf[sizeof(buf) - 1] = '\0'; | 234 buf[sizeof(buf) - 1] = '\0'; |
235 va_end(args); | 235 va_end(args); |
236 | 236 |
237 pp::Var value(buf); | 237 pp::Var value(buf); |
238 console_->Log(pp_instance(), level, value.pp_var()); | 238 console_->Log(pp_instance(), level, value.pp_var()); |
239 } | 239 } |
240 | 240 |
241 int width_; | 241 int width_; |
242 int height_; | 242 int height_; |
243 | 243 |
244 bool mouse_locked_; | 244 bool mouse_locked_; |
245 pp::Point mouse_movement_; | 245 pp::Point mouse_movement_; |
246 | 246 |
247 bool pending_paint_; | 247 bool pending_paint_; |
248 bool waiting_for_flush_completion_; | 248 bool waiting_for_flush_completion_; |
249 | 249 |
250 pp::CompletionCallbackFactory<MyInstance> callback_factory_; | 250 pp::CompletionCallbackFactory<MyInstance> callback_factory_; |
251 | 251 |
252 const PPB_Console_Dev* console_; | 252 const PPB_Console* console_; |
253 | 253 |
254 pp::FlashFullscreen flash_fullscreen_; | 254 pp::FlashFullscreen flash_fullscreen_; |
255 | 255 |
256 pp::Graphics2D device_context_; | 256 pp::Graphics2D device_context_; |
257 }; | 257 }; |
258 | 258 |
259 // This object is the global object representing this plugin library as long | 259 // This object is the global object representing this plugin library as long |
260 // as it is loaded. | 260 // as it is loaded. |
261 class MyModule : public pp::Module { | 261 class MyModule : public pp::Module { |
262 public: | 262 public: |
263 MyModule() : pp::Module() {} | 263 MyModule() : pp::Module() {} |
264 virtual ~MyModule() {} | 264 virtual ~MyModule() {} |
265 | 265 |
266 // Override CreateInstance to create your customized Instance object. | 266 // Override CreateInstance to create your customized Instance object. |
267 virtual pp::Instance* CreateInstance(PP_Instance instance) { | 267 virtual pp::Instance* CreateInstance(PP_Instance instance) { |
268 return new MyInstance(instance); | 268 return new MyInstance(instance); |
269 } | 269 } |
270 }; | 270 }; |
271 | 271 |
272 namespace pp { | 272 namespace pp { |
273 | 273 |
274 // Factory function for your specialization of the Module object. | 274 // Factory function for your specialization of the Module object. |
275 Module* CreateModule() { | 275 Module* CreateModule() { |
276 return new MyModule(); | 276 return new MyModule(); |
277 } | 277 } |
278 | 278 |
279 } // namespace pp | 279 } // namespace pp |
280 | 280 |
OLD | NEW |