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 "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 "base/command_line.h" |
| 9 #include "content/common/child_thread.h" | 9 #include "content/common/child_thread.h" |
| 10 #include "content/common/gpu/gpu_channel.h" | 10 #include "content/common/gpu/gpu_channel.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 DCHECK(io_message_loop); | 35 DCHECK(io_message_loop); |
| 36 DCHECK(shutdown_event); | 36 DCHECK(shutdown_event); |
| 37 } | 37 } |
| 38 | 38 |
| 39 GpuChannelManager::~GpuChannelManager() { | 39 GpuChannelManager::~GpuChannelManager() { |
| 40 gpu_channels_.clear(); | 40 gpu_channels_.clear(); |
| 41 if (default_offscreen_surface_.get()) { | 41 if (default_offscreen_surface_.get()) { |
| 42 default_offscreen_surface_->Destroy(); | 42 default_offscreen_surface_->Destroy(); |
| 43 default_offscreen_surface_ = NULL; | 43 default_offscreen_surface_ = NULL; |
| 44 } | 44 } |
| 45 DCHECK(image_operations_.empty()); | |
| 45 } | 46 } |
| 46 | 47 |
| 47 gpu::gles2::ProgramCache* GpuChannelManager::program_cache() { | 48 gpu::gles2::ProgramCache* GpuChannelManager::program_cache() { |
| 48 if (!program_cache_.get() && | 49 if (!program_cache_.get() && |
| 49 (gfx::g_ARB_get_program_binary || gfx::g_OES_get_program_binary) && | 50 (gfx::g_ARB_get_program_binary || gfx::g_OES_get_program_binary) && |
| 50 !CommandLine::ForCurrentProcess()->HasSwitch( | 51 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 51 switches::kDisableGpuProgramCache)) { | 52 switches::kDisableGpuProgramCache)) { |
| 52 program_cache_.reset(new gpu::gles2::MemoryProgramCache()); | 53 program_cache_.reset(new gpu::gles2::MemoryProgramCache()); |
| 53 } | 54 } |
| 54 return program_cache_.get(); | 55 return program_cache_.get(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 } | 89 } |
| 89 | 90 |
| 90 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { | 91 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { |
| 91 bool msg_is_ok = true; | 92 bool msg_is_ok = true; |
| 92 bool handled = true; | 93 bool handled = true; |
| 93 IPC_BEGIN_MESSAGE_MAP_EX(GpuChannelManager, msg, msg_is_ok) | 94 IPC_BEGIN_MESSAGE_MAP_EX(GpuChannelManager, msg, msg_is_ok) |
| 94 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) | 95 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) |
| 95 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) | 96 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) |
| 96 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, | 97 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, |
| 97 OnCreateViewCommandBuffer) | 98 OnCreateViewCommandBuffer) |
| 99 IPC_MESSAGE_HANDLER(GpuMsg_CreateImage, OnCreateImage) | |
| 100 IPC_MESSAGE_HANDLER(GpuMsg_DeleteImage, OnDeleteImage) | |
| 98 IPC_MESSAGE_UNHANDLED(handled = false) | 101 IPC_MESSAGE_UNHANDLED(handled = false) |
| 99 IPC_END_MESSAGE_MAP_EX() | 102 IPC_END_MESSAGE_MAP_EX() |
| 100 return handled; | 103 return handled; |
| 101 } | 104 } |
| 102 | 105 |
| 103 bool GpuChannelManager::Send(IPC::Message* msg) { | 106 bool GpuChannelManager::Send(IPC::Message* msg) { |
| 104 return gpu_child_thread_->Send(msg); | 107 return gpu_child_thread_->Send(msg); |
| 105 } | 108 } |
| 106 | 109 |
| 107 void GpuChannelManager::OnEstablishChannel(int client_id, bool share_context) { | 110 void GpuChannelManager::OnEstablishChannel(int client_id, bool share_context) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 | 165 |
| 163 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); | 166 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); |
| 164 if (iter != gpu_channels_.end()) { | 167 if (iter != gpu_channels_.end()) { |
| 165 iter->second->CreateViewCommandBuffer( | 168 iter->second->CreateViewCommandBuffer( |
| 166 window, surface_id, init_params, &route_id); | 169 window, surface_id, init_params, &route_id); |
| 167 } | 170 } |
| 168 | 171 |
| 169 Send(new GpuHostMsg_CommandBufferCreated(route_id)); | 172 Send(new GpuHostMsg_CommandBufferCreated(route_id)); |
| 170 } | 173 } |
| 171 | 174 |
| 175 void GpuChannelManager::CreateImage( | |
| 176 gfx::PluginWindowHandle window, int32 client_id, int32 image_id) { | |
| 177 gfx::Size size; | |
| 178 | |
| 179 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); | |
| 180 if (iter != gpu_channels_.end()) { | |
| 181 iter->second->CreateImage(window, image_id, &size); | |
| 182 } | |
| 183 | |
| 184 Send(new GpuHostMsg_ImageCreated(size)); | |
| 185 } | |
| 186 | |
| 187 void GpuChannelManager::OnCreateImage( | |
| 188 gfx::PluginWindowHandle window, int32 client_id, int32 image_id) { | |
| 189 DCHECK(image_id); | |
| 190 | |
| 191 if (image_operations_.empty()) | |
| 192 CreateImage(window, client_id, image_id); | |
| 193 else | |
|
piman
2012/10/17 17:46:20
nit: style requires braces here because the statem
reveman
2012/10/17 21:22:55
Ah, braces required for multiple lines and not jus
| |
| 194 image_operations_.push_back( | |
| 195 std::make_pair(0, base::Bind(&GpuChannelManager::CreateImage, | |
| 196 base::Unretained(this), | |
| 197 window, | |
| 198 client_id, | |
| 199 image_id))); | |
| 200 } | |
| 201 | |
| 202 void GpuChannelManager::DeleteImage(int32 client_id, int32 image_id) { | |
| 203 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); | |
| 204 if (iter != gpu_channels_.end()) { | |
| 205 iter->second->DeleteImage(image_id); | |
| 206 } | |
| 207 } | |
| 208 | |
| 209 void GpuChannelManager::OnDeleteImage( | |
| 210 int32 client_id, int32 image_id, int32 sync_point) { | |
| 211 DCHECK(image_id); | |
| 212 | |
| 213 if (!sync_point && image_operations_.empty()) { | |
| 214 DeleteImage(client_id, image_id); | |
| 215 } else { | |
| 216 image_operations_.push_back( | |
| 217 std::make_pair(sync_point, base::Bind(&GpuChannelManager::DeleteImage, | |
| 218 base::Unretained(this), | |
| 219 client_id, | |
| 220 image_id))); | |
| 221 if (sync_point) | |
|
piman
2012/10/17 17:46:20
nit: style requires braces
| |
| 222 sync_point_manager()->AddSyncPointCallback( | |
| 223 sync_point, | |
| 224 base::Bind(&GpuChannelManager::OnDeleteImageSyncPointRetired, | |
| 225 base::Unretained(this), | |
| 226 &image_operations_.back())); | |
|
piman
2012/10/17 17:46:20
I don't think taking a pointer to the deque entry
reveman
2012/10/17 21:22:55
Oops, that's bad.
| |
| 227 } | |
| 228 } | |
| 229 | |
| 230 void GpuChannelManager::OnDeleteImageSyncPointRetired( | |
| 231 ImageOperation* delete_image_operation) { | |
| 232 // Mark operation as no longer having a pending sync point. | |
| 233 delete_image_operation->first = 0; | |
| 234 | |
| 235 // De-queue operations until we reach a pending sync point. | |
| 236 while (!image_operations_.empty()) { | |
| 237 // Check if operation has a pending sync point. | |
| 238 if (image_operations_.front().first) | |
| 239 return; | |
| 240 | |
| 241 image_operations_.front().second.Run(); | |
| 242 image_operations_.pop_front(); | |
| 243 } | |
| 244 } | |
| 245 | |
| 172 void GpuChannelManager::LoseAllContexts() { | 246 void GpuChannelManager::LoseAllContexts() { |
| 173 MessageLoop::current()->PostTask( | 247 MessageLoop::current()->PostTask( |
| 174 FROM_HERE, | 248 FROM_HERE, |
| 175 base::Bind(&GpuChannelManager::OnLoseAllContexts, | 249 base::Bind(&GpuChannelManager::OnLoseAllContexts, |
| 176 weak_factory_.GetWeakPtr())); | 250 weak_factory_.GetWeakPtr())); |
| 177 } | 251 } |
| 178 | 252 |
| 179 void GpuChannelManager::OnLoseAllContexts() { | 253 void GpuChannelManager::OnLoseAllContexts() { |
| 180 gpu_channels_.clear(); | 254 gpu_channels_.clear(); |
| 181 } | 255 } |
| 182 | 256 |
| 183 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { | 257 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { |
| 184 if (!default_offscreen_surface_.get()) { | 258 if (!default_offscreen_surface_.get()) { |
| 185 default_offscreen_surface_ = gfx::GLSurface::CreateOffscreenGLSurface( | 259 default_offscreen_surface_ = gfx::GLSurface::CreateOffscreenGLSurface( |
| 186 false, gfx::Size(1, 1)); | 260 false, gfx::Size(1, 1)); |
| 187 } | 261 } |
| 188 return default_offscreen_surface_.get(); | 262 return default_offscreen_surface_.get(); |
| 189 } | 263 } |
| OLD | NEW |