Mercurial > hg > orthanc-stone
changeset 1482:5c96bf3f1d32
IOpenGL::RefreshCanvasSize()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 20 Jun 2020 11:08:28 +0200 |
parents | 970ee51fe01f |
children | 6abd819aa534 |
files | Framework/OpenGL/IOpenGLContext.h Framework/OpenGL/SdlOpenGLContext.h Framework/OpenGL/WebAssemblyOpenGLContext.cpp Framework/OpenGL/WebAssemblyOpenGLContext.h Framework/Scene2D/CairoCompositor.h Framework/Scene2D/ICompositor.h Framework/Scene2D/OpenGLCompositor.cpp Framework/Scene2D/OpenGLCompositor.h Framework/Viewport/WebGLViewport.cpp |
diffstat | 9 files changed, 36 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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; }; } }
--- 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 + } }; }
--- 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();
--- 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;
--- 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();
--- 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;
--- 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(); + } + } }
--- 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_;