diff Framework/Viewport/SdlViewport.cpp @ 911:64e5f3ff6360 am-dev

Merge
author Alain Mazy <alain@mazy.be>
date Thu, 18 Jul 2019 10:50:59 +0200
parents 7a7e4e1f558f
children 1091b2adeb5a
line wrap: on
line diff
--- a/Framework/Viewport/SdlViewport.cpp	Wed Jul 17 15:33:07 2019 +0200
+++ b/Framework/Viewport/SdlViewport.cpp	Thu Jul 18 10:50:59 2019 +0200
@@ -26,24 +26,78 @@
 
 namespace OrthancStone
 {
-  SdlViewport::SdlViewport(const char* title,
-                           unsigned int width,
-                           unsigned int height,
-                           bool allowDpiScaling) :
-    ViewportBase(title),
+  SdlOpenGLViewport::SdlOpenGLViewport(const char* title,
+                                       unsigned int width,
+                                       unsigned int height,
+                                       bool allowDpiScaling) :
+    SdlViewport(title),
+    context_(title, width, height, allowDpiScaling),
+    compositor_(context_, GetScene())
+  {
+  }
+
+  SdlOpenGLViewport::SdlOpenGLViewport(const char* title,
+                                       unsigned int width,
+                                       unsigned int height,
+                                       boost::shared_ptr<Scene2D>& scene,
+                                       bool allowDpiScaling) :
+    SdlViewport(title, scene),
     context_(title, width, height, allowDpiScaling),
     compositor_(context_, GetScene())
   {
   }
 
-  SdlViewport::SdlViewport(const char* title,
-                           unsigned int width,
-                           unsigned int height,
-                           boost::shared_ptr<Scene2D>& scene,
-                           bool allowDpiScaling) :
-    ViewportBase(title, scene),
-    context_(title, width, height, allowDpiScaling),
-    compositor_(context_, GetScene())
+
+  SdlCairoViewport::SdlCairoViewport(const char* title,
+                                     unsigned int width,
+                                     unsigned int height,
+                                     bool allowDpiScaling) :
+    SdlViewport(title),
+    window_(title, width, height, false /* enable OpenGL */, allowDpiScaling),
+    compositor_(GetScene(), width, height)
+  {
+    UpdateSdlSurfaceSize(width, height);
+  }
+
+
+  SdlCairoViewport::~SdlCairoViewport()
+  {
+    if (sdlSurface_)
+    {
+      SDL_FreeSurface(sdlSurface_);
+    }
+  }
+
+
+  void SdlCairoViewport::Refresh()
   {
+    GetCompositor().Refresh();
+    window_.Render(sdlSurface_);
   }
+
+  void SdlCairoViewport::UpdateSize(unsigned int width,
+                                    unsigned int height)
+  {
+    compositor_.UpdateSize(width, height);
+    UpdateSdlSurfaceSize(width, height);
+    Refresh();
+  }
+
+
+  void SdlCairoViewport::UpdateSdlSurfaceSize(unsigned int width,
+                                              unsigned int height)
+  {
+    static const uint32_t rmask = 0x00ff0000;
+    static const uint32_t gmask = 0x0000ff00;
+    static const uint32_t bmask = 0x000000ff;
+
+    sdlSurface_ = SDL_CreateRGBSurfaceFrom((void*)(compositor_.GetCanvas().GetBuffer()), width, height, 32,
+                                           compositor_.GetCanvas().GetPitch(), rmask, gmask, bmask, 0);
+    if (!sdlSurface_)
+    {
+      LOG(ERROR) << "Cannot create a SDL surface from a Cairo surface";
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
+    }
+  }
+
 }