Mercurial > hg > orthanc-stone
annotate Framework/Viewport/WebAssemblyViewport.h @ 1474:d1dde1f86d4a
fix build of wasm samples
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 15 Jun 2020 18:21:34 +0200 |
parents | 30deba7bc8e2 |
children | 6e43cac7833c |
rev | line source |
---|---|
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Stone of Orthanc |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
1270
2d8ab34c8c91
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1239
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
16 * |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 **/ |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 #pragma once |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
24 #if !defined(ORTHANC_ENABLE_WASM) |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
25 # error Macro ORTHANC_ENABLE_WASM must be defined |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
26 #endif |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
27 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
28 #if ORTHANC_ENABLE_WASM != 1 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
29 # error This file can only be used if targeting WebAssembly |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
30 #endif |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
31 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
32 #include "IViewport.h" |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
33 |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1351
diff
changeset
|
34 #include <Compatibility.h> |
1333
5b731e176236
Added missing #include directives
Benjamin Golinvaux <bgo@osimis.io>
parents:
1331
diff
changeset
|
35 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
36 #include <emscripten.h> |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
37 #include <emscripten/html5.h> |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 |
1333
5b731e176236
Added missing #include directives
Benjamin Golinvaux <bgo@osimis.io>
parents:
1331
diff
changeset
|
39 #include <memory> |
5b731e176236
Added missing #include directives
Benjamin Golinvaux <bgo@osimis.io>
parents:
1331
diff
changeset
|
40 #include <string> |
5b731e176236
Added missing #include directives
Benjamin Golinvaux <bgo@osimis.io>
parents:
1331
diff
changeset
|
41 |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 namespace OrthancStone |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 { |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
44 class WebAssemblyViewport : public IViewport, |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
45 public boost::enable_shared_from_this<WebAssemblyViewport> |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
46 |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 { |
1055
af456106576c
moving GetCanvasIdentifier from IViewport to WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
48 private: |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
49 class WasmLock; |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
50 |
1351
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
51 std::string canvasId_; |
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
52 std::string canvasCssSelector_; |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
53 std::unique_ptr<ICompositor> compositor_; |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
54 std::unique_ptr<ViewportController> controller_; |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
55 std::unique_ptr<IViewportInteractor> interactor_; |
1346
df8bf351c23f
The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1333
diff
changeset
|
56 bool enableEmscriptenMouseEvents_; |
1055
af456106576c
moving GetCanvasIdentifier from IViewport to WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
57 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
58 static EM_BOOL OnRequestAnimationFrame(double time, void *userData); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
59 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
60 static EM_BOOL OnResize(int eventType, const EmscriptenUiEvent *uiEvent, void *userData); |
1055
af456106576c
moving GetCanvasIdentifier from IViewport to WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
61 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
62 static EM_BOOL OnMouseDown(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
63 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
64 static EM_BOOL OnMouseMove(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
65 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
66 static EM_BOOL OnMouseUp(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
67 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
68 protected: |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
69 void Invalidate(); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
70 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
71 void ClearCompositor() |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
905
diff
changeset
|
72 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
73 compositor_.reset(); |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
905
diff
changeset
|
74 } |
1055
af456106576c
moving GetCanvasIdentifier from IViewport to WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
75 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
76 bool HasCompositor() const |
1055
af456106576c
moving GetCanvasIdentifier from IViewport to WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
77 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
78 return compositor_.get() != NULL; |
1055
af456106576c
moving GetCanvasIdentifier from IViewport to WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
79 } |
af456106576c
moving GetCanvasIdentifier from IViewport to WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
80 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
81 void AcquireCompositor(ICompositor* compositor /* takes ownership */); |
1239
ce3052f28f2e
Added a lazy size update system in WebAssemblyOpenGLViewport::Refresh
Benjamin Golinvaux <bgo@osimis.io>
parents:
1072
diff
changeset
|
82 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
83 virtual void Paint(ICompositor& compositor, |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
84 ViewportController& controller) = 0; |
1055
af456106576c
moving GetCanvasIdentifier from IViewport to WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
85 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
86 virtual void UpdateSize(ICompositor& compositor) = 0; |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
88 /** |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
89 The second argument is temporary and should be deleted once the migration |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
90 to interactors is finished. |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
91 */ |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
92 WebAssemblyViewport(const std::string& canvasId, |
1346
df8bf351c23f
The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1333
diff
changeset
|
93 bool enableEmscriptenMouseEvents = true); |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
94 |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
95 void PostConstructor(); |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
96 |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 public: |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
98 virtual ILock* Lock() ORTHANC_OVERRIDE; |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
99 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
100 ~WebAssemblyViewport(); |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
101 |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
103 /** |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
104 This method takes ownership |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
105 */ |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
106 void AcquireInteractor(IViewportInteractor* interactor); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1072
diff
changeset
|
107 |
1351
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
108 const std::string& GetCanvasId() const |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 { |
1351
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
110 return canvasId_; |
1072
391fb6d6905d
OrthancMultiframeVolumeLoader asks volume image to compute range +
Benjamin Golinvaux <bgo@osimis.io>
parents:
1055
diff
changeset
|
111 } |
391fb6d6905d
OrthancMultiframeVolumeLoader asks volume image to compute range +
Benjamin Golinvaux <bgo@osimis.io>
parents:
1055
diff
changeset
|
112 |
1351
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
113 /** |
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
114 emscripten functions requires the css selector for the canvas. This is |
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
115 different from the canvas id (the syntax is '#mycanvasid') |
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
116 */ |
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
117 const std::string& GetCanvasCssSelector() const |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
905
diff
changeset
|
118 { |
1351
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
119 return canvasCssSelector_; |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
905
diff
changeset
|
120 } |
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
905
diff
changeset
|
121 }; |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 } |