OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 "ui/gl/async_pixel_transfer_delegate_stub.h" |
| 6 |
| 7 #include "base/shared_memory.h" |
| 8 #include "build/build_config.h" |
| 9 #include "ui/gl/gl_bindings.h" |
| 10 |
| 11 using base::SharedMemory; |
| 12 using base::SharedMemoryHandle; |
| 13 |
| 14 namespace { |
| 15 // Gets the address of the data from shared memory. |
| 16 void* GetAddress(SharedMemory* shared_memory, |
| 17 uint32 shm_size, |
| 18 uint32 shm_data_offset, |
| 19 uint32 shm_data_size) { |
| 20 // Memory bounds have already been validated, so there |
| 21 // is just DCHECKS here. |
| 22 DCHECK(shared_memory); |
| 23 DCHECK(shared_memory->memory()); |
| 24 DCHECK_LE(shm_data_offset + shm_data_size, shm_size); |
| 25 return static_cast<int8*>(shared_memory->memory()) + shm_data_offset; |
| 26 } |
| 27 } // namespace |
| 28 |
| 29 namespace gfx { |
| 30 |
| 31 scoped_ptr<AsyncPixelTransferDelegate> |
| 32 AsyncPixelTransferDelegate::Create(gfx::GLContext* context) { |
| 33 return AsyncPixelTransferDelegateStub::Create(context); |
| 34 } |
| 35 |
| 36 scoped_ptr<AsyncPixelTransferDelegate> |
| 37 AsyncPixelTransferDelegateStub::Create(gfx::GLContext* context) { |
| 38 return make_scoped_ptr( |
| 39 static_cast<AsyncPixelTransferDelegate*>( |
| 40 new AsyncPixelTransferDelegateStub())); |
| 41 } |
| 42 |
| 43 AsyncTransferStateStub::AsyncTransferStateStub(GLuint texture_id) { |
| 44 static const AsyncTexImage2DParams zero_params = {0, 0, 0, 0, 0, 0, 0, 0}; |
| 45 late_bind_define_params_ = zero_params; |
| 46 needs_late_bind_ = false; |
| 47 } |
| 48 |
| 49 AsyncTransferStateStub::~AsyncTransferStateStub() { |
| 50 } |
| 51 |
| 52 bool AsyncTransferStateStub::TransferIsInProgress() { |
| 53 return needs_late_bind_; |
| 54 } |
| 55 |
| 56 bool AsyncTransferStateStub::BindTransfer( |
| 57 GLenum target, AsyncTexImage2DParams* bound_params) { |
| 58 DCHECK(bound_params); |
| 59 if (needs_late_bind_) { |
| 60 *bound_params = late_bind_define_params_; |
| 61 needs_late_bind_ = false; |
| 62 return true; |
| 63 } |
| 64 return false; |
| 65 } |
| 66 |
| 67 AsyncPixelTransferDelegateStub::AsyncPixelTransferDelegateStub() { |
| 68 } |
| 69 |
| 70 AsyncPixelTransferDelegateStub::~AsyncPixelTransferDelegateStub() { |
| 71 } |
| 72 |
| 73 scoped_refptr<AsyncPixelTransferState> |
| 74 AsyncPixelTransferDelegateStub::CreatePixelTransferState( |
| 75 GLuint texture_id) { |
| 76 return make_scoped_refptr( |
| 77 static_cast<AsyncPixelTransferState*>( |
| 78 new AsyncTransferStateStub(texture_id))); |
| 79 } |
| 80 |
| 81 void AsyncPixelTransferDelegateStub::AsyncNotifyCompletion( |
| 82 const base::Closure& task) { |
| 83 task.Run(); |
| 84 } |
| 85 |
| 86 void AsyncPixelTransferDelegateStub::AsyncTexImage2D( |
| 87 AsyncPixelTransferState* transfer_state, |
| 88 const AsyncTexImage2DParams& tex_params, |
| 89 const AsyncMemoryParams& mem_params) { |
| 90 // Save the define params to return later during deferred |
| 91 // binding of the transfer texture. |
| 92 DCHECK(transfer_state); |
| 93 AsyncTransferStateStub* state = |
| 94 static_cast<AsyncTransferStateStub*>(transfer_state); |
| 95 state->needs_late_bind_ = true; |
| 96 state->late_bind_define_params_ = tex_params; |
| 97 void* data = GetAddress(mem_params.shared_memory, |
| 98 mem_params.shm_size, |
| 99 mem_params.shm_data_offset, |
| 100 mem_params.shm_data_size); |
| 101 glTexImage2D( |
| 102 tex_params.target, |
| 103 tex_params.level, |
| 104 tex_params.internal_format, |
| 105 tex_params.width, |
| 106 tex_params.height, |
| 107 tex_params.border, |
| 108 tex_params.format, |
| 109 tex_params.type, |
| 110 data); |
| 111 } |
| 112 |
| 113 void AsyncPixelTransferDelegateStub::AsyncTexSubImage2D( |
| 114 AsyncPixelTransferState* transfer_state, |
| 115 const AsyncTexSubImage2DParams& tex_params, |
| 116 const AsyncMemoryParams& mem_params) { |
| 117 void* data = GetAddress(mem_params.shared_memory, |
| 118 mem_params.shm_size, |
| 119 mem_params.shm_data_offset, |
| 120 mem_params.shm_data_size); |
| 121 DCHECK(transfer_state); |
| 122 AsyncTransferStateStub* state = |
| 123 static_cast<AsyncTransferStateStub*>(transfer_state); |
| 124 DCHECK(!state->needs_late_bind_); |
| 125 glTexSubImage2D( |
| 126 tex_params.target, |
| 127 tex_params.level, |
| 128 tex_params.xoffset, |
| 129 tex_params.yoffset, |
| 130 tex_params.width, |
| 131 tex_params.height, |
| 132 tex_params.format, |
| 133 tex_params.type, |
| 134 data); |
| 135 } |
| 136 } // namespace gfx |
| 137 |
OLD | NEW |