Index: webkit/tools/pepper_test_plugin/plugin_object.cc |
=================================================================== |
--- webkit/tools/pepper_test_plugin/plugin_object.cc (revision 37846) |
+++ webkit/tools/pepper_test_plugin/plugin_object.cc (working copy) |
@@ -308,6 +308,11 @@ |
} |
PluginObject::~PluginObject() { |
+#if !defined(INDEPENDENT_PLUGIN) |
+ if (pgl_context_) |
+ Destroy3D(); |
+#endif |
+ |
deviceaudio_->destroyContext(npp_, &context_audio_); |
// FIXME(brettw) destroy the context. |
browser->releaseobject(test_object_); |
@@ -352,10 +357,10 @@ |
} |
void PluginObject::SetWindow(const NPWindow& window) { |
+ width_ = window.width; |
+ height_ = window.height; |
+ |
if (dimensions_ == 2) { |
- width_ = window.width; |
- height_ = window.height; |
- |
NPDeviceContext2DConfig config; |
NPDeviceContext2D context; |
device2d_->initializeContext(npp_, &config, &context); |
@@ -369,21 +374,9 @@ |
device2d_->flushContext(npp_, &context, callback, NULL); |
} else { |
#if !defined(INDEPENDENT_PLUGIN) |
- if (!pgl_context_) { |
- // Initialize a 3D context. |
- NPDeviceContext3DConfig config; |
- config.commandBufferSize = kCommandBufferSize; |
- device3d_->initializeContext(npp_, &config, &context3d_); |
+ if (!pgl_context_) |
+ Initialize3D(); |
- // Create a PGL context. |
- pgl_context_ = pglCreateContext(npp_, device3d_, &context3d_); |
- } |
- |
- // Reset the viewport to new window size. |
- pglMakeCurrent(pgl_context_); |
- glViewport(0, 0, window.width, window.height); |
- pglMakeCurrent(NULL); |
- |
// Schedule the first call to Draw. |
browser->pluginthreadasynccall(npp_, Draw3DCallback, this); |
#endif |
@@ -403,15 +396,52 @@ |
} |
} |
+void PluginObject::Initialize3D() { |
+#if !defined(INDEPENDENT_PLUGIN) |
+ DCHECK(!pgl_context_); |
+ |
+ // Initialize a 3D context. |
+ NPDeviceContext3DConfig config; |
+ config.commandBufferSize = kCommandBufferSize; |
+ device3d_->initializeContext(npp_, &config, &context3d_); |
+ |
+ // Create a PGL context. |
+ pgl_context_ = pglCreateContext(npp_, device3d_, &context3d_); |
+ |
+ // Initialize the demo GL state. |
+ pglMakeCurrent(pgl_context_); |
+ GLFromCPPInit(); |
+ pglMakeCurrent(NULL); |
+#endif // INDEPENDENT_PLUGIN |
+} |
+ |
+void PluginObject::Destroy3D() { |
+#if !defined(INDEPENDENT_PLUGIN) |
+ DCHECK(pgl_context_); |
+ |
+ // Destroy the PGL context. |
+ pglDestroyContext(pgl_context_); |
+ pgl_context_ = NULL; |
+ |
+ // Destroy the Device3D context. |
+ device3d_->destroyContext(npp_, &context3d_); |
+#endif // INDEPENDENT_PLUGIN |
+} |
+ |
void PluginObject::Draw3D() { |
#if !defined(INDEPENDENT_PLUGIN) |
- // Render some stuff. |
- pglMakeCurrent(pgl_context_); |
- GLFromCPPTestFunction(); |
+ if (!pglMakeCurrent(pgl_context_) && pglGetError() == PGL_CONTEXT_LOST) { |
+ Destroy3D(); |
+ Initialize3D(); |
+ pglMakeCurrent(pgl_context_); |
+ } |
+ |
+ glViewport(0, 0, width_, height_); |
+ GLFromCPPDraw(); |
pglSwapBuffers(); |
pglMakeCurrent(NULL); |
// Schedule another call to Draw. |
browser->pluginthreadasynccall(npp_, Draw3DCallback, this); |
-#endif |
+#endif // INDEPENDENT_PLUGIN |
} |