Mercurial > hg > orthanc-stone
comparison Framework/Viewport/WebGLViewportsRegistry.cpp @ 1242:b9b5d4378874 broker
working of WebAssemblyOracle
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 06 Jan 2020 18:08:05 +0100 |
parents | e71ee3e88448 |
children | 0ca50d275b9a |
comparison
equal
deleted
inserted
replaced
1241:a4bb8c2dd211 | 1242:b9b5d4378874 |
---|---|
20 | 20 |
21 | 21 |
22 #include "WebGLViewportsRegistry.h" | 22 #include "WebGLViewportsRegistry.h" |
23 | 23 |
24 #include <Core/OrthancException.h> | 24 #include <Core/OrthancException.h> |
25 | |
26 #include <boost/make_shared.hpp> | |
25 | 27 |
26 namespace OrthancStone | 28 namespace OrthancStone |
27 { | 29 { |
28 void WebGLViewportsRegistry::LaunchTimer() | 30 void WebGLViewportsRegistry::LaunchTimer() |
29 { | 31 { |
56 ); | 58 ); |
57 | 59 |
58 // At this point, the old canvas is removed from the DOM and | 60 // At this point, the old canvas is removed from the DOM and |
59 // replaced by a fresh one with the same ID: Recreate the | 61 // replaced by a fresh one with the same ID: Recreate the |
60 // WebGL context on the new canvas | 62 // WebGL context on the new canvas |
61 std::auto_ptr<WebGLViewport> viewport; | 63 boost::shared_ptr<WebGLViewport> viewport; |
62 | 64 |
63 { | 65 { |
64 std::auto_ptr<IViewport::ILock> lock(it->second->Lock()); | 66 std::auto_ptr<IViewport::ILock> lock(it->second->Lock()); |
65 viewport.reset(new WebGLViewport(it->first, lock->GetController().GetScene())); | 67 viewport = boost::make_shared<WebGLViewport>(it->first, lock->GetController().GetScene()); |
66 } | 68 } |
67 | 69 |
68 // Replace the old WebGL viewport by the new one | 70 // Replace the old WebGL viewport by the new one |
69 delete it->second; | 71 it->second = viewport; |
70 it->second = viewport.release(); | |
71 | 72 |
72 // Tag the fresh canvas as needing a repaint | 73 // Tag the fresh canvas as needing a repaint |
73 { | 74 { |
74 std::auto_ptr<IViewport::ILock> lock(it->second->Lock()); | 75 std::auto_ptr<IViewport::ILock> lock(it->second->Lock()); |
75 lock->Invalidate(); | 76 lock->Invalidate(); |
98 | 99 |
99 LaunchTimer(); | 100 LaunchTimer(); |
100 } | 101 } |
101 | 102 |
102 | 103 |
103 void WebGLViewportsRegistry::Add(const std::string& canvasId) | 104 boost::shared_ptr<WebGLViewport> WebGLViewportsRegistry::Add(const std::string& canvasId) |
104 { | 105 { |
105 if (viewports_.find(canvasId) != viewports_.end()) | 106 if (viewports_.find(canvasId) != viewports_.end()) |
106 { | 107 { |
107 LOG(ERROR) << "Canvas was already registered: " << canvasId; | 108 LOG(ERROR) << "Canvas was already registered: " << canvasId; |
108 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | 109 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
109 } | 110 } |
110 else | 111 else |
111 { | 112 { |
112 viewports_[canvasId] = new WebGLViewport(canvasId); | 113 boost::shared_ptr<WebGLViewport> viewport(new WebGLViewport(canvasId)); |
114 viewports_[canvasId] = viewport; | |
115 return viewport; | |
113 } | 116 } |
114 } | 117 } |
115 | 118 |
116 | 119 |
117 void WebGLViewportsRegistry::Remove(const std::string& canvasId) | 120 void WebGLViewportsRegistry::Remove(const std::string& canvasId) |
122 { | 125 { |
123 LOG(ERROR) << "Cannot remove unregistered canvas: " << canvasId; | 126 LOG(ERROR) << "Cannot remove unregistered canvas: " << canvasId; |
124 } | 127 } |
125 else | 128 else |
126 { | 129 { |
127 if (found->second != NULL) | |
128 { | |
129 delete found->second; | |
130 } | |
131 | |
132 viewports_.erase(found); | 130 viewports_.erase(found); |
133 } | 131 } |
134 } | 132 } |
135 | 133 |
136 | 134 |
137 void WebGLViewportsRegistry::Clear() | 135 void WebGLViewportsRegistry::Clear() |
138 { | 136 { |
139 for (Viewports::iterator it = viewports_.begin(); it != viewports_.end(); ++it) | |
140 { | |
141 if (it->second != NULL) | |
142 { | |
143 delete it->second; | |
144 } | |
145 } | |
146 | |
147 viewports_.clear(); | 137 viewports_.clear(); |
148 } | 138 } |
149 | 139 |
150 | 140 |
151 WebGLViewportsRegistry::Accessor::Accessor(WebGLViewportsRegistry& that, | 141 WebGLViewportsRegistry::Accessor::Accessor(WebGLViewportsRegistry& that, |