diff options
author | alokp@chromium.org <alokp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-18 21:18:27 +0000 |
---|---|---|
committer | alokp@chromium.org <alokp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-18 21:18:27 +0000 |
commit | e5eb5c46fa4a9b3412f6dc41cbbc636fe23490f1 (patch) | |
tree | 981d68c305778f15a3dd4a821fd69b359e148450 /webkit/plugins | |
parent | 764b80591d30619821b3c6c78bad6cae8ece82d2 (diff) | |
download | chromium_src-e5eb5c46fa4a9b3412f6dc41cbbc636fe23490f1.zip chromium_src-e5eb5c46fa4a9b3412f6dc41cbbc636fe23490f1.tar.gz chromium_src-e5eb5c46fa4a9b3412f6dc41cbbc636fe23490f1.tar.bz2 |
Revert 92885 - Completed the implementation for PPB_Graphics3D interface.
- Mostly copied from the implementations for PPB_Surface3D and PPB_Context3D.
- Added the proxy implementation
- Refactored common code between host and plugin side into a common class.
I will send the changes to bind Graphics3D with Instance and OpenGLES2 interface in a separate patch.
BUG=86370,78087
Review URL: http://codereview.chromium.org/6824006
TBR=alokp@chromium.org
Review URL: http://codereview.chromium.org/7398033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92891 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/plugins')
-rw-r--r-- | webkit/plugins/ppapi/ppb_graphics_3d_impl.cc | 229 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_graphics_3d_impl.h | 67 | ||||
-rw-r--r-- | webkit/plugins/ppapi/resource_creation_impl.cc | 9 | ||||
-rw-r--r-- | webkit/plugins/ppapi/resource_creation_impl.h | 4 |
4 files changed, 28 insertions, 281 deletions
diff --git a/webkit/plugins/ppapi/ppb_graphics_3d_impl.cc b/webkit/plugins/ppapi/ppb_graphics_3d_impl.cc index 9d347a2..486c790 100644 --- a/webkit/plugins/ppapi/ppb_graphics_3d_impl.cc +++ b/webkit/plugins/ppapi/ppb_graphics_3d_impl.cc @@ -1,63 +1,25 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" -#include "base/message_loop.h" -#include "gpu/command_buffer/client/gles2_implementation.h" -#include "webkit/plugins/ppapi/plugin_module.h" +#include "base/logging.h" +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_errors.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/resource_tracker.h" using ppapi::thunk::PPB_Graphics3D_API; namespace webkit { namespace ppapi { -namespace { -const int32 kCommandBufferSize = 1024 * 1024; -const int32 kTransferBufferSize = 1024 * 1024; - -PP_Bool ShmToHandle(base::SharedMemory* shm, - size_t size, - int* shm_handle, - uint32_t* shm_size) { - if (!shm || !shm_handle || !shm_size) - return PP_FALSE; -#if defined(OS_POSIX) - *shm_handle = shm->handle().fd; -#elif defined(OS_WIN) - *shm_handle = reinterpret_cast<int>(shm->handle()); -#else - #error "Platform not supported." -#endif - *shm_size = size; - return PP_TRUE; -} - -PP_Graphics3DTrustedState PPStateFromGPUState( - const gpu::CommandBuffer::State& s) { - PP_Graphics3DTrustedState state = { - s.num_entries, - s.get_offset, - s.put_offset, - s.token, - static_cast<PPB_Graphics3DTrustedError>(s.error), - s.generation - }; - return state; -} -} // namespace. - PPB_Graphics3D_Impl::PPB_Graphics3D_Impl(PluginInstance* instance) - : Resource(instance), - bound_to_instance_(false), - commit_pending_(false), - callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { + : Resource(instance) { } PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() { - DestroyGLES2Impl(); } // static @@ -65,187 +27,36 @@ PP_Resource PPB_Graphics3D_Impl::Create(PluginInstance* instance, PP_Config3D_Dev config, PP_Resource share_context, const int32_t* attrib_list) { - scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( - new PPB_Graphics3D_Impl(instance)); - - if (!graphics_3d->Init(config, share_context, attrib_list)) - return 0; - - return graphics_3d->GetReference(); -} - -PP_Resource PPB_Graphics3D_Impl::CreateRaw(PluginInstance* instance, - PP_Config3D_Dev config, - PP_Resource share_context, - const int32_t* attrib_list) { - scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( - new PPB_Graphics3D_Impl(instance)); - - if (!graphics_3d->InitRaw(config, share_context, attrib_list)) + scoped_refptr<PPB_Graphics3D_Impl> t(new PPB_Graphics3D_Impl(instance)); + if (!t->Init(config, share_context, attrib_list)) return 0; - - return graphics_3d->GetReference(); + return t->GetReference(); } PPB_Graphics3D_API* PPB_Graphics3D_Impl::AsPPB_Graphics3D_API() { return this; } -PP_Bool PPB_Graphics3D_Impl::InitCommandBuffer(int32_t size) { - return PP_FromBool(GetCommandBuffer()->Initialize(size)); -} - -PP_Bool PPB_Graphics3D_Impl::GetRingBuffer(int* shm_handle, - uint32_t* shm_size) { - gpu::Buffer buffer = GetCommandBuffer()->GetRingBuffer(); - return ShmToHandle(buffer.shared_memory, buffer.size, shm_handle, shm_size); -} - -PP_Graphics3DTrustedState PPB_Graphics3D_Impl::GetState() { - return PPStateFromGPUState(GetCommandBuffer()->GetState()); -} - -int32_t PPB_Graphics3D_Impl::CreateTransferBuffer(uint32_t size) { - return GetCommandBuffer()->CreateTransferBuffer(size, -1); -} - -PP_Bool PPB_Graphics3D_Impl::DestroyTransferBuffer(int32_t id) { - GetCommandBuffer()->DestroyTransferBuffer(id); - return PP_TRUE; -} - -PP_Bool PPB_Graphics3D_Impl::GetTransferBuffer(int32_t id, - int* shm_handle, - uint32_t* shm_size) { - gpu::Buffer buffer = GetCommandBuffer()->GetTransferBuffer(id); - return ShmToHandle(buffer.shared_memory, buffer.size, shm_handle, shm_size); -} - -PP_Bool PPB_Graphics3D_Impl::Flush(int32_t put_offset) { - GetCommandBuffer()->Flush(put_offset); - return PP_TRUE; -} - -PP_Graphics3DTrustedState PPB_Graphics3D_Impl::FlushSync(int32_t put_offset) { - gpu::CommandBuffer::State state = GetCommandBuffer()->GetState(); - return PPStateFromGPUState( - GetCommandBuffer()->FlushSync(put_offset, state.get_offset)); -} - -PP_Graphics3DTrustedState PPB_Graphics3D_Impl::FlushSyncFast( - int32_t put_offset, - int32_t last_known_get) { - return PPStateFromGPUState( - GetCommandBuffer()->FlushSync(put_offset, last_known_get)); -} - -bool PPB_Graphics3D_Impl::BindToInstance(bool bind) { - bound_to_instance_ = bind; - return true; -} - -unsigned int PPB_Graphics3D_Impl::GetBackingTextureId() { - return platform_context_->GetBackingTextureId(); -} - -void PPB_Graphics3D_Impl::ViewInitiatedPaint() { +int32_t PPB_Graphics3D_Impl::GetAttribs(int32_t* attrib_list) { + // TODO(alokp): Implement me. + return PP_ERROR_FAILED; } -void PPB_Graphics3D_Impl::ViewFlushedPaint() { - commit_pending_ = false; - - if (HasPendingSwap()) - SwapBuffersACK(PP_OK); -} - -gpu::CommandBuffer* PPB_Graphics3D_Impl::GetCommandBuffer() { - return platform_context_->GetCommandBuffer(); +int32_t PPB_Graphics3D_Impl::SetAttribs(int32_t* attrib_list) { + // TODO(alokp): Implement me. + return PP_ERROR_FAILED; } -int32 PPB_Graphics3D_Impl::DoSwapBuffers() { - // We do not have a GLES2 implementation when using an OOP proxy. - // The plugin-side proxy is responsible for adding the SwapBuffers command - // to the command buffer in that case. - if (gles2_impl()) - gles2_impl()->SwapBuffers(); - - return PP_OK_COMPLETIONPENDING; +int32_t PPB_Graphics3D_Impl::SwapBuffers(PP_CompletionCallback callback) { + // TODO(alokp): Implement me. + return PP_ERROR_FAILED; } bool PPB_Graphics3D_Impl::Init(PP_Config3D_Dev config, PP_Resource share_context, const int32_t* attrib_list) { - if (!InitRaw(config, share_context, attrib_list)) - return false; - - gpu::CommandBuffer* command_buffer = GetCommandBuffer(); - if (!command_buffer->Initialize(kCommandBufferSize)) - return false; - - return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize); -} - -bool PPB_Graphics3D_Impl::InitRaw(PP_Config3D_Dev config, - PP_Resource share_context, - const int32_t* attrib_list) { - // TODO(alokp): Support shared context. - DCHECK_EQ(0, share_context); - if (share_context != 0) - return 0; - - platform_context_.reset(instance()->CreateContext3D()); - if (!platform_context_.get()) - return false; - - if (!platform_context_->Init()) - return false; - - platform_context_->SetContextLostCallback( - callback_factory_.NewCallback(&PPB_Graphics3D_Impl::OnContextLost)); - platform_context_->SetSwapBuffersCallback( - callback_factory_.NewCallback(&PPB_Graphics3D_Impl::OnSwapBuffers)); - return true; -} - -void PPB_Graphics3D_Impl::OnSwapBuffers() { - if (bound_to_instance_) { - // If we are bound to the instance, we need to ask the compositor - // to commit our backing texture so that the graphics appears on the page. - // When the backing texture will be committed we get notified via - // ViewFlushedPaint(). - instance()->CommitBackingTexture(); - commit_pending_ = true; - } else if (HasPendingSwap()) { - // If we're off-screen, no need to trigger and wait for compositing. - // Just send the swap-buffers ACK to the plugin immediately. - commit_pending_ = false; - SwapBuffersACK(PP_OK); - } -} - -void PPB_Graphics3D_Impl::OnContextLost() { - if (bound_to_instance_) - instance()->BindGraphics(instance()->pp_instance(), 0); - - // Send context lost to plugin. This may have been caused by a PPAPI call, so - // avoid re-entering. - MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( - this, &PPB_Graphics3D_Impl::SendContextLost)); -} - -void PPB_Graphics3D_Impl::SendContextLost() { - // By the time we run this, the instance may have been deleted, or in the - // process of being deleted. Even in the latter case, we don't want to send a - // callback after DidDestroy. - if (!instance() || !instance()->container()) - return; - - const PPP_Graphics3D_Dev* ppp_graphics_3d = - static_cast<const PPP_Graphics3D_Dev*>( - instance()->module()->GetPluginInterface( - PPP_GRAPHICS_3D_DEV_INTERFACE)); - if (ppp_graphics_3d) - ppp_graphics_3d->Graphics3DContextLost(instance()->pp_instance()); + // TODO(alokp): Implement me. + return false; } } // namespace ppapi diff --git a/webkit/plugins/ppapi/ppb_graphics_3d_impl.h b/webkit/plugins/ppapi/ppb_graphics_3d_impl.h index 60888f2..8b41297 100644 --- a/webkit/plugins/ppapi/ppb_graphics_3d_impl.h +++ b/webkit/plugins/ppapi/ppb_graphics_3d_impl.h @@ -1,20 +1,18 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef WEBKIT_PLUGINS_PPAPI_PPB_GRAPHICS_3D_IMPL_H_ #define WEBKIT_PLUGINS_PPAPI_PPB_GRAPHICS_3D_IMPL_H_ -#include "base/memory/scoped_callback_factory.h" -#include "ppapi/shared_impl/graphics_3d_impl.h" -#include "webkit/plugins/ppapi/plugin_delegate.h" +#include "ppapi/thunk/ppb_graphics_3d_api.h" #include "webkit/plugins/ppapi/resource.h" namespace webkit { namespace ppapi { class PPB_Graphics3D_Impl : public Resource, - public ::ppapi::Graphics3DImpl { + public ::ppapi::thunk::PPB_Graphics3D_API { public: virtual ~PPB_Graphics3D_Impl(); @@ -22,47 +20,14 @@ class PPB_Graphics3D_Impl : public Resource, PP_Config3D_Dev config, PP_Resource share_context, const int32_t* attrib_list); - static PP_Resource CreateRaw(PluginInstance* instance, - PP_Config3D_Dev config, - PP_Resource share_context, - const int32_t* attrib_list); // ResourceObjectBase override. virtual ::ppapi::thunk::PPB_Graphics3D_API* AsPPB_Graphics3D_API() OVERRIDE; - // PPB_Graphics3D_API trusted implementation. - virtual PP_Bool InitCommandBuffer(int32_t size) OVERRIDE; - virtual PP_Bool GetRingBuffer(int* shm_handle, - uint32_t* shm_size) OVERRIDE; - virtual PP_Graphics3DTrustedState GetState() OVERRIDE; - virtual int32_t CreateTransferBuffer(uint32_t size) OVERRIDE; - virtual PP_Bool DestroyTransferBuffer(int32_t id) OVERRIDE; - virtual PP_Bool GetTransferBuffer(int32_t id, - int* shm_handle, - uint32_t* shm_size) OVERRIDE; - virtual PP_Bool Flush(int32_t put_offset) OVERRIDE; - virtual PP_Graphics3DTrustedState FlushSync(int32_t put_offset) OVERRIDE; - virtual PP_Graphics3DTrustedState FlushSyncFast( - int32_t put_offset, - int32_t last_known_get) OVERRIDE; - - // Binds/unbinds the graphics of this context with the associated instance. - // Returns true if binding/unbinding is successful. - bool BindToInstance(bool bind); - - // Returns the id of texture that can be used by the compositor. - unsigned int GetBackingTextureId(); - - // Notifications that the view has rendered the page and that it has been - // flushed to the screen. These messages are used to send Flush callbacks to - // the plugin. - void ViewInitiatedPaint(); - void ViewFlushedPaint(); - - protected: - // ppapi::Graphics3DImpl overrides. - virtual gpu::CommandBuffer* GetCommandBuffer() OVERRIDE; - virtual int32 DoSwapBuffers() OVERRIDE; + // PPB_Graphics3D_API implementation. + virtual int32_t GetAttribs(int32_t* attrib_list) OVERRIDE; + virtual int32_t SetAttribs(int32_t* attrib_list) OVERRIDE; + virtual int32_t SwapBuffers(PP_CompletionCallback callback) OVERRIDE; private: explicit PPB_Graphics3D_Impl(PluginInstance* instance); @@ -70,23 +35,6 @@ class PPB_Graphics3D_Impl : public Resource, bool Init(PP_Config3D_Dev config, PP_Resource share_context, const int32_t* attrib_list); - bool InitRaw(PP_Config3D_Dev config, - PP_Resource share_context, - const int32_t* attrib_list); - - // Notifications received from the GPU process. - void OnSwapBuffers(); - void OnContextLost(); - // Notifications sent to plugin. - void SendContextLost(); - - // True if context is bound to instance. - bool bound_to_instance_; - // True when waiting for compositor to commit our backing texture. - bool commit_pending_; - // PluginDelegate's 3D Context. Responsible for providing the command buffer. - scoped_ptr<PluginDelegate::PlatformContext3D> platform_context_; - base::ScopedCallbackFactory<PPB_Graphics3D_Impl> callback_factory_; DISALLOW_COPY_AND_ASSIGN(PPB_Graphics3D_Impl); }; @@ -95,3 +43,4 @@ class PPB_Graphics3D_Impl : public Resource, } // namespace webkit #endif // WEBKIT_PLUGINS_PPAPI_PPB_GRAPHICS_3D_IMPL_H_ + diff --git a/webkit/plugins/ppapi/resource_creation_impl.cc b/webkit/plugins/ppapi/resource_creation_impl.cc index e79195d..37c096a 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.cc +++ b/webkit/plugins/ppapi/resource_creation_impl.cc @@ -182,15 +182,6 @@ PP_Resource ResourceCreationImpl::CreateGraphics3D( attrib_list); } -PP_Resource ResourceCreationImpl::CreateGraphics3DRaw( - PP_Instance instance, - PP_Config3D_Dev config, - PP_Resource share_context, - const int32_t* attrib_list) { - return PPB_Graphics3D_Impl::CreateRaw(instance_, config, share_context, - attrib_list); -} - PP_Resource ResourceCreationImpl::CreateImageData(PP_Instance pp_instance, PP_ImageDataFormat format, const PP_Size& size, diff --git a/webkit/plugins/ppapi/resource_creation_impl.h b/webkit/plugins/ppapi/resource_creation_impl.h index 68a88a1..6421b80 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.h +++ b/webkit/plugins/ppapi/resource_creation_impl.h @@ -67,10 +67,6 @@ class ResourceCreationImpl : public ::ppapi::FunctionGroupBase, PP_Config3D_Dev config, PP_Resource share_context, const int32_t* attrib_list) OVERRIDE; - virtual PP_Resource CreateGraphics3DRaw(PP_Instance instance, - PP_Config3D_Dev config, - PP_Resource share_context, - const int32_t* attrib_list) OVERRIDE; virtual PP_Resource CreateImageData(PP_Instance instance, PP_ImageDataFormat format, const PP_Size& size, |