Mercurial > hg > orthanc-stone
annotate Applications/Platforms/Sdl/SdlViewport.cpp @ 1873:e0966648ebd0
unit tests of SegmentTree
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 11 Jan 2022 15:36:04 +0100 |
parents | 7053b8a0aaec |
children |
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 |
1871
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * 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
|
10 * as published by the Free Software Foundation, either version 3 of |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * the License, or (at your option) any later version. |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * 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
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * Affero General Public License for more details. |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * 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
|
19 * 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
|
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 "SdlViewport.h" |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
1591
5887a4f8594b
moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
24 #include "../../../OrthancStone/Sources/Scene2DViewport/ViewportController.h" |
1560
b4ccd4963d37
fix sdl and wasm samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
25 |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1391
diff
changeset
|
26 #include <OrthancException.h> |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1315
diff
changeset
|
28 #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
|
29 |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 namespace OrthancStone |
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 { |
1216
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
32 ICompositor& SdlViewport::SdlLock::GetCompositor() |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
33 { |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
34 if (that_.compositor_.get() == NULL) |
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 // The derived class should have called "AcquireCompositor()" |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
37 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
38 } |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
39 else |
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 return *that_.compositor_; |
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 } |
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 |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
46 void SdlViewport::AcquireCompositor(ICompositor* compositor /* takes ownership */) |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
47 { |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
48 if (compositor == NULL) |
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 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
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 |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
53 compositor_.reset(compositor); |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
54 } |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
55 |
1576
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
56 |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1315
diff
changeset
|
57 SdlViewport::SdlViewport() |
1205 | 58 { |
59 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
|
60 |
1205 | 61 if (refreshEvent_ == static_cast<uint32_t>(-1)) |
62 { | |
63 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
64 } | |
65 } | |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1315
diff
changeset
|
66 |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1315
diff
changeset
|
67 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
|
68 { |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1315
diff
changeset
|
69 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
|
70 } |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1315
diff
changeset
|
71 |
1205 | 72 void SdlViewport::SendRefreshEvent() |
73 { | |
74 SDL_Event event; | |
75 SDL_memset(&event, 0, sizeof(event)); | |
76 event.type = refreshEvent_; | |
77 SDL_PushEvent(&event); // This function is thread-safe, and can be called from other threads safely. | |
78 } | |
79 | |
80 | |
1576
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
81 void SdlViewport::UpdateSize(unsigned int width, unsigned int height) |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
82 { |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
83 SdlLock lock(*this); |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
84 lock.GetCompositor().SetCanvasSize(width, height); |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
85 lock.Invalidate(); |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
86 } |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
87 |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
88 |
1804 | 89 #if ORTHANC_ENABLE_OPENGL == 1 |
1332
be614695747d
std::string in viewport ctor
Benjamin Golinvaux <bgo@osimis.io>
parents:
1331
diff
changeset
|
90 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
|
91 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
|
92 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
|
93 bool allowDpiScaling) : |
1332
be614695747d
std::string in viewport ctor
Benjamin Golinvaux <bgo@osimis.io>
parents:
1331
diff
changeset
|
94 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
|
95 { |
1216
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
96 AcquireCompositor(new OpenGLCompositor(context_)); // (*) |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
97 } |
1804 | 98 #endif |
1216
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
99 |
1576
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
100 |
1804 | 101 #if ORTHANC_ENABLE_OPENGL == 1 |
1576
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
102 void SdlOpenGLViewport::RefreshCanvasSize() |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
103 { |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
104 UpdateSize(context_.GetCanvasWidth(), context_.GetCanvasHeight()); |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
105 } |
1804 | 106 #endif |
1576
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
107 |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
108 |
1804 | 109 #if ORTHANC_ENABLE_OPENGL == 1 |
110 boost::shared_ptr<SdlOpenGLViewport> SdlOpenGLViewport::Create(const std::string& title, | |
111 unsigned int width, | |
112 unsigned int height, | |
113 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
|
114 { |
1331
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1315
diff
changeset
|
115 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
|
116 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
|
117 that->SdlViewport::PostConstructor(); |
ab81ee8fce1f
- Viewport is not passed and stored as a shared_ptr instead
Benjamin Golinvaux <bgo@osimis.io>
parents:
1315
diff
changeset
|
118 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
|
119 } |
1804 | 120 #endif |
1216
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
121 |
1804 | 122 |
123 #if ORTHANC_ENABLE_OPENGL == 1 | |
1391
32272ecfc6c2
Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents:
1332
diff
changeset
|
124 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
|
125 { |
1571 | 126 const SdlWindow& sdlWindowWrapper = context_.GetWindow(); |
1391
32272ecfc6c2
Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents:
1332
diff
changeset
|
127 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
|
128 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
|
129 return sdlWindowId; |
32272ecfc6c2
Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents:
1332
diff
changeset
|
130 } |
1804 | 131 #endif |
132 | |
1391
32272ecfc6c2
Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents:
1332
diff
changeset
|
133 |
1804 | 134 #if ORTHANC_ENABLE_OPENGL == 1 |
1216
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
135 SdlOpenGLViewport::~SdlOpenGLViewport() |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
136 { |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
137 // Make sure that the "OpenGLCompositor" is destroyed BEFORE the |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
138 // "OpenGLContext" it references (*) |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
139 ClearCompositor(); |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
140 } |
1804 | 141 #endif |
1315
1a08b779be64
warning 4996 (deprecation in jsoncpp) + indentation changes
Benjamin Golinvaux <bgo@osimis.io>
parents:
1311
diff
changeset
|
142 |
1a08b779be64
warning 4996 (deprecation in jsoncpp) + indentation changes
Benjamin Golinvaux <bgo@osimis.io>
parents:
1311
diff
changeset
|
143 |
1804 | 144 #if ORTHANC_ENABLE_OPENGL == 1 |
1216
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
145 void SdlOpenGLViewport::Paint() |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
146 { |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
147 SdlLock lock(*this); |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
148 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
|
149 } |
1804 | 150 #endif |
1315
1a08b779be64
warning 4996 (deprecation in jsoncpp) + indentation changes
Benjamin Golinvaux <bgo@osimis.io>
parents:
1311
diff
changeset
|
151 |
1a08b779be64
warning 4996 (deprecation in jsoncpp) + indentation changes
Benjamin Golinvaux <bgo@osimis.io>
parents:
1311
diff
changeset
|
152 |
1804 | 153 #if ORTHANC_ENABLE_OPENGL == 1 |
1216
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
154 void SdlOpenGLViewport::ToggleMaximize() |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 { |
1216
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
156 // No need to call "Invalidate()" here, as "UpdateSize()" will |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
157 // be invoked after event "SDL_WINDOWEVENT_SIZE_CHANGED" |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
158 SdlLock lock(*this); |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
159 context_.ToggleMaximize(); |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 } |
1804 | 161 #endif |
1315
1a08b779be64
warning 4996 (deprecation in jsoncpp) + indentation changes
Benjamin Golinvaux <bgo@osimis.io>
parents:
1311
diff
changeset
|
162 |
1a08b779be64
warning 4996 (deprecation in jsoncpp) + indentation changes
Benjamin Golinvaux <bgo@osimis.io>
parents:
1311
diff
changeset
|
163 |
1576
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
164 void SdlCairoViewport::RefreshCanvasSize() |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
165 { |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
166 UpdateSize(window_.GetWidth(), window_.GetHeight()); |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
167 } |
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
168 |
1804 | 169 SdlCairoViewport::SdlCairoViewport(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
|
170 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
|
171 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
|
172 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
|
173 window_(title, width, height, false /* enable OpenGL */, allowDpiScaling), |
1205 | 174 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
|
175 { |
1216
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
176 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
|
177 } |
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
|
178 |
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
|
179 SdlCairoViewport::~SdlCairoViewport() |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 { |
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
|
181 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
|
182 { |
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
|
183 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
|
184 } |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 } |
947
1091b2adeb5a
Fixed animation frame stopping when returning false + big work on the OpenGL
Benjamin Golinvaux <bgo@osimis.io>
parents:
909
diff
changeset
|
186 |
1391
32272ecfc6c2
Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents:
1332
diff
changeset
|
187 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
|
188 { |
32272ecfc6c2
Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents:
1332
diff
changeset
|
189 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
|
190 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
|
191 return sdlWindowId; |
32272ecfc6c2
Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents:
1332
diff
changeset
|
192 } |
32272ecfc6c2
Drilled a hole through the abstractions to be able to match
Benjamin Golinvaux <bgo@osimis.io>
parents:
1332
diff
changeset
|
193 |
1216
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
194 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
|
195 { |
1216
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
196 SdlLock lock(*this); |
1213
86a8266b8888
moving the scene from IViewport to ViewportController
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1211
diff
changeset
|
197 |
1216
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
198 lock.GetCompositor().Refresh(lock.GetController().GetScene()); |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
199 CreateSdlSurfaceFromCompositor(dynamic_cast<CairoCompositor&>(lock.GetCompositor())); |
1205 | 200 |
201 if (sdlSurface_ != NULL) | |
202 { | |
203 window_.Render(sdlSurface_); | |
1216
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
204 } |
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
|
205 } |
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
|
206 |
1203
f3bb9a6dd949
locking abstraction in IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1055
diff
changeset
|
207 |
1216
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
208 void SdlCairoViewport::ToggleMaximize() |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
209 { |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
210 // No need to call "Invalidate()" here, as "UpdateSize()" will |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
211 // be invoked after event "SDL_WINDOWEVENT_SIZE_CHANGED" |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
212 SdlLock lock(*this); |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
213 window_.ToggleMaximize(); |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
214 } |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
215 |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
216 |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
217 // Assumes that the mutex is locked |
1571 | 218 void SdlCairoViewport::CreateSdlSurfaceFromCompositor(const CairoCompositor& compositor) |
909 | 219 { |
220 static const uint32_t rmask = 0x00ff0000; | |
221 static const uint32_t gmask = 0x0000ff00; | |
222 static const uint32_t bmask = 0x000000ff; | |
223 | |
1216
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
224 const unsigned int width = compositor.GetCanvas().GetWidth(); |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
225 const unsigned int height = compositor.GetCanvas().GetHeight(); |
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
226 |
1205 | 227 if (sdlSurface_ != NULL) |
228 { | |
1216
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
229 if (sdlSurface_->pixels == compositor.GetCanvas().GetBuffer() && |
1205 | 230 sdlSurface_->w == static_cast<int>(width) && |
231 sdlSurface_->h == static_cast<int>(height) && | |
1216
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
232 sdlSurface_->pitch == static_cast<int>(compositor.GetCanvas().GetPitch())) |
1205 | 233 { |
234 // The image from the compositor has not changed, no need to update the surface | |
235 return; | |
236 } | |
237 else | |
238 { | |
239 SDL_FreeSurface(sdlSurface_); | |
240 } | |
241 } | |
242 | |
1216
5147277850cf
better abstraction for IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1213
diff
changeset
|
243 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
|
244 compositor.GetCanvas().GetPitch(), rmask, gmask, bmask, 0); |
909 | 245 if (!sdlSurface_) |
246 { | |
247 LOG(ERROR) << "Cannot create a SDL surface from a Cairo surface"; | |
248 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
249 } | |
250 } | |
1804 | 251 |
252 | |
253 boost::shared_ptr<SdlCairoViewport> SdlCairoViewport::Create(const std::string& title, | |
254 unsigned int width, | |
255 unsigned int height, | |
256 bool allowDpiScaling) | |
257 { | |
258 boost::shared_ptr<SdlCairoViewport> that = | |
259 boost::shared_ptr<SdlCairoViewport>(new SdlCairoViewport(title, width, height, allowDpiScaling)); | |
260 that->SdlViewport::PostConstructor(); | |
261 return that; | |
262 } | |
891
0aff28f15ea2
new abstraction: IViewport
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
263 } |