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

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: remove GetContentLayer 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
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_android.h ('k') | ui/android/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #include "base/android/build_info.h" 11 #include "base/android/build_info.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback_helpers.h" 13 #include "base/callback_helpers.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ptr_util.h"
19 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
20 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
21 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
22 #include "base/sys_info.h" 21 #include "base/sys_info.h"
23 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
24 #include "base/threading/worker_pool.h" 23 #include "base/threading/worker_pool.h"
25 #include "cc/layers/layer.h" 24 #include "cc/layers/layer.h"
26 #include "cc/layers/surface_layer.h" 25 #include "cc/layers/surface_layer.h"
27 #include "cc/output/compositor_frame.h" 26 #include "cc/output/compositor_frame.h"
28 #include "cc/output/copy_output_request.h" 27 #include "cc/output/copy_output_request.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 #include "content/public/common/content_switches.h" 67 #include "content/public/common/content_switches.h"
69 #include "gpu/command_buffer/client/gles2_implementation.h" 68 #include "gpu/command_buffer/client/gles2_implementation.h"
70 #include "gpu/command_buffer/client/gles2_interface.h" 69 #include "gpu/command_buffer/client/gles2_interface.h"
71 #include "gpu/config/gpu_driver_bug_workaround_type.h" 70 #include "gpu/config/gpu_driver_bug_workaround_type.h"
72 #include "ipc/ipc_message_macros.h" 71 #include "ipc/ipc_message_macros.h"
73 #include "ipc/ipc_message_start.h" 72 #include "ipc/ipc_message_start.h"
74 #include "skia/ext/image_operations.h" 73 #include "skia/ext/image_operations.h"
75 #include "third_party/khronos/GLES2/gl2.h" 74 #include "third_party/khronos/GLES2/gl2.h"
76 #include "third_party/khronos/GLES2/gl2ext.h" 75 #include "third_party/khronos/GLES2/gl2ext.h"
77 #include "third_party/skia/include/core/SkCanvas.h" 76 #include "third_party/skia/include/core/SkCanvas.h"
78 #include "ui/android/context_provider_factory.h" 77 #include "ui/android/delegated_frame_host_android.h"
79 #include "ui/android/window_android.h" 78 #include "ui/android/window_android.h"
80 #include "ui/android/window_android_compositor.h" 79 #include "ui/android/window_android_compositor.h"
81 #include "ui/base/layout.h" 80 #include "ui/base/layout.h"
82 #include "ui/display/display.h" 81 #include "ui/display/display.h"
83 #include "ui/display/screen.h" 82 #include "ui/display/screen.h"
84 #include "ui/events/blink/blink_event_util.h" 83 #include "ui/events/blink/blink_event_util.h"
85 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" 84 #include "ui/events/gesture_detection/gesture_provider_config_helper.h"
86 #include "ui/events/gesture_detection/motion_event.h" 85 #include "ui/events/gesture_detection/motion_event.h"
87 #include "ui/gfx/android/device_display_info.h" 86 #include "ui/gfx/android/device_display_info.h"
88 #include "ui/gfx/android/java_bitmap.h" 87 #include "ui/gfx/android/java_bitmap.h"
89 #include "ui/gfx/android/view_configuration.h" 88 #include "ui/gfx/android/view_configuration.h"
90 #include "ui/gfx/geometry/dip_util.h" 89 #include "ui/gfx/geometry/dip_util.h"
91 #include "ui/gfx/geometry/size_conversions.h" 90 #include "ui/gfx/geometry/size_conversions.h"
92 #include "ui/touch_selection/touch_selection_controller.h" 91 #include "ui/touch_selection/touch_selection_controller.h"
93 92
94 namespace content { 93 namespace content {
95 94
96 namespace { 95 namespace {
97 96
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; 97 const int kUndefinedOutputSurfaceId = -1;
117 98
118 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime"; 99 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime";
119 100
120 class GLHelperHolder { 101 class GLHelperHolder {
121 public: 102 public:
122 static GLHelperHolder* Create(); 103 static GLHelperHolder* Create();
123 104
124 display_compositor::GLHelper* gl_helper() { return gl_helper_.get(); } 105 display_compositor::GLHelper* gl_helper() { return gl_helper_.get(); }
125 bool IsLost() { 106 bool IsLost() {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 gfx::RectF GetSelectionRect(const ui::TouchSelectionController& controller) { 260 gfx::RectF GetSelectionRect(const ui::TouchSelectionController& controller) {
280 gfx::RectF rect = controller.GetRectBetweenBounds(); 261 gfx::RectF rect = controller.GetRectBetweenBounds();
281 if (rect.IsEmpty()) 262 if (rect.IsEmpty())
282 return rect; 263 return rect;
283 264
284 rect.Union(controller.GetStartHandleRect()); 265 rect.Union(controller.GetStartHandleRect());
285 rect.Union(controller.GetEndHandleRect()); 266 rect.Union(controller.GetEndHandleRect());
286 return rect; 267 return rect;
287 } 268 }
288 269
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 270 } // anonymous namespace
309 271
310 RenderWidgetHostViewAndroid::LastFrameInfo::LastFrameInfo( 272 RenderWidgetHostViewAndroid::LastFrameInfo::LastFrameInfo(
311 uint32_t output_id, 273 uint32_t output_id,
312 cc::CompositorFrame output_frame) 274 cc::CompositorFrame output_frame)
313 : output_surface_id(output_id), frame(std::move(output_frame)) {} 275 : output_surface_id(output_id), frame(std::move(output_frame)) {}
314 276
315 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {} 277 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {}
316 278
317 void RenderWidgetHostViewAndroid::OnContextLost() { 279 void RenderWidgetHostViewAndroid::OnContextLost() {
(...skipping 21 matching lines...) Expand all
339 last_output_surface_id_(kUndefinedOutputSurfaceId), 301 last_output_surface_id_(kUndefinedOutputSurfaceId),
340 gesture_provider_(ui::GetGestureProviderConfig( 302 gesture_provider_(ui::GetGestureProviderConfig(
341 ui::GestureProviderConfigType::CURRENT_PLATFORM), 303 ui::GestureProviderConfigType::CURRENT_PLATFORM),
342 this), 304 this),
343 stylus_text_selector_(this), 305 stylus_text_selector_(this),
344 using_browser_compositor_(CompositorImpl::IsInitialized()), 306 using_browser_compositor_(CompositorImpl::IsInitialized()),
345 frame_evictor_(new DelegatedFrameEvictor(this)), 307 frame_evictor_(new DelegatedFrameEvictor(this)),
346 locks_on_frame_count_(0), 308 locks_on_frame_count_(0),
347 observing_root_window_(false), 309 observing_root_window_(false),
348 weak_ptr_factory_(this) { 310 weak_ptr_factory_(this) {
311 // Set the layer which will hold the content layer for this view. The content
312 // layer is managed by the DelegatedFrameHost.
313 view_.SetLayer(cc::Layer::Create());
349 if (using_browser_compositor_) { 314 if (using_browser_compositor_) {
350 id_allocator_.reset(new cc::SurfaceIdAllocator( 315 delegated_frame_host_.reset(new ui::DelegatedFrameHostAndroid(
351 ui::ContextProviderFactory::GetInstance()->AllocateSurfaceClientId())); 316 &view_, cached_background_color_,
352 ui::ContextProviderFactory::GetInstance() 317 base::Bind(&RenderWidgetHostViewAndroid::ReturnResources,
353 ->GetSurfaceManager() 318 weak_ptr_factory_.GetWeakPtr())));
354 ->RegisterSurfaceClientId(id_allocator_->client_id());
355 } 319 }
356 320
357 host_->SetView(this); 321 host_->SetView(this);
358 SetContentViewCore(content_view_core); 322 SetContentViewCore(content_view_core);
359 } 323 }
360 324
361 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { 325 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() {
362 if (content_view_core_) 326 if (content_view_core_)
363 content_view_core_->RemoveObserver(this); 327 content_view_core_->RemoveObserver(this);
364 SetContentViewCore(NULL); 328 SetContentViewCore(NULL);
365 DCHECK(ack_callbacks_.empty()); 329 DCHECK(ack_callbacks_.empty());
366 DCHECK(!surface_factory_); 330 DCHECK(!delegated_frame_host_);
367 DCHECK(surface_id_.is_null());
368 } 331 }
369 332
370 void RenderWidgetHostViewAndroid::Blur() { 333 void RenderWidgetHostViewAndroid::Blur() {
371 host_->Blur(); 334 host_->Blur();
372 if (overscroll_controller_) 335 if (overscroll_controller_)
373 overscroll_controller_->Disable(); 336 overscroll_controller_->Disable();
374 } 337 }
375 338
376 bool RenderWidgetHostViewAndroid::OnMessageReceived( 339 bool RenderWidgetHostViewAndroid::OnMessageReceived(
377 const IPC::Message& message) { 340 const IPC::Message& message) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 RenderWidgetHostView* reference_host_view) { 374 RenderWidgetHostView* reference_host_view) {
412 NOTIMPLEMENTED(); 375 NOTIMPLEMENTED();
413 } 376 }
414 377
415 RenderWidgetHost* 378 RenderWidgetHost*
416 RenderWidgetHostViewAndroid::GetRenderWidgetHost() const { 379 RenderWidgetHostViewAndroid::GetRenderWidgetHost() const {
417 return host_; 380 return host_;
418 } 381 }
419 382
420 void RenderWidgetHostViewAndroid::WasResized() { 383 void RenderWidgetHostViewAndroid::WasResized() {
384 if (delegated_frame_host_)
385 delegated_frame_host_->UpdateContainerSizeinDIP(GetVisibleViewportSize());
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 = current_surface_size_;
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())
464 return false;
465 428
466 if (texture_size_in_layer_.IsEmpty()) 429 if (current_surface_size_.IsEmpty())
467 return false; 430 return false;
468 // This tell us whether a valid frame has arrived or not. 431 // This tell us whether a valid frame has arrived or not.
469 if (!frame_evictor_->HasFrame()) 432 if (!frame_evictor_->HasFrame())
470 return false; 433 return false;
471 434
435 DCHECK(!delegated_frame_host_ ||
436 delegated_frame_host_->HasDelegatedContent());
472 return true; 437 return true;
473 } 438 }
474 439
475 gfx::Vector2dF RenderWidgetHostViewAndroid::GetLastScrollOffset() const { 440 gfx::Vector2dF RenderWidgetHostViewAndroid::GetLastScrollOffset() const {
476 return last_scroll_offset_; 441 return last_scroll_offset_;
477 } 442 }
478 443
479 gfx::NativeView RenderWidgetHostViewAndroid::GetNativeView() const { 444 gfx::NativeView RenderWidgetHostViewAndroid::GetNativeView() const {
480 return &view_; 445 return &view_;
481 } 446 }
(...skipping 17 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 view_.GetLayer()->SetHideLayerAndSubtree(!is_showing_);
562 view_.GetLayer()->SetHideLayerAndSubtree(true);
563 } 526 }
564 } 527 }
565 528
566 void RenderWidgetHostViewAndroid::OnShowUnhandledTapUIIfNeeded(int x_dip, 529 void RenderWidgetHostViewAndroid::OnShowUnhandledTapUIIfNeeded(int x_dip,
567 int y_dip) { 530 int y_dip) {
568 if (!content_view_core_) 531 if (!content_view_core_)
569 return; 532 return;
570 // Validate the coordinates are within the viewport. 533 // Validate the coordinates are within the viewport.
571 gfx::Size viewport_size = content_view_core_->GetViewportSizeDip(); 534 gfx::Size viewport_size = content_view_core_->GetViewportSizeDip();
572 if (x_dip < 0 || x_dip > viewport_size.width() || 535 if (x_dip < 0 || x_dip > viewport_size.width() ||
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 params.value, params.selection_start, params.selection_end, 618 params.value, params.selection_start, params.selection_end,
656 params.composition_start, params.composition_end, 619 params.composition_start, params.composition_end,
657 params.show_ime_if_needed, params.is_non_ime_change); 620 params.show_ime_if_needed, params.is_non_ime_change);
658 } 621 }
659 622
660 void RenderWidgetHostViewAndroid::UpdateBackgroundColor(SkColor color) { 623 void RenderWidgetHostViewAndroid::UpdateBackgroundColor(SkColor color) {
661 if (cached_background_color_ == color) 624 if (cached_background_color_ == color)
662 return; 625 return;
663 626
664 cached_background_color_ = color; 627 cached_background_color_ = color;
628 delegated_frame_host_->UpdateBackgroundColor(color);
665 if (content_view_core_) 629 if (content_view_core_)
666 content_view_core_->OnBackgroundColorChanged(color); 630 content_view_core_->OnBackgroundColorChanged(color);
667 } 631 }
668 632
669 void RenderWidgetHostViewAndroid::OnSetNeedsBeginFrames(bool enabled) { 633 void RenderWidgetHostViewAndroid::OnSetNeedsBeginFrames(bool enabled) {
670 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::OnSetNeedsBeginFrames", 634 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::OnSetNeedsBeginFrames",
671 "enabled", enabled); 635 "enabled", enabled);
672 if (enabled) 636 if (enabled)
673 RequestVSyncUpdate(PERSISTENT_BEGIN_FRAME); 637 RequestVSyncUpdate(PERSISTENT_BEGIN_FRAME);
674 else 638 else
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 ime_adapter_android_.FocusedNodeChanged(is_editable_node); 751 ime_adapter_android_.FocusedNodeChanged(is_editable_node);
788 } 752 }
789 753
790 void RenderWidgetHostViewAndroid::RenderProcessGone( 754 void RenderWidgetHostViewAndroid::RenderProcessGone(
791 base::TerminationStatus status, int error_code) { 755 base::TerminationStatus status, int error_code) {
792 Destroy(); 756 Destroy();
793 } 757 }
794 758
795 void RenderWidgetHostViewAndroid::Destroy() { 759 void RenderWidgetHostViewAndroid::Destroy() {
796 host_->ViewDestroyed(); 760 host_->ViewDestroyed();
797 RemoveLayers();
798 SetContentViewCore(NULL); 761 SetContentViewCore(NULL);
799 762 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 763
812 // The RenderWidgetHost's destruction led here, so don't call it. 764 // The RenderWidgetHost's destruction led here, so don't call it.
813 host_ = NULL; 765 host_ = NULL;
814 766
815 delete this; 767 delete this;
816 } 768 }
817 769
818 void RenderWidgetHostViewAndroid::SetTooltipText( 770 void RenderWidgetHostViewAndroid::SetTooltipText(
819 const base::string16& tooltip_text) { 771 const base::string16& tooltip_text) {
820 // Tooltips don't makes sense on Android. 772 // 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, 838 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback,
887 preferred_color_type); 839 preferred_color_type);
888 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", 840 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous",
889 base::TimeTicks::Now() - start_time); 841 base::TimeTicks::Now() - start_time);
890 return; 842 return;
891 } 843 }
892 844
893 ui::WindowAndroidCompositor* compositor = 845 ui::WindowAndroidCompositor* compositor =
894 content_view_core_->GetWindowAndroid()->GetCompositor(); 846 content_view_core_->GetWindowAndroid()->GetCompositor();
895 DCHECK(compositor); 847 DCHECK(compositor);
896 DCHECK(!surface_id_.is_null()); 848 delegated_frame_host_->RequestCopyOfSurface(
897 scoped_refptr<cc::Layer> layer = 849 compositor, src_subrect_in_pixel,
898 CreateSurfaceLayer(surface_id_, texture_size_in_layer_); 850 base::Bind(&PrepareTextureCopyOutputResult, dst_size_in_pixel,
899 layer->SetHideLayerAndSubtree(true); 851 preferred_color_type, start_time, callback));
900 compositor->AttachLayerForReadback(layer);
901
902 std::unique_ptr<cc::CopyOutputRequest> request =
903 cc::CopyOutputRequest::CreateRequest(
904 base::Bind(&PrepareTextureCopyOutputResult,
905 weak_ptr_factory_.GetWeakPtr(), layer, dst_size_in_pixel,
906 preferred_color_type, start_time, callback));
907
908 if (!src_subrect_in_pixel.IsEmpty())
909 request->set_area(src_subrect_in_pixel);
910 surface_factory_->RequestCopyOfSurface(surface_id_, std::move(request));
911 } 852 }
912 853
913 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( 854 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame(
914 const gfx::Rect& src_subrect, 855 const gfx::Rect& src_subrect,
915 const scoped_refptr<media::VideoFrame>& target, 856 const scoped_refptr<media::VideoFrame>& target,
916 const base::Callback<void(const gfx::Rect&, bool)>& callback) { 857 const base::Callback<void(const gfx::Rect&, bool)>& callback) {
917 NOTIMPLEMENTED(); 858 NOTIMPLEMENTED();
918 callback.Run(gfx::Rect(), false); 859 callback.Run(gfx::Rect(), false);
919 } 860 }
920 861
(...skipping 30 matching lines...) Expand all
951 const cc::ReturnedResourceArray& resources) { 892 const cc::ReturnedResourceArray& resources) {
952 if (resources.empty()) 893 if (resources.empty())
953 return; 894 return;
954 std::copy(resources.begin(), resources.end(), 895 std::copy(resources.begin(), resources.end(),
955 std::back_inserter(surface_returned_resources_)); 896 std::back_inserter(surface_returned_resources_));
956 if (ack_callbacks_.empty()) 897 if (ack_callbacks_.empty())
957 SendReclaimCompositorResources(last_output_surface_id_, 898 SendReclaimCompositorResources(last_output_surface_id_,
958 false /* is_swap_ack */); 899 false /* is_swap_ack */);
959 } 900 }
960 901
961 void RenderWidgetHostViewAndroid::SetBeginFrameSource(
962 cc::BeginFrameSource* begin_frame_source) {
963 // TODO(tansell): Hook this up.
964 }
965
966 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() {
967 RemoveLayers();
968 if (!surface_id_.is_null()) {
969 DCHECK(surface_factory_.get());
970 cc::SurfaceId surface_id;
971 std::swap(surface_id, surface_id_);
972 surface_factory_->Destroy(surface_id);
973 }
974 view_.SetLayer(nullptr);
975 }
976
977 void RenderWidgetHostViewAndroid::CheckOutputSurfaceChanged( 902 void RenderWidgetHostViewAndroid::CheckOutputSurfaceChanged(
978 uint32_t output_surface_id) { 903 uint32_t output_surface_id) {
979 if (output_surface_id == last_output_surface_id_) 904 if (output_surface_id == last_output_surface_id_)
980 return; 905 return;
981 DestroyDelegatedContent(); 906 delegated_frame_host_->OutputSurfaceChanged();
982 surface_factory_.reset(); 907
983 if (!surface_returned_resources_.empty()) 908 if (!surface_returned_resources_.empty())
984 SendReclaimCompositorResources(last_output_surface_id_, 909 SendReclaimCompositorResources(last_output_surface_id_,
985 false /* is_swap_ack */); 910 false /* is_swap_ack */);
986 911
987 last_output_surface_id_ = output_surface_id; 912 last_output_surface_id_ = output_surface_id;
988 } 913 }
989 914
990 void RenderWidgetHostViewAndroid::SubmitCompositorFrame(
991 cc::CompositorFrame frame) {
992 cc::SurfaceManager* manager =
993 ui::ContextProviderFactory::GetInstance()->GetSurfaceManager();
994 if (!surface_factory_) {
995 surface_factory_ = base::WrapUnique(new cc::SurfaceFactory(manager, this));
996 }
997 if (surface_id_.is_null() ||
998 texture_size_in_layer_ != current_surface_size_ ||
999 location_bar_content_translation_ !=
1000 frame.metadata.location_bar_content_translation ||
1001 current_viewport_selection_ != frame.metadata.selection) {
1002 RemoveLayers();
1003 if (!surface_id_.is_null())
1004 surface_factory_->Destroy(surface_id_);
1005 surface_id_ = id_allocator_->GenerateId();
1006 surface_factory_->Create(surface_id_);
1007 view_.SetLayer(CreateSurfaceLayer(surface_id_, texture_size_in_layer_));
1008
1009 DCHECK(view_.GetLayer());
1010
1011 current_surface_size_ = texture_size_in_layer_;
1012 location_bar_content_translation_ =
1013 frame.metadata.location_bar_content_translation;
1014 current_viewport_selection_ = frame.metadata.selection;
1015 AttachLayers();
1016 }
1017
1018 cc::SurfaceFactory::DrawCallback ack_callback =
1019 base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks,
1020 weak_ptr_factory_.GetWeakPtr());
1021 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame),
1022 ack_callback);
1023 }
1024
1025 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( 915 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame(
1026 uint32_t output_surface_id, 916 uint32_t output_surface_id,
1027 cc::CompositorFrame frame) { 917 cc::CompositorFrame frame) {
1028 last_scroll_offset_ = frame.metadata.root_scroll_offset; 918 last_scroll_offset_ = frame.metadata.root_scroll_offset;
1029 DCHECK(frame.delegated_frame_data); 919 DCHECK(frame.delegated_frame_data);
920 DCHECK(delegated_frame_host_);
1030 921
1031 if (locks_on_frame_count_ > 0) { 922 if (locks_on_frame_count_ > 0) {
1032 DCHECK(HasValidFrame()); 923 DCHECK(HasValidFrame());
1033 RetainFrame(output_surface_id, std::move(frame)); 924 RetainFrame(output_surface_id, std::move(frame));
1034 return; 925 return;
1035 } 926 }
1036 927
1037 DCHECK(!frame.delegated_frame_data->render_pass_list.empty()); 928 DCHECK(!frame.delegated_frame_data->render_pass_list.empty());
1038 929
1039 cc::RenderPass* root_pass = 930 cc::RenderPass* root_pass =
1040 frame.delegated_frame_data->render_pass_list.back().get(); 931 frame.delegated_frame_data->render_pass_list.back().get();
1041 texture_size_in_layer_ = root_pass->output_rect.size(); 932 current_surface_size_ = root_pass->output_rect.size();
1042 933
1043 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); 934 cc::CompositorFrameMetadata metadata = frame.metadata.Clone();
1044 935
1045 CheckOutputSurfaceChanged(output_surface_id); 936 CheckOutputSurfaceChanged(output_surface_id);
1046 bool has_content = !texture_size_in_layer_.IsEmpty(); 937 bool has_content = !current_surface_size_.IsEmpty();
1047 938
1048 base::Closure ack_callback = 939 base::Closure ack_callback =
1049 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources, 940 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources,
1050 weak_ptr_factory_.GetWeakPtr(), output_surface_id, 941 weak_ptr_factory_.GetWeakPtr(), output_surface_id,
1051 true /* is_swap_ack */); 942 true /* is_swap_ack */);
1052 943
1053 ack_callbacks_.push(ack_callback); 944 ack_callbacks_.push(ack_callback);
1054 945
1055 if (!has_content) { 946 if (!has_content) {
1056 DestroyDelegatedContent(); 947 delegated_frame_host_->DestroyDelegatedContent();
1057 } else { 948 } else {
1058 SubmitCompositorFrame(std::move(frame)); 949 cc::SurfaceFactory::DrawCallback ack_callback =
1059 view_.GetLayer()->SetIsDrawable(true); 950 base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks,
1060 view_.GetLayer()->SetContentsOpaque(true); 951 weak_ptr_factory_.GetWeakPtr());
1061 view_.GetLayer()->SetBounds(texture_size_in_layer_); 952 delegated_frame_host_->SubmitCompositorFrame(std::move(frame),
953 ack_callback);
1062 } 954 }
1063 955
1064 if (host_->is_hidden()) 956 if (host_->is_hidden())
1065 RunAckCallbacks(); 957 RunAckCallbacks();
1066 frame_evictor_->SwappedFrame(!host_->is_hidden()); 958 frame_evictor_->SwappedFrame(!host_->is_hidden());
1067 959
1068 // As the metadata update may trigger view invalidation, always call it after 960 // As the metadata update may trigger view invalidation, always call it after
1069 // any potential compositor scheduling. 961 // any potential compositor scheduling.
1070 OnFrameMetadataUpdated(std::move(metadata)); 962 OnFrameMetadataUpdated(std::move(metadata));
1071 } 963 }
1072 964
1073 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( 965 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame(
1074 uint32_t output_surface_id, 966 uint32_t output_surface_id,
1075 cc::CompositorFrame frame) { 967 cc::CompositorFrame frame) {
1076 InternalSwapCompositorFrame(output_surface_id, std::move(frame)); 968 InternalSwapCompositorFrame(output_surface_id, std::move(frame));
1077 } 969 }
1078 970
1079 void RenderWidgetHostViewAndroid::ClearCompositorFrame() { 971 void RenderWidgetHostViewAndroid::ClearCompositorFrame() {
1080 DestroyDelegatedContent(); 972 delegated_frame_host_->DestroyDelegatedContent();
1081 } 973 }
1082 974
1083 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t output_surface_id, 975 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t output_surface_id,
1084 cc::CompositorFrame frame) { 976 cc::CompositorFrame frame) {
1085 DCHECK(locks_on_frame_count_); 977 DCHECK(locks_on_frame_count_);
1086 978
1087 // Store the incoming frame so that it can be swapped when all the locks have 979 // Store the incoming frame so that it can be swapped when all the locks have
1088 // been released. If there is already a stored frame, then replace and skip 980 // been released. If there is already a stored frame, then replace and skip
1089 // the previous one but make sure we still eventually send the ACK. Holding 981 // the previous one but make sure we still eventually send the ACK. Holding
1090 // the ACK also blocks the renderer when its max_frames_pending is reached. 982 // the ACK also blocks the renderer when its max_frames_pending is reached.
(...skipping 28 matching lines...) Expand all
1119 BrowserThread::PostTask( 1011 BrowserThread::PostTask(
1120 BrowserThread::UI, FROM_HERE, 1012 BrowserThread::UI, FROM_HERE,
1121 base::Bind( 1013 base::Bind(
1122 &RenderFrameDevToolsAgentHost::SynchronousSwapCompositorFrame, 1014 &RenderFrameDevToolsAgentHost::SynchronousSwapCompositorFrame,
1123 static_cast<RenderFrameDevToolsAgentHost*>(dtah.get()), 1015 static_cast<RenderFrameDevToolsAgentHost*>(dtah.get()),
1124 base::Passed(&frame_metadata))); 1016 base::Passed(&frame_metadata)));
1125 } 1017 }
1126 } 1018 }
1127 1019
1128 void RenderWidgetHostViewAndroid::SetOverlayVideoMode(bool enabled) { 1020 void RenderWidgetHostViewAndroid::SetOverlayVideoMode(bool enabled) {
1129 if (view_.GetLayer()) 1021 if (delegated_frame_host_)
1130 view_.GetLayer()->SetContentsOpaque(!enabled); 1022 delegated_frame_host_->SetContentsOpaque(!enabled);
1131 } 1023 }
1132 1024
1133 bool RenderWidgetHostViewAndroid::SupportsAnimation() const { 1025 bool RenderWidgetHostViewAndroid::SupportsAnimation() const {
1134 // The synchronous (WebView) compositor does not have a proper browser 1026 // The synchronous (WebView) compositor does not have a proper browser
1135 // compositor with which to drive animations. 1027 // compositor with which to drive animations.
1136 return using_browser_compositor_; 1028 return using_browser_compositor_;
1137 } 1029 }
1138 1030
1139 void RenderWidgetHostViewAndroid::SetNeedsAnimate() { 1031 void RenderWidgetHostViewAndroid::SetNeedsAnimate() {
1140 DCHECK(content_view_core_ && content_view_core_->GetWindowAndroid()); 1032 DCHECK(content_view_core_ && content_view_core_->GetWindowAndroid());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 content_view_core_->GetContext().obj())); 1083 content_view_core_->GetContext().obj()));
1192 } 1084 }
1193 1085
1194 void RenderWidgetHostViewAndroid::SynchronousCopyContents( 1086 void RenderWidgetHostViewAndroid::SynchronousCopyContents(
1195 const gfx::Rect& src_subrect_in_pixel, 1087 const gfx::Rect& src_subrect_in_pixel,
1196 const gfx::Size& dst_size_in_pixel, 1088 const gfx::Size& dst_size_in_pixel,
1197 const ReadbackRequestCallback& callback, 1089 const ReadbackRequestCallback& callback,
1198 const SkColorType color_type) { 1090 const SkColorType color_type) {
1199 gfx::Size input_size_in_pixel; 1091 gfx::Size input_size_in_pixel;
1200 if (src_subrect_in_pixel.IsEmpty()) 1092 if (src_subrect_in_pixel.IsEmpty())
1201 input_size_in_pixel = texture_size_in_layer_; 1093 input_size_in_pixel = current_surface_size_;
1202 else 1094 else
1203 input_size_in_pixel = src_subrect_in_pixel.size(); 1095 input_size_in_pixel = src_subrect_in_pixel.size();
1204 1096
1205 gfx::Size output_size_in_pixel; 1097 gfx::Size output_size_in_pixel;
1206 if (dst_size_in_pixel.IsEmpty()) 1098 if (dst_size_in_pixel.IsEmpty())
1207 output_size_in_pixel = input_size_in_pixel; 1099 output_size_in_pixel = input_size_in_pixel;
1208 else 1100 else
1209 output_size_in_pixel = dst_size_in_pixel; 1101 output_size_in_pixel = dst_size_in_pixel;
1210 int output_width = output_size_in_pixel.width(); 1102 int output_width = output_size_in_pixel.width();
1211 int output_height = output_size_in_pixel.height(); 1103 int output_height = output_size_in_pixel.height();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 } 1176 }
1285 1177
1286 void RenderWidgetHostViewAndroid::ShowInternal() { 1178 void RenderWidgetHostViewAndroid::ShowInternal() {
1287 bool show = is_showing_ && is_window_activity_started_ && is_window_visible_; 1179 bool show = is_showing_ && is_window_activity_started_ && is_window_visible_;
1288 if (!show) 1180 if (!show)
1289 return; 1181 return;
1290 1182
1291 if (!host_ || !host_->is_hidden()) 1183 if (!host_ || !host_->is_hidden())
1292 return; 1184 return;
1293 1185
1294 if (view_.GetLayer()) 1186 view_.GetLayer()->SetHideLayerAndSubtree(false);
1295 view_.GetLayer()->SetHideLayerAndSubtree(false);
1296 1187
1297 frame_evictor_->SetVisible(true); 1188 frame_evictor_->SetVisible(true);
1298 1189
1299 if (overscroll_controller_) 1190 if (overscroll_controller_)
1300 overscroll_controller_->Enable(); 1191 overscroll_controller_->Enable();
1301 1192
1302 host_->WasShown(ui::LatencyInfo()); 1193 host_->WasShown(ui::LatencyInfo());
1303 1194
1304 if (content_view_core_) { 1195 if (content_view_core_) {
1305 StartObservingRootWindow(); 1196 StartObservingRootWindow();
1306 RequestVSyncUpdate(BEGIN_FRAME); 1197 RequestVSyncUpdate(BEGIN_FRAME);
1307 } 1198 }
1308 } 1199 }
1309 1200
1310 void RenderWidgetHostViewAndroid::HideInternal() { 1201 void RenderWidgetHostViewAndroid::HideInternal() {
1311 DCHECK(!is_showing_ || !is_window_activity_started_ || !is_window_visible_) 1202 DCHECK(!is_showing_ || !is_window_activity_started_ || !is_window_visible_)
1312 << "Hide called when the widget should be shown."; 1203 << "Hide called when the widget should be shown.";
1313 1204
1314 // Only preserve the frontbuffer if the activity was stopped while the 1205 // Only preserve the frontbuffer if the activity was stopped while the
1315 // window is still visible. This avoids visual artificts when transitioning 1206 // window is still visible. This avoids visual artificts when transitioning
1316 // between activities. 1207 // between activities.
1317 bool hide_frontbuffer = is_window_activity_started_ || !is_window_visible_; 1208 bool hide_frontbuffer = is_window_activity_started_ || !is_window_visible_;
1318 1209
1319 // Only stop observing the root window if the widget has been explicitly 1210 // Only stop observing the root window if the widget has been explicitly
1320 // hidden and the frontbuffer is being cleared. This allows window visibility 1211 // hidden and the frontbuffer is being cleared. This allows window visibility
1321 // notifications to eventually clear the frontbuffer. 1212 // notifications to eventually clear the frontbuffer.
1322 bool stop_observing_root_window = !is_showing_ && hide_frontbuffer; 1213 bool stop_observing_root_window = !is_showing_ && hide_frontbuffer;
1323 1214
1324 if (hide_frontbuffer) { 1215 if (hide_frontbuffer) {
1325 if (view_.GetLayer() && locks_on_frame_count_ == 0) 1216 if (locks_on_frame_count_ == 0)
Khushal 2016/08/16 06:22:42 Btw, why is there a locks check here?
Khushal 2016/08/16 18:37:36 Pingy!
no sievers 2016/08/16 20:36:36 I'm about to remove the locking code here as it st
1326 view_.GetLayer()->SetHideLayerAndSubtree(true); 1217 view_.GetLayer()->SetHideLayerAndSubtree(true);
1327 1218
1328 frame_evictor_->SetVisible(false); 1219 frame_evictor_->SetVisible(false);
1329 } 1220 }
1330 1221
1331 if (stop_observing_root_window) { 1222 if (stop_observing_root_window) {
1332 DCHECK(!is_showing_); 1223 DCHECK(!is_showing_);
1333 StopObservingRootWindow(); 1224 StopObservingRootWindow();
1334 } 1225 }
1335 1226
1336 if (!host_ || host_->is_hidden()) 1227 if (!host_ || host_->is_hidden())
1337 return; 1228 return;
1338 1229
1339 if (overscroll_controller_) 1230 if (overscroll_controller_)
1340 overscroll_controller_->Disable(); 1231 overscroll_controller_->Disable();
1341 1232
1342 RunAckCallbacks(); 1233 RunAckCallbacks();
1343 1234
1344 // Inform the renderer that we are being hidden so it can reduce its resource 1235 // Inform the renderer that we are being hidden so it can reduce its resource
1345 // utilization. 1236 // utilization.
1346 host_->WasHidden(); 1237 host_->WasHidden();
1347 } 1238 }
1348 1239
1349 void RenderWidgetHostViewAndroid::AttachLayers() {
1350 if (!content_view_core_)
1351 return;
1352 if (!view_.GetLayer())
1353 return;
1354
1355 content_view_core_->AttachLayer(view_.GetLayer());
1356 view_.GetLayer()->SetHideLayerAndSubtree(!is_showing_);
1357 }
1358
1359 void RenderWidgetHostViewAndroid::RemoveLayers() {
1360 if (!content_view_core_)
1361 return;
1362
1363 if (!view_.GetLayer())
1364 return;
1365
1366 content_view_core_->RemoveLayer(view_.GetLayer());
1367 }
1368
1369 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32_t requests) { 1240 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32_t requests) {
1370 bool should_request_vsync = !outstanding_vsync_requests_ && requests; 1241 bool should_request_vsync = !outstanding_vsync_requests_ && requests;
1371 outstanding_vsync_requests_ |= requests; 1242 outstanding_vsync_requests_ |= requests;
1372 1243
1373 // Note that if we're not currently observing the root window, outstanding 1244 // Note that if we're not currently observing the root window, outstanding
1374 // vsync requests will be pushed if/when we resume observing in 1245 // vsync requests will be pushed if/when we resume observing in
1375 // |StartObservingRootWindow()|. 1246 // |StartObservingRootWindow()|.
1376 if (observing_root_window_ && should_request_vsync) 1247 if (observing_root_window_ && should_request_vsync)
1377 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); 1248 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate();
1378 } 1249 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 } 1316 }
1446 1317
1447 void RenderWidgetHostViewAndroid::RequestDisallowInterceptTouchEvent() { 1318 void RenderWidgetHostViewAndroid::RequestDisallowInterceptTouchEvent() {
1448 if (content_view_core_) 1319 if (content_view_core_)
1449 content_view_core_->RequestDisallowInterceptTouchEvent(); 1320 content_view_core_->RequestDisallowInterceptTouchEvent();
1450 } 1321 }
1451 1322
1452 void RenderWidgetHostViewAndroid::EvictDelegatedFrame() { 1323 void RenderWidgetHostViewAndroid::EvictDelegatedFrame() {
1453 DCHECK_EQ(locks_on_frame_count_, 0u); 1324 DCHECK_EQ(locks_on_frame_count_, 0u);
1454 frame_evictor_->DiscardedFrame(); 1325 frame_evictor_->DiscardedFrame();
1455 if (view_.GetLayer()) 1326 delegated_frame_host_->DestroyDelegatedContent();
1456 DestroyDelegatedContent();
1457 } 1327 }
1458 1328
1459 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface( 1329 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface(
1460 const gfx::Size& desired_size) { 1330 const gfx::Size& desired_size) {
1461 NOTREACHED(); 1331 NOTREACHED();
1462 return false; 1332 return false;
1463 } 1333 }
1464 1334
1465 // TODO(jrg): Find out the implications and answer correctly here, 1335 // TODO(jrg): Find out the implications and answer correctly here,
1466 // as we are returning the WebView and not root window bounds. 1336 // as we are returning the WebView and not root window bounds.
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 1521
1652 SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const { 1522 SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const {
1653 return cached_background_color_; 1523 return cached_background_color_;
1654 } 1524 }
1655 1525
1656 void RenderWidgetHostViewAndroid::DidOverscroll( 1526 void RenderWidgetHostViewAndroid::DidOverscroll(
1657 const DidOverscrollParams& params) { 1527 const DidOverscrollParams& params) {
1658 if (sync_compositor_) 1528 if (sync_compositor_)
1659 sync_compositor_->DidOverscroll(params); 1529 sync_compositor_->DidOverscroll(params);
1660 1530
1661 if (!content_view_core_ || !view_.GetLayer() || !is_showing_) 1531 if (!content_view_core_ || !is_showing_)
1532 return;
1533
1534 if (delegated_frame_host_ && delegated_frame_host_->HasDelegatedContent())
1662 return; 1535 return;
1663 1536
1664 if (overscroll_controller_) 1537 if (overscroll_controller_)
1665 overscroll_controller_->OnOverscrolled(params); 1538 overscroll_controller_->OnOverscrolled(params);
1666 } 1539 }
1667 1540
1668 void RenderWidgetHostViewAndroid::DidStopFlinging() { 1541 void RenderWidgetHostViewAndroid::DidStopFlinging() {
1669 if (content_view_core_) 1542 if (content_view_core_)
1670 content_view_core_->DidStopFlinging(); 1543 content_view_core_->DidStopFlinging();
1671 } 1544 }
1672 1545
1673 uint32_t RenderWidgetHostViewAndroid::GetSurfaceClientId() { 1546 uint32_t RenderWidgetHostViewAndroid::GetSurfaceClientId() {
1674 if (id_allocator_) 1547 if (!delegated_frame_host_)
1675 return id_allocator_->client_id(); 1548 return 0;
1676 return 0; 1549
1550 return delegated_frame_host_->GetSurfaceClientId();
1677 } 1551 }
1678 1552
1679 void RenderWidgetHostViewAndroid::SetContentViewCore( 1553 void RenderWidgetHostViewAndroid::SetContentViewCore(
1680 ContentViewCoreImpl* content_view_core) { 1554 ContentViewCoreImpl* content_view_core) {
1681 DCHECK(!content_view_core || !content_view_core_ || 1555 DCHECK(!content_view_core || !content_view_core_ ||
1682 (content_view_core_ == content_view_core)); 1556 (content_view_core_ == content_view_core));
1683 RemoveLayers();
1684 StopObservingRootWindow(); 1557 StopObservingRootWindow();
1685 1558
1686 bool resize = false; 1559 bool resize = false;
1687 if (content_view_core != content_view_core_) { 1560 if (content_view_core != content_view_core_) {
1688 overscroll_controller_.reset(); 1561 overscroll_controller_.reset();
1689 selection_controller_.reset(); 1562 selection_controller_.reset();
1690 ReleaseLocksOnSurface(); 1563 ReleaseLocksOnSurface();
1691 // TODO(yusufo) : Get rid of the below conditions and have a better handling 1564 // TODO(yusufo) : Get rid of the below conditions and have a better handling
1692 // for resizing after crbug.com/628302 is handled. 1565 // for resizing after crbug.com/628302 is handled.
1693 bool is_size_initialized = !content_view_core 1566 bool is_size_initialized = !content_view_core
1694 || content_view_core->GetViewportSizeDip().width() != 0 1567 || content_view_core->GetViewportSizeDip().width() != 0
1695 || content_view_core->GetViewportSizeDip().height() != 0; 1568 || content_view_core->GetViewportSizeDip().height() != 0;
1696 if (content_view_core_ || is_size_initialized) 1569 if (content_view_core_ || is_size_initialized)
1697 resize = true; 1570 resize = true;
1698 if (content_view_core_) { 1571 if (content_view_core_) {
1699 content_view_core_->RemoveObserver(this); 1572 content_view_core_->RemoveObserver(this);
1700 view_.RemoveFromParent(); 1573 view_.RemoveFromParent();
1574 view_.GetLayer()->RemoveFromParent();
1701 } 1575 }
1702 if (content_view_core) { 1576 if (content_view_core) {
1703 content_view_core->AddObserver(this); 1577 content_view_core->AddObserver(this);
1704 content_view_core->GetViewAndroid()->AddChild(&view_); 1578 ui::ViewAndroid* parent_view = content_view_core->GetViewAndroid();
1579 parent_view->AddChild(&view_);
1580 parent_view->GetLayer()->AddChild(view_.GetLayer());
1705 } 1581 }
1706 content_view_core_ = content_view_core; 1582 content_view_core_ = content_view_core;
1707 } 1583 }
1708 1584
1709 BrowserAccessibilityManager* manager = NULL; 1585 BrowserAccessibilityManager* manager = NULL;
1710 if (host_) 1586 if (host_)
1711 manager = host_->GetRootBrowserAccessibilityManager(); 1587 manager = host_->GetRootBrowserAccessibilityManager();
1712 if (manager) { 1588 if (manager) {
1713 base::android::ScopedJavaLocalRef<jobject> obj; 1589 base::android::ScopedJavaLocalRef<jobject> obj;
1714 if (content_view_core_) 1590 if (content_view_core_)
1715 obj = content_view_core_->GetJavaObject(); 1591 obj = content_view_core_->GetJavaObject();
1716 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); 1592 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj);
1717 } 1593 }
1718 1594
1719 AttachLayers();
1720 if (!content_view_core_) { 1595 if (!content_view_core_) {
1721 sync_compositor_.reset(); 1596 sync_compositor_.reset();
1722 return; 1597 return;
1723 } 1598 }
1724 1599
1725 if (is_showing_) 1600 if (is_showing_)
1726 StartObservingRootWindow(); 1601 StartObservingRootWindow();
1727 1602
1728 if (resize) 1603 if (resize)
1729 WasResized(); 1604 WasResized();
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1854 1729
1855 void RenderWidgetHostViewAndroid::OnActivityStarted() { 1730 void RenderWidgetHostViewAndroid::OnActivityStarted() {
1856 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityStarted"); 1731 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityStarted");
1857 DCHECK(observing_root_window_); 1732 DCHECK(observing_root_window_);
1858 is_window_activity_started_ = true; 1733 is_window_activity_started_ = true;
1859 ShowInternal(); 1734 ShowInternal();
1860 } 1735 }
1861 1736
1862 void RenderWidgetHostViewAndroid::OnLostResources() { 1737 void RenderWidgetHostViewAndroid::OnLostResources() {
1863 ReleaseLocksOnSurface(); 1738 ReleaseLocksOnSurface();
1864 if (view_.GetLayer()) 1739 delegated_frame_host_->DestroyDelegatedContent();
1865 DestroyDelegatedContent();
1866 DCHECK(ack_callbacks_.empty()); 1740 DCHECK(ack_callbacks_.empty());
1867 } 1741 }
1868 1742
1869 // TODO(wjmaclean): There is significant overlap between 1743 // TODO(wjmaclean): There is significant overlap between
1870 // PrepareTextureCopyOutputResult and CopyFromCompositingSurfaceFinished in 1744 // PrepareTextureCopyOutputResult and CopyFromCompositingSurfaceFinished in
1871 // this file, and the versions in surface_utils.cc. They should 1745 // this file, and the versions in surface_utils.cc. They should
1872 // be merged. See https://crbug.com/582955 1746 // be merged. See https://crbug.com/582955
1873 1747
1874 // static 1748 // static
1875 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( 1749 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult(
1876 base::WeakPtr<RenderWidgetHostViewAndroid> rwhva,
1877 scoped_refptr<cc::Layer> readback_layer,
1878 const gfx::Size& dst_size_in_pixel, 1750 const gfx::Size& dst_size_in_pixel,
1879 SkColorType color_type, 1751 SkColorType color_type,
1880 const base::TimeTicks& start_time, 1752 const base::TimeTicks& start_time,
1881 const ReadbackRequestCallback& callback, 1753 const ReadbackRequestCallback& callback,
1882 std::unique_ptr<cc::CopyOutputResult> result) { 1754 std::unique_ptr<cc::CopyOutputResult> result) {
1883 base::ScopedClosureRunner scoped_callback_runner( 1755 base::ScopedClosureRunner scoped_callback_runner(
1884 base::Bind(callback, SkBitmap(), READBACK_FAILED)); 1756 base::Bind(callback, SkBitmap(), READBACK_FAILED));
1885 TRACE_EVENT0("cc", 1757 TRACE_EVENT0("cc",
1886 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult"); 1758 "RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult");
1887 readback_layer->RemoveFromParent();
1888 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) 1759 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty())
1889 return; 1760 return;
1890 cc::TextureMailbox texture_mailbox; 1761 cc::TextureMailbox texture_mailbox;
1891 std::unique_ptr<cc::SingleReleaseCallback> release_callback; 1762 std::unique_ptr<cc::SingleReleaseCallback> release_callback;
1892 result->TakeTexture(&texture_mailbox, &release_callback); 1763 result->TakeTexture(&texture_mailbox, &release_callback);
1893 DCHECK(texture_mailbox.IsTexture()); 1764 DCHECK(texture_mailbox.IsTexture());
1894 if (!texture_mailbox.IsTexture()) 1765 if (!texture_mailbox.IsTexture())
1895 return; 1766 return;
1896 display_compositor::GLHelper* gl_helper = GetPostReadbackGLHelper(); 1767 display_compositor::GLHelper* gl_helper = GetPostReadbackGLHelper();
1897 if (!gl_helper) 1768 if (!gl_helper)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1974 case ui::MotionEvent::ACTION_UP: 1845 case ui::MotionEvent::ACTION_UP:
1975 case ui::MotionEvent::ACTION_POINTER_UP: 1846 case ui::MotionEvent::ACTION_POINTER_UP:
1976 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", 1847 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED",
1977 delta.InMicroseconds(), 1, 1000000, 50); 1848 delta.InMicroseconds(), 1, 1000000, 50);
1978 default: 1849 default:
1979 return; 1850 return;
1980 } 1851 }
1981 } 1852 }
1982 1853
1983 } // namespace content 1854 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_android.h ('k') | ui/android/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698