Mercurial > hg > orthanc-stone
annotate Framework/Viewport/WebAssemblyViewport.cpp @ 1118:35e798b16b65
RadiographyDicomLayer: allow replacing low res image by high res image
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Mon, 04 Nov 2019 22:16:04 +0100 |
parents | 3c9529edf5fd |
children | a28861abf888 ce3052f28f2e |
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 |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
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. |
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
|
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 #include "WebAssemblyViewport.h" |
1050 | 23 |
24 #include "../StoneException.h" | |
25 | |
910
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
26 #include <emscripten/html5.h> |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 namespace OrthancStone |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 { |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
30 WebAssemblyOpenGLViewport::WebAssemblyOpenGLViewport(const std::string& canvas) : |
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
31 WebAssemblyViewport(canvas), |
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
|
32 context_(canvas) |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 { |
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
|
34 compositor_.reset(new OpenGLCompositor(context_, GetScene())); |
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
|
35 RegisterContextCallbacks(); |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 } |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
38 WebAssemblyOpenGLViewport::WebAssemblyOpenGLViewport(const std::string& canvas, |
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
|
39 boost::shared_ptr<Scene2D>& scene) : |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
40 WebAssemblyViewport(canvas, scene), |
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
|
41 context_(canvas) |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 { |
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
|
43 compositor_.reset(new OpenGLCompositor(context_, GetScene())); |
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
|
44 RegisterContextCallbacks(); |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 } |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
47 void WebAssemblyOpenGLViewport::UpdateSize() |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 { |
997
d6b83ee3a950
fix WebAssemblyOpenGLViewport::UpdateSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
964
diff
changeset
|
49 context_.UpdateSize(); // First read the size of the canvas |
d6b83ee3a950
fix WebAssemblyOpenGLViewport::UpdateSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
964
diff
changeset
|
50 |
d6b83ee3a950
fix WebAssemblyOpenGLViewport::UpdateSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
964
diff
changeset
|
51 if (compositor_.get() != NULL) |
d6b83ee3a950
fix WebAssemblyOpenGLViewport::UpdateSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
964
diff
changeset
|
52 { |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
53 compositor_->Refresh(); // Then refresh the content of the canvas |
997
d6b83ee3a950
fix WebAssemblyOpenGLViewport::UpdateSize()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
964
diff
changeset
|
54 } |
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
|
55 } |
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
|
56 |
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
|
57 /* |
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
|
58 typedef EM_BOOL (*em_webgl_context_callback)(int eventType, const void *reserved, void *userData); |
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
|
59 |
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
|
60 EMSCRIPTEN_EVENT_WEBGLCONTEXTLOST EMSCRIPTEN_EVENT_WEBGLCONTEXTRESTORED |
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
|
61 |
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
|
62 EMSCRIPTEN_RESULT emscripten_set_webglcontextlost_callback( |
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
|
63 const char *target, void *userData, EM_BOOL useCapture, em_webgl_context_callback callback) |
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
|
64 |
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
|
65 EMSCRIPTEN_RESULT emscripten_set_webglcontextrestored_callback( |
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 const char *target, void *userData, EM_BOOL useCapture, em_webgl_context_callback callback) |
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
|
67 |
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
|
68 */ |
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
|
69 |
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
|
70 EM_BOOL WebAssemblyOpenGLViewport_OpenGLContextLost_callback( |
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
|
71 int eventType, const void* reserved, void* userData) |
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
|
72 { |
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
|
73 ORTHANC_ASSERT(eventType == EMSCRIPTEN_EVENT_WEBGLCONTEXTLOST); |
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
|
74 WebAssemblyOpenGLViewport* viewport = reinterpret_cast<WebAssemblyOpenGLViewport*>(userData); |
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
|
75 return viewport->OpenGLContextLost(); |
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
|
76 } |
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
|
77 |
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
|
78 EM_BOOL WebAssemblyOpenGLViewport_OpenGLContextRestored_callback( |
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
|
79 int eventType, const void* reserved, void* userData) |
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
|
80 { |
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
|
81 ORTHANC_ASSERT(eventType == EMSCRIPTEN_EVENT_WEBGLCONTEXTRESTORED); |
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
|
82 WebAssemblyOpenGLViewport* viewport = reinterpret_cast<WebAssemblyOpenGLViewport*>(userData); |
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
|
83 return viewport->OpenGLContextRestored(); |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 } |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
85 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
86 void WebAssemblyOpenGLViewport::DisableCompositor() |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
87 { |
1054
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
88 compositor_.reset(); |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
89 } |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
90 |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
91 ICompositor& WebAssemblyOpenGLViewport::GetCompositor() |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
92 { |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
93 if (compositor_.get() == NULL) |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
94 { |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
95 // "HasCompositor()" should have been called |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
96 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
97 } |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
98 else |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
99 { |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
100 return *compositor_; |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
101 } |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
102 } |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
103 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
104 void WebAssemblyOpenGLViewport::Refresh() |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
105 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
106 try |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
107 { |
1054
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
108 if (HasCompositor()) |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
109 { |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
110 GetCompositor().Refresh(); |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
111 } |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
112 else |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
113 { |
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
114 // this block was added because of (perceived?) bugs in the |
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
115 // browser where the WebGL contexts are NOT automatically restored |
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
116 // after being lost. |
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
117 // the WebGL context has been lost. Sce |
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
118 |
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
119 //LOG(ERROR) << "About to call WebAssemblyOpenGLContext::TryRecreate()."; |
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
120 //LOG(ERROR) << "Before calling it, isContextLost == " << context_.IsContextLost(); |
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
121 |
1054
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
122 if (!context_.IsContextLost()) |
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
123 { |
964
91f827272c1f
Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
Benjamin Golinvaux <bgo@osimis.io>
parents:
956
diff
changeset
|
124 LOG(TRACE) << "Context restored!"; |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
125 //LOG(ERROR) << "After calling it, isContextLost == " << context_.IsContextLost(); |
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
126 RestoreCompositor(); |
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
127 UpdateSize(); |
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
128 } |
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
129 } |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
130 } |
1050 | 131 catch (const StoneException& e) |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
132 { |
1050 | 133 if (e.GetErrorCode() == ErrorCode_WebGLContextLost) |
134 { | |
135 LOG(WARNING) << "Context is lost! Compositor will be disabled."; | |
136 DisableCompositor(); | |
137 // we now need to wait for the "context restored" callback | |
138 } | |
139 else | |
140 { | |
141 throw; | |
142 } | |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
143 } |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
144 catch (...) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
145 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
146 // something else nasty happened |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
147 throw; |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
148 } |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
149 } |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
150 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
151 void WebAssemblyOpenGLViewport::RestoreCompositor() |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
152 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
153 // the context must have been restored! |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
154 ORTHANC_ASSERT(!context_.IsContextLost()); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
155 if (compositor_.get() == NULL) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
156 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
157 compositor_.reset(new OpenGLCompositor(context_, GetScene())); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
158 } |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
159 else |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
160 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
161 LOG(WARNING) << "RestoreCompositor() called for \"" << GetCanvasIdentifier() << "\" while it was NOT lost! Nothing done."; |
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 } |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
164 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
165 bool WebAssemblyOpenGLViewport::OpenGLContextLost() |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
166 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
167 LOG(ERROR) << "WebAssemblyOpenGLViewport::OpenGLContextLost() for canvas: " << GetCanvasIdentifier(); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
168 DisableCompositor(); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
169 return true; |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
170 } |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
171 |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
172 bool WebAssemblyOpenGLViewport::OpenGLContextRestored() |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
173 { |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
174 LOG(ERROR) << "WebAssemblyOpenGLViewport::OpenGLContextRestored() for canvas: " << GetCanvasIdentifier(); |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
175 |
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
176 // maybe the context has already been restored by other means (the |
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
177 // Refresh() function) |
1054
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
178 if (!HasCompositor()) |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
179 { |
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
180 RestoreCompositor(); |
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
181 UpdateSize(); |
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
182 } |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
183 return false; |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
184 } |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
185 |
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
|
186 void WebAssemblyOpenGLViewport::RegisterContextCallbacks() |
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
|
187 { |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
188 #if 0 |
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
189 // DISABLED ON 2019-08-20 and replaced by external JS calls because I could |
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
190 // not get emscripten API to work |
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
|
191 // TODO: what's the impact of userCapture=true ? |
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
|
192 const char* canvasId = GetCanvasIdentifier().c_str(); |
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
|
193 void* that = reinterpret_cast<void*>(this); |
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
|
194 EMSCRIPTEN_RESULT status = EMSCRIPTEN_RESULT_SUCCESS; |
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
|
195 |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
196 //status = emscripten_set_webglcontextlost_callback(canvasId, that, true, WebAssemblyOpenGLViewport_OpenGLContextLost_callback); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
197 //if (status != EMSCRIPTEN_RESULT_SUCCESS) |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
198 //{ |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
199 // std::stringstream ss; |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
200 // ss << "Error while calling emscripten_set_webglcontextlost_callback for: \"" << GetCanvasIdentifier() << "\""; |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
201 // std::string msg = ss.str(); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
202 // LOG(ERROR) << msg; |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
203 // ORTHANC_ASSERT(false, msg.c_str()); |
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
204 //} |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
205 |
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
|
206 status = emscripten_set_webglcontextrestored_callback(canvasId, that, true, WebAssemblyOpenGLViewport_OpenGLContextRestored_callback); |
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
|
207 if (status != EMSCRIPTEN_RESULT_SUCCESS) |
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
|
208 { |
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
|
209 std::stringstream ss; |
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
|
210 ss << "Error while calling emscripten_set_webglcontextrestored_callback for: \"" << GetCanvasIdentifier() << "\""; |
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
|
211 std::string msg = ss.str(); |
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
|
212 LOG(ERROR) << msg; |
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
|
213 ORTHANC_ASSERT(false, msg.c_str()); |
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
|
214 } |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
942
diff
changeset
|
215 LOG(TRACE) << "WebAssemblyOpenGLViewport::RegisterContextCallbacks() SUCCESS!!!"; |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
947
diff
changeset
|
216 #endif |
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
|
217 } |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
218 |
910
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
219 WebAssemblyCairoViewport::WebAssemblyCairoViewport(const std::string& canvas) : |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
220 WebAssemblyViewport(canvas), |
910
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
221 canvas_(canvas), |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
222 compositor_(GetScene(), 1024, 768) |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
223 { |
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
224 } |
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
225 |
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
226 WebAssemblyCairoViewport::WebAssemblyCairoViewport(const std::string& canvas, |
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
|
227 boost::shared_ptr<Scene2D>& scene) : |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
228 WebAssemblyViewport(canvas, scene), |
910
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
229 canvas_(canvas), |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
230 compositor_(GetScene(), 1024, 768) |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
231 { |
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
232 } |
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
233 |
910
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
234 void WebAssemblyCairoViewport::UpdateSize() |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
235 { |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
236 LOG(INFO) << "updating cairo viewport size"; |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
237 double w, h; |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
238 emscripten_get_element_css_size(canvas_.c_str(), &w, &h); |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
239 |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
240 /** |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
241 * Emscripten has the function emscripten_get_element_css_size() |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
242 * to query the width and height of a named HTML element. I'm |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
243 * calling this first to get the initial size of the canvas DOM |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
244 * element, and then call emscripten_set_canvas_size() to |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
245 * initialize the framebuffer size of the canvas to the same |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
246 * size as its DOM element. |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
247 * https://floooh.github.io/2017/02/22/emsc-html.html |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
248 **/ |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
249 unsigned int canvasWidth = 0; |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
250 unsigned int canvasHeight = 0; |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
251 |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
252 if (w > 0 || |
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
|
253 h > 0) |
910
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
254 { |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
255 canvasWidth = static_cast<unsigned int>(boost::math::iround(w)); |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
256 canvasHeight = static_cast<unsigned int>(boost::math::iround(h)); |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
257 } |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
258 |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
259 emscripten_set_canvas_element_size(canvas_.c_str(), canvasWidth, canvasHeight); |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
260 compositor_.UpdateSize(canvasWidth, canvasHeight); |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
261 } |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
262 |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
263 void WebAssemblyCairoViewport::Refresh() |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
264 { |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
265 LOG(INFO) << "refreshing cairo viewport, TODO: blit to the canvans.getContext('2d')"; |
1054
3c9529edf5fd
fixing WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
266 GetCompositor().Refresh(); |
910
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
267 } |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
268 } |