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

Side by Side Diff: content/common/gpu/gpu_command_buffer_stub.cc

Issue 16294003: Update content/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/hash.h" 9 #include "base/hash.h"
10 #include "base/shared_memory.h" 10 #include "base/shared_memory.h"
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 context = decoder_->GetGLContext(); 363 context = decoder_->GetGLContext();
364 decoder_->Destroy(have_context); 364 decoder_->Destroy(have_context);
365 decoder_.reset(); 365 decoder_.reset();
366 } 366 }
367 367
368 command_buffer_.reset(); 368 command_buffer_.reset();
369 369
370 // Make sure that context_ is current while we destroy surface_, because 370 // Make sure that context_ is current while we destroy surface_, because
371 // surface_ may have GL resources that it needs to destroy, and will need 371 // surface_ may have GL resources that it needs to destroy, and will need
372 // context_ to be current in order to not leak these resources. 372 // context_ to be current in order to not leak these resources.
373 if (context) 373 if (context.get())
374 context->MakeCurrent(surface_.get()); 374 context->MakeCurrent(surface_.get());
375 surface_ = NULL; 375 surface_ = NULL;
376 if (context) 376 if (context.get())
377 context->ReleaseCurrent(NULL); 377 context->ReleaseCurrent(NULL);
378 } 378 }
379 379
380 void GpuCommandBufferStub::OnInitializeFailed(IPC::Message* reply_message) { 380 void GpuCommandBufferStub::OnInitializeFailed(IPC::Message* reply_message) {
381 Destroy(); 381 Destroy();
382 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, false); 382 GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, false);
383 Send(reply_message); 383 Send(reply_message);
384 } 384 }
385 385
386 void GpuCommandBufferStub::OnInitialize( 386 void GpuCommandBufferStub::OnInitialize(
(...skipping 12 matching lines...) Expand all
399 DLOG(ERROR) << "CommandBufferService failed to initialize.\n"; 399 DLOG(ERROR) << "CommandBufferService failed to initialize.\n";
400 OnInitializeFailed(reply_message); 400 OnInitializeFailed(reply_message);
401 return; 401 return;
402 } 402 }
403 403
404 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group_.get())); 404 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group_.get()));
405 405
406 scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), 406 scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(),
407 decoder_.get(), 407 decoder_.get(),
408 decoder_.get())); 408 decoder_.get()));
409 if (preemption_flag_) 409 if (preemption_flag_.get())
410 scheduler_->SetPreemptByFlag(preemption_flag_); 410 scheduler_->SetPreemptByFlag(preemption_flag_);
411 411
412 decoder_->set_engine(scheduler_.get()); 412 decoder_->set_engine(scheduler_.get());
413 413
414 if (!handle_.is_null()) { 414 if (!handle_.is_null()) {
415 #if defined(OS_MACOSX) || defined(UI_COMPOSITOR_IMAGE_TRANSPORT) 415 #if defined(OS_MACOSX) || defined(UI_COMPOSITOR_IMAGE_TRANSPORT)
416 if (software_) { 416 if (software_) {
417 DLOG(ERROR) << "No software support.\n"; 417 DLOG(ERROR) << "No software support.\n";
418 OnInitializeFailed(reply_message); 418 OnInitializeFailed(reply_message);
419 return; 419 return;
420 } 420 }
421 #endif 421 #endif
422 422
423 surface_ = ImageTransportSurface::CreateSurface( 423 surface_ = ImageTransportSurface::CreateSurface(
424 channel_->gpu_channel_manager(), 424 channel_->gpu_channel_manager(),
425 this, 425 this,
426 handle_); 426 handle_);
427 } else { 427 } else {
428 GpuChannelManager* manager = channel_->gpu_channel_manager(); 428 GpuChannelManager* manager = channel_->gpu_channel_manager();
429 surface_ = manager->GetDefaultOffscreenSurface(); 429 surface_ = manager->GetDefaultOffscreenSurface();
430 } 430 }
431 431
432 if (!surface_) { 432 if (!surface_.get()) {
433 DLOG(ERROR) << "Failed to create surface.\n"; 433 DLOG(ERROR) << "Failed to create surface.\n";
434 OnInitializeFailed(reply_message); 434 OnInitializeFailed(reply_message);
435 return; 435 return;
436 } 436 }
437 437
438 scoped_refptr<gfx::GLContext> context; 438 scoped_refptr<gfx::GLContext> context;
439 if ((CommandLine::ForCurrentProcess()->HasSwitch( 439 if ((CommandLine::ForCurrentProcess()->HasSwitch(
440 switches::kEnableVirtualGLContexts) || use_virtualized_gl_context_) && 440 switches::kEnableVirtualGLContexts) || use_virtualized_gl_context_) &&
441 channel_->share_group()) { 441 channel_->share_group()) {
442 context = channel_->share_group()->GetSharedContext(); 442 context = channel_->share_group()->GetSharedContext();
443 if (!context) { 443 if (!context.get()) {
444 context = gfx::GLContext::CreateGLContext( 444 context = gfx::GLContext::CreateGLContext(
445 channel_->share_group(), 445 channel_->share_group(),
446 channel_->gpu_channel_manager()->GetDefaultOffscreenSurface(), 446 channel_->gpu_channel_manager()->GetDefaultOffscreenSurface(),
447 gpu_preference_); 447 gpu_preference_);
448 channel_->share_group()->SetSharedContext(context); 448 channel_->share_group()->SetSharedContext(context.get());
449 } 449 }
450 // This should be a non-virtual GL context. 450 // This should be a non-virtual GL context.
451 DCHECK(context->GetHandle()); 451 DCHECK(context->GetHandle());
452 context = new gpu::GLContextVirtual(channel_->share_group(), 452 context = new gpu::GLContextVirtual(
453 context, 453 channel_->share_group(), context.get(), decoder_->AsWeakPtr());
454 decoder_->AsWeakPtr()); 454 if (!context->Initialize(surface_.get(), gpu_preference_)) {
455 if (!context->Initialize(surface_, gpu_preference_)) {
456 // TODO(sievers): The real context created above for the default 455 // TODO(sievers): The real context created above for the default
457 // offscreen surface might not be compatible with this surface. 456 // offscreen surface might not be compatible with this surface.
458 // Need to adjust at least GLX to be able to create the initial context 457 // Need to adjust at least GLX to be able to create the initial context
459 // with a config that is compatible with onscreen and offscreen surfaces. 458 // with a config that is compatible with onscreen and offscreen surfaces.
460 context = NULL; 459 context = NULL;
461 460
462 DLOG(ERROR) << "Failed to initialize virtual GL context."; 461 DLOG(ERROR) << "Failed to initialize virtual GL context.";
463 OnInitializeFailed(reply_message); 462 OnInitializeFailed(reply_message);
464 return; 463 return;
465 } else { 464 } else {
466 LOG(INFO) << "Created virtual GL context."; 465 LOG(INFO) << "Created virtual GL context.";
467 } 466 }
468 } 467 }
469 if (!context) { 468 if (!context.get()) {
470 context = gfx::GLContext::CreateGLContext( 469 context = gfx::GLContext::CreateGLContext(
471 channel_->share_group(), 470 channel_->share_group(), surface_.get(), gpu_preference_);
472 surface_.get(),
473 gpu_preference_);
474 } 471 }
475 if (!context) { 472 if (!context.get()) {
476 DLOG(ERROR) << "Failed to create context.\n"; 473 DLOG(ERROR) << "Failed to create context.\n";
477 OnInitializeFailed(reply_message); 474 OnInitializeFailed(reply_message);
478 return; 475 return;
479 } 476 }
480 477
481 if (!context->MakeCurrent(surface_)) { 478 if (!context->MakeCurrent(surface_.get())) {
482 LOG(ERROR) << "Failed to make context current."; 479 LOG(ERROR) << "Failed to make context current.";
483 OnInitializeFailed(reply_message); 480 OnInitializeFailed(reply_message);
484 return; 481 return;
485 } 482 }
486 483
487 if (!context->GetGLStateRestorer()) { 484 if (!context->GetGLStateRestorer()) {
488 context->SetGLStateRestorer( 485 context->SetGLStateRestorer(
489 new gpu::GLStateRestorerImpl(decoder_->AsWeakPtr())); 486 new gpu::GLStateRestorerImpl(decoder_->AsWeakPtr()));
490 } 487 }
491 488
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 } 751 }
755 752
756 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { 753 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) {
757 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSetSurfaceVisible"); 754 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSetSurfaceVisible");
758 if (memory_manager_client_state_) 755 if (memory_manager_client_state_)
759 memory_manager_client_state_->SetVisible(visible); 756 memory_manager_client_state_->SetVisible(visible);
760 } 757 }
761 758
762 void GpuCommandBufferStub::OnDiscardBackbuffer() { 759 void GpuCommandBufferStub::OnDiscardBackbuffer() {
763 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnDiscardBackbuffer"); 760 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnDiscardBackbuffer");
764 if (!surface_) 761 if (!surface_.get())
765 return; 762 return;
766 if (surface_->DeferDraws()) { 763 if (surface_->DeferDraws()) {
767 DCHECK(!IsScheduled()); 764 DCHECK(!IsScheduled());
768 channel_->RequeueMessage(); 765 channel_->RequeueMessage();
769 } else { 766 } else {
770 if (!surface_->SetBackbufferAllocation(false)) 767 if (!surface_->SetBackbufferAllocation(false))
771 channel_->DestroySoon(); 768 channel_->DestroySoon();
772 } 769 }
773 } 770 }
774 771
775 void GpuCommandBufferStub::OnEnsureBackbuffer() { 772 void GpuCommandBufferStub::OnEnsureBackbuffer() {
776 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnEnsureBackbuffer"); 773 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnEnsureBackbuffer");
777 if (!surface_) 774 if (!surface_.get())
778 return; 775 return;
779 if (surface_->DeferDraws()) { 776 if (surface_->DeferDraws()) {
780 DCHECK(!IsScheduled()); 777 DCHECK(!IsScheduled());
781 channel_->RequeueMessage(); 778 channel_->RequeueMessage();
782 } else { 779 } else {
783 if (!surface_->SetBackbufferAllocation(true)) 780 if (!surface_->SetBackbufferAllocation(true))
784 channel_->DestroySoon(); 781 channel_->DestroySoon();
785 } 782 }
786 } 783 }
787 784
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 if (scheduler_) 887 if (scheduler_)
891 scheduler_->SetPreemptByFlag(preemption_flag_); 888 scheduler_->SetPreemptByFlag(preemption_flag_);
892 } 889 }
893 890
894 bool GpuCommandBufferStub::GetTotalGpuMemory(uint64* bytes) { 891 bool GpuCommandBufferStub::GetTotalGpuMemory(uint64* bytes) {
895 *bytes = total_gpu_memory_; 892 *bytes = total_gpu_memory_;
896 return !!total_gpu_memory_; 893 return !!total_gpu_memory_;
897 } 894 }
898 895
899 gfx::Size GpuCommandBufferStub::GetSurfaceSize() const { 896 gfx::Size GpuCommandBufferStub::GetSurfaceSize() const {
900 if (!surface_) 897 if (!surface_.get())
901 return gfx::Size(); 898 return gfx::Size();
902 return surface_->GetSize(); 899 return surface_->GetSize();
903 } 900 }
904 901
905 gpu::gles2::MemoryTracker* GpuCommandBufferStub::GetMemoryTracker() const { 902 gpu::gles2::MemoryTracker* GpuCommandBufferStub::GetMemoryTracker() const {
906 return context_group_->memory_tracker(); 903 return context_group_->memory_tracker();
907 } 904 }
908 905
909 void GpuCommandBufferStub::SetMemoryAllocation( 906 void GpuCommandBufferStub::SetMemoryAllocation(
910 const GpuMemoryAllocation& allocation) { 907 const GpuMemoryAllocation& allocation) {
911 if (!last_memory_allocation_valid_ || 908 if (!last_memory_allocation_valid_ ||
912 !allocation.renderer_allocation.Equals( 909 !allocation.renderer_allocation.Equals(
913 last_memory_allocation_.renderer_allocation)) { 910 last_memory_allocation_.renderer_allocation)) {
914 Send(new GpuCommandBufferMsg_SetMemoryAllocation( 911 Send(new GpuCommandBufferMsg_SetMemoryAllocation(
915 route_id_, allocation.renderer_allocation)); 912 route_id_, allocation.renderer_allocation));
916 } 913 }
917 914
918 if (!last_memory_allocation_valid_ || 915 if (!last_memory_allocation_valid_ ||
919 !allocation.browser_allocation.Equals( 916 !allocation.browser_allocation.Equals(
920 last_memory_allocation_.browser_allocation)) { 917 last_memory_allocation_.browser_allocation)) {
921 // This can be called outside of OnMessageReceived, so the context needs 918 // This can be called outside of OnMessageReceived, so the context needs
922 // to be made current before calling methods on the surface. 919 // to be made current before calling methods on the surface.
923 if (surface_ && MakeCurrent()) 920 if (surface_.get() && MakeCurrent())
924 surface_->SetFrontbufferAllocation( 921 surface_->SetFrontbufferAllocation(
925 allocation.browser_allocation.suggest_have_frontbuffer); 922 allocation.browser_allocation.suggest_have_frontbuffer);
926 } 923 }
927 924
928 last_memory_allocation_valid_ = true; 925 last_memory_allocation_valid_ = true;
929 last_memory_allocation_ = allocation; 926 last_memory_allocation_ = allocation;
930 } 927 }
931 928
932 } // namespace content 929 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/gpu_command_buffer_stub.h ('k') | content/common/gpu/gpu_memory_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698