Mercurial > hg > orthanc-stone
comparison Framework/Viewport/SdlViewport.cpp @ 947:1091b2adeb5a toa2019081001
Fixed animation frame stopping when returning false + big work on the OpenGL
objects to make them lost context-safe + debug code to forcefully tag a
context as lost + debug macros
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Sat, 10 Aug 2019 13:07:31 +0200 |
parents | 7a7e4e1f558f |
children | a7351ad54960 |
comparison
equal
deleted
inserted
replaced
946:dbe3e1e47019 | 947:1091b2adeb5a |
---|---|
29 SdlOpenGLViewport::SdlOpenGLViewport(const char* title, | 29 SdlOpenGLViewport::SdlOpenGLViewport(const char* title, |
30 unsigned int width, | 30 unsigned int width, |
31 unsigned int height, | 31 unsigned int height, |
32 bool allowDpiScaling) : | 32 bool allowDpiScaling) : |
33 SdlViewport(title), | 33 SdlViewport(title), |
34 context_(title, width, height, allowDpiScaling), | 34 context_(title, width, height, allowDpiScaling) |
35 compositor_(context_, GetScene()) | |
36 { | 35 { |
36 compositor_.reset(new OpenGLCompositor(context_, GetScene())); | |
37 } | 37 } |
38 | 38 |
39 SdlOpenGLViewport::SdlOpenGLViewport(const char* title, | 39 SdlOpenGLViewport::SdlOpenGLViewport(const char* title, |
40 unsigned int width, | 40 unsigned int width, |
41 unsigned int height, | 41 unsigned int height, |
42 boost::shared_ptr<Scene2D>& scene, | 42 boost::shared_ptr<Scene2D>& scene, |
43 bool allowDpiScaling) : | 43 bool allowDpiScaling) : |
44 SdlViewport(title, scene), | 44 SdlViewport(title, scene), |
45 context_(title, width, height, allowDpiScaling), | 45 context_(title, width, height, allowDpiScaling) |
46 compositor_(context_, GetScene()) | |
47 { | 46 { |
47 compositor_.reset(new OpenGLCompositor(context_, GetScene())); | |
48 } | 48 } |
49 | |
50 bool SdlOpenGLViewport::OpenGLContextLost() | |
51 { | |
52 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
53 } | |
54 | |
55 void SdlOpenGLViewport::DisableCompositor() | |
56 { | |
57 compositor_.reset(NULL); | |
58 } | |
59 | |
60 void SdlOpenGLViewport::RestoreCompositor() | |
61 { | |
62 // the context must have been restored! | |
63 ORTHANC_ASSERT(!context_.IsContextLost()); | |
64 | |
65 if (compositor_.get() == NULL) | |
66 { | |
67 compositor_.reset(new OpenGLCompositor(context_, GetScene())); | |
68 } | |
69 else | |
70 { | |
71 std::string windowTitle(SDL_GetWindowTitle(GetWindow().GetObject())); | |
72 LOG(WARNING) << "RestoreCompositor() called for \"" << windowTitle << "\" while it was NOT lost! Nothing done."; | |
73 } | |
74 } | |
75 | |
76 // extern bool Debug_MustContextBeRestored(std::string title); | |
77 // extern void Debug_Context_ClearRestoreFlag(std::string title); | |
78 // extern void Debug_Context_ClearKillFlag(std::string title); | |
79 | |
80 bool Debug_SdlOpenGLViewport_Refresh_BP = false; | |
81 | |
82 void SdlOpenGLViewport::Refresh() | |
83 { | |
84 // <DEBUG CODE USED FOR CONTEXT LOSS RESTORING> | |
85 // try to restore the context if requested | |
86 // Debug_Context_ClearRestoreFlag | |
87 // Debug_SdlOpenGLViewport_Refresh_BP = true; | |
88 // try | |
89 // { | |
90 // if (Debug_MustContextBeRestored(GetCanvasIdentifier())) | |
91 // { | |
92 // // to prevent a bug where the context is both labelled as "to be lost" and "to be restored" | |
93 // // (occurs when one is hammering away at the keyboard like there's no tomorrow) | |
94 // Debug_Context_ClearKillFlag(GetCanvasIdentifier()); | |
95 // // this is called manually for loss/restore simulation | |
96 // context_.RestoreLostContext(); | |
97 // RestoreCompositor(); | |
98 // Debug_Context_ClearRestoreFlag(GetCanvasIdentifier()); | |
99 // } | |
100 // } | |
101 // catch (const OpenGLContextLostException& e) | |
102 // { | |
103 // LOG(ERROR) << "OpenGLContextLostException in SdlOpenGLViewport::Refresh() part 1"; | |
104 // } | |
105 // Debug_SdlOpenGLViewport_Refresh_BP = false; | |
106 // </DEBUG CODE USED FOR CONTEXT LOSS RESTORING> | |
107 | |
108 try | |
109 { | |
110 // the compositor COULD be dead! | |
111 if (GetCompositor()) | |
112 GetCompositor()->Refresh(); | |
113 } | |
114 catch (const OpenGLContextLostException& e) | |
115 { | |
116 // we need to wait for the "context restored" callback | |
117 LOG(WARNING) << "Context " << std::hex << e.context_ << " is lost! Compositor will be disabled."; | |
118 DisableCompositor(); | |
119 | |
120 // <DEBUG CODE USED FOR CONTEXT LOSS RESTORING> | |
121 // in case this was externally triggered... | |
122 //Debug_Context_ClearKillFlag(GetCanvasIdentifier()); | |
123 // </DEBUG CODE USED FOR CONTEXT LOSS RESTORING> | |
124 } | |
125 catch (...) | |
126 { | |
127 // something else nasty happened | |
128 throw; | |
129 } | |
130 } | |
131 | |
132 | |
133 | |
49 | 134 |
50 | 135 |
51 SdlCairoViewport::SdlCairoViewport(const char* title, | 136 SdlCairoViewport::SdlCairoViewport(const char* title, |
52 unsigned int width, | 137 unsigned int width, |
53 unsigned int height, | 138 unsigned int height, |
57 compositor_(GetScene(), width, height) | 142 compositor_(GetScene(), width, height) |
58 { | 143 { |
59 UpdateSdlSurfaceSize(width, height); | 144 UpdateSdlSurfaceSize(width, height); |
60 } | 145 } |
61 | 146 |
147 void SdlCairoViewport::DisableCompositor() | |
148 { | |
149 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
150 } | |
151 | |
152 void SdlCairoViewport::RestoreCompositor() | |
153 { | |
154 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
155 } | |
62 | 156 |
63 SdlCairoViewport::~SdlCairoViewport() | 157 SdlCairoViewport::~SdlCairoViewport() |
64 { | 158 { |
65 if (sdlSurface_) | 159 if (sdlSurface_) |
66 { | 160 { |
67 SDL_FreeSurface(sdlSurface_); | 161 SDL_FreeSurface(sdlSurface_); |
68 } | 162 } |
69 } | 163 } |
70 | 164 |
71 | |
72 void SdlCairoViewport::Refresh() | 165 void SdlCairoViewport::Refresh() |
73 { | 166 { |
74 GetCompositor().Refresh(); | 167 GetCompositor()->Refresh(); |
75 window_.Render(sdlSurface_); | 168 window_.Render(sdlSurface_); |
76 } | 169 } |
77 | 170 |
78 void SdlCairoViewport::UpdateSize(unsigned int width, | 171 void SdlCairoViewport::UpdateSize(unsigned int width, |
79 unsigned int height) | 172 unsigned int height) |
80 { | 173 { |
81 compositor_.UpdateSize(width, height); | 174 compositor_.UpdateSize(width, height); |
82 UpdateSdlSurfaceSize(width, height); | 175 UpdateSdlSurfaceSize(width, height); |
83 Refresh(); | 176 Refresh(); |
84 } | 177 } |
85 | 178 |
86 | |
87 void SdlCairoViewport::UpdateSdlSurfaceSize(unsigned int width, | 179 void SdlCairoViewport::UpdateSdlSurfaceSize(unsigned int width, |
88 unsigned int height) | 180 unsigned int height) |
89 { | 181 { |
90 static const uint32_t rmask = 0x00ff0000; | 182 static const uint32_t rmask = 0x00ff0000; |
91 static const uint32_t gmask = 0x0000ff00; | 183 static const uint32_t gmask = 0x0000ff00; |