comparison Framework/Viewport/WebAssemblyViewport.cpp @ 1054:3c9529edf5fd

fixing WebAssemblyViewport
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 10 Oct 2019 15:55:54 +0200
parents d393ad9cf68c
children a28861abf888 ce3052f28f2e
comparison
equal deleted inserted replaced
1053:32b403a47b19 1054:3c9529edf5fd
83 return viewport->OpenGLContextRestored(); 83 return viewport->OpenGLContextRestored();
84 } 84 }
85 85
86 void WebAssemblyOpenGLViewport::DisableCompositor() 86 void WebAssemblyOpenGLViewport::DisableCompositor()
87 { 87 {
88 compositor_.reset(NULL); 88 compositor_.reset();
89 }
90
91 ICompositor& WebAssemblyOpenGLViewport::GetCompositor()
92 {
93 if (compositor_.get() == NULL)
94 {
95 // "HasCompositor()" should have been called
96 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
97 }
98 else
99 {
100 return *compositor_;
101 }
89 } 102 }
90 103
91 void WebAssemblyOpenGLViewport::Refresh() 104 void WebAssemblyOpenGLViewport::Refresh()
92 { 105 {
93 try 106 try
94 { 107 {
95 if (!GetCompositor()) 108 if (HasCompositor())
109 {
110 GetCompositor().Refresh();
111 }
112 else
96 { 113 {
97 // this block was added because of (perceived?) bugs in the 114 // this block was added because of (perceived?) bugs in the
98 // browser where the WebGL contexts are NOT automatically restored 115 // browser where the WebGL contexts are NOT automatically restored
99 // after being lost. 116 // after being lost.
100 // the WebGL context has been lost. Sce 117 // the WebGL context has been lost. Sce
101 118
102 //LOG(ERROR) << "About to call WebAssemblyOpenGLContext::TryRecreate()."; 119 //LOG(ERROR) << "About to call WebAssemblyOpenGLContext::TryRecreate().";
103 //LOG(ERROR) << "Before calling it, isContextLost == " << context_.IsContextLost(); 120 //LOG(ERROR) << "Before calling it, isContextLost == " << context_.IsContextLost();
104 121
105 if (!context_.IsContextLost()) { 122 if (!context_.IsContextLost())
123 {
106 LOG(TRACE) << "Context restored!"; 124 LOG(TRACE) << "Context restored!";
107 //LOG(ERROR) << "After calling it, isContextLost == " << context_.IsContextLost(); 125 //LOG(ERROR) << "After calling it, isContextLost == " << context_.IsContextLost();
108 RestoreCompositor(); 126 RestoreCompositor();
109 UpdateSize(); 127 UpdateSize();
110 } 128 }
111 } 129 }
112 if (GetCompositor()) {
113 GetCompositor()->Refresh();
114 }
115 } 130 }
116 catch (const StoneException& e) 131 catch (const StoneException& e)
117 { 132 {
118 if (e.GetErrorCode() == ErrorCode_WebGLContextLost) 133 if (e.GetErrorCode() == ErrorCode_WebGLContextLost)
119 { 134 {
158 { 173 {
159 LOG(ERROR) << "WebAssemblyOpenGLViewport::OpenGLContextRestored() for canvas: " << GetCanvasIdentifier(); 174 LOG(ERROR) << "WebAssemblyOpenGLViewport::OpenGLContextRestored() for canvas: " << GetCanvasIdentifier();
160 175
161 // maybe the context has already been restored by other means (the 176 // maybe the context has already been restored by other means (the
162 // Refresh() function) 177 // Refresh() function)
163 if (!GetCompositor()) 178 if (!HasCompositor())
164 { 179 {
165 RestoreCompositor(); 180 RestoreCompositor();
166 UpdateSize(); 181 UpdateSize();
167 } 182 }
168 return false; 183 return false;
246 } 261 }
247 262
248 void WebAssemblyCairoViewport::Refresh() 263 void WebAssemblyCairoViewport::Refresh()
249 { 264 {
250 LOG(INFO) << "refreshing cairo viewport, TODO: blit to the canvans.getContext('2d')"; 265 LOG(INFO) << "refreshing cairo viewport, TODO: blit to the canvans.getContext('2d')";
251 GetCompositor()->Refresh(); 266 GetCompositor().Refresh();
252 } 267 }
253 } 268 }