mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1569605 - Reuse WebVR FrameData Float32Arrays. r=kip,rbarker
Summary Do not recreate WebVR FrameData Float32Arrays every frame.: Differential Revision: https://phabricator.services.mozilla.com/D39683 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
d7d56b3178
commit
5c78386c22
@ -56,16 +56,30 @@ Pose::~Pose() { mozilla::DropJSObjects(this); }
|
||||
|
||||
nsISupports* Pose::GetParentObject() const { return mParent; }
|
||||
|
||||
void Pose::SetFloat32Array(JSContext* aJSContext,
|
||||
void Pose::SetFloat32Array(JSContext* aJSContext, nsWrapperCache* creator,
|
||||
JS::MutableHandle<JSObject*> aRetVal,
|
||||
JS::Heap<JSObject*>& aObj, float* aVal,
|
||||
uint32_t sizeOfVal, bool bCreate, ErrorResult& aRv) {
|
||||
if (bCreate) {
|
||||
aObj = Float32Array::Create(aJSContext, this, sizeOfVal, aVal);
|
||||
uint32_t aValLength, bool bCreate,
|
||||
ErrorResult& aRv) {
|
||||
if (!bCreate) {
|
||||
aRetVal.set(aObj);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!aObj) {
|
||||
aObj = Float32Array::Create(aJSContext, creator, aValLength, aVal);
|
||||
if (!aObj) {
|
||||
aRv.NoteJSContextException(aJSContext);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
JS::AutoCheckCannotGC nogc;
|
||||
bool isShared = false;
|
||||
JS::RootedObject obj(aJSContext, aObj.get());
|
||||
float* data = JS_GetFloat32ArrayData(obj, &isShared, nogc);
|
||||
if (data) {
|
||||
memcpy(data, aVal, aValLength * sizeof(float));
|
||||
}
|
||||
}
|
||||
|
||||
aRetVal.set(aObj);
|
||||
|
@ -40,15 +40,15 @@ class Pose : public nsWrapperCache {
|
||||
virtual void GetAngularAcceleration(JSContext* aJSContext,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) = 0;
|
||||
static void SetFloat32Array(JSContext* aJSContext, nsWrapperCache* creator,
|
||||
JS::MutableHandle<JSObject*> aRetVal,
|
||||
JS::Heap<JSObject*>& aObj, float* aVal,
|
||||
uint32_t aValLength, bool bCreate,
|
||||
ErrorResult& aRv);
|
||||
|
||||
protected:
|
||||
virtual ~Pose();
|
||||
|
||||
void SetFloat32Array(JSContext* aJSContext,
|
||||
JS::MutableHandle<JSObject*> aRetVal,
|
||||
JS::Heap<JSObject*>& aObj, float* aVal,
|
||||
uint32_t sizeOfVal, bool bCreate, ErrorResult& aRv);
|
||||
|
||||
nsCOMPtr<nsISupports> mParent;
|
||||
|
||||
JS::Heap<JSObject*> mPosition;
|
||||
|
@ -42,7 +42,7 @@ bool GamepadPose::HasPosition() const {
|
||||
void GamepadPose::GetPosition(JSContext* aJSContext,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) {
|
||||
SetFloat32Array(aJSContext, aRetval, mPosition,
|
||||
SetFloat32Array(aJSContext, this, aRetval, mPosition,
|
||||
mPoseState.isPositionValid ? mPoseState.position : nullptr, 3,
|
||||
bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Position),
|
||||
aRv);
|
||||
@ -52,7 +52,7 @@ void GamepadPose::GetLinearVelocity(JSContext* aJSContext,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) {
|
||||
SetFloat32Array(
|
||||
aJSContext, aRetval, mLinearVelocity,
|
||||
aJSContext, this, aRetval, mLinearVelocity,
|
||||
mPoseState.isPositionValid ? mPoseState.linearVelocity : nullptr, 3,
|
||||
bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Position), aRv);
|
||||
}
|
||||
@ -61,7 +61,7 @@ void GamepadPose::GetLinearAcceleration(JSContext* aJSContext,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) {
|
||||
SetFloat32Array(
|
||||
aJSContext, aRetval, mLinearAcceleration,
|
||||
aJSContext, this, aRetval, mLinearAcceleration,
|
||||
mPoseState.isPositionValid ? mPoseState.linearAcceleration : nullptr, 3,
|
||||
bool(mPoseState.flags & GamepadCapabilityFlags::Cap_LinearAcceleration),
|
||||
aRv);
|
||||
@ -71,7 +71,7 @@ void GamepadPose::GetOrientation(JSContext* aJSContext,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) {
|
||||
SetFloat32Array(
|
||||
aJSContext, aRetval, mOrientation,
|
||||
aJSContext, this, aRetval, mOrientation,
|
||||
mPoseState.isOrientationValid ? mPoseState.orientation : nullptr, 4,
|
||||
bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Orientation), aRv);
|
||||
}
|
||||
@ -80,7 +80,7 @@ void GamepadPose::GetAngularVelocity(JSContext* aJSContext,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) {
|
||||
SetFloat32Array(
|
||||
aJSContext, aRetval, mAngularVelocity,
|
||||
aJSContext, this, aRetval, mAngularVelocity,
|
||||
mPoseState.isOrientationValid ? mPoseState.angularVelocity : nullptr, 3,
|
||||
bool(mPoseState.flags & GamepadCapabilityFlags::Cap_Orientation), aRv);
|
||||
}
|
||||
@ -89,7 +89,7 @@ void GamepadPose::GetAngularAcceleration(JSContext* aJSContext,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) {
|
||||
SetFloat32Array(
|
||||
aJSContext, aRetval, mAngularAcceleration,
|
||||
aJSContext, this, aRetval, mAngularAcceleration,
|
||||
mPoseState.isOrientationValid ? mPoseState.angularAcceleration : nullptr,
|
||||
3,
|
||||
bool(mPoseState.flags & GamepadCapabilityFlags::Cap_AngularAcceleration),
|
||||
|
@ -244,7 +244,7 @@ VRPose::~VRPose() { mozilla::DropJSObjects(this); }
|
||||
void VRPose::GetPosition(JSContext* aCx, JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) {
|
||||
SetFloat32Array(
|
||||
aCx, aRetval, mPosition, mVRState.pose.position, 3,
|
||||
aCx, this, aRetval, mPosition, mVRState.pose.position, 3,
|
||||
!mPosition &&
|
||||
(bool(mVRState.flags & gfx::VRDisplayCapabilityFlags::Cap_Position) ||
|
||||
bool(mVRState.flags &
|
||||
@ -256,7 +256,7 @@ void VRPose::GetLinearVelocity(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) {
|
||||
SetFloat32Array(
|
||||
aCx, aRetval, mLinearVelocity, mVRState.pose.linearVelocity, 3,
|
||||
aCx, this, aRetval, mLinearVelocity, mVRState.pose.linearVelocity, 3,
|
||||
!mLinearVelocity &&
|
||||
bool(mVRState.flags & gfx::VRDisplayCapabilityFlags::Cap_Position),
|
||||
aRv);
|
||||
@ -266,7 +266,8 @@ void VRPose::GetLinearAcceleration(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) {
|
||||
SetFloat32Array(
|
||||
aCx, aRetval, mLinearAcceleration, mVRState.pose.linearAcceleration, 3,
|
||||
aCx, this, aRetval, mLinearAcceleration, mVRState.pose.linearAcceleration,
|
||||
3,
|
||||
!mLinearAcceleration &&
|
||||
bool(mVRState.flags &
|
||||
gfx::VRDisplayCapabilityFlags::Cap_LinearAcceleration),
|
||||
@ -277,7 +278,7 @@ void VRPose::GetOrientation(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) {
|
||||
SetFloat32Array(
|
||||
aCx, aRetval, mOrientation, mVRState.pose.orientation, 4,
|
||||
aCx, this, aRetval, mOrientation, mVRState.pose.orientation, 4,
|
||||
!mOrientation &&
|
||||
bool(mVRState.flags & gfx::VRDisplayCapabilityFlags::Cap_Orientation),
|
||||
aRv);
|
||||
@ -287,7 +288,7 @@ void VRPose::GetAngularVelocity(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) {
|
||||
SetFloat32Array(
|
||||
aCx, aRetval, mAngularVelocity, mVRState.pose.angularVelocity, 3,
|
||||
aCx, this, aRetval, mAngularVelocity, mVRState.pose.angularVelocity, 3,
|
||||
!mAngularVelocity &&
|
||||
bool(mVRState.flags & gfx::VRDisplayCapabilityFlags::Cap_Orientation),
|
||||
aRv);
|
||||
@ -297,13 +298,16 @@ void VRPose::GetAngularAcceleration(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) {
|
||||
SetFloat32Array(
|
||||
aCx, aRetval, mAngularAcceleration, mVRState.pose.angularAcceleration, 3,
|
||||
aCx, this, aRetval, mAngularAcceleration,
|
||||
mVRState.pose.angularAcceleration, 3,
|
||||
!mAngularAcceleration &&
|
||||
bool(mVRState.flags &
|
||||
gfx::VRDisplayCapabilityFlags::Cap_AngularAcceleration),
|
||||
aRv);
|
||||
}
|
||||
|
||||
void VRPose::Update(const gfx::VRHMDSensorState& aState) { mVRState = aState; }
|
||||
|
||||
JSObject* VRPose::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
return VRPose_Binding::Wrap(aCx, this, aGivenProto);
|
||||
@ -691,21 +695,6 @@ JSObject* VRFrameData::WrapObject(JSContext* aCx,
|
||||
|
||||
VRPose* VRFrameData::Pose() { return mPose; }
|
||||
|
||||
void VRFrameData::LazyCreateMatrix(JS::Heap<JSObject*>& aArray,
|
||||
gfx::Matrix4x4& aMat, JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) {
|
||||
if (!aArray) {
|
||||
// Lazily create the Float32Array
|
||||
aArray = dom::Float32Array::Create(aCx, this, 16, aMat.components);
|
||||
if (!aArray) {
|
||||
aRv.NoteJSContextException(aCx);
|
||||
return;
|
||||
}
|
||||
}
|
||||
aRetval.set(aArray);
|
||||
}
|
||||
|
||||
double VRFrameData::Timestamp() const {
|
||||
// Converting from seconds to milliseconds
|
||||
return mFrameInfo.mVRState.timestamp * 1000.0f;
|
||||
@ -714,38 +703,34 @@ double VRFrameData::Timestamp() const {
|
||||
void VRFrameData::GetLeftProjectionMatrix(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) {
|
||||
LazyCreateMatrix(mLeftProjectionMatrix, mFrameInfo.mLeftProjection, aCx,
|
||||
aRetval, aRv);
|
||||
Pose::SetFloat32Array(aCx, this, aRetval, mLeftProjectionMatrix,
|
||||
mFrameInfo.mLeftProjection.components, 16, true, aRv);
|
||||
}
|
||||
|
||||
void VRFrameData::GetLeftViewMatrix(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) {
|
||||
LazyCreateMatrix(mLeftViewMatrix, mFrameInfo.mLeftView, aCx, aRetval, aRv);
|
||||
Pose::SetFloat32Array(aCx, this, aRetval, mLeftViewMatrix,
|
||||
mFrameInfo.mLeftView.components, 16, true, aRv);
|
||||
}
|
||||
|
||||
void VRFrameData::GetRightProjectionMatrix(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) {
|
||||
LazyCreateMatrix(mRightProjectionMatrix, mFrameInfo.mRightProjection, aCx,
|
||||
aRetval, aRv);
|
||||
Pose::SetFloat32Array(aCx, this, aRetval, mRightProjectionMatrix,
|
||||
mFrameInfo.mRightProjection.components, 16, true, aRv);
|
||||
}
|
||||
|
||||
void VRFrameData::GetRightViewMatrix(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aRetval,
|
||||
ErrorResult& aRv) {
|
||||
LazyCreateMatrix(mRightViewMatrix, mFrameInfo.mRightView, aCx, aRetval, aRv);
|
||||
Pose::SetFloat32Array(aCx, this, aRetval, mRightViewMatrix,
|
||||
mFrameInfo.mRightView.components, 16, true, aRv);
|
||||
}
|
||||
|
||||
void VRFrameData::Update(const VRFrameInfo& aFrameInfo) {
|
||||
mFrameInfo = aFrameInfo;
|
||||
|
||||
mLeftProjectionMatrix = nullptr;
|
||||
mLeftViewMatrix = nullptr;
|
||||
mRightProjectionMatrix = nullptr;
|
||||
mRightViewMatrix = nullptr;
|
||||
|
||||
mPose = new VRPose(GetParentObject(), mFrameInfo.mVRState);
|
||||
mPose->Update(mFrameInfo.mVRState);
|
||||
}
|
||||
|
||||
void VRFrameInfo::Update(const gfx::VRDisplayInfo& aInfo,
|
||||
|
@ -116,6 +116,8 @@ class VRPose final : public Pose {
|
||||
virtual JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
void Update(const gfx::VRHMDSensorState& aState);
|
||||
|
||||
protected:
|
||||
~VRPose();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user