| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "android_webview/browser/browser_view_renderer_client.h" | 9 #include "android_webview/browser/browser_view_renderer_client.h" |
| 10 #include "android_webview/browser/child_frame.h" | 10 #include "android_webview/browser/child_frame.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 BrowserViewRenderer* BrowserViewRenderer::FromWebContents( | 85 BrowserViewRenderer* BrowserViewRenderer::FromWebContents( |
| 86 content::WebContents* web_contents) { | 86 content::WebContents* web_contents) { |
| 87 return BrowserViewRendererUserData::GetBrowserViewRenderer(web_contents); | 87 return BrowserViewRendererUserData::GetBrowserViewRenderer(web_contents); |
| 88 } | 88 } |
| 89 | 89 |
| 90 BrowserViewRenderer::BrowserViewRenderer( | 90 BrowserViewRenderer::BrowserViewRenderer( |
| 91 BrowserViewRendererClient* client, | 91 BrowserViewRendererClient* client, |
| 92 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) | 92 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) |
| 93 : client_(client), | 93 : client_(client), |
| 94 ui_task_runner_(ui_task_runner), | 94 ui_task_runner_(ui_task_runner), |
| 95 compositor_frame_consumer_(nullptr), | 95 current_compositor_frame_consumer_(nullptr), |
| 96 compositor_(NULL), | 96 compositor_(NULL), |
| 97 is_paused_(false), | 97 is_paused_(false), |
| 98 view_visible_(false), | 98 view_visible_(false), |
| 99 window_visible_(false), | 99 window_visible_(false), |
| 100 attached_to_window_(false), | 100 attached_to_window_(false), |
| 101 hardware_enabled_(false), | 101 hardware_enabled_(false), |
| 102 dip_scale_(0.f), | 102 dip_scale_(0.f), |
| 103 page_scale_factor_(1.f), | 103 page_scale_factor_(1.f), |
| 104 min_page_scale_factor_(0.f), | 104 min_page_scale_factor_(0.f), |
| 105 max_page_scale_factor_(0.f), | 105 max_page_scale_factor_(0.f), |
| 106 on_new_picture_enable_(false), | 106 on_new_picture_enable_(false), |
| 107 clear_view_(false), | 107 clear_view_(false), |
| 108 offscreen_pre_raster_(false), | 108 offscreen_pre_raster_(false), |
| 109 next_compositor_id_(1) {} | 109 next_compositor_id_(1) {} |
| 110 | 110 |
| 111 BrowserViewRenderer::~BrowserViewRenderer() { | 111 BrowserViewRenderer::~BrowserViewRenderer() { |
| 112 DCHECK(compositor_map_.empty()); | 112 DCHECK(compositor_map_.empty()); |
| 113 SetCompositorFrameConsumer(nullptr); | 113 SetCurrentCompositorFrameConsumer(nullptr); |
| 114 } | 114 while (compositor_frame_consumers_.size()) { |
| 115 | 115 RemoveCompositorFrameConsumer(*compositor_frame_consumers_.begin()); |
| 116 void BrowserViewRenderer::SetCompositorFrameConsumer( | |
| 117 CompositorFrameConsumer* compositor_frame_consumer) { | |
| 118 if (compositor_frame_consumer == compositor_frame_consumer_) { | |
| 119 return; | |
| 120 } | |
| 121 if (compositor_frame_consumer_) { | |
| 122 compositor_frame_consumer_->DeleteHardwareRendererOnUI(); | |
| 123 ReturnUnusedResource( | |
| 124 compositor_frame_consumer_->PassUncommittedFrameOnUI()); | |
| 125 ReturnResourceFromParent(compositor_frame_consumer_); | |
| 126 compositor_frame_consumer_->SetCompositorFrameProducer(nullptr); | |
| 127 } | |
| 128 compositor_frame_consumer_ = compositor_frame_consumer; | |
| 129 if (compositor_frame_consumer_) { | |
| 130 compositor_frame_consumer_->SetCompositorFrameProducer(this); | |
| 131 } | 116 } |
| 132 } | 117 } |
| 133 | 118 |
| 119 void BrowserViewRenderer::SetCurrentCompositorFrameConsumer( |
| 120 CompositorFrameConsumer* compositor_frame_consumer) { |
| 121 if (compositor_frame_consumer == current_compositor_frame_consumer_) { |
| 122 return; |
| 123 } |
| 124 current_compositor_frame_consumer_ = compositor_frame_consumer; |
| 125 if (current_compositor_frame_consumer_) { |
| 126 compositor_frame_consumers_.insert(current_compositor_frame_consumer_); |
| 127 current_compositor_frame_consumer_->SetCompositorFrameProducer(this); |
| 128 OnParentDrawConstraintsUpdated(current_compositor_frame_consumer_); |
| 129 } |
| 130 } |
| 131 |
| 134 void BrowserViewRenderer::RegisterWithWebContents( | 132 void BrowserViewRenderer::RegisterWithWebContents( |
| 135 content::WebContents* web_contents) { | 133 content::WebContents* web_contents) { |
| 136 web_contents->SetUserData(kBrowserViewRendererUserDataKey, | 134 web_contents->SetUserData(kBrowserViewRendererUserDataKey, |
| 137 new BrowserViewRendererUserData(this)); | 135 new BrowserViewRendererUserData(this)); |
| 138 } | 136 } |
| 139 | 137 |
| 140 void BrowserViewRenderer::TrimMemory() { | 138 void BrowserViewRenderer::TrimMemory() { |
| 141 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 139 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 142 TRACE_EVENT0("android_webview", "BrowserViewRenderer::TrimMemory"); | 140 TRACE_EVENT0("android_webview", "BrowserViewRenderer::TrimMemory"); |
| 143 // Just set the memory limit to 0 and drop all tiles. This will be reset to | 141 // Just set the memory limit to 0 and drop all tiles. This will be reset to |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 if (clear_view_) { | 191 if (clear_view_) { |
| 194 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_ClearView", | 192 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_ClearView", |
| 195 TRACE_EVENT_SCOPE_THREAD); | 193 TRACE_EVENT_SCOPE_THREAD); |
| 196 return false; | 194 return false; |
| 197 } | 195 } |
| 198 | 196 |
| 199 return true; | 197 return true; |
| 200 } | 198 } |
| 201 | 199 |
| 202 bool BrowserViewRenderer::OnDrawHardware() { | 200 bool BrowserViewRenderer::OnDrawHardware() { |
| 203 DCHECK(compositor_frame_consumer_); | 201 DCHECK(current_compositor_frame_consumer_); |
| 204 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware"); | 202 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware"); |
| 205 | 203 |
| 206 compositor_frame_consumer_->InitializeHardwareDrawIfNeededOnUI(); | 204 current_compositor_frame_consumer_->InitializeHardwareDrawIfNeededOnUI(); |
| 207 | 205 |
| 208 if (!CanOnDraw()) { | 206 if (!CanOnDraw()) { |
| 209 return false; | 207 return false; |
| 210 } | 208 } |
| 211 | 209 |
| 212 compositor_frame_consumer_->SetScrollOffsetOnUI(last_on_draw_scroll_offset_); | 210 current_compositor_frame_consumer_->SetScrollOffsetOnUI( |
| 211 last_on_draw_scroll_offset_); |
| 213 hardware_enabled_ = true; | 212 hardware_enabled_ = true; |
| 214 | 213 |
| 215 external_draw_constraints_ = | 214 external_draw_constraints_ = |
| 216 compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); | 215 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); |
| 217 | 216 |
| 218 ReturnResourceFromParent(compositor_frame_consumer_); | 217 ReturnResourceFromParent(current_compositor_frame_consumer_); |
| 219 UpdateMemoryPolicy(); | 218 UpdateMemoryPolicy(); |
| 220 | 219 |
| 221 gfx::Size surface_size(size_); | 220 gfx::Size surface_size(size_); |
| 222 gfx::Rect viewport(surface_size); | 221 gfx::Rect viewport(surface_size); |
| 223 gfx::Rect clip = viewport; | 222 gfx::Rect clip = viewport; |
| 224 gfx::Transform transform_for_tile_priority = | 223 gfx::Transform transform_for_tile_priority = |
| 225 external_draw_constraints_.transform; | 224 external_draw_constraints_.transform; |
| 226 | 225 |
| 227 // If the WebView is on a layer, WebView does not know what transform is | 226 // If the WebView is on a layer, WebView does not know what transform is |
| 228 // applied onto the layer so global visible rect does not make sense here. | 227 // applied onto the layer so global visible rect does not make sense here. |
| 229 // In this case, just use the surface rect for tiling. | 228 // In this case, just use the surface rect for tiling. |
| 230 gfx::Rect viewport_rect_for_tile_priority; | 229 gfx::Rect viewport_rect_for_tile_priority; |
| 231 | 230 |
| 232 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. | 231 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. |
| 233 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { | 232 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { |
| 234 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; | 233 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; |
| 235 } | 234 } |
| 236 | 235 |
| 237 content::SynchronousCompositor::Frame frame = | 236 content::SynchronousCompositor::Frame frame = |
| 238 compositor_->DemandDrawHw(surface_size, | 237 compositor_->DemandDrawHw(surface_size, |
| 239 gfx::Transform(), | 238 gfx::Transform(), |
| 240 viewport, | 239 viewport, |
| 241 clip, | 240 clip, |
| 242 viewport_rect_for_tile_priority, | 241 viewport_rect_for_tile_priority, |
| 243 transform_for_tile_priority); | 242 transform_for_tile_priority); |
| 244 if (!frame.frame.get()) { | 243 if (!frame.frame.get()) { |
| 245 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame", | 244 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame", |
| 246 TRACE_EVENT_SCOPE_THREAD); | 245 TRACE_EVENT_SCOPE_THREAD); |
| 247 return compositor_frame_consumer_->HasFrameOnUI(); | 246 return current_compositor_frame_consumer_->HasFrameOnUI(); |
| 248 } | 247 } |
| 249 | 248 |
| 250 std::unique_ptr<ChildFrame> child_frame = base::WrapUnique(new ChildFrame( | 249 std::unique_ptr<ChildFrame> child_frame = base::WrapUnique(new ChildFrame( |
| 251 frame.output_surface_id, std::move(frame.frame), | 250 frame.output_surface_id, std::move(frame.frame), |
| 252 GetCompositorID(compositor_), viewport_rect_for_tile_priority.IsEmpty(), | 251 GetCompositorID(compositor_), viewport_rect_for_tile_priority.IsEmpty(), |
| 253 transform_for_tile_priority, offscreen_pre_raster_, | 252 transform_for_tile_priority, offscreen_pre_raster_, |
| 254 external_draw_constraints_.is_layer)); | 253 external_draw_constraints_.is_layer)); |
| 255 | 254 |
| 256 ReturnUnusedResource(compositor_frame_consumer_->PassUncommittedFrameOnUI()); | 255 ReturnUnusedResource( |
| 257 compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame)); | 256 current_compositor_frame_consumer_->PassUncommittedFrameOnUI()); |
| 257 current_compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame)); |
| 258 return true; | 258 return true; |
| 259 } | 259 } |
| 260 | 260 |
| 261 void BrowserViewRenderer::OnParentDrawConstraintsUpdated() { | 261 void BrowserViewRenderer::OnParentDrawConstraintsUpdated( |
| 262 DCHECK(compositor_frame_consumer_); | 262 CompositorFrameConsumer* compositor_frame_consumer) { |
| 263 DCHECK(compositor_frame_consumer); |
| 264 if (compositor_frame_consumer != current_compositor_frame_consumer_) |
| 265 return; |
| 263 PostInvalidate(); | 266 PostInvalidate(); |
| 264 external_draw_constraints_ = | 267 external_draw_constraints_ = |
| 265 compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); | 268 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); |
| 266 UpdateMemoryPolicy(); | 269 UpdateMemoryPolicy(); |
| 267 } | 270 } |
| 268 | 271 |
| 269 void BrowserViewRenderer::OnCompositorFrameConsumerWillDestroy() { | 272 void BrowserViewRenderer::RemoveCompositorFrameConsumer( |
| 270 DCHECK(compositor_frame_consumer_); | 273 CompositorFrameConsumer* compositor_frame_consumer) { |
| 271 SetCompositorFrameConsumer(nullptr); | 274 DCHECK(compositor_frame_consumers_.count(compositor_frame_consumer)); |
| 275 compositor_frame_consumers_.erase(compositor_frame_consumer); |
| 276 if (current_compositor_frame_consumer_ == compositor_frame_consumer) { |
| 277 SetCurrentCompositorFrameConsumer(nullptr); |
| 278 } |
| 279 |
| 280 // At this point the compositor frame consumer has to hand back all resources |
| 281 // to the child compositor. |
| 282 compositor_frame_consumer->DeleteHardwareRendererOnUI(); |
| 283 ReturnUnusedResource(compositor_frame_consumer->PassUncommittedFrameOnUI()); |
| 284 ReturnResourceFromParent(compositor_frame_consumer); |
| 285 compositor_frame_consumer->SetCompositorFrameProducer(nullptr); |
| 272 } | 286 } |
| 273 | 287 |
| 274 void BrowserViewRenderer::ReturnUnusedResource( | 288 void BrowserViewRenderer::ReturnUnusedResource( |
| 275 std::unique_ptr<ChildFrame> child_frame) { | 289 std::unique_ptr<ChildFrame> child_frame) { |
| 276 if (!child_frame.get() || !child_frame->frame.get()) | 290 if (!child_frame.get() || !child_frame->frame.get()) |
| 277 return; | 291 return; |
| 278 | 292 |
| 279 cc::CompositorFrameAck frame_ack; | 293 cc::CompositorFrameAck frame_ack; |
| 280 cc::TransferableResource::ReturnResources( | 294 cc::TransferableResource::ReturnResources( |
| 281 child_frame->frame->delegated_frame_data->resource_list, | 295 child_frame->frame->delegated_frame_data->resource_list, |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 } | 442 } |
| 429 | 443 |
| 430 void BrowserViewRenderer::OnComputeScroll(base::TimeTicks animation_time) { | 444 void BrowserViewRenderer::OnComputeScroll(base::TimeTicks animation_time) { |
| 431 if (!compositor_) | 445 if (!compositor_) |
| 432 return; | 446 return; |
| 433 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnComputeScroll"); | 447 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnComputeScroll"); |
| 434 compositor_->OnComputeScroll(animation_time); | 448 compositor_->OnComputeScroll(animation_time); |
| 435 } | 449 } |
| 436 | 450 |
| 437 void BrowserViewRenderer::ReleaseHardware() { | 451 void BrowserViewRenderer::ReleaseHardware() { |
| 438 if (compositor_frame_consumer_) { | 452 for (auto compositor_frame_consumer : compositor_frame_consumers_) { |
| 439 ReturnUnusedResource( | 453 ReturnUnusedResource(compositor_frame_consumer->PassUncommittedFrameOnUI()); |
| 440 compositor_frame_consumer_->PassUncommittedFrameOnUI()); | 454 ReturnResourceFromParent(compositor_frame_consumer); |
| 441 ReturnResourceFromParent(compositor_frame_consumer_); | 455 DCHECK(compositor_frame_consumer->ReturnedResourcesEmptyOnUI()); |
| 442 DCHECK(compositor_frame_consumer_->ReturnedResourcesEmptyOnUI()); | |
| 443 } | 456 } |
| 444 hardware_enabled_ = false; | 457 hardware_enabled_ = false; |
| 445 UpdateMemoryPolicy(); | 458 UpdateMemoryPolicy(); |
| 446 } | 459 } |
| 447 | 460 |
| 448 bool BrowserViewRenderer::IsVisible() const { | 461 bool BrowserViewRenderer::IsVisible() const { |
| 449 // Ignore |window_visible_| if |attached_to_window_| is false. | 462 // Ignore |window_visible_| if |attached_to_window_| is false. |
| 450 return view_visible_ && (!attached_to_window_ || window_visible_); | 463 return view_visible_ && (!attached_to_window_ || window_visible_); |
| 451 } | 464 } |
| 452 | 465 |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 base::StringAppendF(&str, | 730 base::StringAppendF(&str, |
| 718 "overscroll_rounding_error_: %s ", | 731 "overscroll_rounding_error_: %s ", |
| 719 overscroll_rounding_error_.ToString().c_str()); | 732 overscroll_rounding_error_.ToString().c_str()); |
| 720 base::StringAppendF( | 733 base::StringAppendF( |
| 721 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); | 734 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); |
| 722 base::StringAppendF(&str, "clear_view: %d ", clear_view_); | 735 base::StringAppendF(&str, "clear_view: %d ", clear_view_); |
| 723 return str; | 736 return str; |
| 724 } | 737 } |
| 725 | 738 |
| 726 } // namespace android_webview | 739 } // namespace android_webview |
| OLD | NEW |