comparison Framework/Viewport/SdlViewport.h @ 1331:ab81ee8fce1f broker

- Viewport is not passed and stored as a shared_ptr instead of raw reference. - ViewportController can now be injected with an undo stack (not a ctor param anymore, as a preparation for the move of the undo stack to an interactor) - Added (temp) flag to disable emscripten events registration in the WebAssemblyViewport (because legacy client code deals with them directly) - Added emscripten_clear_timeout in ~WebGLViewportsRegistry - Removed GenericToolbox::HoldingRef whose responsibility is better served with proper callback un-registration.
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 30 Mar 2020 14:23:46 +0200
parents adf234ecaa00
children be614695747d
comparison
equal deleted inserted replaced
1329:8d3e669f01a2 1331:ab81ee8fce1f
51 51
52 namespace OrthancStone 52 namespace OrthancStone
53 { 53 {
54 class UndoStack; 54 class UndoStack;
55 55
56 class SdlViewport : public IViewport 56 class SdlViewport : public IViewport,
57 public boost::enable_shared_from_this<SdlViewport>
57 { 58 {
58 private: 59 private:
59 boost::recursive_mutex mutex_; 60 boost::recursive_mutex mutex_;
60 uint32_t refreshEvent_; 61 uint32_t refreshEvent_;
61 boost::shared_ptr<ViewportController> controller_; 62 boost::shared_ptr<ViewportController> controller_;
62 std::unique_ptr<ICompositor> compositor_; 63 std::unique_ptr<ICompositor> compositor_;
63 64
64 void SendRefreshEvent(); 65 void SendRefreshEvent();
65 66
66 protected: 67 protected:
67 class SdlLock : public ILock 68 class SdlLock : public ILock
100 compositor_.reset(); 101 compositor_.reset();
101 } 102 }
102 103
103 void AcquireCompositor(ICompositor* compositor /* takes ownership */); 104 void AcquireCompositor(ICompositor* compositor /* takes ownership */);
104 105
106 protected:
107 SdlViewport();
108 void PostConstructor();
109
105 public: 110 public:
106 SdlViewport();
107 SdlViewport(boost::weak_ptr<UndoStack> undoStackW);
108 111
109 bool IsRefreshEvent(const SDL_Event& event) const 112 bool IsRefreshEvent(const SDL_Event& event) const
110 { 113 {
111 return (event.type == refreshEvent_); 114 return (event.type == refreshEvent_);
112 } 115 }
129 class SdlOpenGLViewport : public SdlViewport 132 class SdlOpenGLViewport : public SdlViewport
130 { 133 {
131 private: 134 private:
132 SdlOpenGLContext context_; 135 SdlOpenGLContext context_;
133 136
134 public: 137 private:
135 SdlOpenGLViewport(const char* title, 138 SdlOpenGLViewport(const char* title,
136 unsigned int width, 139 unsigned int width,
137 unsigned int height, 140 unsigned int height,
138 bool allowDpiScaling = true); 141 bool allowDpiScaling = true);
142 public:
143 static boost::shared_ptr<SdlOpenGLViewport> Create(const char* title,
144 unsigned int width,
145 unsigned int height,
146 bool allowDpiScaling = true);
139 147
140 SdlOpenGLViewport(const char* title,
141 boost::weak_ptr<UndoStack> undoStackW,
142 unsigned int width,
143 unsigned int height,
144 bool allowDpiScaling = true);
145 148
146 virtual ~SdlOpenGLViewport(); 149 virtual ~SdlOpenGLViewport();
147 150
148 virtual void Paint() ORTHANC_OVERRIDE; 151 virtual void Paint() ORTHANC_OVERRIDE;
149 152
160 SdlWindow window_; 163 SdlWindow window_;
161 SDL_Surface* sdlSurface_; 164 SDL_Surface* sdlSurface_;
162 165
163 void CreateSdlSurfaceFromCompositor(CairoCompositor& compositor); 166 void CreateSdlSurfaceFromCompositor(CairoCompositor& compositor);
164 167
165 public: 168 private:
166 SdlCairoViewport(const char* title, 169 SdlCairoViewport(const char* title,
167 unsigned int width, 170 unsigned int width,
168 unsigned int height, 171 unsigned int height,
169 bool allowDpiScaling = true); 172 bool allowDpiScaling = true);
173 public:
174 static boost::shared_ptr<SdlCairoViewport> Create(const char* title,
175 unsigned int width,
176 unsigned int height,
177 bool allowDpiScaling = true);
178
170 179
171 virtual ~SdlCairoViewport(); 180 virtual ~SdlCairoViewport();
172 181
173 virtual void Paint() ORTHANC_OVERRIDE; 182 virtual void Paint() ORTHANC_OVERRIDE;
174 183