changeset 1054:3c9529edf5fd

fixing WebAssemblyViewport
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 10 Oct 2019 15:55:54 +0200
parents 32b403a47b19
children af456106576c
files Framework/Viewport/WebAssemblyViewport.cpp Framework/Viewport/WebAssemblyViewport.h
diffstat 2 files changed, 35 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- 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();
   }
 }
--- 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_;
     }
   };
 }