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 #if defined(OS_ANDROID) | 10 #if defined(OS_ANDROID) |
11 #include "base/android/sys_utils.h" | 11 #include "base/android/sys_utils.h" |
12 #endif | 12 #endif |
13 | 13 |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "base/values.h" | 19 #include "base/values.h" |
20 #include "cc/base/latency_info_swap_promise.h" | 20 #include "cc/base/latency_info_swap_promise.h" |
21 #include "cc/base/latency_info_swap_promise_monitor.h" | 21 #include "cc/base/latency_info_swap_promise_monitor.h" |
22 #include "cc/base/switches.h" | 22 #include "cc/base/switches.h" |
23 #include "cc/debug/layer_tree_debug_state.h" | 23 #include "cc/debug/layer_tree_debug_state.h" |
24 #include "cc/debug/micro_benchmark.h" | 24 #include "cc/debug/micro_benchmark.h" |
25 #include "cc/input/layer_selection_bound.h" | |
25 #include "cc/layers/layer.h" | 26 #include "cc/layers/layer.h" |
26 #include "cc/output/copy_output_request.h" | 27 #include "cc/output/copy_output_request.h" |
27 #include "cc/output/copy_output_result.h" | 28 #include "cc/output/copy_output_result.h" |
28 #include "cc/resources/single_release_callback.h" | 29 #include "cc/resources/single_release_callback.h" |
29 #include "cc/trees/layer_tree_host.h" | 30 #include "cc/trees/layer_tree_host.h" |
30 #include "content/child/child_shared_bitmap_manager.h" | 31 #include "content/child/child_shared_bitmap_manager.h" |
31 #include "content/common/content_switches_internal.h" | 32 #include "content/common/content_switches_internal.h" |
32 #include "content/common/gpu/client/context_provider_command_buffer.h" | 33 #include "content/common/gpu/client/context_provider_command_buffer.h" |
33 #include "content/public/common/content_switches.h" | 34 #include "content/public/common/content_switches.h" |
34 #include "content/renderer/input/input_handler_manager.h" | 35 #include "content/renderer/input/input_handler_manager.h" |
35 #include "content/renderer/render_thread_impl.h" | 36 #include "content/renderer/render_thread_impl.h" |
36 #include "gpu/command_buffer/client/gles2_interface.h" | 37 #include "gpu/command_buffer/client/gles2_interface.h" |
37 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac k.h" | 38 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac k.h" |
38 #include "third_party/WebKit/public/platform/WebSize.h" | 39 #include "third_party/WebKit/public/platform/WebSize.h" |
40 #include "third_party/WebKit/public/web/WebSelection.h" | |
39 #include "third_party/WebKit/public/web/WebWidget.h" | 41 #include "third_party/WebKit/public/web/WebWidget.h" |
40 #include "ui/gfx/frame_time.h" | 42 #include "ui/gfx/frame_time.h" |
41 #include "ui/gl/gl_switches.h" | 43 #include "ui/gl/gl_switches.h" |
42 #include "ui/native_theme/native_theme_switches.h" | 44 #include "ui/native_theme/native_theme_switches.h" |
43 #include "webkit/renderer/compositor_bindings/web_layer_impl.h" | 45 #include "webkit/renderer/compositor_bindings/web_layer_impl.h" |
44 | 46 |
45 namespace base { | 47 namespace base { |
46 class Value; | 48 class Value; |
47 } | 49 } |
48 | 50 |
49 namespace cc { | 51 namespace cc { |
50 class Layer; | 52 class Layer; |
51 } | 53 } |
52 | 54 |
53 using blink::WebFloatPoint; | 55 using blink::WebFloatPoint; |
56 using blink::WebSelection; | |
54 using blink::WebSize; | 57 using blink::WebSize; |
55 using blink::WebRect; | 58 using blink::WebRect; |
56 | 59 |
57 namespace content { | 60 namespace content { |
58 namespace { | 61 namespace { |
59 | 62 |
60 bool GetSwitchValueAsInt( | 63 bool GetSwitchValueAsInt( |
61 const CommandLine& command_line, | 64 const CommandLine& command_line, |
62 const std::string& switch_string, | 65 const std::string& switch_string, |
63 int min_value, | 66 int min_value, |
64 int max_value, | 67 int max_value, |
65 int* result) { | 68 int* result) { |
66 std::string string_value = command_line.GetSwitchValueASCII(switch_string); | 69 std::string string_value = command_line.GetSwitchValueASCII(switch_string); |
67 int int_value; | 70 int int_value; |
68 if (base::StringToInt(string_value, &int_value) && | 71 if (base::StringToInt(string_value, &int_value) && |
69 int_value >= min_value && int_value <= max_value) { | 72 int_value >= min_value && int_value <= max_value) { |
70 *result = int_value; | 73 *result = int_value; |
71 return true; | 74 return true; |
72 } else { | 75 } else { |
73 LOG(WARNING) << "Failed to parse switch " << switch_string << ": " << | 76 LOG(WARNING) << "Failed to parse switch " << switch_string << ": " << |
74 string_value; | 77 string_value; |
75 return false; | 78 return false; |
76 } | 79 } |
77 } | 80 } |
78 | 81 |
82 bool ConvertWebSelection(const WebSelection& selection, | |
83 cc::LayerSelectionBound* anchor, | |
84 cc::LayerSelectionBound* focus) { | |
85 DCHECK(anchor); | |
86 DCHECK(focus); | |
87 if (selection.type == WebSelection::TypeNone) | |
88 return false; | |
89 | |
90 if (!selection.anchorLayerId) | |
91 return false; | |
92 | |
93 if (selection.type == WebSelection::TypeInsertion) { | |
94 anchor->type = cc::SELECTION_BOUND_CENTER; | |
95 anchor->layer_id = selection.anchorLayerId; | |
96 anchor->layer_rect = gfx::Rect(selection.anchorRectInLayer); | |
97 return true; | |
98 } | |
99 | |
100 if (!selection.focusLayerId) | |
101 return false; | |
102 | |
103 anchor->layer_id = selection.anchorLayerId; | |
104 focus->layer_id = selection.focusLayerId; | |
105 | |
106 anchor->type = selection.anchorDirection == blink::WebTextDirectionRightToLeft | |
107 ? cc::SELECTION_BOUND_RIGHT | |
108 : cc::SELECTION_BOUND_LEFT; | |
109 focus->type = selection.focusDirection == blink::WebTextDirectionRightToLeft | |
110 ? cc::SELECTION_BOUND_LEFT | |
111 : cc::SELECTION_BOUND_RIGHT; | |
112 | |
113 anchor->layer_rect = gfx::Rect(selection.anchorRectInLayer); | |
114 focus->layer_rect = gfx::Rect(selection.focusRectInLayer); | |
115 | |
116 return true; | |
117 } | |
118 | |
79 } // namespace | 119 } // namespace |
80 | 120 |
81 // static | 121 // static |
82 scoped_ptr<RenderWidgetCompositor> RenderWidgetCompositor::Create( | 122 scoped_ptr<RenderWidgetCompositor> RenderWidgetCompositor::Create( |
83 RenderWidget* widget, | 123 RenderWidget* widget, |
84 bool threaded) { | 124 bool threaded) { |
85 scoped_ptr<RenderWidgetCompositor> compositor( | 125 scoped_ptr<RenderWidgetCompositor> compositor( |
86 new RenderWidgetCompositor(widget, threaded)); | 126 new RenderWidgetCompositor(widget, threaded)); |
87 | 127 |
88 CommandLine* cmd = CommandLine::ForCurrentProcess(); | 128 CommandLine* cmd = CommandLine::ForCurrentProcess(); |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 | 357 |
318 compositor->Initialize(settings); | 358 compositor->Initialize(settings); |
319 | 359 |
320 return compositor.Pass(); | 360 return compositor.Pass(); |
321 } | 361 } |
322 | 362 |
323 RenderWidgetCompositor::RenderWidgetCompositor(RenderWidget* widget, | 363 RenderWidgetCompositor::RenderWidgetCompositor(RenderWidget* widget, |
324 bool threaded) | 364 bool threaded) |
325 : threaded_(threaded), | 365 : threaded_(threaded), |
326 suppress_schedule_composite_(false), | 366 suppress_schedule_composite_(false), |
367 suppress_selection_updates_(false), | |
327 widget_(widget) { | 368 widget_(widget) { |
328 } | 369 } |
329 | 370 |
330 RenderWidgetCompositor::~RenderWidgetCompositor() {} | 371 RenderWidgetCompositor::~RenderWidgetCompositor() {} |
331 | 372 |
332 const base::WeakPtr<cc::InputHandler>& | 373 const base::WeakPtr<cc::InputHandler>& |
333 RenderWidgetCompositor::GetInputHandler() { | 374 RenderWidgetCompositor::GetInputHandler() { |
334 return layer_tree_host_->GetInputHandler(); | 375 return layer_tree_host_->GetInputHandler(); |
335 } | 376 } |
336 | 377 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 const base::Callback<void(scoped_ptr<base::Value>)>& callback) { | 460 const base::Callback<void(scoped_ptr<base::Value>)>& callback) { |
420 return layer_tree_host_->ScheduleMicroBenchmark(name, value.Pass(), callback); | 461 return layer_tree_host_->ScheduleMicroBenchmark(name, value.Pass(), callback); |
421 } | 462 } |
422 | 463 |
423 bool RenderWidgetCompositor::SendMessageToMicroBenchmark( | 464 bool RenderWidgetCompositor::SendMessageToMicroBenchmark( |
424 int id, | 465 int id, |
425 scoped_ptr<base::Value> value) { | 466 scoped_ptr<base::Value> value) { |
426 return layer_tree_host_->SendMessageToMicroBenchmark(id, value.Pass()); | 467 return layer_tree_host_->SendMessageToMicroBenchmark(id, value.Pass()); |
427 } | 468 } |
428 | 469 |
470 void RenderWidgetCompositor::SetIgnoreSelectionUpdates(bool ignore_selection) { | |
aelias_OOO_until_Jul13
2014/06/12 06:22:42
This feels like the wrong way to solve this. Also
jdduke (slow)
2014/06/12 18:32:44
Sounds good to me. I'll update RenderWidget/Rende
| |
471 if (suppress_selection_updates_ == ignore_selection) | |
472 return; | |
473 | |
474 if (ignore_selection) { | |
475 cc::LayerSelectionBound ignored_selection; | |
476 ignored_selection.type = cc::SELECTION_BOUND_IGNORED; | |
477 layer_tree_host_->RegisterSelection(ignored_selection, ignored_selection); | |
478 } | |
479 | |
480 suppress_selection_updates_ = ignore_selection; | |
481 } | |
482 | |
429 void RenderWidgetCompositor::Initialize(cc::LayerTreeSettings settings) { | 483 void RenderWidgetCompositor::Initialize(cc::LayerTreeSettings settings) { |
430 scoped_refptr<base::MessageLoopProxy> compositor_message_loop_proxy; | 484 scoped_refptr<base::MessageLoopProxy> compositor_message_loop_proxy; |
431 RenderThreadImpl* render_thread = RenderThreadImpl::current(); | 485 RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
432 cc::SharedBitmapManager* shared_bitmap_manager = NULL; | 486 cc::SharedBitmapManager* shared_bitmap_manager = NULL; |
433 // render_thread may be NULL in tests. | 487 // render_thread may be NULL in tests. |
434 if (render_thread) { | 488 if (render_thread) { |
435 compositor_message_loop_proxy = | 489 compositor_message_loop_proxy = |
436 render_thread->compositor_message_loop_proxy(); | 490 render_thread->compositor_message_loop_proxy(); |
437 shared_bitmap_manager = render_thread->shared_bitmap_manager(); | 491 shared_bitmap_manager = render_thread->shared_bitmap_manager(); |
438 } | 492 } |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
564 outerViewportScrollLayer)->layer() | 618 outerViewportScrollLayer)->layer() |
565 : NULL); | 619 : NULL); |
566 } | 620 } |
567 | 621 |
568 void RenderWidgetCompositor::clearViewportLayers() { | 622 void RenderWidgetCompositor::clearViewportLayers() { |
569 layer_tree_host_->RegisterViewportLayers(scoped_refptr<cc::Layer>(), | 623 layer_tree_host_->RegisterViewportLayers(scoped_refptr<cc::Layer>(), |
570 scoped_refptr<cc::Layer>(), | 624 scoped_refptr<cc::Layer>(), |
571 scoped_refptr<cc::Layer>()); | 625 scoped_refptr<cc::Layer>()); |
572 } | 626 } |
573 | 627 |
628 void RenderWidgetCompositor::registerSelection( | |
629 const blink::WebSelection& selection) { | |
630 if (suppress_selection_updates_) | |
631 return; | |
632 | |
633 cc::LayerSelectionBound anchor; | |
634 cc::LayerSelectionBound focus; | |
635 if (!ConvertWebSelection(selection, &anchor, &focus)) { | |
636 clearSelection(); | |
637 return; | |
638 } | |
639 | |
640 layer_tree_host_->RegisterSelection(anchor, focus); | |
641 } | |
642 | |
643 void RenderWidgetCompositor::clearSelection() { | |
644 if (suppress_selection_updates_) | |
645 return; | |
646 | |
647 cc::LayerSelectionBound empty_selection; | |
648 empty_selection.type = cc::SELECTION_BOUND_EMPTY; | |
649 layer_tree_host_->RegisterSelection(empty_selection, empty_selection); | |
650 } | |
651 | |
574 void CompositeAndReadbackAsyncCallback( | 652 void CompositeAndReadbackAsyncCallback( |
575 blink::WebCompositeAndReadbackAsyncCallback* callback, | 653 blink::WebCompositeAndReadbackAsyncCallback* callback, |
576 scoped_ptr<cc::CopyOutputResult> result) { | 654 scoped_ptr<cc::CopyOutputResult> result) { |
577 if (result->HasBitmap()) { | 655 if (result->HasBitmap()) { |
578 scoped_ptr<SkBitmap> result_bitmap = result->TakeBitmap(); | 656 scoped_ptr<SkBitmap> result_bitmap = result->TakeBitmap(); |
579 callback->didCompositeAndReadback(*result_bitmap); | 657 callback->didCompositeAndReadback(*result_bitmap); |
580 } else { | 658 } else { |
581 callback->didCompositeAndReadback(SkBitmap()); | 659 callback->didCompositeAndReadback(SkBitmap()); |
582 } | 660 } |
583 } | 661 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
704 widget_->OnSwapBuffersAborted(); | 782 widget_->OnSwapBuffersAborted(); |
705 } | 783 } |
706 | 784 |
707 void RenderWidgetCompositor::RateLimitSharedMainThreadContext() { | 785 void RenderWidgetCompositor::RateLimitSharedMainThreadContext() { |
708 cc::ContextProvider* provider = | 786 cc::ContextProvider* provider = |
709 RenderThreadImpl::current()->SharedMainThreadContextProvider().get(); | 787 RenderThreadImpl::current()->SharedMainThreadContextProvider().get(); |
710 provider->ContextGL()->RateLimitOffscreenContextCHROMIUM(); | 788 provider->ContextGL()->RateLimitOffscreenContextCHROMIUM(); |
711 } | 789 } |
712 | 790 |
713 } // namespace content | 791 } // namespace content |
OLD | NEW |