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