| 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/common/gpu/gpu_channel_manager.h" | 5 #include "content/common/gpu/gpu_channel_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | |
| 9 #include "content/common/child_thread.h" | 8 #include "content/common/child_thread.h" |
| 10 #include "content/common/gpu/gpu_channel.h" | 9 #include "content/common/gpu/gpu_channel.h" |
| 11 #include "content/common/gpu/gpu_memory_manager.h" | 10 #include "content/common/gpu/gpu_memory_manager.h" |
| 12 #include "content/common/gpu/gpu_messages.h" | 11 #include "content/common/gpu/gpu_messages.h" |
| 13 #include "content/common/gpu/sync_point_manager.h" | 12 #include "content/common/gpu/sync_point_manager.h" |
| 14 #include "gpu/command_buffer/service/gpu_switches.h" | |
| 15 #include "gpu/command_buffer/service/mailbox_manager.h" | 13 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 16 #include "gpu/command_buffer/service/memory_program_cache.h" | |
| 17 #include "ui/gl/gl_bindings.h" | |
| 18 #include "ui/gl/gl_share_group.h" | 14 #include "ui/gl/gl_share_group.h" |
| 19 | 15 |
| 20 GpuChannelManager::GpuChannelManager(ChildThread* gpu_child_thread, | 16 GpuChannelManager::GpuChannelManager(ChildThread* gpu_child_thread, |
| 21 GpuWatchdog* watchdog, | 17 GpuWatchdog* watchdog, |
| 22 base::MessageLoopProxy* io_message_loop, | 18 base::MessageLoopProxy* io_message_loop, |
| 23 base::WaitableEvent* shutdown_event) | 19 base::WaitableEvent* shutdown_event) |
| 24 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 20 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 25 io_message_loop_(io_message_loop), | 21 io_message_loop_(io_message_loop), |
| 26 shutdown_event_(shutdown_event), | 22 shutdown_event_(shutdown_event), |
| 27 gpu_child_thread_(gpu_child_thread), | 23 gpu_child_thread_(gpu_child_thread), |
| 28 ALLOW_THIS_IN_INITIALIZER_LIST(gpu_memory_manager_(this, | 24 ALLOW_THIS_IN_INITIALIZER_LIST(gpu_memory_manager_(this, |
| 29 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit)), | 25 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit)), |
| 30 watchdog_(watchdog), | 26 watchdog_(watchdog), |
| 31 sync_point_manager_(new SyncPointManager), | 27 sync_point_manager_(new SyncPointManager) { |
| 32 program_cache_( | |
| 33 gfx::g_glProgramBinary && | |
| 34 gfx::g_glGetProgramBinary && | |
| 35 !CommandLine::ForCurrentProcess()->HasSwitch( | |
| 36 switches::kDisableGpuProgramCache) ? | |
| 37 new gpu::gles2::MemoryProgramCache() : NULL) { | |
| 38 DCHECK(gpu_child_thread); | 28 DCHECK(gpu_child_thread); |
| 39 DCHECK(io_message_loop); | 29 DCHECK(io_message_loop); |
| 40 DCHECK(shutdown_event); | 30 DCHECK(shutdown_event); |
| 41 } | 31 } |
| 42 | 32 |
| 43 GpuChannelManager::~GpuChannelManager() { | 33 GpuChannelManager::~GpuChannelManager() { |
| 44 gpu_channels_.clear(); | 34 gpu_channels_.clear(); |
| 45 } | 35 } |
| 46 | 36 |
| 47 void GpuChannelManager::RemoveChannel(int client_id) { | 37 void GpuChannelManager::RemoveChannel(int client_id) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 68 else | 58 else |
| 69 return iter->second; | 59 return iter->second; |
| 70 } | 60 } |
| 71 | 61 |
| 72 void GpuChannelManager::AppendAllCommandBufferStubs( | 62 void GpuChannelManager::AppendAllCommandBufferStubs( |
| 73 std::vector<GpuCommandBufferStubBase*>& stubs) { | 63 std::vector<GpuCommandBufferStubBase*>& stubs) { |
| 74 for (GpuChannelMap::const_iterator it = gpu_channels_.begin(); | 64 for (GpuChannelMap::const_iterator it = gpu_channels_.begin(); |
| 75 it != gpu_channels_.end(); ++it ) { | 65 it != gpu_channels_.end(); ++it ) { |
| 76 it->second->AppendAllCommandBufferStubs(stubs); | 66 it->second->AppendAllCommandBufferStubs(stubs); |
| 77 } | 67 } |
| 68 |
| 78 } | 69 } |
| 79 | 70 |
| 80 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { | 71 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { |
| 81 bool msg_is_ok = true; | 72 bool msg_is_ok = true; |
| 82 bool handled = true; | 73 bool handled = true; |
| 83 IPC_BEGIN_MESSAGE_MAP_EX(GpuChannelManager, msg, msg_is_ok) | 74 IPC_BEGIN_MESSAGE_MAP_EX(GpuChannelManager, msg, msg_is_ok) |
| 84 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) | 75 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) |
| 85 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) | 76 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) |
| 86 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, | 77 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, |
| 87 OnCreateViewCommandBuffer) | 78 OnCreateViewCommandBuffer) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 107 } | 98 } |
| 108 share_group = share_group_; | 99 share_group = share_group_; |
| 109 mailbox_manager = mailbox_manager_; | 100 mailbox_manager = mailbox_manager_; |
| 110 } | 101 } |
| 111 | 102 |
| 112 scoped_refptr<GpuChannel> channel = new GpuChannel(this, | 103 scoped_refptr<GpuChannel> channel = new GpuChannel(this, |
| 113 watchdog_, | 104 watchdog_, |
| 114 share_group, | 105 share_group, |
| 115 mailbox_manager, | 106 mailbox_manager, |
| 116 client_id, | 107 client_id, |
| 117 false, | 108 false); |
| 118 program_cache_.get()); | |
| 119 if (channel->Init(io_message_loop_, shutdown_event_)) { | 109 if (channel->Init(io_message_loop_, shutdown_event_)) { |
| 120 gpu_channels_[client_id] = channel; | 110 gpu_channels_[client_id] = channel; |
| 121 channel_handle.name = channel->GetChannelName(); | 111 channel_handle.name = channel->GetChannelName(); |
| 122 | 112 |
| 123 #if defined(OS_POSIX) | 113 #if defined(OS_POSIX) |
| 124 // On POSIX, pass the renderer-side FD. Also mark it as auto-close so | 114 // On POSIX, pass the renderer-side FD. Also mark it as auto-close so |
| 125 // that it gets closed after it has been sent. | 115 // that it gets closed after it has been sent. |
| 126 int renderer_fd = channel->TakeRendererFileDescriptor(); | 116 int renderer_fd = channel->TakeRendererFileDescriptor(); |
| 127 DCHECK_NE(-1, renderer_fd); | 117 DCHECK_NE(-1, renderer_fd); |
| 128 channel_handle.socket = base::FileDescriptor(renderer_fd, true); | 118 channel_handle.socket = base::FileDescriptor(renderer_fd, true); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 void GpuChannelManager::LoseAllContexts() { | 153 void GpuChannelManager::LoseAllContexts() { |
| 164 MessageLoop::current()->PostTask( | 154 MessageLoop::current()->PostTask( |
| 165 FROM_HERE, | 155 FROM_HERE, |
| 166 base::Bind(&GpuChannelManager::OnLoseAllContexts, | 156 base::Bind(&GpuChannelManager::OnLoseAllContexts, |
| 167 weak_factory_.GetWeakPtr())); | 157 weak_factory_.GetWeakPtr())); |
| 168 } | 158 } |
| 169 | 159 |
| 170 void GpuChannelManager::OnLoseAllContexts() { | 160 void GpuChannelManager::OnLoseAllContexts() { |
| 171 gpu_channels_.clear(); | 161 gpu_channels_.clear(); |
| 172 } | 162 } |
| OLD | NEW |