Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Platforms/WebAssembly/WebGLViewportsRegistry.h @ 1899:917500c46fe0
moved the Platform folder from the Applications folder to the Stone library itself
author | Alain Mazy <am@osimis.io> |
---|---|
date | Sat, 29 Jan 2022 12:47:32 +0100 |
parents | |
children | 07964689cb0b |
comparison
equal
deleted
inserted
replaced
1898:a5e54bd87b25 | 1899:917500c46fe0 |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium | |
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium | |
7 * | |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU Lesser General Public License | |
10 * as published by the Free Software Foundation, either version 3 of | |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * Lesser General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Lesser General Public | |
19 * License along with this program. If not, see | |
20 * <http://www.gnu.org/licenses/>. | |
21 **/ | |
22 | |
23 | |
24 #pragma once | |
25 | |
26 #include "WebGLViewport.h" | |
27 | |
28 #include <boost/enable_shared_from_this.hpp> | |
29 | |
30 namespace OrthancStone | |
31 { | |
32 /** | |
33 * This singleton class must be used if many WebGL viewports are | |
34 * created by the higher-level application, implying possible loss | |
35 * of WebGL contexts. The object will run an infinite update loop | |
36 * that checks whether all the WebGL context are still valid (not | |
37 * lost). If some WebGL context is lost, it is automatically | |
38 * reinitialized by created a fresh HTML5 canvas. | |
39 **/ | |
40 class WebGLViewportsRegistry : public boost::noncopyable, | |
41 public boost::enable_shared_from_this<WebGLViewportsRegistry> | |
42 { | |
43 private: | |
44 typedef std::map<std::string, boost::shared_ptr<WebGLViewport> > Viewports; | |
45 | |
46 double timeoutMS_; | |
47 Viewports viewports_; | |
48 long timeOutID_; | |
49 | |
50 void LaunchTimer(); | |
51 | |
52 void OnTimeout(); | |
53 | |
54 static void OnTimeoutCallback(void *userData); | |
55 | |
56 public: | |
57 explicit WebGLViewportsRegistry(double timeoutMS /* in milliseconds */); | |
58 | |
59 ~WebGLViewportsRegistry(); | |
60 | |
61 boost::shared_ptr<WebGLViewport> Add(const std::string& canvasId); | |
62 | |
63 void Remove(const std::string& canvasId); | |
64 | |
65 void Clear(); | |
66 | |
67 class Accessor : public boost::noncopyable | |
68 { | |
69 private: | |
70 WebGLViewportsRegistry& that_; | |
71 std::unique_ptr<IViewport::ILock> lock_; | |
72 | |
73 public: | |
74 Accessor(WebGLViewportsRegistry& that, | |
75 const std::string& canvasId); | |
76 | |
77 bool IsValid() const | |
78 { | |
79 return lock_.get() != NULL; | |
80 } | |
81 | |
82 IViewport::ILock& GetViewport() const; | |
83 }; | |
84 | |
85 | |
86 | |
87 static void FinalizeGlobalRegistry(); | |
88 | |
89 static void SetGlobalRegistryTimeout(double timeout); | |
90 | |
91 static WebGLViewportsRegistry& GetGlobalRegistry(); | |
92 }; | |
93 } |