Mercurial > hg > orthanc-stone
comparison Framework/Viewport/SdlViewport.cpp @ 1045:6a9300ecfa13
tests for context loss are now restricted to WebAssembly
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 09 Oct 2019 17:17:56 +0200 |
parents | a7351ad54960 |
children | 32b403a47b19 |
comparison
equal
deleted
inserted
replaced
1044:b60d70e8b55c | 1045:6a9300ecfa13 |
---|---|
45 context_(title, width, height, allowDpiScaling) | 45 context_(title, width, height, allowDpiScaling) |
46 { | 46 { |
47 compositor_.reset(new OpenGLCompositor(context_, GetScene())); | 47 compositor_.reset(new OpenGLCompositor(context_, GetScene())); |
48 } | 48 } |
49 | 49 |
50 | 50 void SdlOpenGLViewport::Refresh() |
51 void* SdlOpenGLViewport::DebugGetInternalContext() const | |
52 { | 51 { |
53 return context_.DebugGetInternalContext(); | 52 if (GetCompositor()) |
54 } | |
55 | |
56 bool SdlOpenGLViewport::IsContextLost() { | |
57 return context_.IsContextLost(); | |
58 } | |
59 | |
60 bool SdlOpenGLViewport::OpenGLContextLost() | |
61 { | |
62 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
63 } | |
64 | |
65 bool SdlOpenGLViewport::OpenGLContextRestored() | |
66 { | |
67 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
68 } | |
69 | |
70 void SdlOpenGLViewport::DisableCompositor() | |
71 { | |
72 compositor_.reset(NULL); | |
73 } | |
74 | |
75 void SdlOpenGLViewport::RestoreCompositor() | |
76 { | |
77 // the context must have been restored! | |
78 ORTHANC_ASSERT(!context_.IsContextLost()); | |
79 | |
80 if (compositor_.get() == NULL) | |
81 { | 53 { |
82 compositor_.reset(new OpenGLCompositor(context_, GetScene())); | 54 GetCompositor()->Refresh(); |
83 } | |
84 else | |
85 { | |
86 std::string windowTitle(SDL_GetWindowTitle(GetWindow().GetObject())); | |
87 LOG(WARNING) << "RestoreCompositor() called for \"" << windowTitle << "\" while it was NOT lost! Nothing done."; | |
88 } | 55 } |
89 } | 56 } |
90 | |
91 // extern bool Debug_MustContextBeRestored(std::string title); | |
92 // extern void Debug_Context_ClearRestoreFlag(std::string title); | |
93 // extern void Debug_Context_ClearKillFlag(std::string title); | |
94 | |
95 bool Debug_SdlOpenGLViewport_Refresh_BP = false; | |
96 | |
97 void SdlOpenGLViewport::Refresh() | |
98 { | |
99 // <DEBUG CODE USED FOR CONTEXT LOSS RESTORING> | |
100 // try to restore the context if requested | |
101 // Debug_Context_ClearRestoreFlag | |
102 // Debug_SdlOpenGLViewport_Refresh_BP = true; | |
103 // try | |
104 // { | |
105 // if (Debug_MustContextBeRestored(GetCanvasIdentifier())) | |
106 // { | |
107 // // to prevent a bug where the context is both labelled as "to be lost" and "to be restored" | |
108 // // (occurs when one is hammering away at the keyboard like there's no tomorrow) | |
109 // Debug_Context_ClearKillFlag(GetCanvasIdentifier()); | |
110 // // this is called manually for loss/restore simulation | |
111 // context_.RestoreLostContext(); | |
112 // RestoreCompositor(); | |
113 // Debug_Context_ClearRestoreFlag(GetCanvasIdentifier()); | |
114 // } | |
115 // } | |
116 // catch (const OpenGLContextLostException& e) | |
117 // { | |
118 // LOG(ERROR) << "OpenGLContextLostException in SdlOpenGLViewport::Refresh() part 1"; | |
119 // } | |
120 // Debug_SdlOpenGLViewport_Refresh_BP = false; | |
121 // </DEBUG CODE USED FOR CONTEXT LOSS RESTORING> | |
122 | |
123 try | |
124 { | |
125 // the compositor COULD be dead! | |
126 if (GetCompositor()) | |
127 GetCompositor()->Refresh(); | |
128 } | |
129 catch (const OpenGLContextLostException& e) | |
130 { | |
131 // we need to wait for the "context restored" callback | |
132 LOG(WARNING) << "Context " << std::hex << e.context_ << " is lost! Compositor will be disabled."; | |
133 DisableCompositor(); | |
134 | |
135 // <DEBUG CODE USED FOR CONTEXT LOSS RESTORING> | |
136 // in case this was externally triggered... | |
137 //Debug_Context_ClearKillFlag(GetCanvasIdentifier()); | |
138 // </DEBUG CODE USED FOR CONTEXT LOSS RESTORING> | |
139 } | |
140 catch (...) | |
141 { | |
142 // something else nasty happened | |
143 throw; | |
144 } | |
145 } | |
146 | |
147 | |
148 | |
149 | 57 |
150 | 58 |
151 SdlCairoViewport::SdlCairoViewport(const char* title, | 59 SdlCairoViewport::SdlCairoViewport(const char* title, |
152 unsigned int width, | 60 unsigned int width, |
153 unsigned int height, | 61 unsigned int height, |
155 SdlViewport(title), | 63 SdlViewport(title), |
156 window_(title, width, height, false /* enable OpenGL */, allowDpiScaling), | 64 window_(title, width, height, false /* enable OpenGL */, allowDpiScaling), |
157 compositor_(GetScene(), width, height) | 65 compositor_(GetScene(), width, height) |
158 { | 66 { |
159 UpdateSdlSurfaceSize(width, height); | 67 UpdateSdlSurfaceSize(width, height); |
160 } | |
161 | |
162 void SdlCairoViewport::DisableCompositor() | |
163 { | |
164 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
165 } | |
166 | |
167 void SdlCairoViewport::RestoreCompositor() | |
168 { | |
169 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
170 } | 68 } |
171 | 69 |
172 SdlCairoViewport::~SdlCairoViewport() | 70 SdlCairoViewport::~SdlCairoViewport() |
173 { | 71 { |
174 if (sdlSurface_) | 72 if (sdlSurface_) |