comparison Framework/Viewport/WebGLViewportsRegistry.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 c38c89684d83
children
comparison
equal deleted inserted replaced
1329:8d3e669f01a2 1331:ab81ee8fce1f
21 21
22 #pragma once 22 #pragma once
23 23
24 #include "WebGLViewport.h" 24 #include "WebGLViewport.h"
25 25
26 #include <boost/enable_shared_from_this.hpp>
27
26 namespace OrthancStone 28 namespace OrthancStone
27 { 29 {
28 /** 30 /**
29 * This singleton class must be used if many WebGL viewports are 31 * This singleton class must be used if many WebGL viewports are
30 * created by the higher-level application, implying possible loss 32 * created by the higher-level application, implying possible loss
31 * of WebGL contexts. The object will run an infinite update loop 33 * of WebGL contexts. The object will run an infinite update loop
32 * that checks whether all the WebGL context are still valid (not 34 * that checks whether all the WebGL context are still valid (not
33 * lost). If some WebGL context is lost, it is automatically 35 * lost). If some WebGL context is lost, it is automatically
34 * reinitialized by created a fresh HTML5 canvas. 36 * reinitialized by created a fresh HTML5 canvas.
35 **/ 37 **/
36 class WebGLViewportsRegistry : public boost::noncopyable 38 class WebGLViewportsRegistry : public boost::noncopyable,
39 public boost::enable_shared_from_this<WebGLViewportsRegistry>
37 { 40 {
38 private: 41 private:
39 typedef std::map<std::string, boost::shared_ptr<WebGLViewport> > Viewports; 42 typedef std::map<std::string, boost::shared_ptr<WebGLViewport> > Viewports;
40 43
41 double timeoutMS_; 44 double timeoutMS_;
42 Viewports viewports_; 45 Viewports viewports_;
46 long timeOutID_;
43 47
44 void LaunchTimer(); 48 void LaunchTimer();
45 49
46 void OnTimeout(); 50 void OnTimeout();
47 51
48 static void OnTimeoutCallback(void *userData); 52 static void OnTimeoutCallback(void *userData);
49 53
50 public: 54 public:
51 WebGLViewportsRegistry(double timeoutMS /* in milliseconds */); 55 WebGLViewportsRegistry(double timeoutMS /* in milliseconds */);
52 56
53 ~WebGLViewportsRegistry() 57 ~WebGLViewportsRegistry();
54 {
55 Clear();
56 }
57 58
58 boost::shared_ptr<WebGLViewport> Add(const std::string& canvasId); 59 boost::shared_ptr<WebGLViewport> Add(const std::string& canvasId);
59 60
60 void Remove(const std::string& canvasId); 61 void Remove(const std::string& canvasId);
61 62
62 void Clear(); 63 void Clear();
63 64
64 class Accessor : public boost::noncopyable 65 class Accessor : public boost::noncopyable
65 { 66 {
66 private: 67 private:
67 WebGLViewportsRegistry& that_; 68 WebGLViewportsRegistry& that_;
68 std::unique_ptr<IViewport::ILock> lock_; 69 std::unique_ptr<IViewport::ILock> lock_;
69 70
70 public: 71 public:
71 Accessor(WebGLViewportsRegistry& that, 72 Accessor(WebGLViewportsRegistry& that,
72 const std::string& canvasId); 73 const std::string& canvasId);