diff options
author | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-03 23:27:43 +0000 |
---|---|---|
committer | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-03 23:27:43 +0000 |
commit | 9a298ada39103abf74e423519a9ee8251bbe0555 (patch) | |
tree | fe6229f2fe75a3d844408d9051cc3fa90dfe7fa8 /gpu/demos | |
parent | 49a518aabe67f9366bc23d0142493cb6508d662d (diff) | |
download | chromium_src-9a298ada39103abf74e423519a9ee8251bbe0555.zip chromium_src-9a298ada39103abf74e423519a9ee8251bbe0555.tar.gz chromium_src-9a298ada39103abf74e423519a9ee8251bbe0555.tar.bz2 |
Added support for lost context recovery on the client side. None of our service side GL implementations actually report lost contexts (yet).
Added pglGetError to PGL library.
pglSwapBuffers returns false on a lost context or other non-recoverable error and pglGetError reports PGL_CONTEXT_LOST.
Updated demo plugins to reset their PGL contexts on context lost. Standalone plugins cannot currently recover from lost context because they don't use PGL.
Added error code to NPDeviceContext3D for lost context.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/566021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38039 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu/demos')
-rw-r--r-- | gpu/demos/framework/plugin.cc | 55 | ||||
-rw-r--r-- | gpu/demos/framework/plugin.h | 3 |
2 files changed, 41 insertions, 17 deletions
diff --git a/gpu/demos/framework/plugin.cc b/gpu/demos/framework/plugin.cc index 153cd97..0514f81 100644 --- a/gpu/demos/framework/plugin.cc +++ b/gpu/demos/framework/plugin.cc @@ -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 @@ Plugin::~Plugin() { demo_.reset(); pglMakeCurrent(NULL); - pglDestroyContext(pgl_context_); + DestroyContext(); } NPClass* Plugin::GetPluginClass() { @@ -116,20 +117,10 @@ void Plugin::New(NPMIMEType pluginType, } void Plugin::SetWindow(const NPWindow& window) { - 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_); + demo_->InitWindowSize(window.width, window.height); - // Initialize demo. - pglMakeCurrent(pgl_context_); - demo_->InitWindowSize(window.width, window.height); - CHECK(demo_->InitGL()); - pglMakeCurrent(NULL); + if (!pgl_context_) { + CreateContext(); } // Schedule the first call to Draw. @@ -137,8 +128,12 @@ void Plugin::SetWindow(const NPWindow& window) { } 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 @@ void Plugin::Paint() { 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 diff --git a/gpu/demos/framework/plugin.h b/gpu/demos/framework/plugin.h index 7832d3b..0f4b55e 100644 --- a/gpu/demos/framework/plugin.h +++ b/gpu/demos/framework/plugin.h @@ -31,6 +31,9 @@ class Plugin : public NPObject { void Paint(); private: + void CreateContext(); + void DestroyContext(); + // This class object needs to be safely casted to NPObject* and cross // c-c++ module boundaries. To accomplish that this class should not have // any virtual member function. |