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 "chrome/common/gpu_messages.h" | 10 #include "chrome/common/gpu_messages.h" |
10 #include "chrome/gpu/gpu_channel.h" | 11 #include "chrome/gpu/gpu_channel.h" |
11 #include "chrome/gpu/gpu_command_buffer_stub.h" | 12 #include "chrome/gpu/gpu_command_buffer_stub.h" |
12 | 13 |
13 using gpu::Buffer; | 14 using gpu::Buffer; |
14 | 15 |
15 GpuCommandBufferStub::GpuCommandBufferStub(GpuChannel* channel, | 16 GpuCommandBufferStub::GpuCommandBufferStub(GpuChannel* channel, |
| 17 gfx::NativeView view, |
| 18 GpuCommandBufferStub* parent, |
| 19 const gfx::Size& size, |
| 20 uint32 parent_texture_id, |
16 int32 route_id) | 21 int32 route_id) |
17 : channel_(channel), | 22 : channel_(channel), |
| 23 view_(view), |
| 24 parent_(parent), |
| 25 initial_size_(size), |
| 26 parent_texture_id_(parent_texture_id), |
18 route_id_(route_id) { | 27 route_id_(route_id) { |
19 } | 28 } |
20 | 29 |
21 GpuCommandBufferStub::~GpuCommandBufferStub() { | 30 GpuCommandBufferStub::~GpuCommandBufferStub() { |
| 31 if (processor_.get()) { |
| 32 processor_->Destroy(); |
| 33 } |
22 } | 34 } |
23 | 35 |
24 void GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) { | 36 void GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) { |
25 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) | 37 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) |
26 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Initialize, OnInitialize); | 38 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Initialize, OnInitialize); |
27 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetState, OnGetState); | 39 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetState, OnGetState); |
28 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncGetState, OnAsyncGetState); | 40 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncGetState, OnAsyncGetState); |
29 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Flush, OnFlush); | 41 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Flush, OnFlush); |
30 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush); | 42 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush); |
31 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateTransferBuffer, | 43 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateTransferBuffer, |
32 OnCreateTransferBuffer); | 44 OnCreateTransferBuffer); |
33 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyTransferBuffer, | 45 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyTransferBuffer, |
34 OnDestroyTransferBuffer); | 46 OnDestroyTransferBuffer); |
35 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetTransferBuffer, | 47 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetTransferBuffer, |
36 OnGetTransferBuffer); | 48 OnGetTransferBuffer); |
| 49 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_ResizeOffscreenFrameBuffer, |
| 50 OnResizeOffscreenFrameBuffer); |
37 IPC_MESSAGE_UNHANDLED_ERROR() | 51 IPC_MESSAGE_UNHANDLED_ERROR() |
38 IPC_END_MESSAGE_MAP() | 52 IPC_END_MESSAGE_MAP() |
39 } | 53 } |
40 | 54 |
41 bool GpuCommandBufferStub::Send(IPC::Message* message) { | 55 bool GpuCommandBufferStub::Send(IPC::Message* message) { |
42 return channel_->Send(message); | 56 return channel_->Send(message); |
43 } | 57 } |
44 | 58 |
45 void GpuCommandBufferStub::OnInitialize( | 59 void GpuCommandBufferStub::OnInitialize( |
46 int32 size, | 60 int32 size, |
47 base::SharedMemoryHandle* ring_buffer) { | 61 base::SharedMemoryHandle* ring_buffer) { |
48 DCHECK(!command_buffer_.get()); | 62 DCHECK(!command_buffer_.get()); |
49 | 63 |
50 *ring_buffer = base::SharedMemory::NULLHandle(); | 64 *ring_buffer = base::SharedMemory::NULLHandle(); |
51 | 65 |
52 command_buffer_.reset(new gpu::CommandBufferService); | 66 command_buffer_.reset(new gpu::CommandBufferService); |
53 | 67 |
54 // Initialize the CommandBufferService and GPUProcessor. | 68 // Initialize the CommandBufferService and GPUProcessor. |
55 if (command_buffer_->Initialize(size)) { | 69 if (command_buffer_->Initialize(size)) { |
56 Buffer buffer = command_buffer_->GetRingBuffer(); | 70 Buffer buffer = command_buffer_->GetRingBuffer(); |
57 if (buffer.shared_memory) { | 71 if (buffer.shared_memory) { |
58 processor_ = new gpu::GPUProcessor(command_buffer_.get()); | 72 gpu::GPUProcessor* parent_processor = |
59 if (processor_->Initialize(gfx::kNullPluginWindow)) { | 73 parent_ ? parent_->processor_.get() : NULL; |
| 74 processor_.reset(new gpu::GPUProcessor(command_buffer_.get())); |
| 75 // TODO(apatrick): The reinterpret_cast below is only valid on windows. |
| 76 #if !defined(OS_WIN) |
| 77 DCHECK_EQ(view_, static_cast<gfx::NativeView>(0)); |
| 78 #endif |
| 79 if (processor_->Initialize( |
| 80 reinterpret_cast<gfx::PluginWindowHandle>(view_), |
| 81 parent_processor, |
| 82 initial_size_, |
| 83 parent_texture_id_)) { |
60 command_buffer_->SetPutOffsetChangeCallback( | 84 command_buffer_->SetPutOffsetChangeCallback( |
61 NewCallback(processor_.get(), | 85 NewCallback(processor_.get(), |
62 &gpu::GPUProcessor::ProcessCommands)); | 86 &gpu::GPUProcessor::ProcessCommands)); |
63 | 87 |
64 // Assume service is responsible for duplicating the handle from the | 88 // Assume service is responsible for duplicating the handle from the |
65 // calling process. | 89 // calling process. |
66 buffer.shared_memory->ShareToProcess(channel_->renderer_handle(), | 90 buffer.shared_memory->ShareToProcess(channel_->renderer_handle(), |
67 ring_buffer); | 91 ring_buffer); |
68 } else { | 92 } else { |
69 processor_ = NULL; | 93 processor_.reset(); |
70 command_buffer_.reset(); | 94 command_buffer_.reset(); |
71 } | 95 } |
72 } | 96 } |
73 } | 97 } |
74 } | 98 } |
75 | 99 |
76 void GpuCommandBufferStub::OnGetState(gpu::CommandBuffer::State* state) { | 100 void GpuCommandBufferStub::OnGetState(gpu::CommandBuffer::State* state) { |
77 *state = command_buffer_->GetState(); | 101 *state = command_buffer_->GetState(); |
78 } | 102 } |
79 | 103 |
(...skipping 30 matching lines...) Expand all Loading... |
110 Buffer buffer = command_buffer_->GetTransferBuffer(id); | 134 Buffer buffer = command_buffer_->GetTransferBuffer(id); |
111 if (buffer.shared_memory) { | 135 if (buffer.shared_memory) { |
112 // Assume service is responsible for duplicating the handle to the calling | 136 // Assume service is responsible for duplicating the handle to the calling |
113 // process. | 137 // process. |
114 buffer.shared_memory->ShareToProcess(channel_->renderer_handle(), | 138 buffer.shared_memory->ShareToProcess(channel_->renderer_handle(), |
115 transfer_buffer); | 139 transfer_buffer); |
116 *size = buffer.shared_memory->max_size(); | 140 *size = buffer.shared_memory->max_size(); |
117 } | 141 } |
118 } | 142 } |
119 | 143 |
| 144 void GpuCommandBufferStub::OnResizeOffscreenFrameBuffer(const gfx::Size& size) { |
| 145 processor_->ResizeOffscreenFrameBuffer(size); |
| 146 } |
| 147 |
120 #endif // ENABLE_GPU | 148 #endif // ENABLE_GPU |
OLD | NEW |