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

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: Addressed comments. 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 #include "content/public/common/content_switches.h" 68 #include "content/public/common/content_switches.h"
69 #include "gpu/command_buffer/client/gles2_implementation.h" 69 #include "gpu/command_buffer/client/gles2_implementation.h"
70 #include "gpu/command_buffer/client/gles2_interface.h" 70 #include "gpu/command_buffer/client/gles2_interface.h"
71 #include "gpu/config/gpu_driver_bug_workaround_type.h" 71 #include "gpu/config/gpu_driver_bug_workaround_type.h"
72 #include "ipc/ipc_message_macros.h" 72 #include "ipc/ipc_message_macros.h"
73 #include "ipc/ipc_message_start.h" 73 #include "ipc/ipc_message_start.h"
74 #include "skia/ext/image_operations.h" 74 #include "skia/ext/image_operations.h"
75 #include "third_party/khronos/GLES2/gl2.h" 75 #include "third_party/khronos/GLES2/gl2.h"
76 #include "third_party/khronos/GLES2/gl2ext.h" 76 #include "third_party/khronos/GLES2/gl2ext.h"
77 #include "third_party/skia/include/core/SkCanvas.h" 77 #include "third_party/skia/include/core/SkCanvas.h"
78 #include "ui/android/context_provider_factory.h" 78 #include "ui/android/delegated_frame_host_android.h"
79 #include "ui/android/window_android.h" 79 #include "ui/android/window_android.h"
80 #include "ui/android/window_android_compositor.h" 80 #include "ui/android/window_android_compositor.h"
81 #include "ui/base/layout.h" 81 #include "ui/base/layout.h"
82 #include "ui/display/display.h" 82 #include "ui/display/display.h"
83 #include "ui/display/screen.h" 83 #include "ui/display/screen.h"
84 #include "ui/events/blink/blink_event_util.h" 84 #include "ui/events/blink/blink_event_util.h"
85 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" 85 #include "ui/events/gesture_detection/gesture_provider_config_helper.h"
86 #include "ui/events/gesture_detection/motion_event.h" 86 #include "ui/events/gesture_detection/motion_event.h"
87 #include "ui/gfx/android/device_display_info.h" 87 #include "ui/gfx/android/device_display_info.h"
88 #include "ui/gfx/android/java_bitmap.h" 88 #include "ui/gfx/android/java_bitmap.h"
89 #include "ui/gfx/android/view_configuration.h" 89 #include "ui/gfx/android/view_configuration.h"
90 #include "ui/gfx/geometry/dip_util.h" 90 #include "ui/gfx/geometry/dip_util.h"
91 #include "ui/gfx/geometry/size_conversions.h" 91 #include "ui/gfx/geometry/size_conversions.h"
92 #include "ui/touch_selection/touch_selection_controller.h" 92 #include "ui/touch_selection/touch_selection_controller.h"
93 93
94 namespace content { 94 namespace content {
95 95
96 namespace { 96 namespace {
97 97
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; 98 const int kUndefinedOutputSurfaceId = -1;
117 99
118 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime"; 100 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime";
119 101
120 class GLHelperHolder { 102 class GLHelperHolder {
121 public: 103 public:
122 static GLHelperHolder* Create(); 104 static GLHelperHolder* Create();
123 105
124 display_compositor::GLHelper* gl_helper() { return gl_helper_.get(); } 106 display_compositor::GLHelper* gl_helper() { return gl_helper_.get(); }
125 bool IsLost() { 107 bool IsLost() {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 gfx::RectF GetSelectionRect(const ui::TouchSelectionController& controller) { 261 gfx::RectF GetSelectionRect(const ui::TouchSelectionController& controller) {
280 gfx::RectF rect = controller.GetRectBetweenBounds(); 262 gfx::RectF rect = controller.GetRectBetweenBounds();
281 if (rect.IsEmpty()) 263 if (rect.IsEmpty())
282 return rect; 264 return rect;
283 265
284 rect.Union(controller.GetStartHandleRect()); 266 rect.Union(controller.GetStartHandleRect());
285 rect.Union(controller.GetEndHandleRect()); 267 rect.Union(controller.GetEndHandleRect());
286 return rect; 268 return rect;
287 } 269 }
288 270
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 =
294 ui::ContextProviderFactory::GetInstance()->GetSurfaceManager();
295 DCHECK(manager);
296 // manager must outlive compositors using it.
297 scoped_refptr<cc::SurfaceLayer> surface_layer = cc::SurfaceLayer::Create(
298 base::Bind(&SatisfyCallback, base::Unretained(manager)),
299 base::Bind(&RequireCallback, base::Unretained(manager)));
300 surface_layer->SetSurfaceId(surface_id, 1.f, size);
301 surface_layer->SetBounds(size);
302 surface_layer->SetIsDrawable(true);
303 surface_layer->SetContentsOpaque(true);
304
305 return surface_layer;
306 }
307
308 } // anonymous namespace 271 } // anonymous namespace
309 272
310 RenderWidgetHostViewAndroid::LastFrameInfo::LastFrameInfo( 273 RenderWidgetHostViewAndroid::LastFrameInfo::LastFrameInfo(
311 uint32_t output_id, 274 uint32_t output_id,
312 cc::CompositorFrame output_frame) 275 cc::CompositorFrame output_frame)
313 : output_surface_id(output_id), frame(std::move(output_frame)) {} 276 : output_surface_id(output_id), frame(std::move(output_frame)) {}
314 277
315 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {} 278 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {}
316 279
317 void RenderWidgetHostViewAndroid::OnContextLost() { 280 void RenderWidgetHostViewAndroid::OnContextLost() {
(...skipping 21 matching lines...) Expand all
339 last_output_surface_id_(kUndefinedOutputSurfaceId), 302 last_output_surface_id_(kUndefinedOutputSurfaceId),
340 gesture_provider_(ui::GetGestureProviderConfig( 303 gesture_provider_(ui::GetGestureProviderConfig(
341 ui::GestureProviderConfigType::CURRENT_PLATFORM), 304 ui::GestureProviderConfigType::CURRENT_PLATFORM),
342 this), 305 this),
343 stylus_text_selector_(this), 306 stylus_text_selector_(this),
344 using_browser_compositor_(CompositorImpl::IsInitialized()), 307 using_browser_compositor_(CompositorImpl::IsInitialized()),
345 frame_evictor_(new DelegatedFrameEvictor(this)), 308 frame_evictor_(new DelegatedFrameEvictor(this)),
346 locks_on_frame_count_(0), 309 locks_on_frame_count_(0),
347 observing_root_window_(false), 310 observing_root_window_(false),
348 weak_ptr_factory_(this) { 311 weak_ptr_factory_(this) {
312 // Set the layer which will hold the content layer for this view. The content
313 // layer is managed by the DelegatedFrameHost.
314 view_.SetLayer(cc::Layer::Create());
349 if (using_browser_compositor_) { 315 if (using_browser_compositor_) {
350 id_allocator_.reset(new cc::SurfaceIdAllocator( 316 delegated_frame_host_.reset(new ui::DelegatedFrameHostAndroid(
351 ui::ContextProviderFactory::GetInstance()->AllocateSurfaceClientId())); 317 &view_, cached_background_color_,
352 ui::ContextProviderFactory::GetInstance() 318 base::Bind(&RenderWidgetHostViewAndroid::ReturnResources,
353 ->GetSurfaceManager() 319 weak_ptr_factory_.GetWeakPtr())));
354 ->RegisterSurfaceClientId(id_allocator_->client_id());
355 } 320 }
356 321
357 host_->SetView(this); 322 host_->SetView(this);
358 SetContentViewCore(content_view_core); 323 SetContentViewCore(content_view_core);
359 } 324 }
360 325
361 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { 326 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() {
362 if (content_view_core_) 327 if (content_view_core_)
363 content_view_core_->RemoveObserver(this); 328 content_view_core_->RemoveObserver(this);
364 SetContentViewCore(NULL); 329 SetContentViewCore(NULL);
365 DCHECK(ack_callbacks_.empty()); 330 DCHECK(ack_callbacks_.empty());
366 DCHECK(!surface_factory_); 331 DCHECK(!delegated_frame_host_);
367 DCHECK(surface_id_.is_null());
368 } 332 }
369 333
370 void RenderWidgetHostViewAndroid::Blur() { 334 void RenderWidgetHostViewAndroid::Blur() {
371 host_->Blur(); 335 host_->Blur();
372 if (overscroll_controller_) 336 if (overscroll_controller_)
373 overscroll_controller_->Disable(); 337 overscroll_controller_->Disable();
374 } 338 }
375 339
376 bool RenderWidgetHostViewAndroid::OnMessageReceived( 340 bool RenderWidgetHostViewAndroid::OnMessageReceived(
377 const IPC::Message& message) { 341 const IPC::Message& message) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 RenderWidgetHostView* reference_host_view) { 375 RenderWidgetHostView* reference_host_view) {
412 NOTIMPLEMENTED(); 376 NOTIMPLEMENTED();
413 } 377 }
414 378
415 RenderWidgetHost* 379 RenderWidgetHost*
416 RenderWidgetHostViewAndroid::GetRenderWidgetHost() const { 380 RenderWidgetHostViewAndroid::GetRenderWidgetHost() const {
417 return host_; 381 return host_;
418 } 382 }
419 383
420 void RenderWidgetHostViewAndroid::WasResized() { 384 void RenderWidgetHostViewAndroid::WasResized() {
385 delegated_frame_host_->UpdateSize(GetViewSize());
no sievers 2016/08/12 19:33:04 I *think* you are passing DIP here but when you co
Khushal 2016/08/16 01:34:23 You're right. Fixed that.
421 host_->WasResized(); 386 host_->WasResized();
422 } 387 }
423 388
424 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { 389 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) {
425 // 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
426 // resize the view on Android. 391 // resize the view on Android.
427 default_size_ = size; 392 default_size_ = size;
428 } 393 }
429 394
430 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { 395 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) {
431 SetSize(rect.size()); 396 SetSize(rect.size());
432 } 397 }
433 398
434 void RenderWidgetHostViewAndroid::GetScaledContentBitmap( 399 void RenderWidgetHostViewAndroid::GetScaledContentBitmap(
435 float scale, 400 float scale,
436 SkColorType preferred_color_type, 401 SkColorType preferred_color_type,
437 gfx::Rect src_subrect, 402 gfx::Rect src_subrect,
438 const ReadbackRequestCallback& result_callback) { 403 const ReadbackRequestCallback& result_callback) {
439 if (!host_ || host_->is_hidden() || !IsSurfaceAvailableForCopy()) { 404 if (!host_ || host_->is_hidden() || !IsSurfaceAvailableForCopy()) {
440 result_callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); 405 result_callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE);
441 return; 406 return;
442 } 407 }
443 gfx::Size bounds = view_.GetLayer()->bounds(); 408 gfx::Size bounds = delegated_frame_host_->GetContentLayer()->bounds();
no sievers 2016/08/12 19:33:04 I think this should be the same as |texture_size_i
Khushal 2016/08/16 01:34:23 Done.
444 if (src_subrect.IsEmpty()) 409 if (src_subrect.IsEmpty())
445 src_subrect = gfx::Rect(bounds); 410 src_subrect = gfx::Rect(bounds);
446 DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width()); 411 DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width());
447 DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height()); 412 DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height());
448 const display::Display& display = 413 const display::Display& display =
449 display::Screen::GetScreen()->GetPrimaryDisplay(); 414 display::Screen::GetScreen()->GetPrimaryDisplay();
450 float device_scale_factor = display.device_scale_factor(); 415 float device_scale_factor = display.device_scale_factor();
451 DCHECK_GT(device_scale_factor, 0); 416 DCHECK_GT(device_scale_factor, 0);
452 gfx::Size dst_size( 417 gfx::Size dst_size(
453 gfx::ScaleToCeiledSize(src_subrect.size(), scale / device_scale_factor)); 418 gfx::ScaleToCeiledSize(src_subrect.size(), scale / device_scale_factor));
454 src_subrect = gfx::ConvertRectToDIP(device_scale_factor, src_subrect); 419 src_subrect = gfx::ConvertRectToDIP(device_scale_factor, src_subrect);
455 420
456 CopyFromCompositingSurface(src_subrect, dst_size, result_callback, 421 CopyFromCompositingSurface(src_subrect, dst_size, result_callback,
457 preferred_color_type); 422 preferred_color_type);
458 } 423 }
459 424
460 bool RenderWidgetHostViewAndroid::HasValidFrame() const { 425 bool RenderWidgetHostViewAndroid::HasValidFrame() const {
461 if (!content_view_core_) 426 if (!content_view_core_)
462 return false; 427 return false;
463 if (!view_.GetLayer()) 428 if (!delegated_frame_host_->GetContentLayer())
no sievers 2016/08/12 19:33:03 I think you can just remove this check. It should
Khushal 2016/08/16 01:34:23 Should there be a DCHECK at the end then? The Dele
464 return false; 429 return false;
465 430
466 if (texture_size_in_layer_.IsEmpty()) 431 if (texture_size_in_layer_.IsEmpty())
467 return false; 432 return false;
468 // This tell us whether a valid frame has arrived or not. 433 // This tell us whether a valid frame has arrived or not.
469 if (!frame_evictor_->HasFrame()) 434 if (!frame_evictor_->HasFrame())
470 return false; 435 return false;
471 436
472 return true; 437 return true;
473 } 438 }
(...skipping 25 matching lines...) Expand all
499 } 464 }
500 465
501 bool RenderWidgetHostViewAndroid::HasFocus() const { 466 bool RenderWidgetHostViewAndroid::HasFocus() const {
502 if (!content_view_core_) 467 if (!content_view_core_)
503 return false; // ContentViewCore not created yet. 468 return false; // ContentViewCore not created yet.
504 469
505 return content_view_core_->HasFocus(); 470 return content_view_core_->HasFocus();
506 } 471 }
507 472
508 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { 473 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const {
509 return !using_browser_compositor_ || 474 return !using_browser_compositor_ || HasValidFrame();
510 (HasValidFrame() && surface_factory_.get());
511 } 475 }
512 476
513 void RenderWidgetHostViewAndroid::Show() { 477 void RenderWidgetHostViewAndroid::Show() {
514 if (is_showing_) 478 if (is_showing_)
515 return; 479 return;
516 480
517 is_showing_ = true; 481 is_showing_ = true;
518 ShowInternal(); 482 ShowInternal();
519 } 483 }
520 484
(...skipping 30 matching lines...) Expand all
551 locks_on_frame_count_--; 515 locks_on_frame_count_--;
552 frame_evictor_->UnlockFrame(); 516 frame_evictor_->UnlockFrame();
553 517
554 if (locks_on_frame_count_ == 0) { 518 if (locks_on_frame_count_ == 0) {
555 if (last_frame_info_) { 519 if (last_frame_info_) {
556 InternalSwapCompositorFrame(last_frame_info_->output_surface_id, 520 InternalSwapCompositorFrame(last_frame_info_->output_surface_id,
557 std::move(last_frame_info_->frame)); 521 std::move(last_frame_info_->frame));
558 last_frame_info_.reset(); 522 last_frame_info_.reset();
559 } 523 }
560 524
561 if (!is_showing_ && view_.GetLayer()) 525 if (!is_showing_ && delegated_frame_host_->GetContentLayer())
562 view_.GetLayer()->SetHideLayerAndSubtree(true); 526 delegated_frame_host_->GetContentLayer()->SetHideLayerAndSubtree(true);
no sievers 2016/08/12 19:33:04 Make this DFH::SetVisible()
Khushal 2016/08/16 01:34:23 Had it update the view's layer directly.
563 } 527 }
564 } 528 }
565 529
566 void RenderWidgetHostViewAndroid::OnShowUnhandledTapUIIfNeeded(int x_dip, 530 void RenderWidgetHostViewAndroid::OnShowUnhandledTapUIIfNeeded(int x_dip,
567 int y_dip) { 531 int y_dip) {
568 if (!content_view_core_) 532 if (!content_view_core_)
569 return; 533 return;
570 // Validate the coordinates are within the viewport. 534 // Validate the coordinates are within the viewport.
571 gfx::Size viewport_size = content_view_core_->GetViewportSizeDip(); 535 gfx::Size viewport_size = content_view_core_->GetViewportSizeDip();
572 if (x_dip < 0 || x_dip > viewport_size.width() || 536 if (x_dip < 0 || x_dip > viewport_size.width() ||
573 y_dip < 0 || y_dip > viewport_size.height()) 537 y_dip < 0 || y_dip > viewport_size.height())
574 return; 538 return;
575 content_view_core_->OnShowUnhandledTapUIIfNeeded(x_dip, y_dip); 539 content_view_core_->OnShowUnhandledTapUIIfNeeded(x_dip, y_dip);
576 } 540 }
577 541
578 void RenderWidgetHostViewAndroid::ReleaseLocksOnSurface() { 542 void RenderWidgetHostViewAndroid::ReleaseLocksOnSurface() {
579 if (!frame_evictor_->HasFrame()) { 543 if (!frame_evictor_->HasFrame()) {
580 DCHECK_EQ(locks_on_frame_count_, 0u); 544 DCHECK_EQ(locks_on_frame_count_, 0u);
581 return; 545 return;
582 } 546 }
583 while (locks_on_frame_count_ > 0) { 547 while (locks_on_frame_count_ > 0) {
584 UnlockCompositingSurface(); 548 UnlockCompositingSurface();
585 } 549 }
586 RunAckCallbacks(); 550 RunAckCallbacks();
587 } 551 }
588 552
589 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { 553 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const {
590 if (!content_view_core_) 554 return gfx::Rect(GetViewSize());
591 return gfx::Rect(default_size_);
592
593 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
594 switches::kEnableOSKOverscroll))
595 return gfx::Rect(content_view_core_->GetViewSizeWithOSKHidden());
596
597 return gfx::Rect(content_view_core_->GetViewSize());
598 } 555 }
599 556
600 gfx::Size RenderWidgetHostViewAndroid::GetVisibleViewportSize() const { 557 gfx::Size RenderWidgetHostViewAndroid::GetVisibleViewportSize() const {
601 if (!content_view_core_) 558 if (!content_view_core_)
602 return default_size_; 559 return default_size_;
603 560
604 return content_view_core_->GetViewSize(); 561 return content_view_core_->GetViewSize();
605 } 562 }
606 563
607 gfx::Size RenderWidgetHostViewAndroid::GetPhysicalBackingSize() const { 564 gfx::Size RenderWidgetHostViewAndroid::GetPhysicalBackingSize() const {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 params.value, params.selection_start, params.selection_end, 612 params.value, params.selection_start, params.selection_end,
656 params.composition_start, params.composition_end, 613 params.composition_start, params.composition_end,
657 params.show_ime_if_needed, params.is_non_ime_change); 614 params.show_ime_if_needed, params.is_non_ime_change);
658 } 615 }
659 616
660 void RenderWidgetHostViewAndroid::UpdateBackgroundColor(SkColor color) { 617 void RenderWidgetHostViewAndroid::UpdateBackgroundColor(SkColor color) {
661 if (cached_background_color_ == color) 618 if (cached_background_color_ == color)
662 return; 619 return;
663 620
664 cached_background_color_ = color; 621 cached_background_color_ = color;
622 delegated_frame_host_->UpdateBackgroundColor(color);
665 if (content_view_core_) 623 if (content_view_core_)
666 content_view_core_->OnBackgroundColorChanged(color); 624 content_view_core_->OnBackgroundColorChanged(color);
667 } 625 }
668 626
669 void RenderWidgetHostViewAndroid::OnSetNeedsBeginFrames(bool enabled) { 627 void RenderWidgetHostViewAndroid::OnSetNeedsBeginFrames(bool enabled) {
670 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::OnSetNeedsBeginFrames", 628 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::OnSetNeedsBeginFrames",
671 "enabled", enabled); 629 "enabled", enabled);
672 if (enabled) 630 if (enabled)
673 RequestVSyncUpdate(PERSISTENT_BEGIN_FRAME); 631 RequestVSyncUpdate(PERSISTENT_BEGIN_FRAME);
674 else 632 else
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 ime_adapter_android_.FocusedNodeChanged(is_editable_node); 745 ime_adapter_android_.FocusedNodeChanged(is_editable_node);
788 } 746 }
789 747
790 void RenderWidgetHostViewAndroid::RenderProcessGone( 748 void RenderWidgetHostViewAndroid::RenderProcessGone(
791 base::TerminationStatus status, int error_code) { 749 base::TerminationStatus status, int error_code) {
792 Destroy(); 750 Destroy();
793 } 751 }
794 752
795 void RenderWidgetHostViewAndroid::Destroy() { 753 void RenderWidgetHostViewAndroid::Destroy() {
796 host_->ViewDestroyed(); 754 host_->ViewDestroyed();
797 RemoveLayers();
798 SetContentViewCore(NULL); 755 SetContentViewCore(NULL);
799 756 delegated_frame_host_.reset();
800 if (!surface_id_.is_null()) {
801 DCHECK(surface_factory_.get());
802 surface_factory_->Destroy(surface_id_);
803 surface_id_ = cc::SurfaceId();
804 }
805 surface_factory_.reset();
806 if (id_allocator_) {
807 ui::ContextProviderFactory::GetInstance()
808 ->GetSurfaceManager()
809 ->InvalidateSurfaceClientId(id_allocator_->client_id());
810 }
811 757
812 // The RenderWidgetHost's destruction led here, so don't call it. 758 // The RenderWidgetHost's destruction led here, so don't call it.
813 host_ = NULL; 759 host_ = NULL;
814 760
815 delete this; 761 delete this;
816 } 762 }
817 763
818 void RenderWidgetHostViewAndroid::SetTooltipText( 764 void RenderWidgetHostViewAndroid::SetTooltipText(
819 const base::string16& tooltip_text) { 765 const base::string16& tooltip_text) {
820 // 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
886 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, 832 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback,
887 preferred_color_type); 833 preferred_color_type);
888 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", 834 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous",
889 base::TimeTicks::Now() - start_time); 835 base::TimeTicks::Now() - start_time);
890 return; 836 return;
891 } 837 }
892 838
893 ui::WindowAndroidCompositor* compositor = 839 ui::WindowAndroidCompositor* compositor =
894 content_view_core_->GetWindowAndroid()->GetCompositor(); 840 content_view_core_->GetWindowAndroid()->GetCompositor();
895 DCHECK(compositor); 841 DCHECK(compositor);
896 DCHECK(!surface_id_.is_null()); 842 DCHECK(delegated_frame_host_->GetContentLayer());
no sievers 2016/08/12 19:33:04 You can move this DCHECK() into DFH.
Khushal 2016/08/16 01:34:23 Done.
897 std::unique_ptr<cc::CopyOutputRequest> request = 843 std::unique_ptr<cc::CopyOutputRequest> request =
898 cc::CopyOutputRequest::CreateRequest(base::Bind( 844 cc::CopyOutputRequest::CreateRequest(base::Bind(
899 &PrepareTextureCopyOutputResult, weak_ptr_factory_.GetWeakPtr(), 845 &PrepareTextureCopyOutputResult, weak_ptr_factory_.GetWeakPtr(),
900 dst_size_in_pixel, preferred_color_type, start_time, callback)); 846 dst_size_in_pixel, preferred_color_type, start_time, callback));
901 if (!src_subrect_in_pixel.IsEmpty()) 847 if (!src_subrect_in_pixel.IsEmpty())
902 request->set_area(src_subrect_in_pixel); 848 request->set_area(src_subrect_in_pixel);
903 // Make sure the current frame doesn't get deleted until we fulfill the 849 // Make sure the current frame doesn't get deleted until we fulfill the
904 // request. 850 // request.
905 LockCompositingSurface(); 851 LockCompositingSurface();
906 surface_factory_->RequestCopyOfSurface(surface_id_, std::move(request)); 852 delegated_frame_host_->RequestCopyOfSurface(std::move(request));
907 } 853 }
908 854
909 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( 855 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame(
910 const gfx::Rect& src_subrect, 856 const gfx::Rect& src_subrect,
911 const scoped_refptr<media::VideoFrame>& target, 857 const scoped_refptr<media::VideoFrame>& target,
912 const base::Callback<void(const gfx::Rect&, bool)>& callback) { 858 const base::Callback<void(const gfx::Rect&, bool)>& callback) {
913 NOTIMPLEMENTED(); 859 NOTIMPLEMENTED();
914 callback.Run(gfx::Rect(), false); 860 callback.Run(gfx::Rect(), false);
915 } 861 }
916 862
(...skipping 30 matching lines...) Expand all
947 const cc::ReturnedResourceArray& resources) { 893 const cc::ReturnedResourceArray& resources) {
948 if (resources.empty()) 894 if (resources.empty())
949 return; 895 return;
950 std::copy(resources.begin(), resources.end(), 896 std::copy(resources.begin(), resources.end(),
951 std::back_inserter(surface_returned_resources_)); 897 std::back_inserter(surface_returned_resources_));
952 if (ack_callbacks_.empty()) 898 if (ack_callbacks_.empty())
953 SendReclaimCompositorResources(last_output_surface_id_, 899 SendReclaimCompositorResources(last_output_surface_id_,
954 false /* is_swap_ack */); 900 false /* is_swap_ack */);
955 } 901 }
956 902
957 void RenderWidgetHostViewAndroid::SetBeginFrameSource(
958 cc::BeginFrameSource* begin_frame_source) {
959 // TODO(tansell): Hook this up.
960 }
961
962 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() {
963 RemoveLayers();
964 if (!surface_id_.is_null()) {
965 DCHECK(surface_factory_.get());
966 cc::SurfaceId surface_id;
967 std::swap(surface_id, surface_id_);
968 surface_factory_->Destroy(surface_id);
969 }
970 view_.SetLayer(nullptr);
971 }
972
973 void RenderWidgetHostViewAndroid::CheckOutputSurfaceChanged( 903 void RenderWidgetHostViewAndroid::CheckOutputSurfaceChanged(
974 uint32_t output_surface_id) { 904 uint32_t output_surface_id) {
975 if (output_surface_id == last_output_surface_id_) 905 if (output_surface_id == last_output_surface_id_)
976 return; 906 return;
977 DestroyDelegatedContent(); 907 delegated_frame_host_->OutputSurfaceChanged();
978 surface_factory_.reset(); 908
979 if (!surface_returned_resources_.empty()) 909 if (!surface_returned_resources_.empty())
980 SendReclaimCompositorResources(last_output_surface_id_, 910 SendReclaimCompositorResources(last_output_surface_id_,
981 false /* is_swap_ack */); 911 false /* is_swap_ack */);
982 912
983 last_output_surface_id_ = output_surface_id; 913 last_output_surface_id_ = output_surface_id;
984 } 914 }
985 915
986 void RenderWidgetHostViewAndroid::SubmitCompositorFrame(
987 cc::CompositorFrame frame) {
988 cc::SurfaceManager* manager =
989 ui::ContextProviderFactory::GetInstance()->GetSurfaceManager();
990 if (!surface_factory_) {
991 surface_factory_ = base::WrapUnique(new cc::SurfaceFactory(manager, this));
992 }
993 if (surface_id_.is_null() ||
994 texture_size_in_layer_ != current_surface_size_ ||
995 location_bar_content_translation_ !=
996 frame.metadata.location_bar_content_translation ||
997 current_viewport_selection_ != frame.metadata.selection) {
998 RemoveLayers();
999 if (!surface_id_.is_null())
1000 surface_factory_->Destroy(surface_id_);
1001 surface_id_ = id_allocator_->GenerateId();
1002 surface_factory_->Create(surface_id_);
1003 view_.SetLayer(CreateSurfaceLayer(surface_id_, texture_size_in_layer_));
1004
1005 DCHECK(view_.GetLayer());
1006
1007 current_surface_size_ = texture_size_in_layer_;
1008 location_bar_content_translation_ =
1009 frame.metadata.location_bar_content_translation;
1010 current_viewport_selection_ = frame.metadata.selection;
1011 AttachLayers();
1012 }
1013
1014 cc::SurfaceFactory::DrawCallback ack_callback =
1015 base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks,
1016 weak_ptr_factory_.GetWeakPtr());
1017 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame),
1018 ack_callback);
1019 }
1020
1021 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( 916 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame(
1022 uint32_t output_surface_id, 917 uint32_t output_surface_id,
1023 cc::CompositorFrame frame) { 918 cc::CompositorFrame frame) {
1024 last_scroll_offset_ = frame.metadata.root_scroll_offset; 919 last_scroll_offset_ = frame.metadata.root_scroll_offset;
1025 DCHECK(frame.delegated_frame_data); 920 DCHECK(frame.delegated_frame_data);
921 DCHECK(delegated_frame_host_);
1026 922
1027 if (locks_on_frame_count_ > 0) { 923 if (locks_on_frame_count_ > 0) {
1028 DCHECK(HasValidFrame()); 924 DCHECK(HasValidFrame());
1029 RetainFrame(output_surface_id, std::move(frame)); 925 RetainFrame(output_surface_id, std::move(frame));
1030 return; 926 return;
1031 } 927 }
1032 928
1033 DCHECK(!frame.delegated_frame_data->render_pass_list.empty()); 929 DCHECK(!frame.delegated_frame_data->render_pass_list.empty());
1034 930
1035 cc::RenderPass* root_pass = 931 cc::RenderPass* root_pass =
1036 frame.delegated_frame_data->render_pass_list.back().get(); 932 frame.delegated_frame_data->render_pass_list.back().get();
1037 texture_size_in_layer_ = root_pass->output_rect.size(); 933 texture_size_in_layer_ = root_pass->output_rect.size();
1038 934
1039 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); 935 cc::CompositorFrameMetadata metadata = frame.metadata.Clone();
1040 936
1041 CheckOutputSurfaceChanged(output_surface_id); 937 CheckOutputSurfaceChanged(output_surface_id);
1042 bool has_content = !texture_size_in_layer_.IsEmpty(); 938 bool has_content = !texture_size_in_layer_.IsEmpty();
1043 939
1044 base::Closure ack_callback = 940 base::Closure ack_callback =
1045 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources, 941 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources,
1046 weak_ptr_factory_.GetWeakPtr(), output_surface_id, 942 weak_ptr_factory_.GetWeakPtr(), output_surface_id,
1047 true /* is_swap_ack */); 943 true /* is_swap_ack */);
1048 944
1049 ack_callbacks_.push(ack_callback); 945 ack_callbacks_.push(ack_callback);
1050 946
1051 if (!has_content) { 947 if (!has_content) {
1052 DestroyDelegatedContent(); 948 delegated_frame_host_->DestroyDelegatedContent();
1053 } else { 949 } else {
1054 SubmitCompositorFrame(std::move(frame)); 950 cc::SurfaceFactory::DrawCallback ack_callback =
1055 view_.GetLayer()->SetIsDrawable(true); 951 base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks,
1056 view_.GetLayer()->SetContentsOpaque(true); 952 weak_ptr_factory_.GetWeakPtr());
1057 view_.GetLayer()->SetBounds(texture_size_in_layer_); 953 delegated_frame_host_->SubmitCompositorFrame(std::move(frame),
954 ack_callback);
1058 } 955 }
1059 956
1060 if (host_->is_hidden()) 957 if (host_->is_hidden())
1061 RunAckCallbacks(); 958 RunAckCallbacks();
1062 frame_evictor_->SwappedFrame(!host_->is_hidden()); 959 frame_evictor_->SwappedFrame(!host_->is_hidden());
1063 960
1064 // 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
1065 // any potential compositor scheduling. 962 // any potential compositor scheduling.
1066 OnFrameMetadataUpdated(std::move(metadata)); 963 OnFrameMetadataUpdated(std::move(metadata));
1067 } 964 }
1068 965
1069 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( 966 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame(
1070 uint32_t output_surface_id, 967 uint32_t output_surface_id,
1071 cc::CompositorFrame frame) { 968 cc::CompositorFrame frame) {
1072 InternalSwapCompositorFrame(output_surface_id, std::move(frame)); 969 InternalSwapCompositorFrame(output_surface_id, std::move(frame));
1073 } 970 }
1074 971
1075 void RenderWidgetHostViewAndroid::ClearCompositorFrame() { 972 void RenderWidgetHostViewAndroid::ClearCompositorFrame() {
1076 DestroyDelegatedContent(); 973 delegated_frame_host_->DestroyDelegatedContent();
1077 } 974 }
1078 975
1079 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t output_surface_id, 976 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t output_surface_id,
1080 cc::CompositorFrame frame) { 977 cc::CompositorFrame frame) {
1081 DCHECK(locks_on_frame_count_); 978 DCHECK(locks_on_frame_count_);
1082 979
1083 // 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
1084 // 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
1085 // 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
1086 // 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
1115 BrowserThread::PostTask( 1012 BrowserThread::PostTask(
1116 BrowserThread::UI, FROM_HERE, 1013 BrowserThread::UI, FROM_HERE,
1117 base::Bind( 1014 base::Bind(
1118 &RenderFrameDevToolsAgentHost::SynchronousSwapCompositorFrame, 1015 &RenderFrameDevToolsAgentHost::SynchronousSwapCompositorFrame,
1119 static_cast<RenderFrameDevToolsAgentHost*>(dtah.get()), 1016 static_cast<RenderFrameDevToolsAgentHost*>(dtah.get()),
1120 base::Passed(&frame_metadata))); 1017 base::Passed(&frame_metadata)));
1121 } 1018 }
1122 } 1019 }
1123 1020
1124 void RenderWidgetHostViewAndroid::SetOverlayVideoMode(bool enabled) { 1021 void RenderWidgetHostViewAndroid::SetOverlayVideoMode(bool enabled) {
1125 if (view_.GetLayer()) 1022 if (delegated_frame_host_->GetContentLayer())
1126 view_.GetLayer()->SetContentsOpaque(!enabled); 1023 delegated_frame_host_->GetContentLayer()->SetContentsOpaque(!enabled);
no sievers 2016/08/12 19:33:04 Make this DFH::SetContentsOpaque().
Khushal 2016/08/16 01:34:23 Done.
1127 } 1024 }
1128 1025
1129 bool RenderWidgetHostViewAndroid::SupportsAnimation() const { 1026 bool RenderWidgetHostViewAndroid::SupportsAnimation() const {
1130 // The synchronous (WebView) compositor does not have a proper browser 1027 // The synchronous (WebView) compositor does not have a proper browser
1131 // compositor with which to drive animations. 1028 // compositor with which to drive animations.
1132 return using_browser_compositor_; 1029 return using_browser_compositor_;
1133 } 1030 }
1134 1031
1135 void RenderWidgetHostViewAndroid::SetNeedsAnimate() { 1032 void RenderWidgetHostViewAndroid::SetNeedsAnimate() {
1136 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
1272 WebContents* web_contents = 1169 WebContents* web_contents =
1273 WebContents::FromRenderViewHost(RenderViewHostImpl::From(host_)); 1170 WebContents::FromRenderViewHost(RenderViewHostImpl::From(host_));
1274 if (web_contents) { 1171 if (web_contents) {
1275 MediaWebContentsObserverAndroid::FromWebContents(web_contents) 1172 MediaWebContentsObserverAndroid::FromWebContents(web_contents)
1276 ->OnFrameInfoUpdated(); 1173 ->OnFrameInfoUpdated();
1277 } 1174 }
1278 } 1175 }
1279 #endif // defined(VIDEO_HOLE) 1176 #endif // defined(VIDEO_HOLE)
1280 } 1177 }
1281 1178
1179 gfx::Size RenderWidgetHostViewAndroid::GetViewSize() const {
no sievers 2016/08/12 19:33:03 nit: Can you not add this method, since RWHV alrea
Khushal 2016/08/16 01:34:23 Done.
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
1282 void RenderWidgetHostViewAndroid::ShowInternal() { 1190 void RenderWidgetHostViewAndroid::ShowInternal() {
1283 bool show = is_showing_ && is_window_activity_started_ && is_window_visible_; 1191 bool show = is_showing_ && is_window_activity_started_ && is_window_visible_;
1284 if (!show) 1192 if (!show)
1285 return; 1193 return;
1286 1194
1287 if (!host_ || !host_->is_hidden()) 1195 if (!host_ || !host_->is_hidden())
1288 return; 1196 return;
1289 1197
1290 if (view_.GetLayer()) 1198 if (delegated_frame_host_->GetContentLayer())
1291 view_.GetLayer()->SetHideLayerAndSubtree(false); 1199 delegated_frame_host_->GetContentLayer()->SetHideLayerAndSubtree(false);
1292 1200
1293 frame_evictor_->SetVisible(true); 1201 frame_evictor_->SetVisible(true);
1294 1202
1295 if (overscroll_controller_) 1203 if (overscroll_controller_)
1296 overscroll_controller_->Enable(); 1204 overscroll_controller_->Enable();
1297 1205
1298 host_->WasShown(ui::LatencyInfo()); 1206 host_->WasShown(ui::LatencyInfo());
1299 1207
1300 if (content_view_core_) { 1208 if (content_view_core_) {
1301 StartObservingRootWindow(); 1209 StartObservingRootWindow();
1302 RequestVSyncUpdate(BEGIN_FRAME); 1210 RequestVSyncUpdate(BEGIN_FRAME);
1303 } 1211 }
1304 } 1212 }
1305 1213
1306 void RenderWidgetHostViewAndroid::HideInternal() { 1214 void RenderWidgetHostViewAndroid::HideInternal() {
1307 DCHECK(!is_showing_ || !is_window_activity_started_ || !is_window_visible_) 1215 DCHECK(!is_showing_ || !is_window_activity_started_ || !is_window_visible_)
1308 << "Hide called when the widget should be shown."; 1216 << "Hide called when the widget should be shown.";
1309 1217
1310 // Only preserve the frontbuffer if the activity was stopped while the 1218 // Only preserve the frontbuffer if the activity was stopped while the
1311 // window is still visible. This avoids visual artificts when transitioning 1219 // window is still visible. This avoids visual artificts when transitioning
1312 // between activities. 1220 // between activities.
1313 bool hide_frontbuffer = is_window_activity_started_ || !is_window_visible_; 1221 bool hide_frontbuffer = is_window_activity_started_ || !is_window_visible_;
1314 1222
1315 // 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
1316 // hidden and the frontbuffer is being cleared. This allows window visibility 1224 // hidden and the frontbuffer is being cleared. This allows window visibility
1317 // notifications to eventually clear the frontbuffer. 1225 // notifications to eventually clear the frontbuffer.
1318 bool stop_observing_root_window = !is_showing_ && hide_frontbuffer; 1226 bool stop_observing_root_window = !is_showing_ && hide_frontbuffer;
1319 1227
1320 if (hide_frontbuffer) { 1228 if (hide_frontbuffer) {
1321 if (view_.GetLayer() && locks_on_frame_count_ == 0) 1229 if (delegated_frame_host_->GetContentLayer() && locks_on_frame_count_ == 0)
Khushal 2016/08/16 01:34:23 Btw, why do we have this lock check here?
1322 view_.GetLayer()->SetHideLayerAndSubtree(true); 1230 delegated_frame_host_->GetContentLayer()->SetHideLayerAndSubtree(true);
1323 1231
1324 frame_evictor_->SetVisible(false); 1232 frame_evictor_->SetVisible(false);
1325 } 1233 }
1326 1234
1327 if (stop_observing_root_window) { 1235 if (stop_observing_root_window) {
1328 DCHECK(!is_showing_); 1236 DCHECK(!is_showing_);
1329 StopObservingRootWindow(); 1237 StopObservingRootWindow();
1330 } 1238 }
1331 1239
1332 if (!host_ || host_->is_hidden()) 1240 if (!host_ || host_->is_hidden())
1333 return; 1241 return;
1334 1242
1335 if (overscroll_controller_) 1243 if (overscroll_controller_)
1336 overscroll_controller_->Disable(); 1244 overscroll_controller_->Disable();
1337 1245
1338 RunAckCallbacks(); 1246 RunAckCallbacks();
1339 1247
1340 // 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
1341 // utilization. 1249 // utilization.
1342 host_->WasHidden(); 1250 host_->WasHidden();
1343 } 1251 }
1344 1252
1345 void RenderWidgetHostViewAndroid::AttachLayers() {
1346 if (!content_view_core_)
1347 return;
1348 if (!view_.GetLayer())
1349 return;
1350
1351 content_view_core_->AttachLayer(view_.GetLayer());
1352 view_.GetLayer()->SetHideLayerAndSubtree(!is_showing_);
1353 }
1354
1355 void RenderWidgetHostViewAndroid::RemoveLayers() {
1356 if (!content_view_core_)
1357 return;
1358
1359 if (!view_.GetLayer())
1360 return;
1361
1362 content_view_core_->RemoveLayer(view_.GetLayer());
1363 }
1364
1365 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32_t requests) { 1253 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32_t requests) {
1366 bool should_request_vsync = !outstanding_vsync_requests_ && requests; 1254 bool should_request_vsync = !outstanding_vsync_requests_ && requests;
1367 outstanding_vsync_requests_ |= requests; 1255 outstanding_vsync_requests_ |= requests;
1368 1256
1369 // 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
1370 // vsync requests will be pushed if/when we resume observing in 1258 // vsync requests will be pushed if/when we resume observing in
1371 // |StartObservingRootWindow()|. 1259 // |StartObservingRootWindow()|.
1372 if (observing_root_window_ && should_request_vsync) 1260 if (observing_root_window_ && should_request_vsync)
1373 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); 1261 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate();
1374 } 1262 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 } 1329 }
1442 1330
1443 void RenderWidgetHostViewAndroid::RequestDisallowInterceptTouchEvent() { 1331 void RenderWidgetHostViewAndroid::RequestDisallowInterceptTouchEvent() {
1444 if (content_view_core_) 1332 if (content_view_core_)
1445 content_view_core_->RequestDisallowInterceptTouchEvent(); 1333 content_view_core_->RequestDisallowInterceptTouchEvent();
1446 } 1334 }
1447 1335
1448 void RenderWidgetHostViewAndroid::EvictDelegatedFrame() { 1336 void RenderWidgetHostViewAndroid::EvictDelegatedFrame() {
1449 DCHECK_EQ(locks_on_frame_count_, 0u); 1337 DCHECK_EQ(locks_on_frame_count_, 0u);
1450 frame_evictor_->DiscardedFrame(); 1338 frame_evictor_->DiscardedFrame();
1451 if (view_.GetLayer()) 1339 delegated_frame_host_->DestroyDelegatedContent();
1452 DestroyDelegatedContent();
1453 } 1340 }
1454 1341
1455 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface( 1342 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface(
1456 const gfx::Size& desired_size) { 1343 const gfx::Size& desired_size) {
1457 NOTREACHED(); 1344 NOTREACHED();
1458 return false; 1345 return false;
1459 } 1346 }
1460 1347
1461 void RenderWidgetHostViewAndroid::GetScreenInfo(blink::WebScreenInfo* result) { 1348 void RenderWidgetHostViewAndroid::GetScreenInfo(blink::WebScreenInfo* result) {
1462 // 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
1652 1539
1653 SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const { 1540 SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const {
1654 return cached_background_color_; 1541 return cached_background_color_;
1655 } 1542 }
1656 1543
1657 void RenderWidgetHostViewAndroid::DidOverscroll( 1544 void RenderWidgetHostViewAndroid::DidOverscroll(
1658 const DidOverscrollParams& params) { 1545 const DidOverscrollParams& params) {
1659 if (sync_compositor_) 1546 if (sync_compositor_)
1660 sync_compositor_->DidOverscroll(params); 1547 sync_compositor_->DidOverscroll(params);
1661 1548
1662 if (!content_view_core_ || !view_.GetLayer() || !is_showing_) 1549 if (!content_view_core_ || !delegated_frame_host_->GetContentLayer() ||
no sievers 2016/08/12 19:33:03 I don't understand the layer check here. I'd just
Khushal 2016/08/16 01:34:23 I added a check for DFH::HasDelegatedContent inste
1550 !is_showing_)
1663 return; 1551 return;
1664 1552
1665 if (overscroll_controller_) 1553 if (overscroll_controller_)
1666 overscroll_controller_->OnOverscrolled(params); 1554 overscroll_controller_->OnOverscrolled(params);
1667 } 1555 }
1668 1556
1669 void RenderWidgetHostViewAndroid::DidStopFlinging() { 1557 void RenderWidgetHostViewAndroid::DidStopFlinging() {
1670 if (content_view_core_) 1558 if (content_view_core_)
1671 content_view_core_->DidStopFlinging(); 1559 content_view_core_->DidStopFlinging();
1672 } 1560 }
1673 1561
1674 uint32_t RenderWidgetHostViewAndroid::GetSurfaceClientId() { 1562 uint32_t RenderWidgetHostViewAndroid::GetSurfaceClientId() {
1675 if (id_allocator_) 1563 if (!delegated_frame_host_)
1676 return id_allocator_->client_id(); 1564 return 0;
1677 return 0; 1565
1566 return delegated_frame_host_->GetSurfaceClientId();
1678 } 1567 }
1679 1568
1680 void RenderWidgetHostViewAndroid::SetContentViewCore( 1569 void RenderWidgetHostViewAndroid::SetContentViewCore(
1681 ContentViewCoreImpl* content_view_core) { 1570 ContentViewCoreImpl* content_view_core) {
1682 DCHECK(!content_view_core || !content_view_core_ || 1571 DCHECK(!content_view_core || !content_view_core_ ||
1683 (content_view_core_ == content_view_core)); 1572 (content_view_core_ == content_view_core));
1684 RemoveLayers();
1685 StopObservingRootWindow(); 1573 StopObservingRootWindow();
1686 1574
1687 bool resize = false; 1575 bool resize = false;
1688 if (content_view_core != content_view_core_) { 1576 if (content_view_core != content_view_core_) {
1689 overscroll_controller_.reset(); 1577 overscroll_controller_.reset();
1690 selection_controller_.reset(); 1578 selection_controller_.reset();
1691 ReleaseLocksOnSurface(); 1579 ReleaseLocksOnSurface();
1692 // 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
1693 // for resizing after crbug.com/628302 is handled. 1581 // for resizing after crbug.com/628302 is handled.
1694 bool is_size_initialized = !content_view_core 1582 bool is_size_initialized = !content_view_core
1695 || content_view_core->GetViewportSizeDip().width() != 0 1583 || content_view_core->GetViewportSizeDip().width() != 0
1696 || content_view_core->GetViewportSizeDip().height() != 0; 1584 || content_view_core->GetViewportSizeDip().height() != 0;
1697 if (content_view_core_ || is_size_initialized) 1585 if (content_view_core_ || is_size_initialized)
1698 resize = true; 1586 resize = true;
1699 if (content_view_core_) { 1587 if (content_view_core_) {
1700 content_view_core_->RemoveObserver(this); 1588 content_view_core_->RemoveObserver(this);
1701 view_.RemoveFromParent(); 1589 view_.RemoveFromParent();
1590 view_.GetLayer()->RemoveFromParent();
1702 } 1591 }
1703 if (content_view_core) { 1592 if (content_view_core) {
1704 content_view_core->AddObserver(this); 1593 content_view_core->AddObserver(this);
1705 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());
1706 } 1597 }
1707 content_view_core_ = content_view_core; 1598 content_view_core_ = content_view_core;
1708 } 1599 }
1709 1600
1710 BrowserAccessibilityManager* manager = NULL; 1601 BrowserAccessibilityManager* manager = NULL;
1711 if (host_) 1602 if (host_)
1712 manager = host_->GetRootBrowserAccessibilityManager(); 1603 manager = host_->GetRootBrowserAccessibilityManager();
1713 if (manager) { 1604 if (manager) {
1714 base::android::ScopedJavaLocalRef<jobject> obj; 1605 base::android::ScopedJavaLocalRef<jobject> obj;
1715 if (content_view_core_) 1606 if (content_view_core_)
1716 obj = content_view_core_->GetJavaObject(); 1607 obj = content_view_core_->GetJavaObject();
1717 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); 1608 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj);
1718 } 1609 }
1719 1610
1720 AttachLayers();
1721 if (!content_view_core_) { 1611 if (!content_view_core_) {
1722 sync_compositor_.reset(); 1612 sync_compositor_.reset();
1723 return; 1613 return;
1724 } 1614 }
1725 1615
1726 if (is_showing_) 1616 if (is_showing_)
1727 StartObservingRootWindow(); 1617 StartObservingRootWindow();
1728 1618
1729 if (resize) 1619 if (resize)
1730 WasResized(); 1620 WasResized();
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 1745
1856 void RenderWidgetHostViewAndroid::OnActivityStarted() { 1746 void RenderWidgetHostViewAndroid::OnActivityStarted() {
1857 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityStarted"); 1747 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityStarted");
1858 DCHECK(observing_root_window_); 1748 DCHECK(observing_root_window_);
1859 is_window_activity_started_ = true; 1749 is_window_activity_started_ = true;
1860 ShowInternal(); 1750 ShowInternal();
1861 } 1751 }
1862 1752
1863 void RenderWidgetHostViewAndroid::OnLostResources() { 1753 void RenderWidgetHostViewAndroid::OnLostResources() {
1864 ReleaseLocksOnSurface(); 1754 ReleaseLocksOnSurface();
1865 if (view_.GetLayer()) 1755 delegated_frame_host_->DestroyDelegatedContent();
1866 DestroyDelegatedContent();
1867 DCHECK(ack_callbacks_.empty()); 1756 DCHECK(ack_callbacks_.empty());
1868 } 1757 }
1869 1758
1870 // TODO(wjmaclean): There is significant overlap between 1759 // TODO(wjmaclean): There is significant overlap between
1871 // PrepareTextureCopyOutputResult and CopyFromCompositingSurfaceFinished in 1760 // PrepareTextureCopyOutputResult and CopyFromCompositingSurfaceFinished in
1872 // this file, and the versions in surface_utils.cc. They should 1761 // this file, and the versions in surface_utils.cc. They should
1873 // be merged. See https://crbug.com/582955 1762 // be merged. See https://crbug.com/582955
1874 1763
1875 // static 1764 // static
1876 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( 1765 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult(
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1993 case ui::MotionEvent::ACTION_UP: 1882 case ui::MotionEvent::ACTION_UP:
1994 case ui::MotionEvent::ACTION_POINTER_UP: 1883 case ui::MotionEvent::ACTION_POINTER_UP:
1995 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", 1884 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED",
1996 delta.InMicroseconds(), 1, 1000000, 50); 1885 delta.InMicroseconds(), 1, 1000000, 50);
1997 default: 1886 default:
1998 return; 1887 return;
1999 } 1888 }
2000 } 1889 }
2001 1890
2002 } // namespace content 1891 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698