| 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/gpu/gpu_channel.h" | 9 #include "content/common/gpu/gpu_channel.h" |
| 10 #include "content/common/gpu/gpu_memory_manager.h" | 10 #include "content/common/gpu/gpu_memory_manager.h" |
| 11 #include "content/common/gpu/gpu_messages.h" | 11 #include "content/common/gpu/gpu_messages.h" |
| 12 #include "content/common/gpu/sync_point_manager.h" | 12 #include "content/common/gpu/sync_point_manager.h" |
| 13 #include "content/common/message_router.h" | 13 #include "content/common/message_router.h" |
| 14 #include "gpu/command_buffer/service/feature_info.h" | 14 #include "gpu/command_buffer/service/feature_info.h" |
| 15 #include "gpu/command_buffer/service/gpu_switches.h" | 15 #include "gpu/command_buffer/service/gpu_switches.h" |
| 16 #include "gpu/command_buffer/service/mailbox_manager.h" | 16 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 17 #include "gpu/command_buffer/service/memory_program_cache.h" | 17 #include "gpu/command_buffer/service/memory_program_cache.h" |
| 18 #include "ui/gl/gl_bindings.h" | 18 #include "ui/gl/gl_bindings.h" |
| 19 #include "ui/gl/gl_share_group.h" | 19 #include "ui/gl/gl_share_group.h" |
| 20 | 20 |
| 21 #if defined(OS_ANDROID) |
| 22 #include "base/containers/scoped_ptr_hash_map.h" |
| 23 #include "base/lazy_instance.h" |
| 24 #include "ui/gl/android/scoped_java_surface.h" |
| 25 #include "ui/gl/android/surface_texture.h" |
| 26 #include "ui/gl/android/surface_texture_tracker.h" |
| 27 #endif |
| 28 |
| 21 namespace content { | 29 namespace content { |
| 22 | 30 |
| 31 #if defined(OS_ANDROID) |
| 32 namespace { |
| 33 |
| 34 class SurfaceTextureTrackerImpl : public gfx::SurfaceTextureTracker { |
| 35 public: |
| 36 SurfaceTextureTrackerImpl() { |
| 37 thread_checker_.DetachFromThread(); |
| 38 } |
| 39 |
| 40 // Overridden from gfx::SurfaceTextureTracker: |
| 41 virtual scoped_refptr<gfx::SurfaceTexture> AcquireSurfaceTexture( |
| 42 int primary_id, |
| 43 int secondary_id) OVERRIDE { |
| 44 base::AutoLock lock(surface_textures_lock_); |
| 45 scoped_ptr<SurfaceTextureInfo> info = |
| 46 surface_textures_.take_and_erase(SurfaceTextureMapKey( |
| 47 primary_id, static_cast<base::ProcessHandle>(secondary_id))); |
| 48 return info ? info->surface_texture : NULL; |
| 49 } |
| 50 |
| 51 void AddSurfaceTexture(gfx::SurfaceTexture* surface_texture, |
| 52 int surface_texture_id, |
| 53 base::ProcessHandle process_handle) { |
| 54 DCHECK(thread_checker_.CalledOnValidThread()); |
| 55 base::AutoLock lock(surface_textures_lock_); |
| 56 SurfaceTextureMapKey key(surface_texture_id, process_handle); |
| 57 DCHECK(surface_textures_.find(key) == surface_textures_.end()); |
| 58 surface_textures_.set( |
| 59 key, make_scoped_ptr(new SurfaceTextureInfo(surface_texture))); |
| 60 } |
| 61 |
| 62 void RemoveAllSurfaceTextures(base::ProcessHandle process_handle) { |
| 63 DCHECK(thread_checker_.CalledOnValidThread()); |
| 64 base::AutoLock lock(surface_textures_lock_); |
| 65 SurfaceTextureMap::iterator it = surface_textures_.begin(); |
| 66 while (it != surface_textures_.end()) { |
| 67 if (it->first.second == process_handle) |
| 68 surface_textures_.erase(it++); |
| 69 else |
| 70 ++it; |
| 71 } |
| 72 } |
| 73 |
| 74 jobject GetSurface(int surface_texture_id, |
| 75 base::ProcessHandle process_handle) const { |
| 76 base::AutoLock lock(surface_textures_lock_); |
| 77 SurfaceTextureMap::const_iterator it = surface_textures_.find( |
| 78 SurfaceTextureMapKey(surface_texture_id, process_handle)); |
| 79 return it == surface_textures_.end() |
| 80 ? NULL |
| 81 : it->second->surface.j_surface().obj(); |
| 82 } |
| 83 |
| 84 private: |
| 85 struct SurfaceTextureInfo { |
| 86 explicit SurfaceTextureInfo(gfx::SurfaceTexture* surface_texture) |
| 87 : surface_texture(surface_texture), surface(surface_texture) {} |
| 88 |
| 89 scoped_refptr<gfx::SurfaceTexture> surface_texture; |
| 90 gfx::ScopedJavaSurface surface; |
| 91 }; |
| 92 |
| 93 typedef std::pair<int, base::ProcessHandle> SurfaceTextureMapKey; |
| 94 typedef base::ScopedPtrHashMap<SurfaceTextureMapKey, SurfaceTextureInfo> |
| 95 SurfaceTextureMap; |
| 96 SurfaceTextureMap surface_textures_; |
| 97 mutable base::Lock surface_textures_lock_; |
| 98 base::ThreadChecker thread_checker_; |
| 99 }; |
| 100 base::LazyInstance<SurfaceTextureTrackerImpl> g_surface_texture_tracker = |
| 101 LAZY_INSTANCE_INITIALIZER; |
| 102 |
| 103 } // namespace |
| 104 |
| 105 #endif // OS_ANDROID |
| 106 |
| 23 GpuChannelManager::ImageOperation::ImageOperation( | 107 GpuChannelManager::ImageOperation::ImageOperation( |
| 24 int32 sync_point, base::Closure callback) | 108 int32 sync_point, base::Closure callback) |
| 25 : sync_point(sync_point), | 109 : sync_point(sync_point), |
| 26 callback(callback) { | 110 callback(callback) { |
| 27 } | 111 } |
| 28 | 112 |
| 29 GpuChannelManager::ImageOperation::~ImageOperation() { | 113 GpuChannelManager::ImageOperation::~ImageOperation() { |
| 30 } | 114 } |
| 31 | 115 |
| 32 GpuChannelManager::GpuChannelManager(MessageRouter* router, | 116 GpuChannelManager::GpuChannelManager(MessageRouter* router, |
| 33 GpuWatchdog* watchdog, | 117 GpuWatchdog* watchdog, |
| 34 base::MessageLoopProxy* io_message_loop, | 118 base::MessageLoopProxy* io_message_loop, |
| 35 base::WaitableEvent* shutdown_event) | 119 base::WaitableEvent* shutdown_event) |
| 36 : weak_factory_(this), | 120 : weak_factory_(this), |
| 37 io_message_loop_(io_message_loop), | 121 io_message_loop_(io_message_loop), |
| 38 shutdown_event_(shutdown_event), | 122 shutdown_event_(shutdown_event), |
| 39 router_(router), | 123 router_(router), |
| 40 gpu_memory_manager_( | 124 gpu_memory_manager_( |
| 41 this, | 125 this, |
| 42 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), | 126 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), |
| 43 watchdog_(watchdog), | 127 watchdog_(watchdog), |
| 44 sync_point_manager_(new SyncPointManager) { | 128 sync_point_manager_(new SyncPointManager) { |
| 45 DCHECK(router_); | 129 DCHECK(router_); |
| 46 DCHECK(io_message_loop); | 130 DCHECK(io_message_loop); |
| 47 DCHECK(shutdown_event); | 131 DCHECK(shutdown_event); |
| 132 // SurfaceTextureTracker instance must be set before we establish a channel |
| 133 // that could be using it to initialize GLImage instances. |
| 134 gfx::SurfaceTextureTracker::InitInstance(g_surface_texture_tracker.Pointer()); |
| 48 } | 135 } |
| 49 | 136 |
| 50 GpuChannelManager::~GpuChannelManager() { | 137 GpuChannelManager::~GpuChannelManager() { |
| 51 gpu_channels_.clear(); | 138 gpu_channels_.clear(); |
| 52 if (default_offscreen_surface_.get()) { | 139 if (default_offscreen_surface_.get()) { |
| 53 default_offscreen_surface_->Destroy(); | 140 default_offscreen_surface_->Destroy(); |
| 54 default_offscreen_surface_ = NULL; | 141 default_offscreen_surface_ = NULL; |
| 55 } | 142 } |
| 56 DCHECK(image_operations_.empty()); | 143 DCHECK(image_operations_.empty()); |
| 57 } | 144 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 bool msg_is_ok = true; | 184 bool msg_is_ok = true; |
| 98 bool handled = true; | 185 bool handled = true; |
| 99 IPC_BEGIN_MESSAGE_MAP_EX(GpuChannelManager, msg, msg_is_ok) | 186 IPC_BEGIN_MESSAGE_MAP_EX(GpuChannelManager, msg, msg_is_ok) |
| 100 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) | 187 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) |
| 101 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) | 188 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) |
| 102 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, | 189 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, |
| 103 OnCreateViewCommandBuffer) | 190 OnCreateViewCommandBuffer) |
| 104 IPC_MESSAGE_HANDLER(GpuMsg_CreateImage, OnCreateImage) | 191 IPC_MESSAGE_HANDLER(GpuMsg_CreateImage, OnCreateImage) |
| 105 IPC_MESSAGE_HANDLER(GpuMsg_DeleteImage, OnDeleteImage) | 192 IPC_MESSAGE_HANDLER(GpuMsg_DeleteImage, OnDeleteImage) |
| 106 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader) | 193 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader) |
| 194 IPC_MESSAGE_HANDLER(GpuMsg_CreateSurfaceTexture, OnCreateSurfaceTexture) |
| 107 IPC_MESSAGE_UNHANDLED(handled = false) | 195 IPC_MESSAGE_UNHANDLED(handled = false) |
| 108 IPC_END_MESSAGE_MAP_EX() | 196 IPC_END_MESSAGE_MAP_EX() |
| 109 return handled; | 197 return handled; |
| 110 } | 198 } |
| 111 | 199 |
| 112 bool GpuChannelManager::Send(IPC::Message* msg) { return router_->Send(msg); } | 200 bool GpuChannelManager::Send(IPC::Message* msg) { return router_->Send(msg); } |
| 113 | 201 |
| 114 void GpuChannelManager::OnEstablishChannel(int client_id, bool share_context) { | 202 void GpuChannelManager::OnEstablishChannel(int client_id, bool share_context) { |
| 115 IPC::ChannelHandle channel_handle; | 203 IPC::ChannelHandle channel_handle; |
| 116 | 204 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 345 |
| 258 bool GpuChannelManager::HandleMessagesScheduled() { | 346 bool GpuChannelManager::HandleMessagesScheduled() { |
| 259 for (GpuChannelMap::iterator iter = gpu_channels_.begin(); | 347 for (GpuChannelMap::iterator iter = gpu_channels_.begin(); |
| 260 iter != gpu_channels_.end(); ++iter) { | 348 iter != gpu_channels_.end(); ++iter) { |
| 261 if (iter->second->handle_messages_scheduled()) | 349 if (iter->second->handle_messages_scheduled()) |
| 262 return true; | 350 return true; |
| 263 } | 351 } |
| 264 return false; | 352 return false; |
| 265 } | 353 } |
| 266 | 354 |
| 355 void GpuChannelManager::OnCreateSurfaceTexture( |
| 356 int32 surface_texture_id, int32 process_handle) { |
| 357 DCHECK(surface_texture_id); |
| 358 #if defined(OS_ANDROID) |
| 359 const int kDummyTextureId = 0; |
| 360 scoped_refptr<gfx::SurfaceTexture> surface_texture = |
| 361 gfx::SurfaceTexture::Create(kDummyTextureId); |
| 362 g_surface_texture_tracker.Pointer()->AddSurfaceTexture( |
| 363 surface_texture.get(), |
| 364 surface_texture_id, |
| 365 static_cast<base::ProcessHandle>(process_handle)); |
| 366 #endif // OS_ANDROID |
| 367 } |
| 368 |
| 267 uint64 GpuChannelManager::MessagesProcessed() { | 369 uint64 GpuChannelManager::MessagesProcessed() { |
| 268 uint64 messages_processed = 0; | 370 uint64 messages_processed = 0; |
| 269 | 371 |
| 270 for (GpuChannelMap::iterator iter = gpu_channels_.begin(); | 372 for (GpuChannelMap::iterator iter = gpu_channels_.begin(); |
| 271 iter != gpu_channels_.end(); ++iter) { | 373 iter != gpu_channels_.end(); ++iter) { |
| 272 messages_processed += iter->second->messages_processed(); | 374 messages_processed += iter->second->messages_processed(); |
| 273 } | 375 } |
| 274 return messages_processed; | 376 return messages_processed; |
| 275 } | 377 } |
| 276 | 378 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 291 | 393 |
| 292 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { | 394 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { |
| 293 if (!default_offscreen_surface_.get()) { | 395 if (!default_offscreen_surface_.get()) { |
| 294 default_offscreen_surface_ = | 396 default_offscreen_surface_ = |
| 295 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1)); | 397 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1)); |
| 296 } | 398 } |
| 297 return default_offscreen_surface_.get(); | 399 return default_offscreen_surface_.get(); |
| 298 } | 400 } |
| 299 | 401 |
| 300 } // namespace content | 402 } // namespace content |
| OLD | NEW |