| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser_view_renderer.h" | 5 #include "android_webview/browser/browser_view_renderer.h" |
| 6 | 6 |
| 7 #include "android_webview/browser/browser_view_renderer_client.h" | 7 #include "android_webview/browser/browser_view_renderer_client.h" |
| 8 #include "android_webview/browser/shared_renderer_state.h" | 8 #include "android_webview/browser/shared_renderer_state.h" |
| 9 #include "android_webview/common/aw_switches.h" | 9 #include "android_webview/common/aw_switches.h" |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 is_paused_(false), | 78 is_paused_(false), |
| 79 view_visible_(false), | 79 view_visible_(false), |
| 80 window_visible_(false), | 80 window_visible_(false), |
| 81 attached_to_window_(false), | 81 attached_to_window_(false), |
| 82 hardware_enabled_(false), | 82 hardware_enabled_(false), |
| 83 dip_scale_(0.0), | 83 dip_scale_(0.0), |
| 84 page_scale_factor_(1.0), | 84 page_scale_factor_(1.0), |
| 85 on_new_picture_enable_(false), | 85 on_new_picture_enable_(false), |
| 86 clear_view_(false), | 86 clear_view_(false), |
| 87 compositor_needs_continuous_invalidate_(false), | 87 compositor_needs_continuous_invalidate_(false), |
| 88 invalidate_after_composite_(false), |
| 88 block_invalidates_(false), | 89 block_invalidates_(false), |
| 89 fallback_tick_pending_(false), | 90 fallback_tick_pending_(false), |
| 90 width_(0), | 91 width_(0), |
| 91 height_(0) { | 92 height_(0) { |
| 92 CHECK(web_contents_); | 93 CHECK(web_contents_); |
| 93 content::SynchronousCompositor::SetClientForWebContents(web_contents_, this); | 94 content::SynchronousCompositor::SetClientForWebContents(web_contents_, this); |
| 94 | 95 |
| 95 // Currently the logic in this class relies on |compositor_| remaining | 96 // Currently the logic in this class relies on |compositor_| remaining |
| 96 // NULL until the DidInitializeCompositor() call, hence it is not set here. | 97 // NULL until the DidInitializeCompositor() call, hence it is not set here. |
| 97 } | 98 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 // Perform a software draw | 202 // Perform a software draw |
| 202 return OnDrawSoftware(java_canvas); | 203 return OnDrawSoftware(java_canvas); |
| 203 } | 204 } |
| 204 | 205 |
| 205 bool BrowserViewRenderer::OnDrawHardware(jobject java_canvas) { | 206 bool BrowserViewRenderer::OnDrawHardware(jobject java_canvas) { |
| 206 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware"); | 207 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware"); |
| 207 if (!compositor_) | 208 if (!compositor_) |
| 208 return false; | 209 return false; |
| 209 | 210 |
| 210 shared_renderer_state_->SetScrollOffset(last_on_draw_scroll_offset_); | 211 shared_renderer_state_->SetScrollOffset(last_on_draw_scroll_offset_); |
| 211 if (last_on_draw_global_visible_rect_.IsEmpty()) { | |
| 212 TRACE_EVENT_INSTANT0("android_webview", | |
| 213 "EarlyOut_EmptyVisibleRect", | |
| 214 TRACE_EVENT_SCOPE_THREAD); | |
| 215 shared_renderer_state_->SetForceInvalidateOnNextDrawGL(true); | |
| 216 return client_->RequestDrawGL(java_canvas, false); | |
| 217 } | |
| 218 | 212 |
| 219 if (!hardware_enabled_) { | 213 if (!hardware_enabled_) { |
| 220 hardware_enabled_ = compositor_->InitializeHwDraw(); | 214 hardware_enabled_ = compositor_->InitializeHwDraw(); |
| 221 if (hardware_enabled_) { | 215 if (hardware_enabled_) { |
| 222 tile_manager_key_ = GlobalTileManager::GetInstance()->PushBack(this); | 216 tile_manager_key_ = GlobalTileManager::GetInstance()->PushBack(this); |
| 223 } | 217 } |
| 224 } | 218 } |
| 225 if (!hardware_enabled_) | 219 if (!hardware_enabled_) |
| 226 return false; | 220 return false; |
| 227 | 221 |
| 222 if (last_on_draw_global_visible_rect_.IsEmpty() && |
| 223 !parent_draw_constraints_.surface_rect.IsEmpty()) { |
| 224 TRACE_EVENT_INSTANT0("android_webview", |
| 225 "EarlyOut_EmptyVisibleRect", |
| 226 TRACE_EVENT_SCOPE_THREAD); |
| 227 shared_renderer_state_->SetForceInvalidateOnNextDrawGL(true); |
| 228 return client_->RequestDrawGL(java_canvas, false); |
| 229 } |
| 230 |
| 228 ReturnResourceFromParent(); | 231 ReturnResourceFromParent(); |
| 229 if (shared_renderer_state_->HasCompositorFrame()) { | 232 if (shared_renderer_state_->HasCompositorFrame()) { |
| 230 TRACE_EVENT_INSTANT0("android_webview", | 233 TRACE_EVENT_INSTANT0("android_webview", |
| 231 "EarlyOut_PreviousFrameUnconsumed", | 234 "EarlyOut_PreviousFrameUnconsumed", |
| 232 TRACE_EVENT_SCOPE_THREAD); | 235 TRACE_EVENT_SCOPE_THREAD); |
| 233 SkippedCompositeInDraw(); | 236 SkippedCompositeInDraw(); |
| 234 return client_->RequestDrawGL(java_canvas, false); | 237 return client_->RequestDrawGL(java_canvas, false); |
| 235 } | 238 } |
| 236 | 239 |
| 237 scoped_ptr<cc::CompositorFrame> frame = CompositeHw(); | 240 scoped_ptr<cc::CompositorFrame> frame = CompositeHw(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 252 gfx::Size surface_size(width_, height_); | 255 gfx::Size surface_size(width_, height_); |
| 253 gfx::Rect viewport(surface_size); | 256 gfx::Rect viewport(surface_size); |
| 254 gfx::Rect clip = viewport; | 257 gfx::Rect clip = viewport; |
| 255 gfx::Transform transform_for_tile_priority = | 258 gfx::Transform transform_for_tile_priority = |
| 256 parent_draw_constraints_.transform; | 259 parent_draw_constraints_.transform; |
| 257 | 260 |
| 258 // If the WebView is on a layer, WebView does not know what transform is | 261 // If the WebView is on a layer, WebView does not know what transform is |
| 259 // applied onto the layer so global visible rect does not make sense here. | 262 // applied onto the layer so global visible rect does not make sense here. |
| 260 // In this case, just use the surface rect for tiling. | 263 // In this case, just use the surface rect for tiling. |
| 261 gfx::Rect viewport_rect_for_tile_priority; | 264 gfx::Rect viewport_rect_for_tile_priority; |
| 262 if (parent_draw_constraints_.is_layer) | 265 if (parent_draw_constraints_.is_layer || |
| 266 last_on_draw_global_visible_rect_.IsEmpty()) { |
| 263 viewport_rect_for_tile_priority = parent_draw_constraints_.surface_rect; | 267 viewport_rect_for_tile_priority = parent_draw_constraints_.surface_rect; |
| 264 else | 268 } else { |
| 265 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; | 269 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; |
| 270 } |
| 266 | 271 |
| 267 scoped_ptr<cc::CompositorFrame> frame = | 272 scoped_ptr<cc::CompositorFrame> frame = |
| 268 compositor_->DemandDrawHw(surface_size, | 273 compositor_->DemandDrawHw(surface_size, |
| 269 gfx::Transform(), | 274 gfx::Transform(), |
| 270 viewport, | 275 viewport, |
| 271 clip, | 276 clip, |
| 272 viewport_rect_for_tile_priority, | 277 viewport_rect_for_tile_priority, |
| 273 transform_for_tile_priority); | 278 transform_for_tile_priority); |
| 274 if (frame.get()) | 279 if (frame.get()) |
| 275 DidComposite(); | 280 DidComposite(); |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 gfx::Vector2d rounded_overscroll_delta = gfx::ToRoundedVector2d( | 646 gfx::Vector2d rounded_overscroll_delta = gfx::ToRoundedVector2d( |
| 642 scaled_overscroll_delta + overscroll_rounding_error_); | 647 scaled_overscroll_delta + overscroll_rounding_error_); |
| 643 overscroll_rounding_error_ = | 648 overscroll_rounding_error_ = |
| 644 scaled_overscroll_delta - rounded_overscroll_delta; | 649 scaled_overscroll_delta - rounded_overscroll_delta; |
| 645 client_->DidOverscroll(rounded_overscroll_delta); | 650 client_->DidOverscroll(rounded_overscroll_delta); |
| 646 } | 651 } |
| 647 | 652 |
| 648 void BrowserViewRenderer::EnsureContinuousInvalidation( | 653 void BrowserViewRenderer::EnsureContinuousInvalidation( |
| 649 bool force_invalidate, | 654 bool force_invalidate, |
| 650 bool skip_reschedule_tick) { | 655 bool skip_reschedule_tick) { |
| 656 if (force_invalidate) |
| 657 invalidate_after_composite_ = true; |
| 658 |
| 651 // This method should be called again when any of these conditions change. | 659 // This method should be called again when any of these conditions change. |
| 652 bool need_invalidate = | 660 bool need_invalidate = |
| 653 compositor_needs_continuous_invalidate_ || force_invalidate; | 661 compositor_needs_continuous_invalidate_ || invalidate_after_composite_; |
| 654 if (!need_invalidate || block_invalidates_) | 662 if (!need_invalidate || block_invalidates_) |
| 655 return; | 663 return; |
| 656 | 664 |
| 665 if (!compositor_needs_continuous_invalidate_ && invalidate_after_composite_) |
| 666 invalidate_after_composite_ = false; |
| 667 |
| 657 // Always call view invalidate. We rely the Android framework to ignore the | 668 // Always call view invalidate. We rely the Android framework to ignore the |
| 658 // invalidate when it's not needed such as when view is not visible. | 669 // invalidate when it's not needed such as when view is not visible. |
| 659 client_->PostInvalidate(); | 670 client_->PostInvalidate(); |
| 660 | 671 |
| 661 // Stop fallback ticks when one of these is true. | 672 // Stop fallback ticks when one of these is true. |
| 662 // 1) Webview is paused. Also need to check we are not in clear view since | 673 // 1) Webview is paused. Also need to check we are not in clear view since |
| 663 // paused, offscreen still expect clear view to recover. | 674 // paused, offscreen still expect clear view to recover. |
| 664 // 2) If we are attached to window and the window is not visible (eg when | 675 // 2) If we are attached to window and the window is not visible (eg when |
| 665 // app is in the background). We are sure in this case the webview is used | 676 // app is in the background). We are sure in this case the webview is used |
| 666 // "on-screen" but that updates are not needed when in the background. | 677 // "on-screen" but that updates are not needed when in the background. |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 base::StringAppendF(&str, | 793 base::StringAppendF(&str, |
| 783 "overscroll_rounding_error_: %s ", | 794 "overscroll_rounding_error_: %s ", |
| 784 overscroll_rounding_error_.ToString().c_str()); | 795 overscroll_rounding_error_.ToString().c_str()); |
| 785 base::StringAppendF( | 796 base::StringAppendF( |
| 786 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); | 797 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); |
| 787 base::StringAppendF(&str, "clear_view: %d ", clear_view_); | 798 base::StringAppendF(&str, "clear_view: %d ", clear_view_); |
| 788 return str; | 799 return str; |
| 789 } | 800 } |
| 790 | 801 |
| 791 } // namespace android_webview | 802 } // namespace android_webview |
| OLD | NEW |