diff options
author | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-05 01:54:06 +0000 |
---|---|---|
committer | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-05 01:54:06 +0000 |
commit | a9a430111290193028dc2b39be75c176d49d7bd3 (patch) | |
tree | 4b28a94aed9596ff8bcaf5f67b1e9273ece1c40f /chrome/renderer | |
parent | 0f8805d56674fff8ef79abd0981a3ede8b79190d (diff) | |
download | chromium_src-a9a430111290193028dc2b39be75c176d49d7bd3.zip chromium_src-a9a430111290193028dc2b39be75c176d49d7bd3.tar.gz chromium_src-a9a430111290193028dc2b39be75c176d49d7bd3.tar.bz2 |
Revert 65152 - Integrated Pepper3D v2 with the accelerated compositor.
- It now uses GGL instead of a child window.
- Fixed a bug where GLES2 decoder set texture state without updating TextureInfo.
- Fixed Pepper3D demos and added awesome 3D CSS programmer art.
- Removed ggl::GetCurrentContext to prevent further abuse. Fixed said abuse :)
- GGL exposes GLES2Implementation to allow issue of GL calls on a particular context without making that context globally current.
- Removed redundant "this context" argument from GGL SwapBuffers completion callback.
- Temporarily removed context lost notification. I need to figure out the best semantics.
TEST=Run Pepper3D and WebGL demos and YouTube videos on Windows and Mac.
BUG=none
Review URL: http://codereview.chromium.org/3531008
TBR=apatrick@chromium.org
Review URL: http://codereview.chromium.org/4561001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65169 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/ggl/ggl.cc | 50 | ||||
-rw-r--r-- | chrome/renderer/ggl/ggl.h | 18 | ||||
-rw-r--r-- | chrome/renderer/pepper_plugin_delegate_impl.cc | 276 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 16 | ||||
-rw-r--r-- | chrome/renderer/webgraphicscontext3d_command_buffer_impl.h | 2 |
5 files changed, 223 insertions, 139 deletions
diff --git a/chrome/renderer/ggl/ggl.cc b/chrome/renderer/ggl/ggl.cc index cfe6743..0589852 100644 --- a/chrome/renderer/ggl/ggl.cc +++ b/chrome/renderer/ggl/ggl.cc @@ -6,6 +6,7 @@ #include "base/ref_counted.h" #include "base/singleton.h" +#include "base/thread_local.h" #include "base/weak_ptr.h" #include "chrome/renderer/command_buffer_proxy.h" #include "chrome/renderer/ggl/ggl.h" @@ -34,6 +35,8 @@ const int32 kCommandBufferSize = 1024 * 1024; // creation attributes. const int32 kTransferBufferSize = 1024 * 1024; +base::ThreadLocalPointer<Context> g_current_context; + // Singleton used to initialize and terminate the gles2 library. class GLES2Initializer { public: @@ -74,7 +77,7 @@ class Context : public base::SupportsWeakPtr<Context> { // Provides a callback that will be invoked when SwapBuffers has completed // service side. - void SetSwapBuffersCallback(Callback0::Type* callback) { + void SetSwapBuffersCallback(Callback1<Context*>::Type* callback) { swap_buffers_callback_.reset(callback); } @@ -114,22 +117,17 @@ class Context : public base::SupportsWeakPtr<Context> { // TODO(gman): Remove this. void DisableShaderTranslation(); - gpu::gles2::GLES2Implementation* gles2_implementation() const { - return gles2_implementation_; - } private: void OnSwapBuffers(); scoped_refptr<GpuChannelHost> channel_; base::WeakPtr<Context> parent_; - scoped_ptr<Callback0::Type> swap_buffers_callback_; + scoped_ptr<Callback1<Context*>::Type> swap_buffers_callback_; uint32 parent_texture_id_; CommandBufferProxy* command_buffer_; gpu::gles2::GLES2CmdHelper* gles2_helper_; int32 transfer_buffer_id_; gpu::gles2::GLES2Implementation* gles2_implementation_; - gfx::Size size_; - Error last_error_; DISALLOW_COPY_AND_ASSIGN(Context); @@ -264,25 +262,19 @@ bool Context::Initialize(gfx::NativeViewId view, transfer_buffer_id_, false); - size_ = size; - return true; } #if defined(OS_MACOSX) void Context::ResizeOnscreen(const gfx::Size& size) { DCHECK(size.width() > 0 && size.height() > 0); - size_ = size; command_buffer_->SetWindowSize(size); } #endif void Context::ResizeOffscreen(const gfx::Size& size) { DCHECK(size.width() > 0 && size.height() > 0); - if (size_ != size) { - command_buffer_->ResizeOffscreenFrameBuffer(size); - size_ = size; - } + command_buffer_->ResizeOffscreenFrameBuffer(size); } uint32 Context::CreateParentTexture(const gfx::Size& size) const { @@ -351,6 +343,7 @@ void Context::Destroy() { } bool Context::MakeCurrent(Context* context) { + g_current_context.Set(context); if (context) { gles2::SetGLContext(context->gles2_implementation_); @@ -412,7 +405,7 @@ void Context::DisableShaderTranslation() { void Context::OnSwapBuffers() { if (swap_buffers_callback_.get()) - swap_buffers_callback_->Run(); + swap_buffers_callback_->Run(this); } #endif // ENABLE_GPU @@ -487,7 +480,7 @@ void DeleteParentTexture(Context* context, uint32 texture) { } void SetSwapBuffersCallback(Context* context, - Callback0::Type* callback) { + Callback1<Context*>::Type* callback) { #if defined(ENABLE_GPU) context->SetSwapBuffersCallback(callback); #endif @@ -501,6 +494,14 @@ bool MakeCurrent(Context* context) { #endif } +Context* GetCurrentContext() { +#if defined(ENABLE_GPU) + return g_current_context.Get(); +#else + return NULL; +#endif +} + bool SwapBuffers(Context* context) { #if defined(ENABLE_GPU) if (!context) @@ -517,6 +518,9 @@ bool DestroyContext(Context* context) { if (!context) return false; + if (context == GetCurrentContext()) + MakeCurrent(NULL); + delete context; return true; #else @@ -533,8 +537,12 @@ media::VideoDecodeContext* CreateVideoDecodeContext( return context->CreateVideoDecodeContext(message_loop, hardware_decoder); } -Error GetError(Context* context) { +Error GetError() { #if defined(ENABLE_GPU) + Context* context = GetCurrentContext(); + if (!context) + return BAD_CONTEXT; + return context->GetError(); #else return NOT_INITIALIZED; @@ -549,12 +557,4 @@ void DisableShaderTranslation(Context* context) { } #endif } - -gpu::gles2::GLES2Implementation* GetImplementation(Context* context) { - if (!context) - return NULL; - - return context->gles2_implementation(); -} - } // namespace ggl diff --git a/chrome/renderer/ggl/ggl.h b/chrome/renderer/ggl/ggl.h index 54a7f8e..1d53f57 100644 --- a/chrome/renderer/ggl/ggl.h +++ b/chrome/renderer/ggl/ggl.h @@ -18,12 +18,6 @@ class GpuChannelHost; class MessageLoop; -namespace gpu { -namespace gles2 { -class GLES2Implementation; -} -} - namespace media { class VideoDecodeContext; class VideoDecodeEngine; @@ -126,11 +120,15 @@ void DeleteParentTexture(Context* context, uint32 texture); // Provides a callback that will be invoked when SwapBuffers has completed // service side. -void SetSwapBuffersCallback(Context* context, Callback0::Type* callback); +void SetSwapBuffersCallback(Context* context, + Callback1<Context*>::Type* callback); // Set the current GGL context for the calling thread. bool MakeCurrent(Context* context); +// Get the calling thread's current GGL context. +Context* GetCurrentContext(); + // For a view context, display everything that has been rendered since the // last call. For an offscreen context, resolve everything that has been // rendered since the last call to a copy that can be accessed by the parent @@ -155,12 +153,8 @@ media::VideoDecodeContext* CreateVideoDecodeContext(Context* context, // TODO(gman): Remove this void DisableShaderTranslation(Context* context); -// Allows direct access to the GLES2 implementation so a context -// can be used without making it current. -gpu::gles2::GLES2Implementation* GetImplementation(Context* context); - // Return the current GGL error. -Error GetError(Context* context); +Error GetError(); } // namespace ggl diff --git a/chrome/renderer/pepper_plugin_delegate_impl.cc b/chrome/renderer/pepper_plugin_delegate_impl.cc index d7b6c87..06ca49a 100644 --- a/chrome/renderer/pepper_plugin_delegate_impl.cc +++ b/chrome/renderer/pepper_plugin_delegate_impl.cc @@ -8,7 +8,6 @@ #include "app/l10n_util.h" #include "app/surface/transport_dib.h" -#include "base/callback.h" #include "base/file_path.h" #include "base/logging.h" #include "base/scoped_ptr.h" @@ -22,13 +21,9 @@ #include "chrome/common/render_messages_params.h" #include "chrome/renderer/audio_message_filter.h" #include "chrome/renderer/command_buffer_proxy.h" -#include "chrome/renderer/ggl/ggl.h" -#include "chrome/renderer/gpu_channel_host.h" #include "chrome/renderer/render_thread.h" #include "chrome/renderer/render_view.h" -#include "chrome/renderer/webgraphicscontext3d_command_buffer_impl.h" #include "chrome/renderer/webplugin_delegate_proxy.h" -#include "gfx/size.h" #include "grit/locale_settings.h" #include "ppapi/c/dev/pp_video_dev.h" #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserCompletion.h" @@ -85,29 +80,139 @@ class PlatformImage2DImpl : public pepper::PluginDelegate::PlatformImage2D { class PlatformContext3DImpl : public pepper::PluginDelegate::PlatformContext3D { public: - explicit PlatformContext3DImpl(WebKit::WebView* web_view) - : web_view_(web_view), - context_(NULL) { - } + explicit PlatformContext3DImpl(RenderView* render_view) + : render_view_(render_view), + nested_delegate_(NULL), + command_buffer_(NULL), + renderview_to_webplugin_adapter_(render_view) {} virtual ~PlatformContext3DImpl() { - if (context_) { - ggl::DestroyContext(context_); - context_ = NULL; + if (nested_delegate_) { + nested_delegate_->DestroyCommandBuffer(command_buffer_); + nested_delegate_->PluginDestroyed(); } } - virtual bool Init(); - virtual bool SwapBuffers(); - virtual unsigned GetError(); - virtual void SetSwapBuffersCallback(Callback0::Type* callback); - void ResizeBackingTexture(const gfx::Size& size); - virtual unsigned GetBackingTextureId(); - virtual gpu::gles2::GLES2Implementation* GetGLES2Implementation(); + virtual bool Init(const gfx::Rect& position, const gfx::Rect& clip); + + virtual gpu::CommandBuffer* GetCommandBuffer() { + return command_buffer_; + } + + virtual void SetNotifyRepaintTask(Task* task) { + command_buffer_->SetNotifyRepaintTask(task); + } private: - WebKit::WebView* web_view_; - ggl::Context* context_; + + class WebPluginAdapter : public webkit_glue::WebPlugin { + public: + explicit WebPluginAdapter(RenderView* render_view) + : render_view_(render_view) {} + + virtual void SetWindow(gfx::PluginWindowHandle window) { + render_view_->CreatedPluginWindow(window); + } + + virtual void WillDestroyWindow(gfx::PluginWindowHandle window) { + render_view_->WillDestroyPluginWindow(window); + } + + virtual void SetAcceptsInputEvents(bool accepts) { + NOTREACHED(); + } + +#if defined(OS_WIN) + virtual void SetWindowlessPumpEvent(HANDLE pump_messages_event) { + NOTREACHED(); + } +#endif + + virtual void CancelResource(unsigned long id) { + NOTREACHED(); + } + + virtual void Invalidate() { + NOTREACHED(); + } + + virtual void InvalidateRect(const gfx::Rect& rect) { + NOTREACHED(); + } + + virtual NPObject* GetWindowScriptNPObject() { + NOTREACHED(); + return NULL; + } + + virtual NPObject* GetPluginElement() { + NOTREACHED(); + return NULL; + } + + virtual void SetCookie(const GURL& url, + const GURL& first_party_for_cookies, + const std::string& cookie) { + NOTREACHED(); + } + + virtual std::string GetCookies(const GURL& url, + const GURL& first_party_for_cookies) { + NOTREACHED(); + return std::string(); + } + + virtual void ShowModalHTMLDialog(const GURL& url, int width, int height, + const std::string& json_arguments, + std::string* json_retval) { + NOTREACHED(); + } + + virtual void OnMissingPluginStatus(int status) { + NOTREACHED(); + } + + virtual void HandleURLRequest(const char* url, + const char* method, + const char* target, + const char* buf, + unsigned int len, + int notify_id, + bool popups_allowed) { + NOTREACHED(); + } + + virtual void CancelDocumentLoad() { + NOTREACHED(); + } + + virtual void InitiateHTTPRangeRequest(const char* url, + const char* range_info, + int range_request_id) { + NOTREACHED(); + } + + virtual bool IsOffTheRecord() { + NOTREACHED(); + return false; + } + + virtual void SetDeferResourceLoading(unsigned long resource_id, + bool defer) { + NOTREACHED(); + } + + private: + RenderView* render_view_; + }; + + void SendNestedDelegateGeometryToBrowser(const gfx::Rect& window_rect, + const gfx::Rect& clip_rect); + + RenderView* render_view_; + WebPluginDelegateProxy* nested_delegate_; + CommandBufferProxy* command_buffer_; + WebPluginAdapter renderview_to_webplugin_adapter_; }; #endif // ENABLE_GPU @@ -173,83 +278,76 @@ class PlatformAudioImpl #ifdef ENABLE_GPU -bool PlatformContext3DImpl::Init() { +bool PlatformContext3DImpl::Init(const gfx::Rect& position, + const gfx::Rect& clip) { +#if defined(ENABLE_GPU) // Ignore initializing more than once. - if (context_) + if (nested_delegate_) return true; - WebGraphicsContext3DCommandBufferImpl* context = - static_cast<WebGraphicsContext3DCommandBufferImpl*>( - web_view_->graphicsContext3D()); - if (!context) - return false; - - ggl::Context* parent_context = context->context(); - if (!parent_context) - return false; - - RenderThread* render_thread = RenderThread::current(); - if (!render_thread) - return false; - - GpuChannelHost* host = render_thread->GetGpuChannel(); - if (!host) - return false; - - DCHECK(host->state() == GpuChannelHost::CONNECTED); - - // TODO(apatrick): Let Pepper plugins configure their back buffer surface. - static const int32 attribs[] = { - ggl::GGL_ALPHA_SIZE, 8, - ggl::GGL_DEPTH_SIZE, 24, - ggl::GGL_STENCIL_SIZE, 8, - ggl::GGL_SAMPLES, 0, - ggl::GGL_SAMPLE_BUFFERS, 0, - ggl::GGL_NONE, - }; - - // TODO(apatrick): Decide which extensions to expose to Pepper plugins. - // Currently they get only core GLES2. - context_ = ggl::CreateOffscreenContext(host, - parent_context, - gfx::Size(1, 1), - "", - attribs); - if (!context_) - return false; - - return true; -} + // Create an instance of the GPU plugin that is responsible for 3D + // rendering. + nested_delegate_ = new WebPluginDelegateProxy( + std::string("application/vnd.google.chrome.gpu-plugin"), + render_view_->AsWeakPtr()); + + if (nested_delegate_->Initialize(GURL(), std::vector<std::string>(), + std::vector<std::string>(), + &renderview_to_webplugin_adapter_, + false)) { + // Ensure the window has the correct size before initializing the + // command buffer. + nested_delegate_->UpdateGeometry(position, clip); + + // Ask the GPU plugin to create a command buffer and return a proxy. + command_buffer_ = nested_delegate_->CreateCommandBuffer(); + if (command_buffer_) { + // Initialize the proxy command buffer. + if (command_buffer_->Initialize(kDefaultCommandBufferSize)) { +#if defined(OS_MACOSX) + command_buffer_->SetWindowSize(position.size()); +#endif // OS_MACOSX -bool PlatformContext3DImpl::SwapBuffers() { - DCHECK(context_); - return ggl::SwapBuffers(context_); -} + // Make sure the nested delegate shows up in the right place + // on the page. + SendNestedDelegateGeometryToBrowser(position, clip); -unsigned PlatformContext3DImpl::GetError() { - DCHECK(context_); - return ggl::GetError(context_); -} + return true; + } + } -void PlatformContext3DImpl::ResizeBackingTexture(const gfx::Size& size) { - DCHECK(context_); - ggl::ResizeOffscreenContext(context_, size); -} + nested_delegate_->DestroyCommandBuffer(command_buffer_); + command_buffer_ = NULL; + } -void PlatformContext3DImpl::SetSwapBuffersCallback(Callback0::Type* callback) { - DCHECK(context_); - ggl::SetSwapBuffersCallback(context_, callback); + nested_delegate_->PluginDestroyed(); + nested_delegate_ = NULL; +#endif // ENABLE_GPU + return false; } -unsigned PlatformContext3DImpl::GetBackingTextureId() { - DCHECK(context_); - return ggl::GetParentTextureId(context_); -} +void PlatformContext3DImpl::SendNestedDelegateGeometryToBrowser( + const gfx::Rect& window_rect, + const gfx::Rect& clip_rect) { + // Inform the browser about the location of the plugin on the page. + // It appears that initially the plugin does not get laid out correctly -- + // possibly due to lazy creation of the nested delegate. + if (!nested_delegate_ || + !nested_delegate_->GetPluginWindowHandle() || + !render_view_) { + return; + } -gpu::gles2::GLES2Implementation* - PlatformContext3DImpl::GetGLES2Implementation() { - DCHECK(context_); - return ggl::GetImplementation(context_); + webkit_glue::WebPluginGeometry geom; + geom.window = nested_delegate_->GetPluginWindowHandle(); + geom.window_rect = window_rect; + geom.clip_rect = clip_rect; + // Rects_valid must be true for this to work in the Gtk port; + // hopefully not having the cutout rects will not cause incorrect + // clipping. + geom.rects_valid = true; + geom.visible = true; + render_view_->DidMovePlugin(geom); } #endif // ENABLE_GPU @@ -506,7 +604,7 @@ PepperPluginDelegateImpl::CreateImage2D(int width, int height) { pepper::PluginDelegate::PlatformContext3D* PepperPluginDelegateImpl::CreateContext3D() { #ifdef ENABLE_GPU - return new PlatformContext3DImpl(render_view_->webview()); + return new PlatformContext3DImpl(render_view_); #else return NULL; #endif diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index aa23831..0b300a1 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -86,7 +86,6 @@ #include "chrome/renderer/user_script_idle_scheduler.h" #include "chrome/renderer/user_script_slave.h" #include "chrome/renderer/visitedlink_slave.h" -#include "chrome/renderer/webgraphicscontext3d_command_buffer_impl.h" #include "chrome/renderer/webplugin_delegate_pepper.h" #include "chrome/renderer/webplugin_delegate_proxy.h" #include "chrome/renderer/websharedworker_proxy.h" @@ -2621,19 +2620,14 @@ WebMediaPlayer* RenderView::createMediaPlayer( if (cmd_line->HasSwitch(switches::kEnableAcceleratedDecoding) && !cmd_line->HasSwitch(switches::kDisableAcceleratedCompositing)) { - WebGraphicsContext3DCommandBufferImpl* context = - static_cast<WebGraphicsContext3DCommandBufferImpl*>( - frame->view()->graphicsContext3D()); - if (!context) - return NULL; - // Add the hardware video decoder factory. - // TODO(hclam): This will cause the renderer process to crash on context - // lost. - bool ret = context->makeContextCurrent(); + // TODO(hclam): This assumes that ggl::Context is set to current + // internally. I need to make it more explicit to get the context. + bool ret = frame->view()->graphicsContext3D()->makeContextCurrent(); CHECK(ret) << "Failed to switch context"; + collection->AddFilter(new IpcVideoDecoder( - MessageLoop::current(), context->context())); + MessageLoop::current(), ggl::GetCurrentContext())); } WebApplicationCacheHostImpl* appcache_host = diff --git a/chrome/renderer/webgraphicscontext3d_command_buffer_impl.h b/chrome/renderer/webgraphicscontext3d_command_buffer_impl.h index 11369d7..116bced 100644 --- a/chrome/renderer/webgraphicscontext3d_command_buffer_impl.h +++ b/chrome/renderer/webgraphicscontext3d_command_buffer_impl.h @@ -368,8 +368,6 @@ class WebGraphicsContext3DCommandBufferImpl virtual void copyTextureToCompositor(unsigned texture, unsigned parent_texture); - ggl::Context* context() { return context_; } - private: // The GGL context we use for OpenGL rendering. ggl::Context* context_; |