| OLD | NEW |
| 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 "gpu/ipc/service/gpu_command_buffer_stub.h" | 5 #include "gpu/ipc/service/gpu_command_buffer_stub.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 manager->shader_translator_cache(), | 469 manager->shader_translator_cache(), |
| 470 manager->framebuffer_completeness_cache(), feature_info, | 470 manager->framebuffer_completeness_cache(), feature_info, |
| 471 init_params.attribs.bind_generates_resource, | 471 init_params.attribs.bind_generates_resource, |
| 472 gmb_factory ? gmb_factory->AsImageFactory() : nullptr); | 472 gmb_factory ? gmb_factory->AsImageFactory() : nullptr); |
| 473 } | 473 } |
| 474 | 474 |
| 475 #if defined(OS_MACOSX) | 475 #if defined(OS_MACOSX) |
| 476 // Virtualize PreferIntegratedGpu contexts by default on OS X to prevent | 476 // Virtualize PreferIntegratedGpu contexts by default on OS X to prevent |
| 477 // performance regressions when enabling FCM. | 477 // performance regressions when enabling FCM. |
| 478 // http://crbug.com/180463 | 478 // http://crbug.com/180463 |
| 479 if (init_params.gpu_preference == gl::PreferIntegratedGpu) | 479 if (init_params.attribs.gpu_preference == gl::PreferIntegratedGpu) |
| 480 use_virtualized_gl_context_ = true; | 480 use_virtualized_gl_context_ = true; |
| 481 #endif | 481 #endif |
| 482 | 482 |
| 483 use_virtualized_gl_context_ |= | 483 use_virtualized_gl_context_ |= |
| 484 context_group_->feature_info()->workarounds().use_virtualized_gl_contexts; | 484 context_group_->feature_info()->workarounds().use_virtualized_gl_contexts; |
| 485 | 485 |
| 486 // MailboxManagerSync synchronization correctness currently depends on having | 486 // MailboxManagerSync synchronization correctness currently depends on having |
| 487 // only a single context. See crbug.com/510243 for details. | 487 // only a single context. See crbug.com/510243 for details. |
| 488 use_virtualized_gl_context_ |= channel_->mailbox_manager()->UsesSync(); | 488 use_virtualized_gl_context_ |= channel_->mailbox_manager()->UsesSync(); |
| 489 | 489 |
| 490 gl::GLSurface::Format surface_format = gl::GLSurface::SURFACE_DEFAULT; | 490 gl::GLSurface::Format surface_format = gl::GLSurface::SURFACE_DEFAULT; |
| 491 bool offscreen = (surface_handle_ == kNullSurfaceHandle); | 491 bool offscreen = (surface_handle_ == kNullSurfaceHandle); |
| 492 gl::GLSurface* default_surface = manager->GetDefaultOffscreenSurface(); | 492 gl::GLSurface* default_surface = manager->GetDefaultOffscreenSurface(); |
| 493 if (!default_surface) { | 493 if (!default_surface) { |
| 494 DLOG(ERROR) << "Failed to create default offscreen surface."; | 494 DLOG(ERROR) << "Failed to create default offscreen surface."; |
| 495 return false; | 495 return false; |
| 496 } | 496 } |
| 497 #if defined(OS_ANDROID) | 497 #if defined(OS_ANDROID) |
| 498 if (init_params.attribs.red_size <= 5 && | 498 if (init_params.attribs.red_size <= 5 && |
| 499 init_params.attribs.green_size <= 6 && | 499 init_params.attribs.green_size <= 6 && |
| 500 init_params.attribs.blue_size <= 5 && | 500 init_params.attribs.blue_size <= 5 && |
| 501 init_params.attribs.alpha_size == 0) | 501 init_params.attribs.alpha_size == 0) |
| 502 surface_format = gl::GLSurface::SURFACE_RGB565; | 502 surface_format = gl::GLSurface::SURFACE_RGB565; |
| 503 // We can only use virtualized contexts for onscreen command buffers if their | 503 // We can only use virtualized contexts for onscreen command buffers if their |
| 504 // config is compatible with the offscreen ones - otherwise MakeCurrent fails. | 504 // config is compatible with the offscreen ones - otherwise MakeCurrent fails. |
| 505 if (surface_format != default_surface->GetFormat() && !offscreen) | 505 if (surface_format != default_surface->GetFormat() && !offscreen) |
| 506 use_virtualized_gl_context_ = false; | 506 use_virtualized_gl_context_ = false; |
| 507 #endif | 507 #endif |
| 508 | 508 |
| 509 gfx::Size initial_size = init_params.size; | |
| 510 if (offscreen && initial_size.IsEmpty()) { | |
| 511 // If we're an offscreen surface with zero width and/or height, set to a | |
| 512 // non-zero size so that we have a complete framebuffer for operations like | |
| 513 // glClear. | |
| 514 initial_size = gfx::Size(1, 1); | |
| 515 } | |
| 516 | |
| 517 command_buffer_.reset(new CommandBufferService( | 509 command_buffer_.reset(new CommandBufferService( |
| 518 context_group_->transfer_buffer_manager())); | 510 context_group_->transfer_buffer_manager())); |
| 519 | 511 |
| 520 decoder_.reset(gles2::GLES2Decoder::Create(context_group_.get())); | 512 decoder_.reset(gles2::GLES2Decoder::Create(context_group_.get())); |
| 521 executor_.reset(new CommandExecutor(command_buffer_.get(), decoder_.get(), | 513 executor_.reset(new CommandExecutor(command_buffer_.get(), decoder_.get(), |
| 522 decoder_.get())); | 514 decoder_.get())); |
| 523 sync_point_client_ = channel_->sync_point_manager()->CreateSyncPointClient( | 515 sync_point_client_ = channel_->sync_point_manager()->CreateSyncPointClient( |
| 524 channel_->GetSyncPointOrderData(stream_id_), | 516 channel_->GetSyncPointOrderData(stream_id_), |
| 525 CommandBufferNamespace::GPU_IO, command_buffer_id_); | 517 CommandBufferNamespace::GPU_IO, command_buffer_id_); |
| 526 | 518 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 539 return false; | 531 return false; |
| 540 } | 532 } |
| 541 } | 533 } |
| 542 | 534 |
| 543 scoped_refptr<gl::GLContext> context; | 535 scoped_refptr<gl::GLContext> context; |
| 544 gl::GLShareGroup* gl_share_group = channel_->share_group(); | 536 gl::GLShareGroup* gl_share_group = channel_->share_group(); |
| 545 if (use_virtualized_gl_context_ && gl_share_group) { | 537 if (use_virtualized_gl_context_ && gl_share_group) { |
| 546 context = gl_share_group->GetSharedContext(); | 538 context = gl_share_group->GetSharedContext(); |
| 547 if (!context.get()) { | 539 if (!context.get()) { |
| 548 context = gl::init::CreateGLContext(gl_share_group, default_surface, | 540 context = gl::init::CreateGLContext(gl_share_group, default_surface, |
| 549 init_params.gpu_preference); | 541 init_params.attribs.gpu_preference); |
| 550 if (!context.get()) { | 542 if (!context.get()) { |
| 551 DLOG(ERROR) << "Failed to create shared context for virtualization."; | 543 DLOG(ERROR) << "Failed to create shared context for virtualization."; |
| 552 return false; | 544 return false; |
| 553 } | 545 } |
| 554 // Ensure that context creation did not lose track of the intended | 546 // Ensure that context creation did not lose track of the intended |
| 555 // gl_share_group. | 547 // gl_share_group. |
| 556 DCHECK(context->share_group() == gl_share_group); | 548 DCHECK(context->share_group() == gl_share_group); |
| 557 gl_share_group->SetSharedContext(context.get()); | 549 gl_share_group->SetSharedContext(context.get()); |
| 558 } | 550 } |
| 559 // This should be either: | 551 // This should be either: |
| 560 // (1) a non-virtual GL context, or | 552 // (1) a non-virtual GL context, or |
| 561 // (2) a mock context. | 553 // (2) a mock context. |
| 562 DCHECK(context->GetHandle() || | 554 DCHECK(context->GetHandle() || |
| 563 gl::GetGLImplementation() == gl::kGLImplementationMockGL); | 555 gl::GetGLImplementation() == gl::kGLImplementationMockGL); |
| 564 context = new GLContextVirtual( | 556 context = new GLContextVirtual( |
| 565 gl_share_group, context.get(), decoder_->AsWeakPtr()); | 557 gl_share_group, context.get(), decoder_->AsWeakPtr()); |
| 566 if (!context->Initialize(surface_.get(), init_params.gpu_preference)) { | 558 if (!context->Initialize(surface_.get(), |
| 559 init_params.attribs.gpu_preference)) { |
| 567 // The real context created above for the default offscreen surface | 560 // The real context created above for the default offscreen surface |
| 568 // might not be compatible with this surface. | 561 // might not be compatible with this surface. |
| 569 context = NULL; | 562 context = NULL; |
| 570 DLOG(ERROR) << "Failed to initialize virtual GL context."; | 563 DLOG(ERROR) << "Failed to initialize virtual GL context."; |
| 571 return false; | 564 return false; |
| 572 } | 565 } |
| 573 } | 566 } |
| 574 if (!context.get()) { | 567 if (!context.get()) { |
| 575 context = gl::init::CreateGLContext(gl_share_group, surface_.get(), | 568 context = gl::init::CreateGLContext(gl_share_group, surface_.get(), |
| 576 init_params.gpu_preference); | 569 init_params.attribs.gpu_preference); |
| 577 } | 570 } |
| 578 if (!context.get()) { | 571 if (!context.get()) { |
| 579 DLOG(ERROR) << "Failed to create context."; | 572 DLOG(ERROR) << "Failed to create context."; |
| 580 return false; | 573 return false; |
| 581 } | 574 } |
| 582 | 575 |
| 583 if (!context->MakeCurrent(surface_.get())) { | 576 if (!context->MakeCurrent(surface_.get())) { |
| 584 LOG(ERROR) << "Failed to make context current."; | 577 LOG(ERROR) << "Failed to make context current."; |
| 585 return false; | 578 return false; |
| 586 } | 579 } |
| 587 | 580 |
| 588 if (!context->GetGLStateRestorer()) { | 581 if (!context->GetGLStateRestorer()) { |
| 589 context->SetGLStateRestorer( | 582 context->SetGLStateRestorer( |
| 590 new GLStateRestorerImpl(decoder_->AsWeakPtr())); | 583 new GLStateRestorerImpl(decoder_->AsWeakPtr())); |
| 591 } | 584 } |
| 592 | 585 |
| 593 if (!context_group_->has_program_cache() && | 586 if (!context_group_->has_program_cache() && |
| 594 !context_group_->feature_info()->workarounds().disable_program_cache) { | 587 !context_group_->feature_info()->workarounds().disable_program_cache) { |
| 595 context_group_->set_program_cache(manager->program_cache()); | 588 context_group_->set_program_cache(manager->program_cache()); |
| 596 } | 589 } |
| 597 | 590 |
| 598 // Initialize the decoder with either the view or pbuffer GLContext. | 591 // Initialize the decoder with either the view or pbuffer GLContext. |
| 599 if (!decoder_->Initialize(surface_, context, offscreen, initial_size, | 592 if (!decoder_->Initialize(surface_, context, offscreen, |
| 600 gpu::gles2::DisallowedFeatures(), | 593 gpu::gles2::DisallowedFeatures(), |
| 601 init_params.attribs)) { | 594 init_params.attribs)) { |
| 602 DLOG(ERROR) << "Failed to initialize decoder."; | 595 DLOG(ERROR) << "Failed to initialize decoder."; |
| 603 return false; | 596 return false; |
| 604 } | 597 } |
| 605 | 598 |
| 606 if (manager->gpu_preferences().enable_gpu_service_logging) { | 599 if (manager->gpu_preferences().enable_gpu_service_logging) { |
| 607 decoder_->set_log_commands(true); | 600 decoder_->set_log_commands(true); |
| 608 } | 601 } |
| 609 | 602 |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 Send(new GpuCommandBufferMsg_SwapBuffersCompleted(route_id_, params)); | 1113 Send(new GpuCommandBufferMsg_SwapBuffersCompleted(route_id_, params)); |
| 1121 } | 1114 } |
| 1122 | 1115 |
| 1123 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase, | 1116 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase, |
| 1124 base::TimeDelta interval) { | 1117 base::TimeDelta interval) { |
| 1125 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase, | 1118 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase, |
| 1126 interval)); | 1119 interval)); |
| 1127 } | 1120 } |
| 1128 | 1121 |
| 1129 } // namespace gpu | 1122 } // namespace gpu |
| OLD | NEW |