| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/gpu/gpu_render_thread.h" | |
| 6 | |
| 7 #include <string> | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "app/win/scoped_com_initializer.h" | |
| 11 #include "base/command_line.h" | |
| 12 #include "base/threading/worker_pool.h" | |
| 13 #include "build/build_config.h" | |
| 14 #include "chrome/common/child_process_logging.h" | |
| 15 #include "chrome/common/chrome_switches.h" | |
| 16 #include "content/common/child_process.h" | |
| 17 #include "content/common/gpu_messages.h" | |
| 18 #include "content/gpu/gpu_child_thread.h" | |
| 19 #include "content/gpu/gpu_info_collector.h" | |
| 20 #include "content/gpu/gpu_watchdog_thread.h" | |
| 21 #include "ipc/ipc_channel_handle.h" | |
| 22 #include "ui/gfx/gl/gl_context.h" | |
| 23 #include "ui/gfx/gl/gl_implementation.h" | |
| 24 | |
| 25 GpuRenderThread::GpuRenderThread(IPC::Message::Sender* browser_channel, | |
| 26 GpuWatchdogThread* gpu_watchdog_thread, | |
| 27 MessageLoop* io_message_loop, | |
| 28 base::WaitableEvent* shutdown_event) | |
| 29 : io_message_loop_(io_message_loop), | |
| 30 shutdown_event_(shutdown_event), | |
| 31 browser_channel_(browser_channel), | |
| 32 watchdog_thread_(gpu_watchdog_thread) { | |
| 33 DCHECK(browser_channel); | |
| 34 DCHECK(io_message_loop); | |
| 35 DCHECK(shutdown_event); | |
| 36 } | |
| 37 | |
| 38 GpuRenderThread::~GpuRenderThread() { | |
| 39 gpu_channels_.clear(); | |
| 40 } | |
| 41 | |
| 42 void GpuRenderThread::RemoveChannel(int renderer_id) { | |
| 43 gpu_channels_.erase(renderer_id); | |
| 44 } | |
| 45 | |
| 46 bool GpuRenderThread::OnMessageReceived(const IPC::Message& msg) { | |
| 47 bool msg_is_ok = true; | |
| 48 bool handled = true; | |
| 49 IPC_BEGIN_MESSAGE_MAP_EX(GpuRenderThread, msg, msg_is_ok) | |
| 50 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) | |
| 51 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) | |
| 52 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, | |
| 53 OnCreateViewCommandBuffer); | |
| 54 IPC_MESSAGE_HANDLER(GpuMsg_Synchronize, OnSynchronize) | |
| 55 #if defined(OS_MACOSX) | |
| 56 IPC_MESSAGE_HANDLER(GpuMsg_AcceleratedSurfaceBuffersSwappedACK, | |
| 57 OnAcceleratedSurfaceBuffersSwappedACK) | |
| 58 IPC_MESSAGE_HANDLER(GpuMsg_DestroyCommandBuffer, | |
| 59 OnDestroyCommandBuffer) | |
| 60 #endif | |
| 61 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 62 IPC_END_MESSAGE_MAP_EX() | |
| 63 return handled; | |
| 64 } | |
| 65 | |
| 66 bool GpuRenderThread::Send(IPC::Message* msg) { | |
| 67 return browser_channel_->Send(msg); | |
| 68 } | |
| 69 | |
| 70 void GpuRenderThread::OnEstablishChannel(int renderer_id) { | |
| 71 scoped_refptr<GpuChannel> channel; | |
| 72 IPC::ChannelHandle channel_handle; | |
| 73 GPUInfo gpu_info; | |
| 74 | |
| 75 GpuChannelMap::const_iterator iter = gpu_channels_.find(renderer_id); | |
| 76 if (iter == gpu_channels_.end()) | |
| 77 channel = new GpuChannel(this, watchdog_thread_, renderer_id); | |
| 78 else | |
| 79 channel = iter->second; | |
| 80 | |
| 81 DCHECK(channel != NULL); | |
| 82 | |
| 83 if (channel->Init(io_message_loop_, shutdown_event_)) | |
| 84 gpu_channels_[renderer_id] = channel; | |
| 85 else | |
| 86 channel = NULL; | |
| 87 | |
| 88 if (channel.get()) { | |
| 89 channel_handle.name = channel->GetChannelName(); | |
| 90 #if defined(OS_POSIX) | |
| 91 // On POSIX, pass the renderer-side FD. Also mark it as auto-close so | |
| 92 // that it gets closed after it has been sent. | |
| 93 int renderer_fd = channel->GetRendererFileDescriptor(); | |
| 94 channel_handle.socket = base::FileDescriptor(dup(renderer_fd), true); | |
| 95 #endif | |
| 96 } | |
| 97 | |
| 98 Send(new GpuHostMsg_ChannelEstablished(channel_handle)); | |
| 99 } | |
| 100 | |
| 101 void GpuRenderThread::OnCloseChannel(const IPC::ChannelHandle& channel_handle) { | |
| 102 for (GpuChannelMap::iterator iter = gpu_channels_.begin(); | |
| 103 iter != gpu_channels_.end(); ++iter) { | |
| 104 if (iter->second->GetChannelName() == channel_handle.name) { | |
| 105 gpu_channels_.erase(iter); | |
| 106 return; | |
| 107 } | |
| 108 } | |
| 109 } | |
| 110 | |
| 111 void GpuRenderThread::OnSynchronize() { | |
| 112 Send(new GpuHostMsg_SynchronizeReply()); | |
| 113 } | |
| 114 | |
| 115 void GpuRenderThread::OnCreateViewCommandBuffer( | |
| 116 gfx::PluginWindowHandle window, | |
| 117 int32 render_view_id, | |
| 118 int32 renderer_id, | |
| 119 const GPUCreateCommandBufferConfig& init_params) { | |
| 120 int32 route_id = MSG_ROUTING_NONE; | |
| 121 | |
| 122 GpuChannelMap::const_iterator iter = gpu_channels_.find(renderer_id); | |
| 123 if (iter != gpu_channels_.end()) { | |
| 124 iter->second->CreateViewCommandBuffer( | |
| 125 window, render_view_id, init_params, &route_id); | |
| 126 } | |
| 127 | |
| 128 Send(new GpuHostMsg_CommandBufferCreated(route_id)); | |
| 129 } | |
| 130 | |
| 131 #if defined(OS_MACOSX) | |
| 132 void GpuRenderThread::OnAcceleratedSurfaceBuffersSwappedACK( | |
| 133 int renderer_id, int32 route_id, uint64 swap_buffers_count) { | |
| 134 GpuChannelMap::const_iterator iter = gpu_channels_.find(renderer_id); | |
| 135 if (iter == gpu_channels_.end()) | |
| 136 return; | |
| 137 scoped_refptr<GpuChannel> channel = iter->second; | |
| 138 channel->AcceleratedSurfaceBuffersSwapped(route_id, swap_buffers_count); | |
| 139 } | |
| 140 void GpuRenderThread::OnDestroyCommandBuffer( | |
| 141 int renderer_id, int32 renderer_view_id) { | |
| 142 GpuChannelMap::const_iterator iter = gpu_channels_.find(renderer_id); | |
| 143 if (iter == gpu_channels_.end()) | |
| 144 return; | |
| 145 scoped_refptr<GpuChannel> channel = iter->second; | |
| 146 channel->DestroyCommandBufferByViewId(renderer_view_id); | |
| 147 } | |
| 148 #endif | |
| OLD | NEW |