OLD | NEW |
1 // Copyright (C) 2011, Google Inc. All rights reserved. | 1 // Copyright (C) 2011, Google Inc. All rights reserved. |
2 // | 2 // |
3 // Redistribution and use in source and binary forms, with or without | 3 // Redistribution and use in source and binary forms, with or without |
4 // modification, are permitted provided that the following conditions are met: | 4 // modification, are permitted provided that the following conditions are met: |
5 // | 5 // |
6 // 1. Redistributions of source code must retain the above copyright | 6 // 1. Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // 2. Redistributions in binary form must reproduce the above copyright | 8 // 2. Redistributions in binary form must reproduce the above copyright |
9 // notice, this list of conditions and the following disclaimer in the | 9 // notice, this list of conditions and the following disclaimer in the |
10 // documentation and/or other materials provided with the distribution. | 10 // documentation and/or other materials provided with the distribution. |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "WebCommon.h" | 27 #include "WebCommon.h" |
28 | 28 |
29 #if BLINK_IMPLEMENTATION | 29 #if BLINK_IMPLEMENTATION |
30 #include "wtf/Assertions.h" | 30 #include "wtf/Assertions.h" |
31 #endif | 31 #endif |
32 | 32 |
33 namespace blink { | 33 namespace blink { |
34 | 34 |
35 #pragma pack(push, 1) | 35 #pragma pack(push, 1) |
36 | 36 |
37 class WebGamepadButton { | |
38 public: | |
39 WebGamepadButton() | |
40 : pressed(false) | |
41 , value(0.f) | |
42 { | |
43 } | |
44 WebGamepadButton(bool pressed, float value) | |
45 : pressed(pressed) | |
46 , value(value) | |
47 { | |
48 } | |
49 bool pressed; | |
50 float value; | |
51 }; | |
52 | |
53 // This structure is intentionally POD and fixed size so that it can be shared | 37 // This structure is intentionally POD and fixed size so that it can be shared |
54 // memory between hardware polling threads and the rest of the browser. See | 38 // memory between hardware polling threads and the rest of the browser. See |
55 // also WebGamepads.h. | 39 // also WebGamepads.h. |
56 class WebGamepad { | 40 class WebGamepad { |
57 public: | 41 public: |
58 static const size_t idLengthCap = 128; | 42 static const size_t idLengthCap = 128; |
59 static const size_t mappingLengthCap = 16; | |
60 static const size_t axesLengthCap = 16; | 43 static const size_t axesLengthCap = 16; |
61 static const size_t buttonsLengthCap = 32; | 44 static const size_t buttonsLengthCap = 32; |
62 | 45 |
63 WebGamepad() | 46 WebGamepad() |
64 : connected(false) | 47 : connected(false) |
65 , timestamp(0) | 48 , timestamp(0) |
66 , axesLength(0) | 49 , axesLength(0) |
67 , buttonsLength(0) | 50 , buttonsLength(0) |
68 { | 51 { |
69 id[0] = 0; | 52 id[0] = 0; |
70 mapping[0] = 0; | |
71 } | 53 } |
72 | 54 |
73 // Is there a gamepad connected at this index? | 55 // Is there a gamepad connected at this index? |
74 bool connected; | 56 bool connected; |
75 | 57 |
76 // Device identifier (based on manufacturer, model, etc.). | 58 // Device identifier (based on manufacturer, model, etc.). |
77 WebUChar id[idLengthCap]; | 59 WebUChar id[idLengthCap]; |
78 | 60 |
79 // Monotonically increasing value referring to when the data were last | 61 // Monotonically increasing value referring to when the data were last |
80 // updated. | 62 // updated. |
81 unsigned long long timestamp; | 63 unsigned long long timestamp; |
82 | 64 |
83 // Number of valid entries in the axes array. | 65 // Number of valid entries in the axes array. |
84 unsigned axesLength; | 66 unsigned axesLength; |
85 | 67 |
86 // Normalized values representing axes, in the range [-1..1]. | 68 // Normalized values representing axes, in the range [-1..1]. |
87 float axes[axesLengthCap]; | 69 float axes[axesLengthCap]; |
88 | 70 |
89 // Number of valid entries in the buttons array. | 71 // Number of valid entries in the buttons array. |
90 unsigned buttonsLength; | 72 unsigned buttonsLength; |
91 | 73 |
92 // Button states | 74 // Normalized values representing buttons, in the range [0..1]. |
93 WebGamepadButton buttons[buttonsLengthCap]; | 75 float buttons[buttonsLengthCap]; |
94 | |
95 // Mapping type (for example "standard") | |
96 WebUChar mapping[mappingLengthCap]; | |
97 }; | 76 }; |
98 | 77 |
99 #if BLINK_IMPLEMENTATION | 78 #if BLINK_IMPLEMENTATION |
100 COMPILE_ASSERT(sizeof(WebGamepad) == 529, WebGamepad_has_wrong_size); | 79 COMPILE_ASSERT(sizeof(WebGamepad) == 465, WebGamepad_has_wrong_size); |
101 #endif | 80 #endif |
102 | 81 |
103 #pragma pack(pop) | 82 #pragma pack(pop) |
104 | 83 |
105 } | 84 } |
106 | 85 |
107 #endif // WebGamepad_h | 86 #endif // WebGamepad_h |
OLD | NEW |