comparison Applications/Platforms/WebAssembly/WebGLViewportsRegistry.h @ 1591:5887a4f8594b

moving platform-specific files out of the "OrthancStone" folder
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 23 Oct 2020 13:15:03 +0200
parents OrthancStone/Sources/Viewport/WebGLViewportsRegistry.h@85e117739eca
children 9ac2a65d4172
comparison
equal deleted inserted replaced
1590:7b963bccafef 1591:5887a4f8594b
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-2020 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #pragma once
23
24 #include "WebGLViewport.h"
25
26 #include <boost/enable_shared_from_this.hpp>
27
28 namespace OrthancStone
29 {
30 /**
31 * This singleton class must be used if many WebGL viewports are
32 * created by the higher-level application, implying possible loss
33 * of WebGL contexts. The object will run an infinite update loop
34 * that checks whether all the WebGL context are still valid (not
35 * lost). If some WebGL context is lost, it is automatically
36 * reinitialized by created a fresh HTML5 canvas.
37 **/
38 class WebGLViewportsRegistry : public boost::noncopyable,
39 public boost::enable_shared_from_this<WebGLViewportsRegistry>
40 {
41 private:
42 typedef std::map<std::string, boost::shared_ptr<WebGLViewport> > Viewports;
43
44 double timeoutMS_;
45 Viewports viewports_;
46 long timeOutID_;
47
48 void LaunchTimer();
49
50 void OnTimeout();
51
52 static void OnTimeoutCallback(void *userData);
53
54 public:
55 explicit WebGLViewportsRegistry(double timeoutMS /* in milliseconds */);
56
57 ~WebGLViewportsRegistry();
58
59 boost::shared_ptr<WebGLViewport> Add(const std::string& canvasId);
60
61 void Remove(const std::string& canvasId);
62
63 void Clear();
64
65 class Accessor : public boost::noncopyable
66 {
67 private:
68 WebGLViewportsRegistry& that_;
69 std::unique_ptr<IViewport::ILock> lock_;
70
71 public:
72 Accessor(WebGLViewportsRegistry& that,
73 const std::string& canvasId);
74
75 bool IsValid() const
76 {
77 return lock_.get() != NULL;
78 }
79
80 IViewport::ILock& GetViewport() const;
81 };
82
83
84
85 static void FinalizeGlobalRegistry();
86
87 static void SetGlobalRegistryTimeout(double timeout);
88
89 static WebGLViewportsRegistry& GetGlobalRegistry();
90 };
91 }