annotate Framework/Viewport/SdlViewport.cpp @ 1455:30deba7bc8e2

simplifying include_directories
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 11 Jun 2020 20:54:01 +0200
parents 32272ecfc6c2
children
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
1270
2d8ab34c8c91 upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1055
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
891
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
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1391
diff changeset
23 #include <OrthancException.h>
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1315
diff changeset
25 #include <boost/make_shared.hpp>
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1315
diff changeset
26
891
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 {
1216
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
29 ICompositor& SdlViewport::SdlLock::GetCompositor()
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
30 {
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
31 if (that_.compositor_.get() == NULL)
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
32 {
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
33 // The derived class should have called "AcquireCompositor()"
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
34 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
35 }
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
36 else
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
37 {
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
38 return *that_.compositor_;
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
39 }
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
40 }
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
41
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
42
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
43 void SdlViewport::AcquireCompositor(ICompositor* compositor /* takes ownership */)
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
44 {
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
45 if (compositor == NULL)
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
46 {
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
47 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
48 }
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
49
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
50 compositor_.reset(compositor);
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
51 }
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
52
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1315
diff changeset
53 SdlViewport::SdlViewport()
1205
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
54 {
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
55 refreshEvent_ = SDL_RegisterEvents(1);
1307
8a28a9bf8876 ViewportController now gets a ref to its parent viewport for proper lock usage
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
56
1205
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
57 if (refreshEvent_ == static_cast<uint32_t>(-1))
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
58 {
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
59 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
60 }
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
61 }
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1315
diff changeset
62
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1315
diff changeset
63 void SdlViewport::PostConstructor()
1307
8a28a9bf8876 ViewportController now gets a ref to its parent viewport for proper lock usage
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
64 {
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1315
diff changeset
65 controller_ = boost::make_shared<ViewportController>(shared_from_this());
1307
8a28a9bf8876 ViewportController now gets a ref to its parent viewport for proper lock usage
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
66 }
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1315
diff changeset
67
1205
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
68 void SdlViewport::SendRefreshEvent()
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
69 {
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
70 SDL_Event event;
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
71 SDL_memset(&event, 0, sizeof(event));
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
72 event.type = refreshEvent_;
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
73 SDL_PushEvent(&event); // This function is thread-safe, and can be called from other threads safely.
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
74 }
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
75
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
76
1332
be614695747d std::string in viewport ctor
Benjamin Golinvaux <bgo@osimis.io>
parents: 1331
diff changeset
77 SdlOpenGLViewport::SdlOpenGLViewport(const std::string& title,
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
78 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
79 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
80 bool allowDpiScaling) :
1332
be614695747d std::string in viewport ctor
Benjamin Golinvaux <bgo@osimis.io>
parents: 1331
diff changeset
81 context_(title.c_str(), 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
82 {
1216
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
83 AcquireCompositor(new OpenGLCompositor(context_)); // (*)
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
84 }
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
85
1332
be614695747d std::string in viewport ctor
Benjamin Golinvaux <bgo@osimis.io>
parents: 1331
diff changeset
86 boost::shared_ptr<SdlOpenGLViewport> SdlOpenGLViewport::Create(
be614695747d std::string in viewport ctor
Benjamin Golinvaux <bgo@osimis.io>
parents: 1331
diff changeset
87 const std::string& title,
be614695747d std::string in viewport ctor
Benjamin Golinvaux <bgo@osimis.io>
parents: 1331
diff changeset
88 unsigned int width,
be614695747d std::string in viewport ctor
Benjamin Golinvaux <bgo@osimis.io>
parents: 1331
diff changeset
89 unsigned int height,
be614695747d std::string in viewport ctor
Benjamin Golinvaux <bgo@osimis.io>
parents: 1331
diff changeset
90 bool allowDpiScaling)
1307
8a28a9bf8876 ViewportController now gets a ref to its parent viewport for proper lock usage
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
91 {
1331
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1315
diff changeset
92 boost::shared_ptr<SdlOpenGLViewport> that =
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1315
diff changeset
93 boost::shared_ptr<SdlOpenGLViewport>(new SdlOpenGLViewport(title, width, height, allowDpiScaling));
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1315
diff changeset
94 that->SdlViewport::PostConstructor();
ab81ee8fce1f - Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents: 1315
diff changeset
95 return that;
1307
8a28a9bf8876 ViewportController now gets a ref to its parent viewport for proper lock usage
Benjamin Golinvaux <bgo@osimis.io>
parents: 1279
diff changeset
96 }
1216
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
97
1391
32272ecfc6c2 Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents: 1332
diff changeset
98 uint32_t SdlOpenGLViewport::GetSdlWindowId()
32272ecfc6c2 Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents: 1332
diff changeset
99 {
32272ecfc6c2 Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents: 1332
diff changeset
100 SdlWindow& sdlWindowWrapper = context_.GetWindow();
32272ecfc6c2 Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents: 1332
diff changeset
101 SDL_Window* sdlWindow = sdlWindowWrapper.GetObject();
32272ecfc6c2 Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents: 1332
diff changeset
102 Uint32 sdlWindowId = SDL_GetWindowID(sdlWindow);
32272ecfc6c2 Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents: 1332
diff changeset
103 return sdlWindowId;
32272ecfc6c2 Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents: 1332
diff changeset
104 }
32272ecfc6c2 Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents: 1332
diff changeset
105
1216
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
106 SdlOpenGLViewport::~SdlOpenGLViewport()
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
107 {
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
108 // Make sure that the "OpenGLCompositor" is destroyed BEFORE the
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
109 // "OpenGLContext" it references (*)
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
110 ClearCompositor();
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
111 }
1315
1a08b779be64 warning 4996 (deprecation in jsoncpp) + indentation changes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1311
diff changeset
112
1a08b779be64 warning 4996 (deprecation in jsoncpp) + indentation changes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1311
diff changeset
113
1216
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
114 void SdlOpenGLViewport::Paint()
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
115 {
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
116 SdlLock lock(*this);
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
117 lock.GetCompositor().Refresh(lock.GetController().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
118 }
1315
1a08b779be64 warning 4996 (deprecation in jsoncpp) + indentation changes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1311
diff changeset
119
1a08b779be64 warning 4996 (deprecation in jsoncpp) + indentation changes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1311
diff changeset
120
1a08b779be64 warning 4996 (deprecation in jsoncpp) + indentation changes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1311
diff changeset
121 void SdlOpenGLViewport::UpdateSize(unsigned int width, unsigned int height)
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 909
diff changeset
122 {
1216
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
123 // nothing to do in OpenGL, the OpenGLCompositor::UpdateSize will be called automatically
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
124 SdlLock lock(*this);
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
125 lock.Invalidate();
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 909
diff changeset
126 }
1315
1a08b779be64 warning 4996 (deprecation in jsoncpp) + indentation changes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1311
diff changeset
127
1a08b779be64 warning 4996 (deprecation in jsoncpp) + indentation changes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1311
diff changeset
128
1216
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
129 void SdlOpenGLViewport::ToggleMaximize()
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
1216
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
131 // No need to call "Invalidate()" here, as "UpdateSize()" will
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
132 // be invoked after event "SDL_WINDOWEVENT_SIZE_CHANGED"
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
133 SdlLock lock(*this);
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
134 context_.ToggleMaximize();
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 }
1315
1a08b779be64 warning 4996 (deprecation in jsoncpp) + indentation changes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1311
diff changeset
136
1a08b779be64 warning 4996 (deprecation in jsoncpp) + indentation changes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1311
diff changeset
137
1a08b779be64 warning 4996 (deprecation in jsoncpp) + indentation changes
Benjamin Golinvaux <bgo@osimis.io>
parents: 1311
diff changeset
138
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
139 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
140 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
141 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
142 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
143 window_(title, width, height, false /* enable OpenGL */, allowDpiScaling),
1205
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
144 sdlSurface_(NULL)
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
145 {
1216
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
146 AcquireCompositor(new CairoCompositor(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
147 }
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
148
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
149 SdlCairoViewport::~SdlCairoViewport()
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 {
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
151 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
152 {
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
153 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
154 }
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 }
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 909
diff changeset
156
1391
32272ecfc6c2 Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents: 1332
diff changeset
157 uint32_t SdlCairoViewport::GetSdlWindowId()
32272ecfc6c2 Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents: 1332
diff changeset
158 {
32272ecfc6c2 Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents: 1332
diff changeset
159 SDL_Window* sdlWindow = window_.GetObject();
32272ecfc6c2 Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents: 1332
diff changeset
160 Uint32 sdlWindowId = SDL_GetWindowID(sdlWindow);
32272ecfc6c2 Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents: 1332
diff changeset
161 return sdlWindowId;
32272ecfc6c2 Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents: 1332
diff changeset
162 }
32272ecfc6c2 Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents: 1332
diff changeset
163
1216
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
164 void SdlCairoViewport::Paint()
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
165 {
1216
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
166 SdlLock lock(*this);
1213
86a8266b8888 moving the scene from IViewport to ViewportController
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1211
diff changeset
167
1216
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
168 lock.GetCompositor().Refresh(lock.GetController().GetScene());
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
169 CreateSdlSurfaceFromCompositor(dynamic_cast<CairoCompositor&>(lock.GetCompositor()));
1205
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
170
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
171 if (sdlSurface_ != NULL)
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
172 {
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
173 window_.Render(sdlSurface_);
1216
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
174 }
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
175 }
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
176
1203
f3bb9a6dd949 locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1055
diff changeset
177
909
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
178 void SdlCairoViewport::UpdateSize(unsigned int width,
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
179 unsigned int height)
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
180 {
1216
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
181 SdlLock lock(*this);
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
182 dynamic_cast<CairoCompositor&>(lock.GetCompositor()).UpdateSize(width, height);
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
183 lock.Invalidate();
909
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
184 }
947
1091b2adeb5a Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents: 909
diff changeset
185
1216
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
186
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
187 void SdlCairoViewport::ToggleMaximize()
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
188 {
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
189 // No need to call "Invalidate()" here, as "UpdateSize()" will
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
190 // be invoked after event "SDL_WINDOWEVENT_SIZE_CHANGED"
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
191 SdlLock lock(*this);
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
192 window_.ToggleMaximize();
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
193 }
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
194
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
195
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
196 // Assumes that the mutex is locked
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
197 void SdlCairoViewport::CreateSdlSurfaceFromCompositor(CairoCompositor& compositor)
909
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
198 {
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
199 static const uint32_t rmask = 0x00ff0000;
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
200 static const uint32_t gmask = 0x0000ff00;
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
201 static const uint32_t bmask = 0x000000ff;
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
202
1216
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
203 const unsigned int width = compositor.GetCanvas().GetWidth();
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
204 const unsigned int height = compositor.GetCanvas().GetHeight();
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
205
1205
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
206 if (sdlSurface_ != NULL)
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
207 {
1216
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
208 if (sdlSurface_->pixels == compositor.GetCanvas().GetBuffer() &&
1205
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
209 sdlSurface_->w == static_cast<int>(width) &&
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
210 sdlSurface_->h == static_cast<int>(height) &&
1216
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
211 sdlSurface_->pitch == static_cast<int>(compositor.GetCanvas().GetPitch()))
1205
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
212 {
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
213 // The image from the compositor has not changed, no need to update the surface
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
214 return;
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
215 }
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
216 else
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
217 {
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
218 SDL_FreeSurface(sdlSurface_);
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
219 }
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
220 }
6009c59d8676 fix to sdl
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1203
diff changeset
221
1216
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
222 sdlSurface_ = SDL_CreateRGBSurfaceFrom((void*)(compositor.GetCanvas().GetBuffer()), width, height, 32,
5147277850cf better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1213
diff changeset
223 compositor.GetCanvas().GetPitch(), rmask, gmask, bmask, 0);
909
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
224 if (!sdlSurface_)
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
225 {
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
226 LOG(ERROR) << "Cannot create a SDL surface from a Cairo surface";
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
227 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
228 }
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 907
diff changeset
229 }
891
0aff28f15ea2 new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 }