comparison Applications/Sdl/SdlSurface.cpp~ @ 102:fcec0ab44054 wasm

display volumes
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 31 May 2017 17:01:18 +0200
parents 6546dbcc0a7d
children 2eca030792aa
comparison
equal deleted inserted replaced
101:af312ce4fe59 102:fcec0ab44054
17 * You should have received a copy of the GNU Affero General Public License 17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/ 19 **/
20 20
21 21
22 #include "SdlBuffering.h" 22 #include "SdlSurface.h"
23 23
24 #if ORTHANC_ENABLE_SDL == 1 24 #if ORTHANC_ENABLE_SDL == 1
25 25
26 #include "../../../Resources/Orthanc/Core/Logging.h" 26 #include "../../../Resources/Orthanc/Core/Logging.h"
27 #include "../../../Resources/Orthanc/Core/OrthancException.h" 27 #include "../../../Resources/Orthanc/Core/OrthancException.h"
28 28
29 namespace OrthancStone 29 namespace OrthancStone
30 { 30 {
31 SdlBuffering::SdlBuffering() : 31 SdlSurface::SdlSurface(SdlWindow& window) :
32 sdlSurface_(NULL), 32 window_(window),
33 pendingFrame_(false) 33 sdlSurface_(NULL)
34 { 34 {
35 } 35 }
36 36
37 37
38 SdlBuffering::~SdlBuffering() 38 SdlSurface::~SdlSurface()
39 { 39 {
40 if (sdlSurface_) 40 if (sdlSurface_)
41 { 41 {
42 SDL_FreeSurface(sdlSurface_); 42 SDL_FreeSurface(sdlSurface_);
43 } 43 }
44 } 44 }
45 45
46 46
47 void SdlBuffering::SetSize(unsigned int width, 47 void SdlSurface::SetSize(unsigned int width,
48 unsigned int height, 48 unsigned int height)
49 IViewport& viewport)
50 { 49 {
51 boost::mutex::scoped_lock lock(mutex_); 50 if (cairoSurface_.get() == NULL ||
52 51 cairoSurface_->GetWidth() != width ||
53 viewport.SetSize(width, height); 52 cairoSurface_->GetHeight() != height)
54
55 if (offscreenSurface_.get() == NULL ||
56 offscreenSurface_->GetWidth() != width ||
57 offscreenSurface_->GetHeight() != height)
58 { 53 {
59 offscreenSurface_.reset(new CairoSurface(width, height)); 54 cairoSurface_.reset(new CairoSurface(width, height));
60 }
61
62 if (onscreenSurface_.get() == NULL ||
63 onscreenSurface_->GetWidth() != width ||
64 onscreenSurface_->GetHeight() != height)
65 {
66 onscreenSurface_.reset(new CairoSurface(width, height));
67 55
68 // TODO Big endian? 56 // TODO Big endian?
69 static const uint32_t rmask = 0x00ff0000; 57 static const uint32_t rmask = 0x00ff0000;
70 static const uint32_t gmask = 0x0000ff00; 58 static const uint32_t gmask = 0x0000ff00;
71 static const uint32_t bmask = 0x000000ff; 59 static const uint32_t bmask = 0x000000ff;
73 if (sdlSurface_) 61 if (sdlSurface_)
74 { 62 {
75 SDL_FreeSurface(sdlSurface_); 63 SDL_FreeSurface(sdlSurface_);
76 } 64 }
77 65
78 sdlSurface_ = SDL_CreateRGBSurfaceFrom(onscreenSurface_->GetBuffer(), width, height, 32, 66 sdlSurface_ = SDL_CreateRGBSurfaceFrom(cairoSurface_->GetBuffer(), width, height, 32,
79 onscreenSurface_->GetPitch(), rmask, gmask, bmask, 0); 67 cairoSurface_->GetPitch(), rmask, gmask, bmask, 0);
80 if (!sdlSurface_) 68 if (!sdlSurface_)
81 { 69 {
82 LOG(ERROR) << "Cannot create a SDL surface from a Cairo surface"; 70 LOG(ERROR) << "Cannot create a SDL surface from a Cairo surface";
83 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); 71 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
84 } 72 }
85 }
86
87 pendingFrame_ = false;
88 }
89
90
91 bool SdlBuffering::RenderOffscreen(IViewport& viewport)
92 {
93 boost::mutex::scoped_lock lock(mutex_);
94
95 if (offscreenSurface_.get() == NULL)
96 {
97 return false;
98 }
99
100 Orthanc::ImageAccessor target = offscreenSurface_->GetAccessor();
101
102 if (viewport.Render(target) &&
103 !pendingFrame_)
104 {
105 pendingFrame_ = true;
106 return true;
107 }
108 else
109 {
110 return false;
111 } 73 }
112 } 74 }
113 75
114 76
115 void SdlBuffering::SwapToScreen(SdlWindow& window) 77 void SdlSurface::Render(IViewport& viewport)
116 { 78 {
117 if (!pendingFrame_ || 79 if (cairoSurface_.get() == NULL)
118 offscreenSurface_.get() == NULL ||
119 onscreenSurface_.get() == NULL)
120 { 80 {
121 return; 81 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
122 } 82 }
123 83
84 Orthanc::ImageAccessor target = cairoSurface_->GetAccessor();
85
86 if (viewport.Render(target))
124 { 87 {
125 boost::mutex::scoped_lock lock(mutex_); 88 window_.Render(sdlSurface_);
126 onscreenSurface_->Copy(*offscreenSurface_);
127 } 89 }
128
129 window.Render(sdlSurface_);
130 pendingFrame_ = false;
131 } 90 }
132 } 91 }
133 92
134 #endif 93 #endif