Chromium Code Reviews| 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 "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 compositor_(NULL), | 61 compositor_(NULL), |
| 62 is_paused_(false), | 62 is_paused_(false), |
| 63 view_visible_(false), | 63 view_visible_(false), |
| 64 window_visible_(false), | 64 window_visible_(false), |
| 65 attached_to_window_(false), | 65 attached_to_window_(false), |
| 66 hardware_enabled_(false), | 66 hardware_enabled_(false), |
| 67 dip_scale_(0.0), | 67 dip_scale_(0.0), |
| 68 page_scale_factor_(1.0), | 68 page_scale_factor_(1.0), |
| 69 on_new_picture_enable_(false), | 69 on_new_picture_enable_(false), |
| 70 clear_view_(false), | 70 clear_view_(false), |
| 71 offscreen_pre_raster_(false), | |
| 71 compositor_needs_continuous_invalidate_(false), | 72 compositor_needs_continuous_invalidate_(false), |
| 72 invalidate_after_composite_(false), | 73 invalidate_after_composite_(false), |
| 73 block_invalidates_(false), | 74 block_invalidates_(false), |
| 74 fallback_tick_pending_(false) { | 75 fallback_tick_pending_(false) { |
| 75 } | 76 } |
| 76 | 77 |
| 77 BrowserViewRenderer::~BrowserViewRenderer() { | 78 BrowserViewRenderer::~BrowserViewRenderer() { |
| 78 } | 79 } |
| 79 | 80 |
| 80 SharedRendererState* BrowserViewRenderer::GetAwDrawGLViewContext() { | 81 SharedRendererState* BrowserViewRenderer::GetAwDrawGLViewContext() { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 // Just set the memory limit to 0 and drop all tiles. This will be reset to | 122 // Just set the memory limit to 0 and drop all tiles. This will be reset to |
| 122 // normal levels in the next DrawGL call. | 123 // normal levels in the next DrawGL call. |
| 123 compositor_->SetMemoryPolicy(0u); | 124 compositor_->SetMemoryPolicy(0u); |
| 124 ForceFakeCompositeSW(); | 125 ForceFakeCompositeSW(); |
| 125 } | 126 } |
| 126 | 127 |
| 127 size_t BrowserViewRenderer::CalculateDesiredMemoryPolicy() { | 128 size_t BrowserViewRenderer::CalculateDesiredMemoryPolicy() { |
| 128 if (g_memory_override_in_bytes) | 129 if (g_memory_override_in_bytes) |
| 129 return static_cast<size_t>(g_memory_override_in_bytes); | 130 return static_cast<size_t>(g_memory_override_in_bytes); |
| 130 | 131 |
| 131 size_t width = last_on_draw_global_visible_rect_.width(); | 132 gfx::Rect interest_rect = offscreen_pre_raster_ |
| 132 size_t height = last_on_draw_global_visible_rect_.height(); | 133 ? gfx::Rect(size_) |
| 134 : last_on_draw_global_visible_rect_; | |
| 135 size_t width = interest_rect.width(); | |
| 136 size_t height = interest_rect.height(); | |
| 133 size_t bytes_limit = kMemoryMultiplier * kBytesPerPixel * width * height; | 137 size_t bytes_limit = kMemoryMultiplier * kBytesPerPixel * width * height; |
| 134 // Round up to a multiple of kMemoryAllocationStep. | 138 // Round up to a multiple of kMemoryAllocationStep. |
| 135 bytes_limit = | 139 bytes_limit = |
| 136 (bytes_limit / kMemoryAllocationStep + 1) * kMemoryAllocationStep; | 140 (bytes_limit / kMemoryAllocationStep + 1) * kMemoryAllocationStep; |
| 137 return bytes_limit; | 141 return bytes_limit; |
| 138 } | 142 } |
| 139 | 143 |
| 140 void BrowserViewRenderer::PrepareToDraw(const gfx::Vector2d& scroll, | 144 void BrowserViewRenderer::PrepareToDraw(const gfx::Vector2d& scroll, |
| 141 const gfx::Rect& global_visible_rect) { | 145 const gfx::Rect& global_visible_rect) { |
| 142 last_on_draw_scroll_offset_ = scroll; | 146 last_on_draw_scroll_offset_ = scroll; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 171 if (!hardware_enabled_) { | 175 if (!hardware_enabled_) { |
| 172 TRACE_EVENT0("android_webview", "InitializeHwDraw"); | 176 TRACE_EVENT0("android_webview", "InitializeHwDraw"); |
| 173 hardware_enabled_ = compositor_->InitializeHwDraw(); | 177 hardware_enabled_ = compositor_->InitializeHwDraw(); |
| 174 } | 178 } |
| 175 if (!hardware_enabled_) { | 179 if (!hardware_enabled_) { |
| 176 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_HardwareNotEnabled", | 180 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_HardwareNotEnabled", |
| 177 TRACE_EVENT_SCOPE_THREAD); | 181 TRACE_EVENT_SCOPE_THREAD); |
| 178 return false; | 182 return false; |
| 179 } | 183 } |
| 180 | 184 |
| 181 if (last_on_draw_global_visible_rect_.IsEmpty() && | |
| 182 parent_draw_constraints_.surface_rect.IsEmpty()) { | |
| 183 TRACE_EVENT_INSTANT0("android_webview", | |
| 184 "EarlyOut_EmptyVisibleRect", | |
| 185 TRACE_EVENT_SCOPE_THREAD); | |
| 186 shared_renderer_state_.SetForceInvalidateOnNextDrawGLOnUI(true); | |
| 187 return true; | |
| 188 } | |
| 189 | |
| 190 ReturnResourceFromParent(); | 185 ReturnResourceFromParent(); |
| 191 if (shared_renderer_state_.HasCompositorFrameOnUI()) { | 186 if (shared_renderer_state_.HasCompositorFrameOnUI()) { |
| 192 TRACE_EVENT_INSTANT0("android_webview", | 187 TRACE_EVENT_INSTANT0("android_webview", |
| 193 "EarlyOut_PreviousFrameUnconsumed", | 188 "EarlyOut_PreviousFrameUnconsumed", |
| 194 TRACE_EVENT_SCOPE_THREAD); | 189 TRACE_EVENT_SCOPE_THREAD); |
| 195 DidSkipCompositeInDraw(); | 190 DidSkipCompositeInDraw(); |
| 196 return true; | 191 return true; |
| 197 } | 192 } |
| 198 | 193 |
| 199 scoped_ptr<cc::CompositorFrame> frame = CompositeHw(); | 194 scoped_ptr<cc::CompositorFrame> frame = CompositeHw(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 215 gfx::Size surface_size(size_); | 210 gfx::Size surface_size(size_); |
| 216 gfx::Rect viewport(surface_size); | 211 gfx::Rect viewport(surface_size); |
| 217 gfx::Rect clip = viewport; | 212 gfx::Rect clip = viewport; |
| 218 gfx::Transform transform_for_tile_priority = | 213 gfx::Transform transform_for_tile_priority = |
| 219 parent_draw_constraints_.transform; | 214 parent_draw_constraints_.transform; |
| 220 | 215 |
| 221 // If the WebView is on a layer, WebView does not know what transform is | 216 // If the WebView is on a layer, WebView does not know what transform is |
| 222 // applied onto the layer so global visible rect does not make sense here. | 217 // applied onto the layer so global visible rect does not make sense here. |
| 223 // In this case, just use the surface rect for tiling. | 218 // In this case, just use the surface rect for tiling. |
| 224 gfx::Rect viewport_rect_for_tile_priority; | 219 gfx::Rect viewport_rect_for_tile_priority; |
| 225 if (parent_draw_constraints_.is_layer || | 220 if (offscreen_pre_raster_) { |
| 226 last_on_draw_global_visible_rect_.IsEmpty()) { | 221 viewport_rect_for_tile_priority = viewport; |
|
boliu
2015/02/20 23:16:07
empty so compositor use its own viewport?
hush (inactive)
2015/02/20 23:47:21
Done.
| |
| 227 viewport_rect_for_tile_priority = parent_draw_constraints_.surface_rect; | |
| 228 } else { | 222 } else { |
| 229 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; | 223 if (parent_draw_constraints_.is_layer || |
| 224 last_on_draw_global_visible_rect_.IsEmpty()) { | |
| 225 viewport_rect_for_tile_priority = parent_draw_constraints_.surface_rect; | |
| 226 } else { | |
| 227 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; | |
| 228 } | |
| 230 } | 229 } |
| 231 | 230 |
| 232 scoped_ptr<cc::CompositorFrame> frame = | 231 scoped_ptr<cc::CompositorFrame> frame = |
| 233 compositor_->DemandDrawHw(surface_size, | 232 compositor_->DemandDrawHw(surface_size, |
| 234 gfx::Transform(), | 233 gfx::Transform(), |
| 235 viewport, | 234 viewport, |
| 236 clip, | 235 clip, |
| 237 viewport_rect_for_tile_priority, | 236 viewport_rect_for_tile_priority, |
| 238 transform_for_tile_priority); | 237 transform_for_tile_priority); |
| 239 if (frame.get()) | 238 if (frame.get()) |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 "BrowserViewRenderer::ClearView", | 318 "BrowserViewRenderer::ClearView", |
| 320 TRACE_EVENT_SCOPE_THREAD); | 319 TRACE_EVENT_SCOPE_THREAD); |
| 321 if (clear_view_) | 320 if (clear_view_) |
| 322 return; | 321 return; |
| 323 | 322 |
| 324 clear_view_ = true; | 323 clear_view_ = true; |
| 325 // Always invalidate ignoring the compositor to actually clear the webview. | 324 // Always invalidate ignoring the compositor to actually clear the webview. |
| 326 EnsureContinuousInvalidation(true, false); | 325 EnsureContinuousInvalidation(true, false); |
| 327 } | 326 } |
| 328 | 327 |
| 328 void BrowserViewRenderer::SetOffscreenPreRaster(bool enable) { | |
| 329 offscreen_pre_raster_ = enable; | |
|
boliu
2015/02/20 23:16:07
leave a TODO here, we need to think about if toggl
hush (inactive)
2015/02/20 23:47:21
Done.
hush (inactive)
2015/02/20 23:54:46
Right now, we only expect the java side to call th
hush (inactive)
2015/02/21 00:27:03
The out of sync thing is not something to worry ab
| |
| 330 } | |
| 331 | |
| 329 void BrowserViewRenderer::SetIsPaused(bool paused) { | 332 void BrowserViewRenderer::SetIsPaused(bool paused) { |
| 330 TRACE_EVENT_INSTANT1("android_webview", | 333 TRACE_EVENT_INSTANT1("android_webview", |
| 331 "BrowserViewRenderer::SetIsPaused", | 334 "BrowserViewRenderer::SetIsPaused", |
| 332 TRACE_EVENT_SCOPE_THREAD, | 335 TRACE_EVENT_SCOPE_THREAD, |
| 333 "paused", | 336 "paused", |
| 334 paused); | 337 paused); |
| 335 is_paused_ = paused; | 338 is_paused_ = paused; |
| 336 EnsureContinuousInvalidation(false, false); | 339 EnsureContinuousInvalidation(false, false); |
| 337 } | 340 } |
| 338 | 341 |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 746 base::StringAppendF(&str, | 749 base::StringAppendF(&str, |
| 747 "overscroll_rounding_error_: %s ", | 750 "overscroll_rounding_error_: %s ", |
| 748 overscroll_rounding_error_.ToString().c_str()); | 751 overscroll_rounding_error_.ToString().c_str()); |
| 749 base::StringAppendF( | 752 base::StringAppendF( |
| 750 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); | 753 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); |
| 751 base::StringAppendF(&str, "clear_view: %d ", clear_view_); | 754 base::StringAppendF(&str, "clear_view: %d ", clear_view_); |
| 752 return str; | 755 return str; |
| 753 } | 756 } |
| 754 | 757 |
| 755 } // namespace android_webview | 758 } // namespace android_webview |
| OLD | NEW |