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 false; |
| 54 } |
| 55 |
| 56 void AsyncTransferStateStub::BindTransfer(AsyncTexImage2DParams* out_params) { |
| 57 DCHECK(out_params); |
| 58 DCHECK(needs_late_bind_); |
| 59 *out_params = late_bind_define_params_; |
| 60 needs_late_bind_ = false; |
| 61 } |
| 62 |
| 63 AsyncPixelTransferDelegateStub::AsyncPixelTransferDelegateStub() { |
| 64 } |
| 65 |
| 66 AsyncPixelTransferDelegateStub::~AsyncPixelTransferDelegateStub() { |
| 67 } |
| 68 |
| 69 AsyncPixelTransferState* |
| 70 AsyncPixelTransferDelegateStub::CreateRawPixelTransferState( |
| 71 GLuint texture_id) { |
| 72 return static_cast<AsyncPixelTransferState*>( |
| 73 new AsyncTransferStateStub(texture_id)); |
| 74 } |
| 75 |
| 76 void AsyncPixelTransferDelegateStub::AsyncNotifyCompletion( |
| 77 const base::Closure& task) { |
| 78 task.Run(); |
| 79 } |
| 80 |
| 81 void AsyncPixelTransferDelegateStub::AsyncTexImage2D( |
| 82 AsyncPixelTransferState* transfer_state, |
| 83 const AsyncTexImage2DParams& tex_params, |
| 84 const AsyncMemoryParams& mem_params) { |
| 85 // Save the define params to return later during deferred |
| 86 // binding of the transfer texture. |
| 87 DCHECK(transfer_state); |
| 88 AsyncTransferStateStub* state = |
| 89 static_cast<AsyncTransferStateStub*>(transfer_state); |
| 90 // We don't actually need a late bind since this stub does |
| 91 // everything synchronously, but this tries to be similar |
| 92 // as an async implementation. |
| 93 state->needs_late_bind_ = true; |
| 94 state->late_bind_define_params_ = tex_params; |
| 95 void* data = GetAddress(mem_params.shared_memory, |
| 96 mem_params.shm_size, |
| 97 mem_params.shm_data_offset, |
| 98 mem_params.shm_data_size); |
| 99 glTexImage2D( |
| 100 tex_params.target, |
| 101 tex_params.level, |
| 102 tex_params.internal_format, |
| 103 tex_params.width, |
| 104 tex_params.height, |
| 105 tex_params.border, |
| 106 tex_params.format, |
| 107 tex_params.type, |
| 108 data); |
| 109 } |
| 110 |
| 111 void AsyncPixelTransferDelegateStub::AsyncTexSubImage2D( |
| 112 AsyncPixelTransferState* transfer_state, |
| 113 const AsyncTexSubImage2DParams& tex_params, |
| 114 const AsyncMemoryParams& mem_params) { |
| 115 void* data = GetAddress(mem_params.shared_memory, |
| 116 mem_params.shm_size, |
| 117 mem_params.shm_data_offset, |
| 118 mem_params.shm_data_size); |
| 119 DCHECK(transfer_state); |
| 120 AsyncTransferStateStub* state = |
| 121 static_cast<AsyncTransferStateStub*>(transfer_state); |
| 122 DCHECK(!state->needs_late_bind_); |
| 123 glTexSubImage2D( |
| 124 tex_params.target, |
| 125 tex_params.level, |
| 126 tex_params.xoffset, |
| 127 tex_params.yoffset, |
| 128 tex_params.width, |
| 129 tex_params.height, |
| 130 tex_params.format, |
| 131 tex_params.type, |
| 132 data); |
| 133 } |
| 134 } // namespace gfx |
| 135 |
OLD | NEW |