diff Framework/Viewport/IViewport.h @ 1203:f3bb9a6dd949 broker

locking abstraction in IViewport
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 29 Nov 2019 21:22:21 +0100
parents 5e164c629923
children 6009c59d8676
line wrap: on
line diff
--- a/Framework/Viewport/IViewport.h	Fri Nov 29 11:03:41 2019 +0100
+++ b/Framework/Viewport/IViewport.h	Fri Nov 29 21:22:21 2019 +0100
@@ -29,25 +29,39 @@
   /**
    * Class that combines a Scene2D with a canvas where to draw the
    * scene. A call to "Refresh()" will update the content of the
-   * canvas.
+   * canvas. A "IViewport" can possibly be accessed from several
+   * threads depending on the rendering back-end (e.g. in SDL or Qt):
+   * The "ILock" subclass implements the locking mechanism to modify
+   * the content of the scene. 
+   *
+   * NB: The lock must be a "recursive_mutex", as the viewport
+   * controller can lock it a second time (TODO - Why so?).
    **/  
   class IViewport : public boost::noncopyable
   {
   public:
+    class ILock : public boost::noncopyable
+    {
+    public:
+      virtual ~ILock()
+      {
+      }
+
+      virtual Scene2D& GetScene() = 0;
+
+      virtual ScenePoint2D GetPixelCenterCoordinates(int x, int y) = 0;
+
+      virtual bool HasCompositor() const = 0;
+
+      virtual ICompositor& GetCompositor() = 0;
+    };   
+    
     virtual ~IViewport()
     {
     }
 
-    virtual Scene2D& GetScene() = 0;
-
     virtual void Refresh() = 0;
 
-    virtual ScenePoint2D GetPixelCenterCoordinates(int x, int y) const = 0;
-
-    virtual bool HasCompositor() const = 0;
-
-    virtual ICompositor& GetCompositor() = 0;
-
-    virtual const ICompositor& GetCompositor() const = 0;
+    virtual ILock* Lock() = 0;
   };
 }