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

Side by Side Diff: device/vr/android/gvr/gvr_gamepad_data_fetcher.cc

Issue 2808093006: [Device Service] Move Gamepad Blink headers to be part of the Gamepad client library (Closed)
Patch Set: rebase and address comments Created 3 years, 8 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
« no previous file with comments | « device/vr/DEPS ('k') | ppapi/shared_impl/DEPS » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "device/vr/android/gvr/gvr_gamepad_data_fetcher.h" 5 #include "device/vr/android/gvr/gvr_gamepad_data_fetcher.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "device/gamepad/public/cpp/gamepads.h"
9 #include "device/vr/android/gvr/gvr_gamepad_data_provider.h" 10 #include "device/vr/android/gvr/gvr_gamepad_data_provider.h"
10 #include "device/vr/vr_types.h" 11 #include "device/vr/vr_types.h"
11 #include "third_party/WebKit/public/platform/WebGamepads.h"
12 12
13 namespace device { 13 namespace device {
14 14
15 namespace { 15 namespace {
16 16
17 void CopyToWebUString(blink::WebUChar* dest, 17 void CopyToUString(UChar* dest, size_t dest_length, base::string16 src) {
18 size_t dest_length, 18 static_assert(sizeof(base::string16::value_type) == sizeof(UChar),
19 base::string16 src) {
20 static_assert(sizeof(base::string16::value_type) == sizeof(blink::WebUChar),
21 "Mismatched string16/WebUChar size."); 19 "Mismatched string16/WebUChar size.");
22 20
23 const size_t str_to_copy = std::min(src.size(), dest_length - 1); 21 const size_t str_to_copy = std::min(src.size(), dest_length - 1);
24 memcpy(dest, src.data(), str_to_copy * sizeof(base::string16::value_type)); 22 memcpy(dest, src.data(), str_to_copy * sizeof(base::string16::value_type));
25 dest[str_to_copy] = 0; 23 dest[str_to_copy] = 0;
26 } 24 }
27 25
28 } // namespace 26 } // namespace
29 27
30 using namespace blink;
31
32 GvrGamepadDataFetcher::Factory::Factory(GvrGamepadDataProvider* data_provider, 28 GvrGamepadDataFetcher::Factory::Factory(GvrGamepadDataProvider* data_provider,
33 unsigned int display_id) 29 unsigned int display_id)
34 : data_provider_(data_provider), display_id_(display_id) { 30 : data_provider_(data_provider), display_id_(display_id) {
35 DVLOG(1) << __FUNCTION__ << "=" << this; 31 DVLOG(1) << __FUNCTION__ << "=" << this;
36 } 32 }
37 33
38 GvrGamepadDataFetcher::Factory::~Factory() { 34 GvrGamepadDataFetcher::Factory::~Factory() {
39 DVLOG(1) << __FUNCTION__ << "=" << this; 35 DVLOG(1) << __FUNCTION__ << "=" << this;
40 } 36 }
41 37
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // Called from gamepad polling thread. 74 // Called from gamepad polling thread.
79 75
80 PadState* state = GetPadState(0); 76 PadState* state = GetPadState(0);
81 if (!state) 77 if (!state)
82 return; 78 return;
83 79
84 // Take a snapshot of the asynchronously updated gamepad data. 80 // Take a snapshot of the asynchronously updated gamepad data.
85 // TODO(bajones): ensure consistency? 81 // TODO(bajones): ensure consistency?
86 GvrGamepadData provided_data = gamepad_data_; 82 GvrGamepadData provided_data = gamepad_data_;
87 83
88 WebGamepad& pad = state->data; 84 Gamepad& pad = state->data;
89 if (state->active_state == GAMEPAD_NEWLY_ACTIVE) { 85 if (state->active_state == GAMEPAD_NEWLY_ACTIVE) {
90 // This is the first time we've seen this device, so do some one-time 86 // This is the first time we've seen this device, so do some one-time
91 // initialization 87 // initialization
92 pad.connected = true; 88 pad.connected = true;
93 CopyToWebUString(pad.id, WebGamepad::kIdLengthCap, 89 CopyToUString(pad.id, Gamepad::kIdLengthCap,
94 base::UTF8ToUTF16("Daydream Controller")); 90 base::UTF8ToUTF16("Daydream Controller"));
95 CopyToWebUString(pad.mapping, WebGamepad::kMappingLengthCap, 91 CopyToUString(pad.mapping, Gamepad::kMappingLengthCap,
96 base::UTF8ToUTF16("")); 92 base::UTF8ToUTF16(""));
97 pad.buttons_length = 1; 93 pad.buttons_length = 1;
98 pad.axes_length = 2; 94 pad.axes_length = 2;
99 95
100 pad.display_id = display_id_; 96 pad.display_id = display_id_;
101 97
102 pad.hand = 98 pad.hand =
103 provided_data.right_handed ? kGamepadHandRight : kGamepadHandLeft; 99 provided_data.right_handed ? GamepadHand::kRight : GamepadHand::kLeft;
104 } 100 }
105 101
106 pad.timestamp = provided_data.timestamp; 102 pad.timestamp = provided_data.timestamp;
107 103
108 if (provided_data.is_touching) { 104 if (provided_data.is_touching) {
109 gfx::Vector2dF touch_position = provided_data.touch_pos; 105 gfx::Vector2dF touch_position = provided_data.touch_pos;
110 pad.axes[0] = (touch_position.x() * 2.0f) - 1.0f; 106 pad.axes[0] = (touch_position.x() * 2.0f) - 1.0f;
111 pad.axes[1] = (touch_position.y() * 2.0f) - 1.0f; 107 pad.axes[1] = (touch_position.y() * 2.0f) - 1.0f;
112 } else { 108 } else {
113 pad.axes[0] = 0.0f; 109 pad.axes[0] = 0.0f;
(...skipping 24 matching lines...) Expand all
138 gfx::Vector3dF gyro = provided_data.gyro; 134 gfx::Vector3dF gyro = provided_data.gyro;
139 pad.pose.angular_velocity.not_null = true; 135 pad.pose.angular_velocity.not_null = true;
140 pad.pose.angular_velocity.x = gyro.x(); 136 pad.pose.angular_velocity.x = gyro.x();
141 pad.pose.angular_velocity.y = gyro.y(); 137 pad.pose.angular_velocity.y = gyro.y();
142 pad.pose.angular_velocity.z = gyro.z(); 138 pad.pose.angular_velocity.z = gyro.z();
143 } 139 }
144 140
145 void GvrGamepadDataFetcher::PauseHint(bool paused) {} 141 void GvrGamepadDataFetcher::PauseHint(bool paused) {}
146 142
147 } // namespace device 143 } // namespace device
OLDNEW
« no previous file with comments | « device/vr/DEPS ('k') | ppapi/shared_impl/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698