Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: ppapi/examples/gamepad/gamepad.cc

Issue 9566022: Rename NaCl/pepper gamepad interface from _dev to stable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/c/ppb_gamepad.h ('k') | ppapi/native_client/src/shared/ppapi_proxy/browser_globals.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/dev/ppb_console_dev.h"
10 #include "ppapi/c/dev/ppb_gamepad_dev.h" 10 #include "ppapi/c/ppb_gamepad.h"
11 #include "ppapi/c/ppb_input_event.h" 11 #include "ppapi/c/ppb_input_event.h"
12 #include "ppapi/cpp/completion_callback.h" 12 #include "ppapi/cpp/completion_callback.h"
13 #include "ppapi/cpp/graphics_2d.h" 13 #include "ppapi/cpp/graphics_2d.h"
14 #include "ppapi/cpp/image_data.h" 14 #include "ppapi/cpp/image_data.h"
15 #include "ppapi/cpp/input_event.h" 15 #include "ppapi/cpp/input_event.h"
16 #include "ppapi/cpp/instance.h" 16 #include "ppapi/cpp/instance.h"
17 #include "ppapi/cpp/logging.h" 17 #include "ppapi/cpp/logging.h"
18 #include "ppapi/cpp/module.h" 18 #include "ppapi/cpp/module.h"
19 #include "ppapi/cpp/rect.h" 19 #include "ppapi/cpp/rect.h"
20 #include "ppapi/cpp/var.h" 20 #include "ppapi/cpp/var.h"
(...skipping 17 matching lines...) Expand all
38 explicit MyInstance(PP_Instance instance) 38 explicit MyInstance(PP_Instance instance)
39 : pp::Instance(instance), 39 : pp::Instance(instance),
40 width_(0), 40 width_(0),
41 height_(0), 41 height_(0),
42 callback_factory_(this), 42 callback_factory_(this),
43 gamepad_(NULL) { 43 gamepad_(NULL) {
44 } 44 }
45 virtual ~MyInstance() {} 45 virtual ~MyInstance() {}
46 46
47 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { 47 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
48 gamepad_ = reinterpret_cast<const PPB_Gamepad_Dev*>( 48 gamepad_ = reinterpret_cast<const PPB_Gamepad*>(
49 pp::Module::Get()->GetBrowserInterface(PPB_GAMEPAD_DEV_INTERFACE)); 49 pp::Module::Get()->GetBrowserInterface(PPB_GAMEPAD_INTERFACE));
50 if (!gamepad_) 50 if (!gamepad_)
51 return false; 51 return false;
52 return true; 52 return true;
53 } 53 }
54 54
55 virtual void DidChangeView(const pp::View& view) { 55 virtual void DidChangeView(const pp::View& view) {
56 pp::Rect rect = view.GetRect(); 56 pp::Rect rect = view.GetRect();
57 if (rect.size().width() == width_ && 57 if (rect.size().width() == width_ &&
58 rect.size().height() == height_) 58 rect.size().height() == height_)
59 return; // We don't care about the position, only the size. 59 return; // We don't care about the position, only the size.
(...skipping 22 matching lines...) Expand all
82 } else { 82 } else {
83 printf("NullImage\n"); 83 printf("NullImage\n");
84 } 84 }
85 } 85 }
86 86
87 pp::ImageData PaintImage(const pp::Size& size) { 87 pp::ImageData PaintImage(const pp::Size& size) {
88 pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, size, false); 88 pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, size, false);
89 if (image.is_null()) 89 if (image.is_null())
90 return image; 90 return image;
91 91
92 PP_GamepadsSampleData_Dev gamepad_data; 92 PP_GamepadsSampleData gamepad_data;
93 gamepad_->Sample(pp_instance(), &gamepad_data); 93 gamepad_->Sample(pp_instance(), &gamepad_data);
94 94
95 if (gamepad_data.length > 1 && gamepad_data.items[0].connected) { 95 if (gamepad_data.length > 1 && gamepad_data.items[0].connected) {
96 int width2 = size.width() / 2; 96 int width2 = size.width() / 2;
97 int height2 = size.height() / 2; 97 int height2 = size.height() / 2;
98 // Draw 2 axes 98 // Draw 2 axes
99 for (size_t i = 0; i < gamepad_data.items[0].axes_length; i += 2) { 99 for (size_t i = 0; i < gamepad_data.items[0].axes_length; i += 2) {
100 int x = static_cast<int>( 100 int x = static_cast<int>(
101 gamepad_data.items[0].axes[i + 0] * width2 + width2); 101 gamepad_data.items[0].axes[i + 0] * width2 + width2);
102 int y = static_cast<int>( 102 int y = static_cast<int>(
(...skipping 11 matching lines...) Expand all
114 } 114 }
115 } 115 }
116 return image; 116 return image;
117 } 117 }
118 118
119 int width_; 119 int width_;
120 int height_; 120 int height_;
121 121
122 pp::CompletionCallbackFactory<MyInstance> callback_factory_; 122 pp::CompletionCallbackFactory<MyInstance> callback_factory_;
123 123
124 const PPB_Gamepad_Dev* gamepad_; 124 const PPB_Gamepad* gamepad_;
125 125
126 pp::Graphics2D device_context_; 126 pp::Graphics2D device_context_;
127 }; 127 };
128 128
129 // This object is the global object representing this plugin library as long 129 // This object is the global object representing this plugin library as long
130 // as it is loaded. 130 // as it is loaded.
131 class MyModule : public pp::Module { 131 class MyModule : public pp::Module {
132 public: 132 public:
133 MyModule() : pp::Module() {} 133 MyModule() : pp::Module() {}
134 virtual ~MyModule() {} 134 virtual ~MyModule() {}
135 135
136 // Override CreateInstance to create your customized Instance object. 136 // Override CreateInstance to create your customized Instance object.
137 virtual pp::Instance* CreateInstance(PP_Instance instance) { 137 virtual pp::Instance* CreateInstance(PP_Instance instance) {
138 return new MyInstance(instance); 138 return new MyInstance(instance);
139 } 139 }
140 }; 140 };
141 141
142 namespace pp { 142 namespace pp {
143 143
144 // Factory function for your specialization of the Module object. 144 // Factory function for your specialization of the Module object.
145 Module* CreateModule() { 145 Module* CreateModule() {
146 return new MyModule(); 146 return new MyModule();
147 } 147 }
148 148
149 } // namespace pp 149 } // namespace pp
150 150
OLDNEW
« no previous file with comments | « ppapi/c/ppb_gamepad.h ('k') | ppapi/native_client/src/shared/ppapi_proxy/browser_globals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698