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

Side by Side 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, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gpu/demos/framework/plugin.h ('k') | gpu/pgl/pgl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/demos/framework/plugin.h" 5 #include "gpu/demos/framework/plugin.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "gpu/demos/framework/demo_factory.h" 8 #include "gpu/demos/framework/demo_factory.h"
9 9
10 using gpu::demos::Plugin;
11
10 namespace { 12 namespace {
11 const int32 kCommandBufferSize = 1024 * 1024; 13 const int32 kCommandBufferSize = 1024 * 1024;
12 NPExtensions* g_extensions = NULL; 14 NPExtensions* g_extensions = NULL;
13 15
14 // Plugin class functions. 16 // Plugin class functions.
15 using gpu::demos::Plugin;
16 NPObject* PluginAllocate(NPP npp, NPClass* the_class) { 17 NPObject* PluginAllocate(NPP npp, NPClass* the_class) {
17 Plugin* plugin = new Plugin(npp); 18 Plugin* plugin = new Plugin(npp);
18 return plugin; 19 return plugin;
19 } 20 }
20 21
21 void PluginDeallocate(NPObject* header) { 22 void PluginDeallocate(NPObject* header) {
22 Plugin* plugin = static_cast<Plugin*>(header); 23 Plugin* plugin = static_cast<Plugin*>(header);
23 delete plugin; 24 delete plugin;
24 } 25 }
25 26
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 demo_(CreateDemo()) { 91 demo_(CreateDemo()) {
91 memset(&context3d_, 0, sizeof(context3d_)); 92 memset(&context3d_, 0, sizeof(context3d_));
92 } 93 }
93 94
94 Plugin::~Plugin() { 95 Plugin::~Plugin() {
95 // Destroy demo while GL context is current and before it is destroyed. 96 // Destroy demo while GL context is current and before it is destroyed.
96 pglMakeCurrent(pgl_context_); 97 pglMakeCurrent(pgl_context_);
97 demo_.reset(); 98 demo_.reset();
98 pglMakeCurrent(NULL); 99 pglMakeCurrent(NULL);
99 100
100 pglDestroyContext(pgl_context_); 101 DestroyContext();
101 } 102 }
102 103
103 NPClass* Plugin::GetPluginClass() { 104 NPClass* Plugin::GetPluginClass() {
104 return &plugin_class; 105 return &plugin_class;
105 } 106 }
106 107
107 void Plugin::New(NPMIMEType pluginType, 108 void Plugin::New(NPMIMEType pluginType,
108 int16 argc, char* argn[], char* argv[]) { 109 int16 argc, char* argn[], char* argv[]) {
109 if (!g_extensions) { 110 if (!g_extensions) {
110 g_browser->getvalue(npp_, NPNVPepperExtensions, &g_extensions); 111 g_browser->getvalue(npp_, NPNVPepperExtensions, &g_extensions);
111 CHECK(g_extensions); 112 CHECK(g_extensions);
112 } 113 }
113 114
114 device3d_ = g_extensions->acquireDevice(npp_, NPPepper3DDevice); 115 device3d_ = g_extensions->acquireDevice(npp_, NPPepper3DDevice);
115 CHECK(device3d_); 116 CHECK(device3d_);
116 } 117 }
117 118
118 void Plugin::SetWindow(const NPWindow& window) { 119 void Plugin::SetWindow(const NPWindow& window) {
120 demo_->InitWindowSize(window.width, window.height);
121
119 if (!pgl_context_) { 122 if (!pgl_context_) {
120 // Initialize a 3D context. 123 CreateContext();
121 NPDeviceContext3DConfig config;
122 config.commandBufferSize = kCommandBufferSize;
123 device3d_->initializeContext(npp_, &config, &context3d_);
124
125 // Create a PGL context.
126 pgl_context_ = pglCreateContext(npp_, device3d_, &context3d_);
127
128 // Initialize demo.
129 pglMakeCurrent(pgl_context_);
130 demo_->InitWindowSize(window.width, window.height);
131 CHECK(demo_->InitGL());
132 pglMakeCurrent(NULL);
133 } 124 }
134 125
135 // Schedule the first call to Draw. 126 // Schedule the first call to Draw.
136 g_browser->pluginthreadasynccall(npp_, PaintCallback, this); 127 g_browser->pluginthreadasynccall(npp_, PaintCallback, this);
137 } 128 }
138 129
139 void Plugin::Paint() { 130 void Plugin::Paint() {
140 // Render some stuff. 131 if (!pglMakeCurrent(pgl_context_) && pglGetError() == PGL_CONTEXT_LOST) {
141 pglMakeCurrent(pgl_context_); 132 DestroyContext();
133 CreateContext();
134 pglMakeCurrent(pgl_context_);
135 }
136
142 demo_->Draw(); 137 demo_->Draw();
143 pglSwapBuffers(); 138 pglSwapBuffers();
144 pglMakeCurrent(NULL); 139 pglMakeCurrent(NULL);
145 140
146 // Schedule another call to Paint. 141 // Schedule another call to Paint.
147 g_browser->pluginthreadasynccall(npp_, PaintCallback, this); 142 g_browser->pluginthreadasynccall(npp_, PaintCallback, this);
148 } 143 }
149 144
145 void Plugin::CreateContext() {
146 DCHECK(!pgl_context_);
147
148 // Initialize a 3D context.
149 NPDeviceContext3DConfig config;
150 config.commandBufferSize = kCommandBufferSize;
151 device3d_->initializeContext(npp_, &config, &context3d_);
152
153 // Create a PGL context.
154 pgl_context_ = pglCreateContext(npp_, device3d_, &context3d_);
155
156 // Initialize demo.
157 pglMakeCurrent(pgl_context_);
158 CHECK(demo_->InitGL());
159 pglMakeCurrent(NULL);
160 }
161
162 void Plugin::DestroyContext() {
163 DCHECK(pgl_context_);
164
165 pglDestroyContext(pgl_context_);
166 pgl_context_ = NULL;
167
168 device3d_->destroyContext(npp_, &context3d_);
169 }
170
150 } // namespace demos 171 } // namespace demos
151 } // namespace gpu 172 } // namespace gpu
OLDNEW
« 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