Bug 1343730 - Part 2: Get the submitframe result from VRDisplay; r=baku,kip

MozReview-Commit-ID: 91SqChn6jlO

--HG--
extra : rebase_source : 6254f99af8b4b08857961cebd8491264bfb9b8f5
This commit is contained in:
Daosheng Mu 2017-05-23 17:13:15 +08:00
parent a839377259
commit 911478d912
3 changed files with 125 additions and 0 deletions

View File

@ -12,9 +12,12 @@
#include "mozilla/dom/VRDisplay.h"
#include "mozilla/HoldDropJSObjects.h"
#include "mozilla/dom/VRDisplayBinding.h"
#include "mozilla/Base64.h"
#include "mozilla/EventStateManager.h"
#include "mozilla/gfx/DataSurfaceHelpers.h"
#include "Navigator.h"
#include "gfxPrefs.h"
#include "gfxUtils.h"
#include "gfxVR.h"
#include "VRDisplayClient.h"
#include "VRManagerChild.h"
@ -441,6 +444,40 @@ VRDisplay::GetFrameData(VRFrameData& aFrameData)
return true;
}
bool
VRDisplay::GetSubmitFrameResult(VRSubmitFrameResult& aResult)
{
if (!mPresentation) {
return false;
}
VRSubmitFrameResultInfo resultInfo;
mClient->GetSubmitFrameResult(resultInfo);
if (!resultInfo.mBase64Image.Length()) {
return false; // The submit frame result is not ready.
}
nsAutoCString decodedImg;
if (Base64Decode(resultInfo.mBase64Image, decodedImg) != NS_OK) {
MOZ_ASSERT(false, "Failed to do decode base64 images.");
return false;
}
const char* srcData = (decodedImg.get());
const gfx::IntSize size(resultInfo.mWidth, resultInfo.mHeight);
RefPtr<DataSourceSurface> dataSurface = gfx::CreateDataSourceSurfaceFromData(
size, resultInfo.mFormat, (uint8_t*)srcData,
StrideForFormatAndWidth(resultInfo.mFormat, resultInfo.mWidth));
if (!dataSurface || !dataSurface->IsValid()) {
MOZ_ASSERT(false, "dataSurface is null.");
return false;
}
nsAutoCString encodedImg(gfxUtils::GetAsDataURI(dataSurface));
aResult.Update(resultInfo.mFrameNum, encodedImg);
return true;
}
already_AddRefed<VRPose>
VRDisplay::GetPose()
{
@ -874,5 +911,54 @@ VRFrameInfo::Clear()
mVRState.Clear();
}
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(VRSubmitFrameResult, mParent)
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(VRSubmitFrameResult, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(VRSubmitFrameResult, Release)
VRSubmitFrameResult::VRSubmitFrameResult(nsISupports* aParent)
: mParent(aParent)
, mFrameNum(0)
{
mozilla::HoldJSObjects(this);
}
VRSubmitFrameResult::~VRSubmitFrameResult()
{
mozilla::DropJSObjects(this);
}
/* static */ already_AddRefed<VRSubmitFrameResult>
VRSubmitFrameResult::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
{
RefPtr<VRSubmitFrameResult> obj = new VRSubmitFrameResult(aGlobal.GetAsSupports());
return obj.forget();
}
JSObject*
VRSubmitFrameResult::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto)
{
return VRSubmitFrameResultBinding::Wrap(aCx, this, aGivenProto);
}
void
VRSubmitFrameResult::Update(uint32_t aFrameNum, const nsACString& aBase64Image)
{
mFrameNum = aFrameNum;
mBase64Image = NS_ConvertASCIItoUTF16(aBase64Image);
}
double
VRSubmitFrameResult::FrameNum() const
{
return mFrameNum;
}
void
VRSubmitFrameResult::GetBase64Image(nsAString& aImage) const
{
aImage = mBase64Image;
}
} // namespace dom
} // namespace mozilla

View File

@ -271,6 +271,33 @@ protected:
RefPtr<VRFieldOfView> mFOV;
};
class VRSubmitFrameResult final : public nsWrapperCache
{
public:
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(VRSubmitFrameResult)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(VRSubmitFrameResult)
explicit VRSubmitFrameResult(nsISupports* aParent);
static already_AddRefed<VRSubmitFrameResult> Constructor(const GlobalObject& aGlobal,
ErrorResult& aRv);
void Update(uint32_t aFrameNum, const nsACString& aBase64Image);
// WebIDL Members
double FrameNum() const;
void GetBase64Image(nsAString& aImage) const;
// WebIDL Boilerplate
nsISupports* GetParentObject() const { return mParent; }
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
protected:
~VRSubmitFrameResult();
nsCOMPtr<nsISupports> mParent;
nsString mBase64Image;
uint32_t mFrameNum;
};
class VRDisplay final : public DOMEventTargetHelper
, public nsIObserver
{
@ -302,6 +329,7 @@ public:
virtual already_AddRefed<VREyeParameters> GetEyeParameters(VREye aEye);
bool GetFrameData(VRFrameData& aFrameData);
bool GetSubmitFrameResult(VRSubmitFrameResult& aResult);
already_AddRefed<VRPose> GetPose();
void ResetPose();

View File

@ -149,6 +149,14 @@ interface VRFrameData {
[Pure] readonly attribute VRPose pose;
};
[Constructor,
Pref="dom.vr.test.enabled",
HeaderFile="mozilla/dom/VRDisplay.h"]
interface VRSubmitFrameResult {
readonly attribute unsigned long frameNum;
readonly attribute DOMString? base64Image;
};
[Pref="dom.vr.enabled",
HeaderFile="mozilla/dom/VRDisplay.h"]
interface VREyeParameters {
@ -220,6 +228,9 @@ interface VRDisplay : EventTarget {
*/
[NewObject] VRPose getPose();
[Pref="dom.vr.test.enabled"]
boolean getSubmitFrameResult(VRSubmitFrameResult result);
/**
* Reset the pose for this display, treating its current position and
* orientation as the "origin/zero" values. VRPose.position,