Mercurial > hg > orthanc-stone
diff Framework/Viewport/SdlViewport.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 | af456106576c |
children | 6009c59d8676 |
line wrap: on
line diff
--- a/Framework/Viewport/SdlViewport.h Fri Nov 29 11:03:41 2019 +0100 +++ b/Framework/Viewport/SdlViewport.h Fri Nov 29 21:22:21 2019 +0100 @@ -45,18 +45,14 @@ { class SdlViewport : public ViewportBase { + protected: + boost::mutex mutex_; + public: SdlViewport() { } - SdlViewport(boost::shared_ptr<Scene2D>& scene) : - ViewportBase(scene) - { - } - - virtual SdlWindow& GetWindow() = 0; - virtual void UpdateSize(unsigned int width, unsigned int height) = 0; }; @@ -66,52 +62,87 @@ { private: SdlOpenGLContext context_; - std::auto_ptr<OpenGLCompositor> compositor_; + std::auto_ptr<OpenGLCompositor> compositor_; + class SdlLock : public LockBase + { + private: + SdlOpenGLViewport& that_; + boost::mutex::scoped_lock lock_; + + public: + SdlLock(SdlOpenGLViewport& viewport) : + LockBase(viewport), + that_(viewport), + lock_(viewport.mutex_) + { + } + + virtual bool HasCompositor() const ORTHANC_OVERRIDE + { + return true; + } + + virtual ICompositor& GetCompositor() ORTHANC_OVERRIDE + { + return *that_.compositor_; + } + }; + public: SdlOpenGLViewport(const char* title, unsigned int width, unsigned int height, bool allowDpiScaling = true); - SdlOpenGLViewport(const char* title, - unsigned int width, - unsigned int height, - boost::shared_ptr<Scene2D>& scene, - bool allowDpiScaling = true); + virtual void Refresh() ORTHANC_OVERRIDE; - virtual SdlWindow& GetWindow() ORTHANC_OVERRIDE + virtual ILock* Lock() ORTHANC_OVERRIDE { - return context_.GetWindow(); + return new SdlLock(*this); } - virtual void Refresh() ORTHANC_OVERRIDE; - virtual void UpdateSize(unsigned int width, unsigned int height) ORTHANC_OVERRIDE { // nothing to do in OpenGL, the OpenGLCompositor::UpdateSize will be called automatically } - - virtual bool HasCompositor() const ORTHANC_OVERRIDE - { - return true; - } - - virtual ICompositor& GetCompositor() ORTHANC_OVERRIDE - { - return *compositor_.get(); - } }; class SdlCairoViewport : public SdlViewport { private: + class SdlLock : public LockBase + { + private: + SdlCairoViewport& that_; + boost::mutex::scoped_lock lock_; + + public: + SdlLock(SdlCairoViewport& viewport) : + LockBase(viewport), + that_(viewport), + lock_(viewport.mutex_) + { + } + + virtual bool HasCompositor() const ORTHANC_OVERRIDE + { + return true; + } + + virtual ICompositor& GetCompositor() ORTHANC_OVERRIDE + { + return that_.compositor_; + } + }; + SdlWindow window_; CairoCompositor compositor_; SDL_Surface* sdlSurface_; - private: + void RefreshInternal(); + void UpdateSdlSurfaceSize(unsigned int width, unsigned int height); @@ -121,32 +152,11 @@ 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 SdlWindow& GetWindow() ORTHANC_OVERRIDE - { - return window_; - } - virtual void Refresh() ORTHANC_OVERRIDE; virtual void UpdateSize(unsigned int width, unsigned int height) ORTHANC_OVERRIDE; - - virtual bool HasCompositor() const ORTHANC_OVERRIDE - { - return true; - } - - virtual ICompositor& GetCompositor() ORTHANC_OVERRIDE - { - return compositor_; - } }; }