# HG changeset patch # User Sebastien Jodogne # Date 1592644108 -7200 # Node ID 5c96bf3f1d3222a1d1cb4624a465a1c45c23f177 # Parent 970ee51fe01fed634e262a3d8b2d6ae4dbbf4900 IOpenGL::RefreshCanvasSize() diff -r 970ee51fe01f -r 5c96bf3f1d32 Framework/OpenGL/IOpenGLContext.h --- a/Framework/OpenGL/IOpenGLContext.h Fri Jun 19 18:43:09 2020 +0200 +++ b/Framework/OpenGL/IOpenGLContext.h Sat Jun 20 11:08:28 2020 +0200 @@ -43,6 +43,11 @@ virtual unsigned int GetCanvasWidth() const = 0; virtual unsigned int GetCanvasHeight() const = 0; + + // Getting the size of the canvas can be expensive, especially + // in WebAssembly => avoid calling this method too often + // (e.g. on each refresh) + virtual void RefreshCanvasSize() = 0; }; } } diff -r 970ee51fe01f -r 5c96bf3f1d32 Framework/OpenGL/SdlOpenGLContext.h --- a/Framework/OpenGL/SdlOpenGLContext.h Fri Jun 19 18:43:09 2020 +0200 +++ b/Framework/OpenGL/SdlOpenGLContext.h Sat Jun 20 11:08:28 2020 +0200 @@ -69,6 +69,11 @@ { window_.ToggleMaximize(); } + + virtual void RefreshCanvasSize() ORTHANC_OVERRIDE + { + // Nothing to do for SDL + } }; } diff -r 970ee51fe01f -r 5c96bf3f1d32 Framework/OpenGL/WebAssemblyOpenGLContext.cpp --- a/Framework/OpenGL/WebAssemblyOpenGLContext.cpp Fri Jun 19 18:43:09 2020 +0200 +++ b/Framework/OpenGL/WebAssemblyOpenGLContext.cpp Sat Jun 20 11:08:28 2020 +0200 @@ -240,7 +240,7 @@ return pimpl_->GetCanvasHeight(); } - void WebAssemblyOpenGLContext::UpdateSize() + void WebAssemblyOpenGLContext::RefreshCanvasSize() { assert(pimpl_.get() != NULL); pimpl_->UpdateSize(); diff -r 970ee51fe01f -r 5c96bf3f1d32 Framework/OpenGL/WebAssemblyOpenGLContext.h --- a/Framework/OpenGL/WebAssemblyOpenGLContext.h Fri Jun 19 18:43:09 2020 +0200 +++ b/Framework/OpenGL/WebAssemblyOpenGLContext.h Sat Jun 20 11:08:28 2020 +0200 @@ -71,7 +71,7 @@ */ //bool TryRecreate(); - void UpdateSize(); + virtual void RefreshCanvasSize() ORTHANC_OVERRIDE; const std::string& GetCanvasSelector() const; diff -r 970ee51fe01f -r 5c96bf3f1d32 Framework/Scene2D/CairoCompositor.h --- a/Framework/Scene2D/CairoCompositor.h Fri Jun 19 18:43:09 2020 +0200 +++ b/Framework/Scene2D/CairoCompositor.h Sat Jun 20 11:08:28 2020 +0200 @@ -59,6 +59,12 @@ return canvas_; } + virtual void RefreshCanvasSize() ORTHANC_OVERRIDE + { + // The canvas size is constant in Cairo, except if + // "UpdateSize()" is called + } + virtual unsigned int GetCanvasWidth() const ORTHANC_OVERRIDE { return canvas_.GetWidth(); diff -r 970ee51fe01f -r 5c96bf3f1d32 Framework/Scene2D/ICompositor.h --- a/Framework/Scene2D/ICompositor.h Fri Jun 19 18:43:09 2020 +0200 +++ b/Framework/Scene2D/ICompositor.h Sat Jun 20 11:08:28 2020 +0200 @@ -33,6 +33,9 @@ { } + // This function can be expensive (notably in wasm) + virtual void RefreshCanvasSize() = 0; + virtual unsigned int GetCanvasWidth() const = 0; virtual unsigned int GetCanvasHeight() const = 0; diff -r 970ee51fe01f -r 5c96bf3f1d32 Framework/Scene2D/OpenGLCompositor.cpp --- a/Framework/Scene2D/OpenGLCompositor.cpp Fri Jun 19 18:43:09 2020 +0200 +++ b/Framework/Scene2D/OpenGLCompositor.cpp Sat Jun 20 11:08:28 2020 +0200 @@ -187,7 +187,6 @@ if (!context_.IsContextLost()) { context_.MakeCurrent(); // this can throw if context lost! - canvasWidth_ = context_.GetCanvasWidth(); canvasHeight_ = context_.GetCanvasHeight(); @@ -244,4 +243,16 @@ } } #endif + + + void OpenGLCompositor::RefreshCanvasSize() + { + if (!context_.IsContextLost()) + { + context_.MakeCurrent(); // this can throw if context lost! + context_.RefreshCanvasSize(); // Difference with Refresh(scene) + canvasWidth_ = context_.GetCanvasWidth(); + canvasHeight_ = context_.GetCanvasHeight(); + } + } } diff -r 970ee51fe01f -r 5c96bf3f1d32 Framework/Scene2D/OpenGLCompositor.h --- a/Framework/Scene2D/OpenGLCompositor.h Fri Jun 19 18:43:09 2020 +0200 +++ b/Framework/Scene2D/OpenGLCompositor.h Sat Jun 20 11:08:28 2020 +0200 @@ -72,6 +72,8 @@ Orthanc::Encoding codepage) ORTHANC_OVERRIDE; #endif + virtual void RefreshCanvasSize() ORTHANC_OVERRIDE; + virtual unsigned int GetCanvasWidth() const ORTHANC_OVERRIDE { return canvasWidth_; diff -r 970ee51fe01f -r 5c96bf3f1d32 Framework/Viewport/WebGLViewport.cpp --- a/Framework/Viewport/WebGLViewport.cpp Fri Jun 19 18:43:09 2020 +0200 +++ b/Framework/Viewport/WebGLViewport.cpp Sat Jun 20 11:08:28 2020 +0200 @@ -63,7 +63,7 @@ { try { - context_.UpdateSize(); + context_.RefreshCanvasSize(); } catch (const StoneException& e) {