comparison Applications/Platforms/WebAssembly/WebAssemblyViewport.cpp @ 1618:9a52bac0c2a7

Added code to clear pending calls to RequestAnimationFrame
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 02 Nov 2020 17:54:18 +0100
parents 5887a4f8594b
children 575f512cdf48
comparison
equal deleted inserted replaced
1617:49ba862d3454 1618:9a52bac0c2a7
127 WebAssemblyViewport* that = reinterpret_cast<WebAssemblyViewport*>(userData); 127 WebAssemblyViewport* that = reinterpret_cast<WebAssemblyViewport*>(userData);
128 128
129 if (that->compositor_.get() != NULL && 129 if (that->compositor_.get() != NULL &&
130 that->controller_ /* should always be true */) 130 that->controller_ /* should always be true */)
131 { 131 {
132 that->animationFrameCallbackIds_.clear();
132 that->Paint(*that->compositor_, *that->controller_); 133 that->Paint(*that->compositor_, *that->controller_);
133 } 134 }
134 135
135 LOG(TRACE) << "Exiting: " << __func__; 136 LOG(TRACE) << "Exiting: " << __func__;
136 return true; 137 return true;
211 return true; 212 return true;
212 } 213 }
213 214
214 void WebAssemblyViewport::Invalidate() 215 void WebAssemblyViewport::Invalidate()
215 { 216 {
216 emscripten_request_animation_frame(OnRequestAnimationFrame, reinterpret_cast<void*>(this)); 217 long id = emscripten_request_animation_frame(OnRequestAnimationFrame,
218 reinterpret_cast<void*>(this));
219 animationFrameCallbackIds_.push_back(id);
217 } 220 }
218 221
219 void WebAssemblyViewport::FitForPrint() 222 void WebAssemblyViewport::FitForPrint()
220 { 223 {
221 if (compositor_.get() != NULL && 224 if (compositor_.get() != NULL &&
318 } 321 }
319 } 322 }
320 323
321 WebAssemblyViewport::~WebAssemblyViewport() 324 WebAssemblyViewport::~WebAssemblyViewport()
322 { 325 {
326 // cancel the pending RequestAnimationFrame callbacks
327 for(size_t i = 0; i < animationFrameCallbackIds_.size(); ++i)
328 {
329 long id = animationFrameCallbackIds_[i];
330 emscripten_cancel_animation_frame(id);
331 }
332
323 emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, 333 emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW,
324 reinterpret_cast<void*>(this), 334 reinterpret_cast<void*>(this),
325 false, 335 false,
326 NULL); 336 NULL);
327 337