summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorapatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-26 21:01:53 +0000
committerapatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-26 21:01:53 +0000
commit41e3a47c68c73041695021d0fe56ec719c01da17 (patch)
tree39c5187d5591d4e98b5ed875e56c911f9315baa6
parent3b5fd0730c69f46d3e42361ac8e8567fc372676a (diff)
downloadchromium_src-41e3a47c68c73041695021d0fe56ec719c01da17.zip
chromium_src-41e3a47c68c73041695021d0fe56ec719c01da17.tar.gz
chromium_src-41e3a47c68c73041695021d0fe56ec719c01da17.tar.bz2
Made gpu demo framework plugins fail without crashing if pepper 3D cannot be initialized.
TEST=trybots BUG=none Review URL: http://codereview.chromium.org/1775001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45617 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--gpu/demos/framework/plugin.cc42
-rw-r--r--gpu/demos/framework/plugin.h2
2 files changed, 33 insertions, 11 deletions
diff --git a/gpu/demos/framework/plugin.cc b/gpu/demos/framework/plugin.cc
index 9ba01d4..ba79947 100644
--- a/gpu/demos/framework/plugin.cc
+++ b/gpu/demos/framework/plugin.cc
@@ -125,7 +125,8 @@ void Plugin::SetWindow(const NPWindow& window) {
demo_->InitWindowSize(window.width, window.height);
if (!pgl_context_) {
- CreateContext();
+ if (!CreateContext())
+ return;
// Schedule first call to Tick.
if (demo_->IsAnimated())
@@ -147,7 +148,9 @@ void Plugin::Tick() {
void Plugin::Paint() {
if (!pglMakeCurrent(pgl_context_) && pglGetError() == PGL_CONTEXT_LOST) {
DestroyContext();
- CreateContext();
+ if (!CreateContext())
+ return;
+
pglMakeCurrent(pgl_context_);
}
@@ -156,31 +159,50 @@ void Plugin::Paint() {
pglMakeCurrent(PGL_NO_CONTEXT);
}
-void Plugin::CreateContext() {
+bool Plugin::CreateContext() {
DCHECK(!pgl_context_);
// Initialize a 3D context.
NPDeviceContext3DConfig config;
config.commandBufferSize = kCommandBufferSize;
- device3d_->initializeContext(npp_, &config, &context3d_);
+ if (NPERR_NO_ERROR != device3d_->initializeContext(npp_,
+ &config,
+ &context3d_)) {
+ DestroyContext();
+ return false;
+ }
+
context3d_.repaintCallback = RepaintCallback;
// Create a PGL context.
pgl_context_ = pglCreateContext(npp_, device3d_, &context3d_);
+ if (!pgl_context_) {
+ DestroyContext();
+ return false;
+ }
// Initialize demo.
pglMakeCurrent(pgl_context_);
- CHECK(demo_->InitGL());
+ if (!demo_->InitGL()) {
+ DestroyContext();
+ return false;
+ }
+
pglMakeCurrent(PGL_NO_CONTEXT);
+
+ return true;
}
void Plugin::DestroyContext() {
- DCHECK(pgl_context_);
-
- pglDestroyContext(pgl_context_);
- pgl_context_ = NULL;
+ if (pgl_context_) {
+ pglDestroyContext(pgl_context_);
+ pgl_context_ = NULL;
+ }
- device3d_->destroyContext(npp_, &context3d_);
+ if (context3d_.commandBuffer) {
+ device3d_->destroyContext(npp_, &context3d_);
+ memset(&context3d_, 0, sizeof(context3d_));
+ }
}
} // namespace demos
diff --git a/gpu/demos/framework/plugin.h b/gpu/demos/framework/plugin.h
index 94910ff..5ddb056 100644
--- a/gpu/demos/framework/plugin.h
+++ b/gpu/demos/framework/plugin.h
@@ -35,7 +35,7 @@ class Plugin : public NPObject {
void Paint();
private:
- void CreateContext();
+ bool CreateContext();
void DestroyContext();
// This class object needs to be safely casted to NPObject* and cross