comparison Framework/Viewport/SdlViewport.h @ 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
43 43
44 namespace OrthancStone 44 namespace OrthancStone
45 { 45 {
46 class SdlViewport : public ViewportBase 46 class SdlViewport : public ViewportBase
47 { 47 {
48 protected:
49 boost::mutex mutex_;
50
48 public: 51 public:
49 SdlViewport() 52 SdlViewport()
50 { 53 {
51 } 54 }
52 55
53 SdlViewport(boost::shared_ptr<Scene2D>& scene) :
54 ViewportBase(scene)
55 {
56 }
57
58 virtual SdlWindow& GetWindow() = 0;
59
60 virtual void UpdateSize(unsigned int width, 56 virtual void UpdateSize(unsigned int width,
61 unsigned int height) = 0; 57 unsigned int height) = 0;
62 }; 58 };
63 59
64 60
65 class SdlOpenGLViewport : public SdlViewport 61 class SdlOpenGLViewport : public SdlViewport
66 { 62 {
67 private: 63 private:
68 SdlOpenGLContext context_; 64 SdlOpenGLContext context_;
69 std::auto_ptr<OpenGLCompositor> compositor_; 65 std::auto_ptr<OpenGLCompositor> compositor_;
70 66
67 class SdlLock : public LockBase
68 {
69 private:
70 SdlOpenGLViewport& that_;
71 boost::mutex::scoped_lock lock_;
72
73 public:
74 SdlLock(SdlOpenGLViewport& viewport) :
75 LockBase(viewport),
76 that_(viewport),
77 lock_(viewport.mutex_)
78 {
79 }
80
81 virtual bool HasCompositor() const ORTHANC_OVERRIDE
82 {
83 return true;
84 }
85
86 virtual ICompositor& GetCompositor() ORTHANC_OVERRIDE
87 {
88 return *that_.compositor_;
89 }
90 };
91
71 public: 92 public:
72 SdlOpenGLViewport(const char* title, 93 SdlOpenGLViewport(const char* title,
73 unsigned int width, 94 unsigned int width,
74 unsigned int height, 95 unsigned int height,
75 bool allowDpiScaling = true); 96 bool allowDpiScaling = true);
76 97
77 SdlOpenGLViewport(const char* title, 98 virtual void Refresh() ORTHANC_OVERRIDE;
78 unsigned int width,
79 unsigned int height,
80 boost::shared_ptr<Scene2D>& scene,
81 bool allowDpiScaling = true);
82 99
83 virtual SdlWindow& GetWindow() ORTHANC_OVERRIDE 100 virtual ILock* Lock() ORTHANC_OVERRIDE
84 { 101 {
85 return context_.GetWindow(); 102 return new SdlLock(*this);
86 } 103 }
87
88 virtual void Refresh() ORTHANC_OVERRIDE;
89 104
90 virtual void UpdateSize(unsigned int width, unsigned int height) ORTHANC_OVERRIDE 105 virtual void UpdateSize(unsigned int width, unsigned int height) ORTHANC_OVERRIDE
91 { 106 {
92 // nothing to do in OpenGL, the OpenGLCompositor::UpdateSize will be called automatically 107 // nothing to do in OpenGL, the OpenGLCompositor::UpdateSize will be called automatically
93 }
94
95 virtual bool HasCompositor() const ORTHANC_OVERRIDE
96 {
97 return true;
98 }
99
100 virtual ICompositor& GetCompositor() ORTHANC_OVERRIDE
101 {
102 return *compositor_.get();
103 } 108 }
104 }; 109 };
105 110
106 111
107 class SdlCairoViewport : public SdlViewport 112 class SdlCairoViewport : public SdlViewport
108 { 113 {
109 private: 114 private:
115 class SdlLock : public LockBase
116 {
117 private:
118 SdlCairoViewport& that_;
119 boost::mutex::scoped_lock lock_;
120
121 public:
122 SdlLock(SdlCairoViewport& viewport) :
123 LockBase(viewport),
124 that_(viewport),
125 lock_(viewport.mutex_)
126 {
127 }
128
129 virtual bool HasCompositor() const ORTHANC_OVERRIDE
130 {
131 return true;
132 }
133
134 virtual ICompositor& GetCompositor() ORTHANC_OVERRIDE
135 {
136 return that_.compositor_;
137 }
138 };
139
110 SdlWindow window_; 140 SdlWindow window_;
111 CairoCompositor compositor_; 141 CairoCompositor compositor_;
112 SDL_Surface* sdlSurface_; 142 SDL_Surface* sdlSurface_;
113 143
114 private: 144 void RefreshInternal();
145
115 void UpdateSdlSurfaceSize(unsigned int width, 146 void UpdateSdlSurfaceSize(unsigned int width,
116 unsigned int height); 147 unsigned int height);
117 148
118 public: 149 public:
119 SdlCairoViewport(const char* title, 150 SdlCairoViewport(const char* title,
120 unsigned int width, 151 unsigned int width,
121 unsigned int height, 152 unsigned int height,
122 bool allowDpiScaling = true); 153 bool allowDpiScaling = true);
123 154
124 SdlCairoViewport(const char* title,
125 unsigned int width,
126 unsigned int height,
127 boost::shared_ptr<Scene2D>& scene,
128 bool allowDpiScaling = true);
129
130 ~SdlCairoViewport(); 155 ~SdlCairoViewport();
131 156
132 virtual SdlWindow& GetWindow() ORTHANC_OVERRIDE
133 {
134 return window_;
135 }
136
137 virtual void Refresh() ORTHANC_OVERRIDE; 157 virtual void Refresh() ORTHANC_OVERRIDE;
138 158
139 virtual void UpdateSize(unsigned int width, 159 virtual void UpdateSize(unsigned int width,
140 unsigned int height) ORTHANC_OVERRIDE; 160 unsigned int height) ORTHANC_OVERRIDE;
141
142 virtual bool HasCompositor() const ORTHANC_OVERRIDE
143 {
144 return true;
145 }
146
147 virtual ICompositor& GetCompositor() ORTHANC_OVERRIDE
148 {
149 return compositor_;
150 }
151 }; 161 };
152 } 162 }