Mercurial > hg > orthanc-stone
comparison Framework/Viewport/SdlViewport.h @ 1307:8a28a9bf8876 broker
ViewportController now gets a ref to its parent viewport for proper lock usage
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 04 Mar 2020 10:07:37 +0100 |
parents | 7ec8fea061b9 |
children | adf234ecaa00 |
comparison
equal
deleted
inserted
replaced
1306:fef1ec42a7db | 1307:8a28a9bf8876 |
---|---|
41 #include "../Scene2D/CairoCompositor.h" | 41 #include "../Scene2D/CairoCompositor.h" |
42 #include "IViewport.h" | 42 #include "IViewport.h" |
43 | 43 |
44 #include <SDL_events.h> | 44 #include <SDL_events.h> |
45 | 45 |
46 // TODO: required for UndoStack injection | |
47 // I don't like it either :) | |
48 #include <boost/weak_ptr.hpp> | |
49 | |
50 #include <boost/thread/recursive_mutex.hpp> | |
51 | |
46 namespace OrthancStone | 52 namespace OrthancStone |
47 { | 53 { |
54 class UndoStack; | |
55 | |
48 class SdlViewport : public IViewport | 56 class SdlViewport : public IViewport |
49 { | 57 { |
50 private: | 58 private: |
51 boost::mutex mutex_; | 59 boost::recursive_mutex mutex_; |
52 uint32_t refreshEvent_; | 60 uint32_t refreshEvent_; |
53 boost::shared_ptr<ViewportController> controller_; | 61 boost::shared_ptr<ViewportController> controller_; |
54 std::auto_ptr<ICompositor> compositor_; | 62 std::auto_ptr<ICompositor> compositor_; |
55 | 63 |
56 void SendRefreshEvent(); | 64 void SendRefreshEvent(); |
57 | 65 |
58 protected: | 66 protected: |
59 class SdlLock : public ILock | 67 class SdlLock : public ILock |
60 { | 68 { |
61 private: | 69 private: |
62 SdlViewport& that_; | 70 SdlViewport& that_; |
63 boost::mutex::scoped_lock lock_; | 71 boost::recursive_mutex::scoped_lock lock_; |
64 | 72 |
65 public: | 73 public: |
66 SdlLock(SdlViewport& that) : | 74 SdlLock(SdlViewport& that) : |
67 that_(that), | 75 that_(that), |
68 lock_(that.mutex_) | 76 lock_(that.mutex_) |
94 | 102 |
95 void AcquireCompositor(ICompositor* compositor /* takes ownership */); | 103 void AcquireCompositor(ICompositor* compositor /* takes ownership */); |
96 | 104 |
97 public: | 105 public: |
98 SdlViewport(); | 106 SdlViewport(); |
107 SdlViewport(boost::weak_ptr<UndoStack> undoStackW); | |
99 | 108 |
100 bool IsRefreshEvent(const SDL_Event& event) const | 109 bool IsRefreshEvent(const SDL_Event& event) const |
101 { | 110 { |
102 return (event.type == refreshEvent_); | 111 return (event.type == refreshEvent_); |
103 } | 112 } |
122 private: | 131 private: |
123 SdlOpenGLContext context_; | 132 SdlOpenGLContext context_; |
124 | 133 |
125 public: | 134 public: |
126 SdlOpenGLViewport(const char* title, | 135 SdlOpenGLViewport(const char* title, |
136 unsigned int width, | |
137 unsigned int height, | |
138 bool allowDpiScaling = true); | |
139 | |
140 SdlOpenGLViewport(const char* title, | |
141 boost::weak_ptr<UndoStack> undoStackW, | |
127 unsigned int width, | 142 unsigned int width, |
128 unsigned int height, | 143 unsigned int height, |
129 bool allowDpiScaling = true); | 144 bool allowDpiScaling = true); |
130 | 145 |
131 virtual ~SdlOpenGLViewport(); | 146 virtual ~SdlOpenGLViewport(); |