Mercurial > hg > orthanc-stone
comparison Framework/OpenGL/WebAssemblyOpenGLContext.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 | 769249e1f3b4 |
comparison
equal
deleted
inserted
replaced
953:118fc5c85d07 | 956:a7351ad54960 |
---|---|
67 void* DebugGetInternalContext() const | 67 void* DebugGetInternalContext() const |
68 { | 68 { |
69 return reinterpret_cast<void*>(context_); | 69 return reinterpret_cast<void*>(context_); |
70 } | 70 } |
71 | 71 |
72 bool IsContextLost() const | 72 bool IsContextLost() |
73 { | 73 { |
74 LOG(TRACE) << "IsContextLost() for context " << std::hex() << | |
74 bool apiFlag = (emscripten_is_webgl_context_lost(context_) != 0); | 75 bool apiFlag = (emscripten_is_webgl_context_lost(context_) != 0); |
75 bool ownFlag = isContextLost_; | 76 isContextLost_ = apiFlag; |
76 if (ownFlag != apiFlag) | 77 return isContextLost_; |
77 { | |
78 LOG(WARNING) << "Context loss, according to emscripten, is: " << apiFlag << " | while, according to internal state, is: " << ownFlag; | |
79 } | |
80 return ownFlag | apiFlag; | |
81 } | 78 } |
82 | 79 |
83 void SetLostContext() | 80 void SetLostContext() |
84 { | 81 { |
85 isContextLost_ = true; | 82 isContextLost_ = true; |
86 } | 83 } |
87 | 84 |
88 ~PImpl() | 85 ~PImpl() |
89 { | 86 { |
90 emscripten_webgl_destroy_context(context_); | 87 try |
88 { | |
89 EMSCRIPTEN_RESULT result = emscripten_webgl_destroy_context(context_); | |
90 if (result != EMSCRIPTEN_RESULT_SUCCESS) | |
91 { | |
92 LOG(ERROR) << "emscripten_webgl_destroy_context returned code " << result; | |
93 } | |
94 } | |
95 catch (const Orthanc::OrthancException& e) | |
96 { | |
97 if (e.HasDetails()) | |
98 { | |
99 LOG(ERROR) << "OrthancException in WebAssemblyOpenGLContext::~PImpl: " << e.What() << " Details: " << e.GetDetails(); | |
100 } | |
101 else | |
102 { | |
103 LOG(ERROR) << "OrthancException in WebAssemblyOpenGLContext::~PImpl: " << e.What(); | |
104 } | |
105 } | |
106 catch (const std::exception& e) | |
107 { | |
108 LOG(ERROR) << "std::exception in WebAssemblyOpenGLContext::~PImpl: " << e.what(); | |
109 } | |
110 catch (...) | |
111 { | |
112 LOG(ERROR) << "Unknown exception in WebAssemblyOpenGLContext::~PImpl"; | |
113 } | |
91 } | 114 } |
92 | 115 |
93 const std::string& GetCanvasIdentifier() const | 116 const std::string& GetCanvasIdentifier() const |
94 { | 117 { |
95 return canvas_; | 118 return canvas_; |
175 WebAssemblyOpenGLContext::WebAssemblyOpenGLContext(const std::string& canvas) : | 198 WebAssemblyOpenGLContext::WebAssemblyOpenGLContext(const std::string& canvas) : |
176 pimpl_(new PImpl(canvas)) | 199 pimpl_(new PImpl(canvas)) |
177 { | 200 { |
178 } | 201 } |
179 | 202 |
180 bool WebAssemblyOpenGLContext::IsContextLost() const | 203 //bool WebAssemblyOpenGLContext::TryRecreate() |
204 //{ | |
205 // // LOG(ERROR) << "WebAssemblyOpenGLContext::TryRecreate() trying to recreate context"; | |
206 // try | |
207 // { | |
208 // std::string canvasId = GetCanvasIdentifier(); | |
209 // pimpl_.reset(new PImpl(canvasId)); | |
210 | |
211 // // no exception does not mean the context is fully | |
212 // // functional! Most probably, if we have >= than 16 | |
213 // // contexts, context wil remain lost for some time | |
214 // bool lost = IsContextLost(); | |
215 // if (lost) { | |
216 // // LOG(ERROR) << "WebAssemblyOpenGLContext::TryRecreate() context is still lost!"; | |
217 // return false; | |
218 // } else { | |
219 // return true; | |
220 // } | |
221 // } | |
222 // catch (const Orthanc::OrthancException& e) | |
223 // { | |
224 // if (e.HasDetails()) | |
225 // { | |
226 // LOG(ERROR) << "OrthancException in WebAssemblyOpenGLContext::TryRecreate: " << e.What() << " Details: " << e.GetDetails(); | |
227 // } | |
228 // else | |
229 // { | |
230 // LOG(ERROR) << "OrthancException in WebAssemblyOpenGLContext::TryRecreate: " << e.What(); | |
231 // } | |
232 // return false; | |
233 // } | |
234 // catch (const std::exception& e) | |
235 // { | |
236 // LOG(ERROR) << "std::exception in WebAssemblyOpenGLContext::TryRecreate: " << e.what(); | |
237 // return false; | |
238 // } | |
239 // catch (...) | |
240 // { | |
241 // LOG(ERROR) << "Unknown exception WebAssemblyOpenGLContext::in TryRecreate"; | |
242 // return false; | |
243 // } | |
244 //} | |
245 | |
246 bool WebAssemblyOpenGLContext::IsContextLost() | |
181 { | 247 { |
182 return pimpl_->IsContextLost(); | 248 return pimpl_->IsContextLost(); |
183 } | 249 } |
184 | 250 |
185 void WebAssemblyOpenGLContext::RestoreLostContext() | 251 void WebAssemblyOpenGLContext::RestoreLostContext() |