Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  VRLayerChild.cpp   Sprache: C

 

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


#include "VRLayerChild.h"

#include "mozilla/dom/HTMLCanvasElement.h"
#include "mozilla/layers/ImageBridgeChild.h"
#include "mozilla/layers/LayersMessages.h"  // for TimedTexture
#include "mozilla/layers/SyncObject.h"      // for SyncObjectClient
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/StaticPrefs_webgl.h"

#include "ClientWebGLContext.h"
#include "gfxPlatform.h"
#include "GLContext.h"
#include "GLScreenBuffer.h"
#include "SharedSurface.h"    // for SharedSurface
#include "SharedSurfaceGL.h"  // for SharedSurface

namespace mozilla::gfx {

VRLayerChild::VRLayerChild() { MOZ_COUNT_CTOR(VRLayerChild); }

VRLayerChild::~VRLayerChild() {
  ClearSurfaces();

  MOZ_COUNT_DTOR(VRLayerChild);
}

void VRLayerChild::Initialize(dom::HTMLCanvasElement* aCanvasElement,
                              const gfx::Rect& aLeftEyeRect,
                              const gfx::Rect& aRightEyeRect) {
  MOZ_ASSERT(aCanvasElement);
  mLeftEyeRect = aLeftEyeRect;
  mRightEyeRect = aRightEyeRect;
  mCanvasElement = aCanvasElement;
}

void VRLayerChild::SetXRFramebuffer(WebGLFramebufferJS* fb) {
  mFramebuffer = fb;
}

static constexpr bool kIsAndroid =
#if defined(MOZ_WIDGET_ANDROID)
    true;
#else
    false;
#endif

void VRLayerChild::SubmitFrame(const VRDisplayInfo& aDisplayInfo) {
  uint64_t frameId = aDisplayInfo.GetFrameId();

  // aFrameId will not increment unless the previuosly submitted
  // frame was received by the VR thread and submitted to the VR
  // compositor.  We early-exit here in the event that SubmitFrame
  // was called twice for the same aFrameId.
  if (!mCanvasElement || frameId == mLastSubmittedFrameId) {
    return;
  }

  const auto& webgl = mCanvasElement->GetWebGLContext();
  if (!webgl) return;

  // Keep the SharedSurfaceTextureClient alive long enough for
  // 1 extra frame, accomodating overlapped asynchronous rendering.
  mLastFrameTextureDesc = mThisFrameTextureDesc;

  bool getNewFrame = true;
  if (kIsAndroid) {
    /**
     * Do not blit WebGL to a SurfaceTexture until the last submitted frame is
     * already processed and the new frame poses are ready. SurfaceTextures need
     * to be released in the VR render thread in order to allow to be used again
     * in the WebGLContext GLScreenBuffer producer. Not doing so causes some
     * freezes, crashes or other undefined behaviour.
     */

    getNewFrame = (!mThisFrameTextureDesc ||
                   aDisplayInfo.mDisplayState.lastSubmittedFrameId ==
                       mLastSubmittedFrameId);
  }
  if (getNewFrame) {
    const RefPtr<layers::ImageBridgeChild> imageBridge =
        layers::ImageBridgeChild::GetSingleton();

    auto texType = layers::TextureType::Unknown;
    if (imageBridge) {
      texType = layers::PreferredCanvasTextureType(imageBridge);
    }
    if (kIsAndroid && StaticPrefs::webgl_enable_surface_texture()) {
      texType = layers::TextureType::AndroidNativeWindow;
    }

    webgl->Present(mFramebuffer, texType, true);
    mThisFrameTextureDesc = webgl->GetFrontBuffer(mFramebuffer, true);
  }

  mLastSubmittedFrameId = frameId;

  if (!mThisFrameTextureDesc) {
    gfxCriticalError() << "ToSurfaceDescriptor failed in "
                          "VRLayerChild::SubmitFrame";
    return;
  }

  SendSubmitFrame(*mThisFrameTextureDesc, frameId, mLeftEyeRect, mRightEyeRect);
}

void VRLayerChild::ClearSurfaces() {
  mThisFrameTextureDesc = Nothing();
  mLastFrameTextureDesc = Nothing();
  const auto& webgl = mCanvasElement->GetWebGLContext();
  if (!mFramebuffer && webgl) {
    webgl->ClearVRSwapChain();
  }
}

// static
already_AddRefed<VRLayerChild> VRLayerChild::CreateIPDLActor() {
  if (!StaticPrefs::dom_vr_enabled() && !StaticPrefs::dom_vr_webxr_enabled()) {
    return nullptr;
  }

  return MakeAndAddRef<VRLayerChild>();
}

}  // namespace mozilla::gfx

Messung V0.5 in Prozent
C=90 H=100 G=95

¤ Dauer der Verarbeitung: 0.12 Sekunden  (vorverarbeitet am  2026-09-28) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1126864
#Domains=1897691