1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5  * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #include "mozilla/dom/XRRenderState.h"
8 #include "VRLayerChild.h"
9 #include "nsIObserverService.h"
10 #include "nsISupportsPrimitives.h"
11 
12 namespace mozilla {
13 namespace dom {
14 
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(XRRenderState,mParent,mSession,mBaseLayer,mOutputCanvas)15 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(XRRenderState, mParent, mSession,
16                                       mBaseLayer, mOutputCanvas)
17 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(XRRenderState, AddRef)
18 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(XRRenderState, Release)
19 
20 XRRenderState::XRRenderState(nsISupports* aParent, XRSession* aSession)
21     : mParent(aParent),
22       mSession(aSession),
23       mDepthNear(0.1f),
24       mDepthFar(1000.0f),
25       mCompositionDisabled(false) {
26   if (!mSession->IsImmersive()) {
27     mInlineVerticalFieldOfView.SetValue(M_PI * 0.5f);
28   }
29 }
30 
XRRenderState(const XRRenderState & aOther)31 XRRenderState::XRRenderState(const XRRenderState& aOther)
32     : mParent(aOther.mParent),
33       mSession(aOther.mSession),
34       mBaseLayer(aOther.mBaseLayer),
35       mDepthNear(aOther.mDepthNear),
36       mDepthFar(aOther.mDepthFar),
37       mInlineVerticalFieldOfView(aOther.mInlineVerticalFieldOfView),
38       mOutputCanvas(aOther.mOutputCanvas),
39       mCompositionDisabled(aOther.mCompositionDisabled) {}
40 
WrapObject(JSContext * aCx,JS::Handle<JSObject * > aGivenProto)41 JSObject* XRRenderState::WrapObject(JSContext* aCx,
42                                     JS::Handle<JSObject*> aGivenProto) {
43   return XRRenderState_Binding::Wrap(aCx, this, aGivenProto);
44 }
45 
DepthNear()46 double XRRenderState::DepthNear() { return mDepthNear; }
47 
DepthFar()48 double XRRenderState::DepthFar() { return mDepthFar; }
49 
GetInlineVerticalFieldOfView()50 Nullable<double> XRRenderState::GetInlineVerticalFieldOfView() {
51   return mInlineVerticalFieldOfView;
52 }
53 
SetDepthNear(double aDepthNear)54 void XRRenderState::SetDepthNear(double aDepthNear) { mDepthNear = aDepthNear; }
55 
SetDepthFar(double aDepthFar)56 void XRRenderState::SetDepthFar(double aDepthFar) { mDepthFar = aDepthFar; }
57 
SetInlineVerticalFieldOfView(double aInlineVerticalFieldOfView)58 void XRRenderState::SetInlineVerticalFieldOfView(
59     double aInlineVerticalFieldOfView) {
60   mInlineVerticalFieldOfView.SetValue(aInlineVerticalFieldOfView);
61 }
62 
GetBaseLayer()63 XRWebGLLayer* XRRenderState::GetBaseLayer() { return mBaseLayer; }
64 
SetBaseLayer(XRWebGLLayer * aBaseLayer)65 void XRRenderState::SetBaseLayer(XRWebGLLayer* aBaseLayer) {
66   mBaseLayer = aBaseLayer;
67 }
68 
SetOutputCanvas(HTMLCanvasElement * aCanvas)69 void XRRenderState::SetOutputCanvas(HTMLCanvasElement* aCanvas) {
70   mOutputCanvas = aCanvas;
71 }
72 
GetOutputCanvas() const73 HTMLCanvasElement* XRRenderState::GetOutputCanvas() const {
74   return mOutputCanvas;
75 }
76 
SetCompositionDisabled(bool aCompositionDisabled)77 void XRRenderState::SetCompositionDisabled(bool aCompositionDisabled) {
78   mCompositionDisabled = aCompositionDisabled;
79 }
80 
IsCompositionDisabled() const81 bool XRRenderState::IsCompositionDisabled() const {
82   return mCompositionDisabled;
83 }
84 
SessionEnded()85 void XRRenderState::SessionEnded() {
86   if (mBaseLayer) {
87     mBaseLayer->SessionEnded();
88     mBaseLayer = nullptr;
89   }
90   mOutputCanvas = nullptr;
91 }
92 
93 }  // namespace dom
94 }  // namespace mozilla
95