| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ppapi/shared_impl/graphics_3d_impl.h" | 5 #include "ppapi/shared_impl/ppb_graphics_3d_shared.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 8 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
| 9 #include "gpu/command_buffer/client/gles2_implementation.h" | 9 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
| 11 | 11 |
| 12 namespace ppapi { | 12 namespace ppapi { |
| 13 | 13 |
| 14 Graphics3DImpl::Graphics3DImpl() | 14 PPB_Graphics3D_Shared::PPB_Graphics3D_Shared() |
| 15 : transfer_buffer_id_(-1), | 15 : transfer_buffer_id_(-1), |
| 16 swap_callback_(PP_BlockUntilComplete()) { | 16 swap_callback_(PP_BlockUntilComplete()) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 Graphics3DImpl::~Graphics3DImpl() { | 19 PPB_Graphics3D_Shared::~PPB_Graphics3D_Shared() { |
| 20 // Make sure that GLES2 implementation has already been destroyed. | 20 // Make sure that GLES2 implementation has already been destroyed. |
| 21 DCHECK_EQ(transfer_buffer_id_, -1); | 21 DCHECK_EQ(transfer_buffer_id_, -1); |
| 22 DCHECK(!gles2_helper_.get()); | 22 DCHECK(!gles2_helper_.get()); |
| 23 DCHECK(!gles2_impl_.get()); | 23 DCHECK(!gles2_impl_.get()); |
| 24 } | 24 } |
| 25 | 25 |
| 26 int32_t Graphics3DImpl::GetAttribs(int32_t* attrib_list) { | 26 int32_t PPB_Graphics3D_Shared::GetAttribs(int32_t* attrib_list) { |
| 27 // TODO(alokp): Implement me. | 27 // TODO(alokp): Implement me. |
| 28 return PP_ERROR_FAILED; | 28 return PP_ERROR_FAILED; |
| 29 } | 29 } |
| 30 | 30 |
| 31 int32_t Graphics3DImpl::SetAttribs(int32_t* attrib_list) { | 31 int32_t PPB_Graphics3D_Shared::SetAttribs(int32_t* attrib_list) { |
| 32 // TODO(alokp): Implement me. | 32 // TODO(alokp): Implement me. |
| 33 return PP_ERROR_FAILED; | 33 return PP_ERROR_FAILED; |
| 34 } | 34 } |
| 35 | 35 |
| 36 int32_t Graphics3DImpl::GetError() { | 36 int32_t PPB_Graphics3D_Shared::GetError() { |
| 37 // TODO(alokp): Implement me. | 37 // TODO(alokp): Implement me. |
| 38 return PP_ERROR_FAILED; | 38 return PP_ERROR_FAILED; |
| 39 } | 39 } |
| 40 | 40 |
| 41 int32_t Graphics3DImpl::ResizeBuffers(int32_t width, int32_t height) { | 41 int32_t PPB_Graphics3D_Shared::ResizeBuffers(int32_t width, int32_t height) { |
| 42 if ((width < 0) || (height < 0)) | 42 if ((width < 0) || (height < 0)) |
| 43 return PP_ERROR_BADARGUMENT; | 43 return PP_ERROR_BADARGUMENT; |
| 44 | 44 |
| 45 gles2_impl()->ResizeCHROMIUM(width, height); | 45 gles2_impl()->ResizeCHROMIUM(width, height); |
| 46 // TODO(alokp): Check if resize succeeded and return appropriate error code. | 46 // TODO(alokp): Check if resize succeeded and return appropriate error code. |
| 47 return PP_OK; | 47 return PP_OK; |
| 48 } | 48 } |
| 49 | 49 |
| 50 int32_t Graphics3DImpl::SwapBuffers(PP_CompletionCallback callback) { | 50 int32_t PPB_Graphics3D_Shared::SwapBuffers(PP_CompletionCallback callback) { |
| 51 if (!callback.func) { | 51 if (!callback.func) { |
| 52 // Blocking SwapBuffers isn't supported (since we have to be on the main | 52 // Blocking SwapBuffers isn't supported (since we have to be on the main |
| 53 // thread). | 53 // thread). |
| 54 return PP_ERROR_BADARGUMENT; | 54 return PP_ERROR_BADARGUMENT; |
| 55 } | 55 } |
| 56 | 56 |
| 57 if (HasPendingSwap()) { | 57 if (HasPendingSwap()) { |
| 58 // Already a pending SwapBuffers that hasn't returned yet. | 58 // Already a pending SwapBuffers that hasn't returned yet. |
| 59 return PP_ERROR_INPROGRESS; | 59 return PP_ERROR_INPROGRESS; |
| 60 } | 60 } |
| 61 | 61 |
| 62 swap_callback_ = callback; | 62 swap_callback_ = callback; |
| 63 return DoSwapBuffers(); | 63 return DoSwapBuffers(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void* Graphics3DImpl::MapTexSubImage2DCHROMIUM(GLenum target, | 66 void* PPB_Graphics3D_Shared::MapTexSubImage2DCHROMIUM(GLenum target, |
| 67 GLint level, | 67 GLint level, |
| 68 GLint xoffset, | 68 GLint xoffset, |
| 69 GLint yoffset, | 69 GLint yoffset, |
| 70 GLsizei width, | 70 GLsizei width, |
| 71 GLsizei height, | 71 GLsizei height, |
| 72 GLenum format, | 72 GLenum format, |
| 73 GLenum type, | 73 GLenum type, |
| 74 GLenum access) { | 74 GLenum access) { |
| 75 return gles2_impl_->MapTexSubImage2DCHROMIUM( | 75 return gles2_impl_->MapTexSubImage2DCHROMIUM( |
| 76 target, level, xoffset, yoffset, width, height, format, type, access); | 76 target, level, xoffset, yoffset, width, height, format, type, access); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void Graphics3DImpl::UnmapTexSubImage2DCHROMIUM(const void* mem) { | 79 void PPB_Graphics3D_Shared::UnmapTexSubImage2DCHROMIUM(const void* mem) { |
| 80 gles2_impl_->UnmapTexSubImage2DCHROMIUM(mem); | 80 gles2_impl_->UnmapTexSubImage2DCHROMIUM(mem); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void Graphics3DImpl::SwapBuffersACK(int32_t pp_error) { | 83 void PPB_Graphics3D_Shared::SwapBuffersACK(int32_t pp_error) { |
| 84 DCHECK(HasPendingSwap()); | 84 DCHECK(HasPendingSwap()); |
| 85 PP_RunAndClearCompletionCallback(&swap_callback_, pp_error); | 85 PP_RunAndClearCompletionCallback(&swap_callback_, pp_error); |
| 86 } | 86 } |
| 87 | 87 |
| 88 bool Graphics3DImpl::CreateGLES2Impl(int32 command_buffer_size, | 88 bool PPB_Graphics3D_Shared::CreateGLES2Impl(int32 command_buffer_size, |
| 89 int32 transfer_buffer_size) { | 89 int32 transfer_buffer_size) { |
| 90 gpu::CommandBuffer* command_buffer = GetCommandBuffer(); | 90 gpu::CommandBuffer* command_buffer = GetCommandBuffer(); |
| 91 DCHECK(command_buffer); | 91 DCHECK(command_buffer); |
| 92 | 92 |
| 93 // Create the GLES2 helper, which writes the command buffer protocol. | 93 // Create the GLES2 helper, which writes the command buffer protocol. |
| 94 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer)); | 94 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer)); |
| 95 if (!gles2_helper_->Initialize(command_buffer_size)) | 95 if (!gles2_helper_->Initialize(command_buffer_size)) |
| 96 return false; | 96 return false; |
| 97 | 97 |
| 98 // Create a transfer buffer used to copy resources between the renderer | 98 // Create a transfer buffer used to copy resources between the renderer |
| 99 // process and the GPU process. | 99 // process and the GPU process. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 113 gles2_helper_.get(), | 113 gles2_helper_.get(), |
| 114 transfer_buffer.size, | 114 transfer_buffer.size, |
| 115 transfer_buffer.ptr, | 115 transfer_buffer.ptr, |
| 116 transfer_buffer_id_, | 116 transfer_buffer_id_, |
| 117 false, | 117 false, |
| 118 true)); | 118 true)); |
| 119 | 119 |
| 120 return true; | 120 return true; |
| 121 } | 121 } |
| 122 | 122 |
| 123 void Graphics3DImpl::DestroyGLES2Impl() { | 123 void PPB_Graphics3D_Shared::DestroyGLES2Impl() { |
| 124 gles2_impl_.reset(); | 124 gles2_impl_.reset(); |
| 125 | 125 |
| 126 if (transfer_buffer_id_ != -1) { | 126 if (transfer_buffer_id_ != -1) { |
| 127 gpu::CommandBuffer* command_buffer = GetCommandBuffer(); | 127 gpu::CommandBuffer* command_buffer = GetCommandBuffer(); |
| 128 DCHECK(command_buffer); | 128 DCHECK(command_buffer); |
| 129 command_buffer->DestroyTransferBuffer(transfer_buffer_id_); | 129 command_buffer->DestroyTransferBuffer(transfer_buffer_id_); |
| 130 transfer_buffer_id_ = -1; | 130 transfer_buffer_id_ = -1; |
| 131 } | 131 } |
| 132 | 132 |
| 133 gles2_helper_.reset(); | 133 gles2_helper_.reset(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 } // namespace ppapi | 136 } // namespace ppapi |
| 137 | 137 |
| OLD | NEW |