LCOV - code coverage report
Current view: top level - gfx/vr - VRDisplayPresentation.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 63 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2             : * This Source Code Form is subject to the terms of the Mozilla Public
       3             : * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #include "VRDisplayPresentation.h"
       7             : 
       8             : #include "mozilla/dom/DocGroup.h"
       9             : #include "mozilla/Unused.h"
      10             : #include "VRDisplayClient.h"
      11             : #include "VRLayerChild.h"
      12             : 
      13             : using namespace mozilla;
      14             : using namespace mozilla::gfx;
      15             : 
      16           0 : VRDisplayPresentation::VRDisplayPresentation(VRDisplayClient *aDisplayClient,
      17             :                                              const nsTArray<mozilla::dom::VRLayer>& aLayers,
      18           0 :                                              uint32_t aGroup)
      19             :   : mDisplayClient(aDisplayClient)
      20             :   , mDOMLayers(aLayers)
      21           0 :   , mGroup(aGroup)
      22             : {
      23           0 :   CreateLayers();
      24           0 : }
      25             : 
      26             : uint32_t
      27           0 : VRDisplayPresentation::GetGroup() const
      28             : {
      29           0 :   return mGroup;
      30             : }
      31             : 
      32             : void
      33           0 : VRDisplayPresentation::CreateLayers()
      34             : {
      35           0 :   if (mLayers.Length()) {
      36           0 :     return;
      37             :   }
      38             : 
      39           0 :   for (dom::VRLayer& layer : mDOMLayers) {
      40           0 :     dom::HTMLCanvasElement* canvasElement = layer.mSource;
      41           0 :     if (!canvasElement) {
      42             :       /// XXX In the future we will support WebVR in WebWorkers here
      43           0 :       continue;
      44             :     }
      45             : 
      46           0 :     Rect leftBounds(0.0, 0.0, 0.5, 1.0);
      47           0 :     if (layer.mLeftBounds.Length() == 4) {
      48           0 :       leftBounds.x = layer.mLeftBounds[0];
      49           0 :       leftBounds.y = layer.mLeftBounds[1];
      50           0 :       leftBounds.width = layer.mLeftBounds[2];
      51           0 :       leftBounds.height = layer.mLeftBounds[3];
      52           0 :     } else if (layer.mLeftBounds.Length() != 0) {
      53             :       /**
      54             :        * We ignore layers with an incorrect number of values.
      55             :        * In the future, VRDisplay.requestPresent may throw in
      56             :        * this case.  See https://github.com/w3c/webvr/issues/71
      57             :        */
      58           0 :       continue;
      59             :     }
      60             : 
      61           0 :     Rect rightBounds(0.5, 0.0, 0.5, 1.0);
      62           0 :     if (layer.mRightBounds.Length() == 4) {
      63           0 :       rightBounds.x = layer.mRightBounds[0];
      64           0 :       rightBounds.y = layer.mRightBounds[1];
      65           0 :       rightBounds.width = layer.mRightBounds[2];
      66           0 :       rightBounds.height = layer.mRightBounds[3];
      67           0 :     } else if (layer.mRightBounds.Length() != 0) {
      68             :       /**
      69             :        * We ignore layers with an incorrect number of values.
      70             :        * In the future, VRDisplay.requestPresent may throw in
      71             :        * this case.  See https://github.com/w3c/webvr/issues/71
      72             :        */
      73           0 :       continue;
      74             :     }
      75             : 
      76           0 :     VRManagerChild *manager = VRManagerChild::Get();
      77           0 :     if (!manager) {
      78           0 :       NS_WARNING("VRManagerChild::Get returned null!");
      79           0 :       continue;
      80             :     }
      81             : 
      82           0 :     nsCOMPtr<nsIEventTarget> target;
      83             :     nsIDocument* doc;
      84           0 :     doc = canvasElement->OwnerDoc();
      85           0 :     if (doc) {
      86           0 :       target = doc->EventTargetFor(TaskCategory::Other);
      87             :     }
      88             : 
      89             :     RefPtr<VRLayerChild> vrLayer =
      90           0 :       static_cast<VRLayerChild*>(manager->CreateVRLayer(mDisplayClient->GetDisplayInfo().GetDisplayID(),
      91             :                                                         leftBounds, rightBounds, target,
      92           0 :                                                         mGroup));
      93           0 :     if (!vrLayer) {
      94           0 :       NS_WARNING("CreateVRLayer returned null!");
      95           0 :       continue;
      96             :     }
      97             : 
      98           0 :     vrLayer->Initialize(canvasElement);
      99             : 
     100           0 :     mLayers.AppendElement(vrLayer);
     101             :   }
     102             : }
     103             : 
     104             : void
     105           0 : VRDisplayPresentation::DestroyLayers()
     106             : {
     107           0 :   for (VRLayerChild* layer : mLayers) {
     108           0 :     if (layer->IsIPCOpen()) {
     109           0 :       Unused << layer->SendDestroy();
     110             :     }
     111             :   }
     112           0 :   mLayers.Clear();
     113           0 : }
     114             : 
     115             : void
     116           0 : VRDisplayPresentation::GetDOMLayers(nsTArray<dom::VRLayer>& result)
     117             : {
     118           0 :   result = mDOMLayers;
     119           0 : }
     120             : 
     121           0 : VRDisplayPresentation::~VRDisplayPresentation()
     122             : {
     123           0 :   DestroyLayers();
     124           0 :   mDisplayClient->PresentationDestroyed();
     125           0 : }
     126             : 
     127           0 : void VRDisplayPresentation::SubmitFrame()
     128             : {
     129           0 :   for (VRLayerChild *layer : mLayers) {
     130           0 :     layer->SubmitFrame();
     131           0 :     break; // Currently only one layer supported, submit only the first
     132             :   }
     133           0 : }

Generated by: LCOV version 1.13