OLD | NEW |
1 // Copyright (c) 2011 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 <set> | 6 #include <set> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
| 14 #include "content/browser/gamepad/data_fetcher.h" |
| 15 #include "content/browser/gamepad/gamepad_provider.h" |
| 16 #include "content/browser/gamepad/platform_data_fetcher.h" |
| 17 #include "content/common/gamepad_messages.h" |
14 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
15 #include "content/browser/gamepad/gamepad_provider.h" | |
16 #include "content/browser/gamepad/data_fetcher.h" | |
17 #include "content/common/gamepad_messages.h" | |
18 | |
19 #if defined(OS_WIN) | |
20 #include "content/browser/gamepad/data_fetcher_win.h" | |
21 #elif defined(OS_MACOSX) | |
22 #include "content/browser/gamepad/data_fetcher_mac.h" | |
23 #endif | |
24 | 19 |
25 namespace content { | 20 namespace content { |
26 | 21 |
27 // Define the default data fetcher that GamepadProvider will use if none is | |
28 // supplied. (GamepadPlatformDataFetcher). | |
29 #if defined(OS_WIN) | |
30 | |
31 typedef GamepadDataFetcherWindows GamepadPlatformDataFetcher; | |
32 | |
33 #elif defined(OS_MACOSX) | |
34 | |
35 typedef GamepadDataFetcherMac GamepadPlatformDataFetcher; | |
36 | |
37 #else | |
38 | |
39 class GamepadEmptyDataFetcher : public GamepadDataFetcher { | |
40 public: | |
41 void GetGamepadData(WebKit::WebGamepads* pads, bool) { | |
42 pads->length = 0; | |
43 } | |
44 }; | |
45 typedef GamepadEmptyDataFetcher GamepadPlatformDataFetcher; | |
46 | |
47 #endif | |
48 | |
49 GamepadProvider::GamepadProvider(GamepadDataFetcher* fetcher) | 22 GamepadProvider::GamepadProvider(GamepadDataFetcher* fetcher) |
50 : is_paused_(false), | 23 : is_paused_(false), |
51 devices_changed_(true), | 24 devices_changed_(true), |
52 provided_fetcher_(fetcher), | 25 provided_fetcher_(fetcher), |
53 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 26 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
54 size_t data_size = sizeof(GamepadHardwareBuffer); | 27 size_t data_size = sizeof(GamepadHardwareBuffer); |
55 base::SystemMonitor* monitor = base::SystemMonitor::Get(); | 28 base::SystemMonitor* monitor = base::SystemMonitor::Get(); |
56 if (monitor) | 29 if (monitor) |
57 monitor->AddDevicesChangedObserver(this); | 30 monitor->AddDevicesChangedObserver(this); |
58 bool res = gamepad_shared_memory_.CreateAndMapAnonymous(data_size); | 31 bool res = gamepad_shared_memory_.CreateAndMapAnonymous(data_size); |
59 DCHECK(res); | 32 DCHECK(res); |
60 GamepadHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer(); | 33 GamepadHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer(); |
61 memset(hwbuf, 0, sizeof(GamepadHardwareBuffer)); | 34 memset(hwbuf, 0, sizeof(GamepadHardwareBuffer)); |
62 | 35 |
63 polling_thread_.reset(new base::Thread("Gamepad polling thread")); | 36 polling_thread_.reset(new base::Thread("Gamepad polling thread")); |
64 polling_thread_->Start(); | 37 polling_thread_->StartWithOptions( |
| 38 base::Thread::Options(MessageLoop::TYPE_IO, 0)); |
65 | 39 |
66 MessageLoop* polling_loop = polling_thread_->message_loop(); | 40 MessageLoop* polling_loop = polling_thread_->message_loop(); |
67 polling_loop->PostTask( | 41 polling_loop->PostTask( |
68 FROM_HERE, | 42 FROM_HERE, |
69 base::Bind(&GamepadProvider::DoInitializePollingThread, this)); | 43 base::Bind(&GamepadProvider::DoInitializePollingThread, this)); |
70 } | 44 } |
71 | 45 |
72 GamepadProvider::~GamepadProvider() { | 46 GamepadProvider::~GamepadProvider() { |
73 base::SystemMonitor* monitor = base::SystemMonitor::Get(); | 47 base::SystemMonitor* monitor = base::SystemMonitor::Get(); |
74 if (monitor) | 48 if (monitor) |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 kDesiredSamplingIntervalMs); | 143 kDesiredSamplingIntervalMs); |
170 } | 144 } |
171 | 145 |
172 GamepadHardwareBuffer* GamepadProvider::SharedMemoryAsHardwareBuffer() { | 146 GamepadHardwareBuffer* GamepadProvider::SharedMemoryAsHardwareBuffer() { |
173 void* mem = gamepad_shared_memory_.memory(); | 147 void* mem = gamepad_shared_memory_.memory(); |
174 DCHECK(mem); | 148 DCHECK(mem); |
175 return static_cast<GamepadHardwareBuffer*>(mem); | 149 return static_cast<GamepadHardwareBuffer*>(mem); |
176 } | 150 } |
177 | 151 |
178 } // namespace content | 152 } // namespace content |
OLD | NEW |