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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_android.cc

Issue 2133873004: content: Move Surfaces related code out of RWHVA. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: .. Created 4 years, 4 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) 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/browser/renderer_host/render_widget_host_view_android.h" 5 #include "content/browser/renderer_host/render_widget_host_view_android.h"
6 6
7 #include <android/bitmap.h> 7 #include <android/bitmap.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 30 matching lines...) Expand all
41 #include "content/browser/android/overscroll_controller_android.h" 41 #include "content/browser/android/overscroll_controller_android.h"
42 #include "content/browser/android/popup_touch_handle_drawable.h" 42 #include "content/browser/android/popup_touch_handle_drawable.h"
43 #include "content/browser/android/synchronous_compositor_host.h" 43 #include "content/browser/android/synchronous_compositor_host.h"
44 #include "content/browser/devtools/render_frame_devtools_agent_host.h" 44 #include "content/browser/devtools/render_frame_devtools_agent_host.h"
45 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" 45 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
46 #include "content/browser/gpu/compositor_util.h" 46 #include "content/browser/gpu/compositor_util.h"
47 #include "content/browser/gpu/gpu_data_manager_impl.h" 47 #include "content/browser/gpu/gpu_data_manager_impl.h"
48 #include "content/browser/gpu/gpu_process_host_ui_shim.h" 48 #include "content/browser/gpu/gpu_process_host_ui_shim.h"
49 #include "content/browser/media/android/media_web_contents_observer_android.h" 49 #include "content/browser/media/android/media_web_contents_observer_android.h"
50 #include "content/browser/renderer_host/compositor_impl_android.h" 50 #include "content/browser/renderer_host/compositor_impl_android.h"
51 #include "content/browser/renderer_host/delegated_frame_host_android.h"
51 #include "content/browser/renderer_host/dip_util.h" 52 #include "content/browser/renderer_host/dip_util.h"
52 #include "content/browser/renderer_host/frame_metadata_util.h" 53 #include "content/browser/renderer_host/frame_metadata_util.h"
53 #include "content/browser/renderer_host/input/synthetic_gesture_target_android.h " 54 #include "content/browser/renderer_host/input/synthetic_gesture_target_android.h "
54 #include "content/browser/renderer_host/input/web_input_event_builders_android.h " 55 #include "content/browser/renderer_host/input/web_input_event_builders_android.h "
55 #include "content/browser/renderer_host/input/web_input_event_util.h" 56 #include "content/browser/renderer_host/input/web_input_event_util.h"
56 #include "content/browser/renderer_host/render_process_host_impl.h" 57 #include "content/browser/renderer_host/render_process_host_impl.h"
57 #include "content/browser/renderer_host/render_view_host_impl.h" 58 #include "content/browser/renderer_host/render_view_host_impl.h"
58 #include "content/browser/renderer_host/render_widget_host_impl.h" 59 #include "content/browser/renderer_host/render_widget_host_impl.h"
59 #include "content/common/gpu_host_messages.h" 60 #include "content/common/gpu_host_messages.h"
60 #include "content/common/gpu_process_launch_causes.h" 61 #include "content/common/gpu_process_launch_causes.h"
(...skipping 27 matching lines...) Expand all
88 #include "ui/gfx/android/java_bitmap.h" 89 #include "ui/gfx/android/java_bitmap.h"
89 #include "ui/gfx/android/view_configuration.h" 90 #include "ui/gfx/android/view_configuration.h"
90 #include "ui/gfx/geometry/dip_util.h" 91 #include "ui/gfx/geometry/dip_util.h"
91 #include "ui/gfx/geometry/size_conversions.h" 92 #include "ui/gfx/geometry/size_conversions.h"
92 #include "ui/touch_selection/touch_selection_controller.h" 93 #include "ui/touch_selection/touch_selection_controller.h"
93 94
94 namespace content { 95 namespace content {
95 96
96 namespace { 97 namespace {
97 98
98 void SatisfyCallback(cc::SurfaceManager* manager,
99 const cc::SurfaceSequence& sequence) {
100 std::vector<uint32_t> sequences;
101 sequences.push_back(sequence.sequence);
102 manager->DidSatisfySequences(sequence.client_id, &sequences);
103 }
104
105 void RequireCallback(cc::SurfaceManager* manager,
106 const cc::SurfaceId& id,
107 const cc::SurfaceSequence& sequence) {
108 cc::Surface* surface = manager->GetSurfaceForId(id);
109 if (!surface) {
110 LOG(ERROR) << "Attempting to require callback on nonexistent surface";
111 return;
112 }
113 surface->AddDestructionDependency(sequence);
114 }
115
116 const int kUndefinedOutputSurfaceId = -1; 99 const int kUndefinedOutputSurfaceId = -1;
117 100
118 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime"; 101 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime";
119 102
120 class GLHelperHolder { 103 class GLHelperHolder {
121 public: 104 public:
122 static GLHelperHolder* Create(); 105 static GLHelperHolder* Create();
123 106
124 display_compositor::GLHelper* gl_helper() { return gl_helper_.get(); } 107 display_compositor::GLHelper* gl_helper() { return gl_helper_.get(); }
125 bool IsLost() { 108 bool IsLost() {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 gfx::RectF GetSelectionRect(const ui::TouchSelectionController& controller) { 262 gfx::RectF GetSelectionRect(const ui::TouchSelectionController& controller) {
280 gfx::RectF rect = controller.GetRectBetweenBounds(); 263 gfx::RectF rect = controller.GetRectBetweenBounds();
281 if (rect.IsEmpty()) 264 if (rect.IsEmpty())
282 return rect; 265 return rect;
283 266
284 rect.Union(controller.GetStartHandleRect()); 267 rect.Union(controller.GetStartHandleRect());
285 rect.Union(controller.GetEndHandleRect()); 268 rect.Union(controller.GetEndHandleRect());
286 return rect; 269 return rect;
287 } 270 }
288 271
289 scoped_refptr<cc::SurfaceLayer> CreateSurfaceLayer(
290 const cc::SurfaceId& surface_id,
291 const gfx::Size& size) {
292 DCHECK(!surface_id.is_null());
293 cc::SurfaceManager* manager = CompositorImpl::GetSurfaceManager();
294 DCHECK(manager);
295 // manager must outlive compositors using it.
296 scoped_refptr<cc::SurfaceLayer> surface_layer = cc::SurfaceLayer::Create(
297 base::Bind(&SatisfyCallback, base::Unretained(manager)),
298 base::Bind(&RequireCallback, base::Unretained(manager)));
299 surface_layer->SetSurfaceId(surface_id, 1.f, size);
300 surface_layer->SetBounds(size);
301 surface_layer->SetIsDrawable(true);
302 surface_layer->SetContentsOpaque(true);
303
304 return surface_layer;
305 }
306
307 } // anonymous namespace 272 } // anonymous namespace
308 273
309 RenderWidgetHostViewAndroid::LastFrameInfo::LastFrameInfo( 274 RenderWidgetHostViewAndroid::LastFrameInfo::LastFrameInfo(
310 uint32_t output_id, 275 uint32_t output_id,
311 cc::CompositorFrame output_frame) 276 cc::CompositorFrame output_frame)
312 : output_surface_id(output_id), frame(std::move(output_frame)) {} 277 : output_surface_id(output_id), frame(std::move(output_frame)) {}
313 278
314 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {} 279 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {}
315 280
316 void RenderWidgetHostViewAndroid::OnContextLost() { 281 void RenderWidgetHostViewAndroid::OnContextLost() {
(...skipping 21 matching lines...) Expand all
338 last_output_surface_id_(kUndefinedOutputSurfaceId), 303 last_output_surface_id_(kUndefinedOutputSurfaceId),
339 gesture_provider_(ui::GetGestureProviderConfig( 304 gesture_provider_(ui::GetGestureProviderConfig(
340 ui::GestureProviderConfigType::CURRENT_PLATFORM), 305 ui::GestureProviderConfigType::CURRENT_PLATFORM),
341 this), 306 this),
342 stylus_text_selector_(this), 307 stylus_text_selector_(this),
343 using_browser_compositor_(CompositorImpl::IsInitialized()), 308 using_browser_compositor_(CompositorImpl::IsInitialized()),
344 frame_evictor_(new DelegatedFrameEvictor(this)), 309 frame_evictor_(new DelegatedFrameEvictor(this)),
345 locks_on_frame_count_(0), 310 locks_on_frame_count_(0),
346 observing_root_window_(false), 311 observing_root_window_(false),
347 weak_ptr_factory_(this) { 312 weak_ptr_factory_(this) {
348 id_allocator_.reset( 313 // Set the layer which will hold the content layer for this view. The content
349 new cc::SurfaceIdAllocator(CompositorImpl::AllocateSurfaceClientId())); 314 // layer is managed by the DelegatedFrameHost.
350 CompositorImpl::GetSurfaceManager()->RegisterSurfaceClientId( 315 view_.SetLayer(cc::Layer::Create());
351 id_allocator_->client_id()); 316
317 delegated_frame_host_.reset(new DelegatedFrameHostAndroid(
318 &view_, cached_background_color_,
319 base::Bind(&RenderWidgetHostViewAndroid::ReturnResources,
320 weak_ptr_factory_.GetWeakPtr())));
321
352 host_->SetView(this); 322 host_->SetView(this);
353 SetContentViewCore(content_view_core); 323 SetContentViewCore(content_view_core);
354 } 324 }
355 325
356 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { 326 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() {
357 if (content_view_core_) 327 if (content_view_core_)
358 content_view_core_->RemoveObserver(this); 328 content_view_core_->RemoveObserver(this);
359 SetContentViewCore(NULL); 329 SetContentViewCore(NULL);
360 DCHECK(ack_callbacks_.empty()); 330 DCHECK(ack_callbacks_.empty());
361 DCHECK(!surface_factory_); 331 DCHECK(!delegated_frame_host_);
362 DCHECK(surface_id_.is_null());
363 } 332 }
364 333
365 void RenderWidgetHostViewAndroid::Blur() { 334 void RenderWidgetHostViewAndroid::Blur() {
366 host_->Blur(); 335 host_->Blur();
367 if (overscroll_controller_) 336 if (overscroll_controller_)
368 overscroll_controller_->Disable(); 337 overscroll_controller_->Disable();
369 } 338 }
370 339
371 bool RenderWidgetHostViewAndroid::OnMessageReceived( 340 bool RenderWidgetHostViewAndroid::OnMessageReceived(
372 const IPC::Message& message) { 341 const IPC::Message& message) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 RenderWidgetHostView* reference_host_view) { 375 RenderWidgetHostView* reference_host_view) {
407 NOTIMPLEMENTED(); 376 NOTIMPLEMENTED();
408 } 377 }
409 378
410 RenderWidgetHost* 379 RenderWidgetHost*
411 RenderWidgetHostViewAndroid::GetRenderWidgetHost() const { 380 RenderWidgetHostViewAndroid::GetRenderWidgetHost() const {
412 return host_; 381 return host_;
413 } 382 }
414 383
415 void RenderWidgetHostViewAndroid::WasResized() { 384 void RenderWidgetHostViewAndroid::WasResized() {
385 delegated_frame_host_->UpdateSize(GetViewSize());
416 host_->WasResized(); 386 host_->WasResized();
417 } 387 }
418 388
419 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { 389 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) {
420 // Ignore the given size as only the Java code has the power to 390 // Ignore the given size as only the Java code has the power to
421 // resize the view on Android. 391 // resize the view on Android.
422 default_size_ = size; 392 default_size_ = size;
423 } 393 }
424 394
425 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { 395 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) {
426 SetSize(rect.size()); 396 SetSize(rect.size());
427 } 397 }
428 398
429 void RenderWidgetHostViewAndroid::GetScaledContentBitmap( 399 void RenderWidgetHostViewAndroid::GetScaledContentBitmap(
430 float scale, 400 float scale,
431 SkColorType preferred_color_type, 401 SkColorType preferred_color_type,
432 gfx::Rect src_subrect, 402 gfx::Rect src_subrect,
433 const ReadbackRequestCallback& result_callback) { 403 const ReadbackRequestCallback& result_callback) {
434 if (!host_ || host_->is_hidden() || !IsSurfaceAvailableForCopy()) { 404 if (!host_ || host_->is_hidden() || !IsSurfaceAvailableForCopy()) {
435 result_callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); 405 result_callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE);
436 return; 406 return;
437 } 407 }
438 gfx::Size bounds = view_.GetLayer()->bounds(); 408 gfx::Size bounds = delegated_frame_host_->GetContentLayer()->bounds();
439 if (src_subrect.IsEmpty()) 409 if (src_subrect.IsEmpty())
440 src_subrect = gfx::Rect(bounds); 410 src_subrect = gfx::Rect(bounds);
441 DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width()); 411 DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width());
442 DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height()); 412 DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height());
443 const display::Display& display = 413 const display::Display& display =
444 display::Screen::GetScreen()->GetPrimaryDisplay(); 414 display::Screen::GetScreen()->GetPrimaryDisplay();
445 float device_scale_factor = display.device_scale_factor(); 415 float device_scale_factor = display.device_scale_factor();
446 DCHECK_GT(device_scale_factor, 0); 416 DCHECK_GT(device_scale_factor, 0);
447 gfx::Size dst_size( 417 gfx::Size dst_size(
448 gfx::ScaleToCeiledSize(src_subrect.size(), scale / device_scale_factor)); 418 gfx::ScaleToCeiledSize(src_subrect.size(), scale / device_scale_factor));
449 src_subrect = gfx::ConvertRectToDIP(device_scale_factor, src_subrect); 419 src_subrect = gfx::ConvertRectToDIP(device_scale_factor, src_subrect);
450 420
451 CopyFromCompositingSurface(src_subrect, dst_size, result_callback, 421 CopyFromCompositingSurface(src_subrect, dst_size, result_callback,
452 preferred_color_type); 422 preferred_color_type);
453 } 423 }
454 424
455 bool RenderWidgetHostViewAndroid::HasValidFrame() const { 425 bool RenderWidgetHostViewAndroid::HasValidFrame() const {
456 if (!content_view_core_) 426 if (!content_view_core_)
457 return false; 427 return false;
458 if (!view_.GetLayer()) 428 if (!delegated_frame_host_->GetContentLayer())
459 return false; 429 return false;
460 430
461 if (texture_size_in_layer_.IsEmpty()) 431 if (texture_size_in_layer_.IsEmpty())
462 return false; 432 return false;
463 // This tell us whether a valid frame has arrived or not. 433 // This tell us whether a valid frame has arrived or not.
464 if (!frame_evictor_->HasFrame()) 434 if (!frame_evictor_->HasFrame())
465 return false; 435 return false;
466 436
467 return true; 437 return true;
468 } 438 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 locks_on_frame_count_--; 515 locks_on_frame_count_--;
546 frame_evictor_->UnlockFrame(); 516 frame_evictor_->UnlockFrame();
547 517
548 if (locks_on_frame_count_ == 0) { 518 if (locks_on_frame_count_ == 0) {
549 if (last_frame_info_) { 519 if (last_frame_info_) {
550 InternalSwapCompositorFrame(last_frame_info_->output_surface_id, 520 InternalSwapCompositorFrame(last_frame_info_->output_surface_id,
551 std::move(last_frame_info_->frame)); 521 std::move(last_frame_info_->frame));
552 last_frame_info_.reset(); 522 last_frame_info_.reset();
553 } 523 }
554 524
555 if (!is_showing_ && view_.GetLayer()) 525 if (!is_showing_ && delegated_frame_host_->GetContentLayer())
556 view_.GetLayer()->SetHideLayerAndSubtree(true); 526 delegated_frame_host_->GetContentLayer()->SetHideLayerAndSubtree(true);
557 } 527 }
558 } 528 }
559 529
560 void RenderWidgetHostViewAndroid::OnShowUnhandledTapUIIfNeeded(int x_dip, 530 void RenderWidgetHostViewAndroid::OnShowUnhandledTapUIIfNeeded(int x_dip,
561 int y_dip) { 531 int y_dip) {
562 if (!content_view_core_) 532 if (!content_view_core_)
563 return; 533 return;
564 // Validate the coordinates are within the viewport. 534 // Validate the coordinates are within the viewport.
565 gfx::Size viewport_size = content_view_core_->GetViewportSizeDip(); 535 gfx::Size viewport_size = content_view_core_->GetViewportSizeDip();
566 if (x_dip < 0 || x_dip > viewport_size.width() || 536 if (x_dip < 0 || x_dip > viewport_size.width() ||
567 y_dip < 0 || y_dip > viewport_size.height()) 537 y_dip < 0 || y_dip > viewport_size.height())
568 return; 538 return;
569 content_view_core_->OnShowUnhandledTapUIIfNeeded(x_dip, y_dip); 539 content_view_core_->OnShowUnhandledTapUIIfNeeded(x_dip, y_dip);
570 } 540 }
571 541
572 void RenderWidgetHostViewAndroid::ReleaseLocksOnSurface() { 542 void RenderWidgetHostViewAndroid::ReleaseLocksOnSurface() {
573 if (!frame_evictor_->HasFrame()) { 543 if (!frame_evictor_->HasFrame()) {
574 DCHECK_EQ(locks_on_frame_count_, 0u); 544 DCHECK_EQ(locks_on_frame_count_, 0u);
575 return; 545 return;
576 } 546 }
577 while (locks_on_frame_count_ > 0) { 547 while (locks_on_frame_count_ > 0) {
578 UnlockCompositingSurface(); 548 UnlockCompositingSurface();
579 } 549 }
580 RunAckCallbacks(); 550 RunAckCallbacks();
581 } 551 }
582 552
583 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { 553 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const {
584 if (!content_view_core_) 554 return gfx::Rect(GetViewSize());
585 return gfx::Rect(default_size_);
586
587 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
588 switches::kEnableOSKOverscroll))
589 return gfx::Rect(content_view_core_->GetViewSizeWithOSKHidden());
590
591 return gfx::Rect(content_view_core_->GetViewSize());
592 } 555 }
593 556
594 gfx::Size RenderWidgetHostViewAndroid::GetVisibleViewportSize() const { 557 gfx::Size RenderWidgetHostViewAndroid::GetVisibleViewportSize() const {
595 if (!content_view_core_) 558 if (!content_view_core_)
596 return default_size_; 559 return default_size_;
597 560
598 return content_view_core_->GetViewSize(); 561 return content_view_core_->GetViewSize();
599 } 562 }
600 563
601 gfx::Size RenderWidgetHostViewAndroid::GetPhysicalBackingSize() const { 564 gfx::Size RenderWidgetHostViewAndroid::GetPhysicalBackingSize() const {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 params.value, params.selection_start, params.selection_end, 612 params.value, params.selection_start, params.selection_end,
650 params.composition_start, params.composition_end, 613 params.composition_start, params.composition_end,
651 params.show_ime_if_needed, params.is_non_ime_change); 614 params.show_ime_if_needed, params.is_non_ime_change);
652 } 615 }
653 616
654 void RenderWidgetHostViewAndroid::UpdateBackgroundColor(SkColor color) { 617 void RenderWidgetHostViewAndroid::UpdateBackgroundColor(SkColor color) {
655 if (cached_background_color_ == color) 618 if (cached_background_color_ == color)
656 return; 619 return;
657 620
658 cached_background_color_ = color; 621 cached_background_color_ = color;
622 delegated_frame_host_->UpdateBackgroundColor(color);
659 if (content_view_core_) 623 if (content_view_core_)
660 content_view_core_->OnBackgroundColorChanged(color); 624 content_view_core_->OnBackgroundColorChanged(color);
661 } 625 }
662 626
663 void RenderWidgetHostViewAndroid::OnSetNeedsBeginFrames(bool enabled) { 627 void RenderWidgetHostViewAndroid::OnSetNeedsBeginFrames(bool enabled) {
664 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::OnSetNeedsBeginFrames", 628 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::OnSetNeedsBeginFrames",
665 "enabled", enabled); 629 "enabled", enabled);
666 if (enabled) 630 if (enabled)
667 RequestVSyncUpdate(PERSISTENT_BEGIN_FRAME); 631 RequestVSyncUpdate(PERSISTENT_BEGIN_FRAME);
668 else 632 else
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 ime_adapter_android_.FocusedNodeChanged(is_editable_node); 745 ime_adapter_android_.FocusedNodeChanged(is_editable_node);
782 } 746 }
783 747
784 void RenderWidgetHostViewAndroid::RenderProcessGone( 748 void RenderWidgetHostViewAndroid::RenderProcessGone(
785 base::TerminationStatus status, int error_code) { 749 base::TerminationStatus status, int error_code) {
786 Destroy(); 750 Destroy();
787 } 751 }
788 752
789 void RenderWidgetHostViewAndroid::Destroy() { 753 void RenderWidgetHostViewAndroid::Destroy() {
790 host_->ViewDestroyed(); 754 host_->ViewDestroyed();
791 RemoveLayers();
792 SetContentViewCore(NULL); 755 SetContentViewCore(NULL);
793 756 delegated_frame_host_.reset();
794 if (!surface_id_.is_null()) {
795 DCHECK(surface_factory_.get());
796 surface_factory_->Destroy(surface_id_);
797 surface_id_ = cc::SurfaceId();
798 }
799 surface_factory_.reset();
800 CompositorImpl::GetSurfaceManager()->InvalidateSurfaceClientId(
801 id_allocator_->client_id());
802 757
803 // The RenderWidgetHost's destruction led here, so don't call it. 758 // The RenderWidgetHost's destruction led here, so don't call it.
804 host_ = NULL; 759 host_ = NULL;
805 760
806 delete this; 761 delete this;
807 } 762 }
808 763
809 void RenderWidgetHostViewAndroid::SetTooltipText( 764 void RenderWidgetHostViewAndroid::SetTooltipText(
810 const base::string16& tooltip_text) { 765 const base::string16& tooltip_text) {
811 // Tooltips don't makes sense on Android. 766 // Tooltips don't makes sense on Android.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, 832 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback,
878 preferred_color_type); 833 preferred_color_type);
879 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", 834 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous",
880 base::TimeTicks::Now() - start_time); 835 base::TimeTicks::Now() - start_time);
881 return; 836 return;
882 } 837 }
883 838
884 ui::WindowAndroidCompositor* compositor = 839 ui::WindowAndroidCompositor* compositor =
885 content_view_core_->GetWindowAndroid()->GetCompositor(); 840 content_view_core_->GetWindowAndroid()->GetCompositor();
886 DCHECK(compositor); 841 DCHECK(compositor);
887 DCHECK(!surface_id_.is_null()); 842 DCHECK(delegated_frame_host_->GetContentLayer());
888 std::unique_ptr<cc::CopyOutputRequest> request = 843 std::unique_ptr<cc::CopyOutputRequest> request =
889 cc::CopyOutputRequest::CreateRequest(base::Bind( 844 cc::CopyOutputRequest::CreateRequest(base::Bind(
890 &PrepareTextureCopyOutputResult, weak_ptr_factory_.GetWeakPtr(), 845 &PrepareTextureCopyOutputResult, weak_ptr_factory_.GetWeakPtr(),
891 dst_size_in_pixel, preferred_color_type, start_time, callback)); 846 dst_size_in_pixel, preferred_color_type, start_time, callback));
892 if (!src_subrect_in_pixel.IsEmpty()) 847 if (!src_subrect_in_pixel.IsEmpty())
893 request->set_area(src_subrect_in_pixel); 848 request->set_area(src_subrect_in_pixel);
894 // Make sure the layer doesn't get deleted until we fulfill the request. 849 // Make sure the layer doesn't get deleted until we fulfill the request.
895 LockCompositingSurface(); 850 LockCompositingSurface();
896 view_.GetLayer()->RequestCopyOfOutput(std::move(request)); 851 delegated_frame_host_->GetContentLayer()->RequestCopyOfOutput(
852 std::move(request));
897 } 853 }
898 854
899 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( 855 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame(
900 const gfx::Rect& src_subrect, 856 const gfx::Rect& src_subrect,
901 const scoped_refptr<media::VideoFrame>& target, 857 const scoped_refptr<media::VideoFrame>& target,
902 const base::Callback<void(const gfx::Rect&, bool)>& callback) { 858 const base::Callback<void(const gfx::Rect&, bool)>& callback) {
903 NOTIMPLEMENTED(); 859 NOTIMPLEMENTED();
904 callback.Run(gfx::Rect(), false); 860 callback.Run(gfx::Rect(), false);
905 } 861 }
906 862
(...skipping 30 matching lines...) Expand all
937 const cc::ReturnedResourceArray& resources) { 893 const cc::ReturnedResourceArray& resources) {
938 if (resources.empty()) 894 if (resources.empty())
939 return; 895 return;
940 std::copy(resources.begin(), resources.end(), 896 std::copy(resources.begin(), resources.end(),
941 std::back_inserter(surface_returned_resources_)); 897 std::back_inserter(surface_returned_resources_));
942 if (ack_callbacks_.empty()) 898 if (ack_callbacks_.empty())
943 SendReclaimCompositorResources(last_output_surface_id_, 899 SendReclaimCompositorResources(last_output_surface_id_,
944 false /* is_swap_ack */); 900 false /* is_swap_ack */);
945 } 901 }
946 902
947 void RenderWidgetHostViewAndroid::SetBeginFrameSource(
948 cc::BeginFrameSource* begin_frame_source) {
949 // TODO(tansell): Hook this up.
950 }
951
952 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() {
953 RemoveLayers();
954 if (!surface_id_.is_null()) {
955 DCHECK(surface_factory_.get());
956 surface_factory_->Destroy(surface_id_);
957 surface_id_ = cc::SurfaceId();
958 }
959 view_.SetLayer(nullptr);
960 }
961
962 void RenderWidgetHostViewAndroid::CheckOutputSurfaceChanged( 903 void RenderWidgetHostViewAndroid::CheckOutputSurfaceChanged(
963 uint32_t output_surface_id) { 904 uint32_t output_surface_id) {
964 if (output_surface_id == last_output_surface_id_) 905 if (output_surface_id == last_output_surface_id_)
965 return; 906 return;
966 DestroyDelegatedContent(); 907 delegated_frame_host_->OutputSurfaceChanged();
967 surface_factory_.reset(); 908
968 if (!surface_returned_resources_.empty()) 909 if (!surface_returned_resources_.empty())
969 SendReclaimCompositorResources(last_output_surface_id_, 910 SendReclaimCompositorResources(last_output_surface_id_,
970 false /* is_swap_ack */); 911 false /* is_swap_ack */);
971 912
972 last_output_surface_id_ = output_surface_id; 913 last_output_surface_id_ = output_surface_id;
973 } 914 }
974 915
975 void RenderWidgetHostViewAndroid::SubmitCompositorFrame(
976 cc::CompositorFrame frame) {
977 cc::SurfaceManager* manager = CompositorImpl::GetSurfaceManager();
978 if (!surface_factory_) {
979 surface_factory_ = base::WrapUnique(new cc::SurfaceFactory(manager, this));
980 }
981 if (surface_id_.is_null() ||
982 texture_size_in_layer_ != current_surface_size_ ||
983 location_bar_content_translation_ !=
984 frame.metadata.location_bar_content_translation ||
985 current_viewport_selection_ != frame.metadata.selection) {
986 RemoveLayers();
987 if (!surface_id_.is_null())
988 surface_factory_->Destroy(surface_id_);
989 surface_id_ = id_allocator_->GenerateId();
990 surface_factory_->Create(surface_id_);
991 view_.SetLayer(CreateSurfaceLayer(surface_id_, texture_size_in_layer_));
992
993 DCHECK(view_.GetLayer());
994
995 current_surface_size_ = texture_size_in_layer_;
996 location_bar_content_translation_ =
997 frame.metadata.location_bar_content_translation;
998 current_viewport_selection_ = frame.metadata.selection;
999 AttachLayers();
1000 }
1001
1002 cc::SurfaceFactory::DrawCallback ack_callback =
1003 base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks,
1004 weak_ptr_factory_.GetWeakPtr());
1005 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame),
1006 ack_callback);
1007 }
1008
1009 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( 916 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame(
1010 uint32_t output_surface_id, 917 uint32_t output_surface_id,
1011 cc::CompositorFrame frame) { 918 cc::CompositorFrame frame) {
1012 last_scroll_offset_ = frame.metadata.root_scroll_offset; 919 last_scroll_offset_ = frame.metadata.root_scroll_offset;
1013 DCHECK(frame.delegated_frame_data); 920 DCHECK(frame.delegated_frame_data);
1014 DCHECK(CompositorImpl::GetSurfaceManager()); 921 DCHECK(delegated_frame_host_);
1015 922
1016 if (locks_on_frame_count_ > 0) { 923 if (locks_on_frame_count_ > 0) {
1017 DCHECK(HasValidFrame()); 924 DCHECK(HasValidFrame());
1018 RetainFrame(output_surface_id, std::move(frame)); 925 RetainFrame(output_surface_id, std::move(frame));
1019 return; 926 return;
1020 } 927 }
1021 928
1022 DCHECK(!frame.delegated_frame_data->render_pass_list.empty()); 929 DCHECK(!frame.delegated_frame_data->render_pass_list.empty());
1023 930
1024 cc::RenderPass* root_pass = 931 cc::RenderPass* root_pass =
1025 frame.delegated_frame_data->render_pass_list.back().get(); 932 frame.delegated_frame_data->render_pass_list.back().get();
1026 texture_size_in_layer_ = root_pass->output_rect.size(); 933 texture_size_in_layer_ = root_pass->output_rect.size();
1027 934
1028 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); 935 cc::CompositorFrameMetadata metadata = frame.metadata.Clone();
1029 936
1030 CheckOutputSurfaceChanged(output_surface_id); 937 CheckOutputSurfaceChanged(output_surface_id);
1031 bool has_content = !texture_size_in_layer_.IsEmpty(); 938 bool has_content = !texture_size_in_layer_.IsEmpty();
1032 939
1033 base::Closure ack_callback = 940 base::Closure ack_callback =
1034 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources, 941 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources,
1035 weak_ptr_factory_.GetWeakPtr(), output_surface_id, 942 weak_ptr_factory_.GetWeakPtr(), output_surface_id,
1036 true /* is_swap_ack */); 943 true /* is_swap_ack */);
1037 944
1038 ack_callbacks_.push(ack_callback); 945 ack_callbacks_.push(ack_callback);
1039 946
1040 if (!has_content) { 947 if (!has_content) {
1041 DestroyDelegatedContent(); 948 delegated_frame_host_->DestroyDelegatedContent();
1042 } else { 949 } else {
1043 SubmitCompositorFrame(std::move(frame)); 950 cc::SurfaceFactory::DrawCallback ack_callback =
1044 view_.GetLayer()->SetIsDrawable(true); 951 base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks,
1045 view_.GetLayer()->SetContentsOpaque(true); 952 weak_ptr_factory_.GetWeakPtr());
1046 view_.GetLayer()->SetBounds(texture_size_in_layer_); 953 delegated_frame_host_->SubmitCompositorFrame(std::move(frame),
954 ack_callback);
1047 } 955 }
1048 956
1049 if (host_->is_hidden()) 957 if (host_->is_hidden())
1050 RunAckCallbacks(); 958 RunAckCallbacks();
1051 frame_evictor_->SwappedFrame(!host_->is_hidden()); 959 frame_evictor_->SwappedFrame(!host_->is_hidden());
1052 960
1053 // As the metadata update may trigger view invalidation, always call it after 961 // As the metadata update may trigger view invalidation, always call it after
1054 // any potential compositor scheduling. 962 // any potential compositor scheduling.
1055 OnFrameMetadataUpdated(std::move(metadata)); 963 OnFrameMetadataUpdated(std::move(metadata));
1056 } 964 }
1057 965
1058 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( 966 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame(
1059 uint32_t output_surface_id, 967 uint32_t output_surface_id,
1060 cc::CompositorFrame frame) { 968 cc::CompositorFrame frame) {
1061 InternalSwapCompositorFrame(output_surface_id, std::move(frame)); 969 InternalSwapCompositorFrame(output_surface_id, std::move(frame));
1062 } 970 }
1063 971
1064 void RenderWidgetHostViewAndroid::ClearCompositorFrame() { 972 void RenderWidgetHostViewAndroid::ClearCompositorFrame() {
1065 DestroyDelegatedContent(); 973 delegated_frame_host_->DestroyDelegatedContent();
1066 } 974 }
1067 975
1068 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t output_surface_id, 976 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t output_surface_id,
1069 cc::CompositorFrame frame) { 977 cc::CompositorFrame frame) {
1070 DCHECK(locks_on_frame_count_); 978 DCHECK(locks_on_frame_count_);
1071 979
1072 // Store the incoming frame so that it can be swapped when all the locks have 980 // Store the incoming frame so that it can be swapped when all the locks have
1073 // been released. If there is already a stored frame, then replace and skip 981 // been released. If there is already a stored frame, then replace and skip
1074 // the previous one but make sure we still eventually send the ACK. Holding 982 // the previous one but make sure we still eventually send the ACK. Holding
1075 // the ACK also blocks the renderer when its max_frames_pending is reached. 983 // the ACK also blocks the renderer when its max_frames_pending is reached.
(...skipping 28 matching lines...) Expand all
1104 BrowserThread::PostTask( 1012 BrowserThread::PostTask(
1105 BrowserThread::UI, FROM_HERE, 1013 BrowserThread::UI, FROM_HERE,
1106 base::Bind( 1014 base::Bind(
1107 &RenderFrameDevToolsAgentHost::SynchronousSwapCompositorFrame, 1015 &RenderFrameDevToolsAgentHost::SynchronousSwapCompositorFrame,
1108 static_cast<RenderFrameDevToolsAgentHost*>(dtah.get()), 1016 static_cast<RenderFrameDevToolsAgentHost*>(dtah.get()),
1109 base::Passed(&frame_metadata))); 1017 base::Passed(&frame_metadata)));
1110 } 1018 }
1111 } 1019 }
1112 1020
1113 void RenderWidgetHostViewAndroid::SetOverlayVideoMode(bool enabled) { 1021 void RenderWidgetHostViewAndroid::SetOverlayVideoMode(bool enabled) {
1114 if (view_.GetLayer()) 1022 if (delegated_frame_host_->GetContentLayer())
1115 view_.GetLayer()->SetContentsOpaque(!enabled); 1023 delegated_frame_host_->GetContentLayer()->SetContentsOpaque(!enabled);
1116 } 1024 }
1117 1025
1118 bool RenderWidgetHostViewAndroid::SupportsAnimation() const { 1026 bool RenderWidgetHostViewAndroid::SupportsAnimation() const {
1119 // The synchronous (WebView) compositor does not have a proper browser 1027 // The synchronous (WebView) compositor does not have a proper browser
1120 // compositor with which to drive animations. 1028 // compositor with which to drive animations.
1121 return using_browser_compositor_; 1029 return using_browser_compositor_;
1122 } 1030 }
1123 1031
1124 void RenderWidgetHostViewAndroid::SetNeedsAnimate() { 1032 void RenderWidgetHostViewAndroid::SetNeedsAnimate() {
1125 DCHECK(content_view_core_ && content_view_core_->GetWindowAndroid()); 1033 DCHECK(content_view_core_ && content_view_core_->GetWindowAndroid());
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 WebContents* web_contents = 1169 WebContents* web_contents =
1262 WebContents::FromRenderViewHost(RenderViewHostImpl::From(host_)); 1170 WebContents::FromRenderViewHost(RenderViewHostImpl::From(host_));
1263 if (web_contents) { 1171 if (web_contents) {
1264 MediaWebContentsObserverAndroid::FromWebContents(web_contents) 1172 MediaWebContentsObserverAndroid::FromWebContents(web_contents)
1265 ->OnFrameInfoUpdated(); 1173 ->OnFrameInfoUpdated();
1266 } 1174 }
1267 } 1175 }
1268 #endif // defined(VIDEO_HOLE) 1176 #endif // defined(VIDEO_HOLE)
1269 } 1177 }
1270 1178
1179 gfx::Size RenderWidgetHostViewAndroid::GetViewSize() const {
1180 if (!content_view_core_)
1181 return default_size_;
1182
1183 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1184 switches::kEnableOSKOverscroll))
1185 return content_view_core_->GetViewSizeWithOSKHidden();
1186
1187 return content_view_core_->GetViewSize();
1188 }
1189
1271 void RenderWidgetHostViewAndroid::ShowInternal() { 1190 void RenderWidgetHostViewAndroid::ShowInternal() {
1272 bool show = is_showing_ && is_window_activity_started_ && is_window_visible_; 1191 bool show = is_showing_ && is_window_activity_started_ && is_window_visible_;
1273 if (!show) 1192 if (!show)
1274 return; 1193 return;
1275 1194
1276 if (!host_ || !host_->is_hidden()) 1195 if (!host_ || !host_->is_hidden())
1277 return; 1196 return;
1278 1197
1279 if (view_.GetLayer()) 1198 if (delegated_frame_host_->GetContentLayer())
1280 view_.GetLayer()->SetHideLayerAndSubtree(false); 1199 delegated_frame_host_->GetContentLayer()->SetHideLayerAndSubtree(false);
1281 1200
1282 frame_evictor_->SetVisible(true); 1201 frame_evictor_->SetVisible(true);
1283 1202
1284 if (overscroll_controller_) 1203 if (overscroll_controller_)
1285 overscroll_controller_->Enable(); 1204 overscroll_controller_->Enable();
1286 1205
1287 host_->WasShown(ui::LatencyInfo()); 1206 host_->WasShown(ui::LatencyInfo());
1288 1207
1289 if (content_view_core_) { 1208 if (content_view_core_) {
1290 StartObservingRootWindow(); 1209 StartObservingRootWindow();
1291 RequestVSyncUpdate(BEGIN_FRAME); 1210 RequestVSyncUpdate(BEGIN_FRAME);
1292 } 1211 }
1293 } 1212 }
1294 1213
1295 void RenderWidgetHostViewAndroid::HideInternal() { 1214 void RenderWidgetHostViewAndroid::HideInternal() {
1296 DCHECK(!is_showing_ || !is_window_activity_started_ || !is_window_visible_) 1215 DCHECK(!is_showing_ || !is_window_activity_started_ || !is_window_visible_)
1297 << "Hide called when the widget should be shown."; 1216 << "Hide called when the widget should be shown.";
1298 1217
1299 // Only preserve the frontbuffer if the activity was stopped while the 1218 // Only preserve the frontbuffer if the activity was stopped while the
1300 // window is still visible. This avoids visual artificts when transitioning 1219 // window is still visible. This avoids visual artificts when transitioning
1301 // between activities. 1220 // between activities.
1302 bool hide_frontbuffer = is_window_activity_started_ || !is_window_visible_; 1221 bool hide_frontbuffer = is_window_activity_started_ || !is_window_visible_;
1303 1222
1304 // Only stop observing the root window if the widget has been explicitly 1223 // Only stop observing the root window if the widget has been explicitly
1305 // hidden and the frontbuffer is being cleared. This allows window visibility 1224 // hidden and the frontbuffer is being cleared. This allows window visibility
1306 // notifications to eventually clear the frontbuffer. 1225 // notifications to eventually clear the frontbuffer.
1307 bool stop_observing_root_window = !is_showing_ && hide_frontbuffer; 1226 bool stop_observing_root_window = !is_showing_ && hide_frontbuffer;
1308 1227
1309 if (hide_frontbuffer) { 1228 if (hide_frontbuffer) {
1310 if (view_.GetLayer() && locks_on_frame_count_ == 0) 1229 if (delegated_frame_host_->GetContentLayer() && locks_on_frame_count_ == 0)
1311 view_.GetLayer()->SetHideLayerAndSubtree(true); 1230 delegated_frame_host_->GetContentLayer()->SetHideLayerAndSubtree(true);
1312 1231
1313 frame_evictor_->SetVisible(false); 1232 frame_evictor_->SetVisible(false);
1314 } 1233 }
1315 1234
1316 if (stop_observing_root_window) { 1235 if (stop_observing_root_window) {
1317 DCHECK(!is_showing_); 1236 DCHECK(!is_showing_);
1318 StopObservingRootWindow(); 1237 StopObservingRootWindow();
1319 } 1238 }
1320 1239
1321 if (!host_ || host_->is_hidden()) 1240 if (!host_ || host_->is_hidden())
1322 return; 1241 return;
1323 1242
1324 if (overscroll_controller_) 1243 if (overscroll_controller_)
1325 overscroll_controller_->Disable(); 1244 overscroll_controller_->Disable();
1326 1245
1327 RunAckCallbacks(); 1246 RunAckCallbacks();
1328 1247
1329 // Inform the renderer that we are being hidden so it can reduce its resource 1248 // Inform the renderer that we are being hidden so it can reduce its resource
1330 // utilization. 1249 // utilization.
1331 host_->WasHidden(); 1250 host_->WasHidden();
1332 } 1251 }
1333 1252
1334 void RenderWidgetHostViewAndroid::AttachLayers() {
1335 if (!content_view_core_)
1336 return;
1337 if (!view_.GetLayer())
1338 return;
1339
1340 content_view_core_->AttachLayer(view_.GetLayer());
1341 view_.GetLayer()->SetHideLayerAndSubtree(!is_showing_);
1342 }
1343
1344 void RenderWidgetHostViewAndroid::RemoveLayers() {
1345 if (!content_view_core_)
1346 return;
1347
1348 if (!view_.GetLayer())
1349 return;
1350
1351 content_view_core_->RemoveLayer(view_.GetLayer());
1352 }
1353
1354 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32_t requests) { 1253 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32_t requests) {
1355 bool should_request_vsync = !outstanding_vsync_requests_ && requests; 1254 bool should_request_vsync = !outstanding_vsync_requests_ && requests;
1356 outstanding_vsync_requests_ |= requests; 1255 outstanding_vsync_requests_ |= requests;
1357 1256
1358 // Note that if we're not currently observing the root window, outstanding 1257 // Note that if we're not currently observing the root window, outstanding
1359 // vsync requests will be pushed if/when we resume observing in 1258 // vsync requests will be pushed if/when we resume observing in
1360 // |StartObservingRootWindow()|. 1259 // |StartObservingRootWindow()|.
1361 if (observing_root_window_ && should_request_vsync) 1260 if (observing_root_window_ && should_request_vsync)
1362 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); 1261 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate();
1363 } 1262 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 } 1329 }
1431 1330
1432 void RenderWidgetHostViewAndroid::RequestDisallowInterceptTouchEvent() { 1331 void RenderWidgetHostViewAndroid::RequestDisallowInterceptTouchEvent() {
1433 if (content_view_core_) 1332 if (content_view_core_)
1434 content_view_core_->RequestDisallowInterceptTouchEvent(); 1333 content_view_core_->RequestDisallowInterceptTouchEvent();
1435 } 1334 }
1436 1335
1437 void RenderWidgetHostViewAndroid::EvictDelegatedFrame() { 1336 void RenderWidgetHostViewAndroid::EvictDelegatedFrame() {
1438 DCHECK_EQ(locks_on_frame_count_, 0u); 1337 DCHECK_EQ(locks_on_frame_count_, 0u);
1439 frame_evictor_->DiscardedFrame(); 1338 frame_evictor_->DiscardedFrame();
1440 if (view_.GetLayer()) 1339 delegated_frame_host_->DestroyDelegatedContent();
1441 DestroyDelegatedContent();
1442 } 1340 }
1443 1341
1444 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface( 1342 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface(
1445 const gfx::Size& desired_size) { 1343 const gfx::Size& desired_size) {
1446 NOTREACHED(); 1344 NOTREACHED();
1447 return false; 1345 return false;
1448 } 1346 }
1449 1347
1450 void RenderWidgetHostViewAndroid::GetScreenInfo(blink::WebScreenInfo* result) { 1348 void RenderWidgetHostViewAndroid::GetScreenInfo(blink::WebScreenInfo* result) {
1451 // ScreenInfo isn't tied to the widget on Android. Always return the default. 1349 // ScreenInfo isn't tied to the widget on Android. Always return the default.
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 1539
1642 SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const { 1540 SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const {
1643 return cached_background_color_; 1541 return cached_background_color_;
1644 } 1542 }
1645 1543
1646 void RenderWidgetHostViewAndroid::DidOverscroll( 1544 void RenderWidgetHostViewAndroid::DidOverscroll(
1647 const DidOverscrollParams& params) { 1545 const DidOverscrollParams& params) {
1648 if (sync_compositor_) 1546 if (sync_compositor_)
1649 sync_compositor_->DidOverscroll(params); 1547 sync_compositor_->DidOverscroll(params);
1650 1548
1651 if (!content_view_core_ || !view_.GetLayer() || !is_showing_) 1549 if (!content_view_core_ || !delegated_frame_host_->GetContentLayer() ||
1550 !is_showing_)
1652 return; 1551 return;
1653 1552
1654 if (overscroll_controller_) 1553 if (overscroll_controller_)
1655 overscroll_controller_->OnOverscrolled(params); 1554 overscroll_controller_->OnOverscrolled(params);
1656 } 1555 }
1657 1556
1658 void RenderWidgetHostViewAndroid::DidStopFlinging() { 1557 void RenderWidgetHostViewAndroid::DidStopFlinging() {
1659 if (content_view_core_) 1558 if (content_view_core_)
1660 content_view_core_->DidStopFlinging(); 1559 content_view_core_->DidStopFlinging();
1661 } 1560 }
1662 1561
1663 uint32_t RenderWidgetHostViewAndroid::GetSurfaceClientId() { 1562 uint32_t RenderWidgetHostViewAndroid::GetSurfaceClientId() {
1664 if (id_allocator_) 1563 if (!delegated_frame_host_)
1665 return id_allocator_->client_id(); 1564 return 0;
1666 return 0; 1565
1566 return delegated_frame_host_->GetSurfaceClientId();
1667 } 1567 }
1668 1568
1669 void RenderWidgetHostViewAndroid::SetContentViewCore( 1569 void RenderWidgetHostViewAndroid::SetContentViewCore(
1670 ContentViewCoreImpl* content_view_core) { 1570 ContentViewCoreImpl* content_view_core) {
1671 DCHECK(!content_view_core || !content_view_core_ || 1571 DCHECK(!content_view_core || !content_view_core_ ||
1672 (content_view_core_ == content_view_core)); 1572 (content_view_core_ == content_view_core));
1673 RemoveLayers();
1674 StopObservingRootWindow(); 1573 StopObservingRootWindow();
1675 1574
1676 bool resize = false; 1575 bool resize = false;
1677 if (content_view_core != content_view_core_) { 1576 if (content_view_core != content_view_core_) {
1678 overscroll_controller_.reset(); 1577 overscroll_controller_.reset();
1679 selection_controller_.reset(); 1578 selection_controller_.reset();
1680 ReleaseLocksOnSurface(); 1579 ReleaseLocksOnSurface();
1681 // TODO(yusufo) : Get rid of the below conditions and have a better handling 1580 // TODO(yusufo) : Get rid of the below conditions and have a better handling
1682 // for resizing after crbug.com/628302 is handled. 1581 // for resizing after crbug.com/628302 is handled.
1683 bool is_size_initialized = !content_view_core 1582 bool is_size_initialized = !content_view_core
1684 || content_view_core->GetViewportSizeDip().width() != 0 1583 || content_view_core->GetViewportSizeDip().width() != 0
1685 || content_view_core->GetViewportSizeDip().height() != 0; 1584 || content_view_core->GetViewportSizeDip().height() != 0;
1686 if (content_view_core_ || is_size_initialized) 1585 if (content_view_core_ || is_size_initialized)
1687 resize = true; 1586 resize = true;
1688 if (content_view_core_) { 1587 if (content_view_core_) {
1689 content_view_core_->RemoveObserver(this); 1588 content_view_core_->RemoveObserver(this);
1690 view_.RemoveFromParent(); 1589 view_.RemoveFromParent();
1590 view_.GetLayer()->RemoveFromParent();
1691 } 1591 }
1692 if (content_view_core) { 1592 if (content_view_core) {
1693 content_view_core->AddObserver(this); 1593 content_view_core->AddObserver(this);
1694 content_view_core->GetViewAndroid()->AddChild(&view_); 1594 ui::ViewAndroid* parent_view = content_view_core->GetViewAndroid();
1595 parent_view->AddChild(&view_);
1596 parent_view->GetLayer()->AddChild(view_.GetLayer());
1695 } 1597 }
1696 content_view_core_ = content_view_core; 1598 content_view_core_ = content_view_core;
1697 } 1599 }
1698 1600
1699 BrowserAccessibilityManager* manager = NULL; 1601 BrowserAccessibilityManager* manager = NULL;
1700 if (host_) 1602 if (host_)
1701 manager = host_->GetRootBrowserAccessibilityManager(); 1603 manager = host_->GetRootBrowserAccessibilityManager();
1702 if (manager) { 1604 if (manager) {
1703 base::android::ScopedJavaLocalRef<jobject> obj; 1605 base::android::ScopedJavaLocalRef<jobject> obj;
1704 if (content_view_core_) 1606 if (content_view_core_)
1705 obj = content_view_core_->GetJavaObject(); 1607 obj = content_view_core_->GetJavaObject();
1706 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); 1608 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj);
1707 } 1609 }
1708 1610
1709 AttachLayers();
1710 if (!content_view_core_) { 1611 if (!content_view_core_) {
1711 sync_compositor_.reset(); 1612 sync_compositor_.reset();
1712 return; 1613 return;
1713 } 1614 }
1714 1615
1715 if (is_showing_) 1616 if (is_showing_)
1716 StartObservingRootWindow(); 1617 StartObservingRootWindow();
1717 1618
1718 if (resize) 1619 if (resize)
1719 WasResized(); 1620 WasResized();
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1844 1745
1845 void RenderWidgetHostViewAndroid::OnActivityStarted() { 1746 void RenderWidgetHostViewAndroid::OnActivityStarted() {
1846 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityStarted"); 1747 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityStarted");
1847 DCHECK(observing_root_window_); 1748 DCHECK(observing_root_window_);
1848 is_window_activity_started_ = true; 1749 is_window_activity_started_ = true;
1849 ShowInternal(); 1750 ShowInternal();
1850 } 1751 }
1851 1752
1852 void RenderWidgetHostViewAndroid::OnLostResources() { 1753 void RenderWidgetHostViewAndroid::OnLostResources() {
1853 ReleaseLocksOnSurface(); 1754 ReleaseLocksOnSurface();
1854 if (view_.GetLayer()) 1755 delegated_frame_host_->DestroyDelegatedContent();
1855 DestroyDelegatedContent();
1856 DCHECK(ack_callbacks_.empty()); 1756 DCHECK(ack_callbacks_.empty());
1857 } 1757 }
1858 1758
1859 // TODO(wjmaclean): There is significant overlap between 1759 // TODO(wjmaclean): There is significant overlap between
1860 // PrepareTextureCopyOutputResult and CopyFromCompositingSurfaceFinished in 1760 // PrepareTextureCopyOutputResult and CopyFromCompositingSurfaceFinished in
1861 // this file, and the versions in surface_utils.cc. They should 1761 // this file, and the versions in surface_utils.cc. They should
1862 // be merged. See https://crbug.com/582955 1762 // be merged. See https://crbug.com/582955
1863 1763
1864 // static 1764 // static
1865 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( 1765 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult(
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1982 case ui::MotionEvent::ACTION_UP: 1882 case ui::MotionEvent::ACTION_UP:
1983 case ui::MotionEvent::ACTION_POINTER_UP: 1883 case ui::MotionEvent::ACTION_POINTER_UP:
1984 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", 1884 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED",
1985 delta.InMicroseconds(), 1, 1000000, 50); 1885 delta.InMicroseconds(), 1, 1000000, 50);
1986 default: 1886 default:
1987 return; 1887 return;
1988 } 1888 }
1989 } 1889 }
1990 1890
1991 } // namespace content 1891 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698