Mercurial > hg > orthanc-stone
annotate Applications/Resources/Graveyard/Threading/SdlBuffering.cpp @ 2012:637d6373127a
width of the vertical slider has doubled to ease user interactions
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 02 Dec 2022 18:49:06 +0100 |
parents | 7053b8a0aaec |
children | 07964689cb0b |
rev | line source |
---|---|
0 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
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 |
0 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
47 | 9 * modify it under the terms of the GNU Affero General Public License |
10 * as published by the Free Software Foundation, either version 3 of | |
11 * the License, or (at your option) any later version. | |
0 | 12 * |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
47 | 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 * Affero General Public License for more details. | |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1586
diff
changeset
|
17 * |
47 | 18 * You should have received a copy of the GNU Affero General Public License |
0 | 19 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 **/ | |
21 | |
22 | |
23 #include "SdlBuffering.h" | |
24 | |
25 #if ORTHANC_ENABLE_SDL == 1 | |
26 | |
84 | 27 #include "../../Resources/Orthanc/Core/Logging.h" |
28 #include "../../Resources/Orthanc/Core/OrthancException.h" | |
0 | 29 |
30 namespace OrthancStone | |
31 { | |
32 SdlBuffering::SdlBuffering() : | |
33 sdlSurface_(NULL), | |
34 pendingFrame_(false) | |
35 { | |
36 } | |
37 | |
38 | |
39 SdlBuffering::~SdlBuffering() | |
40 { | |
41 if (sdlSurface_) | |
42 { | |
43 SDL_FreeSurface(sdlSurface_); | |
44 } | |
45 } | |
46 | |
47 | |
48 void SdlBuffering::SetSize(unsigned int width, | |
49 unsigned int height, | |
50 IViewport& viewport) | |
51 { | |
52 boost::mutex::scoped_lock lock(mutex_); | |
53 | |
54 viewport.SetSize(width, height); | |
55 | |
56 if (offscreenSurface_.get() == NULL || | |
57 offscreenSurface_->GetWidth() != width || | |
58 offscreenSurface_->GetHeight() != height) | |
59 { | |
60 offscreenSurface_.reset(new CairoSurface(width, height)); | |
61 } | |
62 | |
63 if (onscreenSurface_.get() == NULL || | |
64 onscreenSurface_->GetWidth() != width || | |
65 onscreenSurface_->GetHeight() != height) | |
66 { | |
67 onscreenSurface_.reset(new CairoSurface(width, height)); | |
68 | |
69 // TODO Big endian? | |
70 static const uint32_t rmask = 0x00ff0000; | |
71 static const uint32_t gmask = 0x0000ff00; | |
72 static const uint32_t bmask = 0x000000ff; | |
73 | |
74 if (sdlSurface_) | |
75 { | |
76 SDL_FreeSurface(sdlSurface_); | |
77 } | |
78 | |
79 sdlSurface_ = SDL_CreateRGBSurfaceFrom(onscreenSurface_->GetBuffer(), width, height, 32, | |
80 onscreenSurface_->GetPitch(), rmask, gmask, bmask, 0); | |
81 if (!sdlSurface_) | |
82 { | |
83 LOG(ERROR) << "Cannot create a SDL surface from a Cairo surface"; | |
84 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
85 } | |
86 } | |
87 | |
88 pendingFrame_ = false; | |
89 } | |
90 | |
91 | |
92 bool SdlBuffering::RenderOffscreen(IViewport& viewport) | |
93 { | |
94 boost::mutex::scoped_lock lock(mutex_); | |
95 | |
96 if (offscreenSurface_.get() == NULL) | |
97 { | |
98 return false; | |
99 } | |
100 | |
101 Orthanc::ImageAccessor target = offscreenSurface_->GetAccessor(); | |
102 | |
103 if (viewport.Render(target) && | |
104 !pendingFrame_) | |
105 { | |
106 pendingFrame_ = true; | |
107 return true; | |
108 } | |
109 else | |
110 { | |
111 return false; | |
112 } | |
113 } | |
114 | |
115 | |
116 void SdlBuffering::SwapToScreen(SdlWindow& window) | |
117 { | |
118 if (!pendingFrame_ || | |
119 offscreenSurface_.get() == NULL || | |
120 onscreenSurface_.get() == NULL) | |
121 { | |
122 return; | |
123 } | |
124 | |
125 { | |
126 boost::mutex::scoped_lock lock(mutex_); | |
127 onscreenSurface_->Copy(*offscreenSurface_); | |
128 } | |
129 | |
130 window.Render(sdlSurface_); | |
131 pendingFrame_ = false; | |
132 } | |
133 } | |
134 | |
135 #endif |