| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #if defined(ENABLE_GPU) | 5 #if defined(ENABLE_GPU) |
| 6 | 6 |
| 7 #include "base/process_util.h" | 7 #include "base/process_util.h" |
| 8 #include "base/shared_memory.h" | 8 #include "base/shared_memory.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/common/child_thread.h" | 10 #include "chrome/common/child_thread.h" |
| 11 #include "chrome/common/gpu_messages.h" | 11 #include "chrome/common/gpu_messages.h" |
| 12 #include "chrome/gpu/gpu_channel.h" | 12 #include "chrome/gpu/gpu_channel.h" |
| 13 #include "chrome/gpu/gpu_command_buffer_stub.h" | 13 #include "chrome/gpu/gpu_command_buffer_stub.h" |
| 14 #include "chrome/gpu/gpu_thread.h" |
| 14 | 15 |
| 15 using gpu::Buffer; | 16 using gpu::Buffer; |
| 16 | 17 |
| 17 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
| 18 #define kCompositorWindowOwner L"CompositorWindowOwner" | 19 #define kCompositorWindowOwner L"CompositorWindowOwner" |
| 19 #endif // defined(OS_WIN) | 20 #endif // defined(OS_WIN) |
| 20 | 21 |
| 21 GpuCommandBufferStub::GpuCommandBufferStub( | 22 GpuCommandBufferStub::GpuCommandBufferStub( |
| 22 GpuChannel* channel, | 23 GpuChannel* channel, |
| 23 gfx::PluginWindowHandle handle, | 24 gfx::PluginWindowHandle handle, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 default: | 75 default: |
| 75 return DefWindowProc(hwnd, message, wparam, lparam); | 76 return DefWindowProc(hwnd, message, wparam, lparam); |
| 76 } | 77 } |
| 77 return 0; | 78 return 0; |
| 78 } | 79 } |
| 79 | 80 |
| 80 bool GpuCommandBufferStub::CreateCompositorWindow() { | 81 bool GpuCommandBufferStub::CreateCompositorWindow() { |
| 81 DCHECK(handle_ != gfx::kNullPluginWindow); | 82 DCHECK(handle_ != gfx::kNullPluginWindow); |
| 82 | 83 |
| 83 // Ask the browser to create the the host window. | 84 // Ask the browser to create the the host window. |
| 84 ChildThread* gpu_thread = ChildThread::current(); | 85 GpuThread* gpu_thread = channel_->gpu_thread(); |
| 85 gfx::PluginWindowHandle host_window_id = gfx::kNullPluginWindow; | 86 gfx::PluginWindowHandle host_window_id = gfx::kNullPluginWindow; |
| 86 gpu_thread->Send(new GpuHostMsg_GetCompositorHostWindow( | 87 gpu_thread->Send(new GpuHostMsg_GetCompositorHostWindow( |
| 87 renderer_id_, | 88 renderer_id_, |
| 88 render_view_id_, | 89 render_view_id_, |
| 89 &host_window_id)); | 90 &host_window_id)); |
| 90 if (host_window_id == gfx::kNullPluginWindow) | 91 if (host_window_id == gfx::kNullPluginWindow) |
| 91 return false; | 92 return false; |
| 92 HWND host_window = static_cast<HWND>(host_window_id); | 93 HWND host_window = static_cast<HWND>(host_window_id); |
| 93 | 94 |
| 94 // Create the compositor window itself. | 95 // Create the compositor window itself. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 NULL, | 140 NULL, |
| 140 0, 0, | 141 0, 0, |
| 141 parent_rect.right - parent_rect.left, | 142 parent_rect.right - parent_rect.left, |
| 142 parent_rect.bottom - parent_rect.top, | 143 parent_rect.bottom - parent_rect.top, |
| 143 flags); | 144 flags); |
| 144 compositor_window_ = static_cast<gfx::PluginWindowHandle>(compositor_window); | 145 compositor_window_ = static_cast<gfx::PluginWindowHandle>(compositor_window); |
| 145 return true; | 146 return true; |
| 146 } | 147 } |
| 147 | 148 |
| 148 void GpuCommandBufferStub::OnCompositorWindowPainted() { | 149 void GpuCommandBufferStub::OnCompositorWindowPainted() { |
| 149 ChildThread* gpu_thread = ChildThread::current(); | 150 GpuThread* gpu_thread = channel_->gpu_thread(); |
| 150 gpu_thread->Send(new GpuHostMsg_ScheduleComposite( | 151 gpu_thread->Send(new GpuHostMsg_ScheduleComposite( |
| 151 renderer_id_, render_view_id_)); | 152 renderer_id_, render_view_id_)); |
| 152 } | 153 } |
| 153 #endif // defined(OS_WIN) | 154 #endif // defined(OS_WIN) |
| 154 | 155 |
| 155 | 156 |
| 156 GpuCommandBufferStub::~GpuCommandBufferStub() { | 157 GpuCommandBufferStub::~GpuCommandBufferStub() { |
| 157 if (processor_.get()) { | 158 if (processor_.get()) { |
| 158 processor_->Destroy(); | 159 processor_->Destroy(); |
| 159 } | 160 } |
| 160 #if defined(OS_WIN) | 161 #if defined(OS_WIN) |
| 161 if (compositor_window_) { | 162 if (compositor_window_) { |
| 162 DestroyWindow(static_cast<HWND>(compositor_window_)); | 163 DestroyWindow(static_cast<HWND>(compositor_window_)); |
| 163 compositor_window_ = NULL; | 164 compositor_window_ = NULL; |
| 164 } | 165 } |
| 165 #elif defined(OS_LINUX) | 166 #elif defined(OS_LINUX) |
| 166 ChildThread* gpu_thread = ChildThread::current(); | 167 GpuThread* gpu_thread = channel_->gpu_thread(); |
| 167 gpu_thread->Send( | 168 gpu_thread->Send( |
| 168 new GpuHostMsg_ReleaseXID(handle_)); | 169 new GpuHostMsg_ReleaseXID(handle_)); |
| 169 #endif // defined(OS_WIN) | 170 #endif // defined(OS_WIN) |
| 170 } | 171 } |
| 171 | 172 |
| 172 bool GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) { | 173 bool GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) { |
| 173 bool handled = true; | 174 bool handled = true; |
| 174 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) | 175 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) |
| 175 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Initialize, OnInitialize); | 176 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Initialize, OnInitialize); |
| 176 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetState, OnGetState); | 177 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetState, OnGetState); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 void GpuCommandBufferStub::OnResizeOffscreenFrameBuffer(const gfx::Size& size) { | 326 void GpuCommandBufferStub::OnResizeOffscreenFrameBuffer(const gfx::Size& size) { |
| 326 processor_->ResizeOffscreenFrameBuffer(size); | 327 processor_->ResizeOffscreenFrameBuffer(size); |
| 327 } | 328 } |
| 328 | 329 |
| 329 void GpuCommandBufferStub::OnSwapBuffers() { | 330 void GpuCommandBufferStub::OnSwapBuffers() { |
| 330 Send(new GpuCommandBufferMsg_SwapBuffers(route_id_)); | 331 Send(new GpuCommandBufferMsg_SwapBuffers(route_id_)); |
| 331 } | 332 } |
| 332 | 333 |
| 333 #if defined(OS_MACOSX) | 334 #if defined(OS_MACOSX) |
| 334 void GpuCommandBufferStub::OnSetWindowSize(const gfx::Size& size) { | 335 void GpuCommandBufferStub::OnSetWindowSize(const gfx::Size& size) { |
| 335 ChildThread* gpu_thread = ChildThread::current(); | 336 GpuThread* gpu_thread = channel_->gpu_thread(); |
| 336 // Try using the IOSurface version first. | 337 // Try using the IOSurface version first. |
| 337 uint64 new_backing_store = processor_->SetWindowSizeForIOSurface(size); | 338 uint64 new_backing_store = processor_->SetWindowSizeForIOSurface(size); |
| 338 if (new_backing_store) { | 339 if (new_backing_store) { |
| 339 GpuHostMsg_AcceleratedSurfaceSetIOSurface_Params params; | 340 GpuHostMsg_AcceleratedSurfaceSetIOSurface_Params params; |
| 340 params.renderer_id = renderer_id_; | 341 params.renderer_id = renderer_id_; |
| 341 params.render_view_id = render_view_id_; | 342 params.render_view_id = render_view_id_; |
| 342 params.window = handle_; | 343 params.window = handle_; |
| 343 params.width = size.width(); | 344 params.width = size.width(); |
| 344 params.height = size.height(); | 345 params.height = size.height(); |
| 345 params.identifier = new_backing_store; | 346 params.identifier = new_backing_store; |
| 346 gpu_thread->Send(new GpuHostMsg_AcceleratedSurfaceSetIOSurface(params)); | 347 gpu_thread->Send(new GpuHostMsg_AcceleratedSurfaceSetIOSurface(params)); |
| 347 } else { | 348 } else { |
| 348 // TODO(kbr): figure out what to do here. It wouldn't be difficult | 349 // TODO(kbr): figure out what to do here. It wouldn't be difficult |
| 349 // to support the compositor on 10.5, but the performance would be | 350 // to support the compositor on 10.5, but the performance would be |
| 350 // questionable. | 351 // questionable. |
| 351 NOTREACHED(); | 352 NOTREACHED(); |
| 352 } | 353 } |
| 353 } | 354 } |
| 354 | 355 |
| 355 void GpuCommandBufferStub::SwapBuffersCallback() { | 356 void GpuCommandBufferStub::SwapBuffersCallback() { |
| 356 OnSwapBuffers(); | 357 OnSwapBuffers(); |
| 357 ChildThread* gpu_thread = ChildThread::current(); | 358 GpuThread* gpu_thread = channel_->gpu_thread(); |
| 358 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 359 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
| 359 params.renderer_id = renderer_id_; | 360 params.renderer_id = renderer_id_; |
| 360 params.render_view_id = render_view_id_; | 361 params.render_view_id = render_view_id_; |
| 361 params.window = handle_; | 362 params.window = handle_; |
| 362 params.surface_id = processor_->GetSurfaceId(); | 363 params.surface_id = processor_->GetSurfaceId(); |
| 363 params.route_id = route_id(); | 364 params.route_id = route_id(); |
| 364 params.swap_buffers_count = processor_->swap_buffers_count(); | 365 params.swap_buffers_count = processor_->swap_buffers_count(); |
| 365 gpu_thread->Send(new GpuHostMsg_AcceleratedSurfaceBuffersSwapped(params)); | 366 gpu_thread->Send(new GpuHostMsg_AcceleratedSurfaceBuffersSwapped(params)); |
| 366 } | 367 } |
| 367 | 368 |
| 368 void GpuCommandBufferStub::AcceleratedSurfaceBuffersSwapped( | 369 void GpuCommandBufferStub::AcceleratedSurfaceBuffersSwapped( |
| 369 uint64 swap_buffers_count) { | 370 uint64 swap_buffers_count) { |
| 370 processor_->set_acknowledged_swap_buffers_count(swap_buffers_count); | 371 processor_->set_acknowledged_swap_buffers_count(swap_buffers_count); |
| 371 // Wake up the GpuProcessor to start doing work again. | 372 // Wake up the GpuProcessor to start doing work again. |
| 372 processor_->ScheduleProcessCommands(); | 373 processor_->ScheduleProcessCommands(); |
| 373 } | 374 } |
| 374 #endif // defined(OS_MACOSX) | 375 #endif // defined(OS_MACOSX) |
| 375 | 376 |
| 376 void GpuCommandBufferStub::ResizeCallback(gfx::Size size) { | 377 void GpuCommandBufferStub::ResizeCallback(gfx::Size size) { |
| 377 if (handle_ == gfx::kNullPluginWindow) | 378 if (handle_ == gfx::kNullPluginWindow) |
| 378 return; | 379 return; |
| 379 | 380 |
| 380 #if defined(OS_LINUX) | 381 #if defined(OS_LINUX) |
| 381 ChildThread* gpu_thread = ChildThread::current(); | 382 GpuThread* gpu_thread = channel_->gpu_thread(); |
| 382 bool result = false; | 383 bool result = false; |
| 383 gpu_thread->Send( | 384 gpu_thread->Send( |
| 384 new GpuHostMsg_ResizeXID(handle_, size, &result)); | 385 new GpuHostMsg_ResizeXID(handle_, size, &result)); |
| 385 #elif defined(OS_WIN) | 386 #elif defined(OS_WIN) |
| 386 HWND hwnd = static_cast<HWND>(compositor_window_); | 387 HWND hwnd = static_cast<HWND>(compositor_window_); |
| 387 UINT swp_flags = SWP_NOSENDCHANGING | SWP_NOOWNERZORDER | SWP_NOCOPYBITS | | 388 UINT swp_flags = SWP_NOSENDCHANGING | SWP_NOOWNERZORDER | SWP_NOCOPYBITS | |
| 388 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_DEFERERASE; | 389 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_DEFERERASE; |
| 389 SetWindowPos(hwnd, NULL, 0, 0, size.width(), size.height(), swp_flags); | 390 SetWindowPos(hwnd, NULL, 0, 0, size.width(), size.height(), swp_flags); |
| 390 #endif // defined(OS_LINUX) | 391 #endif // defined(OS_LINUX) |
| 391 } | 392 } |
| 392 | 393 |
| 393 #endif // defined(ENABLE_GPU) | 394 #endif // defined(ENABLE_GPU) |
| OLD | NEW |