Mercurial > hg > orthanc-stone
comparison Framework/Viewport/SdlViewport.cpp @ 1203:f3bb9a6dd949 broker
locking abstraction in IViewport
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 29 Nov 2019 21:22:21 +0100 |
parents | af456106576c |
children | 6009c59d8676 |
comparison
equal
deleted
inserted
replaced
1200:54cbffabdc45 | 1203:f3bb9a6dd949 |
---|---|
20 | 20 |
21 #include "SdlViewport.h" | 21 #include "SdlViewport.h" |
22 | 22 |
23 #include <Core/OrthancException.h> | 23 #include <Core/OrthancException.h> |
24 | 24 |
25 #include <boost/make_shared.hpp> | |
26 | |
27 namespace OrthancStone | 25 namespace OrthancStone |
28 { | 26 { |
29 SdlOpenGLViewport::SdlOpenGLViewport(const char* title, | 27 SdlOpenGLViewport::SdlOpenGLViewport(const char* title, |
30 unsigned int width, | 28 unsigned int width, |
31 unsigned int height, | 29 unsigned int height, |
33 context_(title, width, height, allowDpiScaling) | 31 context_(title, width, height, allowDpiScaling) |
34 { | 32 { |
35 compositor_.reset(new OpenGLCompositor(context_, GetScene())); | 33 compositor_.reset(new OpenGLCompositor(context_, GetScene())); |
36 } | 34 } |
37 | 35 |
38 SdlOpenGLViewport::SdlOpenGLViewport(const char* title, | |
39 unsigned int width, | |
40 unsigned int height, | |
41 boost::shared_ptr<Scene2D>& scene, | |
42 bool allowDpiScaling) : | |
43 SdlViewport(scene), | |
44 context_(title, width, height, allowDpiScaling) | |
45 { | |
46 compositor_.reset(new OpenGLCompositor(context_, GetScene())); | |
47 } | |
48 | |
49 void SdlOpenGLViewport::Refresh() | 36 void SdlOpenGLViewport::Refresh() |
50 { | 37 { |
38 boost::mutex::scoped_lock lock(mutex_); | |
51 compositor_->Refresh(); | 39 compositor_->Refresh(); |
52 } | 40 } |
53 | 41 |
54 | 42 |
55 SdlCairoViewport::SdlCairoViewport(const char* title, | 43 SdlCairoViewport::SdlCairoViewport(const char* title, |
68 { | 56 { |
69 SDL_FreeSurface(sdlSurface_); | 57 SDL_FreeSurface(sdlSurface_); |
70 } | 58 } |
71 } | 59 } |
72 | 60 |
73 void SdlCairoViewport::Refresh() | 61 void SdlCairoViewport::RefreshInternal() // Assumes that the mutex is locked |
74 { | 62 { |
75 compositor_.Refresh(); | 63 compositor_.Refresh(); |
76 window_.Render(sdlSurface_); | 64 window_.Render(sdlSurface_); |
77 } | 65 } |
78 | 66 |
67 void SdlCairoViewport::Refresh() | |
68 { | |
69 boost::mutex::scoped_lock lock(mutex_); | |
70 RefreshInternal(); | |
71 } | |
72 | |
79 void SdlCairoViewport::UpdateSize(unsigned int width, | 73 void SdlCairoViewport::UpdateSize(unsigned int width, |
80 unsigned int height) | 74 unsigned int height) |
81 { | 75 { |
76 boost::mutex::scoped_lock lock(mutex_); | |
82 compositor_.UpdateSize(width, height); | 77 compositor_.UpdateSize(width, height); |
83 UpdateSdlSurfaceSize(width, height); | 78 UpdateSdlSurfaceSize(width, height); |
84 Refresh(); | 79 RefreshInternal(); |
85 } | 80 } |
86 | 81 |
87 void SdlCairoViewport::UpdateSdlSurfaceSize(unsigned int width, | 82 void SdlCairoViewport::UpdateSdlSurfaceSize(unsigned int width, |
88 unsigned int height) | 83 unsigned int height) // Assumes that the mutex is locked |
89 { | 84 { |
90 static const uint32_t rmask = 0x00ff0000; | 85 static const uint32_t rmask = 0x00ff0000; |
91 static const uint32_t gmask = 0x0000ff00; | 86 static const uint32_t gmask = 0x0000ff00; |
92 static const uint32_t bmask = 0x000000ff; | 87 static const uint32_t bmask = 0x000000ff; |
93 | 88 |