OLD | NEW |
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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 java_helper_(java_helper), | 222 java_helper_(java_helper), |
223 web_contents_(web_contents), | 223 web_contents_(web_contents), |
224 compositor_(NULL), | 224 compositor_(NULL), |
225 is_paused_(false), | 225 is_paused_(false), |
226 view_visible_(false), | 226 view_visible_(false), |
227 window_visible_(false), | 227 window_visible_(false), |
228 attached_to_window_(false), | 228 attached_to_window_(false), |
229 dip_scale_(0.0), | 229 dip_scale_(0.0), |
230 page_scale_factor_(1.0), | 230 page_scale_factor_(1.0), |
231 on_new_picture_enable_(false), | 231 on_new_picture_enable_(false), |
| 232 clear_view_(false), |
232 compositor_needs_continuous_invalidate_(false), | 233 compositor_needs_continuous_invalidate_(false), |
233 block_invalidates_(false), | 234 block_invalidates_(false), |
234 width_(0), | 235 width_(0), |
235 height_(0), | 236 height_(0), |
236 hardware_initialized_(false), | 237 hardware_initialized_(false), |
237 hardware_failed_(false), | 238 hardware_failed_(false), |
238 last_egl_context_(NULL), | 239 last_egl_context_(NULL), |
239 manager_key_(g_view_renderer_manager.Get().NullKey()) { | 240 manager_key_(g_view_renderer_manager.Get().NullKey()) { |
240 CHECK(web_contents_); | 241 CHECK(web_contents_); |
241 web_contents_->SetUserData(kUserDataKey, new UserData(this)); | 242 web_contents_->SetUserData(kUserDataKey, new UserData(this)); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 | 369 |
369 void InProcessViewRenderer::UpdateCachedGlobalVisibleRect() { | 370 void InProcessViewRenderer::UpdateCachedGlobalVisibleRect() { |
370 client_->UpdateGlobalVisibleRect(); | 371 client_->UpdateGlobalVisibleRect(); |
371 } | 372 } |
372 | 373 |
373 bool InProcessViewRenderer::OnDraw(jobject java_canvas, | 374 bool InProcessViewRenderer::OnDraw(jobject java_canvas, |
374 bool is_hardware_canvas, | 375 bool is_hardware_canvas, |
375 const gfx::Vector2d& scroll, | 376 const gfx::Vector2d& scroll, |
376 const gfx::Rect& clip) { | 377 const gfx::Rect& clip) { |
377 scroll_at_start_of_frame_ = scroll; | 378 scroll_at_start_of_frame_ = scroll; |
| 379 if (clear_view_) |
| 380 return false; |
378 if (is_hardware_canvas && attached_to_window_ && HardwareEnabled()) { | 381 if (is_hardware_canvas && attached_to_window_ && HardwareEnabled()) { |
379 // We should be performing a hardware draw here. If we don't have the | 382 // We should be performing a hardware draw here. If we don't have the |
380 // comositor yet or if RequestDrawGL fails, it means we failed this draw and | 383 // comositor yet or if RequestDrawGL fails, it means we failed this draw and |
381 // thus return false here to clear to background color for this draw. | 384 // thus return false here to clear to background color for this draw. |
382 return compositor_ && client_->RequestDrawGL(java_canvas); | 385 return compositor_ && client_->RequestDrawGL(java_canvas); |
383 } | 386 } |
384 // Perform a software draw | 387 // Perform a software draw |
385 return DrawSWInternal(java_canvas, clip); | 388 return DrawSWInternal(java_canvas, clip); |
386 } | 389 } |
387 | 390 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 CompositeSW(rec_canvas); | 623 CompositeSW(rec_canvas); |
621 picture->endRecording(); | 624 picture->endRecording(); |
622 return picture; | 625 return picture; |
623 } | 626 } |
624 | 627 |
625 void InProcessViewRenderer::EnableOnNewPicture(bool enabled) { | 628 void InProcessViewRenderer::EnableOnNewPicture(bool enabled) { |
626 on_new_picture_enable_ = enabled; | 629 on_new_picture_enable_ = enabled; |
627 EnsureContinuousInvalidation(NULL, false); | 630 EnsureContinuousInvalidation(NULL, false); |
628 } | 631 } |
629 | 632 |
| 633 void InProcessViewRenderer::ClearView() { |
| 634 TRACE_EVENT_INSTANT0("android_webview", |
| 635 "InProcessViewRenderer::ClearView", |
| 636 TRACE_EVENT_SCOPE_THREAD); |
| 637 if (clear_view_) |
| 638 return; |
| 639 |
| 640 clear_view_ = true; |
| 641 // Always invalidate ignoring the compositor to actually clear the webview. |
| 642 EnsureContinuousInvalidation(NULL, true); |
| 643 } |
| 644 |
630 void InProcessViewRenderer::SetIsPaused(bool paused) { | 645 void InProcessViewRenderer::SetIsPaused(bool paused) { |
631 TRACE_EVENT_INSTANT1("android_webview", | 646 TRACE_EVENT_INSTANT1("android_webview", |
632 "InProcessViewRenderer::SetIsPaused", | 647 "InProcessViewRenderer::SetIsPaused", |
633 TRACE_EVENT_SCOPE_THREAD, | 648 TRACE_EVENT_SCOPE_THREAD, |
634 "paused", | 649 "paused", |
635 paused); | 650 paused); |
636 is_paused_ = paused; | 651 is_paused_ = paused; |
637 EnsureContinuousInvalidation(NULL, false); | 652 EnsureContinuousInvalidation(NULL, false); |
638 } | 653 } |
639 | 654 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 if (scroll_offset_dip_ == scroll_offset_dip) | 800 if (scroll_offset_dip_ == scroll_offset_dip) |
786 return; | 801 return; |
787 | 802 |
788 scroll_offset_dip_ = scroll_offset_dip; | 803 scroll_offset_dip_ = scroll_offset_dip; |
789 | 804 |
790 if (compositor_) | 805 if (compositor_) |
791 compositor_->DidChangeRootLayerScrollOffset(); | 806 compositor_->DidChangeRootLayerScrollOffset(); |
792 } | 807 } |
793 | 808 |
794 void InProcessViewRenderer::DidUpdateContent() { | 809 void InProcessViewRenderer::DidUpdateContent() { |
| 810 TRACE_EVENT_INSTANT0("android_webview", |
| 811 "InProcessViewRenderer::DidUpdateContent", |
| 812 TRACE_EVENT_SCOPE_THREAD); |
| 813 clear_view_ = false; |
| 814 EnsureContinuousInvalidation(NULL, false); |
795 if (on_new_picture_enable_) | 815 if (on_new_picture_enable_) |
796 client_->OnNewPicture(); | 816 client_->OnNewPicture(); |
797 } | 817 } |
798 | 818 |
799 void InProcessViewRenderer::SetMaxRootLayerScrollOffset( | 819 void InProcessViewRenderer::SetMaxRootLayerScrollOffset( |
800 gfx::Vector2dF new_value_dip) { | 820 gfx::Vector2dF new_value_dip) { |
801 DCHECK_GT(dip_scale_, 0); | 821 DCHECK_GT(dip_scale_, 0); |
802 | 822 |
803 max_scroll_offset_dip_ = new_value_dip; | 823 max_scroll_offset_dip_ = new_value_dip; |
804 DCHECK_LE(0, max_scroll_offset_dip_.x()); | 824 DCHECK_LE(0, max_scroll_offset_dip_.x()); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 | 896 |
877 void InProcessViewRenderer::EnsureContinuousInvalidation( | 897 void InProcessViewRenderer::EnsureContinuousInvalidation( |
878 AwDrawGLInfo* draw_info, | 898 AwDrawGLInfo* draw_info, |
879 bool invalidate_ignore_compositor) { | 899 bool invalidate_ignore_compositor) { |
880 // This method should be called again when any of these conditions change. | 900 // This method should be called again when any of these conditions change. |
881 bool need_invalidate = | 901 bool need_invalidate = |
882 compositor_needs_continuous_invalidate_ || invalidate_ignore_compositor; | 902 compositor_needs_continuous_invalidate_ || invalidate_ignore_compositor; |
883 if (!need_invalidate || block_invalidates_) | 903 if (!need_invalidate || block_invalidates_) |
884 return; | 904 return; |
885 | 905 |
| 906 // Always call view invalidate. We rely the Android framework to ignore the |
| 907 // invalidate when it's not needed such as when view is not visible. |
886 if (draw_info) { | 908 if (draw_info) { |
887 draw_info->dirty_left = cached_global_visible_rect_.x(); | 909 draw_info->dirty_left = cached_global_visible_rect_.x(); |
888 draw_info->dirty_top = cached_global_visible_rect_.y(); | 910 draw_info->dirty_top = cached_global_visible_rect_.y(); |
889 draw_info->dirty_right = cached_global_visible_rect_.right(); | 911 draw_info->dirty_right = cached_global_visible_rect_.right(); |
890 draw_info->dirty_bottom = cached_global_visible_rect_.bottom(); | 912 draw_info->dirty_bottom = cached_global_visible_rect_.bottom(); |
891 draw_info->status_mask |= AwDrawGLInfo::kStatusMaskDraw; | 913 draw_info->status_mask |= AwDrawGLInfo::kStatusMaskDraw; |
892 } else { | 914 } else { |
893 client_->PostInvalidate(); | 915 client_->PostInvalidate(); |
894 } | 916 } |
895 | 917 |
896 bool throttle_fallback_tick = (is_paused_ && !on_new_picture_enable_) || | 918 // Stop fallback ticks when one of these is true. |
897 (attached_to_window_ && !window_visible_); | 919 // 1) Webview is paused. Also need to check we are not in clear view since |
| 920 // paused, offscreen still expect clear view to recover. |
| 921 // 2) If we are attached to window and the window is not visible (eg when |
| 922 // app is in the background). We are sure in this case the webview is used |
| 923 // "on-screen" but that updates are not needed when in the background. |
| 924 bool throttle_fallback_tick = |
| 925 (is_paused_ && !clear_view_) || (attached_to_window_ && !window_visible_); |
898 if (throttle_fallback_tick) | 926 if (throttle_fallback_tick) |
899 return; | 927 return; |
900 | 928 |
901 block_invalidates_ = compositor_needs_continuous_invalidate_; | 929 block_invalidates_ = compositor_needs_continuous_invalidate_; |
902 | 930 |
903 // Unretained here is safe because the callback is cancelled when | 931 // Unretained here is safe because the callback is cancelled when |
904 // |fallback_tick_| is destroyed. | 932 // |fallback_tick_| is destroyed. |
905 fallback_tick_.Reset(base::Bind(&InProcessViewRenderer::FallbackTickFired, | 933 fallback_tick_.Reset(base::Bind(&InProcessViewRenderer::FallbackTickFired, |
906 base::Unretained(this))); | 934 base::Unretained(this))); |
907 | 935 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
970 base::StringAppendF(&str, | 998 base::StringAppendF(&str, |
971 "scroll_at_start_of_frame: %s ", | 999 "scroll_at_start_of_frame: %s ", |
972 scroll_at_start_of_frame_.ToString().c_str()); | 1000 scroll_at_start_of_frame_.ToString().c_str()); |
973 base::StringAppendF( | 1001 base::StringAppendF( |
974 &str, "scroll_offset_dip: %s ", scroll_offset_dip_.ToString().c_str()); | 1002 &str, "scroll_offset_dip: %s ", scroll_offset_dip_.ToString().c_str()); |
975 base::StringAppendF(&str, | 1003 base::StringAppendF(&str, |
976 "overscroll_rounding_error_: %s ", | 1004 "overscroll_rounding_error_: %s ", |
977 overscroll_rounding_error_.ToString().c_str()); | 1005 overscroll_rounding_error_.ToString().c_str()); |
978 base::StringAppendF( | 1006 base::StringAppendF( |
979 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); | 1007 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); |
| 1008 base::StringAppendF(&str, "clear_view: %d ", clear_view_); |
980 if (draw_info) { | 1009 if (draw_info) { |
981 base::StringAppendF(&str, | 1010 base::StringAppendF(&str, |
982 "clip left top right bottom: [%d %d %d %d] ", | 1011 "clip left top right bottom: [%d %d %d %d] ", |
983 draw_info->clip_left, | 1012 draw_info->clip_left, |
984 draw_info->clip_top, | 1013 draw_info->clip_top, |
985 draw_info->clip_right, | 1014 draw_info->clip_right, |
986 draw_info->clip_bottom); | 1015 draw_info->clip_bottom); |
987 base::StringAppendF(&str, | 1016 base::StringAppendF(&str, |
988 "surface width height: [%d %d] ", | 1017 "surface width height: [%d %d] ", |
989 draw_info->width, | 1018 draw_info->width, |
990 draw_info->height); | 1019 draw_info->height); |
991 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); | 1020 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); |
992 } | 1021 } |
993 return str; | 1022 return str; |
994 } | 1023 } |
995 | 1024 |
996 } // namespace android_webview | 1025 } // namespace android_webview |
OLD | NEW |