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 #if defined(ENABLE_NEW_GAMEPAD_API) | |
38 class WebGamepadButton { | |
39 public: | |
40 WebGamepadButton() | |
41 : pressed(false) | |
42 , value(0.f) | |
43 { | |
44 } | |
45 WebGamepadButton(bool pressed, float value) | |
46 : pressed(pressed) | |
47 , value(value) | |
48 { | |
49 } | |
50 bool pressed; | |
51 float value; | |
52 }; | |
53 #endif | |
54 | |
37 // This structure is intentionally POD and fixed size so that it can be shared | 55 // This structure is intentionally POD and fixed size so that it can be shared |
38 // memory between hardware polling threads and the rest of the browser. See | 56 // memory between hardware polling threads and the rest of the browser. See |
39 // also WebGamepads.h. | 57 // also WebGamepads.h. |
40 class WebGamepad { | 58 class WebGamepad { |
41 public: | 59 public: |
42 static const size_t idLengthCap = 128; | 60 static const size_t idLengthCap = 128; |
61 static const size_t mappingLengthCap = 16; | |
43 static const size_t axesLengthCap = 16; | 62 static const size_t axesLengthCap = 16; |
44 static const size_t buttonsLengthCap = 32; | 63 static const size_t buttonsLengthCap = 32; |
45 | 64 |
46 WebGamepad() | 65 WebGamepad() |
47 : connected(false) | 66 : connected(false) |
48 , timestamp(0) | 67 , timestamp(0) |
49 , axesLength(0) | 68 , axesLength(0) |
50 , buttonsLength(0) | 69 , buttonsLength(0) |
51 { | 70 { |
52 id[0] = 0; | 71 id[0] = 0; |
72 #if defined(ENABLE_NEW_GAMEPAD_API) | |
73 mapping[0] = 0; | |
74 #endif | |
53 } | 75 } |
54 | 76 |
55 // Is there a gamepad connected at this index? | 77 // Is there a gamepad connected at this index? |
56 bool connected; | 78 bool connected; |
57 | 79 |
58 // Device identifier (based on manufacturer, model, etc.). | 80 // Device identifier (based on manufacturer, model, etc.). |
59 WebUChar id[idLengthCap]; | 81 WebUChar id[idLengthCap]; |
60 | 82 |
61 // Monotonically increasing value referring to when the data were last | 83 // Monotonically increasing value referring to when the data were last |
62 // updated. | 84 // updated. |
63 unsigned long long timestamp; | 85 unsigned long long timestamp; |
64 | 86 |
65 // Number of valid entries in the axes array. | 87 // Number of valid entries in the axes array. |
66 unsigned axesLength; | 88 unsigned axesLength; |
67 | 89 |
68 // Normalized values representing axes, in the range [-1..1]. | 90 // Normalized values representing axes, in the range [-1..1]. |
69 float axes[axesLengthCap]; | 91 float axes[axesLengthCap]; |
70 | 92 |
71 // Number of valid entries in the buttons array. | 93 // Number of valid entries in the buttons array. |
72 unsigned buttonsLength; | 94 unsigned buttonsLength; |
73 | 95 |
74 // Normalized values representing buttons, in the range [0..1]. | 96 #if defined(ENABLE_NEW_GAMEPAD_API) |
97 // Button states | |
98 WebGamepadButton buttons[buttonsLengthCap]; | |
99 | |
100 // Mapping type (for example "standard") | |
101 WebUChar mapping[mappingLengthCap]; | |
102 #else | |
75 float buttons[buttonsLengthCap]; | 103 float buttons[buttonsLengthCap]; |
104 #endif | |
76 }; | 105 }; |
77 | 106 |
78 #if BLINK_IMPLEMENTATION | 107 #if BLINK_IMPLEMENTATION |
108 #if defined(ENABLE_NEW_GAMEPAD_API) | |
109 COMPILE_ASSERT(sizeof(WebGamepad) == 529, WebGamepad_has_wrong_size); | |
110 #else | |
79 COMPILE_ASSERT(sizeof(WebGamepad) == 465, WebGamepad_has_wrong_size); | 111 COMPILE_ASSERT(sizeof(WebGamepad) == 465, WebGamepad_has_wrong_size); |
80 #endif | 112 #endif |
113 #endif | |
abarth-chromium
2014/02/20 06:12:45
What's the point of these COMPILE_ASSERTs if we're
bajones
2014/02/20 17:03:24
Truthfully I'm not sure. The class must be a stati
| |
81 | 114 |
82 #pragma pack(pop) | 115 #pragma pack(pop) |
83 | 116 |
84 } | 117 } |
85 | 118 |
86 #endif // WebGamepad_h | 119 #endif // WebGamepad_h |
OLD | NEW |