comparison Framework/Viewport/WebAssemblyViewport.cpp @ 956:a7351ad54960

Made IsContextLost automatically set the flag by checking with the emscripten WebGL wrapper + added a LOT of logging messages right before throwing ErrorCode_BadSequenceOfCalls exceptions + increased the http request timeouts from 60 to 600 sec (big datasets in some recent customer use cases) + added IsContext lost through the Viewport/Context layer (to make it reachable from external API) + the same for the underlying device context (for debug)
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 21 Aug 2019 16:16:30 +0200
parents 1091b2adeb5a
children 91f827272c1f
comparison
equal deleted inserted replaced
953:118fc5c85d07 956:a7351ad54960
84 84
85 void WebAssemblyOpenGLViewport::Refresh() 85 void WebAssemblyOpenGLViewport::Refresh()
86 { 86 {
87 try 87 try
88 { 88 {
89 // the compositor COULD be dead! 89 if (!GetCompositor())
90 if (GetCompositor()) 90 {
91 // this block was added because of (perceived?) bugs in the
92 // browser where the WebGL contexts are NOT automatically restored
93 // after being lost.
94 // the WebGL context has been lost. Sce
95
96 //LOG(ERROR) << "About to call WebAssemblyOpenGLContext::TryRecreate().";
97 //LOG(ERROR) << "Before calling it, isContextLost == " << context_.IsContextLost();
98
99 if (!context_.IsContextLost()) {
100 LOG(ERROR) << "Context restored!";
101 //LOG(ERROR) << "After calling it, isContextLost == " << context_.IsContextLost();
102 RestoreCompositor();
103 UpdateSize();
104 }
105 }
106 if (GetCompositor()) {
91 GetCompositor()->Refresh(); 107 GetCompositor()->Refresh();
108 }
92 } 109 }
93 catch (const OpenGLContextLostException& e) 110 catch (const OpenGLContextLostException& e)
94 { 111 {
95 LOG(WARNING) << "Context " << std::hex << e.context_ << " is lost! Compositor will be disabled."; 112 LOG(WARNING) << "Context " << std::hex << e.context_ << " is lost! Compositor will be disabled.";
96 DisableCompositor(); 113 DisableCompositor();
101 // something else nasty happened 118 // something else nasty happened
102 throw; 119 throw;
103 } 120 }
104 } 121 }
105 122
123 bool WebAssemblyOpenGLViewport::IsContextLost()
124 {
125 return context_.IsContextLost();
126 }
127
106 void WebAssemblyOpenGLViewport::RestoreCompositor() 128 void WebAssemblyOpenGLViewport::RestoreCompositor()
107 { 129 {
108 // the context must have been restored! 130 // the context must have been restored!
109 ORTHANC_ASSERT(!context_.IsContextLost()); 131 ORTHANC_ASSERT(!context_.IsContextLost());
110 if (compositor_.get() == NULL) 132 if (compositor_.get() == NULL)
125 } 147 }
126 148
127 bool WebAssemblyOpenGLViewport::OpenGLContextRestored() 149 bool WebAssemblyOpenGLViewport::OpenGLContextRestored()
128 { 150 {
129 LOG(ERROR) << "WebAssemblyOpenGLViewport::OpenGLContextRestored() for canvas: " << GetCanvasIdentifier(); 151 LOG(ERROR) << "WebAssemblyOpenGLViewport::OpenGLContextRestored() for canvas: " << GetCanvasIdentifier();
130 RestoreCompositor(); 152
131 UpdateSize(); 153 // maybe the context has already been restored by other means (the
154 // Refresh() function)
155 if (!GetCompositor())
156 {
157 RestoreCompositor();
158 UpdateSize();
159 }
132 return false; 160 return false;
133 } 161 }
134 162
163 void* WebAssemblyOpenGLViewport::DebugGetInternalContext() const
164 {
165 return context_.DebugGetInternalContext();
166 }
167
135 void WebAssemblyOpenGLViewport::RegisterContextCallbacks() 168 void WebAssemblyOpenGLViewport::RegisterContextCallbacks()
136 { 169 {
170 #if 0
171 // DISABLED ON 2019-08-20 and replaced by external JS calls because I could
172 // not get emscripten API to work
137 // TODO: what's the impact of userCapture=true ? 173 // TODO: what's the impact of userCapture=true ?
138 const char* canvasId = GetCanvasIdentifier().c_str(); 174 const char* canvasId = GetCanvasIdentifier().c_str();
139 void* that = reinterpret_cast<void*>(this); 175 void* that = reinterpret_cast<void*>(this);
140 EMSCRIPTEN_RESULT status = EMSCRIPTEN_RESULT_SUCCESS; 176 EMSCRIPTEN_RESULT status = EMSCRIPTEN_RESULT_SUCCESS;
141 177
146 // ss << "Error while calling emscripten_set_webglcontextlost_callback for: \"" << GetCanvasIdentifier() << "\""; 182 // ss << "Error while calling emscripten_set_webglcontextlost_callback for: \"" << GetCanvasIdentifier() << "\"";
147 // std::string msg = ss.str(); 183 // std::string msg = ss.str();
148 // LOG(ERROR) << msg; 184 // LOG(ERROR) << msg;
149 // ORTHANC_ASSERT(false, msg.c_str()); 185 // ORTHANC_ASSERT(false, msg.c_str());
150 //} 186 //}
187
151 status = emscripten_set_webglcontextrestored_callback(canvasId, that, true, WebAssemblyOpenGLViewport_OpenGLContextRestored_callback); 188 status = emscripten_set_webglcontextrestored_callback(canvasId, that, true, WebAssemblyOpenGLViewport_OpenGLContextRestored_callback);
152 if (status != EMSCRIPTEN_RESULT_SUCCESS) 189 if (status != EMSCRIPTEN_RESULT_SUCCESS)
153 { 190 {
154 std::stringstream ss; 191 std::stringstream ss;
155 ss << "Error while calling emscripten_set_webglcontextrestored_callback for: \"" << GetCanvasIdentifier() << "\""; 192 ss << "Error while calling emscripten_set_webglcontextrestored_callback for: \"" << GetCanvasIdentifier() << "\"";
156 std::string msg = ss.str(); 193 std::string msg = ss.str();
157 LOG(ERROR) << msg; 194 LOG(ERROR) << msg;
158 ORTHANC_ASSERT(false, msg.c_str()); 195 ORTHANC_ASSERT(false, msg.c_str());
159 } 196 }
160 LOG(TRACE) << "WebAssemblyOpenGLViewport::RegisterContextCallbacks() SUCCESS!!!"; 197 LOG(TRACE) << "WebAssemblyOpenGLViewport::RegisterContextCallbacks() SUCCESS!!!";
198 #endif
161 } 199 }
162 200
163 WebAssemblyCairoViewport::WebAssemblyCairoViewport(const std::string& canvas) : 201 WebAssemblyCairoViewport::WebAssemblyCairoViewport(const std::string& canvas) :
164 WebAssemblyViewport(canvas), 202 WebAssemblyViewport(canvas),
165 canvas_(canvas), 203 canvas_(canvas),
207 void WebAssemblyCairoViewport::Refresh() 245 void WebAssemblyCairoViewport::Refresh()
208 { 246 {
209 LOG(INFO) << "refreshing cairo viewport, TODO: blit to the canvans.getContext('2d')"; 247 LOG(INFO) << "refreshing cairo viewport, TODO: blit to the canvans.getContext('2d')";
210 GetCompositor()->Refresh(); 248 GetCompositor()->Refresh();
211 } 249 }
212
213 } 250 }