| 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::GetError() { | |
| 37 // TODO(alokp): Implement me. | |
| 38 return PP_ERROR_FAILED; | |
| 39 } | |
| 40 | |
| 41 int32_t Graphics3DImpl::ResizeBuffers(int32_t width, int32_t height) { | |
| 42 if ((width < 0) || (height < 0)) | |
| 43 return PP_ERROR_BADARGUMENT; | |
| 44 | |
| 45 gles2_impl()->ResizeCHROMIUM(width, height); | |
| 46 // TODO(alokp): Check if resize succeeded and return appropriate error code. | |
| 47 return PP_OK; | |
| 48 } | |
| 49 | |
| 50 int32_t Graphics3DImpl::SwapBuffers(PP_CompletionCallback callback) { | |
| 51 if (!callback.func) { | |
| 52 // Blocking SwapBuffers isn't supported (since we have to be on the main | |
| 53 // thread). | |
| 54 return PP_ERROR_BADARGUMENT; | |
| 55 } | |
| 56 | |
| 57 if (HasPendingSwap()) { | |
| 58 // Already a pending SwapBuffers that hasn't returned yet. | |
| 59 return PP_ERROR_INPROGRESS; | |
| 60 } | |
| 61 | |
| 62 swap_callback_ = callback; | |
| 63 return DoSwapBuffers(); | |
| 64 } | |
| 65 | |
| 66 void* Graphics3DImpl::MapTexSubImage2DCHROMIUM(GLenum target, | |
| 67 GLint level, | |
| 68 GLint xoffset, | |
| 69 GLint yoffset, | |
| 70 GLsizei width, | |
| 71 GLsizei height, | |
| 72 GLenum format, | |
| 73 GLenum type, | |
| 74 GLenum access) { | |
| 75 return gles2_impl_->MapTexSubImage2DCHROMIUM( | |
| 76 target, level, xoffset, yoffset, width, height, format, type, access); | |
| 77 } | |
| 78 | |
| 79 void Graphics3DImpl::UnmapTexSubImage2DCHROMIUM(const void* mem) { | |
| 80 gles2_impl_->UnmapTexSubImage2DCHROMIUM(mem); | |
| 81 } | |
| 82 | |
| 83 void Graphics3DImpl::SwapBuffersACK(int32_t pp_error) { | |
| 84 DCHECK(HasPendingSwap()); | |
| 85 PP_RunAndClearCompletionCallback(&swap_callback_, pp_error); | |
| 86 } | |
| 87 | |
| 88 bool Graphics3DImpl::CreateGLES2Impl(int32 command_buffer_size, | |
| 89 int32 transfer_buffer_size) { | |
| 90 gpu::CommandBuffer* command_buffer = GetCommandBuffer(); | |
| 91 DCHECK(command_buffer); | |
| 92 | |
| 93 // Create the GLES2 helper, which writes the command buffer protocol. | |
| 94 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer)); | |
| 95 if (!gles2_helper_->Initialize(command_buffer_size)) | |
| 96 return false; | |
| 97 | |
| 98 // Create a transfer buffer used to copy resources between the renderer | |
| 99 // process and the GPU process. | |
| 100 transfer_buffer_id_ = | |
| 101 command_buffer->CreateTransferBuffer(transfer_buffer_size, -1); | |
| 102 if (transfer_buffer_id_ < 0) | |
| 103 return false; | |
| 104 | |
| 105 // Map the buffer into the renderer process's address space. | |
| 106 gpu::Buffer transfer_buffer = | |
| 107 command_buffer->GetTransferBuffer(transfer_buffer_id_); | |
| 108 if (!transfer_buffer.ptr) | |
| 109 return false; | |
| 110 | |
| 111 // Create the object exposing the OpenGL API. | |
| 112 gles2_impl_.reset(new gpu::gles2::GLES2Implementation( | |
| 113 gles2_helper_.get(), | |
| 114 transfer_buffer.size, | |
| 115 transfer_buffer.ptr, | |
| 116 transfer_buffer_id_, | |
| 117 false, | |
| 118 true)); | |
| 119 | |
| 120 return true; | |
| 121 } | |
| 122 | |
| 123 void Graphics3DImpl::DestroyGLES2Impl() { | |
| 124 gles2_impl_.reset(); | |
| 125 | |
| 126 if (transfer_buffer_id_ != -1) { | |
| 127 gpu::CommandBuffer* command_buffer = GetCommandBuffer(); | |
| 128 DCHECK(command_buffer); | |
| 129 command_buffer->DestroyTransferBuffer(transfer_buffer_id_); | |
| 130 transfer_buffer_id_ = -1; | |
| 131 } | |
| 132 | |
| 133 gles2_helper_.reset(); | |
| 134 } | |
| 135 | |
| 136 } // namespace ppapi | |
| 137 | |
| OLD | NEW |