Commit cf1c8194 authored by bajones's avatar bajones Committed by Commit bot

Added Pose attribute to Gamepad

BUG=628417

TBR=mkwst@chromium.org

Review-Url: https://codereview.chromium.org/2300543003
Cr-Commit-Position: refs/heads/master@{#419564}
parent 0f1a2fab
...@@ -25,6 +25,30 @@ struct WebKitGamepadButton { ...@@ -25,6 +25,30 @@ struct WebKitGamepadButton {
double value; double value;
}; };
struct WebKitGamepadVector {
bool notNull;
float x, y, z;
};
struct WebKitGamepadQuaternion {
bool notNull;
float x, y, z, w;
};
struct WebKitGamepadPose {
bool notNull;
bool hasOrientation;
bool hasPosition;
WebKitGamepadQuaternion orientation;
WebKitGamepadVector position;
WebKitGamepadVector angularVelocity;
WebKitGamepadVector linearVelocity;
WebKitGamepadVector angularAcceleration;
WebKitGamepadVector linearAcceleration;
};
// This must match the definition of blink::Gamepad. The GamepadHost unit test // This must match the definition of blink::Gamepad. The GamepadHost unit test
// has some compile asserts to validate this. // has some compile asserts to validate this.
struct WebKitGamepad { struct WebKitGamepad {
...@@ -57,6 +81,8 @@ struct WebKitGamepad { ...@@ -57,6 +81,8 @@ struct WebKitGamepad {
// Mapping type (for example "standard") // Mapping type (for example "standard")
base::char16 mapping[kMappingLengthCap]; base::char16 mapping[kMappingLengthCap];
WebKitGamepadPose pose;
}; };
// This must match the definition of blink::Gamepads. The GamepadHost unit // This must match the definition of blink::Gamepads. The GamepadHost unit
......
...@@ -16,6 +16,8 @@ blink_modules_sources("gamepad") { ...@@ -16,6 +16,8 @@ blink_modules_sources("gamepad") {
"GamepadEvent.h", "GamepadEvent.h",
"GamepadList.cpp", "GamepadList.cpp",
"GamepadList.h", "GamepadList.h",
"GamepadPose.cpp",
"GamepadPose.h",
"NavigatorGamepad.cpp", "NavigatorGamepad.cpp",
"NavigatorGamepad.h", "NavigatorGamepad.h",
] ]
......
...@@ -58,9 +58,24 @@ void Gamepad::setButtons(unsigned count, const WebGamepadButton* data) ...@@ -58,9 +58,24 @@ void Gamepad::setButtons(unsigned count, const WebGamepadButton* data)
} }
} }
void Gamepad::setPose(const WebGamepadPose& pose)
{
if (!pose.notNull) {
if (m_pose)
m_pose = nullptr;
return;
}
if (!m_pose)
m_pose = GamepadPose::create();
m_pose->setPose(pose);
}
DEFINE_TRACE(Gamepad) DEFINE_TRACE(Gamepad)
{ {
visitor->trace(m_buttons); visitor->trace(m_buttons);
visitor->trace(m_pose);
} }
} // namespace blink } // namespace blink
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "bindings/core/v8/ScriptWrappable.h" #include "bindings/core/v8/ScriptWrappable.h"
#include "modules/gamepad/GamepadButton.h" #include "modules/gamepad/GamepadButton.h"
#include "modules/gamepad/GamepadPose.h"
#include "platform/heap/Handle.h" #include "platform/heap/Handle.h"
#include "public/platform/WebGamepad.h" #include "public/platform/WebGamepad.h"
#include "wtf/Vector.h" #include "wtf/Vector.h"
...@@ -67,6 +68,9 @@ public: ...@@ -67,6 +68,9 @@ public:
const GamepadButtonVector& buttons() const { return m_buttons; } const GamepadButtonVector& buttons() const { return m_buttons; }
void setButtons(unsigned count, const WebGamepadButton* data); void setButtons(unsigned count, const WebGamepadButton* data);
GamepadPose* pose() const { return m_pose; }
void setPose(const WebGamepadPose&);
DECLARE_TRACE(); DECLARE_TRACE();
private: private:
...@@ -79,6 +83,7 @@ private: ...@@ -79,6 +83,7 @@ private:
String m_mapping; String m_mapping;
DoubleVector m_axes; DoubleVector m_axes;
GamepadButtonVector m_buttons; GamepadButtonVector m_buttons;
Member<GamepadPose> m_pose;
}; };
} // namespace blink } // namespace blink
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
* DAMAGE. * DAMAGE.
*/ */
// https://w3c.github.io/gamepad/#gamepad-interface
interface Gamepad { interface Gamepad {
readonly attribute DOMString id; readonly attribute DOMString id;
readonly attribute unsigned long index; readonly attribute unsigned long index;
...@@ -31,4 +32,5 @@ interface Gamepad { ...@@ -31,4 +32,5 @@ interface Gamepad {
readonly attribute DOMString mapping; readonly attribute DOMString mapping;
readonly attribute double[] axes; readonly attribute double[] axes;
readonly attribute GamepadButton[] buttons; readonly attribute GamepadButton[] buttons;
[RuntimeEnabled=GamepadExtensions] readonly attribute GamepadPose? pose;
}; };
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "modules/gamepad/GamepadPose.h"
namespace blink {
namespace {
DOMFloat32Array* vecToFloat32Array(const WebGamepadVector& vec)
{
if (vec.notNull) {
DOMFloat32Array* out = DOMFloat32Array::create(3);
out->data()[0] = vec.x;
out->data()[1] = vec.y;
out->data()[2] = vec.z;
return out;
}
return nullptr;
}
DOMFloat32Array* quatToFloat32Array(const WebGamepadQuaternion& quat)
{
if (quat.notNull) {
DOMFloat32Array* out = DOMFloat32Array::create(4);
out->data()[0] = quat.x;
out->data()[1] = quat.y;
out->data()[2] = quat.z;
out->data()[3] = quat.w;
return out;
}
return nullptr;
}
} // namespace
GamepadPose::GamepadPose()
{
}
void GamepadPose::setPose(const WebGamepadPose &state)
{
if (state.notNull) {
m_hasOrientation = state.hasOrientation;
m_hasPosition = state.hasPosition;
m_orientation = quatToFloat32Array(state.orientation);
m_position = vecToFloat32Array(state.position);
m_angularVelocity = vecToFloat32Array(state.angularVelocity);
m_linearVelocity = vecToFloat32Array(state.linearVelocity);
m_angularAcceleration = vecToFloat32Array(state.angularAcceleration);
m_linearAcceleration = vecToFloat32Array(state.linearAcceleration);
}
}
DEFINE_TRACE(GamepadPose)
{
visitor->trace(m_orientation);
visitor->trace(m_position);
visitor->trace(m_angularVelocity);
visitor->trace(m_linearVelocity);
visitor->trace(m_angularAcceleration);
visitor->trace(m_linearAcceleration);
}
} // namespace blink
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef GamepadPose_h
#define GamepadPose_h
#include "bindings/core/v8/ScriptWrappable.h"
#include "core/dom/DOMTypedArray.h"
#include "platform/heap/Handle.h"
#include "public/platform/WebGamepad.h"
#include "wtf/Forward.h"
namespace blink {
class GamepadPose final : public GarbageCollected<GamepadPose>, public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
static GamepadPose* create()
{
return new GamepadPose();
}
bool hasOrientation() const { return m_hasOrientation; }
bool hasPosition() const { return m_hasPosition; }
DOMFloat32Array* orientation() const { return m_orientation; }
DOMFloat32Array* position() const { return m_position; }
DOMFloat32Array* angularVelocity() const { return m_angularVelocity; }
DOMFloat32Array* linearVelocity() const { return m_linearVelocity; }
DOMFloat32Array* angularAcceleration() const { return m_angularAcceleration; }
DOMFloat32Array* linearAcceleration() const { return m_linearAcceleration; }
void setPose(const WebGamepadPose &state);
DECLARE_VIRTUAL_TRACE();
private:
GamepadPose();
bool m_hasOrientation;
bool m_hasPosition;
Member<DOMFloat32Array> m_orientation;
Member<DOMFloat32Array> m_position;
Member<DOMFloat32Array> m_angularVelocity;
Member<DOMFloat32Array> m_linearVelocity;
Member<DOMFloat32Array> m_angularAcceleration;
Member<DOMFloat32Array> m_linearAcceleration;
};
} // namespace blink
#endif // VRPose_h
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://w3c.github.io/gamepad/extensions.html#gamepadpose-interface
[
RuntimeEnabled=GamepadExtensions,
] interface GamepadPose {
readonly attribute boolean hasOrientation;
readonly attribute boolean hasPosition;
readonly attribute Float32Array? position;
readonly attribute Float32Array? linearVelocity;
readonly attribute Float32Array? linearAcceleration;
readonly attribute Float32Array? orientation;
readonly attribute Float32Array? angularVelocity;
readonly attribute Float32Array? angularAcceleration;
};
...@@ -45,6 +45,7 @@ static void sampleGamepad(unsigned index, T& gamepad, const WebGamepad& webGamep ...@@ -45,6 +45,7 @@ static void sampleGamepad(unsigned index, T& gamepad, const WebGamepad& webGamep
gamepad.setMapping(webGamepad.mapping); gamepad.setMapping(webGamepad.mapping);
gamepad.setAxes(webGamepad.axesLength, webGamepad.axes); gamepad.setAxes(webGamepad.axesLength, webGamepad.axes);
gamepad.setButtons(webGamepad.buttonsLength, webGamepad.buttons); gamepad.setButtons(webGamepad.buttonsLength, webGamepad.buttons);
gamepad.setPose(webGamepad.pose);
} }
template<typename GamepadType, typename ListType> template<typename GamepadType, typename ListType>
......
...@@ -112,6 +112,7 @@ modules_idl_files = ...@@ -112,6 +112,7 @@ modules_idl_files =
"gamepad/GamepadButton.idl", "gamepad/GamepadButton.idl",
"gamepad/GamepadEvent.idl", "gamepad/GamepadEvent.idl",
"gamepad/GamepadList.idl", "gamepad/GamepadList.idl",
"gamepad/GamepadPose.idl",
"geolocation/Coordinates.idl", "geolocation/Coordinates.idl",
"geolocation/Geolocation.idl", "geolocation/Geolocation.idl",
"geolocation/Geoposition.idl", "geolocation/Geoposition.idl",
......
...@@ -49,6 +49,48 @@ public: ...@@ -49,6 +49,48 @@ public:
double value; double value;
}; };
class WebGamepadVector {
public:
WebGamepadVector()
: notNull(false)
{
}
bool notNull;
float x, y, z;
};
class WebGamepadQuaternion {
public:
WebGamepadQuaternion()
: notNull(false)
{
}
bool notNull;
float x, y, z, w;
};
class WebGamepadPose {
public:
WebGamepadPose()
: notNull(false)
{
}
bool notNull;
bool hasOrientation;
bool hasPosition;
WebGamepadQuaternion orientation;
WebGamepadVector position;
WebGamepadVector angularVelocity;
WebGamepadVector linearVelocity;
WebGamepadVector angularAcceleration;
WebGamepadVector linearAcceleration;
};
// This structure is intentionally POD and fixed size so that it can be shared // This structure is intentionally POD and fixed size so that it can be shared
// memory between hardware polling threads and the rest of the browser. See // memory between hardware polling threads and the rest of the browser. See
// also WebGamepads.h. // also WebGamepads.h.
...@@ -93,9 +135,11 @@ public: ...@@ -93,9 +135,11 @@ public:
// Mapping type (for example "standard") // Mapping type (for example "standard")
WebUChar mapping[mappingLengthCap]; WebUChar mapping[mappingLengthCap];
WebGamepadPose pose;
}; };
static_assert(sizeof(WebGamepad) == 753, "WebGamepad has wrong size"); static_assert(sizeof(WebGamepad) == 838, "WebGamepad has wrong size");
#pragma pack(pop) #pragma pack(pop)
......
...@@ -47,7 +47,7 @@ public: ...@@ -47,7 +47,7 @@ public:
WebGamepad items[itemsLengthCap]; WebGamepad items[itemsLengthCap];
}; };
static_assert(sizeof(WebGamepads) == 3016, "WebGamepads has wrong size"); static_assert(sizeof(WebGamepads) == 3356, "WebGamepads has wrong size");
#pragma pack(pop) #pragma pack(pop)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment