| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "content/renderer/gpu/command_buffer_proxy.h" | 5 #include "content/renderer/gpu/command_buffer_proxy.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 DLOG(INFO) << "CONSOLE_MESSAGE: " | 94 DLOG(INFO) << "CONSOLE_MESSAGE: " |
| 95 << message.id << " : " << message.message; | 95 << message.id << " : " << message.message; |
| 96 } | 96 } |
| 97 | 97 |
| 98 void CommandBufferProxy::SetChannelErrorCallback( | 98 void CommandBufferProxy::SetChannelErrorCallback( |
| 99 const base::Closure& callback) { | 99 const base::Closure& callback) { |
| 100 channel_error_callback_ = callback; | 100 channel_error_callback_ = callback; |
| 101 } | 101 } |
| 102 | 102 |
| 103 bool CommandBufferProxy::Initialize() { | 103 bool CommandBufferProxy::Initialize() { |
| 104 ChildThread* child_thread = ChildThread::current(); | 104 if (!channel_->factory()->IsMainThread()) |
| 105 if (!child_thread) | |
| 106 return false; | 105 return false; |
| 107 | 106 |
| 108 bool result; | 107 bool result; |
| 109 if (!Send(new GpuCommandBufferMsg_Initialize(route_id_, &result))) { | 108 if (!Send(new GpuCommandBufferMsg_Initialize(route_id_, &result))) { |
| 110 LOG(ERROR) << "Could not send GpuCommandBufferMsg_Initialize."; | 109 LOG(ERROR) << "Could not send GpuCommandBufferMsg_Initialize."; |
| 111 return false; | 110 return false; |
| 112 } | 111 } |
| 113 | 112 |
| 114 if (!result) { | 113 if (!result) { |
| 115 LOG(ERROR) << "Failed to initialize command buffer service."; | 114 LOG(ERROR) << "Failed to initialize command buffer service."; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 171 |
| 173 void CommandBufferProxy::SetGetOffset(int32 get_offset) { | 172 void CommandBufferProxy::SetGetOffset(int32 get_offset) { |
| 174 // Not implemented in proxy. | 173 // Not implemented in proxy. |
| 175 NOTREACHED(); | 174 NOTREACHED(); |
| 176 } | 175 } |
| 177 | 176 |
| 178 int32 CommandBufferProxy::CreateTransferBuffer(size_t size, int32 id_request) { | 177 int32 CommandBufferProxy::CreateTransferBuffer(size_t size, int32 id_request) { |
| 179 if (last_state_.error != gpu::error::kNoError) | 178 if (last_state_.error != gpu::error::kNoError) |
| 180 return -1; | 179 return -1; |
| 181 | 180 |
| 182 ChildThread* child_thread = ChildThread::current(); | |
| 183 if (!child_thread) | |
| 184 return -1; | |
| 185 | |
| 186 base::SharedMemoryHandle handle; | |
| 187 if (!child_thread->Send(new ChildProcessHostMsg_SyncAllocateSharedMemory( | |
| 188 size, | |
| 189 &handle))) { | |
| 190 return -1; | |
| 191 } | |
| 192 | |
| 193 if (!base::SharedMemory::IsHandleValid(handle)) | |
| 194 return -1; | |
| 195 | |
| 196 // Handle is closed by the SharedMemory object below. This stops | |
| 197 // base::FileDescriptor from closing it as well. | |
| 198 #if defined(OS_POSIX) | |
| 199 handle.auto_close = false; | |
| 200 #endif | |
| 201 | |
| 202 // Take ownership of shared memory. This will close the handle if Send below | 181 // Take ownership of shared memory. This will close the handle if Send below |
| 203 // fails. Otherwise, callee takes ownership before this variable | 182 // fails. Otherwise, callee takes ownership before this variable |
| 204 // goes out of scope by duping the handle. | 183 // goes out of scope by duping the handle. |
| 205 base::SharedMemory shared_memory(handle, false); | 184 scoped_ptr<base::SharedMemory> shm( |
| 185 channel_->factory()->AllocateSharedMemory(size)); |
| 186 if (!shm.get()) |
| 187 return -1; |
| 188 |
| 189 base::SharedMemoryHandle handle = shm->handle(); |
| 190 #if defined(OS_POSIX) |
| 191 DCHECK(!handle.auto_close); |
| 192 #endif |
| 206 | 193 |
| 207 int32 id; | 194 int32 id; |
| 208 if (!Send(new GpuCommandBufferMsg_RegisterTransferBuffer(route_id_, | 195 if (!Send(new GpuCommandBufferMsg_RegisterTransferBuffer(route_id_, |
| 209 handle, | 196 handle, |
| 210 size, | 197 size, |
| 211 id_request, | 198 id_request, |
| 212 &id))) { | 199 &id))) { |
| 213 return -1; | 200 return -1; |
| 214 } | 201 } |
| 215 | 202 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 delete msg; | 404 delete msg; |
| 418 return false; | 405 return false; |
| 419 } | 406 } |
| 420 | 407 |
| 421 void CommandBufferProxy::OnUpdateState(const gpu::CommandBuffer::State& state) { | 408 void CommandBufferProxy::OnUpdateState(const gpu::CommandBuffer::State& state) { |
| 422 // Handle wraparound. It works as long as we don't have more than 2B state | 409 // Handle wraparound. It works as long as we don't have more than 2B state |
| 423 // updates in flight across which reordering occurs. | 410 // updates in flight across which reordering occurs. |
| 424 if (state.generation - last_state_.generation < 0x80000000U) | 411 if (state.generation - last_state_.generation < 0x80000000U) |
| 425 last_state_ = state; | 412 last_state_ = state; |
| 426 } | 413 } |
| OLD | NEW |