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

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

Issue 14268004: Add overscroll edge effect animations for Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use vsync ticks to drive overscroll animation Created 7 years, 8 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 "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/message_loop.h" 12 #include "base/message_loop.h"
12 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
13 #include "cc/layers/layer.h" 14 #include "cc/layers/layer.h"
14 #include "cc/layers/texture_layer.h" 15 #include "cc/layers/texture_layer.h"
15 #include "cc/output/compositor_frame.h" 16 #include "cc/output/compositor_frame.h"
16 #include "cc/output/compositor_frame_ack.h" 17 #include "cc/output/compositor_frame_ack.h"
17 #include "content/browser/android/content_view_core_impl.h" 18 #include "content/browser/android/content_view_core_impl.h"
19 #include "content/browser/android/overscroll_glow.h"
18 #include "content/browser/gpu/gpu_surface_tracker.h" 20 #include "content/browser/gpu/gpu_surface_tracker.h"
19 #include "content/browser/renderer_host/compositor_impl_android.h" 21 #include "content/browser/renderer_host/compositor_impl_android.h"
20 #include "content/browser/renderer_host/image_transport_factory_android.h" 22 #include "content/browser/renderer_host/image_transport_factory_android.h"
21 #include "content/browser/renderer_host/render_widget_host_impl.h" 23 #include "content/browser/renderer_host/render_widget_host_impl.h"
22 #include "content/browser/renderer_host/surface_texture_transport_client_android .h" 24 #include "content/browser/renderer_host/surface_texture_transport_client_android .h"
23 #include "content/common/gpu/client/gl_helper.h" 25 #include "content/common/gpu/client/gl_helper.h"
24 #include "content/common/gpu/gpu_messages.h" 26 #include "content/common/gpu/gpu_messages.h"
25 #include "content/common/view_messages.h" 27 #include "content/common/view_messages.h"
28 #include "content/public/common/content_switches.h"
26 #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h" 29 #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h"
27 #include "third_party/WebKit/Source/Platform/chromium/public/WebExternalTextureL ayer.h" 30 #include "third_party/WebKit/Source/Platform/chromium/public/WebExternalTextureL ayer.h"
28 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" 31 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
29 #include "third_party/khronos/GLES2/gl2.h" 32 #include "third_party/khronos/GLES2/gl2.h"
30 #include "third_party/khronos/GLES2/gl2ext.h" 33 #include "third_party/khronos/GLES2/gl2ext.h"
31 #include "ui/gfx/android/device_display_info.h" 34 #include "ui/gfx/android/device_display_info.h"
32 #include "ui/gfx/android/java_bitmap.h" 35 #include "ui/gfx/android/java_bitmap.h"
33 #include "ui/gfx/display.h" 36 #include "ui/gfx/display.h"
34 #include "ui/gfx/screen.h" 37 #include "ui/gfx/screen.h"
35 #include "ui/gfx/size_conversions.h" 38 #include "ui/gfx/size_conversions.h"
(...skipping 30 matching lines...) Expand all
66 RenderWidgetHostImpl::SendSwapCompositorFrameAck( 69 RenderWidgetHostImpl::SendSwapCompositorFrameAck(
67 route_id, renderer_host_id, ack); 70 route_id, renderer_host_id, ack);
68 } 71 }
69 72
70 } // anonymous namespace 73 } // anonymous namespace
71 74
72 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( 75 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid(
73 RenderWidgetHostImpl* widget_host, 76 RenderWidgetHostImpl* widget_host,
74 ContentViewCoreImpl* content_view_core) 77 ContentViewCoreImpl* content_view_core)
75 : host_(widget_host), 78 : host_(widget_host),
76 is_layer_attached_(true), 79 are_layers_attached_(true),
77 content_view_core_(NULL), 80 content_view_core_(NULL),
78 ime_adapter_android_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 81 ime_adapter_android_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
79 cached_background_color_(SK_ColorWHITE), 82 cached_background_color_(SK_ColorWHITE),
80 texture_id_in_layer_(0), 83 texture_id_in_layer_(0),
81 consumed_current_texture_(true) { 84 consumed_current_texture_(true),
85 vsync_notifications_enabled_(false),
86 client_vsync_notifications_enabled_(false),
87 animation_vsync_notifications_enabled_(false) {
82 if (CompositorImpl::UsesDirectGL()) { 88 if (CompositorImpl::UsesDirectGL()) {
83 surface_texture_transport_.reset(new SurfaceTextureTransportClient()); 89 surface_texture_transport_.reset(new SurfaceTextureTransportClient());
84 layer_ = surface_texture_transport_->Initialize(); 90 layer_ = surface_texture_transport_->Initialize();
85 layer_->SetIsDrawable(true); 91 layer_->SetIsDrawable(true);
86 } else { 92 } else {
87 texture_layer_ = cc::TextureLayer::Create(this); 93 texture_layer_ = cc::TextureLayer::Create(this);
88 layer_ = texture_layer_; 94 layer_ = texture_layer_;
89 } 95 }
90 96
91 layer_->SetContentsOpaque(true); 97 layer_->SetContentsOpaque(true);
92 98
99 if (CommandLine::ForCurrentProcess()->
100 HasSwitch(switches::kEnableOverscrollEdgeEffect)) {
101 overscroll_effect_ = OverscrollGlow::Create();
102 }
103
93 host_->SetView(this); 104 host_->SetView(this);
94 SetContentViewCore(content_view_core); 105 SetContentViewCore(content_view_core);
95 } 106 }
96 107
97 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { 108 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() {
98 SetContentViewCore(NULL); 109 SetContentViewCore(NULL);
99 DCHECK(ack_callbacks_.empty()); 110 DCHECK(ack_callbacks_.empty());
100 if (texture_id_in_layer_ || !last_mailbox_.IsZero()) { 111 if (texture_id_in_layer_ || !last_mailbox_.IsZero()) {
101 ImageTransportFactoryAndroid* factory = 112 ImageTransportFactoryAndroid* factory =
102 ImageTransportFactoryAndroid::GetInstance(); 113 ImageTransportFactoryAndroid::GetInstance();
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 302
292 return content_view_core_->HasFocus(); 303 return content_view_core_->HasFocus();
293 } 304 }
294 305
295 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { 306 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const {
296 NOTIMPLEMENTED(); 307 NOTIMPLEMENTED();
297 return false; 308 return false;
298 } 309 }
299 310
300 void RenderWidgetHostViewAndroid::Show() { 311 void RenderWidgetHostViewAndroid::Show() {
301 if (is_layer_attached_) 312 if (are_layers_attached_)
302 return; 313 return;
303 314
304 is_layer_attached_ = true; 315 are_layers_attached_ = true;
305 if (content_view_core_) 316 AttachLayers();
306 content_view_core_->AttachLayer(layer_);
307 } 317 }
308 318
309 void RenderWidgetHostViewAndroid::Hide() { 319 void RenderWidgetHostViewAndroid::Hide() {
310 if (!is_layer_attached_) 320 if (!are_layers_attached_)
311 return; 321 return;
312 322
313 is_layer_attached_ = false; 323 are_layers_attached_ = false;
314 if (content_view_core_) 324 RemoveLayers();
315 content_view_core_->RemoveLayer(layer_);
316 } 325 }
317 326
318 bool RenderWidgetHostViewAndroid::IsShowing() { 327 bool RenderWidgetHostViewAndroid::IsShowing() {
319 // ContentViewCoreImpl represents the native side of the Java 328 // ContentViewCoreImpl represents the native side of the Java
320 // ContentViewCore. It being NULL means that it is not attached 329 // ContentViewCore. It being NULL means that it is not attached
321 // to the View system yet, so we treat this RWHVA as hidden. 330 // to the View system yet, so we treat this RWHVA as hidden.
322 return is_layer_attached_ && content_view_core_; 331 return are_layers_attached_ && content_view_core_;
323 } 332 }
324 333
325 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { 334 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const {
326 if (!content_view_core_) 335 if (!content_view_core_)
327 return gfx::Rect(); 336 return gfx::Rect();
328 337
329 // If the backing hasn't been initialized yet, report empty view bounds 338 // If the backing hasn't been initialized yet, report empty view bounds
330 // as well. Otherwise, we may end up stuck in a white-screen state because 339 // as well. Otherwise, we may end up stuck in a white-screen state because
331 // the resize ack is sent after swapbuffers. 340 // the resize ack is sent after swapbuffers.
332 if (GetPhysicalBackingSize().IsEmpty()) 341 if (GetPhysicalBackingSize().IsEmpty())
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 SkColor color) { 397 SkColor color) {
389 if (cached_background_color_ == color) 398 if (cached_background_color_ == color)
390 return; 399 return;
391 400
392 cached_background_color_ = color; 401 cached_background_color_ = color;
393 if (content_view_core_) 402 if (content_view_core_)
394 content_view_core_->OnBackgroundColorChanged(color); 403 content_view_core_->OnBackgroundColorChanged(color);
395 } 404 }
396 405
397 void RenderWidgetHostViewAndroid::SendVSync(base::TimeTicks frame_time) { 406 void RenderWidgetHostViewAndroid::SendVSync(base::TimeTicks frame_time) {
398 host_->Send(new ViewMsg_DidVSync(host_->GetRoutingID(), frame_time)); 407 if (client_vsync_notifications_enabled_)
408 host_->Send(new ViewMsg_DidVSync(host_->GetRoutingID(), frame_time));
409 if (animation_vsync_notifications_enabled_)
410 Animate();
399 } 411 }
400 412
401 void RenderWidgetHostViewAndroid::OnSetVSyncNotificationEnabled(bool enabled) { 413 void RenderWidgetHostViewAndroid::OnSetVSyncNotificationEnabled(bool enabled) {
402 if (content_view_core_) 414 client_vsync_notifications_enabled_ = enabled;
403 content_view_core_->SetVSyncNotificationEnabled(enabled); 415 RequestVSyncNotificationsIfNecessary();
416 }
417
418 void RenderWidgetHostViewAndroid::RequestVSyncNotificationsIfNecessary() {
419 bool notifications_enabled = client_vsync_notifications_enabled_ ||
420 animation_vsync_notifications_enabled_;
421 if (notifications_enabled != vsync_notifications_enabled_) {
aelias_OOO_until_Jul13 2013/04/22 23:46:48 I think this vsync_notifications_enabled_ value is
jdduke (slow) 2013/04/23 16:02:13 Are you sure? Every enable/disable call will affec
422 if (content_view_core_)
423 content_view_core_->SetVSyncNotificationEnabled(notifications_enabled);
424 vsync_notifications_enabled_ = notifications_enabled;
425 }
404 } 426 }
405 427
406 void RenderWidgetHostViewAndroid::OnStartContentIntent( 428 void RenderWidgetHostViewAndroid::OnStartContentIntent(
407 const GURL& content_url) { 429 const GURL& content_url) {
408 if (content_view_core_) 430 if (content_view_core_)
409 content_view_core_->StartContentIntent(content_url); 431 content_view_core_->StartContentIntent(content_url);
410 } 432 }
411 433
412 void RenderWidgetHostViewAndroid::ImeCancelComposition() { 434 void RenderWidgetHostViewAndroid::ImeCancelComposition() {
413 ime_adapter_android_.CancelComposition(); 435 ime_adapter_android_.CancelComposition();
(...skipping 10 matching lines...) Expand all
424 const std::vector<gfx::Rect>& copy_rects) { 446 const std::vector<gfx::Rect>& copy_rects) {
425 NOTIMPLEMENTED(); 447 NOTIMPLEMENTED();
426 } 448 }
427 449
428 void RenderWidgetHostViewAndroid::RenderViewGone( 450 void RenderWidgetHostViewAndroid::RenderViewGone(
429 base::TerminationStatus status, int error_code) { 451 base::TerminationStatus status, int error_code) {
430 Destroy(); 452 Destroy();
431 } 453 }
432 454
433 void RenderWidgetHostViewAndroid::Destroy() { 455 void RenderWidgetHostViewAndroid::Destroy() {
434 if (content_view_core_) { 456 RemoveLayers();
435 content_view_core_->RemoveLayer(layer_); 457 content_view_core_ = NULL;
436 content_view_core_ = NULL; 458
437 } 459 overscroll_effect_.reset();
aelias_OOO_until_Jul13 2013/04/22 23:46:48 Delete this line, we can rely on the destructor.
jdduke (slow) 2013/04/23 16:02:13 Right, I had it here as I was unsure of the behavi
438 460
439 // The RenderWidgetHost's destruction led here, so don't call it. 461 // The RenderWidgetHost's destruction led here, so don't call it.
440 host_ = NULL; 462 host_ = NULL;
441 463
442 delete this; 464 delete this;
443 } 465 }
444 466
445 void RenderWidgetHostViewAndroid::SetTooltipText( 467 void RenderWidgetHostViewAndroid::SetTooltipText(
446 const string16& tooltip_text) { 468 const string16& tooltip_text) {
447 // Tooltips don't makes sense on Android. 469 // Tooltips don't makes sense on Android.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 if (texture_size.GetArea() > 0) 580 if (texture_size.GetArea() > 0)
559 offset = frame->metadata.location_bar_content_translation; 581 offset = frame->metadata.location_bar_content_translation;
560 offset.set_y(offset.y() + frame->metadata.overdraw_bottom_height); 582 offset.set_y(offset.y() + frame->metadata.overdraw_bottom_height);
561 gfx::SizeF content_size(texture_size.width() - offset.x() * dp2px, 583 gfx::SizeF content_size(texture_size.width() - offset.x() * dp2px,
562 texture_size.height() - offset.y() * dp2px); 584 texture_size.height() - offset.y() * dp2px);
563 BuffersSwapped(frame->gl_frame_data->mailbox, 585 BuffersSwapped(frame->gl_frame_data->mailbox,
564 texture_size, 586 texture_size,
565 content_size, 587 content_size,
566 callback); 588 callback);
567 589
590 if (overscroll_effect_) {
591 // Disable left/right edge effects when fully zoomed out.
592 const cc::CompositorFrameMetadata& metadata = frame->metadata;
593 bool horizontal_scrolling_possible =
594 metadata.page_scale_factor != metadata.min_page_scale_factor &&
aelias_OOO_until_Jul13 2013/04/22 23:46:48 Can this page scale factor comparison be removed?
jdduke (slow) 2013/04/23 16:02:13 I added the page scale check when I noticed certai
595 metadata.root_layer_size.width() != metadata.viewport_size.width();
596
597 overscroll_effect_->set_horizontal_overscroll_enabled(
aelias_OOO_until_Jul13 2013/04/22 23:46:48 There should be an analogous check for the vertica
jdduke (slow) 2013/04/23 16:02:13 Right, for whatever reason I thought it still show
598 horizontal_scrolling_possible);
599 overscroll_effect_->set_size(content_size);
600 }
568 } 601 }
569 602
570 void RenderWidgetHostViewAndroid::AcceleratedSurfaceBuffersSwapped( 603 void RenderWidgetHostViewAndroid::AcceleratedSurfaceBuffersSwapped(
571 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, 604 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
572 int gpu_host_id) { 605 int gpu_host_id) {
573 NOTREACHED() << "Deprecated. Use --composite-to-mailbox."; 606 NOTREACHED() << "Deprecated. Use --composite-to-mailbox.";
574 607
575 if (params.mailbox_name.empty()) 608 if (params.mailbox_name.empty())
576 return; 609 return;
577 610
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 current_mailbox_ = mailbox; 668 current_mailbox_ = mailbox;
636 669
637 if (consumed_current_texture_ || host_->is_hidden()) 670 if (consumed_current_texture_ || host_->is_hidden())
638 ack_callback.Run(); 671 ack_callback.Run();
639 else 672 else
640 ack_callbacks_.push(ack_callback); 673 ack_callbacks_.push(ack_callback);
641 674
642 consumed_current_texture_ = false; 675 consumed_current_texture_ = false;
643 } 676 }
644 677
678 void RenderWidgetHostViewAndroid::AttachLayers() {
679 if (!content_view_core_)
680 return;
681
682 content_view_core_->AttachLayer(layer_);
683
684 if (overscroll_effect_)
685 overscroll_effect_->set_parent_layer(content_view_core_->GetLayer());
686 }
687
688 void RenderWidgetHostViewAndroid::RemoveLayers() {
689 if (!content_view_core_)
690 return;
691
692 if (overscroll_effect_)
693 overscroll_effect_->set_parent_layer(NULL);
694
695 content_view_core_->RemoveLayer(layer_);
696 }
697
698 void RenderWidgetHostViewAndroid::Animate() {
699 if (!overscroll_effect_)
700 return;
701 overscroll_effect_->Animate(base::TimeTicks::Now());
702 ScheduleAnimation();
703 }
704
705 void RenderWidgetHostViewAndroid::ScheduleAnimation() {
706 animation_vsync_notifications_enabled_ = overscroll_effect_ &&
707 overscroll_effect_->IsAnimating();
708 RequestVSyncNotificationsIfNecessary();
709 }
710
645 void RenderWidgetHostViewAndroid::AcceleratedSurfacePostSubBuffer( 711 void RenderWidgetHostViewAndroid::AcceleratedSurfacePostSubBuffer(
646 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, 712 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
647 int gpu_host_id) { 713 int gpu_host_id) {
648 NOTREACHED(); 714 NOTREACHED();
649 } 715 }
650 716
651 void RenderWidgetHostViewAndroid::AcceleratedSurfaceSuspend() { 717 void RenderWidgetHostViewAndroid::AcceleratedSurfaceSuspend() {
652 NOTREACHED(); 718 NOTREACHED();
653 } 719 }
654 720
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 839
774 void RenderWidgetHostViewAndroid::MoveCaret(const gfx::Point& point) { 840 void RenderWidgetHostViewAndroid::MoveCaret(const gfx::Point& point) {
775 if (host_) 841 if (host_)
776 host_->MoveCaret(point); 842 host_->MoveCaret(point);
777 } 843 }
778 844
779 SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const { 845 SkColor RenderWidgetHostViewAndroid::GetCachedBackgroundColor() const {
780 return cached_background_color_; 846 return cached_background_color_;
781 } 847 }
782 848
849 void RenderWidgetHostViewAndroid::OnOverscrolled(
850 const gfx::Vector2dF& accumulated_overscroll,
851 const gfx::Vector2dF& current_fling_velocity) {
852 if (overscroll_effect_) {
853 overscroll_effect_->OnOverscrolled(base::TimeTicks::Now(),
854 accumulated_overscroll,
855 current_fling_velocity);
856 ScheduleAnimation();
857 }
858 }
859
783 void RenderWidgetHostViewAndroid::SetContentViewCore( 860 void RenderWidgetHostViewAndroid::SetContentViewCore(
784 ContentViewCoreImpl* content_view_core) { 861 ContentViewCoreImpl* content_view_core) {
785 RunAckCallbacks(); 862 RunAckCallbacks();
786 863
787 if (content_view_core_ && is_layer_attached_) 864 if (are_layers_attached_)
788 content_view_core_->RemoveLayer(layer_); 865 RemoveLayers();
789 866
790 content_view_core_ = content_view_core; 867 content_view_core_ = content_view_core;
791 if (content_view_core_ && is_layer_attached_) 868
792 content_view_core_->AttachLayer(layer_); 869 if (are_layers_attached_)
870 AttachLayers();
793 } 871 }
794 872
795 void RenderWidgetHostViewAndroid::RunAckCallbacks() { 873 void RenderWidgetHostViewAndroid::RunAckCallbacks() {
796 while (!ack_callbacks_.empty()) { 874 while (!ack_callbacks_.empty()) {
797 ack_callbacks_.front().Run(); 875 ack_callbacks_.front().Run();
798 ack_callbacks_.pop(); 876 ack_callbacks_.pop();
799 } 877 }
800 } 878 }
801 879
802 void RenderWidgetHostViewAndroid::HasTouchEventHandlers( 880 void RenderWidgetHostViewAndroid::HasTouchEventHandlers(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 // RenderWidgetHostView, public: 918 // RenderWidgetHostView, public:
841 919
842 // static 920 // static
843 RenderWidgetHostView* 921 RenderWidgetHostView*
844 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { 922 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) {
845 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); 923 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget);
846 return new RenderWidgetHostViewAndroid(rwhi, NULL); 924 return new RenderWidgetHostViewAndroid(rwhi, NULL);
847 } 925 }
848 926
849 } // namespace content 927 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698