| 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" |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 IPC_END_MESSAGE_MAP() | 185 IPC_END_MESSAGE_MAP() |
| 186 DCHECK(handled); | 186 DCHECK(handled); |
| 187 return handled; | 187 return handled; |
| 188 } | 188 } |
| 189 | 189 |
| 190 bool GpuCommandBufferStub::Send(IPC::Message* message) { | 190 bool GpuCommandBufferStub::Send(IPC::Message* message) { |
| 191 return channel_->Send(message); | 191 return channel_->Send(message); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void GpuCommandBufferStub::OnInitialize( | 194 void GpuCommandBufferStub::OnInitialize( |
| 195 base::SharedMemoryHandle ring_buffer, |
| 195 int32 size, | 196 int32 size, |
| 196 base::SharedMemoryHandle* ring_buffer) { | 197 bool* result) { |
| 197 DCHECK(!command_buffer_.get()); | 198 DCHECK(!command_buffer_.get()); |
| 198 | 199 |
| 199 *ring_buffer = base::SharedMemory::NULLHandle(); | 200 *result = false; |
| 200 | 201 |
| 201 command_buffer_.reset(new gpu::CommandBufferService); | 202 command_buffer_.reset(new gpu::CommandBufferService); |
| 202 | 203 |
| 203 // Create the child window, if needed | 204 // Create the child window, if needed |
| 204 #if defined(OS_WIN) | 205 #if defined(OS_WIN) |
| 205 gfx::PluginWindowHandle output_window_handle; | 206 gfx::PluginWindowHandle output_window_handle; |
| 206 if (handle_) { | 207 if (handle_) { |
| 207 if (!CreateCompositorWindow()) { | 208 if (!CreateCompositorWindow()) { |
| 208 return; | 209 return; |
| 209 } | 210 } |
| 210 output_window_handle = compositor_window_; | 211 output_window_handle = compositor_window_; |
| 211 } else { | 212 } else { |
| 212 output_window_handle = handle_; | 213 output_window_handle = handle_; |
| 213 } | 214 } |
| 214 #else | 215 #else |
| 215 gfx::PluginWindowHandle output_window_handle = handle_; | 216 gfx::PluginWindowHandle output_window_handle = handle_; |
| 216 #endif // defined(OS_WIN) | 217 #endif // defined(OS_WIN) |
| 217 | 218 |
| 219 #if defined(OS_WIN) |
| 220 // Windows dups the shared memory handle it receives into the current process |
| 221 // and closes it when this variable goes out of scope. |
| 222 base::SharedMemory shared_memory(ring_buffer, |
| 223 false, |
| 224 channel_->renderer_process()); |
| 225 #else |
| 226 // POSIX receives a dup of the shared memory handle and closes the dup when |
| 227 // this variable goes out of scope. |
| 228 base::SharedMemory shared_memory(ring_buffer, false); |
| 229 #endif |
| 230 |
| 218 // Initialize the CommandBufferService and GPUProcessor. | 231 // Initialize the CommandBufferService and GPUProcessor. |
| 219 if (command_buffer_->Initialize(size)) { | 232 if (command_buffer_->Initialize(&shared_memory, size)) { |
| 220 Buffer buffer = command_buffer_->GetRingBuffer(); | 233 gpu::GPUProcessor* parent_processor = |
| 221 if (buffer.shared_memory) { | 234 parent_ ? parent_->processor_.get() : NULL; |
| 222 gpu::GPUProcessor* parent_processor = | 235 processor_.reset(new gpu::GPUProcessor(command_buffer_.get(), NULL)); |
| 223 parent_ ? parent_->processor_.get() : NULL; | 236 if (processor_->Initialize( |
| 224 processor_.reset(new gpu::GPUProcessor(command_buffer_.get(), NULL)); | 237 output_window_handle, |
| 225 if (processor_->Initialize( | 238 initial_size_, |
| 226 output_window_handle, | 239 allowed_extensions_.c_str(), |
| 227 initial_size_, | 240 requested_attribs_, |
| 228 allowed_extensions_.c_str(), | 241 parent_processor, |
| 229 requested_attribs_, | 242 parent_texture_id_)) { |
| 230 parent_processor, | 243 command_buffer_->SetPutOffsetChangeCallback( |
| 231 parent_texture_id_)) { | 244 NewCallback(processor_.get(), |
| 232 command_buffer_->SetPutOffsetChangeCallback( | 245 &gpu::GPUProcessor::ProcessCommands)); |
| 233 NewCallback(processor_.get(), | 246 processor_->SetSwapBuffersCallback( |
| 234 &gpu::GPUProcessor::ProcessCommands)); | 247 NewCallback(this, &GpuCommandBufferStub::OnSwapBuffers)); |
| 248 |
| 249 #if defined(OS_MACOSX) |
| 250 if (handle_) { |
| 251 // This context conceptually puts its output directly on the |
| 252 // screen, rendered by the accelerated plugin layer in |
| 253 // RenderWidgetHostViewMac. Set up a pathway to notify the |
| 254 // browser process when its contents change. |
| 235 processor_->SetSwapBuffersCallback( | 255 processor_->SetSwapBuffersCallback( |
| 236 NewCallback(this, &GpuCommandBufferStub::OnSwapBuffers)); | 256 NewCallback(this, |
| 237 | 257 &GpuCommandBufferStub::SwapBuffersCallback)); |
| 238 // Assume service is responsible for duplicating the handle from the | 258 } |
| 239 // calling process. | |
| 240 buffer.shared_memory->ShareToProcess(channel_->renderer_process(), | |
| 241 ring_buffer); | |
| 242 #if defined(OS_MACOSX) | |
| 243 if (handle_) { | |
| 244 // This context conceptually puts its output directly on the | |
| 245 // screen, rendered by the accelerated plugin layer in | |
| 246 // RenderWidgetHostViewMac. Set up a pathway to notify the | |
| 247 // browser process when its contents change. | |
| 248 processor_->SetSwapBuffersCallback( | |
| 249 NewCallback(this, | |
| 250 &GpuCommandBufferStub::SwapBuffersCallback)); | |
| 251 } | |
| 252 #endif // defined(OS_MACOSX) | 259 #endif // defined(OS_MACOSX) |
| 253 | 260 |
| 254 // Set up a pathway for resizing the output window or framebuffer at the | 261 // Set up a pathway for resizing the output window or framebuffer at the |
| 255 // right time relative to other GL commands. | 262 // right time relative to other GL commands. |
| 256 processor_->SetResizeCallback( | 263 processor_->SetResizeCallback( |
| 257 NewCallback(this, &GpuCommandBufferStub::ResizeCallback)); | 264 NewCallback(this, &GpuCommandBufferStub::ResizeCallback)); |
| 258 } else { | 265 |
| 259 processor_.reset(); | 266 *result = true; |
| 260 command_buffer_.reset(); | 267 } else { |
| 261 } | 268 processor_.reset(); |
| 269 command_buffer_.reset(); |
| 262 } | 270 } |
| 263 } | 271 } |
| 264 } | 272 } |
| 265 | 273 |
| 266 void GpuCommandBufferStub::OnGetState(gpu::CommandBuffer::State* state) { | 274 void GpuCommandBufferStub::OnGetState(gpu::CommandBuffer::State* state) { |
| 267 *state = command_buffer_->GetState(); | 275 *state = command_buffer_->GetState(); |
| 268 } | 276 } |
| 269 | 277 |
| 270 void GpuCommandBufferStub::OnAsyncGetState() { | 278 void GpuCommandBufferStub::OnAsyncGetState() { |
| 271 gpu::CommandBuffer::State state = command_buffer_->GetState(); | 279 gpu::CommandBuffer::State state = command_buffer_->GetState(); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 #elif defined(OS_WIN) | 407 #elif defined(OS_WIN) |
| 400 HWND hwnd = static_cast<HWND>(compositor_window_); | 408 HWND hwnd = static_cast<HWND>(compositor_window_); |
| 401 UINT swp_flags = SWP_NOSENDCHANGING | SWP_NOOWNERZORDER | SWP_NOCOPYBITS | | 409 UINT swp_flags = SWP_NOSENDCHANGING | SWP_NOOWNERZORDER | SWP_NOCOPYBITS | |
| 402 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_DEFERERASE; | 410 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_DEFERERASE; |
| 403 SetWindowPos(hwnd, NULL, 0, 0, size.width(), size.height(), swp_flags); | 411 SetWindowPos(hwnd, NULL, 0, 0, size.width(), size.height(), swp_flags); |
| 404 #endif // defined(OS_LINUX) | 412 #endif // defined(OS_LINUX) |
| 405 } | 413 } |
| 406 } | 414 } |
| 407 | 415 |
| 408 #endif // defined(ENABLE_GPU) | 416 #endif // defined(ENABLE_GPU) |
| OLD | NEW |