Chromium Code Reviews| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/hash.h" | 9 #include "base/hash.h" |
| 10 #include "base/shared_memory.h" | 10 #include "base/shared_memory.h" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 #include "ui/gl/gl_switches.h" | 30 #include "ui/gl/gl_switches.h" |
| 31 | 31 |
| 32 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
| 33 #include "content/public/common/sandbox_init.h" | 33 #include "content/public/common/sandbox_init.h" |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 #if defined(OS_ANDROID) | 36 #if defined(OS_ANDROID) |
| 37 #include "content/common/gpu/stream_texture_manager_android.h" | 37 #include "content/common/gpu/stream_texture_manager_android.h" |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 #include "base/threading/thread_restrictions.h" | |
|
boliu
2013/03/01 00:19:12
oops, no needed
| |
| 41 | |
| 40 namespace content { | 42 namespace content { |
| 41 namespace { | 43 namespace { |
| 42 | 44 |
| 43 // The GpuCommandBufferMemoryTracker class provides a bridge between the | 45 // The GpuCommandBufferMemoryTracker class provides a bridge between the |
| 44 // ContextGroup's memory type managers and the GpuMemoryManager class. | 46 // ContextGroup's memory type managers and the GpuMemoryManager class. |
| 45 class GpuCommandBufferMemoryTracker : public gpu::gles2::MemoryTracker { | 47 class GpuCommandBufferMemoryTracker : public gpu::gles2::MemoryTracker { |
| 46 public: | 48 public: |
| 47 explicit GpuCommandBufferMemoryTracker(GpuChannel* channel) : | 49 explicit GpuCommandBufferMemoryTracker(GpuChannel* channel) : |
| 48 tracking_group_(channel->gpu_channel_manager()->gpu_memory_manager()-> | 50 tracking_group_(channel->gpu_channel_manager()->gpu_memory_manager()-> |
| 49 CreateTrackingGroup(channel->renderer_pid(), this)) { | 51 CreateTrackingGroup(channel->renderer_pid(), this)) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 if (!MakeCurrent()) | 167 if (!MakeCurrent()) |
| 166 return false; | 168 return false; |
| 167 } | 169 } |
| 168 | 170 |
| 169 // Always use IPC_MESSAGE_HANDLER_DELAY_REPLY for synchronous message handlers | 171 // Always use IPC_MESSAGE_HANDLER_DELAY_REPLY for synchronous message handlers |
| 170 // here. This is so the reply can be delayed if the scheduler is unscheduled. | 172 // here. This is so the reply can be delayed if the scheduler is unscheduled. |
| 171 bool handled = true; | 173 bool handled = true; |
| 172 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) | 174 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) |
| 173 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_Initialize, | 175 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_Initialize, |
| 174 OnInitialize); | 176 OnInitialize); |
| 175 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_SetGetBuffer, | 177 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SetGetBuffer, |
| 176 OnSetGetBuffer); | 178 OnSetGetBuffer); |
| 177 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_SetParent, | 179 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_SetParent, |
| 178 OnSetParent); | 180 OnSetParent); |
| 179 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Echo, OnEcho); | 181 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Echo, OnEcho); |
| 180 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_GetState, OnGetState); | 182 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_GetState, OnGetState); |
| 181 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_GetStateFast, | 183 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetStateFast, |
| 182 OnGetStateFast); | 184 OnGetStateFast); |
| 183 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush); | 185 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush); |
| 184 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Rescheduled, OnRescheduled); | 186 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Rescheduled, OnRescheduled); |
| 185 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_RegisterTransferBuffer, | 187 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_RegisterTransferBuffer, |
| 186 OnRegisterTransferBuffer); | 188 OnRegisterTransferBuffer); |
| 187 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyTransferBuffer, | 189 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyTransferBuffer, |
| 188 OnDestroyTransferBuffer); | 190 OnDestroyTransferBuffer); |
| 189 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_GetTransferBuffer, | 191 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_GetTransferBuffer, |
| 190 OnGetTransferBuffer); | 192 OnGetTransferBuffer); |
| 191 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_CreateVideoDecoder, | 193 IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_CreateVideoDecoder, |
| 192 OnCreateVideoDecoder) | 194 OnCreateVideoDecoder) |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 if (context) | 329 if (context) |
| 328 context->ReleaseCurrent(NULL); | 330 context->ReleaseCurrent(NULL); |
| 329 } | 331 } |
| 330 | 332 |
| 331 void GpuCommandBufferStub::OnInitializeFailed(IPC::Message* reply_message) { | 333 void GpuCommandBufferStub::OnInitializeFailed(IPC::Message* reply_message) { |
| 332 Destroy(); | 334 Destroy(); |
| 333 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, false); | 335 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, false); |
| 334 Send(reply_message); | 336 Send(reply_message); |
| 335 } | 337 } |
| 336 | 338 |
| 337 void GpuCommandBufferStub::OnInitialize( | 339 void GpuCommandBufferStub::OnInitialize( |
|
boliu
2013/03/01 00:19:12
This doesn't really need flexibility of DELAYED_RE
| |
| 338 base::SharedMemoryHandle shared_state_handle, | 340 base::SharedMemoryHandle shared_state_handle, |
| 339 IPC::Message* reply_message) { | 341 IPC::Message* reply_message) { |
| 340 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnInitialize"); | 342 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnInitialize"); |
| 341 DCHECK(!command_buffer_.get()); | 343 DCHECK(!command_buffer_.get()); |
| 342 | 344 |
| 343 scoped_ptr<base::SharedMemory> shared_state_shm( | 345 scoped_ptr<base::SharedMemory> shared_state_shm( |
| 344 new base::SharedMemory(shared_state_handle, false)); | 346 new base::SharedMemory(shared_state_handle, false)); |
| 345 | 347 |
| 346 command_buffer_.reset(new gpu::CommandBufferService( | 348 command_buffer_.reset(new gpu::CommandBufferService( |
| 347 context_group_->transfer_buffer_manager())); | 349 context_group_->transfer_buffer_manager())); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, true); | 516 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, true); |
| 515 Send(reply_message); | 517 Send(reply_message); |
| 516 | 518 |
| 517 if (handle_.is_null() && !active_url_.is_empty()) { | 519 if (handle_.is_null() && !active_url_.is_empty()) { |
| 518 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); | 520 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); |
| 519 gpu_channel_manager->Send(new GpuHostMsg_DidCreateOffscreenContext( | 521 gpu_channel_manager->Send(new GpuHostMsg_DidCreateOffscreenContext( |
| 520 active_url_)); | 522 active_url_)); |
| 521 } | 523 } |
| 522 } | 524 } |
| 523 | 525 |
| 524 void GpuCommandBufferStub::OnSetGetBuffer(int32 shm_id, | 526 void GpuCommandBufferStub::OnSetGetBuffer(int32 shm_id) { |
| 525 IPC::Message* reply_message) { | |
| 526 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSetGetBuffer"); | 527 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSetGetBuffer"); |
| 527 if (command_buffer_.get()) | 528 if (command_buffer_.get()) |
| 528 command_buffer_->SetGetBuffer(shm_id); | 529 command_buffer_->SetGetBuffer(shm_id); |
| 529 Send(reply_message); | |
| 530 } | 530 } |
| 531 | 531 |
| 532 void GpuCommandBufferStub::OnSetParent(int32 parent_route_id, | 532 void GpuCommandBufferStub::OnSetParent(int32 parent_route_id, |
| 533 uint32 parent_texture_id, | 533 uint32 parent_texture_id, |
| 534 IPC::Message* reply_message) { | 534 IPC::Message* reply_message) { |
| 535 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSetParent"); | 535 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSetParent"); |
| 536 GpuCommandBufferStub* parent_stub = NULL; | 536 GpuCommandBufferStub* parent_stub = NULL; |
| 537 if (parent_route_id != MSG_ROUTING_NONE) { | 537 if (parent_route_id != MSG_ROUTING_NONE) { |
| 538 parent_stub = channel_->LookupCommandBuffer(parent_route_id); | 538 parent_stub = channel_->LookupCommandBuffer(parent_route_id); |
| 539 } | 539 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 581 Send(msg); | 581 Send(msg); |
| 582 | 582 |
| 583 // Tell the browser about this context loss as well, so it can | 583 // Tell the browser about this context loss as well, so it can |
| 584 // determine whether client APIs like WebGL need to be immediately | 584 // determine whether client APIs like WebGL need to be immediately |
| 585 // blocked from automatically running. | 585 // blocked from automatically running. |
| 586 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); | 586 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); |
| 587 gpu_channel_manager->Send(new GpuHostMsg_DidLoseContext( | 587 gpu_channel_manager->Send(new GpuHostMsg_DidLoseContext( |
| 588 handle_.is_null(), state.context_lost_reason, active_url_)); | 588 handle_.is_null(), state.context_lost_reason, active_url_)); |
| 589 } | 589 } |
| 590 | 590 |
| 591 void GpuCommandBufferStub::OnGetStateFast(IPC::Message* reply_message) { | 591 void GpuCommandBufferStub::OnGetStateFast(gpu::CommandBuffer::State* state) { |
| 592 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnGetStateFast"); | 592 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnGetStateFast"); |
| 593 DCHECK(command_buffer_.get()); | 593 DCHECK(command_buffer_.get()); |
| 594 gpu::CommandBuffer::State state = command_buffer_->GetState(); | 594 *state = command_buffer_->GetState(); |
| 595 if (state.error == gpu::error::kLostContext && | 595 if (state->error == gpu::error::kLostContext && |
| 596 gfx::GLContext::LosesAllContextsOnContextLost()) | 596 gfx::GLContext::LosesAllContextsOnContextLost()) |
| 597 channel_->LoseAllContexts(); | 597 channel_->LoseAllContexts(); |
| 598 | |
| 599 GpuCommandBufferMsg_GetStateFast::WriteReplyParams(reply_message, state); | |
| 600 Send(reply_message); | |
| 601 } | 598 } |
| 602 | 599 |
| 603 void GpuCommandBufferStub::OnAsyncFlush(int32 put_offset, | 600 void GpuCommandBufferStub::OnAsyncFlush(int32 put_offset, |
| 604 uint32 flush_count) { | 601 uint32 flush_count) { |
| 605 TRACE_EVENT1("gpu", "GpuCommandBufferStub::OnAsyncFlush", | 602 TRACE_EVENT1("gpu", "GpuCommandBufferStub::OnAsyncFlush", |
| 606 "put_offset", put_offset); | 603 "put_offset", put_offset); |
| 607 DCHECK(command_buffer_.get()); | 604 DCHECK(command_buffer_.get()); |
| 608 if (flush_count - last_flush_count_ < 0x8000000U) { | 605 if (flush_count - last_flush_count_ < 0x8000000U) { |
| 609 last_flush_count_ = flush_count; | 606 last_flush_count_ = flush_count; |
| 610 command_buffer_->Flush(put_offset); | 607 command_buffer_->Flush(put_offset); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 879 if (surface_ && MakeCurrent()) | 876 if (surface_ && MakeCurrent()) |
| 880 surface_->SetFrontbufferAllocation( | 877 surface_->SetFrontbufferAllocation( |
| 881 allocation.browser_allocation.suggest_have_frontbuffer); | 878 allocation.browser_allocation.suggest_have_frontbuffer); |
| 882 } | 879 } |
| 883 | 880 |
| 884 last_memory_allocation_valid_ = true; | 881 last_memory_allocation_valid_ = true; |
| 885 last_memory_allocation_ = allocation; | 882 last_memory_allocation_ = allocation; |
| 886 } | 883 } |
| 887 | 884 |
| 888 } // namespace content | 885 } // namespace content |
| OLD | NEW |