OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "content/renderer/gpu/render_widget_compositor.h" | 5 #include "content/renderer/gpu/render_widget_compositor.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
14 #include "base/sys_info.h" | 14 #include "base/sys_info.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "cc/base/latency_info_swap_promise.h" | 17 #include "cc/base/latency_info_swap_promise.h" |
18 #include "cc/base/latency_info_swap_promise_monitor.h" | 18 #include "cc/base/latency_info_swap_promise_monitor.h" |
19 #include "cc/base/switches.h" | 19 #include "cc/base/switches.h" |
20 #include "cc/debug/layer_tree_debug_state.h" | 20 #include "cc/debug/layer_tree_debug_state.h" |
21 #include "cc/debug/micro_benchmark.h" | 21 #include "cc/debug/micro_benchmark.h" |
| 22 #include "cc/input/layer_selection_bound.h" |
22 #include "cc/layers/layer.h" | 23 #include "cc/layers/layer.h" |
23 #include "cc/output/copy_output_request.h" | 24 #include "cc/output/copy_output_request.h" |
24 #include "cc/output/copy_output_result.h" | 25 #include "cc/output/copy_output_result.h" |
25 #include "cc/resources/single_release_callback.h" | 26 #include "cc/resources/single_release_callback.h" |
26 #include "cc/trees/layer_tree_host.h" | 27 #include "cc/trees/layer_tree_host.h" |
27 #include "content/child/child_shared_bitmap_manager.h" | 28 #include "content/child/child_shared_bitmap_manager.h" |
28 #include "content/common/content_switches_internal.h" | 29 #include "content/common/content_switches_internal.h" |
29 #include "content/common/gpu/client/context_provider_command_buffer.h" | 30 #include "content/common/gpu/client/context_provider_command_buffer.h" |
30 #include "content/public/common/content_switches.h" | 31 #include "content/public/common/content_switches.h" |
31 #include "content/renderer/compositor_bindings/web_layer_impl.h" | 32 #include "content/renderer/compositor_bindings/web_layer_impl.h" |
32 #include "content/renderer/input/input_handler_manager.h" | 33 #include "content/renderer/input/input_handler_manager.h" |
33 #include "content/renderer/render_thread_impl.h" | 34 #include "content/renderer/render_thread_impl.h" |
34 #include "gpu/command_buffer/client/gles2_interface.h" | 35 #include "gpu/command_buffer/client/gles2_interface.h" |
35 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac
k.h" | 36 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac
k.h" |
| 37 #include "third_party/WebKit/public/platform/WebSelectionBound.h" |
36 #include "third_party/WebKit/public/platform/WebSize.h" | 38 #include "third_party/WebKit/public/platform/WebSize.h" |
37 #include "third_party/WebKit/public/web/WebWidget.h" | 39 #include "third_party/WebKit/public/web/WebWidget.h" |
38 #include "ui/gfx/frame_time.h" | 40 #include "ui/gfx/frame_time.h" |
39 #include "ui/gl/gl_switches.h" | 41 #include "ui/gl/gl_switches.h" |
40 #include "ui/native_theme/native_theme_switches.h" | 42 #include "ui/native_theme/native_theme_switches.h" |
41 | 43 |
42 namespace base { | 44 namespace base { |
43 class Value; | 45 class Value; |
44 } | 46 } |
45 | 47 |
46 namespace cc { | 48 namespace cc { |
47 class Layer; | 49 class Layer; |
48 } | 50 } |
49 | 51 |
50 using blink::WebFloatPoint; | 52 using blink::WebFloatPoint; |
| 53 using blink::WebSelectionBound; |
51 using blink::WebSize; | 54 using blink::WebSize; |
52 using blink::WebRect; | 55 using blink::WebRect; |
53 | 56 |
54 namespace content { | 57 namespace content { |
55 namespace { | 58 namespace { |
56 | 59 |
57 bool GetSwitchValueAsInt( | 60 bool GetSwitchValueAsInt( |
58 const CommandLine& command_line, | 61 const CommandLine& command_line, |
59 const std::string& switch_string, | 62 const std::string& switch_string, |
60 int min_value, | 63 int min_value, |
61 int max_value, | 64 int max_value, |
62 int* result) { | 65 int* result) { |
63 std::string string_value = command_line.GetSwitchValueASCII(switch_string); | 66 std::string string_value = command_line.GetSwitchValueASCII(switch_string); |
64 int int_value; | 67 int int_value; |
65 if (base::StringToInt(string_value, &int_value) && | 68 if (base::StringToInt(string_value, &int_value) && |
66 int_value >= min_value && int_value <= max_value) { | 69 int_value >= min_value && int_value <= max_value) { |
67 *result = int_value; | 70 *result = int_value; |
68 return true; | 71 return true; |
69 } else { | 72 } else { |
70 LOG(WARNING) << "Failed to parse switch " << switch_string << ": " << | 73 LOG(WARNING) << "Failed to parse switch " << switch_string << ": " << |
71 string_value; | 74 string_value; |
72 return false; | 75 return false; |
73 } | 76 } |
74 } | 77 } |
75 | 78 |
| 79 cc::LayerSelectionBound ConvertWebSelectionBound( |
| 80 const WebSelectionBound& bound) { |
| 81 DCHECK(bound.layerId); |
| 82 |
| 83 cc::LayerSelectionBound result; |
| 84 switch (bound.type) { |
| 85 case blink::WebSelectionBound::Caret: |
| 86 result.type = cc::SELECTION_BOUND_CENTER; |
| 87 break; |
| 88 case blink::WebSelectionBound::SelectionLeft: |
| 89 result.type = cc::SELECTION_BOUND_LEFT; |
| 90 break; |
| 91 case blink::WebSelectionBound::SelectionRight: |
| 92 result.type = cc::SELECTION_BOUND_RIGHT; |
| 93 break; |
| 94 } |
| 95 result.layer_id = bound.layerId; |
| 96 result.layer_rect = gfx::Rect(bound.edgeRectInLayer); |
| 97 return result; |
| 98 } |
| 99 |
76 } // namespace | 100 } // namespace |
77 | 101 |
78 // static | 102 // static |
79 scoped_ptr<RenderWidgetCompositor> RenderWidgetCompositor::Create( | 103 scoped_ptr<RenderWidgetCompositor> RenderWidgetCompositor::Create( |
80 RenderWidget* widget, | 104 RenderWidget* widget, |
81 bool threaded) { | 105 bool threaded) { |
82 scoped_ptr<RenderWidgetCompositor> compositor( | 106 scoped_ptr<RenderWidgetCompositor> compositor( |
83 new RenderWidgetCompositor(widget, threaded)); | 107 new RenderWidgetCompositor(widget, threaded)); |
84 | 108 |
85 CommandLine* cmd = CommandLine::ForCurrentProcess(); | 109 CommandLine* cmd = CommandLine::ForCurrentProcess(); |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 ? static_cast<const WebLayerImpl*>(outerViewportScrollLayer)->layer() | 584 ? static_cast<const WebLayerImpl*>(outerViewportScrollLayer)->layer() |
561 : NULL); | 585 : NULL); |
562 } | 586 } |
563 | 587 |
564 void RenderWidgetCompositor::clearViewportLayers() { | 588 void RenderWidgetCompositor::clearViewportLayers() { |
565 layer_tree_host_->RegisterViewportLayers(scoped_refptr<cc::Layer>(), | 589 layer_tree_host_->RegisterViewportLayers(scoped_refptr<cc::Layer>(), |
566 scoped_refptr<cc::Layer>(), | 590 scoped_refptr<cc::Layer>(), |
567 scoped_refptr<cc::Layer>()); | 591 scoped_refptr<cc::Layer>()); |
568 } | 592 } |
569 | 593 |
| 594 void RenderWidgetCompositor::registerSelection( |
| 595 const blink::WebSelectionBound& anchor, |
| 596 const blink::WebSelectionBound& focus) { |
| 597 layer_tree_host_->RegisterSelection(ConvertWebSelectionBound(anchor), |
| 598 ConvertWebSelectionBound(focus)); |
| 599 } |
| 600 |
| 601 void RenderWidgetCompositor::clearSelection() { |
| 602 cc::LayerSelectionBound empty_selection; |
| 603 layer_tree_host_->RegisterSelection(empty_selection, empty_selection); |
| 604 } |
| 605 |
570 void CompositeAndReadbackAsyncCallback( | 606 void CompositeAndReadbackAsyncCallback( |
571 blink::WebCompositeAndReadbackAsyncCallback* callback, | 607 blink::WebCompositeAndReadbackAsyncCallback* callback, |
572 scoped_ptr<cc::CopyOutputResult> result) { | 608 scoped_ptr<cc::CopyOutputResult> result) { |
573 if (result->HasBitmap()) { | 609 if (result->HasBitmap()) { |
574 scoped_ptr<SkBitmap> result_bitmap = result->TakeBitmap(); | 610 scoped_ptr<SkBitmap> result_bitmap = result->TakeBitmap(); |
575 callback->didCompositeAndReadback(*result_bitmap); | 611 callback->didCompositeAndReadback(*result_bitmap); |
576 } else { | 612 } else { |
577 callback->didCompositeAndReadback(SkBitmap()); | 613 callback->didCompositeAndReadback(SkBitmap()); |
578 } | 614 } |
579 } | 615 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 widget_->OnSwapBuffersAborted(); | 736 widget_->OnSwapBuffersAborted(); |
701 } | 737 } |
702 | 738 |
703 void RenderWidgetCompositor::RateLimitSharedMainThreadContext() { | 739 void RenderWidgetCompositor::RateLimitSharedMainThreadContext() { |
704 cc::ContextProvider* provider = | 740 cc::ContextProvider* provider = |
705 RenderThreadImpl::current()->SharedMainThreadContextProvider().get(); | 741 RenderThreadImpl::current()->SharedMainThreadContextProvider().get(); |
706 provider->ContextGL()->RateLimitOffscreenContextCHROMIUM(); | 742 provider->ContextGL()->RateLimitOffscreenContextCHROMIUM(); |
707 } | 743 } |
708 | 744 |
709 } // namespace content | 745 } // namespace content |
OLD | NEW |