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

Side by Side Diff: ppapi/shared_impl/ppb_gamepad_shared.cc

Issue 1136463002: Pass correct length value in WebGamepads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
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 "ppapi/shared_impl/ppb_gamepad_shared.h" 5 #include "ppapi/shared_impl/ppb_gamepad_shared.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 8
9 namespace ppapi { 9 namespace ppapi {
10 10
11 void ConvertWebKitGamepadData(const WebKitGamepads& webkit_data, 11 void ConvertWebKitGamepadData(const WebKitGamepads& webkit_data,
12 PP_GamepadsSampleData* output_data) { 12 PP_GamepadsSampleData* output_data) {
13 output_data->length = webkit_data.length; 13 output_data->length = (webkit_data.length < WebKitGamepads::kItemsLengthCap) ?
14 for (unsigned i = 0; i < webkit_data.length; ++i) { 14 webkit_data.length : WebKitGamepads::kItemsLengthCap;
arajp 2015/05/07 12:19:54 Added this for safety.
bbudge 2015/05/07 13:58:57 std::min(webkit_data.length, WebKitGamepads::kItem
arajp 2015/05/08 06:03:20 Done.
15 for (unsigned i = 0; i < output_data->length; ++i) {
15 PP_GamepadSampleData& output_pad = output_data->items[i]; 16 PP_GamepadSampleData& output_pad = output_data->items[i];
16 const WebKitGamepad& webkit_pad = webkit_data.items[i]; 17 const WebKitGamepad& webkit_pad = webkit_data.items[i];
17 output_pad.connected = webkit_pad.connected ? PP_TRUE : PP_FALSE; 18 output_pad.connected = webkit_pad.connected ? PP_TRUE : PP_FALSE;
18 if (webkit_pad.connected) { 19 if (webkit_pad.connected) {
19 static_assert(sizeof(output_pad.id) == sizeof(webkit_pad.id), 20 static_assert(sizeof(output_pad.id) == sizeof(webkit_pad.id),
20 "id size does not match"); 21 "id size does not match");
21 memcpy(output_pad.id, webkit_pad.id, sizeof(output_pad.id)); 22 memcpy(output_pad.id, webkit_pad.id, sizeof(output_pad.id));
22 output_pad.timestamp = static_cast<double>(webkit_pad.timestamp); 23 output_pad.timestamp = static_cast<double>(webkit_pad.timestamp);
23 output_pad.axes_length = webkit_pad.axes_length; 24 output_pad.axes_length = webkit_pad.axes_length;
24 for (unsigned j = 0; j < webkit_pad.axes_length; ++j) 25 for (unsigned j = 0; j < webkit_pad.axes_length; ++j)
25 output_pad.axes[j] = static_cast<float>(webkit_pad.axes[j]); 26 output_pad.axes[j] = static_cast<float>(webkit_pad.axes[j]);
26 output_pad.buttons_length = webkit_pad.buttons_length; 27 output_pad.buttons_length = webkit_pad.buttons_length;
27 for (unsigned j = 0; j < webkit_pad.buttons_length; ++j) 28 for (unsigned j = 0; j < webkit_pad.buttons_length; ++j)
28 output_pad.buttons[j] = static_cast<float>(webkit_pad.buttons[j].value); 29 output_pad.buttons[j] = static_cast<float>(webkit_pad.buttons[j].value);
29 } 30 }
30 } 31 }
31 } 32 }
32 33
33 } // namespace ppapi 34 } // namespace ppapi
OLDNEW
« ppapi/examples/gamepad/gamepad.cc ('K') | « ppapi/examples/gamepad/gamepad.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698