Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Unified Diff: gpu/demos/framework/plugin.cc

Issue 566021: [GPU] GLES2 lost context recovery (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gpu/demos/framework/plugin.h ('k') | gpu/pgl/pgl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/demos/framework/plugin.cc
===================================================================
--- gpu/demos/framework/plugin.cc (revision 37846)
+++ gpu/demos/framework/plugin.cc (working copy)
@@ -7,12 +7,13 @@
#include "base/logging.h"
#include "gpu/demos/framework/demo_factory.h"
+using gpu::demos::Plugin;
+
namespace {
const int32 kCommandBufferSize = 1024 * 1024;
NPExtensions* g_extensions = NULL;
// Plugin class functions.
-using gpu::demos::Plugin;
NPObject* PluginAllocate(NPP npp, NPClass* the_class) {
Plugin* plugin = new Plugin(npp);
return plugin;
@@ -97,7 +98,7 @@
demo_.reset();
pglMakeCurrent(NULL);
- pglDestroyContext(pgl_context_);
+ DestroyContext();
}
NPClass* Plugin::GetPluginClass() {
@@ -116,20 +117,10 @@
}
void Plugin::SetWindow(const NPWindow& window) {
+ demo_->InitWindowSize(window.width, window.height);
+
if (!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 demo.
- pglMakeCurrent(pgl_context_);
- demo_->InitWindowSize(window.width, window.height);
- CHECK(demo_->InitGL());
- pglMakeCurrent(NULL);
+ CreateContext();
}
// Schedule the first call to Draw.
@@ -137,8 +128,12 @@
}
void Plugin::Paint() {
- // Render some stuff.
- pglMakeCurrent(pgl_context_);
+ if (!pglMakeCurrent(pgl_context_) && pglGetError() == PGL_CONTEXT_LOST) {
+ DestroyContext();
+ CreateContext();
+ pglMakeCurrent(pgl_context_);
+ }
+
demo_->Draw();
pglSwapBuffers();
pglMakeCurrent(NULL);
@@ -147,5 +142,31 @@
g_browser->pluginthreadasynccall(npp_, PaintCallback, this);
}
+void Plugin::CreateContext() {
+ 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 demo.
+ pglMakeCurrent(pgl_context_);
+ CHECK(demo_->InitGL());
+ pglMakeCurrent(NULL);
+}
+
+void Plugin::DestroyContext() {
+ DCHECK(pgl_context_);
+
+ pglDestroyContext(pgl_context_);
+ pgl_context_ = NULL;
+
+ device3d_->destroyContext(npp_, &context3d_);
+}
+
} // namespace demos
} // namespace gpu
« no previous file with comments | « gpu/demos/framework/plugin.h ('k') | gpu/pgl/pgl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698