XRRenderState.cpp (2789B)
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 9 #include "VRLayerChild.h" 10 #include "nsIObserverService.h" 11 #include "nsISupportsPrimitives.h" 12 13 namespace mozilla::dom { 14 15 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(XRRenderState, mParent, mSession, 16 mBaseLayer, mOutputCanvas) 17 18 XRRenderState::XRRenderState(nsISupports* aParent, XRSession* aSession) 19 : mParent(aParent), 20 mSession(aSession), 21 mDepthNear(0.1f), 22 mDepthFar(1000.0f), 23 mCompositionDisabled(false) { 24 if (!mSession->IsImmersive()) { 25 mInlineVerticalFieldOfView.SetValue(M_PI * 0.5f); 26 } 27 } 28 29 XRRenderState::XRRenderState(const XRRenderState& aOther) 30 : mParent(aOther.mParent), 31 mSession(aOther.mSession), 32 mBaseLayer(aOther.mBaseLayer), 33 mDepthNear(aOther.mDepthNear), 34 mDepthFar(aOther.mDepthFar), 35 mInlineVerticalFieldOfView(aOther.mInlineVerticalFieldOfView), 36 mOutputCanvas(aOther.mOutputCanvas), 37 mCompositionDisabled(aOther.mCompositionDisabled) {} 38 39 JSObject* XRRenderState::WrapObject(JSContext* aCx, 40 JS::Handle<JSObject*> aGivenProto) { 41 return XRRenderState_Binding::Wrap(aCx, this, aGivenProto); 42 } 43 44 double XRRenderState::DepthNear() { return mDepthNear; } 45 46 double XRRenderState::DepthFar() { return mDepthFar; } 47 48 Nullable<double> XRRenderState::GetInlineVerticalFieldOfView() { 49 return mInlineVerticalFieldOfView; 50 } 51 52 void XRRenderState::SetDepthNear(double aDepthNear) { mDepthNear = aDepthNear; } 53 54 void XRRenderState::SetDepthFar(double aDepthFar) { mDepthFar = aDepthFar; } 55 56 void XRRenderState::SetInlineVerticalFieldOfView( 57 double aInlineVerticalFieldOfView) { 58 mInlineVerticalFieldOfView.SetValue(aInlineVerticalFieldOfView); 59 } 60 61 XRWebGLLayer* XRRenderState::GetBaseLayer() { return mBaseLayer; } 62 63 void XRRenderState::SetBaseLayer(XRWebGLLayer* aBaseLayer) { 64 mBaseLayer = aBaseLayer; 65 } 66 67 void XRRenderState::SetOutputCanvas(HTMLCanvasElement* aCanvas) { 68 mOutputCanvas = aCanvas; 69 } 70 71 HTMLCanvasElement* XRRenderState::GetOutputCanvas() const { 72 return mOutputCanvas; 73 } 74 75 void XRRenderState::SetCompositionDisabled(bool aCompositionDisabled) { 76 mCompositionDisabled = aCompositionDisabled; 77 } 78 79 bool XRRenderState::IsCompositionDisabled() const { 80 return mCompositionDisabled; 81 } 82 83 void XRRenderState::SessionEnded() { 84 if (mBaseLayer) { 85 mBaseLayer->SessionEnded(); 86 mBaseLayer = nullptr; 87 } 88 mOutputCanvas = nullptr; 89 } 90 91 } // namespace mozilla::dom