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

Side by Side Diff: android_webview/browser/in_process_view_renderer.cc

Issue 23533051: [android_webview] Use a fraction to calculate scroll offset. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: get rid of NaNs Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "android_webview/browser/in_process_view_renderer.h" 5 #include "android_webview/browser/in_process_view_renderer.h"
6 6
7 #include <android/bitmap.h> 7 #include <android/bitmap.h>
8 8
9 #include "android_webview/browser/aw_gl_surface.h" 9 #include "android_webview/browser/aw_gl_surface.h"
10 #include "android_webview/browser/scoped_app_gl_state_restore.h" 10 #include "android_webview/browser/scoped_app_gl_state_restore.h"
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 TRACE_EVENT0("android_webview", "InProcessViewRenderer::CapturePicture"); 561 TRACE_EVENT0("android_webview", "InProcessViewRenderer::CapturePicture");
562 562
563 // Return empty Picture objects for empty SkPictures. 563 // Return empty Picture objects for empty SkPictures.
564 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture); 564 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture);
565 if (width <= 0 || height <= 0) { 565 if (width <= 0 || height <= 0) {
566 return picture; 566 return picture;
567 } 567 }
568 568
569 // Reset scroll back to the origin, will go back to the old 569 // Reset scroll back to the origin, will go back to the old
570 // value when scroll_reset is out of scope. 570 // value when scroll_reset is out of scope.
571 base::AutoReset<gfx::Vector2dF> scroll_reset(&scroll_offset_css_, 571 base::AutoReset<gfx::Vector2dF> scroll_reset(&scroll_offset_dip_,
572 gfx::Vector2d()); 572 gfx::Vector2d());
573 573
574 SkCanvas* rec_canvas = picture->beginRecording(width, height, 0); 574 SkCanvas* rec_canvas = picture->beginRecording(width, height, 0);
575 if (compositor_) 575 if (compositor_)
576 CompositeSW(rec_canvas); 576 CompositeSW(rec_canvas);
577 picture->endRecording(); 577 picture->endRecording();
578 return picture; 578 return picture;
579 } 579 }
580 580
581 void InProcessViewRenderer::EnableOnNewPicture(bool enabled) { 581 void InProcessViewRenderer::EnableOnNewPicture(bool enabled) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 void InProcessViewRenderer::SetDipScale(float dip_scale) { 708 void InProcessViewRenderer::SetDipScale(float dip_scale) {
709 dip_scale_ = dip_scale; 709 dip_scale_ = dip_scale;
710 CHECK(dip_scale_ > 0); 710 CHECK(dip_scale_ > 0);
711 } 711 }
712 712
713 void InProcessViewRenderer::SetPageScaleFactor(float page_scale_factor) { 713 void InProcessViewRenderer::SetPageScaleFactor(float page_scale_factor) {
714 page_scale_factor_ = page_scale_factor; 714 page_scale_factor_ = page_scale_factor;
715 CHECK(page_scale_factor_ > 0); 715 CHECK(page_scale_factor_ > 0);
716 } 716 }
717 717
718 void InProcessViewRenderer::ScrollTo(gfx::Vector2d new_value) { 718 gfx::Vector2d InProcessViewRenderer::max_scroll_offset() const {
719 DCHECK(dip_scale_ > 0); 719 DCHECK(dip_scale_ > 0);
720 // In general we don't guarantee that the scroll offset transforms are 720 return gfx::ToRoundedVector2d(gfx::ScaleVector2d(
aelias_OOO_until_Jul13 2013/09/24 22:03:19 Is there a reason why you're using Rounded and not
mkosiba (inactive) 2013/09/24 23:18:53 no, there was no particular reason. I assumed the
721 // symmetrical. That is if scrolling from JS to offset1 results in a native 721 max_scroll_offset_dip_, dip_scale_ * page_scale_factor_));
722 // offset2 then scrolling from UI to offset2 results in JS being scrolled to 722 }
723 // offset1 again.
724 // The reason we explicitly do rounding here is that it seems to yeld the
725 // most stabile transformation.
726 gfx::Vector2dF new_value_css = gfx::ToRoundedVector2d(
727 gfx::ScaleVector2d(new_value, 1.0f / (dip_scale_ * page_scale_factor_)));
728 723
729 // It's possible that more than one set of unique physical coordinates maps 724 void InProcessViewRenderer::ScrollTo(gfx::Vector2d scroll_offset) {
730 // to the same set of CSS coordinates which means we can't reliably early-out 725 gfx::Vector2d max_offset = max_scroll_offset();
731 // earlier in the call stack. 726 gfx::Vector2dF scroll_offset_dip;
732 if (scroll_offset_css_ == new_value_css) 727 if (max_offset.x()) {
728 scroll_offset_dip.set_x((scroll_offset.x() * max_scroll_offset_dip_.x()) /
729 max_offset.x());
730 }
731 if (max_offset.y()) {
732 scroll_offset_dip.set_y((scroll_offset.y() * max_scroll_offset_dip_.y()) /
733 max_offset.y());
mkosiba (inactive) 2013/09/24 18:43:05 I could alternatively write these as gfx::Vecto
aelias_OOO_until_Jul13 2013/09/24 22:03:19 The current way is fine. Could you add a comment
734 }
735
736 DCHECK(0 <= scroll_offset_dip.x());
aelias_OOO_until_Jul13 2013/09/24 22:03:19 Use DCHECK_LE instead. That gives more informativ
mkosiba (inactive) 2013/09/25 14:23:49 Done.
737 DCHECK(0 <= scroll_offset_dip.y());
738 DCHECK(scroll_offset_dip.x() <= max_scroll_offset_dip_.x());
739 DCHECK(scroll_offset_dip.y() <= max_scroll_offset_dip_.y());
740
741 if (scroll_offset_dip_ == scroll_offset_dip)
733 return; 742 return;
734 743
735 scroll_offset_css_ = new_value_css; 744 scroll_offset_dip_ = scroll_offset_dip;
736 745
737 if (compositor_) 746 if (compositor_)
738 compositor_->DidChangeRootLayerScrollOffset(); 747 compositor_->DidChangeRootLayerScrollOffset();
739 } 748 }
740 749
741 void InProcessViewRenderer::DidUpdateContent() { 750 void InProcessViewRenderer::DidUpdateContent() {
742 if (on_new_picture_enable_) 751 if (on_new_picture_enable_)
743 client_->OnNewPicture(); 752 client_->OnNewPicture();
744 } 753 }
745 754
755 void InProcessViewRenderer::SetMaxRootLayerScrollOffset(
756 gfx::Vector2dF new_value_dip) {
757 DCHECK(dip_scale_ > 0);
758
759 max_scroll_offset_dip_ = new_value_dip;
760 DCHECK(max_scroll_offset_dip_.x() >= 0);
761 DCHECK(max_scroll_offset_dip_.y() >= 0);
762
763 client_->SetMaxContainerViewScrollOffset(max_scroll_offset());
764 }
765
746 void InProcessViewRenderer::SetTotalRootLayerScrollOffset( 766 void InProcessViewRenderer::SetTotalRootLayerScrollOffset(
747 gfx::Vector2dF new_value_css) { 767 gfx::Vector2dF scroll_offset_dip) {
748 // TOOD(mkosiba): Add a DCHECK to say that this does _not_ get called during 768 // TOOD(mkosiba): Add a DCHECK to say that this does _not_ get called during
749 // DrawGl when http://crbug.com/249972 is fixed. 769 // DrawGl when http://crbug.com/249972 is fixed.
750 if (scroll_offset_css_ == new_value_css) 770 if (scroll_offset_dip_ == scroll_offset_dip)
751 return; 771 return;
752 772
753 scroll_offset_css_ = new_value_css; 773 scroll_offset_dip_ = scroll_offset_dip;
754 774
755 DCHECK(dip_scale_ > 0); 775 gfx::Vector2d max_offset = max_scroll_offset();
756 DCHECK(page_scale_factor_ > 0); 776 gfx::Vector2d scroll_offset;
777 if (max_scroll_offset_dip_.x()) {
778 scroll_offset.set_x((scroll_offset_dip.x() * max_offset.x()) /
779 max_scroll_offset_dip_.x());
780 }
757 781
758 gfx::Vector2d scroll_offset = gfx::ToRoundedVector2d( 782 if (max_scroll_offset_dip_.y()) {
759 gfx::ScaleVector2d(new_value_css, dip_scale_ * page_scale_factor_)); 783 scroll_offset.set_y((scroll_offset_dip.y() * max_offset.y()) /
784 max_scroll_offset_dip_.y());
785 }
786
787 DCHECK(0 <= scroll_offset.x());
788 DCHECK(0 <= scroll_offset.y());
789 DCHECK(scroll_offset.x() <= max_offset.x());
790 DCHECK(scroll_offset.y() <= max_offset.y());
760 791
761 client_->ScrollContainerViewTo(scroll_offset); 792 client_->ScrollContainerViewTo(scroll_offset);
762 } 793 }
763 794
764 gfx::Vector2dF InProcessViewRenderer::GetTotalRootLayerScrollOffset() { 795 gfx::Vector2dF InProcessViewRenderer::GetTotalRootLayerScrollOffset() {
765 return scroll_offset_css_; 796 return scroll_offset_dip_;
766 } 797 }
767 798
768 void InProcessViewRenderer::DidOverscroll( 799 void InProcessViewRenderer::DidOverscroll(
769 gfx::Vector2dF accumulated_overscroll, 800 gfx::Vector2dF accumulated_overscroll,
770 gfx::Vector2dF latest_overscroll_delta, 801 gfx::Vector2dF latest_overscroll_delta,
771 gfx::Vector2dF current_fling_velocity) { 802 gfx::Vector2dF current_fling_velocity) {
772 DCHECK(current_fling_velocity.IsZero()); 803 DCHECK(current_fling_velocity.IsZero());
773 const float physical_pixel_scale = dip_scale_ * page_scale_factor_; 804 const float physical_pixel_scale = dip_scale_ * page_scale_factor_;
774 if (accumulated_overscroll == latest_overscroll_delta) 805 if (accumulated_overscroll == latest_overscroll_delta)
775 overscroll_rounding_error_ = gfx::Vector2dF(); 806 overscroll_rounding_error_ = gfx::Vector2dF();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 base::StringAppendF(&str, "attached_to_window: %d ", attached_to_window_); 892 base::StringAppendF(&str, "attached_to_window: %d ", attached_to_window_);
862 base::StringAppendF(&str, "hardware_initialized: %d ", hardware_initialized_); 893 base::StringAppendF(&str, "hardware_initialized: %d ", hardware_initialized_);
863 base::StringAppendF(&str, "hardware_failed: %d ", hardware_failed_); 894 base::StringAppendF(&str, "hardware_failed: %d ", hardware_failed_);
864 base::StringAppendF(&str, 895 base::StringAppendF(&str,
865 "global visible rect: %s ", 896 "global visible rect: %s ",
866 cached_global_visible_rect_.ToString().c_str()); 897 cached_global_visible_rect_.ToString().c_str());
867 base::StringAppendF(&str, 898 base::StringAppendF(&str,
868 "scroll_at_start_of_frame: %s ", 899 "scroll_at_start_of_frame: %s ",
869 scroll_at_start_of_frame_.ToString().c_str()); 900 scroll_at_start_of_frame_.ToString().c_str());
870 base::StringAppendF( 901 base::StringAppendF(
871 &str, "scroll_offset_css: %s ", scroll_offset_css_.ToString().c_str()); 902 &str, "scroll_offset_dip: %s ", scroll_offset_dip_.ToString().c_str());
872 base::StringAppendF(&str, 903 base::StringAppendF(&str,
873 "overscroll_rounding_error_: %s ", 904 "overscroll_rounding_error_: %s ",
874 overscroll_rounding_error_.ToString().c_str()); 905 overscroll_rounding_error_.ToString().c_str());
875 if (draw_info) { 906 if (draw_info) {
876 base::StringAppendF(&str, 907 base::StringAppendF(&str,
877 "clip left top right bottom: [%d %d %d %d] ", 908 "clip left top right bottom: [%d %d %d %d] ",
878 draw_info->clip_left, 909 draw_info->clip_left,
879 draw_info->clip_top, 910 draw_info->clip_top,
880 draw_info->clip_right, 911 draw_info->clip_right,
881 draw_info->clip_bottom); 912 draw_info->clip_bottom);
882 base::StringAppendF(&str, 913 base::StringAppendF(&str,
883 "surface width height: [%d %d] ", 914 "surface width height: [%d %d] ",
884 draw_info->width, 915 draw_info->width,
885 draw_info->height); 916 draw_info->height);
886 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); 917 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer);
887 } 918 }
888 return str; 919 return str;
889 } 920 }
890 921
891 } // namespace android_webview 922 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698