# HG changeset patch # User Alain Mazy # Date 1563434379 -7200 # Node ID 722ee73e6ba2408d182448252e158aed7832b786 # Parent 88bf49aebc13b212974132948c596b22bece8f75 cleanup + started to implement WebAssemblyCairoViewport (wip) diff -r 88bf49aebc13 -r 722ee73e6ba2 Framework/Viewport/SdlViewport.cpp --- a/Framework/Viewport/SdlViewport.cpp Wed Jul 17 16:56:53 2019 +0200 +++ b/Framework/Viewport/SdlViewport.cpp Thu Jul 18 09:19:39 2019 +0200 @@ -78,35 +78,6 @@ } } -// void SdlCairoViewport::SetSize(unsigned int width, -// unsigned int height) -// { - // if (cairoSurface_.get() == NULL || - // cairoSurface_->GetWidth() != width || - // cairoSurface_->GetHeight() != height) - // { - // cairoSurface_.reset(new CairoSurface(width, height, false /* no alpha */)); - - // // TODO Big endian? - // static const uint32_t rmask = 0x00ff0000; - // static const uint32_t gmask = 0x0000ff00; - // static const uint32_t bmask = 0x000000ff; - - // if (sdlSurface_) - // { - // SDL_FreeSurface(sdlSurface_); - // } - - // sdlSurface_ = SDL_CreateRGBSurfaceFrom(cairoSurface_->GetBuffer(), width, height, 32, - // cairoSurface_->GetPitch(), rmask, gmask, bmask, 0); - // if (!sdlSurface_) - // { - // LOG(ERROR) << "Cannot create a SDL surface from a Cairo surface"; - // throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); - // } - // } -// } - void SdlCairoViewport::Refresh() { @@ -114,17 +85,4 @@ window_.Render(sdlSurface_); } - - // void SdlCairoViewport::Render() - // { - // Orthanc::ImageAccessor target; - // compositor_.GetCanvas() cairoSurface_->GetWriteableAccessor(target); - - // if (viewport.Render(target)) - // { - // window_.Render(sdlSurface_); - // } - // } - - } diff -r 88bf49aebc13 -r 722ee73e6ba2 Framework/Viewport/SdlViewport.h --- a/Framework/Viewport/SdlViewport.h Wed Jul 17 16:56:53 2019 +0200 +++ b/Framework/Viewport/SdlViewport.h Thu Jul 18 09:19:39 2019 +0200 @@ -57,7 +57,6 @@ } - virtual SdlWindow& GetWindow() = 0; }; @@ -89,10 +88,6 @@ { return context_.GetWindow(); } - // SdlOpenGLContext& GetContext() - // { - // return context_; - // } }; diff -r 88bf49aebc13 -r 722ee73e6ba2 Framework/Viewport/WebAssemblyViewport.cpp --- a/Framework/Viewport/WebAssemblyViewport.cpp Wed Jul 17 16:56:53 2019 +0200 +++ b/Framework/Viewport/WebAssemblyViewport.cpp Thu Jul 18 09:19:39 2019 +0200 @@ -23,26 +23,42 @@ namespace OrthancStone { - WebAssemblyViewport::WebAssemblyViewport(const std::string& canvas) : - ViewportBase(canvas), + WebAssemblyOpenGLViewport::WebAssemblyOpenGLViewport(const std::string& canvas) : + WebAssemblyViewport(canvas), context_(canvas), compositor_(context_, GetScene()) { } - WebAssemblyViewport::WebAssemblyViewport(const std::string& canvas, - boost::shared_ptr& scene) : - ViewportBase(canvas, scene), + WebAssemblyOpenGLViewport::WebAssemblyOpenGLViewport(const std::string& canvas, + boost::shared_ptr& scene) : + WebAssemblyViewport(canvas, scene), context_(canvas), compositor_(context_, GetScene()) { } - void WebAssemblyViewport::UpdateSize() + void WebAssemblyOpenGLViewport::UpdateSize() { context_.UpdateSize(); // First read the size of the canvas compositor_.Refresh(); // Then refresh the content of the canvas } + + + WebAssemblyCairoViewport::WebAssemblyCairoViewport(const std::string& canvas, unsigned int width, unsigned int height) : + WebAssemblyViewport(canvas), + compositor_(GetScene(), width, height) + { + } + + + WebAssemblyCairoViewport::WebAssemblyCairoViewport(const std::string& canvas, + boost::shared_ptr& scene, unsigned int width, unsigned int height) : + WebAssemblyViewport(canvas, scene), + compositor_(GetScene(), width, height) + { + } + } diff -r 88bf49aebc13 -r 722ee73e6ba2 Framework/Viewport/WebAssemblyViewport.h --- a/Framework/Viewport/WebAssemblyViewport.h Wed Jul 17 16:56:53 2019 +0200 +++ b/Framework/Viewport/WebAssemblyViewport.h Thu Jul 18 09:19:39 2019 +0200 @@ -23,28 +23,70 @@ #include "../OpenGL/WebAssemblyOpenGLContext.h" #include "../Scene2D/OpenGLCompositor.h" +#include "../Scene2D/CairoCompositor.h" #include "ViewportBase.h" namespace OrthancStone { class WebAssemblyViewport : public ViewportBase { + public: + WebAssemblyViewport(const std::string& identifier) + : ViewportBase(identifier) + { + } + + WebAssemblyViewport(const std::string& identifier, + boost::shared_ptr& scene) + : ViewportBase(identifier, scene) + { + } + }; + + class WebAssemblyOpenGLViewport : public WebAssemblyViewport + { private: OpenGL::WebAssemblyOpenGLContext context_; OpenGLCompositor compositor_; public: - WebAssemblyViewport(const std::string& canvas); + WebAssemblyOpenGLViewport(const std::string& canvas); - WebAssemblyViewport(const std::string& canvas, - boost::shared_ptr& scene); + WebAssemblyOpenGLViewport(const std::string& canvas, + boost::shared_ptr& scene); // This function must be called each time the browser window is resized void UpdateSize(); - ICompositor& GetCompositor() + virtual ICompositor& GetCompositor() { return compositor_; } }; + + class WebAssemblyCairoViewport : public WebAssemblyViewport + { + private: + CairoCompositor compositor_; + + public: + WebAssemblyCairoViewport(const std::string& canvas, + unsigned int width, + unsigned int height); + + WebAssemblyCairoViewport(const std::string& canvas, + boost::shared_ptr& scene, + unsigned int width, + unsigned int height); + + // This function must be called each time the browser window is resized + void UpdateSize(); // TODO: implement + + // TODO: implement Refresh + virtual ICompositor& GetCompositor() + { + return compositor_; + } + }; + }