Mercurial > hg > orthanc-stone
annotate Applications/Platforms/WebAssembly/WebAssemblyViewport.cpp @ 1870:3889ae96d2e9
added copyright UCLouvain
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 11 Jan 2022 11:04:09 +0100 |
parents | fdc6a8089eb9 |
children | 7053b8a0aaec |
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 |
1739
9ac2a65d4172
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1687
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
1870
3889ae96d2e9
added copyright UCLouvain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1811
diff
changeset
|
6 * Copyright (C) 2021-2021 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * 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
|
10 * as published by the Free Software Foundation, either version 3 of |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * the License, or (at your option) any later version. |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * 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
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * Affero General Public License for more details. |
942
685c9a2d115f
Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents:
910
diff
changeset
|
17 * |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * 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
|
19 * 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
|
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 |
1549
a48ae10857b1
packaging of the WebAssembly module
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
23 #if defined(ORTHANC_BUILDING_STONE_LIBRARY) && ORTHANC_BUILDING_STONE_LIBRARY == 1 |
a48ae10857b1
packaging of the WebAssembly module
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
24 # include "WebAssemblyViewport.h" |
1591
5887a4f8594b
moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1578
diff
changeset
|
25 # include "../../../OrthancStone/Sources/Scene2DViewport/ViewportController.h" |
5887a4f8594b
moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1578
diff
changeset
|
26 # include "../../../OrthancStone/Sources/Toolbox/GenericToolbox.h" |
5887a4f8594b
moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1578
diff
changeset
|
27 # include "../../../OrthancStone/Sources/Viewport/DefaultViewportInteractor.h" |
1549
a48ae10857b1
packaging of the WebAssembly module
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
28 #else |
a48ae10857b1
packaging of the WebAssembly module
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
29 // This is the case when using the WebAssembly side module, and this |
a48ae10857b1
packaging of the WebAssembly module
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
30 // source file must be compiled within the WebAssembly main module |
a48ae10857b1
packaging of the WebAssembly module
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
31 # include <Viewport/WebAssemblyViewport.h> |
a48ae10857b1
packaging of the WebAssembly module
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
32 # include <Toolbox/GenericToolbox.h> |
1558 | 33 # include <Scene2DViewport/ViewportController.h> |
34 # include <Viewport/DefaultViewportInteractor.h> | |
1549
a48ae10857b1
packaging of the WebAssembly module
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
35 #endif |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
36 |
1557 | 37 |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1356
diff
changeset
|
38 #include <OrthancException.h> |
1050 | 39 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
40 #include <boost/make_shared.hpp> |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
41 #include <boost/enable_shared_from_this.hpp> |
1576
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
42 #include <boost/math/special_functions/round.hpp> |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 namespace OrthancStone |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
46 static void ConvertMouseEvent(PointerEvent& target, |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
47 const EmscriptenMouseEvent& source, |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
48 const ICompositor& compositor) |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
50 int x = static_cast<int>(source.targetX); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
51 int y = static_cast<int>(source.targetY); |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
53 switch (source.button) |
997
d6b83ee3a950
fix WebAssemblyOpenGLViewport::UpdateSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
964
diff
changeset
|
54 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
55 case 0: |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
56 target.SetMouseButton(MouseButton_Left); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
57 break; |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
59 case 1: |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
60 target.SetMouseButton(MouseButton_Middle); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
61 break; |
997
d6b83ee3a950
fix WebAssemblyOpenGLViewport::UpdateSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
964
diff
changeset
|
62 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
63 case 2: |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
64 target.SetMouseButton(MouseButton_Right); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
65 break; |
942
685c9a2d115f
Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents:
910
diff
changeset
|
66 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
67 default: |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
68 target.SetMouseButton(MouseButton_None); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
69 break; |
997
d6b83ee3a950
fix WebAssemblyOpenGLViewport::UpdateSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
964
diff
changeset
|
70 } |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
71 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
72 target.AddPosition(compositor.GetPixelCenterCoordinates(x, y)); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
73 target.SetAltModifier(source.altKey); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
74 target.SetControlModifier(source.ctrlKey); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
75 target.SetShiftModifier(source.shiftKey); |
1054
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
76 } |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
77 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
78 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
79 class WebAssemblyViewport::WasmLock : public ILock |
1239
ce3052f28f2e
Added a lazy size update system in WebAssemblyOpenGLViewport::Refresh
Benjamin Golinvaux <bgo@osimis.io>
parents:
1054
diff
changeset
|
80 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
81 private: |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
82 WebAssemblyViewport& that_; |
1239
ce3052f28f2e
Added a lazy size update system in WebAssemblyOpenGLViewport::Refresh
Benjamin Golinvaux <bgo@osimis.io>
parents:
1054
diff
changeset
|
83 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
84 public: |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
85 WasmLock(WebAssemblyViewport& that) : |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
86 that_(that) |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
87 { |
1239
ce3052f28f2e
Added a lazy size update system in WebAssemblyOpenGLViewport::Refresh
Benjamin Golinvaux <bgo@osimis.io>
parents:
1054
diff
changeset
|
88 } |
ce3052f28f2e
Added a lazy size update system in WebAssemblyOpenGLViewport::Refresh
Benjamin Golinvaux <bgo@osimis.io>
parents:
1054
diff
changeset
|
89 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
90 virtual bool HasCompositor() const ORTHANC_OVERRIDE |
1239
ce3052f28f2e
Added a lazy size update system in WebAssemblyOpenGLViewport::Refresh
Benjamin Golinvaux <bgo@osimis.io>
parents:
1054
diff
changeset
|
91 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
92 return that_.compositor_.get() != NULL; |
1239
ce3052f28f2e
Added a lazy size update system in WebAssemblyOpenGLViewport::Refresh
Benjamin Golinvaux <bgo@osimis.io>
parents:
1054
diff
changeset
|
93 } |
ce3052f28f2e
Added a lazy size update system in WebAssemblyOpenGLViewport::Refresh
Benjamin Golinvaux <bgo@osimis.io>
parents:
1054
diff
changeset
|
94 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
95 virtual ICompositor& GetCompositor() ORTHANC_OVERRIDE |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
96 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
97 if (that_.compositor_.get() == NULL) |
1054
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
98 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
99 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
1054
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
100 } |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
101 else |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
102 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
103 return *that_.compositor_; |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
104 } |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
105 } |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
106 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
107 virtual ViewportController& GetController() ORTHANC_OVERRIDE |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
108 { |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
109 assert(that_.controller_); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
110 return *that_.controller_; |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
111 } |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
112 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
113 virtual void Invalidate() ORTHANC_OVERRIDE |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
114 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
115 that_.Invalidate(); |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
116 } |
1576
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
117 |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
118 virtual void RefreshCanvasSize() ORTHANC_OVERRIDE |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
119 { |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
120 that_.RefreshCanvasSize(); |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
121 } |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
122 }; |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
123 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
124 EM_BOOL WebAssemblyViewport::OnRequestAnimationFrame(double time, void *userData) |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
125 { |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
126 LOG(TRACE) << __func__; |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
127 |
1621
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
128 WebAssemblyViewport* that = |
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
129 WebAssemblyViewport::DereferenceObjectCookie(userData); |
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
130 |
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
131 if (that != NULL) |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
132 { |
1621
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
133 if (that->compositor_.get() != NULL && |
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
134 that->controller_ /* should always be true */) |
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
135 { |
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
136 that->Paint(*that->compositor_, *that->controller_); |
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
137 } |
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
138 } |
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
139 else |
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
140 { |
1623
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
141 LOG(TRACE) << "WebAssemblyViewport::OnRequestAnimationFrame: the " << |
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
142 "WebAssemblyViewport is deleted and Paint will not be called."; |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
143 } |
1623
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
144 WebAssemblyViewport::ReleaseObjectCookie(userData); |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
145 LOG(TRACE) << "Exiting: " << __func__; |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
146 return true; |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
147 } |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
148 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
149 EM_BOOL WebAssemblyViewport::OnResize(int eventType, const EmscriptenUiEvent *uiEvent, void *userData) |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
150 { |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
151 LOG(TRACE) << __func__; |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
152 WebAssemblyViewport* that = reinterpret_cast<WebAssemblyViewport*>(userData); |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
153 |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
154 if (that->compositor_.get() != NULL) |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
155 { |
1576
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
156 that->RefreshCanvasSize(); |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
157 that->Invalidate(); |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
158 } |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
159 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
160 LOG(TRACE) << "Exiting: " << __func__; |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
161 return true; |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
162 } |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
163 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
164 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
165 EM_BOOL WebAssemblyViewport::OnMouseDown(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
166 { |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
167 WebAssemblyViewport* that = reinterpret_cast<WebAssemblyViewport*>(userData); |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
168 |
1351
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
169 LOG(TRACE) << "mouse down: " << that->GetCanvasCssSelector(); |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
170 |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
171 if (that->compositor_.get() != NULL && |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
172 that->interactor_.get() != NULL) |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
173 { |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
174 PointerEvent pointer; |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
175 ConvertMouseEvent(pointer, *mouseEvent, *that->compositor_); |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
176 |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
177 that->controller_->HandleMousePress(*that->interactor_, pointer, |
1811
fdc6a8089eb9
hovering of annotations in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
178 that->compositor_->GetCanvasWidth(), |
fdc6a8089eb9
hovering of annotations in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
179 that->compositor_->GetCanvasHeight()); |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
180 that->Invalidate(); |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
181 } |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
182 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
183 LOG(TRACE) << "Exiting: " << __func__; |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
184 return true; |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
185 } |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
186 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
187 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
188 EM_BOOL WebAssemblyViewport::OnMouseMove(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
189 { |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
190 WebAssemblyViewport* that = reinterpret_cast<WebAssemblyViewport*>(userData); |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
191 |
1811
fdc6a8089eb9
hovering of annotations in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
192 if (that->compositor_.get() != NULL) |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
193 { |
1811
fdc6a8089eb9
hovering of annotations in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
194 if (that->controller_->HasActiveTracker()) |
1050 | 195 { |
1811
fdc6a8089eb9
hovering of annotations in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
196 PointerEvent pointer; |
fdc6a8089eb9
hovering of annotations in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
197 ConvertMouseEvent(pointer, *mouseEvent, *that->compositor_); |
fdc6a8089eb9
hovering of annotations in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
198 |
fdc6a8089eb9
hovering of annotations in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
199 if (that->controller_->HandleMouseMove(pointer)) |
fdc6a8089eb9
hovering of annotations in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
200 { |
fdc6a8089eb9
hovering of annotations in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
201 that->Invalidate(); |
fdc6a8089eb9
hovering of annotations in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
202 } |
fdc6a8089eb9
hovering of annotations in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
203 } |
fdc6a8089eb9
hovering of annotations in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
204 else if (that->interactor_.get() != NULL && |
fdc6a8089eb9
hovering of annotations in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
205 that->interactor_->HasMouseHover()) |
fdc6a8089eb9
hovering of annotations in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
206 { |
fdc6a8089eb9
hovering of annotations in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
207 // New in Stone Web viewer 2.0 |
fdc6a8089eb9
hovering of annotations in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
208 PointerEvent pointer; |
fdc6a8089eb9
hovering of annotations in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
209 ConvertMouseEvent(pointer, *mouseEvent, *that->compositor_); |
fdc6a8089eb9
hovering of annotations in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
210 that->interactor_->HandleMouseHover(*that, pointer); |
1050 | 211 } |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
212 } |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
213 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
214 LOG(TRACE) << "Exiting: " << __func__; |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
215 return true; |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
216 } |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
217 |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
218 EM_BOOL WebAssemblyViewport::OnMouseUp(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
219 { |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
220 LOG(TRACE) << __func__; |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
221 WebAssemblyViewport* that = reinterpret_cast<WebAssemblyViewport*>(userData); |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
222 |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
223 if (that->compositor_.get() != NULL) |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
224 { |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
225 PointerEvent pointer; |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
226 ConvertMouseEvent(pointer, *mouseEvent, *that->compositor_); |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
227 that->controller_->HandleMouseRelease(pointer); |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
228 that->Invalidate(); |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
229 } |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
230 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
231 LOG(TRACE) << "Exiting: " << __func__; |
1328
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
232 return true; |
fd616c4a5904
Added mechanism to prevent callbacks from being sent on dead WebAssemblyViewport objects
Benjamin Golinvaux <bgo@osimis.io>
parents:
1318
diff
changeset
|
233 } |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
234 |
1623
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
235 void* WebAssemblyViewport::CreateObjectCookie() |
1621
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
236 { |
1623
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
237 boost::weak_ptr<WebAssemblyViewport>* weakThisPtr = |
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
238 new boost::weak_ptr<WebAssemblyViewport>(); |
1621
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
239 |
1623
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
240 *weakThisPtr = shared_from_this(); |
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
241 |
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
242 void* cookie = reinterpret_cast<void*>(weakThisPtr); |
1621
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
243 |
1623
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
244 LOG(TRACE) << "WebAssemblyViewport::CreateObjectCookie() => cookie = " |
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
245 << cookie << "\n"; |
1621
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
246 |
1623
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
247 return cookie; |
1621
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
248 } |
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
249 |
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
250 WebAssemblyViewport* WebAssemblyViewport::DereferenceObjectCookie(void* cookie) |
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
251 { |
1623
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
252 LOG(TRACE) << "WebAssemblyViewport::DereferenceObjectCookie(cookie = " |
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
253 << cookie << ")\n"; |
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
254 |
1621
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
255 boost::weak_ptr<WebAssemblyViewport>* weakThisPtr = |
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
256 reinterpret_cast<boost::weak_ptr<WebAssemblyViewport>*>(cookie); |
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
257 |
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
258 boost::shared_ptr<WebAssemblyViewport> sharedThis = weakThisPtr->lock(); |
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
259 |
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
260 return sharedThis.get(); |
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
261 } |
575f512cdf48
Used a weak_ptr as a cookie to RequestAnimationFrame to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents:
1618
diff
changeset
|
262 |
1623
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
263 void WebAssemblyViewport::ReleaseObjectCookie(void* cookie) |
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
264 { |
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
265 LOG(TRACE) << "WebAssemblyViewport::ReleaseObjectCookie(cookie = " |
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
266 << cookie << ")\n"; |
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
267 |
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
268 boost::weak_ptr<WebAssemblyViewport>* weakThisPtr = |
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
269 reinterpret_cast<boost::weak_ptr<WebAssemblyViewport>*>(cookie); |
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
270 |
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
271 delete weakThisPtr; |
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
272 } |
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
273 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
274 void WebAssemblyViewport::Invalidate() |
942
685c9a2d115f
Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents:
910
diff
changeset
|
275 { |
1623
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
276 LOG(TRACE) << "WebAssemblyViewport::Invalidate()\n"; |
1618
9a52bac0c2a7
Added code to clear pending calls to RequestAnimationFrame
Benjamin Golinvaux <bgo@osimis.io>
parents:
1591
diff
changeset
|
277 long id = emscripten_request_animation_frame(OnRequestAnimationFrame, |
1623
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
278 CreateObjectCookie()); |
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
279 //animationFrameCallbackIds_.push_back(id); |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
280 } |
942
685c9a2d115f
Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents:
910
diff
changeset
|
281 |
1575 | 282 void WebAssemblyViewport::FitForPrint() |
283 { | |
284 if (compositor_.get() != NULL && | |
285 controller_ /* should always be true */) | |
286 { | |
1576
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
287 RefreshCanvasSize(); |
1575 | 288 compositor_->FitContent(controller_->GetScene()); |
1653
2e3b2ed239b9
Fixed usage of object cookie
Benjamin Golinvaux <bgo@osimis.io>
parents:
1623
diff
changeset
|
289 |
2e3b2ed239b9
Fixed usage of object cookie
Benjamin Golinvaux <bgo@osimis.io>
parents:
1623
diff
changeset
|
290 void* cookie = CreateObjectCookie(); |
2e3b2ed239b9
Fixed usage of object cookie
Benjamin Golinvaux <bgo@osimis.io>
parents:
1623
diff
changeset
|
291 OnRequestAnimationFrame(0, cookie); // Mandatory to work with Firefox |
1575 | 292 } |
293 } | |
294 | |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
295 void WebAssemblyViewport::AcquireCompositor(ICompositor* compositor /* takes ownership */) |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
296 { |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
297 if (compositor == NULL) |
942
685c9a2d115f
Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents:
910
diff
changeset
|
298 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
299 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
942
685c9a2d115f
Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents:
910
diff
changeset
|
300 } |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
301 else |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
302 { |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
303 compositor_.reset(compositor); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
304 } |
942
685c9a2d115f
Added missing ORTHANC_OVERRIDE + preparation for lost GL context handling + stubs for GL context event handlers
Benjamin Golinvaux <bgo@osimis.io>
parents:
910
diff
changeset
|
305 } |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
306 |
1356
d8bb885e9b0a
Checking DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR
Benjamin Golinvaux <bgo@osimis.io>
parents:
1351
diff
changeset
|
307 #if DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR == 1 |
d8bb885e9b0a
Checking DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR
Benjamin Golinvaux <bgo@osimis.io>
parents:
1351
diff
changeset
|
308 // everything OK..... we're using the new setting |
d8bb885e9b0a
Checking DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR
Benjamin Golinvaux <bgo@osimis.io>
parents:
1351
diff
changeset
|
309 #else |
d8bb885e9b0a
Checking DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR
Benjamin Golinvaux <bgo@osimis.io>
parents:
1351
diff
changeset
|
310 #pragma message("WARNING: DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR is not defined or equal to 0. Stone will use the OLD Emscripten rules for DOM element selection.") |
d8bb885e9b0a
Checking DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR
Benjamin Golinvaux <bgo@osimis.io>
parents:
1351
diff
changeset
|
311 #endif |
d8bb885e9b0a
Checking DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR
Benjamin Golinvaux <bgo@osimis.io>
parents:
1351
diff
changeset
|
312 |
1318
cbfdba08e039
removed SDL code in wasm + added undostack CTOR in Wasm viewport + build fix + ORTHANC_OVERRIDE
Benjamin Golinvaux <bgo@osimis.io>
parents:
1315
diff
changeset
|
313 WebAssemblyViewport::WebAssemblyViewport( |
1346
df8bf351c23f
The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1331
diff
changeset
|
314 const std::string& canvasId, bool enableEmscriptenMouseEvents) : |
1351
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
315 canvasId_(canvasId), |
1356
d8bb885e9b0a
Checking DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR
Benjamin Golinvaux <bgo@osimis.io>
parents:
1351
diff
changeset
|
316 #if DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR == 1 |
1351
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
317 canvasCssSelector_("#" + canvasId), |
1356
d8bb885e9b0a
Checking DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR
Benjamin Golinvaux <bgo@osimis.io>
parents:
1351
diff
changeset
|
318 #else |
d8bb885e9b0a
Checking DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR
Benjamin Golinvaux <bgo@osimis.io>
parents:
1351
diff
changeset
|
319 canvasCssSelector_(canvasId), |
d8bb885e9b0a
Checking DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR
Benjamin Golinvaux <bgo@osimis.io>
parents:
1351
diff
changeset
|
320 #endif |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
321 interactor_(new DefaultViewportInteractor), |
1576
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
322 enableEmscriptenMouseEvents_(enableEmscriptenMouseEvents), |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
323 canvasWidth_(0), |
1623
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
324 canvasHeight_(0) |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
325 { |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
326 } |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
327 |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
328 void WebAssemblyViewport::PostConstructor() |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
329 { |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
330 boost::shared_ptr<IViewport> viewport = shared_from_this(); |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
331 controller_.reset(new ViewportController(viewport)); |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
332 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
333 LOG(INFO) << "Initializing Stone viewport on HTML canvas: " |
1480
4de884c95cd8
fix includes in WebAssemblyCairoViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
334 << canvasId_; |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
335 |
1351
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
336 if (canvasId_.empty() || |
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
337 canvasId_[0] == '#') |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
338 { |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
339 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
340 "The canvas identifier must not start with '#'"); |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
341 } |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
342 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
343 // Disable right-click on the canvas (i.e. context menu) |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
344 EM_ASM({ |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
345 document.getElementById(UTF8ToString($0)).oncontextmenu = |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
346 function(event) |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
347 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
348 event.preventDefault(); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
349 } |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
350 }, |
1351
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
351 canvasId_.c_str() // $0 |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
352 ); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
353 |
1346
df8bf351c23f
The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1331
diff
changeset
|
354 // It is not possible to monitor the resizing of individual |
df8bf351c23f
The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1331
diff
changeset
|
355 // canvas, so we track the full window of the browser |
df8bf351c23f
The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1331
diff
changeset
|
356 emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, |
df8bf351c23f
The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1331
diff
changeset
|
357 reinterpret_cast<void*>(this), |
df8bf351c23f
The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1331
diff
changeset
|
358 false, |
df8bf351c23f
The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1331
diff
changeset
|
359 OnResize); |
df8bf351c23f
The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1331
diff
changeset
|
360 |
df8bf351c23f
The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1331
diff
changeset
|
361 if (enableEmscriptenMouseEvents_) |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
362 { |
1318
cbfdba08e039
removed SDL code in wasm + added undostack CTOR in Wasm viewport + build fix + ORTHANC_OVERRIDE
Benjamin Golinvaux <bgo@osimis.io>
parents:
1315
diff
changeset
|
363 |
1351
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
364 // if any of this function causes an error in the console, please |
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
365 // make sure you are using the new (as of 1.39.x) version of |
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
366 // emscripten element lookup rules( pass |
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
367 // "-s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1" to the linker. |
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
368 |
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
369 emscripten_set_mousedown_callback(canvasCssSelector_.c_str(), |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
370 reinterpret_cast<void*>(this), |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
371 false, |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
372 OnMouseDown); |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
373 |
1351
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
374 emscripten_set_mousemove_callback(canvasCssSelector_.c_str(), |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
375 reinterpret_cast<void*>(this), |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
376 false, |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
377 OnMouseMove); |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
378 |
1351
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
379 emscripten_set_mouseup_callback(canvasCssSelector_.c_str(), |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
380 reinterpret_cast<void*>(this), |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
381 false, |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
382 OnMouseUp); |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
383 } |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
384 } |
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
385 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
386 WebAssemblyViewport::~WebAssemblyViewport() |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
387 { |
1623
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
388 LOG(TRACE) << "WebAssemblyViewport::~WebAssemblyViewport()\n"; |
74be0f498b08
Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1621
diff
changeset
|
389 |
1346
df8bf351c23f
The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1331
diff
changeset
|
390 emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, |
df8bf351c23f
The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1331
diff
changeset
|
391 reinterpret_cast<void*>(this), |
df8bf351c23f
The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1331
diff
changeset
|
392 false, |
df8bf351c23f
The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1331
diff
changeset
|
393 NULL); |
df8bf351c23f
The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1331
diff
changeset
|
394 |
df8bf351c23f
The flag that allows the WebAssemblyViewport to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1331
diff
changeset
|
395 if (enableEmscriptenMouseEvents_) |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
396 { |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
397 |
1351
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
398 emscripten_set_mousedown_callback(canvasCssSelector_.c_str(), |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
399 reinterpret_cast<void*>(this), |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
400 false, |
1480
4de884c95cd8
fix includes in WebAssemblyCairoViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
401 NULL); |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
402 |
1351
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
403 emscripten_set_mousemove_callback(canvasCssSelector_.c_str(), |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
404 reinterpret_cast<void*>(this), |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
405 false, |
1480
4de884c95cd8
fix includes in WebAssemblyCairoViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
406 NULL); |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
407 |
1351
1b8e37770d78
ID vs CSS selector distinction in API and field names.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1346
diff
changeset
|
408 emscripten_set_mouseup_callback(canvasCssSelector_.c_str(), |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
409 reinterpret_cast<void*>(this), |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
410 false, |
1480
4de884c95cd8
fix includes in WebAssemblyCairoViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1455
diff
changeset
|
411 NULL); |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
412 } |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1328
diff
changeset
|
413 } |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
414 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
415 IViewport::ILock* WebAssemblyViewport::Lock() |
910
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
416 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
417 return new WasmLock(*this); |
910
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
418 } |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
419 |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
420 void WebAssemblyViewport::AcquireInteractor(IViewportInteractor* interactor) |
910
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
421 { |
1232
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
422 if (interactor == NULL) |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
423 { |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
424 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
425 } |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
426 else |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
427 { |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
428 interactor_.reset(interactor); |
a28861abf888
viewports for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1054
diff
changeset
|
429 } |
910
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
430 } |
1576
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
431 |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
432 |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
433 void WebAssemblyViewport::RefreshCanvasSize() |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
434 { |
1687
cc5a2e076746
Added error check to emscripten_get_element_css_size
Benjamin Golinvaux <bgo@osimis.io>
parents:
1653
diff
changeset
|
435 double w = -1, h = -1; |
cc5a2e076746
Added error check to emscripten_get_element_css_size
Benjamin Golinvaux <bgo@osimis.io>
parents:
1653
diff
changeset
|
436 EMSCRIPTEN_RESULT result = |
cc5a2e076746
Added error check to emscripten_get_element_css_size
Benjamin Golinvaux <bgo@osimis.io>
parents:
1653
diff
changeset
|
437 emscripten_get_element_css_size(GetCanvasCssSelector().c_str(), &w, &h); |
cc5a2e076746
Added error check to emscripten_get_element_css_size
Benjamin Golinvaux <bgo@osimis.io>
parents:
1653
diff
changeset
|
438 |
cc5a2e076746
Added error check to emscripten_get_element_css_size
Benjamin Golinvaux <bgo@osimis.io>
parents:
1653
diff
changeset
|
439 if (result != EMSCRIPTEN_RESULT_SUCCESS) |
cc5a2e076746
Added error check to emscripten_get_element_css_size
Benjamin Golinvaux <bgo@osimis.io>
parents:
1653
diff
changeset
|
440 { |
cc5a2e076746
Added error check to emscripten_get_element_css_size
Benjamin Golinvaux <bgo@osimis.io>
parents:
1653
diff
changeset
|
441 LOG(WARNING) << "WebAssemblyViewport::RefreshCanvasSize failed to " |
cc5a2e076746
Added error check to emscripten_get_element_css_size
Benjamin Golinvaux <bgo@osimis.io>
parents:
1653
diff
changeset
|
442 << "retrieve CSS size for " << GetCanvasCssSelector(); |
cc5a2e076746
Added error check to emscripten_get_element_css_size
Benjamin Golinvaux <bgo@osimis.io>
parents:
1653
diff
changeset
|
443 } |
1576
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
444 |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
445 /** |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
446 * Emscripten has the function emscripten_get_element_css_size() |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
447 * to query the width and height of a named HTML element. I'm |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
448 * calling this first to get the initial size of the canvas DOM |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
449 * element, and then call emscripten_set_canvas_size() to |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
450 * initialize the framebuffer size of the canvas to the same |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
451 * size as its DOM element. |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
452 * https://floooh.github.io/2017/02/22/emsc-html.html |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
453 **/ |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
454 if (w > 0 && |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
455 h > 0) |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
456 { |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
457 canvasWidth_ = static_cast<unsigned int>(boost::math::iround(w)); |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
458 canvasHeight_ = static_cast<unsigned int>(boost::math::iround(h)); |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
459 } |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
460 else |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
461 { |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
462 canvasWidth_ = 0; |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
463 canvasHeight_ = 0; |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
464 } |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
465 |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
466 emscripten_set_canvas_element_size(GetCanvasCssSelector().c_str(), canvasWidth_, canvasHeight_); |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
467 |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
468 if (compositor_.get() != NULL) |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
469 { |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
470 compositor_->SetCanvasSize(canvasWidth_, canvasHeight_); |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
471 } |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1575
diff
changeset
|
472 } |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
473 } |