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

Side by Side Diff: content/renderer/gpu/render_widget_compositor.cc

Issue 300323005: Route selection bounds updates through the compositor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updates Created 6 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
OLDNEW
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/layers/layer.h" 25 #include "cc/layers/layer.h"
26 #include "cc/output/copy_output_request.h" 26 #include "cc/output/copy_output_request.h"
27 #include "cc/output/copy_output_result.h" 27 #include "cc/output/copy_output_result.h"
28 #include "cc/output/selection_handle.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::Layer** start_layer,
84 cc::SelectionHandle* start_handle,
85 cc::Layer** end_layer,
86 cc::SelectionHandle* end_handle) {
87 DCHECK(start_layer);
88 DCHECK(end_layer);
89 if (selection.type == WebSelection::TypeNone)
90 return false;
91
92 if (!selection.anchorLayer)
93 return false;
94
95 if (selection.type == WebSelection::TypeInsertion) {
96 *start_layer = static_cast<const webkit::WebLayerImpl*>(
97 selection.anchorLayer)->layer();
98 start_handle->type = cc::SelectionHandle::CENTER;
99 start_handle->bounds = gfx::Rect(selection.anchorRectInLayer);
100 return true;
101 }
102
103 if (!selection.focusLayer)
104 return false;
105
106 *start_layer =
107 static_cast<const webkit::WebLayerImpl*>(selection.anchorLayer)->layer();
108 *end_layer =
109 static_cast<const webkit::WebLayerImpl*>(selection.focusLayer)->layer();
110
111 // TODO(jdduke): Use text direction (selection.startDirection) and
112 // anchorIsFirst to properly orient.
113 start_handle->type = cc::SelectionHandle::LEFT;
114 end_handle->type = cc::SelectionHandle::RIGHT;
115
116 start_handle->bounds = gfx::Rect(selection.anchorRectInLayer);
117 end_handle->bounds = gfx::Rect(selection.focusRectInLayer);
118
119 return true;
120 }
121
79 } // namespace 122 } // namespace
80 123
81 // static 124 // static
82 scoped_ptr<RenderWidgetCompositor> RenderWidgetCompositor::Create( 125 scoped_ptr<RenderWidgetCompositor> RenderWidgetCompositor::Create(
83 RenderWidget* widget, 126 RenderWidget* widget,
84 bool threaded) { 127 bool threaded) {
85 scoped_ptr<RenderWidgetCompositor> compositor( 128 scoped_ptr<RenderWidgetCompositor> compositor(
86 new RenderWidgetCompositor(widget, threaded)); 129 new RenderWidgetCompositor(widget, threaded));
87 130
88 CommandLine* cmd = CommandLine::ForCurrentProcess(); 131 CommandLine* cmd = CommandLine::ForCurrentProcess();
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 360
318 compositor->Initialize(settings); 361 compositor->Initialize(settings);
319 362
320 return compositor.Pass(); 363 return compositor.Pass();
321 } 364 }
322 365
323 RenderWidgetCompositor::RenderWidgetCompositor(RenderWidget* widget, 366 RenderWidgetCompositor::RenderWidgetCompositor(RenderWidget* widget,
324 bool threaded) 367 bool threaded)
325 : threaded_(threaded), 368 : threaded_(threaded),
326 suppress_schedule_composite_(false), 369 suppress_schedule_composite_(false),
370 suppress_selection_updates_(false),
327 widget_(widget) { 371 widget_(widget) {
328 } 372 }
329 373
330 RenderWidgetCompositor::~RenderWidgetCompositor() {} 374 RenderWidgetCompositor::~RenderWidgetCompositor() {}
331 375
332 const base::WeakPtr<cc::InputHandler>& 376 const base::WeakPtr<cc::InputHandler>&
333 RenderWidgetCompositor::GetInputHandler() { 377 RenderWidgetCompositor::GetInputHandler() {
334 return layer_tree_host_->GetInputHandler(); 378 return layer_tree_host_->GetInputHandler();
335 } 379 }
336 380
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 const base::Callback<void(scoped_ptr<base::Value>)>& callback) { 463 const base::Callback<void(scoped_ptr<base::Value>)>& callback) {
420 return layer_tree_host_->ScheduleMicroBenchmark(name, value.Pass(), callback); 464 return layer_tree_host_->ScheduleMicroBenchmark(name, value.Pass(), callback);
421 } 465 }
422 466
423 bool RenderWidgetCompositor::SendMessageToMicroBenchmark( 467 bool RenderWidgetCompositor::SendMessageToMicroBenchmark(
424 int id, 468 int id,
425 scoped_ptr<base::Value> value) { 469 scoped_ptr<base::Value> value) {
426 return layer_tree_host_->SendMessageToMicroBenchmark(id, value.Pass()); 470 return layer_tree_host_->SendMessageToMicroBenchmark(id, value.Pass());
427 } 471 }
428 472
473 void RenderWidgetCompositor::SetIgnoreSelectionUpdates(bool ignore_selection) {
474 if (suppress_selection_updates_ == ignore_selection)
475 return;
476
477 if (!suppress_selection_updates_) {
478 cc::SelectionHandle ignored_selection;
479 ignored_selection.type = cc::SelectionHandle::IGNORED;
480 layer_tree_host_->RegisterSelection(scoped_refptr<cc::Layer>(),
481 ignored_selection,
482 scoped_refptr<cc::Layer>(),
483 ignored_selection);
484 }
485
486 suppress_selection_updates_ = ignore_selection;
487 }
488
429 void RenderWidgetCompositor::Initialize(cc::LayerTreeSettings settings) { 489 void RenderWidgetCompositor::Initialize(cc::LayerTreeSettings settings) {
430 scoped_refptr<base::MessageLoopProxy> compositor_message_loop_proxy; 490 scoped_refptr<base::MessageLoopProxy> compositor_message_loop_proxy;
431 RenderThreadImpl* render_thread = RenderThreadImpl::current(); 491 RenderThreadImpl* render_thread = RenderThreadImpl::current();
432 cc::SharedBitmapManager* shared_bitmap_manager = NULL; 492 cc::SharedBitmapManager* shared_bitmap_manager = NULL;
433 // render_thread may be NULL in tests. 493 // render_thread may be NULL in tests.
434 if (render_thread) { 494 if (render_thread) {
435 compositor_message_loop_proxy = 495 compositor_message_loop_proxy =
436 render_thread->compositor_message_loop_proxy(); 496 render_thread->compositor_message_loop_proxy();
437 shared_bitmap_manager = render_thread->shared_bitmap_manager(); 497 shared_bitmap_manager = render_thread->shared_bitmap_manager();
438 } 498 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 outerViewportScrollLayer)->layer() 624 outerViewportScrollLayer)->layer()
565 : NULL); 625 : NULL);
566 } 626 }
567 627
568 void RenderWidgetCompositor::clearViewportLayers() { 628 void RenderWidgetCompositor::clearViewportLayers() {
569 layer_tree_host_->RegisterViewportLayers(scoped_refptr<cc::Layer>(), 629 layer_tree_host_->RegisterViewportLayers(scoped_refptr<cc::Layer>(),
570 scoped_refptr<cc::Layer>(), 630 scoped_refptr<cc::Layer>(),
571 scoped_refptr<cc::Layer>()); 631 scoped_refptr<cc::Layer>());
572 } 632 }
573 633
634 void RenderWidgetCompositor::registerSelection(
635 const blink::WebSelection& selection) {
636 if (suppress_selection_updates_)
637 return;
638
639 cc::Layer* start_layer = NULL;
640 cc::SelectionHandle start_handle;
641 cc::Layer* end_layer = NULL;
642 cc::SelectionHandle end_handle;
643 if (!ConvertWebSelection(
644 selection, &start_layer, &start_handle, &end_layer, &end_handle)) {
645 clearSelection();
646 return;
647 }
648
649 layer_tree_host_->RegisterSelection(
650 start_layer, start_handle, end_layer, end_handle);
651 }
652
653 void RenderWidgetCompositor::clearSelection() {
654 if (suppress_selection_updates_)
655 return;
656
657 cc::SelectionHandle empty_handle;
658 empty_handle.type = cc::SelectionHandle::NONE;
659 layer_tree_host_->RegisterSelection(scoped_refptr<cc::Layer>(),
660 empty_handle,
661 scoped_refptr<cc::Layer>(),
662 empty_handle);
663 }
664
574 void CompositeAndReadbackAsyncCallback( 665 void CompositeAndReadbackAsyncCallback(
575 blink::WebCompositeAndReadbackAsyncCallback* callback, 666 blink::WebCompositeAndReadbackAsyncCallback* callback,
576 scoped_ptr<cc::CopyOutputResult> result) { 667 scoped_ptr<cc::CopyOutputResult> result) {
577 if (result->HasBitmap()) { 668 if (result->HasBitmap()) {
578 scoped_ptr<SkBitmap> result_bitmap = result->TakeBitmap(); 669 scoped_ptr<SkBitmap> result_bitmap = result->TakeBitmap();
579 callback->didCompositeAndReadback(*result_bitmap); 670 callback->didCompositeAndReadback(*result_bitmap);
580 } else { 671 } else {
581 callback->didCompositeAndReadback(SkBitmap()); 672 callback->didCompositeAndReadback(SkBitmap());
582 } 673 }
583 } 674 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 widget_->OnSwapBuffersAborted(); 795 widget_->OnSwapBuffersAborted();
705 } 796 }
706 797
707 void RenderWidgetCompositor::RateLimitSharedMainThreadContext() { 798 void RenderWidgetCompositor::RateLimitSharedMainThreadContext() {
708 cc::ContextProvider* provider = 799 cc::ContextProvider* provider =
709 RenderThreadImpl::current()->SharedMainThreadContextProvider().get(); 800 RenderThreadImpl::current()->SharedMainThreadContextProvider().get();
710 provider->ContextGL()->RateLimitOffscreenContextCHROMIUM(); 801 provider->ContextGL()->RateLimitOffscreenContextCHROMIUM();
711 } 802 }
712 803
713 } // namespace content 804 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698