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

Side by Side Diff: native_client_sdk/src/examples/gamepad/gamepad.cc

Issue 9405033: Revise gamepad interface (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 | « no previous file | ppapi/api/dev/ppb_gamepad_dev.idl » ('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 Native Client Authors. All rights reserved. 1 // Copyright (c) 2012 The Native Client 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 "gamepad.h" 5 #include "gamepad.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <cassert> 9 #include <cassert>
10 #include <cmath> 10 #include <cmath>
11 #include <cstring> 11 #include <cstring>
12 #include <string> 12 #include <string>
13 #include "ppapi/c/dev/ppb_gamepad_dev.h"
13 #include "ppapi/cpp/completion_callback.h" 14 #include "ppapi/cpp/completion_callback.h"
14 #include "ppapi/cpp/var.h" 15 #include "ppapi/cpp/var.h"
15 16
16 namespace { 17 namespace {
17 18
18 // This is called by the browser when the 2D context has been flushed to the 19 // This is called by the browser when the 2D context has been flushed to the
19 // browser window. 20 // browser window.
20 void FlushCallback(void* data, int32_t result) { 21 void FlushCallback(void* data, int32_t result) {
21 static_cast<gamepad::Gamepad*>(data)->set_flush_pending(false); 22 static_cast<gamepad::Gamepad*>(data)->set_flush_pending(false);
22 static_cast<gamepad::Gamepad*>(data)->Paint(); 23 static_cast<gamepad::Gamepad*>(data)->Paint();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 x++) 77 x++)
77 *image->GetAddr32(pp::Point(x, y)) = color; 78 *image->GetAddr32(pp::Point(x, y)) = color;
78 } 79 }
79 } 80 }
80 81
81 void Gamepad::Paint() { 82 void Gamepad::Paint() {
82 // Clear the background. 83 // Clear the background.
83 FillRect(pixel_buffer_, 0, 0, width(), height(), 0xfff0f0f0); 84 FillRect(pixel_buffer_, 0, 0, width(), height(), 0xfff0f0f0);
84 85
85 // Get current gamepad data. 86 // Get current gamepad data.
86 PP_GamepadsData_Dev gamepad_data; 87 PP_GamepadsSampleData_Dev gamepad_data;
87 gamepad_->SampleGamepads(pp_instance(), &gamepad_data); 88 gamepad_->Sample(pp_instance(), &gamepad_data);
88 89
89 // Draw the current state for each connected gamepad. 90 // Draw the current state for each connected gamepad.
90 for (size_t p = 0; p < gamepad_data.length; ++p) { 91 for (size_t p = 0; p < gamepad_data.length; ++p) {
91 int width2 = width() / gamepad_data.length / 2; 92 int width2 = width() / gamepad_data.length / 2;
92 int height2 = height() / 2; 93 int height2 = height() / 2;
93 int offset = width2 * 2 * p; 94 int offset = width2 * 2 * p;
94 PP_GamepadData_Dev& pad = gamepad_data.items[p]; 95 PP_GamepadSampleData_Dev& pad = gamepad_data.items[p];
95 96
96 if (!pad.connected) 97 if (!pad.connected)
97 continue; 98 continue;
98 99
99 // Draw axes. 100 // Draw axes.
100 for (size_t i = 0; i < pad.axes_length; i += 2) { 101 for (size_t i = 0; i < pad.axes_length; i += 2) {
101 int x = static_cast<int>(pad.axes[i + 0] * width2 + width2) + offset; 102 int x = static_cast<int>(pad.axes[i + 0] * width2 + width2) + offset;
102 int y = static_cast<int>(pad.axes[i + 1] * height2 + height2); 103 int y = static_cast<int>(pad.axes[i + 1] * height2 + height2);
103 uint32_t box_bgra = 0x80000000; // Alpha 50%. 104 uint32_t box_bgra = 0x80000000; // Alpha 50%.
104 FillRect(pixel_buffer_, x - 3, y - 3, 7, 7, box_bgra); 105 FillRect(pixel_buffer_, x - 3, y - 3, 7, 7, box_bgra);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 // Note that the pixel lock is held while the buffer is copied into the 141 // Note that the pixel lock is held while the buffer is copied into the
141 // device context and then flushed. 142 // device context and then flushed.
142 graphics_2d_context_->PaintImageData(*pixel_buffer_, pp::Point()); 143 graphics_2d_context_->PaintImageData(*pixel_buffer_, pp::Point());
143 if (flush_pending()) 144 if (flush_pending())
144 return; 145 return;
145 set_flush_pending(true); 146 set_flush_pending(true);
146 graphics_2d_context_->Flush(pp::CompletionCallback(&FlushCallback, this)); 147 graphics_2d_context_->Flush(pp::CompletionCallback(&FlushCallback, this));
147 } 148 }
148 149
149 } // namespace gamepad 150 } // namespace gamepad
OLDNEW
« no previous file with comments | « no previous file | ppapi/api/dev/ppb_gamepad_dev.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698