Mercurial > hg > orthanc-stone
annotate Framework/Viewport/WebAssemblyViewport.cpp @ 924:9ba1e1198e73
merge
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Mon, 22 Jul 2019 14:29:23 +0200 |
parents | a6c12fe88bcb |
children | 685c9a2d115f |
rev | line source |
---|---|
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Stone of Orthanc |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 **/ |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 #include "WebAssemblyViewport.h" |
910
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
23 #include <emscripten/html5.h> |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 namespace OrthancStone |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 { |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
27 WebAssemblyOpenGLViewport::WebAssemblyOpenGLViewport(const std::string& canvas) : |
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
28 WebAssemblyViewport(canvas), |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 context_(canvas), |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 compositor_(context_, GetScene()) |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 { |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 } |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
35 WebAssemblyOpenGLViewport::WebAssemblyOpenGLViewport(const std::string& canvas, |
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
36 boost::shared_ptr<Scene2D>& scene) : |
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
37 WebAssemblyViewport(canvas, scene), |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 context_(canvas), |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 compositor_(context_, GetScene()) |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 { |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 } |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
44 void WebAssemblyOpenGLViewport::UpdateSize() |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 { |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 context_.UpdateSize(); // First read the size of the canvas |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 compositor_.Refresh(); // Then refresh the content of the canvas |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 } |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
49 |
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
50 |
910
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
51 WebAssemblyCairoViewport::WebAssemblyCairoViewport(const std::string& canvas) : |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
52 WebAssemblyViewport(canvas), |
910
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
53 canvas_(canvas), |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
54 compositor_(GetScene(), 1024, 768) |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
55 { |
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
56 } |
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
57 |
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
58 |
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
59 WebAssemblyCairoViewport::WebAssemblyCairoViewport(const std::string& canvas, |
910
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
60 boost::shared_ptr<Scene2D>& scene) : |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
61 WebAssemblyViewport(canvas, scene), |
910
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
62 canvas_(canvas), |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
63 compositor_(GetScene(), 1024, 768) |
907
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
64 { |
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
65 } |
722ee73e6ba2
cleanup + started to implement WebAssemblyCairoViewport (wip)
Alain Mazy <alain@mazy.be>
parents:
891
diff
changeset
|
66 |
910
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
67 |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
68 void WebAssemblyCairoViewport::UpdateSize() |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
69 { |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
70 LOG(INFO) << "updating cairo viewport size"; |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
71 double w, h; |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
72 emscripten_get_element_css_size(canvas_.c_str(), &w, &h); |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
73 |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
74 /** |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
75 * Emscripten has the function emscripten_get_element_css_size() |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
76 * to query the width and height of a named HTML element. I'm |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
77 * calling this first to get the initial size of the canvas DOM |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
78 * element, and then call emscripten_set_canvas_size() to |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
79 * initialize the framebuffer size of the canvas to the same |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
80 * size as its DOM element. |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
81 * https://floooh.github.io/2017/02/22/emsc-html.html |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
82 **/ |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
83 unsigned int canvasWidth = 0; |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
84 unsigned int canvasHeight = 0; |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
85 |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
86 if (w > 0 || |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
87 h > 0) |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
88 { |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
89 canvasWidth = static_cast<unsigned int>(boost::math::iround(w)); |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
90 canvasHeight = static_cast<unsigned int>(boost::math::iround(h)); |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
91 } |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
92 |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
93 emscripten_set_canvas_element_size(canvas_.c_str(), canvasWidth, canvasHeight); |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
94 compositor_.UpdateSize(canvasWidth, canvasHeight); |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
95 } |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
96 |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
97 void WebAssemblyCairoViewport::Refresh() |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
98 { |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
99 LOG(INFO) << "refreshing cairo viewport, TODO: blit to the canvans.getContext('2d')"; |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
100 GetCompositor().Refresh(); |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
101 } |
a6c12fe88bcb
wip: WebAssemblyCairoViewport: still need to implement blit to canvas
Alain Mazy <alain@mazy.be>
parents:
907
diff
changeset
|
102 |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 } |