OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ppapi/shared_impl/graphics_3d_impl.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
| 9 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 10 #include "ppapi/c/pp_errors.h" |
| 11 |
| 12 namespace ppapi { |
| 13 |
| 14 Graphics3DImpl::Graphics3DImpl() |
| 15 : transfer_buffer_id_(-1), |
| 16 swap_callback_(PP_BlockUntilComplete()) { |
| 17 } |
| 18 |
| 19 Graphics3DImpl::~Graphics3DImpl() { |
| 20 // Make sure that GLES2 implementation has already been destroyed. |
| 21 DCHECK_EQ(transfer_buffer_id_, -1); |
| 22 DCHECK(!gles2_helper_.get()); |
| 23 DCHECK(!gles2_impl_.get()); |
| 24 } |
| 25 |
| 26 int32_t Graphics3DImpl::GetAttribs(int32_t* attrib_list) { |
| 27 // TODO(alokp): Implement me. |
| 28 return PP_ERROR_FAILED; |
| 29 } |
| 30 |
| 31 int32_t Graphics3DImpl::SetAttribs(int32_t* attrib_list) { |
| 32 // TODO(alokp): Implement me. |
| 33 return PP_ERROR_FAILED; |
| 34 } |
| 35 |
| 36 int32_t Graphics3DImpl::SwapBuffers(PP_CompletionCallback callback) { |
| 37 if (!callback.func) { |
| 38 // Blocking SwapBuffers isn't supported (since we have to be on the main |
| 39 // thread). |
| 40 return PP_ERROR_BADARGUMENT; |
| 41 } |
| 42 |
| 43 if (HasPendingSwap()) { |
| 44 // Already a pending SwapBuffers that hasn't returned yet. |
| 45 return PP_ERROR_INPROGRESS; |
| 46 } |
| 47 |
| 48 swap_callback_ = callback; |
| 49 return DoSwapBuffers(); |
| 50 } |
| 51 |
| 52 void Graphics3DImpl::SwapBuffersACK(int32_t pp_error) { |
| 53 DCHECK(HasPendingSwap()); |
| 54 PP_RunAndClearCompletionCallback(&swap_callback_, pp_error); |
| 55 } |
| 56 |
| 57 bool Graphics3DImpl::CreateGLES2Impl(int32 command_buffer_size, |
| 58 int32 transfer_buffer_size) { |
| 59 gpu::CommandBuffer* command_buffer = GetCommandBuffer(); |
| 60 DCHECK(command_buffer); |
| 61 |
| 62 // Create the GLES2 helper, which writes the command buffer protocol. |
| 63 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer)); |
| 64 if (!gles2_helper_->Initialize(command_buffer_size)) |
| 65 return false; |
| 66 |
| 67 // Create a transfer buffer used to copy resources between the renderer |
| 68 // process and the GPU process. |
| 69 transfer_buffer_id_ = |
| 70 command_buffer->CreateTransferBuffer(transfer_buffer_size, -1); |
| 71 if (transfer_buffer_id_ < 0) |
| 72 return false; |
| 73 |
| 74 // Map the buffer into the renderer process's address space. |
| 75 gpu::Buffer transfer_buffer = |
| 76 command_buffer->GetTransferBuffer(transfer_buffer_id_); |
| 77 if (!transfer_buffer.ptr) |
| 78 return false; |
| 79 |
| 80 // Create the object exposing the OpenGL API. |
| 81 gles2_impl_.reset(new gpu::gles2::GLES2Implementation( |
| 82 gles2_helper_.get(), |
| 83 transfer_buffer.size, |
| 84 transfer_buffer.ptr, |
| 85 transfer_buffer_id_, |
| 86 false)); |
| 87 |
| 88 return true; |
| 89 } |
| 90 |
| 91 void Graphics3DImpl::DestroyGLES2Impl() { |
| 92 gles2_impl_.reset(); |
| 93 |
| 94 if (transfer_buffer_id_ != -1) { |
| 95 gpu::CommandBuffer* command_buffer = GetCommandBuffer(); |
| 96 DCHECK(command_buffer); |
| 97 command_buffer->DestroyTransferBuffer(transfer_buffer_id_); |
| 98 transfer_buffer_id_ = -1; |
| 99 } |
| 100 |
| 101 gles2_helper_.reset(); |
| 102 } |
| 103 |
| 104 } // namespace ppapi |
| 105 |
OLD | NEW |