| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #if defined(ENABLE_GPU) | 5 #if defined(ENABLE_GPU) |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
| 10 #include "base/shared_memory.h" | 10 #include "base/shared_memory.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
| 23 #include "base/win/wrapped_window_proc.h" | 23 #include "base/win/wrapped_window_proc.h" |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 using gpu::Buffer; | 26 using gpu::Buffer; |
| 27 | 27 |
| 28 GpuCommandBufferStub::GpuCommandBufferStub( | 28 GpuCommandBufferStub::GpuCommandBufferStub( |
| 29 GpuChannel* channel, | 29 GpuChannel* channel, |
| 30 gfx::PluginWindowHandle handle, | 30 gfx::PluginWindowHandle handle, |
| 31 GpuCommandBufferStub* parent, | |
| 32 const gfx::Size& size, | 31 const gfx::Size& size, |
| 33 const gpu::gles2::DisallowedExtensions& disallowed_extensions, | 32 const gpu::gles2::DisallowedExtensions& disallowed_extensions, |
| 34 const std::string& allowed_extensions, | 33 const std::string& allowed_extensions, |
| 35 const std::vector<int32>& attribs, | 34 const std::vector<int32>& attribs, |
| 36 uint32 parent_texture_id, | |
| 37 int32 route_id, | 35 int32 route_id, |
| 38 int32 renderer_id, | 36 int32 renderer_id, |
| 39 int32 render_view_id, | 37 int32 render_view_id, |
| 40 GpuWatchdog* watchdog) | 38 GpuWatchdog* watchdog) |
| 41 : channel_(channel), | 39 : channel_(channel), |
| 42 handle_(handle), | 40 handle_(handle), |
| 43 parent_( | |
| 44 parent ? parent->AsWeakPtr() : base::WeakPtr<GpuCommandBufferStub>()), | |
| 45 initial_size_(size), | 41 initial_size_(size), |
| 46 disallowed_extensions_(disallowed_extensions), | 42 disallowed_extensions_(disallowed_extensions), |
| 47 allowed_extensions_(allowed_extensions), | 43 allowed_extensions_(allowed_extensions), |
| 48 requested_attribs_(attribs), | 44 requested_attribs_(attribs), |
| 49 parent_texture_id_(parent_texture_id), | |
| 50 route_id_(route_id), | 45 route_id_(route_id), |
| 51 last_flush_count_(0), | 46 last_flush_count_(0), |
| 52 renderer_id_(renderer_id), | 47 renderer_id_(renderer_id), |
| 53 render_view_id_(render_view_id), | 48 render_view_id_(render_view_id), |
| 54 watchdog_(watchdog), | 49 watchdog_(watchdog), |
| 55 task_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 50 task_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 56 } | 51 } |
| 57 | 52 |
| 58 GpuCommandBufferStub::~GpuCommandBufferStub() { | 53 GpuCommandBufferStub::~GpuCommandBufferStub() { |
| 59 if (scheduler_.get()) { | 54 if (scheduler_.get()) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 75 deferred_messages_.push(new IPC::Message(message)); | 70 deferred_messages_.push(new IPC::Message(message)); |
| 76 return true; | 71 return true; |
| 77 } | 72 } |
| 78 | 73 |
| 79 // Always use IPC_MESSAGE_HANDLER_DELAY_REPLY for synchronous message handlers | 74 // Always use IPC_MESSAGE_HANDLER_DELAY_REPLY for synchronous message handlers |
| 80 // here. This is so the reply can be delayed if the scheduler is unscheduled. | 75 // here. This is so the reply can be delayed if the scheduler is unscheduled. |
| 81 bool handled = true; | 76 bool handled = true; |
| 82 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) | 77 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) |
| 83 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_Initialize, | 78 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_Initialize, |
| 84 OnInitialize); | 79 OnInitialize); |
| 80 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_SetParent, |
| 81 OnSetParent); |
| 85 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_GetState, OnGetState); | 82 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_GetState, OnGetState); |
| 86 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_Flush, OnFlush); | 83 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_Flush, OnFlush); |
| 87 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush); | 84 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush); |
| 88 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_CreateTransferBuffer, | 85 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_CreateTransferBuffer, |
| 89 OnCreateTransferBuffer); | 86 OnCreateTransferBuffer); |
| 90 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_RegisterTransferBuffer, | 87 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_RegisterTransferBuffer, |
| 91 OnRegisterTransferBuffer); | 88 OnRegisterTransferBuffer); |
| 92 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_DestroyTransferBuffer, | 89 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_DestroyTransferBuffer, |
| 93 OnDestroyTransferBuffer); | 90 OnDestroyTransferBuffer); |
| 94 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_GetTransferBuffer, | 91 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_GetTransferBuffer, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 125 false, | 122 false, |
| 126 channel_->renderer_process()); | 123 channel_->renderer_process()); |
| 127 #else | 124 #else |
| 128 // POSIX receives a dup of the shared memory handle and closes the dup when | 125 // POSIX receives a dup of the shared memory handle and closes the dup when |
| 129 // this variable goes out of scope. | 126 // this variable goes out of scope. |
| 130 base::SharedMemory shared_memory(ring_buffer, false); | 127 base::SharedMemory shared_memory(ring_buffer, false); |
| 131 #endif | 128 #endif |
| 132 | 129 |
| 133 // Initialize the CommandBufferService and GpuScheduler. | 130 // Initialize the CommandBufferService and GpuScheduler. |
| 134 if (command_buffer_->Initialize(&shared_memory, size)) { | 131 if (command_buffer_->Initialize(&shared_memory, size)) { |
| 135 gpu::GpuScheduler* parent_processor = | |
| 136 parent_ ? parent_->scheduler_.get() : NULL; | |
| 137 scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), | 132 scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), |
| 138 channel_, | 133 channel_, |
| 139 NULL)); | 134 NULL)); |
| 140 if (scheduler_->Initialize( | 135 if (scheduler_->Initialize( |
| 141 handle_, | 136 handle_, |
| 142 initial_size_, | 137 initial_size_, |
| 143 disallowed_extensions_, | 138 disallowed_extensions_, |
| 144 allowed_extensions_.c_str(), | 139 allowed_extensions_.c_str(), |
| 145 requested_attribs_, | 140 requested_attribs_, |
| 146 parent_processor, | |
| 147 parent_texture_id_, | |
| 148 channel_->share_group())) { | 141 channel_->share_group())) { |
| 149 command_buffer_->SetPutOffsetChangeCallback( | 142 command_buffer_->SetPutOffsetChangeCallback( |
| 150 NewCallback(scheduler_.get(), | 143 NewCallback(scheduler_.get(), |
| 151 &gpu::GpuScheduler::PutChanged)); | 144 &gpu::GpuScheduler::PutChanged)); |
| 152 command_buffer_->SetParseErrorCallback( | 145 command_buffer_->SetParseErrorCallback( |
| 153 NewCallback(this, &GpuCommandBufferStub::OnParseError)); | 146 NewCallback(this, &GpuCommandBufferStub::OnParseError)); |
| 154 scheduler_->SetSwapBuffersCallback( | 147 scheduler_->SetSwapBuffersCallback( |
| 155 NewCallback(this, &GpuCommandBufferStub::OnSwapBuffers)); | 148 NewCallback(this, &GpuCommandBufferStub::OnSwapBuffers)); |
| 156 scheduler_->SetLatchCallback(base::Bind( | 149 scheduler_->SetLatchCallback(base::Bind( |
| 157 &GpuChannel::OnLatchCallback, base::Unretained(channel_), route_id_)); | 150 &GpuChannel::OnLatchCallback, base::Unretained(channel_), route_id_)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 182 } else { | 175 } else { |
| 183 scheduler_.reset(); | 176 scheduler_.reset(); |
| 184 command_buffer_.reset(); | 177 command_buffer_.reset(); |
| 185 } | 178 } |
| 186 } | 179 } |
| 187 | 180 |
| 188 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, result); | 181 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, result); |
| 189 Send(reply_message); | 182 Send(reply_message); |
| 190 } | 183 } |
| 191 | 184 |
| 185 void GpuCommandBufferStub::OnSetParent(int32 parent_route_id, |
| 186 uint32 parent_texture_id, |
| 187 IPC::Message* reply_message) { |
| 188 bool result = false; |
| 189 |
| 190 if (parent_route_id == MSG_ROUTING_NONE) { |
| 191 result = scheduler_->SetParent(NULL, 0); |
| 192 } else { |
| 193 GpuCommandBufferStub* parent_stub = channel_->LookupCommandBuffer( |
| 194 parent_route_id); |
| 195 if (parent_stub) { |
| 196 result = scheduler_->SetParent(parent_stub->scheduler_.get(), |
| 197 parent_texture_id); |
| 198 } |
| 199 } |
| 200 |
| 201 GpuCommandBufferMsg_SetParent::WriteReplyParams(reply_message, result); |
| 202 Send(reply_message); |
| 203 } |
| 204 |
| 192 void GpuCommandBufferStub::OnGetState(IPC::Message* reply_message) { | 205 void GpuCommandBufferStub::OnGetState(IPC::Message* reply_message) { |
| 193 gpu::CommandBuffer::State state = command_buffer_->GetState(); | 206 gpu::CommandBuffer::State state = command_buffer_->GetState(); |
| 194 if (state.error == gpu::error::kLostContext && | 207 if (state.error == gpu::error::kLostContext && |
| 195 gfx::GLContext::LosesAllContextsOnContextLost()) | 208 gfx::GLContext::LosesAllContextsOnContextLost()) |
| 196 channel_->LoseAllContexts(); | 209 channel_->LoseAllContexts(); |
| 197 | 210 |
| 198 GpuCommandBufferMsg_GetState::WriteReplyParams(reply_message, state); | 211 GpuCommandBufferMsg_GetState::WriteReplyParams(reply_message, state); |
| 199 Send(reply_message); | 212 Send(reply_message); |
| 200 } | 213 } |
| 201 | 214 |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 gfx::GLContext::LosesAllContextsOnContextLost()) { | 477 gfx::GLContext::LosesAllContextsOnContextLost()) { |
| 465 channel_->LoseAllContexts(); | 478 channel_->LoseAllContexts(); |
| 466 } else { | 479 } else { |
| 467 IPC::Message* msg = new GpuCommandBufferMsg_UpdateState(route_id_, state); | 480 IPC::Message* msg = new GpuCommandBufferMsg_UpdateState(route_id_, state); |
| 468 msg->set_unblock(true); | 481 msg->set_unblock(true); |
| 469 Send(msg); | 482 Send(msg); |
| 470 } | 483 } |
| 471 } | 484 } |
| 472 | 485 |
| 473 #endif // defined(ENABLE_GPU) | 486 #endif // defined(ENABLE_GPU) |
| OLD | NEW |