# HG changeset patch # User Sebastien Jodogne # Date 1570715754 -7200 # Node ID 3c9529edf5fdc9ec14f2adc0372c3eb99d363e26 # Parent 32b403a47b19a6d631781ca1f7082e46dba3d9cc fixing WebAssemblyViewport diff -r 32b403a47b19 -r 3c9529edf5fd Framework/Viewport/WebAssemblyViewport.cpp --- a/Framework/Viewport/WebAssemblyViewport.cpp Thu Oct 10 15:24:48 2019 +0200 +++ b/Framework/Viewport/WebAssemblyViewport.cpp Thu Oct 10 15:55:54 2019 +0200 @@ -85,14 +85,31 @@ void WebAssemblyOpenGLViewport::DisableCompositor() { - compositor_.reset(NULL); + compositor_.reset(); + } + + ICompositor& WebAssemblyOpenGLViewport::GetCompositor() + { + if (compositor_.get() == NULL) + { + // "HasCompositor()" should have been called + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + else + { + return *compositor_; + } } void WebAssemblyOpenGLViewport::Refresh() { try { - if (!GetCompositor()) + if (HasCompositor()) + { + GetCompositor().Refresh(); + } + else { // this block was added because of (perceived?) bugs in the // browser where the WebGL contexts are NOT automatically restored @@ -102,16 +119,14 @@ //LOG(ERROR) << "About to call WebAssemblyOpenGLContext::TryRecreate()."; //LOG(ERROR) << "Before calling it, isContextLost == " << context_.IsContextLost(); - if (!context_.IsContextLost()) { + if (!context_.IsContextLost()) + { LOG(TRACE) << "Context restored!"; //LOG(ERROR) << "After calling it, isContextLost == " << context_.IsContextLost(); RestoreCompositor(); UpdateSize(); } } - if (GetCompositor()) { - GetCompositor()->Refresh(); - } } catch (const StoneException& e) { @@ -160,7 +175,7 @@ // maybe the context has already been restored by other means (the // Refresh() function) - if (!GetCompositor()) + if (!HasCompositor()) { RestoreCompositor(); UpdateSize(); @@ -248,6 +263,6 @@ void WebAssemblyCairoViewport::Refresh() { LOG(INFO) << "refreshing cairo viewport, TODO: blit to the canvans.getContext('2d')"; - GetCompositor()->Refresh(); + GetCompositor().Refresh(); } } diff -r 32b403a47b19 -r 3c9529edf5fd Framework/Viewport/WebAssemblyViewport.h --- a/Framework/Viewport/WebAssemblyViewport.h Thu Oct 10 15:24:48 2019 +0200 +++ b/Framework/Viewport/WebAssemblyViewport.h Thu Oct 10 15:55:54 2019 +0200 @@ -58,10 +58,12 @@ // This function must be called each time the browser window is resized void UpdateSize(); - virtual ICompositor* GetCompositor() ORTHANC_OVERRIDE + virtual bool HasCompositor() const ORTHANC_OVERRIDE { - return compositor_.get(); + return (compositor_.get() != NULL); } + + virtual ICompositor& GetCompositor() ORTHANC_OVERRIDE; virtual void Refresh() ORTHANC_OVERRIDE; @@ -93,11 +95,16 @@ void UpdateSize(); - virtual void Refresh(); + virtual void Refresh() ORTHANC_OVERRIDE; - virtual ICompositor* GetCompositor() + virtual bool HasCompositor() const ORTHANC_OVERRIDE { - return &compositor_; + return true; + } + + virtual ICompositor& GetCompositor() ORTHANC_OVERRIDE + { + return compositor_; } }; }