diff options
author | alokp@chromium.org <alokp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-18 20:58:20 +0000 |
---|---|---|
committer | alokp@chromium.org <alokp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-18 20:58:20 +0000 |
commit | 914f41855d381b3777142609e2d94ef83b1339ad (patch) | |
tree | 56c1d6601b795869683a4fc3291caa8e79ea2525 /ppapi/shared_impl | |
parent | d3b0574f1e2baf8cd09967499b9ab55ec713e188 (diff) | |
download | chromium_src-914f41855d381b3777142609e2d94ef83b1339ad.zip chromium_src-914f41855d381b3777142609e2d94ef83b1339ad.tar.gz chromium_src-914f41855d381b3777142609e2d94ef83b1339ad.tar.bz2 |
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
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92885 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/shared_impl')
-rw-r--r-- | ppapi/shared_impl/DEPS | 1 | ||||
-rw-r--r-- | ppapi/shared_impl/graphics_3d_impl.cc | 104 | ||||
-rw-r--r-- | ppapi/shared_impl/graphics_3d_impl.h | 63 |
3 files changed, 168 insertions, 0 deletions
diff --git a/ppapi/shared_impl/DEPS b/ppapi/shared_impl/DEPS index 512b07b..013d2acf 100644 --- a/ppapi/shared_impl/DEPS +++ b/ppapi/shared_impl/DEPS @@ -1,5 +1,6 @@ include_rules = [ "+base", + "+gpu", "+skia", "+webkit/glue", diff --git a/ppapi/shared_impl/graphics_3d_impl.cc b/ppapi/shared_impl/graphics_3d_impl.cc new file mode 100644 index 0000000..e7f5c70 --- /dev/null +++ b/ppapi/shared_impl/graphics_3d_impl.cc @@ -0,0 +1,104 @@ +// Copyright (c) 2011 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 "ppapi/shared_impl/graphics_3d_impl.h" + +#include "gpu/command_buffer/client/gles2_cmd_helper.h" +#include "gpu/command_buffer/client/gles2_implementation.h" +#include "ppapi/c/pp_errors.h" + +namespace ppapi { + +Graphics3DImpl::Graphics3DImpl() + : transfer_buffer_id_(-1), + swap_callback_(PP_BlockUntilComplete()) { +} + +Graphics3DImpl::~Graphics3DImpl() { + // Make sure that GLES2 implementation has already been destroyed. + DCHECK_EQ(transfer_buffer_id_, -1); + DCHECK(!gles2_helper_.get()); + DCHECK(!gles2_impl_.get()); +} + +int32_t Graphics3DImpl::GetAttribs(int32_t* attrib_list) { + // TODO(alokp): Implement me. + return PP_ERROR_FAILED; +} + +int32_t Graphics3DImpl::SetAttribs(int32_t* attrib_list) { + // TODO(alokp): Implement me. + return PP_ERROR_FAILED; +} + +int32_t Graphics3DImpl::SwapBuffers(PP_CompletionCallback callback) { + if (!callback.func) { + // Blocking SwapBuffers isn't supported (since we have to be on the main + // thread). + return PP_ERROR_BADARGUMENT; + } + + if (HasPendingSwap()) { + // Already a pending SwapBuffers that hasn't returned yet. + return PP_ERROR_INPROGRESS; + } + + swap_callback_ = callback; + return DoSwapBuffers(); +} + +void Graphics3DImpl::SwapBuffersACK(int32_t pp_error) { + DCHECK(HasPendingSwap()); + PP_RunAndClearCompletionCallback(&swap_callback_, pp_error); +} + +bool Graphics3DImpl::CreateGLES2Impl(int32 command_buffer_size, + int32 transfer_buffer_size) { + gpu::CommandBuffer* command_buffer = GetCommandBuffer(); + DCHECK(command_buffer); + + // Create the GLES2 helper, which writes the command buffer protocol. + gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer)); + if (!gles2_helper_->Initialize(command_buffer_size)) + return false; + + // Create a transfer buffer used to copy resources between the renderer + // process and the GPU process. + transfer_buffer_id_ = + command_buffer->CreateTransferBuffer(transfer_buffer_size, -1); + if (transfer_buffer_id_ < 0) + return false; + + // Map the buffer into the renderer process's address space. + gpu::Buffer transfer_buffer = + command_buffer->GetTransferBuffer(transfer_buffer_id_); + if (!transfer_buffer.ptr) + return false; + + // Create the object exposing the OpenGL API. + gles2_impl_.reset(new gpu::gles2::GLES2Implementation( + gles2_helper_.get(), + transfer_buffer.size, + transfer_buffer.ptr, + transfer_buffer_id_, + false)); + + return true; +} + +void Graphics3DImpl::DestroyGLES2Impl() { + gles2_impl_.reset(); + + if (transfer_buffer_id_ != -1) { + gpu::CommandBuffer* command_buffer = GetCommandBuffer(); + DCHECK(command_buffer); + command_buffer->DestroyTransferBuffer(transfer_buffer_id_); + transfer_buffer_id_ = -1; + } + + gles2_helper_.reset(); +} + +} // namespace ppapi + diff --git a/ppapi/shared_impl/graphics_3d_impl.h b/ppapi/shared_impl/graphics_3d_impl.h new file mode 100644 index 0000000..41a71af --- /dev/null +++ b/ppapi/shared_impl/graphics_3d_impl.h @@ -0,0 +1,63 @@ +// Copyright (c) 2011 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 PPAPI_SHARED_IMPL_GRAPHICS_3D_IMPL_H_ +#define PPAPI_SHARED_IMPL_GRAPHICS_3D_IMPL_H_ + +#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/thunk/ppb_graphics_3d_api.h" + +namespace gpu { +class CommandBuffer; +namespace gles2 { +class GLES2CmdHelper; +class GLES2Implementation; +} // namespace gles2 +} // namespace gpu. + +namespace ppapi { + +class Graphics3DImpl : public thunk::PPB_Graphics3D_API { + public: + // 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; + + gpu::gles2::GLES2Implementation* gles2_impl() { + return gles2_impl_.get(); + } + + // Sends swap-buffers notification to the plugin. + void SwapBuffersACK(int32_t pp_error); + + protected: + Graphics3DImpl(); + virtual ~Graphics3DImpl(); + + virtual gpu::CommandBuffer* GetCommandBuffer() = 0; + virtual int32 DoSwapBuffers() = 0; + + bool HasPendingSwap() { return swap_callback_.func != NULL; } + bool CreateGLES2Impl(int32 command_buffer_size, + int32 transfer_buffer_size); + void DestroyGLES2Impl(); + + private: + int32 transfer_buffer_id_; + scoped_ptr<gpu::gles2::GLES2CmdHelper> gles2_helper_; + scoped_ptr<gpu::gles2::GLES2Implementation> gles2_impl_; + + // Callback that needs to be executed when swap-buffers is completed. + PP_CompletionCallback swap_callback_; + + DISALLOW_COPY_AND_ASSIGN(Graphics3DImpl); +}; + +} // namespace ppapi + +#endif // PPAPI_SHARED_IMPL_GRAPHICS_3D_IMPL_H_ + |