comparison Framework/Viewport/SdlViewport.cpp @ 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 1a08b779be64
children be614695747d
comparison
equal deleted inserted replaced
1329:8d3e669f01a2 1331:ab81ee8fce1f
20 20
21 #include "SdlViewport.h" 21 #include "SdlViewport.h"
22 22
23 #include <Core/OrthancException.h> 23 #include <Core/OrthancException.h>
24 24
25 #include <boost/make_shared.hpp>
26
25 namespace OrthancStone 27 namespace OrthancStone
26 { 28 {
27 ICompositor& SdlViewport::SdlLock::GetCompositor() 29 ICompositor& SdlViewport::SdlLock::GetCompositor()
28 { 30 {
29 if (that_.compositor_.get() == NULL) 31 if (that_.compositor_.get() == NULL)
46 } 48 }
47 49
48 compositor_.reset(compositor); 50 compositor_.reset(compositor);
49 } 51 }
50 52
51 SdlViewport::SdlViewport() : 53 SdlViewport::SdlViewport()
52 controller_(new ViewportController(*this))
53 { 54 {
54 refreshEvent_ = SDL_RegisterEvents(1); 55 refreshEvent_ = SDL_RegisterEvents(1);
55 56
56 if (refreshEvent_ == static_cast<uint32_t>(-1)) 57 if (refreshEvent_ == static_cast<uint32_t>(-1))
57 { 58 {
58 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); 59 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
59 } 60 }
60 } 61 }
61 62
62 SdlViewport::SdlViewport(boost::weak_ptr<UndoStack> undoStackW) : 63 void SdlViewport::PostConstructor()
63 controller_(new ViewportController(*this,undoStackW)) 64 {
64 { 65 controller_ = boost::make_shared<ViewportController>(shared_from_this());
65 refreshEvent_ = SDL_RegisterEvents(1); 66 }
66 67
67 if (refreshEvent_ == static_cast<uint32_t>(-1))
68 {
69 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
70 }
71 }
72
73 void SdlViewport::SendRefreshEvent() 68 void SdlViewport::SendRefreshEvent()
74 { 69 {
75 SDL_Event event; 70 SDL_Event event;
76 SDL_memset(&event, 0, sizeof(event)); 71 SDL_memset(&event, 0, sizeof(event));
77 event.type = refreshEvent_; 72 event.type = refreshEvent_;
86 context_(title, width, height, allowDpiScaling) 81 context_(title, width, height, allowDpiScaling)
87 { 82 {
88 AcquireCompositor(new OpenGLCompositor(context_)); // (*) 83 AcquireCompositor(new OpenGLCompositor(context_)); // (*)
89 } 84 }
90 85
91 SdlOpenGLViewport::SdlOpenGLViewport(const char* title, 86 boost::shared_ptr<SdlOpenGLViewport> SdlOpenGLViewport::Create(const char* title,
92 boost::weak_ptr<UndoStack> undoStackW, 87 unsigned int width,
93 unsigned int width, 88 unsigned int height,
94 unsigned int height, 89 bool allowDpiScaling)
95 bool allowDpiScaling) : 90 {
96 SdlViewport(undoStackW), 91 boost::shared_ptr<SdlOpenGLViewport> that =
97 context_(title, width, height, allowDpiScaling) 92 boost::shared_ptr<SdlOpenGLViewport>(new SdlOpenGLViewport(title, width, height, allowDpiScaling));
98 { 93 that->SdlViewport::PostConstructor();
99 AcquireCompositor(new OpenGLCompositor(context_)); // (*) 94 return that;
100 } 95 }
101 96
102 SdlOpenGLViewport::~SdlOpenGLViewport() 97 SdlOpenGLViewport::~SdlOpenGLViewport()
103 { 98 {
104 // Make sure that the "OpenGLCompositor" is destroyed BEFORE the 99 // Make sure that the "OpenGLCompositor" is destroyed BEFORE the