Chromium Code Reviews| 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 | 14 |
| 15 using gpu::Buffer; | 15 using gpu::Buffer; |
| 16 | 16 |
| 17 #define kCompositorWindowOwner L"kCompositorWindowOwner" | |
|
apatrick_chromium
2010/11/19 23:09:51
nit: make this const wchar_t[]
nduca
2010/11/20 00:28:49
Other code that does this follows the define patte
| |
| 18 | |
| 17 GpuCommandBufferStub::GpuCommandBufferStub( | 19 GpuCommandBufferStub::GpuCommandBufferStub( |
| 18 GpuChannel* channel, | 20 GpuChannel* channel, |
| 19 gfx::PluginWindowHandle handle, | 21 gfx::PluginWindowHandle handle, |
| 20 GpuCommandBufferStub* parent, | 22 GpuCommandBufferStub* parent, |
| 21 const gfx::Size& size, | 23 const gfx::Size& size, |
| 22 const std::string& allowed_extensions, | 24 const std::string& allowed_extensions, |
| 23 const std::vector<int32>& attribs, | 25 const std::vector<int32>& attribs, |
| 24 uint32 parent_texture_id, | 26 uint32 parent_texture_id, |
| 25 int32 route_id, | 27 int32 route_id, |
| 26 int32 renderer_id, | 28 int32 renderer_id, |
| 27 int32 render_view_id) | 29 int32 render_view_id) |
| 28 : channel_(channel), | 30 : channel_(channel), |
| 29 handle_(handle), | 31 handle_(handle), |
| 30 parent_( | 32 parent_( |
| 31 parent ? parent->AsWeakPtr() : base::WeakPtr<GpuCommandBufferStub>()), | 33 parent ? parent->AsWeakPtr() : base::WeakPtr<GpuCommandBufferStub>()), |
| 32 initial_size_(size), | 34 initial_size_(size), |
| 33 allowed_extensions_(allowed_extensions), | 35 allowed_extensions_(allowed_extensions), |
| 34 requested_attribs_(attribs), | 36 requested_attribs_(attribs), |
| 35 parent_texture_id_(parent_texture_id), | 37 parent_texture_id_(parent_texture_id), |
| 36 route_id_(route_id), | 38 route_id_(route_id), |
| 37 renderer_id_(renderer_id), | 39 renderer_id_(renderer_id), |
| 38 render_view_id_(render_view_id) { | 40 render_view_id_(render_view_id) { |
| 39 } | 41 } |
| 40 | 42 |
| 43 #if defined(OS_WIN) | |
| 44 static LRESULT CALLBACK CompositorWindowProc( | |
| 45 HWND hwnd, | |
| 46 UINT message, | |
| 47 WPARAM wparam, | |
| 48 LPARAM lparam) { | |
| 49 switch (message) { | |
| 50 case WM_ERASEBKGND: | |
| 51 return 0; | |
| 52 case WM_DESTROY: | |
| 53 return 0; | |
| 54 case WM_PAINT: { | |
| 55 PAINTSTRUCT paint; | |
| 56 BeginPaint(hwnd, &paint); | |
|
apatrick_chromium
2010/11/19 23:09:51
Check this doesn't return null and don't call EndP
nduca
2010/11/20 00:28:49
Done.
| |
| 57 HANDLE h = GetProp(hwnd, kCompositorWindowOwner); | |
|
apatrick_chromium
2010/11/19 23:09:51
Check this does not return null before calling OnC
nduca
2010/11/20 00:28:49
Done.
| |
| 58 GpuCommandBufferStub* stub = reinterpret_cast<GpuCommandBufferStub*>(h); | |
| 59 stub->OnCompositorWindowPainted(); | |
| 60 EndPaint(hwnd, &paint); | |
| 61 break; | |
| 62 } | |
| 63 default: | |
| 64 return DefWindowProc(hwnd, message, wparam, lparam); | |
| 65 } | |
| 66 return 0; | |
| 67 } | |
| 68 | |
| 69 void GpuCommandBufferStub::CreateCompositorWindow() { | |
| 70 DCHECK(handle_ != gfx::kNullPluginWindow); | |
| 71 | |
| 72 // Ask the browser to create the the host window. | |
| 73 ChildThread* gpu_thread = ChildThread::current(); | |
|
apatrick_chromium
2010/11/19 23:09:51
nit: add a pointer from GpuCommandBufferStub to Gp
nduca
2010/11/20 00:28:49
I don't see why that would affect this call. Are y
| |
| 74 gfx::PluginWindowHandle host_window_id; | |
| 75 gpu_thread->Send(new GpuHostMsg_CreateCompositorHostWindow( | |
| 76 renderer_id_, | |
| 77 render_view_id_, | |
| 78 &host_window_id)); | |
| 79 HWND host_window = static_cast<HWND>(host_window_id); | |
|
apatrick_chromium
2010/11/19 23:09:51
If Send fails, host_window_id will be uninitialize
nduca
2010/11/20 00:28:49
If send fails, it means browser is dead. We're ter
| |
| 80 | |
| 81 // Create the compositor window itself. | |
| 82 DCHECK(host_window); | |
| 83 static ATOM window_class = 0; | |
| 84 if (!window_class) { | |
| 85 WNDCLASSEX wcex; | |
| 86 wcex.cbSize = sizeof(wcex); | |
| 87 wcex.style = 0; | |
| 88 wcex.lpfnWndProc = CompositorWindowProc; | |
| 89 wcex.cbClsExtra = 0; | |
| 90 wcex.cbWndExtra = 0; | |
| 91 wcex.hInstance = GetModuleHandle(NULL); | |
| 92 wcex.hIcon = 0; | |
| 93 wcex.hCursor = 0; | |
| 94 wcex.hbrBackground = NULL; | |
| 95 wcex.lpszMenuName = 0; | |
| 96 wcex.lpszClassName = L"CompositorWindowClass"; | |
| 97 wcex.hIconSm = 0; | |
| 98 window_class = RegisterClassEx(&wcex); | |
| 99 DCHECK(window_class); | |
| 100 } | |
| 101 | |
| 102 HWND compositor_window = CreateWindowEx( | |
| 103 WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR, | |
| 104 MAKEINTATOM(window_class), | |
| 105 0, | |
| 106 WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_DISABLED, | |
| 107 0, 0, | |
| 108 0, 0, | |
| 109 host_window, | |
| 110 0, | |
| 111 GetModuleHandle(NULL), | |
| 112 0); | |
| 113 DCHECK(compositor_window); | |
|
apatrick_chromium
2010/11/19 23:09:51
I think this might legitimately fail. It might be
nduca
2010/11/20 00:28:49
Done.
| |
| 114 SetProp(compositor_window, kCompositorWindowOwner, | |
| 115 reinterpret_cast<HANDLE>(this)); | |
| 116 | |
| 117 RECT parent_rect; | |
| 118 GetClientRect(host_window, &parent_rect); | |
|
apatrick_chromium
2010/11/19 23:09:51
If the host window is destroyed for any reason, th
nduca
2010/11/20 00:28:49
Done.
| |
| 119 | |
| 120 UINT flags = SWP_NOSENDCHANGING | SWP_NOCOPYBITS | SWP_NOZORDER | | |
| 121 SWP_NOACTIVATE | SWP_DEFERERASE | SWP_SHOWWINDOW; | |
| 122 SetWindowPos(compositor_window, | |
|
apatrick_chromium
2010/11/19 23:09:51
nit: can you drop this argument to the next line a
| |
| 123 NULL, | |
| 124 0, 0, | |
| 125 parent_rect.right - parent_rect.left, | |
| 126 parent_rect.bottom - parent_rect.top, | |
| 127 flags); | |
| 128 compositor_window_ = static_cast<gfx::PluginWindowHandle>(compositor_window); | |
| 129 } | |
| 130 | |
| 131 void GpuCommandBufferStub::OnCompositorWindowPainted() { | |
| 132 ChildThread* gpu_thread = ChildThread::current(); | |
|
apatrick_chromium
2010/11/19 23:09:51
See comment about GpuThread above.
nduca
2010/11/20 00:28:49
Not sold on this being necessary.
| |
| 133 gpu_thread->Send(new GpuHostMsg_ScheduleComposite( | |
| 134 renderer_id_, render_view_id_)); | |
| 135 } | |
| 136 #endif // defined(OS_WIN) | |
| 137 | |
| 138 | |
| 41 GpuCommandBufferStub::~GpuCommandBufferStub() { | 139 GpuCommandBufferStub::~GpuCommandBufferStub() { |
| 42 if (processor_.get()) { | 140 if (processor_.get()) { |
| 43 processor_->Destroy(); | 141 processor_->Destroy(); |
| 44 } | 142 } |
| 143 #if defined(OS_WIN) | |
| 144 if (compositor_window_) { | |
| 145 RemoveProp(compositor_window_, kCompositorWindowOwner); | |
| 146 DestroyWindow(static_cast<HWND>(compositor_window_)); | |
| 147 compositor_window_ = NULL; | |
| 148 } | |
| 149 #endif | |
| 45 } | 150 } |
| 46 | 151 |
| 47 void GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) { | 152 void GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) { |
| 48 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) | 153 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) |
| 49 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Initialize, OnInitialize); | 154 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Initialize, OnInitialize); |
| 50 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetState, OnGetState); | 155 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetState, OnGetState); |
| 51 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncGetState, OnAsyncGetState); | 156 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncGetState, OnAsyncGetState); |
| 52 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Flush, OnFlush); | 157 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Flush, OnFlush); |
| 53 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush); | 158 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush); |
| 54 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateTransferBuffer, | 159 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateTransferBuffer, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 72 | 177 |
| 73 void GpuCommandBufferStub::OnInitialize( | 178 void GpuCommandBufferStub::OnInitialize( |
| 74 int32 size, | 179 int32 size, |
| 75 base::SharedMemoryHandle* ring_buffer) { | 180 base::SharedMemoryHandle* ring_buffer) { |
| 76 DCHECK(!command_buffer_.get()); | 181 DCHECK(!command_buffer_.get()); |
| 77 | 182 |
| 78 *ring_buffer = base::SharedMemory::NULLHandle(); | 183 *ring_buffer = base::SharedMemory::NULLHandle(); |
| 79 | 184 |
| 80 command_buffer_.reset(new gpu::CommandBufferService); | 185 command_buffer_.reset(new gpu::CommandBufferService); |
| 81 | 186 |
| 187 // Create the child window, if needed | |
| 188 #if defined(OS_WIN) | |
| 189 CreateCompositorWindow(); | |
|
apatrick_chromium
2010/11/19 23:09:51
Check if this fails.
nduca
2010/11/20 00:28:49
Done.
| |
| 190 gfx::PluginWindowHandle output_window_handle = compositor_window_; | |
| 191 #else | |
| 192 gfx::PluginWindowHandle output_window_handle = handle_; | |
| 193 #endif | |
| 194 | |
| 82 // Initialize the CommandBufferService and GPUProcessor. | 195 // Initialize the CommandBufferService and GPUProcessor. |
| 83 if (command_buffer_->Initialize(size)) { | 196 if (command_buffer_->Initialize(size)) { |
| 84 Buffer buffer = command_buffer_->GetRingBuffer(); | 197 Buffer buffer = command_buffer_->GetRingBuffer(); |
| 85 if (buffer.shared_memory) { | 198 if (buffer.shared_memory) { |
| 86 gpu::GPUProcessor* parent_processor = | 199 gpu::GPUProcessor* parent_processor = |
| 87 parent_ ? parent_->processor_.get() : NULL; | 200 parent_ ? parent_->processor_.get() : NULL; |
| 88 processor_.reset(new gpu::GPUProcessor(command_buffer_.get(), NULL)); | 201 processor_.reset(new gpu::GPUProcessor(command_buffer_.get(), NULL)); |
| 89 if (processor_->Initialize( | 202 if (processor_->Initialize( |
| 90 handle_, | 203 output_window_handle, |
| 91 initial_size_, | 204 initial_size_, |
| 92 allowed_extensions_.c_str(), | 205 allowed_extensions_.c_str(), |
| 93 requested_attribs_, | 206 requested_attribs_, |
| 94 parent_processor, | 207 parent_processor, |
| 95 parent_texture_id_)) { | 208 parent_texture_id_)) { |
| 96 command_buffer_->SetPutOffsetChangeCallback( | 209 command_buffer_->SetPutOffsetChangeCallback( |
| 97 NewCallback(processor_.get(), | 210 NewCallback(processor_.get(), |
| 98 &gpu::GPUProcessor::ProcessCommands)); | 211 &gpu::GPUProcessor::ProcessCommands)); |
| 99 processor_->SetSwapBuffersCallback( | 212 processor_->SetSwapBuffersCallback( |
| 100 NewCallback(this, &GpuCommandBufferStub::OnSwapBuffers)); | 213 NewCallback(this, &GpuCommandBufferStub::OnSwapBuffers)); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 } | 310 } |
| 198 | 311 |
| 199 void GpuCommandBufferStub::SwapBuffersCallback() { | 312 void GpuCommandBufferStub::SwapBuffersCallback() { |
| 200 ChildThread* gpu_thread = ChildThread::current(); | 313 ChildThread* gpu_thread = ChildThread::current(); |
| 201 gpu_thread->Send(new GpuHostMsg_AcceleratedSurfaceBuffersSwapped( | 314 gpu_thread->Send(new GpuHostMsg_AcceleratedSurfaceBuffersSwapped( |
| 202 renderer_id_, render_view_id_, handle_, processor_->GetSurfaceId())); | 315 renderer_id_, render_view_id_, handle_, processor_->GetSurfaceId())); |
| 203 } | 316 } |
| 204 #endif // defined(OS_MACOSX) | 317 #endif // defined(OS_MACOSX) |
| 205 | 318 |
| 206 #endif // ENABLE_GPU | 319 #endif // ENABLE_GPU |
| OLD | NEW |