changeset 907:722ee73e6ba2

cleanup + started to implement WebAssemblyCairoViewport (wip)
author Alain Mazy <alain@mazy.be>
date Thu, 18 Jul 2019 09:19:39 +0200
parents 88bf49aebc13
children 2f16ad9d30ad
files Framework/Viewport/SdlViewport.cpp Framework/Viewport/SdlViewport.h Framework/Viewport/WebAssemblyViewport.cpp Framework/Viewport/WebAssemblyViewport.h
diffstat 4 files changed, 68 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Viewport/SdlViewport.cpp	Wed Jul 17 16:56:53 2019 +0200
+++ b/Framework/Viewport/SdlViewport.cpp	Thu Jul 18 09:19:39 2019 +0200
@@ -78,35 +78,6 @@
     }
   }
 
-//  void SdlCairoViewport::SetSize(unsigned int width,
-//                                 unsigned int height)
-//  {
-    //    if (cairoSurface_.get() == NULL ||
-    //        cairoSurface_->GetWidth() != width ||
-    //        cairoSurface_->GetHeight() != height)
-    //    {
-    //      cairoSurface_.reset(new CairoSurface(width, height, false /* no alpha */));
-
-    //      // TODO Big endian?
-    //      static const uint32_t rmask = 0x00ff0000;
-    //      static const uint32_t gmask = 0x0000ff00;
-    //      static const uint32_t bmask = 0x000000ff;
-
-    //      if (sdlSurface_)
-    //      {
-    //        SDL_FreeSurface(sdlSurface_);
-    //      }
-
-    //      sdlSurface_ = SDL_CreateRGBSurfaceFrom(cairoSurface_->GetBuffer(), width, height, 32,
-    //                                             cairoSurface_->GetPitch(), rmask, gmask, bmask, 0);
-    //      if (!sdlSurface_)
-    //      {
-    //        LOG(ERROR) << "Cannot create a SDL surface from a Cairo surface";
-    //        throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
-    //      }
-    //    }
-//  }
-
 
   void SdlCairoViewport::Refresh()
   {
@@ -114,17 +85,4 @@
     window_.Render(sdlSurface_);
   }
 
-
-  //  void SdlCairoViewport::Render()
-  //  {
-  //    Orthanc::ImageAccessor target;
-  //    compositor_.GetCanvas() cairoSurface_->GetWriteableAccessor(target);
-
-  //    if (viewport.Render(target))
-  //    {
-  //      window_.Render(sdlSurface_);
-  //    }
-  //  }
-
-
 }
--- a/Framework/Viewport/SdlViewport.h	Wed Jul 17 16:56:53 2019 +0200
+++ b/Framework/Viewport/SdlViewport.h	Thu Jul 18 09:19:39 2019 +0200
@@ -57,7 +57,6 @@
 
     }
 
-
     virtual SdlWindow& GetWindow() = 0;
   };
 
@@ -89,10 +88,6 @@
     {
       return context_.GetWindow();
     }
-    //    SdlOpenGLContext& GetContext()
-    //    {
-    //      return context_;
-    //    }
   };
 
 
--- a/Framework/Viewport/WebAssemblyViewport.cpp	Wed Jul 17 16:56:53 2019 +0200
+++ b/Framework/Viewport/WebAssemblyViewport.cpp	Thu Jul 18 09:19:39 2019 +0200
@@ -23,26 +23,42 @@
 
 namespace OrthancStone
 {
-  WebAssemblyViewport::WebAssemblyViewport(const std::string& canvas) :
-    ViewportBase(canvas),
+  WebAssemblyOpenGLViewport::WebAssemblyOpenGLViewport(const std::string& canvas) :
+    WebAssemblyViewport(canvas),
     context_(canvas),
     compositor_(context_, GetScene())
   {
   }
 
     
-  WebAssemblyViewport::WebAssemblyViewport(const std::string& canvas,
-                                           boost::shared_ptr<Scene2D>& scene) :
-    ViewportBase(canvas, scene),
+  WebAssemblyOpenGLViewport::WebAssemblyOpenGLViewport(const std::string& canvas,
+                                                       boost::shared_ptr<Scene2D>& scene) :
+    WebAssemblyViewport(canvas, scene),
     context_(canvas),
     compositor_(context_, GetScene())
   {
   }
     
 
-  void WebAssemblyViewport::UpdateSize()
+  void WebAssemblyOpenGLViewport::UpdateSize()
   {
     context_.UpdateSize();  // First read the size of the canvas
     compositor_.Refresh();  // Then refresh the content of the canvas
   }
+
+
+  WebAssemblyCairoViewport::WebAssemblyCairoViewport(const std::string& canvas, unsigned int width, unsigned int height) :
+    WebAssemblyViewport(canvas),
+    compositor_(GetScene(), width, height)
+  {
+  }
+
+    
+  WebAssemblyCairoViewport::WebAssemblyCairoViewport(const std::string& canvas,
+                                                     boost::shared_ptr<Scene2D>& scene, unsigned int width, unsigned int height) :
+    WebAssemblyViewport(canvas, scene),
+    compositor_(GetScene(), width, height)
+  {
+  }
+
 }
--- a/Framework/Viewport/WebAssemblyViewport.h	Wed Jul 17 16:56:53 2019 +0200
+++ b/Framework/Viewport/WebAssemblyViewport.h	Thu Jul 18 09:19:39 2019 +0200
@@ -23,28 +23,70 @@
 
 #include "../OpenGL/WebAssemblyOpenGLContext.h"
 #include "../Scene2D/OpenGLCompositor.h"
+#include "../Scene2D/CairoCompositor.h"
 #include "ViewportBase.h"
 
 namespace OrthancStone
 {
   class WebAssemblyViewport : public ViewportBase
   {
+  public:
+    WebAssemblyViewport(const std::string& identifier)
+      : ViewportBase(identifier)
+    {
+    }
+
+    WebAssemblyViewport(const std::string& identifier,
+                        boost::shared_ptr<Scene2D>& scene)
+      : ViewportBase(identifier, scene)
+    {
+    }
+  };
+
+  class WebAssemblyOpenGLViewport : public WebAssemblyViewport
+  {
   private:
     OpenGL::WebAssemblyOpenGLContext  context_;
     OpenGLCompositor                  compositor_;
 
   public:
-    WebAssemblyViewport(const std::string& canvas);
+    WebAssemblyOpenGLViewport(const std::string& canvas);
     
-    WebAssemblyViewport(const std::string& canvas,
-                        boost::shared_ptr<Scene2D>& scene);
+    WebAssemblyOpenGLViewport(const std::string& canvas,
+                              boost::shared_ptr<Scene2D>& scene);
     
     // This function must be called each time the browser window is resized
     void UpdateSize();
 
-    ICompositor& GetCompositor()
+    virtual ICompositor& GetCompositor()
     {
       return compositor_;
     }
   };
+
+  class WebAssemblyCairoViewport : public WebAssemblyViewport
+  {
+  private:
+    CairoCompositor                  compositor_;
+
+  public:
+    WebAssemblyCairoViewport(const std::string& canvas, 
+                             unsigned int width, 
+                             unsigned int height);
+    
+    WebAssemblyCairoViewport(const std::string& canvas,
+                             boost::shared_ptr<Scene2D>& scene, 
+                             unsigned int width, 
+                             unsigned int height);
+    
+    // This function must be called each time the browser window is resized
+    void UpdateSize(); // TODO: implement
+
+    // TODO: implement Refresh
+    virtual ICompositor& GetCompositor()
+    {
+      return compositor_;
+    }
+  };
+
 }