OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "content/common/gpu/gpu_channel.h" | 7 #include "content/common/gpu/gpu_channel.h" |
8 #include "content/common/gpu/gpu_messages.h" | 8 #include "content/common/gpu/gpu_messages.h" |
9 #include "content/gpu/gpu_child_thread.h" | |
9 | 10 |
10 GpuChannelManager::GpuChannelManager(IPC::Message::Sender* browser_channel, | 11 GpuChannelManager::GpuChannelManager(GpuChildThread* gpu_child_thread, |
11 GpuWatchdog* watchdog, | 12 GpuWatchdog* watchdog, |
12 base::MessageLoopProxy* io_message_loop, | 13 base::MessageLoopProxy* io_message_loop, |
13 base::WaitableEvent* shutdown_event) | 14 base::WaitableEvent* shutdown_event) |
14 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | 15 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
15 io_message_loop_(io_message_loop), | 16 io_message_loop_(io_message_loop), |
16 shutdown_event_(shutdown_event), | 17 shutdown_event_(shutdown_event), |
17 browser_channel_(browser_channel), | 18 gpu_child_thread_(gpu_child_thread), |
18 watchdog_(watchdog) { | 19 watchdog_(watchdog) { |
19 DCHECK(browser_channel); | 20 DCHECK(gpu_child_thread); |
20 DCHECK(io_message_loop); | 21 DCHECK(io_message_loop); |
21 DCHECK(shutdown_event); | 22 DCHECK(shutdown_event); |
22 } | 23 } |
23 | 24 |
24 GpuChannelManager::~GpuChannelManager() { | 25 GpuChannelManager::~GpuChannelManager() { |
25 gpu_channels_.clear(); | 26 gpu_channels_.clear(); |
26 } | 27 } |
27 | 28 |
28 void GpuChannelManager::RemoveChannel(int renderer_id) { | 29 void GpuChannelManager::RemoveChannel(int renderer_id) { |
29 gpu_channels_.erase(renderer_id); | 30 gpu_channels_.erase(renderer_id); |
30 } | 31 } |
31 | 32 |
33 int GpuChannelManager::GenerateRouteID() { | |
34 static int last_id = 0; | |
apatrick_chromium
2011/07/21 21:03:02
Is this the first time we've had to add routed obj
jonathan.backer
2011/07/22 13:12:40
AFAIK. I'm pretty disappointed that ChildThread do
| |
35 return ++last_id; | |
36 } | |
37 | |
38 void GpuChannelManager::AddRoute(int32 routing_id, | |
39 IPC::Channel::Listener* listener) { | |
40 gpu_child_thread_->AddRoute(routing_id, listener); | |
41 } | |
42 | |
43 void GpuChannelManager::RemoveRoute(int32 routing_id) { | |
44 gpu_child_thread_->RemoveRoute(routing_id); | |
45 } | |
46 | |
32 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { | 47 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { |
33 bool msg_is_ok = true; | 48 bool msg_is_ok = true; |
34 bool handled = true; | 49 bool handled = true; |
35 IPC_BEGIN_MESSAGE_MAP_EX(GpuChannelManager, msg, msg_is_ok) | 50 IPC_BEGIN_MESSAGE_MAP_EX(GpuChannelManager, msg, msg_is_ok) |
36 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) | 51 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) |
37 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) | 52 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) |
38 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, | 53 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, |
39 OnCreateViewCommandBuffer) | 54 OnCreateViewCommandBuffer) |
40 IPC_MESSAGE_HANDLER(GpuMsg_VisibilityChanged, OnVisibilityChanged) | 55 IPC_MESSAGE_HANDLER(GpuMsg_VisibilityChanged, OnVisibilityChanged) |
41 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) || defined(OS_WIN) | 56 #if defined(TOOLKIT_USES_GTK) && !defined(TOUCH_UI) || defined(OS_WIN) |
42 IPC_MESSAGE_HANDLER(GpuMsg_ResizeViewACK, OnResizeViewACK); | 57 IPC_MESSAGE_HANDLER(GpuMsg_ResizeViewACK, OnResizeViewACK); |
43 #endif | 58 #endif |
44 #if defined(TOUCH_UI) | 59 #if defined(OS_MACOSX) |
45 IPC_MESSAGE_HANDLER(GpuMsg_AcceleratedSurfaceSetIOSurfaceACK, | |
46 OnAcceleratedSurfaceSetIOSurfaceACK) | |
47 IPC_MESSAGE_HANDLER(GpuMsg_AcceleratedSurfaceReleaseACK, | |
48 OnAcceleratedSurfaceReleaseACK) | |
49 #endif | |
50 #if defined(OS_MACOSX) || defined(TOUCH_UI) | |
51 IPC_MESSAGE_HANDLER(GpuMsg_AcceleratedSurfaceBuffersSwappedACK, | 60 IPC_MESSAGE_HANDLER(GpuMsg_AcceleratedSurfaceBuffersSwappedACK, |
52 OnAcceleratedSurfaceBuffersSwappedACK) | 61 OnAcceleratedSurfaceBuffersSwappedACK) |
53 #endif | |
54 #if defined(OS_MACOSX) | |
55 IPC_MESSAGE_HANDLER(GpuMsg_DestroyCommandBuffer, | 62 IPC_MESSAGE_HANDLER(GpuMsg_DestroyCommandBuffer, |
56 OnDestroyCommandBuffer) | 63 OnDestroyCommandBuffer) |
57 #endif | 64 #endif |
58 IPC_MESSAGE_UNHANDLED(handled = false) | 65 IPC_MESSAGE_UNHANDLED(handled = false) |
59 IPC_END_MESSAGE_MAP_EX() | 66 IPC_END_MESSAGE_MAP_EX() |
60 return handled; | 67 return handled; |
61 } | 68 } |
62 | 69 |
63 bool GpuChannelManager::Send(IPC::Message* msg) { | 70 bool GpuChannelManager::Send(IPC::Message* msg) { |
64 return browser_channel_->Send(msg); | 71 return gpu_child_thread_->Send(msg); |
65 } | 72 } |
66 | 73 |
67 void GpuChannelManager::OnEstablishChannel(int renderer_id) { | 74 void GpuChannelManager::OnEstablishChannel(int renderer_id) { |
68 scoped_refptr<GpuChannel> channel; | 75 scoped_refptr<GpuChannel> channel; |
69 IPC::ChannelHandle channel_handle; | 76 IPC::ChannelHandle channel_handle; |
70 GPUInfo gpu_info; | 77 GPUInfo gpu_info; |
71 | 78 |
72 GpuChannelMap::const_iterator iter = gpu_channels_.find(renderer_id); | 79 GpuChannelMap::const_iterator iter = gpu_channels_.find(renderer_id); |
73 if (iter == gpu_channels_.end()) | 80 if (iter == gpu_channels_.end()) |
74 channel = new GpuChannel(this, watchdog_, renderer_id); | 81 channel = new GpuChannel(this, watchdog_, renderer_id); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 void GpuChannelManager::OnResizeViewACK(int32 renderer_id, | 138 void GpuChannelManager::OnResizeViewACK(int32 renderer_id, |
132 int32 command_buffer_route_id) { | 139 int32 command_buffer_route_id) { |
133 GpuChannelMap::const_iterator iter = gpu_channels_.find(renderer_id); | 140 GpuChannelMap::const_iterator iter = gpu_channels_.find(renderer_id); |
134 if (iter == gpu_channels_.end()) | 141 if (iter == gpu_channels_.end()) |
135 return; | 142 return; |
136 scoped_refptr<GpuChannel> channel = iter->second; | 143 scoped_refptr<GpuChannel> channel = iter->second; |
137 | 144 |
138 channel->ViewResized(command_buffer_route_id); | 145 channel->ViewResized(command_buffer_route_id); |
139 } | 146 } |
140 | 147 |
141 #if defined(TOUCH_UI) | 148 #if defined(OS_MACOSX) |
142 void GpuChannelManager::OnAcceleratedSurfaceSetIOSurfaceACK( | |
143 int renderer_id, int32 route_id, uint64 surface_id) { | |
144 GpuChannelMap::const_iterator iter = gpu_channels_.find(renderer_id); | |
145 if (iter == gpu_channels_.end()) | |
146 return; | |
147 scoped_refptr<GpuChannel> channel = iter->second; | |
148 channel->AcceleratedSurfaceIOSurfaceSet(route_id, surface_id); | |
149 } | |
150 | |
151 void GpuChannelManager::OnAcceleratedSurfaceReleaseACK( | |
152 int renderer_id, int32 route_id, uint64 surface_id) { | |
153 GpuChannelMap::const_iterator iter = gpu_channels_.find(renderer_id); | |
154 if (iter == gpu_channels_.end()) | |
155 return; | |
156 scoped_refptr<GpuChannel> channel = iter->second; | |
157 channel->AcceleratedSurfaceReleased(route_id, surface_id); | |
158 } | |
159 #endif | |
160 | |
161 #if defined(OS_MACOSX) || defined(TOUCH_UI) | |
162 void GpuChannelManager::OnAcceleratedSurfaceBuffersSwappedACK( | 149 void GpuChannelManager::OnAcceleratedSurfaceBuffersSwappedACK( |
163 int renderer_id, int32 route_id, uint64 swap_buffers_count) { | 150 int renderer_id, int32 route_id, uint64 swap_buffers_count) { |
164 GpuChannelMap::const_iterator iter = gpu_channels_.find(renderer_id); | 151 GpuChannelMap::const_iterator iter = gpu_channels_.find(renderer_id); |
165 if (iter == gpu_channels_.end()) | 152 if (iter == gpu_channels_.end()) |
166 return; | 153 return; |
167 scoped_refptr<GpuChannel> channel = iter->second; | 154 scoped_refptr<GpuChannel> channel = iter->second; |
168 channel->AcceleratedSurfaceBuffersSwapped(route_id, swap_buffers_count); | 155 channel->AcceleratedSurfaceBuffersSwapped(route_id, swap_buffers_count); |
169 } | 156 } |
170 #endif | |
171 | 157 |
172 #if defined(OS_MACOSX) | |
173 void GpuChannelManager::OnDestroyCommandBuffer( | 158 void GpuChannelManager::OnDestroyCommandBuffer( |
174 int renderer_id, int32 renderer_view_id) { | 159 int renderer_id, int32 renderer_view_id) { |
175 GpuChannelMap::const_iterator iter = gpu_channels_.find(renderer_id); | 160 GpuChannelMap::const_iterator iter = gpu_channels_.find(renderer_id); |
176 if (iter == gpu_channels_.end()) | 161 if (iter == gpu_channels_.end()) |
177 return; | 162 return; |
178 scoped_refptr<GpuChannel> channel = iter->second; | 163 scoped_refptr<GpuChannel> channel = iter->second; |
179 channel->DestroyCommandBufferByViewId(renderer_view_id); | 164 channel->DestroyCommandBufferByViewId(renderer_view_id); |
180 } | 165 } |
181 #endif | 166 #endif |
182 | 167 |
183 void GpuChannelManager::LoseAllContexts() { | 168 void GpuChannelManager::LoseAllContexts() { |
184 MessageLoop::current()->PostTask( | 169 MessageLoop::current()->PostTask( |
185 FROM_HERE, method_factory_.NewRunnableMethod( | 170 FROM_HERE, method_factory_.NewRunnableMethod( |
186 &GpuChannelManager::OnLoseAllContexts)); | 171 &GpuChannelManager::OnLoseAllContexts)); |
187 } | 172 } |
188 | 173 |
189 void GpuChannelManager::OnLoseAllContexts() { | 174 void GpuChannelManager::OnLoseAllContexts() { |
190 gpu_channels_.clear(); | 175 gpu_channels_.clear(); |
191 } | 176 } |
OLD | NEW |