Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: gpu/command_buffer/service/in_process_command_buffer.cc

Issue 1885903002: Revert of Make lost context and error message callbacks on GpuControl go to client (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "gpu/command_buffer/service/in_process_command_buffer.h" 5 #include "gpu/command_buffer/service/in_process_command_buffer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <queue> 10 #include <queue>
11 #include <set> 11 #include <set>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/bind_helpers.h" 15 #include "base/bind_helpers.h"
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/lazy_instance.h" 17 #include "base/lazy_instance.h"
18 #include "base/location.h" 18 #include "base/location.h"
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/memory/weak_ptr.h" 20 #include "base/memory/weak_ptr.h"
21 #include "base/numerics/safe_conversions.h" 21 #include "base/numerics/safe_conversions.h"
22 #include "base/sequence_checker.h" 22 #include "base/sequence_checker.h"
23 #include "base/single_thread_task_runner.h" 23 #include "base/single_thread_task_runner.h"
24 #include "base/thread_task_runner_handle.h" 24 #include "base/thread_task_runner_handle.h"
25 #include "gpu/command_buffer/client/gpu_control_client.h"
26 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" 25 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
27 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" 26 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h"
28 #include "gpu/command_buffer/common/sync_token.h" 27 #include "gpu/command_buffer/common/sync_token.h"
29 #include "gpu/command_buffer/common/value_state.h" 28 #include "gpu/command_buffer/common/value_state.h"
30 #include "gpu/command_buffer/service/command_buffer_service.h" 29 #include "gpu/command_buffer/service/command_buffer_service.h"
31 #include "gpu/command_buffer/service/command_executor.h" 30 #include "gpu/command_buffer/service/command_executor.h"
32 #include "gpu/command_buffer/service/context_group.h" 31 #include "gpu/command_buffer/service/context_group.h"
33 #include "gpu/command_buffer/service/gl_context_virtual.h" 32 #include "gpu/command_buffer/service/gl_context_virtual.h"
34 #include "gpu/command_buffer/service/gpu_preferences.h" 33 #include "gpu/command_buffer/service/gpu_preferences.h"
35 #include "gpu/command_buffer/service/image_factory.h" 34 #include "gpu/command_buffer/service/image_factory.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 } 205 }
207 return program_cache_.get(); 206 return program_cache_.get();
208 } 207 }
209 208
210 InProcessCommandBuffer::InProcessCommandBuffer( 209 InProcessCommandBuffer::InProcessCommandBuffer(
211 const scoped_refptr<Service>& service) 210 const scoped_refptr<Service>& service)
212 : command_buffer_id_( 211 : command_buffer_id_(
213 CommandBufferId::FromUnsafeValue(g_next_command_buffer_id.GetNext())), 212 CommandBufferId::FromUnsafeValue(g_next_command_buffer_id.GetNext())),
214 delayed_work_pending_(false), 213 delayed_work_pending_(false),
215 image_factory_(nullptr), 214 image_factory_(nullptr),
216 gpu_control_client_(nullptr),
217 #if DCHECK_IS_ON()
218 context_lost_(false),
219 #endif
220 last_put_offset_(-1), 215 last_put_offset_(-1),
221 gpu_memory_buffer_manager_(nullptr), 216 gpu_memory_buffer_manager_(nullptr),
222 next_fence_sync_release_(1), 217 next_fence_sync_release_(1),
223 flushed_fence_sync_release_(0), 218 flushed_fence_sync_release_(0),
224 flush_event_(false, false), 219 flush_event_(false, false),
225 service_(GetInitialService(service)), 220 service_(GetInitialService(service)),
226 fence_sync_wait_event_(false, false), 221 fence_sync_wait_event_(false, false),
227 client_thread_weak_ptr_factory_(this),
228 gpu_thread_weak_ptr_factory_(this) { 222 gpu_thread_weak_ptr_factory_(this) {
229 DCHECK(service_.get()); 223 DCHECK(service_.get());
230 next_image_id_.GetNext(); 224 next_image_id_.GetNext();
231 } 225 }
232 226
233 InProcessCommandBuffer::~InProcessCommandBuffer() { 227 InProcessCommandBuffer::~InProcessCommandBuffer() {
234 Destroy(); 228 Destroy();
235 } 229 }
236 230
237 bool InProcessCommandBuffer::MakeCurrent() { 231 bool InProcessCommandBuffer::MakeCurrent() {
238 CheckSequencedThread(); 232 CheckSequencedThread();
239 command_buffer_lock_.AssertAcquired(); 233 command_buffer_lock_.AssertAcquired();
240 234
241 if (error::IsError(command_buffer_->GetLastState().error)) { 235 if (error::IsError(command_buffer_->GetLastState().error)) {
242 DLOG(ERROR) << "MakeCurrent failed because context lost."; 236 DLOG(ERROR) << "MakeCurrent failed because context lost.";
243 return false; 237 return false;
244 } 238 }
245 if (!decoder_->MakeCurrent()) { 239 if (!decoder_->MakeCurrent()) {
246 DLOG(ERROR) << "Context lost because MakeCurrent failed."; 240 DLOG(ERROR) << "Context lost because MakeCurrent failed.";
247 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); 241 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason());
248 command_buffer_->SetParseError(gpu::error::kLostContext); 242 command_buffer_->SetParseError(gpu::error::kLostContext);
249 return false; 243 return false;
250 } 244 }
251 return true; 245 return true;
252 } 246 }
253 247
254 void InProcessCommandBuffer::PumpCommandsOnGpuThread() { 248 void InProcessCommandBuffer::PumpCommands() {
255 CheckSequencedThread(); 249 CheckSequencedThread();
256 command_buffer_lock_.AssertAcquired(); 250 command_buffer_lock_.AssertAcquired();
257 251
258 if (!MakeCurrent()) 252 if (!MakeCurrent())
259 return; 253 return;
260 254
261 executor_->PutChanged(); 255 executor_->PutChanged();
262 } 256 }
263 257
258 bool InProcessCommandBuffer::GetBufferChanged(int32_t transfer_buffer_id) {
259 CheckSequencedThread();
260 command_buffer_lock_.AssertAcquired();
261 command_buffer_->SetGetBuffer(transfer_buffer_id);
262 return true;
263 }
264
264 bool InProcessCommandBuffer::Initialize( 265 bool InProcessCommandBuffer::Initialize(
265 scoped_refptr<gfx::GLSurface> surface, 266 scoped_refptr<gfx::GLSurface> surface,
266 bool is_offscreen, 267 bool is_offscreen,
267 gfx::AcceleratedWidget window, 268 gfx::AcceleratedWidget window,
268 const gfx::Size& size, 269 const gfx::Size& size,
269 const std::vector<int32_t>& attribs, 270 const std::vector<int32_t>& attribs,
270 gfx::GpuPreference gpu_preference, 271 gfx::GpuPreference gpu_preference,
272 const base::Closure& context_lost_callback,
271 InProcessCommandBuffer* share_group, 273 InProcessCommandBuffer* share_group,
272 GpuMemoryBufferManager* gpu_memory_buffer_manager, 274 GpuMemoryBufferManager* gpu_memory_buffer_manager,
273 ImageFactory* image_factory) { 275 ImageFactory* image_factory) {
274 DCHECK(!share_group || service_.get() == share_group->service_.get()); 276 DCHECK(!share_group || service_.get() == share_group->service_.get());
277 context_lost_callback_ = WrapCallback(context_lost_callback);
275 278
276 if (surface) { 279 if (surface.get()) {
277 // GPU thread must be the same as client thread due to GLSurface not being 280 // GPU thread must be the same as client thread due to GLSurface not being
278 // thread safe. 281 // thread safe.
279 sequence_checker_.reset(new base::SequenceChecker); 282 sequence_checker_.reset(new base::SequenceChecker);
280 surface_ = surface; 283 surface_ = surface;
281 } else {
282 origin_task_runner_ = base::ThreadTaskRunnerHandle::Get();
283 client_thread_weak_ptr_ = client_thread_weak_ptr_factory_.GetWeakPtr();
284 } 284 }
285 285
286 gpu::Capabilities capabilities; 286 gpu::Capabilities capabilities;
287 InitializeOnGpuThreadParams params(is_offscreen, 287 InitializeOnGpuThreadParams params(is_offscreen,
288 window, 288 window,
289 size, 289 size,
290 attribs, 290 attribs,
291 gpu_preference, 291 gpu_preference,
292 &capabilities, 292 &capabilities,
293 share_group, 293 share_group,
(...skipping 27 matching lines...) Expand all
321 321
322 DCHECK(params.size.width() >= 0 && params.size.height() >= 0); 322 DCHECK(params.size.width() >= 0 && params.size.height() >= 0);
323 323
324 TransferBufferManager* manager = new TransferBufferManager(nullptr); 324 TransferBufferManager* manager = new TransferBufferManager(nullptr);
325 transfer_buffer_manager_ = manager; 325 transfer_buffer_manager_ = manager;
326 manager->Initialize(); 326 manager->Initialize();
327 327
328 scoped_ptr<CommandBufferService> command_buffer( 328 scoped_ptr<CommandBufferService> command_buffer(
329 new CommandBufferService(transfer_buffer_manager_.get())); 329 new CommandBufferService(transfer_buffer_manager_.get()));
330 command_buffer->SetPutOffsetChangeCallback(base::Bind( 330 command_buffer->SetPutOffsetChangeCallback(base::Bind(
331 &InProcessCommandBuffer::PumpCommandsOnGpuThread, gpu_thread_weak_ptr_)); 331 &InProcessCommandBuffer::PumpCommands, gpu_thread_weak_ptr_));
332 command_buffer->SetParseErrorCallback(base::Bind( 332 command_buffer->SetParseErrorCallback(base::Bind(
333 &InProcessCommandBuffer::OnContextLostOnGpuThread, gpu_thread_weak_ptr_)); 333 &InProcessCommandBuffer::OnContextLost, gpu_thread_weak_ptr_));
334 334
335 if (!command_buffer->Initialize()) { 335 if (!command_buffer->Initialize()) {
336 LOG(ERROR) << "Could not initialize command buffer."; 336 LOG(ERROR) << "Could not initialize command buffer.";
337 DestroyOnGpuThread(); 337 DestroyOnGpuThread();
338 return false; 338 return false;
339 } 339 }
340 340
341 gl_share_group_ = params.context_group 341 gl_share_group_ = params.context_group
342 ? params.context_group->gl_share_group_ 342 ? params.context_group->gl_share_group_
343 : service_->share_group(); 343 : service_->share_group();
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 base::Bind(&InProcessCommandBuffer::WaitFenceSyncOnGpuThread, 448 base::Bind(&InProcessCommandBuffer::WaitFenceSyncOnGpuThread,
449 base::Unretained(this))); 449 base::Unretained(this)));
450 450
451 image_factory_ = params.image_factory; 451 image_factory_ = params.image_factory;
452 452
453 return true; 453 return true;
454 } 454 }
455 455
456 void InProcessCommandBuffer::Destroy() { 456 void InProcessCommandBuffer::Destroy() {
457 CheckSequencedThread(); 457 CheckSequencedThread();
458 client_thread_weak_ptr_factory_.InvalidateWeakPtrs(); 458
459 gpu_control_client_ = nullptr;
460 base::WaitableEvent completion(true, false); 459 base::WaitableEvent completion(true, false);
461 bool result = false; 460 bool result = false;
462 base::Callback<bool(void)> destroy_task = base::Bind( 461 base::Callback<bool(void)> destroy_task = base::Bind(
463 &InProcessCommandBuffer::DestroyOnGpuThread, base::Unretained(this)); 462 &InProcessCommandBuffer::DestroyOnGpuThread, base::Unretained(this));
464 QueueTask( 463 QueueTask(
465 base::Bind(&RunTaskWithResult<bool>, destroy_task, &result, &completion)); 464 base::Bind(&RunTaskWithResult<bool>, destroy_task, &result, &completion));
466 completion.Wait(); 465 completion.Wait();
467 } 466 }
468 467
469 bool InProcessCommandBuffer::DestroyOnGpuThread() { 468 bool InProcessCommandBuffer::DestroyOnGpuThread() {
470 CheckSequencedThread(); 469 CheckSequencedThread();
471 gpu_thread_weak_ptr_factory_.InvalidateWeakPtrs(); 470 gpu_thread_weak_ptr_factory_.InvalidateWeakPtrs();
472 command_buffer_.reset(); 471 command_buffer_.reset();
473 // Clean up GL resources if possible. 472 // Clean up GL resources if possible.
474 bool have_context = context_.get() && context_->MakeCurrent(surface_.get()); 473 bool have_context = context_.get() && context_->MakeCurrent(surface_.get());
475 if (decoder_) { 474 if (decoder_) {
476 decoder_->Destroy(have_context); 475 decoder_->Destroy(have_context);
477 decoder_.reset(); 476 decoder_.reset();
478 } 477 }
479 context_ = nullptr; 478 context_ = NULL;
480 surface_ = nullptr; 479 surface_ = NULL;
481 sync_point_client_ = nullptr; 480 sync_point_client_ = NULL;
482 if (sync_point_order_data_) { 481 if (sync_point_order_data_) {
483 sync_point_order_data_->Destroy(); 482 sync_point_order_data_->Destroy();
484 sync_point_order_data_ = nullptr; 483 sync_point_order_data_ = nullptr;
485 } 484 }
486 gl_share_group_ = nullptr; 485 gl_share_group_ = NULL;
487 #if defined(OS_ANDROID) 486 #if defined(OS_ANDROID)
488 stream_texture_manager_.reset(); 487 stream_texture_manager_.reset();
489 #endif 488 #endif
490 489
491 return true; 490 return true;
492 } 491 }
493 492
494 void InProcessCommandBuffer::CheckSequencedThread() { 493 void InProcessCommandBuffer::CheckSequencedThread() {
495 DCHECK(!sequence_checker_ || 494 DCHECK(!sequence_checker_ ||
496 sequence_checker_->CalledOnValidSequencedThread()); 495 sequence_checker_->CalledOnValidSequencedThread());
497 } 496 }
498 497
499 void InProcessCommandBuffer::OnContextLostOnGpuThread() {
500 if (!origin_task_runner_)
501 return OnContextLost(); // Just kidding, we're on the client thread.
502 origin_task_runner_->PostTask(
503 FROM_HERE, base::Bind(&InProcessCommandBuffer::OnContextLost,
504 client_thread_weak_ptr_));
505 }
506
507 void InProcessCommandBuffer::OnContextLost() { 498 void InProcessCommandBuffer::OnContextLost() {
508 CheckSequencedThread(); 499 CheckSequencedThread();
509 500 if (!context_lost_callback_.is_null()) {
510 #if DCHECK_IS_ON() 501 context_lost_callback_.Run();
511 // This method shouldn't be called more than once. 502 context_lost_callback_.Reset();
512 DCHECK(!context_lost_); 503 }
513 context_lost_ = true;
514 #endif
515
516 if (gpu_control_client_)
517 gpu_control_client_->OnGpuControlLostContext();
518 } 504 }
519 505
520 CommandBuffer::State InProcessCommandBuffer::GetStateFast() { 506 CommandBuffer::State InProcessCommandBuffer::GetStateFast() {
521 CheckSequencedThread(); 507 CheckSequencedThread();
522 base::AutoLock lock(state_after_last_flush_lock_); 508 base::AutoLock lock(state_after_last_flush_lock_);
523 if (state_after_last_flush_.generation - last_state_.generation < 0x80000000U) 509 if (state_after_last_flush_.generation - last_state_.generation < 0x80000000U)
524 last_state_ = state_after_last_flush_; 510 last_state_ = state_after_last_flush_;
525 return last_state_; 511 return last_state_;
526 } 512 }
527 513
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 } 547 }
562 548
563 // If we've processed all pending commands but still have pending queries, 549 // If we've processed all pending commands but still have pending queries,
564 // pump idle work until the query is passed. 550 // pump idle work until the query is passed.
565 if (put_offset == state_after_last_flush_.get_offset && 551 if (put_offset == state_after_last_flush_.get_offset &&
566 (executor_->HasMoreIdleWork() || executor_->HasPendingQueries())) { 552 (executor_->HasMoreIdleWork() || executor_->HasPendingQueries())) {
567 ScheduleDelayedWorkOnGpuThread(); 553 ScheduleDelayedWorkOnGpuThread();
568 } 554 }
569 } 555 }
570 556
571 void InProcessCommandBuffer::PerformDelayedWorkOnGpuThread() { 557 void InProcessCommandBuffer::PerformDelayedWork() {
572 CheckSequencedThread(); 558 CheckSequencedThread();
573 delayed_work_pending_ = false; 559 delayed_work_pending_ = false;
574 base::AutoLock lock(command_buffer_lock_); 560 base::AutoLock lock(command_buffer_lock_);
575 if (MakeCurrent()) { 561 if (MakeCurrent()) {
576 executor_->PerformIdleWork(); 562 executor_->PerformIdleWork();
577 executor_->ProcessPendingQueries(); 563 executor_->ProcessPendingQueries();
578 if (executor_->HasMoreIdleWork() || executor_->HasPendingQueries()) { 564 if (executor_->HasMoreIdleWork() || executor_->HasPendingQueries()) {
579 ScheduleDelayedWorkOnGpuThread(); 565 ScheduleDelayedWorkOnGpuThread();
580 } 566 }
581 } 567 }
582 } 568 }
583 569
584 void InProcessCommandBuffer::ScheduleDelayedWorkOnGpuThread() { 570 void InProcessCommandBuffer::ScheduleDelayedWorkOnGpuThread() {
585 CheckSequencedThread(); 571 CheckSequencedThread();
586 if (delayed_work_pending_) 572 if (delayed_work_pending_)
587 return; 573 return;
588 delayed_work_pending_ = true; 574 delayed_work_pending_ = true;
589 service_->ScheduleDelayedWork( 575 service_->ScheduleDelayedWork(base::Bind(
590 base::Bind(&InProcessCommandBuffer::PerformDelayedWorkOnGpuThread, 576 &InProcessCommandBuffer::PerformDelayedWork, gpu_thread_weak_ptr_));
591 gpu_thread_weak_ptr_));
592 } 577 }
593 578
594 void InProcessCommandBuffer::Flush(int32_t put_offset) { 579 void InProcessCommandBuffer::Flush(int32_t put_offset) {
595 CheckSequencedThread(); 580 CheckSequencedThread();
596 if (last_state_.error != gpu::error::kNoError) 581 if (last_state_.error != gpu::error::kNoError)
597 return; 582 return;
598 583
599 if (last_put_offset_ == put_offset) 584 if (last_put_offset_ == put_offset)
600 return; 585 return;
601 586
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 id); 663 id);
679 664
680 QueueTask(task); 665 QueueTask(task);
681 } 666 }
682 667
683 void InProcessCommandBuffer::DestroyTransferBufferOnGpuThread(int32_t id) { 668 void InProcessCommandBuffer::DestroyTransferBufferOnGpuThread(int32_t id) {
684 base::AutoLock lock(command_buffer_lock_); 669 base::AutoLock lock(command_buffer_lock_);
685 command_buffer_->DestroyTransferBuffer(id); 670 command_buffer_->DestroyTransferBuffer(id);
686 } 671 }
687 672
688 void InProcessCommandBuffer::SetGpuControlClient(GpuControlClient* client) {
689 gpu_control_client_ = client;
690 }
691
692 gpu::Capabilities InProcessCommandBuffer::GetCapabilities() { 673 gpu::Capabilities InProcessCommandBuffer::GetCapabilities() {
693 return capabilities_; 674 return capabilities_;
694 } 675 }
695 676
696 int32_t InProcessCommandBuffer::CreateImage(ClientBuffer buffer, 677 int32_t InProcessCommandBuffer::CreateImage(ClientBuffer buffer,
697 size_t width, 678 size_t width,
698 size_t height, 679 size_t height,
699 unsigned internalformat) { 680 unsigned internalformat) {
700 CheckSequencedThread(); 681 CheckSequencedThread();
701 682
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 framebuffer_completeness_cache_ = 1095 framebuffer_completeness_cache_ =
1115 new gpu::gles2::FramebufferCompletenessCache; 1096 new gpu::gles2::FramebufferCompletenessCache;
1116 return framebuffer_completeness_cache_; 1097 return framebuffer_completeness_cache_;
1117 } 1098 }
1118 1099
1119 SyncPointManager* GpuInProcessThread::sync_point_manager() { 1100 SyncPointManager* GpuInProcessThread::sync_point_manager() {
1120 return sync_point_manager_; 1101 return sync_point_manager_;
1121 } 1102 }
1122 1103
1123 } // namespace gpu 1104 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/in_process_command_buffer.h ('k') | gpu/command_buffer/tests/gl_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698