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

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: Code review. Properly disable animation on loss of focus. 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 animation_vsync_notifications_enabled_(false),
87 renderer_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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 void RenderWidgetHostViewAndroid::Focus() { 287 void RenderWidgetHostViewAndroid::Focus() {
277 host_->Focus(); 288 host_->Focus();
278 host_->SetInputMethodActive(true); 289 host_->SetInputMethodActive(true);
279 } 290 }
280 291
281 void RenderWidgetHostViewAndroid::Blur() { 292 void RenderWidgetHostViewAndroid::Blur() {
282 host_->Send(new ViewMsg_ExecuteEditCommand( 293 host_->Send(new ViewMsg_ExecuteEditCommand(
283 host_->GetRoutingID(), "Unselect", "")); 294 host_->GetRoutingID(), "Unselect", ""));
284 host_->SetInputMethodActive(false); 295 host_->SetInputMethodActive(false);
285 host_->Blur(); 296 host_->Blur();
297
298 if (overscroll_effect_)
299 overscroll_effect_->Finish();
286 } 300 }
287 301
288 bool RenderWidgetHostViewAndroid::HasFocus() const { 302 bool RenderWidgetHostViewAndroid::HasFocus() const {
289 if (!content_view_core_) 303 if (!content_view_core_)
290 return false; // ContentViewCore not created yet. 304 return false; // ContentViewCore not created yet.
291 305
292 return content_view_core_->HasFocus(); 306 return content_view_core_->HasFocus();
293 } 307 }
294 308
295 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { 309 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const {
296 NOTIMPLEMENTED(); 310 NOTIMPLEMENTED();
297 return false; 311 return false;
298 } 312 }
299 313
300 void RenderWidgetHostViewAndroid::Show() { 314 void RenderWidgetHostViewAndroid::Show() {
301 if (is_layer_attached_) 315 if (are_layers_attached_)
302 return; 316 return;
303 317
304 is_layer_attached_ = true; 318 are_layers_attached_ = true;
305 if (content_view_core_) 319 AttachLayers();
306 content_view_core_->AttachLayer(layer_);
307 } 320 }
308 321
309 void RenderWidgetHostViewAndroid::Hide() { 322 void RenderWidgetHostViewAndroid::Hide() {
310 if (!is_layer_attached_) 323 if (!are_layers_attached_)
311 return; 324 return;
312 325
313 is_layer_attached_ = false; 326 are_layers_attached_ = false;
314 if (content_view_core_) 327 RemoveLayers();
315 content_view_core_->RemoveLayer(layer_);
316 } 328 }
317 329
318 bool RenderWidgetHostViewAndroid::IsShowing() { 330 bool RenderWidgetHostViewAndroid::IsShowing() {
319 // ContentViewCoreImpl represents the native side of the Java 331 // ContentViewCoreImpl represents the native side of the Java
320 // ContentViewCore. It being NULL means that it is not attached 332 // ContentViewCore. It being NULL means that it is not attached
321 // to the View system yet, so we treat this RWHVA as hidden. 333 // to the View system yet, so we treat this RWHVA as hidden.
322 return is_layer_attached_ && content_view_core_; 334 return are_layers_attached_ && content_view_core_;
323 } 335 }
324 336
325 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { 337 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const {
326 if (!content_view_core_) 338 if (!content_view_core_)
327 return gfx::Rect(); 339 return gfx::Rect();
328 340
329 // If the backing hasn't been initialized yet, report empty view bounds 341 // 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 342 // as well. Otherwise, we may end up stuck in a white-screen state because
331 // the resize ack is sent after swapbuffers. 343 // the resize ack is sent after swapbuffers.
332 if (GetPhysicalBackingSize().IsEmpty()) 344 if (GetPhysicalBackingSize().IsEmpty())
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 SkColor color) { 400 SkColor color) {
389 if (cached_background_color_ == color) 401 if (cached_background_color_ == color)
390 return; 402 return;
391 403
392 cached_background_color_ = color; 404 cached_background_color_ = color;
393 if (content_view_core_) 405 if (content_view_core_)
394 content_view_core_->OnBackgroundColorChanged(color); 406 content_view_core_->OnBackgroundColorChanged(color);
395 } 407 }
396 408
397 void RenderWidgetHostViewAndroid::SendVSync(base::TimeTicks frame_time) { 409 void RenderWidgetHostViewAndroid::SendVSync(base::TimeTicks frame_time) {
398 host_->Send(new ViewMsg_DidVSync(host_->GetRoutingID(), frame_time)); 410 if (renderer_vsync_notifications_enabled_)
411 host_->Send(new ViewMsg_DidVSync(host_->GetRoutingID(), frame_time));
412 if (animation_vsync_notifications_enabled_)
413 Animate();
399 } 414 }
400 415
401 void RenderWidgetHostViewAndroid::OnSetVSyncNotificationEnabled(bool enabled) { 416 void RenderWidgetHostViewAndroid::OnSetVSyncNotificationEnabled(bool enabled) {
402 if (content_view_core_) 417 renderer_vsync_notifications_enabled_ = enabled;
403 content_view_core_->SetVSyncNotificationEnabled(enabled); 418 RequestVSyncNotificationsIfNecessary();
419 }
420
421 void RenderWidgetHostViewAndroid::RequestVSyncNotificationsIfNecessary() {
422 bool notifications_enabled = animation_vsync_notifications_enabled_ ||
423 renderer_vsync_notifications_enabled_;
424 if (notifications_enabled != vsync_notifications_enabled_) {
425 if (content_view_core_)
426 content_view_core_->SetVSyncNotificationEnabled(notifications_enabled);
427 vsync_notifications_enabled_ = notifications_enabled;
428 }
404 } 429 }
405 430
406 void RenderWidgetHostViewAndroid::OnStartContentIntent( 431 void RenderWidgetHostViewAndroid::OnStartContentIntent(
407 const GURL& content_url) { 432 const GURL& content_url) {
408 if (content_view_core_) 433 if (content_view_core_)
409 content_view_core_->StartContentIntent(content_url); 434 content_view_core_->StartContentIntent(content_url);
410 } 435 }
411 436
412 void RenderWidgetHostViewAndroid::ImeCancelComposition() { 437 void RenderWidgetHostViewAndroid::ImeCancelComposition() {
413 ime_adapter_android_.CancelComposition(); 438 ime_adapter_android_.CancelComposition();
(...skipping 10 matching lines...) Expand all
424 const std::vector<gfx::Rect>& copy_rects) { 449 const std::vector<gfx::Rect>& copy_rects) {
425 NOTIMPLEMENTED(); 450 NOTIMPLEMENTED();
426 } 451 }
427 452
428 void RenderWidgetHostViewAndroid::RenderViewGone( 453 void RenderWidgetHostViewAndroid::RenderViewGone(
429 base::TerminationStatus status, int error_code) { 454 base::TerminationStatus status, int error_code) {
430 Destroy(); 455 Destroy();
431 } 456 }
432 457
433 void RenderWidgetHostViewAndroid::Destroy() { 458 void RenderWidgetHostViewAndroid::Destroy() {
434 if (content_view_core_) { 459 RemoveLayers();
435 content_view_core_->RemoveLayer(layer_); 460 content_view_core_ = NULL;
436 content_view_core_ = NULL;
437 }
438 461
439 // The RenderWidgetHost's destruction led here, so don't call it. 462 // The RenderWidgetHost's destruction led here, so don't call it.
440 host_ = NULL; 463 host_ = NULL;
441 464
442 delete this; 465 delete this;
443 } 466 }
444 467
445 void RenderWidgetHostViewAndroid::SetTooltipText( 468 void RenderWidgetHostViewAndroid::SetTooltipText(
446 const string16& tooltip_text) { 469 const string16& tooltip_text) {
447 // Tooltips don't makes sense on Android. 470 // 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) 581 if (texture_size.GetArea() > 0)
559 offset = frame->metadata.location_bar_content_translation; 582 offset = frame->metadata.location_bar_content_translation;
560 offset.set_y(offset.y() + frame->metadata.overdraw_bottom_height); 583 offset.set_y(offset.y() + frame->metadata.overdraw_bottom_height);
561 gfx::SizeF content_size(texture_size.width() - offset.x() * dp2px, 584 gfx::SizeF content_size(texture_size.width() - offset.x() * dp2px,
562 texture_size.height() - offset.y() * dp2px); 585 texture_size.height() - offset.y() * dp2px);
563 BuffersSwapped(frame->gl_frame_data->mailbox, 586 BuffersSwapped(frame->gl_frame_data->mailbox,
564 texture_size, 587 texture_size,
565 content_size, 588 content_size,
566 callback); 589 callback);
567 590
591 if (overscroll_effect_) {
592 // Disable edge effects for axes on which scrolling is impossible.
593 const cc::CompositorFrameMetadata& metadata = frame->metadata;
594 overscroll_effect_->set_horizontal_overscroll_enabled(
595 metadata.root_layer_size.width() != metadata.viewport_size.width());
596 overscroll_effect_->set_vertical_overscroll_enabled(
597 metadata.root_layer_size.height() != metadata.viewport_size.height());
598 overscroll_effect_->set_size(content_size);
599 }
568 } 600 }
569 601
570 void RenderWidgetHostViewAndroid::AcceleratedSurfaceBuffersSwapped( 602 void RenderWidgetHostViewAndroid::AcceleratedSurfaceBuffersSwapped(
571 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, 603 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
572 int gpu_host_id) { 604 int gpu_host_id) {
573 NOTREACHED() << "Deprecated. Use --composite-to-mailbox."; 605 NOTREACHED() << "Deprecated. Use --composite-to-mailbox.";
574 606
575 if (params.mailbox_name.empty()) 607 if (params.mailbox_name.empty())
576 return; 608 return;
577 609
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 current_mailbox_ = mailbox; 667 current_mailbox_ = mailbox;
636 668
637 if (consumed_current_texture_ || host_->is_hidden()) 669 if (consumed_current_texture_ || host_->is_hidden())
638 ack_callback.Run(); 670 ack_callback.Run();
639 else 671 else
640 ack_callbacks_.push(ack_callback); 672 ack_callbacks_.push(ack_callback);
641 673
642 consumed_current_texture_ = false; 674 consumed_current_texture_ = false;
643 } 675 }
644 676
677 void RenderWidgetHostViewAndroid::AttachLayers() {
678 if (!content_view_core_)
679 return;
680
681 content_view_core_->AttachLayer(layer_);
682
683 if (overscroll_effect_)
684 overscroll_effect_->set_parent_layer(content_view_core_->GetLayer());
685 }
686
687 void RenderWidgetHostViewAndroid::RemoveLayers() {
688 if (!content_view_core_)
689 return;
690
691 if (overscroll_effect_)
692 overscroll_effect_->set_parent_layer(NULL);
693
694 content_view_core_->RemoveLayer(layer_);
695 }
696
697 void RenderWidgetHostViewAndroid::Animate() {
698 if (!overscroll_effect_)
699 return;
700 overscroll_effect_->Animate(base::TimeTicks::Now());
701 ScheduleAnimation();
702 }
703
704 void RenderWidgetHostViewAndroid::ScheduleAnimation() {
705 animation_vsync_notifications_enabled_ = overscroll_effect_ &&
706 overscroll_effect_->IsAnimating() &&
707 HasFocus();
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