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