Mercurial > hg > orthanc-stone
comparison Framework/Viewport/WebAssemblyViewport.cpp @ 910:a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Thu, 18 Jul 2019 10:39:00 +0200 |
parents | 722ee73e6ba2 |
children | 685c9a2d115f |
comparison
equal
deleted
inserted
replaced
909:7a7e4e1f558f | 910:a6c12fe88bcb |
---|---|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | 19 **/ |
20 | 20 |
21 | 21 |
22 #include "WebAssemblyViewport.h" | 22 #include "WebAssemblyViewport.h" |
23 #include <emscripten/html5.h> | |
23 | 24 |
24 namespace OrthancStone | 25 namespace OrthancStone |
25 { | 26 { |
26 WebAssemblyOpenGLViewport::WebAssemblyOpenGLViewport(const std::string& canvas) : | 27 WebAssemblyOpenGLViewport::WebAssemblyOpenGLViewport(const std::string& canvas) : |
27 WebAssemblyViewport(canvas), | 28 WebAssemblyViewport(canvas), |
45 context_.UpdateSize(); // First read the size of the canvas | 46 context_.UpdateSize(); // First read the size of the canvas |
46 compositor_.Refresh(); // Then refresh the content of the canvas | 47 compositor_.Refresh(); // Then refresh the content of the canvas |
47 } | 48 } |
48 | 49 |
49 | 50 |
50 WebAssemblyCairoViewport::WebAssemblyCairoViewport(const std::string& canvas, unsigned int width, unsigned int height) : | 51 WebAssemblyCairoViewport::WebAssemblyCairoViewport(const std::string& canvas) : |
51 WebAssemblyViewport(canvas), | 52 WebAssemblyViewport(canvas), |
52 compositor_(GetScene(), width, height) | 53 canvas_(canvas), |
54 compositor_(GetScene(), 1024, 768) | |
53 { | 55 { |
54 } | 56 } |
55 | 57 |
56 | 58 |
57 WebAssemblyCairoViewport::WebAssemblyCairoViewport(const std::string& canvas, | 59 WebAssemblyCairoViewport::WebAssemblyCairoViewport(const std::string& canvas, |
58 boost::shared_ptr<Scene2D>& scene, unsigned int width, unsigned int height) : | 60 boost::shared_ptr<Scene2D>& scene) : |
59 WebAssemblyViewport(canvas, scene), | 61 WebAssemblyViewport(canvas, scene), |
60 compositor_(GetScene(), width, height) | 62 canvas_(canvas), |
63 compositor_(GetScene(), 1024, 768) | |
61 { | 64 { |
62 } | 65 } |
63 | 66 |
67 | |
68 void WebAssemblyCairoViewport::UpdateSize() | |
69 { | |
70 LOG(INFO) << "updating cairo viewport size"; | |
71 double w, h; | |
72 emscripten_get_element_css_size(canvas_.c_str(), &w, &h); | |
73 | |
74 /** | |
75 * Emscripten has the function emscripten_get_element_css_size() | |
76 * to query the width and height of a named HTML element. I'm | |
77 * calling this first to get the initial size of the canvas DOM | |
78 * element, and then call emscripten_set_canvas_size() to | |
79 * initialize the framebuffer size of the canvas to the same | |
80 * size as its DOM element. | |
81 * https://floooh.github.io/2017/02/22/emsc-html.html | |
82 **/ | |
83 unsigned int canvasWidth = 0; | |
84 unsigned int canvasHeight = 0; | |
85 | |
86 if (w > 0 || | |
87 h > 0) | |
88 { | |
89 canvasWidth = static_cast<unsigned int>(boost::math::iround(w)); | |
90 canvasHeight = static_cast<unsigned int>(boost::math::iround(h)); | |
91 } | |
92 | |
93 emscripten_set_canvas_element_size(canvas_.c_str(), canvasWidth, canvasHeight); | |
94 compositor_.UpdateSize(canvasWidth, canvasHeight); | |
95 } | |
96 | |
97 void WebAssemblyCairoViewport::Refresh() | |
98 { | |
99 LOG(INFO) << "refreshing cairo viewport, TODO: blit to the canvans.getContext('2d')"; | |
100 GetCompositor().Refresh(); | |
101 } | |
102 | |
64 } | 103 } |