OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "components/mus/gles2/command_buffer_local.h" | 5 #include "components/mus/gles2/command_buffer_local.h" |
6 | 6 |
7 #include "base/atomic_sequence_num.h" | |
7 #include "base/bind.h" | 8 #include "base/bind.h" |
8 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
9 #include "components/mus/gles2/command_buffer_local_client.h" | 10 #include "components/mus/gles2/command_buffer_local_client.h" |
10 #include "components/mus/gles2/gpu_memory_tracker.h" | 11 #include "components/mus/gles2/gpu_memory_tracker.h" |
11 #include "components/mus/gles2/mojo_gpu_memory_buffer.h" | 12 #include "components/mus/gles2/mojo_gpu_memory_buffer.h" |
12 #include "gpu/command_buffer/service/command_buffer_service.h" | 13 #include "gpu/command_buffer/service/command_buffer_service.h" |
13 #include "gpu/command_buffer/service/context_group.h" | 14 #include "gpu/command_buffer/service/context_group.h" |
14 #include "gpu/command_buffer/service/gpu_scheduler.h" | 15 #include "gpu/command_buffer/service/gpu_scheduler.h" |
15 #include "gpu/command_buffer/service/image_factory.h" | 16 #include "gpu/command_buffer/service/image_factory.h" |
16 #include "gpu/command_buffer/service/image_manager.h" | 17 #include "gpu/command_buffer/service/image_manager.h" |
17 #include "gpu/command_buffer/service/memory_tracking.h" | 18 #include "gpu/command_buffer/service/memory_tracking.h" |
18 #include "gpu/command_buffer/service/shader_translator_cache.h" | 19 #include "gpu/command_buffer/service/shader_translator_cache.h" |
19 #include "gpu/command_buffer/service/transfer_buffer_manager.h" | 20 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
20 #include "gpu/command_buffer/service/valuebuffer_manager.h" | 21 #include "gpu/command_buffer/service/valuebuffer_manager.h" |
21 #include "ui/gfx/buffer_format_util.h" | 22 #include "ui/gfx/buffer_format_util.h" |
22 #include "ui/gfx/vsync_provider.h" | 23 #include "ui/gfx/vsync_provider.h" |
23 #include "ui/gl/gl_context.h" | 24 #include "ui/gl/gl_context.h" |
24 #include "ui/gl/gl_image_shared_memory.h" | 25 #include "ui/gl/gl_image_shared_memory.h" |
25 #include "ui/gl/gl_surface.h" | 26 #include "ui/gl/gl_surface.h" |
26 | 27 |
27 namespace mus { | 28 namespace mus { |
28 | 29 |
30 namespace { | |
31 | |
32 base::StaticAtomicSequenceNumber g_next_command_buffer_id; | |
David Yen
2015/11/19 18:12:52
Same question as above.
Peng
2015/11/20 17:41:15
All instances will be in the same process (mus pro
| |
33 | |
34 } | |
35 | |
29 const unsigned int GL_READ_WRITE_CHROMIUM = 0x78F2; | 36 const unsigned int GL_READ_WRITE_CHROMIUM = 0x78F2; |
30 | 37 |
31 CommandBufferLocal::CommandBufferLocal(CommandBufferLocalClient* client, | 38 CommandBufferLocal::CommandBufferLocal(CommandBufferLocalClient* client, |
32 gfx::AcceleratedWidget widget, | 39 gfx::AcceleratedWidget widget, |
33 const scoped_refptr<GpuState>& gpu_state) | 40 const scoped_refptr<GpuState>& gpu_state) |
34 : widget_(widget), | 41 : command_buffer_id_(g_next_command_buffer_id.GetNext()), |
42 widget_(widget), | |
35 gpu_state_(gpu_state), | 43 gpu_state_(gpu_state), |
36 client_(client), | 44 client_(client), |
37 next_fence_sync_release_(1), | 45 next_fence_sync_release_(1), |
38 weak_factory_(this) {} | 46 weak_factory_(this) {} |
39 | 47 |
40 CommandBufferLocal::~CommandBufferLocal() { | 48 CommandBufferLocal::~CommandBufferLocal() { |
41 command_buffer_.reset(); | 49 command_buffer_.reset(); |
42 if (decoder_.get()) { | 50 if (decoder_.get()) { |
43 bool have_context = decoder_->GetGLContext()->MakeCurrent(surface_.get()); | 51 bool have_context = decoder_->GetGLContext()->MakeCurrent(surface_.get()); |
44 decoder_->Destroy(have_context); | 52 decoder_->Destroy(have_context); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 nullptr, bind_generates_resource); | 91 nullptr, bind_generates_resource); |
84 | 92 |
85 command_buffer_.reset( | 93 command_buffer_.reset( |
86 new gpu::CommandBufferService(context_group->transfer_buffer_manager())); | 94 new gpu::CommandBufferService(context_group->transfer_buffer_manager())); |
87 bool result = command_buffer_->Initialize(); | 95 bool result = command_buffer_->Initialize(); |
88 DCHECK(result); | 96 DCHECK(result); |
89 | 97 |
90 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group.get())); | 98 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group.get())); |
91 scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), decoder_.get(), | 99 scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), decoder_.get(), |
92 decoder_.get())); | 100 decoder_.get())); |
101 sync_point_order_data_ = gpu::SyncPointOrderData::Create(); | |
David Yen
2015/11/19 18:12:52
Same comment about order data as above.
Peng
2015/11/20 20:32:15
Done.
| |
102 sync_point_client_ = gpu_state_->sync_point_manager()->CreateSyncPointClient( | |
103 sync_point_order_data_, GetNamespaceID(), GetCommandBufferID()); | |
93 decoder_->set_engine(scheduler_.get()); | 104 decoder_->set_engine(scheduler_.get()); |
94 decoder_->SetWaitSyncPointCallback( | 105 decoder_->SetWaitSyncPointCallback( |
95 base::Bind(&CommandBufferLocal::OnWaitSyncPoint, base::Unretained(this))); | 106 base::Bind(&CommandBufferLocal::OnWaitSyncPoint, base::Unretained(this))); |
96 decoder_->SetFenceSyncReleaseCallback(base::Bind( | 107 decoder_->SetFenceSyncReleaseCallback(base::Bind( |
97 &CommandBufferLocal::OnFenceSyncRelease, base::Unretained(this))); | 108 &CommandBufferLocal::OnFenceSyncRelease, base::Unretained(this))); |
98 decoder_->SetWaitFenceSyncCallback( | 109 decoder_->SetWaitFenceSyncCallback( |
99 base::Bind(&CommandBufferLocal::OnWaitFenceSync, base::Unretained(this))); | 110 base::Bind(&CommandBufferLocal::OnWaitFenceSync, base::Unretained(this))); |
100 | 111 |
101 gpu::gles2::DisallowedFeatures disallowed_features; | 112 gpu::gles2::DisallowedFeatures disallowed_features; |
102 | 113 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 void CommandBufferLocal::SetLock(base::Lock* lock) { | 216 void CommandBufferLocal::SetLock(base::Lock* lock) { |
206 NOTIMPLEMENTED(); | 217 NOTIMPLEMENTED(); |
207 } | 218 } |
208 | 219 |
209 bool CommandBufferLocal::IsGpuChannelLost() { | 220 bool CommandBufferLocal::IsGpuChannelLost() { |
210 // This is only possible for out-of-process command buffers. | 221 // This is only possible for out-of-process command buffers. |
211 return false; | 222 return false; |
212 } | 223 } |
213 | 224 |
214 gpu::CommandBufferNamespace CommandBufferLocal::GetNamespaceID() const { | 225 gpu::CommandBufferNamespace CommandBufferLocal::GetNamespaceID() const { |
215 NOTIMPLEMENTED(); | 226 return gpu::CommandBufferNamespace::MOJO_LOCAL; |
216 return gpu::CommandBufferNamespace::INVALID; | |
217 } | 227 } |
218 | 228 |
219 uint64_t CommandBufferLocal::GetCommandBufferID() const { | 229 uint64_t CommandBufferLocal::GetCommandBufferID() const { |
220 NOTIMPLEMENTED(); | 230 return command_buffer_id_; |
221 return 0; | |
222 } | 231 } |
223 | 232 |
224 uint64_t CommandBufferLocal::GenerateFenceSyncRelease() { | 233 uint64_t CommandBufferLocal::GenerateFenceSyncRelease() { |
225 return next_fence_sync_release_++; | 234 return next_fence_sync_release_++; |
226 } | 235 } |
227 | 236 |
228 bool CommandBufferLocal::IsFenceSyncRelease(uint64_t release) { | 237 bool CommandBufferLocal::IsFenceSyncRelease(uint64_t release) { |
229 return release > 0 && release < next_fence_sync_release_; | 238 return release > 0 && release < next_fence_sync_release_; |
230 } | 239 } |
231 | 240 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 const base::TimeDelta interval) { | 272 const base::TimeDelta interval) { |
264 if (client_) | 273 if (client_) |
265 client_->UpdateVSyncParameters(timebase.ToInternalValue(), | 274 client_->UpdateVSyncParameters(timebase.ToInternalValue(), |
266 interval.ToInternalValue()); | 275 interval.ToInternalValue()); |
267 } | 276 } |
268 | 277 |
269 bool CommandBufferLocal::OnWaitSyncPoint(uint32_t sync_point) { | 278 bool CommandBufferLocal::OnWaitSyncPoint(uint32_t sync_point) { |
270 if (!sync_point) | 279 if (!sync_point) |
271 return true; | 280 return true; |
272 | 281 |
273 bool context_changed = false; | 282 if (gpu_state_->sync_point_manager()->IsSyncPointRetired(sync_point)) |
274 while (!gpu_state_->sync_point_manager()->IsSyncPointRetired(sync_point)) { | 283 return true; |
284 | |
285 do { | |
275 gpu_state_->command_buffer_task_runner()->RunOneTask(); | 286 gpu_state_->command_buffer_task_runner()->RunOneTask(); |
276 context_changed = true; | 287 } while (!gpu_state_->sync_point_manager()->IsSyncPointRetired(sync_point)); |
277 } | |
278 | 288 |
279 // RunOneTask() changes the current GL context, so we have to recover it. | 289 // RunOneTask() changes the current GL context, so we have to recover it. |
280 if (context_changed) { | 290 if (!decoder_->MakeCurrent()) { |
281 if (!decoder_->MakeCurrent()) { | 291 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); |
282 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); | 292 command_buffer_->SetParseError(::gpu::error::kLostContext); |
283 command_buffer_->SetParseError(::gpu::error::kLostContext); | |
284 } | |
285 } | 293 } |
286 return true; | 294 return true; |
287 } | 295 } |
288 | 296 |
289 void CommandBufferLocal::OnFenceSyncRelease(uint64_t release) { | 297 void CommandBufferLocal::OnFenceSyncRelease(uint64_t release) { |
290 // TODO(dyen): Implement once CommandBufferID has been figured out and | 298 if (!sync_point_client_->client_state()->IsFenceSyncReleased(release)) |
291 // we have a SyncPointClient. It would probably look like what is commented | 299 sync_point_client_->ReleaseFenceSync(release); |
292 // out below: | |
293 // if (!sync_point_client_->client_state()->IsFenceSyncReleased(release)) | |
294 // sync_point_client_->ReleaseFenceSync(release); | |
295 NOTIMPLEMENTED(); | |
296 } | 300 } |
297 | 301 |
298 bool CommandBufferLocal::OnWaitFenceSync( | 302 bool CommandBufferLocal::OnWaitFenceSync( |
299 gpu::CommandBufferNamespace namespace_id, | 303 gpu::CommandBufferNamespace namespace_id, |
300 uint64_t command_buffer_id, | 304 uint64_t command_buffer_id, |
301 uint64_t release) { | 305 uint64_t release) { |
302 gpu::SyncPointManager* sync_point_manager = gpu_state_->sync_point_manager(); | 306 gpu::SyncPointManager* sync_point_manager = gpu_state_->sync_point_manager(); |
303 DCHECK(sync_point_manager); | 307 DCHECK(sync_point_manager); |
304 | 308 |
305 scoped_refptr<gpu::SyncPointClientState> release_state = | 309 scoped_refptr<gpu::SyncPointClientState> release_state = |
306 sync_point_manager->GetSyncPointClientState(namespace_id, | 310 sync_point_manager->GetSyncPointClientState(namespace_id, |
307 command_buffer_id); | 311 command_buffer_id); |
308 | 312 |
309 if (!release_state) | 313 if (!release_state) |
310 return true; | 314 return true; |
311 | 315 |
312 if (release_state->IsFenceSyncReleased(release)) | 316 if (release_state->IsFenceSyncReleased(release)) |
313 return true; | 317 return true; |
314 | 318 |
315 // TODO(dyen): Implement once CommandBufferID has been figured out and | 319 do { |
316 // we have a SyncPointClient. It would probably look like what is commented | 320 gpu_state_->command_buffer_task_runner()->RunOneTask(); |
317 // out below: | 321 } while (!release_state->IsFenceSyncReleased(release)); |
318 // scheduler_->SetScheduled(false); | 322 |
319 // sync_point_client_->Wait( | 323 // RunOneTask() changes the current GL context, so we have to recover it. |
320 // release_state.get(), | 324 if (!decoder_->MakeCurrent()) { |
321 // release, | 325 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); |
322 // base::Bind(&CommandBufferLocal::OnSyncPointRetired, | 326 command_buffer_->SetParseError(::gpu::error::kLostContext); |
323 // weak_factory_.GetWeakPtr())); | 327 } |
324 NOTIMPLEMENTED(); | 328 return true; |
325 return scheduler_->scheduled(); | |
326 } | 329 } |
327 | 330 |
328 void CommandBufferLocal::OnParseError() { | 331 void CommandBufferLocal::OnParseError() { |
329 gpu::CommandBuffer::State state = command_buffer_->GetLastState(); | 332 gpu::CommandBuffer::State state = command_buffer_->GetLastState(); |
330 OnContextLost(state.context_lost_reason); | 333 OnContextLost(state.context_lost_reason); |
331 } | 334 } |
332 | 335 |
333 void CommandBufferLocal::OnContextLost(uint32_t reason) { | 336 void CommandBufferLocal::OnContextLost(uint32_t reason) { |
334 if (client_) | 337 if (client_) |
335 client_->DidLoseContext(); | 338 client_->DidLoseContext(); |
336 } | 339 } |
337 | 340 |
338 } // namespace mus | 341 } // namespace mus |
OLD | NEW |