diff Framework/Viewport/SdlViewport.h @ 905:88bf49aebc13

introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
author Alain Mazy <alain@mazy.be>
date Wed, 17 Jul 2019 16:56:53 +0200
parents 0c5201499af8
children 722ee73e6ba2
line wrap: on
line diff
--- a/Framework/Viewport/SdlViewport.h	Wed Jul 17 15:33:34 2019 +0200
+++ b/Framework/Viewport/SdlViewport.h	Wed Jul 17 16:56:53 2019 +0200
@@ -38,51 +38,96 @@
 
 #include "../../Applications/Sdl/SdlOpenGLContext.h"
 #include "../Scene2D/OpenGLCompositor.h"
+#include "../Scene2D/CairoCompositor.h"
 #include "ViewportBase.h"
 
 namespace OrthancStone
 {
   class SdlViewport : public ViewportBase
   {
+  public:
+    SdlViewport(const std::string& identifier)
+      : ViewportBase(identifier)
+    {}
+
+    SdlViewport(const std::string& identifier,
+                boost::shared_ptr<Scene2D>& scene)
+      : ViewportBase(identifier, scene)
+    {
+
+    }
+
+
+    virtual SdlWindow& GetWindow() = 0;
+  };
+
+  class SdlOpenGLViewport : public SdlViewport
+  {
   private:
     SdlOpenGLContext  context_;
     OpenGLCompositor  compositor_;
 
   public:
-    SdlViewport(const char* title,
-                unsigned int width,
-                unsigned int height,
-                bool allowDpiScaling = true);
-
-    SdlViewport(const char* title,
-                unsigned int width,
-                unsigned int height,
-                boost::shared_ptr<Scene2D>& scene,
-                bool allowDpiScaling = true);
+    SdlOpenGLViewport(const char* title,
+                      unsigned int width,
+                      unsigned int height,
+                      bool allowDpiScaling = true);
 
-    virtual void Refresh()
-    {
-      compositor_.Refresh();
-    }
+    SdlOpenGLViewport(const char* title,
+                      unsigned int width,
+                      unsigned int height,
+                      boost::shared_ptr<Scene2D>& scene,
+                      bool allowDpiScaling = true);
 
-    virtual unsigned int GetCanvasWidth() const
-    {
-      return compositor_.GetCanvasWidth();
-    }
 
-    virtual unsigned int GetCanvasHeight() const
-    {
-      return compositor_.GetCanvasHeight();
-    }
-
-    OpenGLCompositor& GetCompositor()
+    virtual ICompositor& GetCompositor()
     {
       return compositor_;
     }
 
-    SdlOpenGLContext& GetContext()
+    virtual SdlWindow& GetWindow()
     {
-      return context_;
+      return context_.GetWindow();
     }
+    //    SdlOpenGLContext& GetContext()
+    //    {
+    //      return context_;
+    //    }
+  };
+
+
+  class SdlCairoViewport : public SdlViewport
+  {
+  private:
+    SdlWindow         window_;
+    CairoCompositor   compositor_;
+    SDL_Surface*      sdlSurface_;
+
+  public:
+    SdlCairoViewport(const char* title,
+                     unsigned int width,
+                     unsigned int height,
+                     bool allowDpiScaling = true);
+
+    SdlCairoViewport(const char* title,
+                     unsigned int width,
+                     unsigned int height,
+                     boost::shared_ptr<Scene2D>& scene,
+                     bool allowDpiScaling = true);
+
+    ~SdlCairoViewport();
+
+    virtual ICompositor& GetCompositor()
+    {
+      return compositor_;
+    }
+
+    virtual SdlWindow& GetWindow()
+    {
+      return window_;
+    }
+
+    virtual void Refresh();
+
   };
 }