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 "content/renderer/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
18 #include "cc/base/switches.h" | 18 #include "cc/base/switches.h" |
19 #include "cc/output/output_surface.h" | 19 #include "cc/output/output_surface.h" |
20 #include "cc/trees/layer_tree_host.h" | 20 #include "cc/trees/layer_tree_host.h" |
21 #include "content/child/npapi/webplugin.h" | 21 #include "content/child/npapi/webplugin.h" |
| 22 #include "content/common/gpu/client/context_provider_command_buffer.h" |
22 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 23 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
23 #include "content/common/input_messages.h" | 24 #include "content/common/input_messages.h" |
24 #include "content/common/swapped_out_messages.h" | 25 #include "content/common/swapped_out_messages.h" |
25 #include "content/common/view_messages.h" | 26 #include "content/common/view_messages.h" |
26 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
27 #include "content/renderer/cursor_utils.h" | 28 #include "content/renderer/cursor_utils.h" |
28 #include "content/renderer/gpu/compositor_output_surface.h" | 29 #include "content/renderer/gpu/compositor_output_surface.h" |
29 #include "content/renderer/gpu/compositor_software_output_device.h" | 30 #include "content/renderer/gpu/compositor_software_output_device.h" |
30 #include "content/renderer/gpu/delegated_compositor_output_surface.h" | 31 #include "content/renderer/gpu/delegated_compositor_output_surface.h" |
31 #include "content/renderer/gpu/input_handler_manager.h" | 32 #include "content/renderer/gpu/input_handler_manager.h" |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 // GPU and browser processes. For these reasons and to avoid platform | 663 // GPU and browser processes. For these reasons and to avoid platform |
663 // disparities we explicitly disable antialiasing. | 664 // disparities we explicitly disable antialiasing. |
664 WebKit::WebGraphicsContext3D::Attributes attributes; | 665 WebKit::WebGraphicsContext3D::Attributes attributes; |
665 attributes.antialias = false; | 666 attributes.antialias = false; |
666 attributes.shareResources = true; | 667 attributes.shareResources = true; |
667 attributes.noAutomaticFlushes = true; | 668 attributes.noAutomaticFlushes = true; |
668 attributes.depth = false; | 669 attributes.depth = false; |
669 attributes.stencil = false; | 670 attributes.stencil = false; |
670 if (command_line.HasSwitch(cc::switches::kForceDirectLayerDrawing)) | 671 if (command_line.HasSwitch(cc::switches::kForceDirectLayerDrawing)) |
671 attributes.stencil = true; | 672 attributes.stencil = true; |
672 WebGraphicsContext3DCommandBufferImpl* context = NULL; | 673 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
673 if (!fallback) | 674 if (!fallback) { |
674 context = CreateGraphicsContext3D(attributes); | 675 context_provider = ContextProviderCommandBuffer::Create( |
| 676 base::Bind(&RenderWidget::CreateGraphicsContext3D, |
| 677 base::Unretained(this), |
| 678 attributes)); |
| 679 } |
675 | 680 |
676 if (!context) { | 681 if (!context_provider.get()) { |
677 if (!command_line.HasSwitch(switches::kEnableSoftwareCompositing)) | 682 if (!command_line.HasSwitch(switches::kEnableSoftwareCompositing)) |
678 return scoped_ptr<cc::OutputSurface>(); | 683 return scoped_ptr<cc::OutputSurface>(); |
679 return scoped_ptr<cc::OutputSurface>( | 684 |
680 new CompositorOutputSurface(routing_id(), | 685 scoped_ptr<cc::SoftwareOutputDevice> software_device( |
681 output_surface_id, | 686 new CompositorSoftwareOutputDevice()); |
682 NULL, | 687 |
683 new CompositorSoftwareOutputDevice(), | 688 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface( |
684 true)); | 689 routing_id(), |
| 690 output_surface_id, |
| 691 NULL, |
| 692 software_device.Pass(), |
| 693 true)); |
685 } | 694 } |
686 | 695 |
687 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer) && | 696 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer) && |
688 !command_line.HasSwitch(switches::kDisableDelegatedRenderer)) { | 697 !command_line.HasSwitch(switches::kDisableDelegatedRenderer)) { |
689 DCHECK(is_threaded_compositing_enabled_); | 698 DCHECK(is_threaded_compositing_enabled_); |
690 return scoped_ptr<cc::OutputSurface>( | 699 return scoped_ptr<cc::OutputSurface>( |
691 new DelegatedCompositorOutputSurface(routing_id(), output_surface_id, | 700 new DelegatedCompositorOutputSurface( |
692 context, NULL)); | 701 routing_id(), |
| 702 output_surface_id, |
| 703 context_provider, |
| 704 scoped_ptr<cc::SoftwareOutputDevice>())); |
693 } | 705 } |
694 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { | 706 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { |
695 DCHECK(is_threaded_compositing_enabled_); | 707 DCHECK(is_threaded_compositing_enabled_); |
696 return scoped_ptr<cc::OutputSurface>( | 708 return scoped_ptr<cc::OutputSurface>( |
697 new MailboxOutputSurface(routing_id(), output_surface_id, | 709 new MailboxOutputSurface( |
698 context, NULL)); | 710 routing_id(), |
| 711 output_surface_id, |
| 712 context_provider, |
| 713 scoped_ptr<cc::SoftwareOutputDevice>())); |
699 } | 714 } |
| 715 bool use_swap_compositor_frame_message = false; |
700 return scoped_ptr<cc::OutputSurface>( | 716 return scoped_ptr<cc::OutputSurface>( |
701 new CompositorOutputSurface(routing_id(), output_surface_id, | 717 new CompositorOutputSurface( |
702 context, NULL, false)); | 718 routing_id(), |
| 719 output_surface_id, |
| 720 context_provider, |
| 721 scoped_ptr<cc::SoftwareOutputDevice>(), |
| 722 use_swap_compositor_frame_message)); |
703 } | 723 } |
704 | 724 |
705 void RenderWidget::OnViewContextSwapBuffersAborted() { | 725 void RenderWidget::OnViewContextSwapBuffersAborted() { |
706 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted"); | 726 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted"); |
707 while (!updates_pending_swap_.empty()) { | 727 while (!updates_pending_swap_.empty()) { |
708 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front(); | 728 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front(); |
709 updates_pending_swap_.pop_front(); | 729 updates_pending_swap_.pop_front(); |
710 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate | 730 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate |
711 // compositing pass, hence doesn't require an UpdateRect message. | 731 // compositing pass, hence doesn't require an UpdateRect message. |
712 if (msg) | 732 if (msg) |
(...skipping 1786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2499 } | 2519 } |
2500 | 2520 |
2501 void RenderWidget::hasTouchEventHandlers(bool has_handlers) { | 2521 void RenderWidget::hasTouchEventHandlers(bool has_handlers) { |
2502 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers)); | 2522 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers)); |
2503 } | 2523 } |
2504 | 2524 |
2505 bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const { | 2525 bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const { |
2506 return true; | 2526 return true; |
2507 } | 2527 } |
2508 | 2528 |
2509 WebGraphicsContext3DCommandBufferImpl* RenderWidget::CreateGraphicsContext3D( | 2529 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
| 2530 RenderWidget::CreateGraphicsContext3D( |
2510 const WebKit::WebGraphicsContext3D::Attributes& attributes) { | 2531 const WebKit::WebGraphicsContext3D::Attributes& attributes) { |
2511 if (!webwidget_) | 2532 if (!webwidget_) |
2512 return NULL; | 2533 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); |
2513 if (CommandLine::ForCurrentProcess()->HasSwitch( | 2534 if (CommandLine::ForCurrentProcess()->HasSwitch( |
2514 switches::kDisableGpuCompositing)) | 2535 switches::kDisableGpuCompositing)) |
2515 return NULL; | 2536 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); |
2516 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( | 2537 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( |
2517 new WebGraphicsContext3DCommandBufferImpl( | 2538 new WebGraphicsContext3DCommandBufferImpl( |
2518 surface_id(), | 2539 surface_id(), |
2519 GetURLForGraphicsContext3D(), | 2540 GetURLForGraphicsContext3D(), |
2520 RenderThreadImpl::current(), | 2541 RenderThreadImpl::current(), |
2521 weak_ptr_factory_.GetWeakPtr())); | 2542 weak_ptr_factory_.GetWeakPtr())); |
2522 | 2543 |
2523 if (!context->InitializeWithDefaultBufferSizes( | 2544 if (!context->InitializeWithDefaultBufferSizes( |
2524 attributes, | 2545 attributes, |
2525 false /* bind generates resources */, | 2546 false /* bind generates resources */, |
2526 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)
) | 2547 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)
) |
2527 return NULL; | 2548 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); |
2528 return context.release(); | 2549 return context.Pass(); |
2529 } | 2550 } |
2530 | 2551 |
2531 } // namespace content | 2552 } // namespace content |
OLD | NEW |