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/browser/gpu/gpu_process_host_ui_shim.h" | 5 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
12 #include "base/id_map.h" | 12 #include "base/id_map.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "content/browser/gpu/gpu_data_manager_impl.h" | 15 #include "content/browser/gpu/gpu_data_manager_impl.h" |
16 #include "content/browser/gpu/gpu_process_host.h" | 16 #include "content/browser/gpu/gpu_process_host.h" |
17 #include "content/browser/gpu/gpu_surface_tracker.h" | 17 #include "content/browser/gpu/gpu_surface_tracker.h" |
18 #include "content/browser/renderer_host/render_process_host_impl.h" | 18 #include "content/browser/renderer_host/render_process_host_impl.h" |
19 #include "content/browser/renderer_host/render_view_host_impl.h" | 19 #include "content/browser/renderer_host/render_view_host_impl.h" |
20 #include "content/common/gpu/gpu_messages.h" | 20 #include "content/common/gpu/gpu_messages.h" |
21 #include "content/port/browser/render_widget_host_view_port.h" | 21 #include "content/port/browser/render_widget_host_view_port.h" |
22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
23 #include "ui/gl/gl_switches.h" | 23 #include "ui/gl/gl_switches.h" |
24 | 24 |
25 #if defined(TOOLKIT_GTK) | |
26 // These two #includes need to come after gpu_messages.h. | |
27 #include "ui/base/x/x11_util.h" | |
28 #include "ui/gfx/size.h" | |
29 #include <gdk/gdk.h> // NOLINT | |
30 #include <gdk/gdkx.h> // NOLINT | |
31 #endif | |
32 | |
33 // From gl2/gl2ext.h. | 25 // From gl2/gl2ext.h. |
34 #ifndef GL_MAILBOX_SIZE_CHROMIUM | 26 #ifndef GL_MAILBOX_SIZE_CHROMIUM |
35 #define GL_MAILBOX_SIZE_CHROMIUM 64 | 27 #define GL_MAILBOX_SIZE_CHROMIUM 64 |
36 #endif | 28 #endif |
37 | 29 |
38 namespace content { | 30 namespace content { |
39 | 31 |
40 namespace { | 32 namespace { |
41 | 33 |
42 // One of the linux specific headers defines this as a macro. | 34 // One of the linux specific headers defines this as a macro. |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 IPC_MESSAGE_HANDLER(GpuHostMsg_GraphicsInfoCollected, | 192 IPC_MESSAGE_HANDLER(GpuHostMsg_GraphicsInfoCollected, |
201 OnGraphicsInfoCollected) | 193 OnGraphicsInfoCollected) |
202 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceRelease, | 194 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceRelease, |
203 OnAcceleratedSurfaceRelease) | 195 OnAcceleratedSurfaceRelease) |
204 IPC_MESSAGE_HANDLER(GpuHostMsg_VideoMemoryUsageStats, | 196 IPC_MESSAGE_HANDLER(GpuHostMsg_VideoMemoryUsageStats, |
205 OnVideoMemoryUsageStatsReceived); | 197 OnVideoMemoryUsageStatsReceived); |
206 IPC_MESSAGE_HANDLER(GpuHostMsg_UpdateVSyncParameters, | 198 IPC_MESSAGE_HANDLER(GpuHostMsg_UpdateVSyncParameters, |
207 OnUpdateVSyncParameters) | 199 OnUpdateVSyncParameters) |
208 IPC_MESSAGE_HANDLER(GpuHostMsg_FrameDrawn, OnFrameDrawn) | 200 IPC_MESSAGE_HANDLER(GpuHostMsg_FrameDrawn, OnFrameDrawn) |
209 | 201 |
210 #if defined(TOOLKIT_GTK) || defined(OS_WIN) | |
211 IPC_MESSAGE_HANDLER(GpuHostMsg_ResizeView, OnResizeView) | 202 IPC_MESSAGE_HANDLER(GpuHostMsg_ResizeView, OnResizeView) |
212 #endif | |
213 | 203 |
214 IPC_MESSAGE_UNHANDLED_ERROR() | 204 IPC_MESSAGE_UNHANDLED_ERROR() |
215 IPC_END_MESSAGE_MAP() | 205 IPC_END_MESSAGE_MAP() |
216 | 206 |
217 return true; | 207 return true; |
218 } | 208 } |
219 | 209 |
220 void GpuProcessHostUIShim::OnUpdateVSyncParameters(int surface_id, | 210 void GpuProcessHostUIShim::OnUpdateVSyncParameters(int surface_id, |
221 base::TimeTicks timebase, | 211 base::TimeTicks timebase, |
222 base::TimeDelta interval) { | 212 base::TimeDelta interval) { |
(...skipping 21 matching lines...) Expand all Loading... |
244 | 234 |
245 void GpuProcessHostUIShim::OnGraphicsInfoCollected( | 235 void GpuProcessHostUIShim::OnGraphicsInfoCollected( |
246 const gpu::GPUInfo& gpu_info) { | 236 const gpu::GPUInfo& gpu_info) { |
247 // OnGraphicsInfoCollected is sent back after the GPU process successfully | 237 // OnGraphicsInfoCollected is sent back after the GPU process successfully |
248 // initializes GL. | 238 // initializes GL. |
249 TRACE_EVENT0("test_gpu", "OnGraphicsInfoCollected"); | 239 TRACE_EVENT0("test_gpu", "OnGraphicsInfoCollected"); |
250 | 240 |
251 GpuDataManagerImpl::GetInstance()->UpdateGpuInfo(gpu_info); | 241 GpuDataManagerImpl::GetInstance()->UpdateGpuInfo(gpu_info); |
252 } | 242 } |
253 | 243 |
254 #if defined(TOOLKIT_GTK) || defined(OS_WIN) | |
255 | |
256 void GpuProcessHostUIShim::OnResizeView(int32 surface_id, | 244 void GpuProcessHostUIShim::OnResizeView(int32 surface_id, |
257 int32 route_id, | 245 int32 route_id, |
258 gfx::Size size) { | 246 gfx::Size size) { |
259 // Always respond even if the window no longer exists. The GPU process cannot | 247 // Always respond even if the window no longer exists. The GPU process cannot |
260 // make progress on the resizing command buffer until it receives the | 248 // make progress on the resizing command buffer until it receives the |
261 // response. | 249 // response. |
262 ScopedSendOnIOThread delayed_send( | 250 ScopedSendOnIOThread delayed_send( |
263 host_id_, | 251 host_id_, |
264 new AcceleratedSurfaceMsg_ResizeViewACK(route_id)); | 252 new AcceleratedSurfaceMsg_ResizeViewACK(route_id)); |
265 | 253 |
266 RenderWidgetHostViewPort* view = | 254 RenderWidgetHostViewPort* view = |
267 GetRenderWidgetHostViewFromSurfaceID(surface_id); | 255 GetRenderWidgetHostViewFromSurfaceID(surface_id); |
268 if (!view) | 256 if (!view) |
269 return; | 257 return; |
270 | 258 |
271 gfx::GLSurfaceHandle surface = view->GetCompositingSurface(); | 259 view->ResizeCompositingSurface(size); |
272 | |
273 // Resize the window synchronously. The GPU process must not issue GL | |
274 // calls on the command buffer until the window is the size it expects it | |
275 // to be. | |
276 #if defined(TOOLKIT_GTK) | |
277 GdkWindow* window = reinterpret_cast<GdkWindow*>( | |
278 gdk_xid_table_lookup(surface.handle)); | |
279 if (window) { | |
280 Display* display = GDK_WINDOW_XDISPLAY(window); | |
281 gdk_window_resize(window, size.width(), size.height()); | |
282 XSync(display, False); | |
283 } | |
284 #elif defined(OS_WIN) | |
285 // Ensure window does not have zero area because D3D cannot create a zero | |
286 // area swap chain. | |
287 SetWindowPos(surface.handle, | |
288 NULL, | |
289 0, 0, | |
290 std::max(1, size.width()), | |
291 std::max(1, size.height()), | |
292 SWP_NOSENDCHANGING | SWP_NOCOPYBITS | SWP_NOZORDER | | |
293 SWP_NOACTIVATE | SWP_DEFERERASE | SWP_NOMOVE); | |
294 #endif | |
295 } | 260 } |
296 | 261 |
297 #endif | |
298 | |
299 static base::TimeDelta GetSwapDelay() { | 262 static base::TimeDelta GetSwapDelay() { |
300 CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 263 CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
301 int delay = 0; | 264 int delay = 0; |
302 if (cmd_line->HasSwitch(switches::kGpuSwapDelay)) { | 265 if (cmd_line->HasSwitch(switches::kGpuSwapDelay)) { |
303 base::StringToInt(cmd_line->GetSwitchValueNative( | 266 base::StringToInt(cmd_line->GetSwitchValueNative( |
304 switches::kGpuSwapDelay).c_str(), &delay); | 267 switches::kGpuSwapDelay).c_str(), &delay); |
305 } | 268 } |
306 return base::TimeDelta::FromMilliseconds(delay); | 269 return base::TimeDelta::FromMilliseconds(delay); |
307 } | 270 } |
308 | 271 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 view->AcceleratedSurfaceRelease(); | 355 view->AcceleratedSurfaceRelease(); |
393 } | 356 } |
394 | 357 |
395 void GpuProcessHostUIShim::OnVideoMemoryUsageStatsReceived( | 358 void GpuProcessHostUIShim::OnVideoMemoryUsageStatsReceived( |
396 const GPUVideoMemoryUsageStats& video_memory_usage_stats) { | 359 const GPUVideoMemoryUsageStats& video_memory_usage_stats) { |
397 GpuDataManagerImpl::GetInstance()->UpdateVideoMemoryUsageStats( | 360 GpuDataManagerImpl::GetInstance()->UpdateVideoMemoryUsageStats( |
398 video_memory_usage_stats); | 361 video_memory_usage_stats); |
399 } | 362 } |
400 | 363 |
401 } // namespace content | 364 } // namespace content |
OLD | NEW |