annotate Framework/Viewport/WebGLViewportsRegistry.h @ 1232:a28861abf888 broker

viewports for WebAssembly
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 09 Dec 2019 17:46:33 +0100
parents
children e71ee3e88448
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1232
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #pragma once
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "WebGLViewport.h"
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 namespace OrthancStone
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 /**
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * This singleton class must be used if many WebGL viewports are
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * created by the higher-level application, implying possible loss
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 * of WebGL contexts. The object will run an infinite update loop
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 * that checks whether all the WebGL context are still valid (not
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 * lost). If some WebGL context is lost, it is automatically
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 * reinitialized by created a fresh HTML5 canvas.
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 **/
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 class WebGLViewportsRegistry : public boost::noncopyable
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 private:
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 typedef std::map<std::string, WebGLViewport*> Viewports;
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 unsigned int timeoutSeconds_;
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 Viewports viewports_;
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 void LaunchTimer();
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 void OnTimeout();
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 static void OnTimeoutCallback(void *userData);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 public:
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 WebGLViewportsRegistry(unsigned int timeoutSeconds);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 ~WebGLViewportsRegistry();
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 void Add(const std::string& canvasId);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 void Remove(const std::string& canvasId);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 class Accessor : public boost::noncopyable
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 private:
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 WebGLViewportsRegistry& that_;
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 std::auto_ptr<IViewport::ILock> lock_;
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 public:
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 Accessor(WebGLViewportsRegistry& that,
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 const std::string& canvasId);
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 bool IsValid() const
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 return lock_.get() != NULL;
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 }
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 IViewport::ILock& GetViewport() const;
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 };
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 };
a28861abf888 viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }