OLD | NEW |
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 <string.h> |
| 6 |
5 #include "ppapi/c/ppb_gamepad.h" | 7 #include "ppapi/c/ppb_gamepad.h" |
6 #include "ppapi/thunk/thunk.h" | 8 #include "ppapi/thunk/thunk.h" |
7 #include "ppapi/thunk/enter.h" | 9 #include "ppapi/thunk/enter.h" |
| 10 #include "ppapi/thunk/ppb_gamepad_api.h" |
8 #include "ppapi/thunk/ppb_instance_api.h" | 11 #include "ppapi/thunk/ppb_instance_api.h" |
9 #include "ppapi/thunk/resource_creation_api.h" | 12 #include "ppapi/thunk/resource_creation_api.h" |
10 | 13 |
11 namespace ppapi { | 14 namespace ppapi { |
12 namespace thunk { | 15 namespace thunk { |
13 | 16 |
14 namespace { | 17 namespace { |
15 | 18 |
16 void SampleGamepads(PP_Instance instance, PP_GamepadsSampleData* data) { | 19 void SampleGamepads(PP_Instance instance, PP_GamepadsSampleData* data) { |
17 EnterInstance enter(instance); | 20 EnterInstance enter(instance); |
18 if (enter.failed()) | 21 if (enter.succeeded()) { |
19 return; | 22 PPB_Gamepad_API* api = enter.functions()->GetGamepadAPI(instance); |
20 enter.functions()->SampleGamepads(instance, data); | 23 if (api) { |
| 24 api->Sample(data); |
| 25 return; |
| 26 } |
| 27 } |
| 28 // Failure, zero out. |
| 29 memset(data, 0, sizeof(PP_GamepadsSampleData)); |
21 } | 30 } |
22 | 31 |
23 const PPB_Gamepad g_ppb_gamepad_thunk = { | 32 const PPB_Gamepad g_ppb_gamepad_thunk = { |
24 &SampleGamepads, | 33 &SampleGamepads, |
25 }; | 34 }; |
26 | 35 |
27 } // namespace | 36 } // namespace |
28 | 37 |
29 const PPB_Gamepad* GetPPB_Gamepad_1_0_Thunk() { | 38 const PPB_Gamepad* GetPPB_Gamepad_1_0_Thunk() { |
30 return &g_ppb_gamepad_thunk; | 39 return &g_ppb_gamepad_thunk; |
31 } | 40 } |
32 | 41 |
33 } // namespace thunk | 42 } // namespace thunk |
34 } // namespace ppapi | 43 } // namespace ppapi |
OLD | NEW |