diff options
author | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-20 00:56:25 +0000 |
---|---|---|
committer | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-20 00:56:25 +0000 |
commit | d717e03b637b8bd133db3fde5f3108b999a51a88 (patch) | |
tree | aca70991012a49441d24bbd201d894903ba05416 /gpu | |
parent | 5fe524efcaf51b401067d936b5ff331249dc99df (diff) | |
download | chromium_src-d717e03b637b8bd133db3fde5f3108b999a51a88.zip chromium_src-d717e03b637b8bd133db3fde5f3108b999a51a88.tar.gz chromium_src-d717e03b637b8bd133db3fde5f3108b999a51a88.tar.bz2 |
GPU plugin forwards repaint events to Pepper plugin.
WM_PAINT results in a call to Pepper repaint callback.
Implemented WM_ERASEBKGND to prevent flickering on repaint.
Implemented PGL_NO_CONTEXT (copied from EGL spec). This is already reviewed by alokp but unfortunately got entangled with this CL.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/571018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39530 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/demos/framework/demo.cc | 4 | ||||
-rw-r--r-- | gpu/demos/framework/demo.h | 4 | ||||
-rw-r--r-- | gpu/demos/framework/main_pepper.cc | 5 | ||||
-rw-r--r-- | gpu/demos/framework/plugin.cc | 35 | ||||
-rw-r--r-- | gpu/demos/framework/plugin.h | 4 | ||||
-rw-r--r-- | gpu/demos/framework/window_win.cc | 4 | ||||
-rw-r--r-- | gpu/demos/gles2_book/simple_vertex_shader.cc | 4 | ||||
-rw-r--r-- | gpu/pgl/pgl.cc | 2 | ||||
-rw-r--r-- | gpu/pgl/pgl.h | 16 |
9 files changed, 59 insertions, 19 deletions
diff --git a/gpu/demos/framework/demo.cc b/gpu/demos/framework/demo.cc index 49fa519..1679b3f 100644 --- a/gpu/demos/framework/demo.cc +++ b/gpu/demos/framework/demo.cc @@ -31,5 +31,9 @@ void Demo::Draw() { Render(elapsed_sec); } +bool Demo::IsAnimated() { + return false; +} + } // namespace demos } // namespace gpu diff --git a/gpu/demos/framework/demo.h b/gpu/demos/framework/demo.h index 801609b..28c8923 100644 --- a/gpu/demos/framework/demo.h +++ b/gpu/demos/framework/demo.h @@ -33,6 +33,10 @@ class Demo { // a rendering context has already been created and made current. virtual bool InitGL() = 0; + // Returns whether the demo is animated. Animated demos are drawn + // continuously. Unanimated demos are only drawn when the window is invalid. + virtual bool IsAnimated(); + // This function is called by the framework to perform OpenGL rendering. // When this function is called, it is assumed that the rendering context // has been made current. diff --git a/gpu/demos/framework/main_pepper.cc b/gpu/demos/framework/main_pepper.cc index 6937b62..cf8f510 100644 --- a/gpu/demos/framework/main_pepper.cc +++ b/gpu/demos/framework/main_pepper.cc @@ -90,6 +90,11 @@ void NPP_Print(NPP instance, NPPrint* platformPrint) { } int16 NPP_HandleEvent(NPP instance, void* event) { + Plugin* plugin = static_cast<Plugin*>(instance->pdata); + + if (plugin) + return plugin->HandleEvent(*static_cast<NPPepperEvent*>(event)); + return 0; } diff --git a/gpu/demos/framework/plugin.cc b/gpu/demos/framework/plugin.cc index 0514f81..9ba01d4 100644 --- a/gpu/demos/framework/plugin.cc +++ b/gpu/demos/framework/plugin.cc @@ -74,8 +74,13 @@ NPClass plugin_class = { PluginSetProperty, }; -void PaintCallback(void* data) { - reinterpret_cast<gpu::demos::Plugin*>(data)->Paint(); +void TickCallback(void* data) { + reinterpret_cast<gpu::demos::Plugin*>(data)->Tick(); +} + +void RepaintCallback(NPP npp, NPDeviceContext3D* /* context */) { + Plugin* plugin = static_cast<Plugin*>(npp->pdata); + plugin->Paint(); } } @@ -96,7 +101,7 @@ Plugin::~Plugin() { // Destroy demo while GL context is current and before it is destroyed. pglMakeCurrent(pgl_context_); demo_.reset(); - pglMakeCurrent(NULL); + pglMakeCurrent(PGL_NO_CONTEXT); DestroyContext(); } @@ -121,10 +126,22 @@ void Plugin::SetWindow(const NPWindow& window) { if (!pgl_context_) { CreateContext(); + + // Schedule first call to Tick. + if (demo_->IsAnimated()) + g_browser->pluginthreadasynccall(npp_, TickCallback, this); } +} - // Schedule the first call to Draw. - g_browser->pluginthreadasynccall(npp_, PaintCallback, this); +int32 Plugin::HandleEvent(const NPPepperEvent& event) { + return 0; +} + +void Plugin::Tick() { + Paint(); + + // Schedule another call to Tick. + g_browser->pluginthreadasynccall(npp_, TickCallback, this); } void Plugin::Paint() { @@ -136,10 +153,7 @@ void Plugin::Paint() { demo_->Draw(); pglSwapBuffers(); - pglMakeCurrent(NULL); - - // Schedule another call to Paint. - g_browser->pluginthreadasynccall(npp_, PaintCallback, this); + pglMakeCurrent(PGL_NO_CONTEXT); } void Plugin::CreateContext() { @@ -149,6 +163,7 @@ void Plugin::CreateContext() { NPDeviceContext3DConfig config; config.commandBufferSize = kCommandBufferSize; device3d_->initializeContext(npp_, &config, &context3d_); + context3d_.repaintCallback = RepaintCallback; // Create a PGL context. pgl_context_ = pglCreateContext(npp_, device3d_, &context3d_); @@ -156,7 +171,7 @@ void Plugin::CreateContext() { // Initialize demo. pglMakeCurrent(pgl_context_); CHECK(demo_->InitGL()); - pglMakeCurrent(NULL); + pglMakeCurrent(PGL_NO_CONTEXT); } void Plugin::DestroyContext() { diff --git a/gpu/demos/framework/plugin.h b/gpu/demos/framework/plugin.h index 0f4b55e..640d9c0 100644 --- a/gpu/demos/framework/plugin.h +++ b/gpu/demos/framework/plugin.h @@ -26,6 +26,10 @@ class Plugin : public NPObject { NPP npp() const { return npp_; } void New(NPMIMEType pluginType, int16 argc, char* argn[], char* argv[]); void SetWindow(const NPWindow& window); + int32 HandleEvent(const NPPepperEvent& event); + + // Called continuously for animated demos. + void Tick(); // Called by the browser to paint the window. void Paint(); diff --git a/gpu/demos/framework/window_win.cc b/gpu/demos/framework/window_win.cc index 37f41c2..dfd79fc 100644 --- a/gpu/demos/framework/window_win.cc +++ b/gpu/demos/framework/window_win.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "gpu/demos/framework/demo.h" #include "gpu/demos/framework/window.h" namespace { @@ -52,7 +53,8 @@ void Window::MainLoop() { ::DispatchMessage(&msg); } // Message queue is empty and application has not quit yet - keep painting. - if (!done) ::InvalidateRect(window_handle_, NULL, FALSE); + if (!done && demo_->IsAnimated()) + ::InvalidateRect(window_handle_,NULL, FALSE); } } diff --git a/gpu/demos/gles2_book/simple_vertex_shader.cc b/gpu/demos/gles2_book/simple_vertex_shader.cc index dff99ca..0f8b72e 100644 --- a/gpu/demos/gles2_book/simple_vertex_shader.cc +++ b/gpu/demos/gles2_book/simple_vertex_shader.cc @@ -22,6 +22,10 @@ class SimpleVertexShader : public Example<SVSUserData> { const wchar_t* Title() const { return L"Simple Vertex Shader"; } + + virtual bool IsAnimated() { + return true; + } }; } // namespace gles2_book diff --git a/gpu/pgl/pgl.cc b/gpu/pgl/pgl.cc index d357fe2..59c2635 100644 --- a/gpu/pgl/pgl.cc +++ b/gpu/pgl/pgl.cc @@ -223,7 +223,7 @@ PGLBoolean pglDestroyContext(PGLContext pgl_context) { return PGL_FALSE; if (pgl_context == pglGetCurrentContext()) - pglMakeCurrent(NULL); + pglMakeCurrent(PGL_NO_CONTEXT); delete static_cast<PGLContextImpl*>(pgl_context); return PGL_TRUE; diff --git a/gpu/pgl/pgl.h b/gpu/pgl/pgl.h index ac67ec1..118d6fe 100644 --- a/gpu/pgl/pgl.h +++ b/gpu/pgl/pgl.h @@ -8,8 +8,10 @@ #include "npapi.h" #include "npapi_extensions.h" -#define PGL_TRUE 1 -#define PGL_FALSE 0 +#define PGL_TRUE 1 +#define PGL_FALSE 0 + +#define PGL_NO_CONTEXT ((PGLContext) 0) #ifdef __cplusplus extern "C" { @@ -21,11 +23,11 @@ typedef int32 PGLInt; // These are the same error codes as used by EGL. enum { - PGL_SUCCESS = 0x3000, - PGL_NOT_INITIALIZED = 0x3001, - PGL_BAD_CONTEXT = 0x3006, - PGL_BAD_PARAMETER = 0x300C, - PGL_CONTEXT_LOST = 0x300E + PGL_SUCCESS = 0x3000, + PGL_NOT_INITIALIZED = 0x3001, + PGL_BAD_CONTEXT = 0x3006, + PGL_BAD_PARAMETER = 0x300C, + PGL_CONTEXT_LOST = 0x300E }; // Initialize the PGL library. This must have completed before any other PGL |