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

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: Created 7 years, 2 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 invalidate); 703 invalidate);
704 compositor_needs_continuous_invalidate_ = invalidate; 704 compositor_needs_continuous_invalidate_ = invalidate;
705 EnsureContinuousInvalidation(NULL, false); 705 EnsureContinuousInvalidation(NULL, false);
706 } 706 }
707 707
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 gfx::Vector2d InProcessViewRenderer::max_scroll_offset() const {
714 page_scale_factor_ = page_scale_factor; 714 DCHECK(dip_scale_ > 0);
bulach 2013/09/25 15:26:05 nit: DCHECK_GT
mkosiba (inactive) 2013/09/25 16:14:15 Done.
715 CHECK(page_scale_factor_ > 0); 715 return gfx::ToCeiledVector2d(gfx::ScaleVector2d(
716 max_scroll_offset_dip_, dip_scale_ * page_scale_factor_));
716 } 717 }
717 718
718 void InProcessViewRenderer::ScrollTo(gfx::Vector2d new_value) { 719 void InProcessViewRenderer::ScrollTo(gfx::Vector2d scroll_offset) {
719 DCHECK(dip_scale_ > 0); 720 gfx::Vector2d max_offset = max_scroll_offset();
720 // In general we don't guarantee that the scroll offset transforms are 721 gfx::Vector2dF scroll_offset_dip;
721 // symmetrical. That is if scrolling from JS to offset1 results in a native 722 // To preserve the invariant that scrolling to the maximum physical pixel
722 // offset2 then scrolling from UI to offset2 results in JS being scrolled to 723 // value also scrolls to the maximum dip pixel value we transform the physical
723 // offset1 again. 724 // offset into the dip offset by using a proportion (instead of dividing by
724 // The reason we explicitly do rounding here is that it seems to yeld the 725 // dip_scale * page_scale_factor).
725 // most stabile transformation. 726 if (max_offset.x()) {
726 gfx::Vector2dF new_value_css = gfx::ToRoundedVector2d( 727 scroll_offset_dip.set_x((scroll_offset.x() * max_scroll_offset_dip_.x()) /
727 gfx::ScaleVector2d(new_value, 1.0f / (dip_scale_ * page_scale_factor_))); 728 max_offset.x());
729 }
730 if (max_offset.y()) {
731 scroll_offset_dip.set_y((scroll_offset.y() * max_scroll_offset_dip_.y()) /
732 max_offset.y());
733 }
728 734
729 // It's possible that more than one set of unique physical coordinates maps 735 DCHECK_LE(0, scroll_offset_dip.x());
730 // to the same set of CSS coordinates which means we can't reliably early-out 736 DCHECK_LE(0, scroll_offset_dip.y());
731 // earlier in the call stack. 737 DCHECK_LE(scroll_offset_dip.x(), max_scroll_offset_dip_.x());
732 if (scroll_offset_css_ == new_value_css) 738 DCHECK_LE(scroll_offset_dip.y(), max_scroll_offset_dip_.y());
739
740 if (scroll_offset_dip_ == scroll_offset_dip)
733 return; 741 return;
734 742
735 scroll_offset_css_ = new_value_css; 743 scroll_offset_dip_ = scroll_offset_dip;
736 744
737 if (compositor_) 745 if (compositor_)
738 compositor_->DidChangeRootLayerScrollOffset(); 746 compositor_->DidChangeRootLayerScrollOffset();
739 } 747 }
740 748
741 void InProcessViewRenderer::DidUpdateContent() { 749 void InProcessViewRenderer::DidUpdateContent() {
742 if (on_new_picture_enable_) 750 if (on_new_picture_enable_)
743 client_->OnNewPicture(); 751 client_->OnNewPicture();
744 } 752 }
745 753
754 void InProcessViewRenderer::SetMaxRootLayerScrollOffset(
755 gfx::Vector2dF new_value_dip) {
756 DCHECK(dip_scale_ > 0);
bulach 2013/09/25 15:26:05 nit: DCHECK_GT
mkosiba (inactive) 2013/09/25 16:14:15 Done.
757
758 max_scroll_offset_dip_ = new_value_dip;
759 DCHECK_LE(0, max_scroll_offset_dip_.x());
760 DCHECK_LE(0, max_scroll_offset_dip_.y());
761
762 client_->SetMaxContainerViewScrollOffset(max_scroll_offset());
763 }
764
746 void InProcessViewRenderer::SetTotalRootLayerScrollOffset( 765 void InProcessViewRenderer::SetTotalRootLayerScrollOffset(
747 gfx::Vector2dF new_value_css) { 766 gfx::Vector2dF scroll_offset_dip) {
748 // TOOD(mkosiba): Add a DCHECK to say that this does _not_ get called during 767 // TOOD(mkosiba): Add a DCHECK to say that this does _not_ get called during
749 // DrawGl when http://crbug.com/249972 is fixed. 768 // DrawGl when http://crbug.com/249972 is fixed.
750 if (scroll_offset_css_ == new_value_css) 769 if (scroll_offset_dip_ == scroll_offset_dip)
751 return; 770 return;
752 771
753 scroll_offset_css_ = new_value_css; 772 scroll_offset_dip_ = scroll_offset_dip;
754 773
755 DCHECK(dip_scale_ > 0); 774 gfx::Vector2d max_offset = max_scroll_offset();
756 DCHECK(page_scale_factor_ > 0); 775 gfx::Vector2d scroll_offset;
776 // For an explanation as to why this is done this way see the comment in
777 // InProcessViewRenderer::ScrollTo.
778 if (max_scroll_offset_dip_.x()) {
779 scroll_offset.set_x((scroll_offset_dip.x() * max_offset.x()) /
780 max_scroll_offset_dip_.x());
781 }
757 782
758 gfx::Vector2d scroll_offset = gfx::ToRoundedVector2d( 783 if (max_scroll_offset_dip_.y()) {
759 gfx::ScaleVector2d(new_value_css, dip_scale_ * page_scale_factor_)); 784 scroll_offset.set_y((scroll_offset_dip.y() * max_offset.y()) /
785 max_scroll_offset_dip_.y());
786 }
787
788 DCHECK(0 <= scroll_offset.x());
789 DCHECK(0 <= scroll_offset.y());
bulach 2013/09/25 15:26:05 nit: here and adbove, DCHECK_LE
mkosiba (inactive) 2013/09/25 16:14:15 Done.
790 DCHECK(scroll_offset.x() <= max_offset.x());
791 DCHECK(scroll_offset.y() <= max_offset.y());
760 792
761 client_->ScrollContainerViewTo(scroll_offset); 793 client_->ScrollContainerViewTo(scroll_offset);
762 } 794 }
763 795
764 gfx::Vector2dF InProcessViewRenderer::GetTotalRootLayerScrollOffset() { 796 gfx::Vector2dF InProcessViewRenderer::GetTotalRootLayerScrollOffset() {
765 return scroll_offset_css_; 797 return scroll_offset_dip_;
798 }
799
800 void InProcessViewRenderer::SetRootLayerPageScaleFactor(
801 float page_scale_factor) {
802 page_scale_factor_ = page_scale_factor;
803 CHECK(page_scale_factor_ > 0);
joth 2013/09/25 15:12:07 DCHECk
bulach 2013/09/25 15:26:05 DCHECK_GT :)
mkosiba (inactive) 2013/09/25 16:14:15 Done.
804 client_->SetPageScaleFactor(page_scale_factor);
805 }
806
807 void InProcessViewRenderer::SetRootLayerScrollableSize(
808 gfx::SizeF scrollable_size) {
809 client_->SetContentsSize(scrollable_size);
766 } 810 }
767 811
768 void InProcessViewRenderer::DidOverscroll( 812 void InProcessViewRenderer::DidOverscroll(
769 gfx::Vector2dF accumulated_overscroll, 813 gfx::Vector2dF accumulated_overscroll,
770 gfx::Vector2dF latest_overscroll_delta, 814 gfx::Vector2dF latest_overscroll_delta,
771 gfx::Vector2dF current_fling_velocity) { 815 gfx::Vector2dF current_fling_velocity) {
772 DCHECK(current_fling_velocity.IsZero()); 816 DCHECK(current_fling_velocity.IsZero());
773 const float physical_pixel_scale = dip_scale_ * page_scale_factor_; 817 const float physical_pixel_scale = dip_scale_ * page_scale_factor_;
774 if (accumulated_overscroll == latest_overscroll_delta) 818 if (accumulated_overscroll == latest_overscroll_delta)
775 overscroll_rounding_error_ = gfx::Vector2dF(); 819 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_); 905 base::StringAppendF(&str, "attached_to_window: %d ", attached_to_window_);
862 base::StringAppendF(&str, "hardware_initialized: %d ", hardware_initialized_); 906 base::StringAppendF(&str, "hardware_initialized: %d ", hardware_initialized_);
863 base::StringAppendF(&str, "hardware_failed: %d ", hardware_failed_); 907 base::StringAppendF(&str, "hardware_failed: %d ", hardware_failed_);
864 base::StringAppendF(&str, 908 base::StringAppendF(&str,
865 "global visible rect: %s ", 909 "global visible rect: %s ",
866 cached_global_visible_rect_.ToString().c_str()); 910 cached_global_visible_rect_.ToString().c_str());
867 base::StringAppendF(&str, 911 base::StringAppendF(&str,
868 "scroll_at_start_of_frame: %s ", 912 "scroll_at_start_of_frame: %s ",
869 scroll_at_start_of_frame_.ToString().c_str()); 913 scroll_at_start_of_frame_.ToString().c_str());
870 base::StringAppendF( 914 base::StringAppendF(
871 &str, "scroll_offset_css: %s ", scroll_offset_css_.ToString().c_str()); 915 &str, "scroll_offset_dip: %s ", scroll_offset_dip_.ToString().c_str());
872 base::StringAppendF(&str, 916 base::StringAppendF(&str,
873 "overscroll_rounding_error_: %s ", 917 "overscroll_rounding_error_: %s ",
874 overscroll_rounding_error_.ToString().c_str()); 918 overscroll_rounding_error_.ToString().c_str());
875 if (draw_info) { 919 if (draw_info) {
876 base::StringAppendF(&str, 920 base::StringAppendF(&str,
877 "clip left top right bottom: [%d %d %d %d] ", 921 "clip left top right bottom: [%d %d %d %d] ",
878 draw_info->clip_left, 922 draw_info->clip_left,
879 draw_info->clip_top, 923 draw_info->clip_top,
880 draw_info->clip_right, 924 draw_info->clip_right,
881 draw_info->clip_bottom); 925 draw_info->clip_bottom);
882 base::StringAppendF(&str, 926 base::StringAppendF(&str,
883 "surface width height: [%d %d] ", 927 "surface width height: [%d %d] ",
884 draw_info->width, 928 draw_info->width,
885 draw_info->height); 929 draw_info->height);
886 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); 930 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer);
887 } 931 }
888 return str; 932 return str;
889 } 933 }
890 934
891 } // namespace android_webview 935 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698