annotate Framework/Viewport/SdlViewport.cpp @ 1055:af456106576c

moving GetCanvasIdentifier from IViewport to WebAssemblyViewport
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 10 Oct 2019 16:07:58 +0200
parents 32b403a47b19
children f3bb9a6dd949 2d8ab34c8c91
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 #include "SdlViewport.h"
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include <Core/OrthancException.h>
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 #include <boost/make_shared.hpp>
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 namespace OrthancStone
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 {
905
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
29 SdlOpenGLViewport::SdlOpenGLViewport(const char* title,
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
30 unsigned int width,
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
31 unsigned int height,
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
32 bool allowDpiScaling) :
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 909
diff changeset
33 context_(title, width, height, allowDpiScaling)
905
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
34 {
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 909
diff changeset
35 compositor_.reset(new OpenGLCompositor(context_, GetScene()));
905
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
36 }
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
37
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
38 SdlOpenGLViewport::SdlOpenGLViewport(const char* title,
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
39 unsigned int width,
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
40 unsigned int height,
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
41 boost::shared_ptr<Scene2D>& scene,
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
42 bool allowDpiScaling) :
1055
af456106576c moving GetCanvasIdentifier from IViewport to WebAssemblyViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1053
diff changeset
43 SdlViewport(scene),
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 909
diff changeset
44 context_(title, width, height, allowDpiScaling)
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 909
diff changeset
45 {
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 909
diff changeset
46 compositor_.reset(new OpenGLCompositor(context_, GetScene()));
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 909
diff changeset
47 }
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 909
diff changeset
48
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 909
diff changeset
49 void SdlOpenGLViewport::Refresh()
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
1053
32b403a47b19 simplifying IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1045
diff changeset
51 compositor_->Refresh();
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
905
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
54
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
55 SdlCairoViewport::SdlCairoViewport(const char* title,
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
56 unsigned int width,
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
57 unsigned int height,
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
58 bool allowDpiScaling) :
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
59 window_(title, width, height, false /* enable OpenGL */, allowDpiScaling),
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
60 compositor_(GetScene(), width, height)
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
61 {
909
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
62 UpdateSdlSurfaceSize(width, height);
905
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
63 }
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
64
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
65 SdlCairoViewport::~SdlCairoViewport()
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
905
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
67 if (sdlSurface_)
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
68 {
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
69 SDL_FreeSurface(sdlSurface_);
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
70 }
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 }
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 909
diff changeset
72
905
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
73 void SdlCairoViewport::Refresh()
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
74 {
1053
32b403a47b19 simplifying IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1045
diff changeset
75 compositor_.Refresh();
905
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
76 window_.Render(sdlSurface_);
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
77 }
88bf49aebc13 introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
Alain Mazy <alain@mazy.be>
parents: 893
diff changeset
78
909
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
79 void SdlCairoViewport::UpdateSize(unsigned int width,
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
80 unsigned int height)
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
81 {
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
82 compositor_.UpdateSize(width, height);
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
83 UpdateSdlSurfaceSize(width, height);
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
84 Refresh();
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
85 }
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 909
diff changeset
86
909
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
87 void SdlCairoViewport::UpdateSdlSurfaceSize(unsigned int width,
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
88 unsigned int height)
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
89 {
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
90 static const uint32_t rmask = 0x00ff0000;
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
91 static const uint32_t gmask = 0x0000ff00;
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
92 static const uint32_t bmask = 0x000000ff;
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
93
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
94 sdlSurface_ = SDL_CreateRGBSurfaceFrom((void*)(compositor_.GetCanvas().GetBuffer()), width, height, 32,
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
95 compositor_.GetCanvas().GetPitch(), rmask, gmask, bmask, 0);
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
96 if (!sdlSurface_)
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
97 {
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
98 LOG(ERROR) << "Cannot create a SDL surface from a Cairo surface";
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
99 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
100 }
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
101 }
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }