OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/process_util.h" | 8 #include "base/process_util.h" |
9 #include "base/shared_memory.h" | 9 #include "base/shared_memory.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 parent_( | 47 parent_( |
48 parent ? parent->AsWeakPtr() : base::WeakPtr<GpuCommandBufferStub>()), | 48 parent ? parent->AsWeakPtr() : base::WeakPtr<GpuCommandBufferStub>()), |
49 initial_size_(size), | 49 initial_size_(size), |
50 disallowed_extensions_(disallowed_extensions), | 50 disallowed_extensions_(disallowed_extensions), |
51 allowed_extensions_(allowed_extensions), | 51 allowed_extensions_(allowed_extensions), |
52 requested_attribs_(attribs), | 52 requested_attribs_(attribs), |
53 parent_texture_id_(parent_texture_id), | 53 parent_texture_id_(parent_texture_id), |
54 route_id_(route_id), | 54 route_id_(route_id), |
55 renderer_id_(renderer_id), | 55 renderer_id_(renderer_id), |
56 render_view_id_(render_view_id), | 56 render_view_id_(render_view_id), |
57 watchdog_(watchdog) { | 57 watchdog_(watchdog), |
58 task_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
58 } | 59 } |
59 | 60 |
60 GpuCommandBufferStub::~GpuCommandBufferStub() { | 61 GpuCommandBufferStub::~GpuCommandBufferStub() { |
61 if (scheduler_.get()) { | 62 if (scheduler_.get()) { |
62 scheduler_->Destroy(); | 63 scheduler_->Destroy(); |
63 } | 64 } |
64 | 65 |
65 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); | 66 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); |
66 gpu_channel_manager->Send(new GpuHostMsg_DestroyCommandBuffer( | 67 gpu_channel_manager->Send(new GpuHostMsg_DestroyCommandBuffer( |
67 handle_, renderer_id_, render_view_id_)); | 68 handle_, renderer_id_, render_view_id_)); |
68 } | 69 } |
69 | 70 |
70 bool GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) { | 71 bool GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) { |
71 bool handled = true; | 72 bool handled = true; |
72 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) | 73 IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) |
73 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Initialize, OnInitialize); | 74 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Initialize, OnInitialize); |
74 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetState, OnGetState); | 75 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetState, OnGetState); |
75 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncGetState, OnAsyncGetState); | |
76 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Flush, OnFlush); | 76 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Flush, OnFlush); |
77 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush); | 77 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush); |
78 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateTransferBuffer, | 78 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateTransferBuffer, |
79 OnCreateTransferBuffer); | 79 OnCreateTransferBuffer); |
80 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_RegisterTransferBuffer, | 80 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_RegisterTransferBuffer, |
81 OnRegisterTransferBuffer); | 81 OnRegisterTransferBuffer); |
82 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyTransferBuffer, | 82 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyTransferBuffer, |
83 OnDestroyTransferBuffer); | 83 OnDestroyTransferBuffer); |
84 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetTransferBuffer, | 84 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_GetTransferBuffer, |
85 OnGetTransferBuffer); | 85 OnGetTransferBuffer); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 if (scheduler_->Initialize( | 128 if (scheduler_->Initialize( |
129 handle_, | 129 handle_, |
130 initial_size_, | 130 initial_size_, |
131 disallowed_extensions_, | 131 disallowed_extensions_, |
132 allowed_extensions_.c_str(), | 132 allowed_extensions_.c_str(), |
133 requested_attribs_, | 133 requested_attribs_, |
134 parent_processor, | 134 parent_processor, |
135 parent_texture_id_)) { | 135 parent_texture_id_)) { |
136 command_buffer_->SetPutOffsetChangeCallback( | 136 command_buffer_->SetPutOffsetChangeCallback( |
137 NewCallback(scheduler_.get(), | 137 NewCallback(scheduler_.get(), |
138 &gpu::GpuScheduler::ProcessCommands)); | 138 &gpu::GpuScheduler::PutChanged)); |
139 scheduler_->SetSwapBuffersCallback( | 139 scheduler_->SetSwapBuffersCallback( |
140 NewCallback(this, &GpuCommandBufferStub::OnSwapBuffers)); | 140 NewCallback(this, &GpuCommandBufferStub::OnSwapBuffers)); |
141 scheduler_->SetLatchCallback(base::Bind( | 141 scheduler_->SetLatchCallback(base::Bind( |
142 &GpuChannel::OnLatchCallback, base::Unretained(channel_), route_id_)); | 142 &GpuChannel::OnLatchCallback, base::Unretained(channel_), route_id_)); |
143 if (watchdog_) | 143 if (watchdog_) |
144 scheduler_->SetCommandProcessedCallback( | 144 scheduler_->SetCommandProcessedCallback( |
145 NewCallback(this, &GpuCommandBufferStub::OnCommandProcessed)); | 145 NewCallback(this, &GpuCommandBufferStub::OnCommandProcessed)); |
146 | 146 |
147 #if defined(OS_MACOSX) | 147 #if defined(OS_MACOSX) |
148 if (handle_) { | 148 if (handle_) { |
(...skipping 20 matching lines...) Expand all Loading... | |
169 } | 169 } |
170 } | 170 } |
171 | 171 |
172 void GpuCommandBufferStub::OnCommandProcessed() { | 172 void GpuCommandBufferStub::OnCommandProcessed() { |
173 if (watchdog_) | 173 if (watchdog_) |
174 watchdog_->CheckArmed(); | 174 watchdog_->CheckArmed(); |
175 } | 175 } |
176 | 176 |
177 void GpuCommandBufferStub::OnGetState(gpu::CommandBuffer::State* state) { | 177 void GpuCommandBufferStub::OnGetState(gpu::CommandBuffer::State* state) { |
178 *state = command_buffer_->GetState(); | 178 *state = command_buffer_->GetState(); |
179 } | 179 if (state->error == gpu::error::kLostContext && |
180 | 180 gfx::GLContext::LosesAllContextsOnContextLost()) |
181 void GpuCommandBufferStub::OnAsyncGetState() { | 181 channel_->LoseAllContexts(); |
182 gpu::CommandBuffer::State state = command_buffer_->GetState(); | |
183 Send(new GpuCommandBufferMsg_UpdateState(route_id_, state)); | |
184 } | 182 } |
185 | 183 |
186 void GpuCommandBufferStub::OnFlush(int32 put_offset, | 184 void GpuCommandBufferStub::OnFlush(int32 put_offset, |
185 int32 last_known_get, | |
187 gpu::CommandBuffer::State* state) { | 186 gpu::CommandBuffer::State* state) { |
188 GPU_TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnFlush"); | 187 GPU_TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnFlush"); |
189 *state = command_buffer_->FlushSync(put_offset); | 188 *state = command_buffer_->FlushSync(put_offset, last_known_get); |
190 if (state->error == gpu::error::kLostContext && | 189 if (state->error == gpu::error::kLostContext && |
191 gfx::GLContext::LosesAllContextsOnContextLost()) | 190 gfx::GLContext::LosesAllContextsOnContextLost()) |
192 channel_->LoseAllContexts(); | 191 channel_->LoseAllContexts(); |
193 } | 192 } |
194 | 193 |
195 void GpuCommandBufferStub::OnAsyncFlush(int32 put_offset) { | 194 void GpuCommandBufferStub::OnAsyncFlush(int32 put_offset) { |
196 GPU_TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnAsyncFlush"); | 195 GPU_TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnAsyncFlush"); |
197 gpu::CommandBuffer::State state = command_buffer_->FlushSync(put_offset); | 196 command_buffer_->Flush(put_offset); |
198 if (state.error == gpu::error::kLostContext && | 197 // TODO(piman): Do this everytime the scheduler finishes processing a batch of |
199 gfx::GLContext::LosesAllContextsOnContextLost()) | 198 // commands. |
200 channel_->LoseAllContexts(); | 199 MessageLoop::current()->PostTask(FROM_HERE, |
201 else | 200 task_factory_.NewRunnableMethod(&GpuCommandBufferStub::ReportState)); |
202 Send(new GpuCommandBufferMsg_UpdateState(route_id_, state)); | |
203 } | 201 } |
204 | 202 |
205 void GpuCommandBufferStub::OnCreateTransferBuffer(int32 size, | 203 void GpuCommandBufferStub::OnCreateTransferBuffer(int32 size, |
206 int32 id_request, | 204 int32 id_request, |
207 int32* id) { | 205 int32* id) { |
208 *id = command_buffer_->CreateTransferBuffer(size, id_request); | 206 *id = command_buffer_->CreateTransferBuffer(size, id_request); |
209 } | 207 } |
210 | 208 |
211 void GpuCommandBufferStub::OnRegisterTransferBuffer( | 209 void GpuCommandBufferStub::OnRegisterTransferBuffer( |
212 base::SharedMemoryHandle transfer_buffer, | 210 base::SharedMemoryHandle transfer_buffer, |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 gfx::GLContext* context = scheduler_->decoder()->GetGLContext(); | 337 gfx::GLContext* context = scheduler_->decoder()->GetGLContext(); |
340 context->ReleaseCurrent(); | 338 context->ReleaseCurrent(); |
341 gfx::GLSurface* surface = context->GetSurface(); | 339 gfx::GLSurface* surface = context->GetSurface(); |
342 if (surface) { | 340 if (surface) { |
343 surface->Destroy(); | 341 surface->Destroy(); |
344 surface->Initialize(); | 342 surface->Initialize(); |
345 } | 343 } |
346 #endif | 344 #endif |
347 } | 345 } |
348 | 346 |
347 void GpuCommandBufferStub::ReportState() { | |
348 gpu::CommandBuffer::State state = command_buffer_->GetState(); | |
349 if (state.error == gpu::error::kLostContext && | |
350 gfx::GLContext::LosesAllContextsOnContextLost()) | |
351 channel_->LoseAllContexts(); | |
352 else { | |
brettw
2011/04/28 21:21:05
Need {} for the top arm since you use them for the
piman
2011/04/28 21:31:13
Done.
| |
353 IPC::Message* msg = new GpuCommandBufferMsg_UpdateState(route_id_, state); | |
354 msg->set_unblock(true); | |
355 Send(msg); | |
356 } | |
357 } | |
358 | |
349 #endif // defined(ENABLE_GPU) | 359 #endif // defined(ENABLE_GPU) |
OLD | NEW |