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 <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 LOG(WARNING) << "XXX " << __PRETTY_FUNCTION__; | |
| 112 DCHECK(compositor_map_.empty()); | 113 DCHECK(compositor_map_.empty()); |
| 113 SetCompositorFrameConsumer(nullptr); | 114 SetCurrentCompositorFrameConsumer(nullptr); |
| 114 } | 115 while (compositor_frame_consumers_.size()) { |
| 115 | 116 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 } | 117 } |
| 132 } | 118 } |
| 133 | 119 |
| 120 void BrowserViewRenderer::SetCurrentCompositorFrameConsumer( | |
| 121 CompositorFrameConsumer* compositor_frame_consumer) { | |
| 122 if (compositor_frame_consumer == current_compositor_frame_consumer_) { | |
| 123 return; | |
| 124 } | |
| 125 current_compositor_frame_consumer_ = compositor_frame_consumer; | |
| 126 if (current_compositor_frame_consumer_) { | |
| 127 compositor_frame_consumers_.insert(current_compositor_frame_consumer_); | |
| 128 current_compositor_frame_consumer_->SetCompositorFrameProducer(this); | |
| 129 OnParentDrawConstraintsUpdated(current_compositor_frame_consumer_); | |
| 130 } | |
| 131 } | |
| 132 | |
| 134 void BrowserViewRenderer::RegisterWithWebContents( | 133 void BrowserViewRenderer::RegisterWithWebContents( |
| 135 content::WebContents* web_contents) { | 134 content::WebContents* web_contents) { |
| 136 web_contents->SetUserData(kBrowserViewRendererUserDataKey, | 135 web_contents->SetUserData(kBrowserViewRendererUserDataKey, |
| 137 new BrowserViewRendererUserData(this)); | 136 new BrowserViewRendererUserData(this)); |
| 138 } | 137 } |
| 139 | 138 |
| 140 void BrowserViewRenderer::TrimMemory() { | 139 void BrowserViewRenderer::TrimMemory() { |
| 141 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 140 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 142 TRACE_EVENT0("android_webview", "BrowserViewRenderer::TrimMemory"); | 141 TRACE_EVENT0("android_webview", "BrowserViewRenderer::TrimMemory"); |
| 143 // Just set the memory limit to 0 and drop all tiles. This will be reset to | 142 // 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_) { | 192 if (clear_view_) { |
| 194 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_ClearView", | 193 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_ClearView", |
| 195 TRACE_EVENT_SCOPE_THREAD); | 194 TRACE_EVENT_SCOPE_THREAD); |
| 196 return false; | 195 return false; |
| 197 } | 196 } |
| 198 | 197 |
| 199 return true; | 198 return true; |
| 200 } | 199 } |
| 201 | 200 |
| 202 bool BrowserViewRenderer::OnDrawHardware() { | 201 bool BrowserViewRenderer::OnDrawHardware() { |
| 203 DCHECK(compositor_frame_consumer_); | 202 DCHECK(current_compositor_frame_consumer_); |
| 204 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware"); | 203 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware"); |
| 205 | 204 |
| 206 compositor_frame_consumer_->InitializeHardwareDrawIfNeededOnUI(); | 205 current_compositor_frame_consumer_->InitializeHardwareDrawIfNeededOnUI(); |
| 207 | 206 |
| 208 if (!CanOnDraw()) { | 207 if (!CanOnDraw()) { |
| 209 return false; | 208 return false; |
| 210 } | 209 } |
| 211 | 210 |
| 212 compositor_frame_consumer_->SetScrollOffsetOnUI(last_on_draw_scroll_offset_); | 211 current_compositor_frame_consumer_->SetScrollOffsetOnUI( |
| 212 last_on_draw_scroll_offset_); | |
| 213 hardware_enabled_ = true; | 213 hardware_enabled_ = true; |
| 214 | 214 |
| 215 external_draw_constraints_ = | 215 external_draw_constraints_ = |
| 216 compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); | 216 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); |
| 217 | 217 |
| 218 ReturnResourceFromParent(compositor_frame_consumer_); | 218 ReturnResourceFromParent(current_compositor_frame_consumer_); |
| 219 UpdateMemoryPolicy(); | 219 UpdateMemoryPolicy(); |
| 220 | 220 |
| 221 gfx::Size surface_size(size_); | 221 gfx::Size surface_size(size_); |
| 222 gfx::Rect viewport(surface_size); | 222 gfx::Rect viewport(surface_size); |
| 223 gfx::Rect clip = viewport; | 223 gfx::Rect clip = viewport; |
| 224 gfx::Transform transform_for_tile_priority = | 224 gfx::Transform transform_for_tile_priority = |
| 225 external_draw_constraints_.transform; | 225 external_draw_constraints_.transform; |
| 226 | 226 |
| 227 // If the WebView is on a layer, WebView does not know what transform is | 227 // 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. | 228 // applied onto the layer so global visible rect does not make sense here. |
| 229 // In this case, just use the surface rect for tiling. | 229 // In this case, just use the surface rect for tiling. |
| 230 gfx::Rect viewport_rect_for_tile_priority; | 230 gfx::Rect viewport_rect_for_tile_priority; |
| 231 | 231 |
| 232 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. | 232 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. |
| 233 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { | 233 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { |
| 234 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; | 234 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; |
| 235 } | 235 } |
| 236 | 236 |
| 237 content::SynchronousCompositor::Frame frame = | 237 content::SynchronousCompositor::Frame frame = |
| 238 compositor_->DemandDrawHw(surface_size, | 238 compositor_->DemandDrawHw(surface_size, |
| 239 gfx::Transform(), | 239 gfx::Transform(), |
| 240 viewport, | 240 viewport, |
| 241 clip, | 241 clip, |
| 242 viewport_rect_for_tile_priority, | 242 viewport_rect_for_tile_priority, |
| 243 transform_for_tile_priority); | 243 transform_for_tile_priority); |
| 244 if (!frame.frame.get()) { | 244 if (!frame.frame.get()) { |
| 245 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame", | 245 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame", |
| 246 TRACE_EVENT_SCOPE_THREAD); | 246 TRACE_EVENT_SCOPE_THREAD); |
| 247 hardware_enabled_ = compositor_frame_consumer_->HasFrameOnUI(); | 247 hardware_enabled_ = current_compositor_frame_consumer_->HasFrameOnUI(); |
| 248 if (!hardware_enabled_) | 248 if (!hardware_enabled_) |
| 249 UpdateMemoryPolicy(); | 249 UpdateMemoryPolicy(); |
| 250 return hardware_enabled_; | 250 return hardware_enabled_; |
| 251 } | 251 } |
| 252 | 252 |
| 253 std::unique_ptr<ChildFrame> child_frame = base::WrapUnique(new ChildFrame( | 253 std::unique_ptr<ChildFrame> child_frame = base::WrapUnique(new ChildFrame( |
| 254 frame.output_surface_id, std::move(frame.frame), | 254 frame.output_surface_id, std::move(frame.frame), |
| 255 GetCompositorID(compositor_), viewport_rect_for_tile_priority.IsEmpty(), | 255 GetCompositorID(compositor_), viewport_rect_for_tile_priority.IsEmpty(), |
| 256 transform_for_tile_priority, offscreen_pre_raster_, | 256 transform_for_tile_priority, offscreen_pre_raster_, |
| 257 external_draw_constraints_.is_layer)); | 257 external_draw_constraints_.is_layer)); |
| 258 | 258 |
| 259 ReturnUnusedResource(compositor_frame_consumer_->PassUncommittedFrameOnUI()); | 259 ReturnUnusedResource( |
| 260 compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame)); | 260 current_compositor_frame_consumer_->PassUncommittedFrameOnUI()); |
| 261 current_compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame)); | |
| 261 return true; | 262 return true; |
| 262 } | 263 } |
| 263 | 264 |
| 264 void BrowserViewRenderer::OnParentDrawConstraintsUpdated() { | 265 void BrowserViewRenderer::OnParentDrawConstraintsUpdated( |
| 265 DCHECK(compositor_frame_consumer_); | 266 CompositorFrameConsumer* compositor_frame_consumer) { |
| 267 DCHECK(compositor_frame_consumer); | |
| 268 if (compositor_frame_consumer != current_compositor_frame_consumer_) | |
| 269 return; | |
| 266 PostInvalidate(); | 270 PostInvalidate(); |
| 267 external_draw_constraints_ = | 271 external_draw_constraints_ = |
| 268 compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); | 272 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); |
| 269 UpdateMemoryPolicy(); | 273 UpdateMemoryPolicy(); |
| 270 } | 274 } |
| 271 | 275 |
| 272 void BrowserViewRenderer::OnCompositorFrameConsumerWillDestroy() { | 276 void BrowserViewRenderer::RemoveCompositorFrameConsumer( |
| 273 DCHECK(compositor_frame_consumer_); | 277 CompositorFrameConsumer* compositor_frame_consumer) { |
| 274 SetCompositorFrameConsumer(nullptr); | 278 DCHECK(compositor_frame_consumers_.count(compositor_frame_consumer)); |
| 279 compositor_frame_consumers_.erase(compositor_frame_consumer); | |
| 280 if (current_compositor_frame_consumer_ == compositor_frame_consumer) { | |
| 281 SetCurrentCompositorFrameConsumer(nullptr); | |
| 282 } | |
| 283 | |
| 284 // At this point the compositor frame consumer has to hand back all resources | |
| 285 // to the child compositor. | |
| 286 compositor_frame_consumer->DeleteHardwareRendererOnUI(); | |
| 287 ReturnUnusedResource(compositor_frame_consumer->PassUncommittedFrameOnUI()); | |
| 288 ReturnResourceFromParent(compositor_frame_consumer); | |
| 289 compositor_frame_consumer->SetCompositorFrameProducer(nullptr); | |
| 275 } | 290 } |
| 276 | 291 |
| 277 void BrowserViewRenderer::ReturnUnusedResource( | 292 void BrowserViewRenderer::ReturnUnusedResource( |
| 278 std::unique_ptr<ChildFrame> child_frame) { | 293 std::unique_ptr<ChildFrame> child_frame) { |
| 279 if (!child_frame.get() || !child_frame->frame.get()) | 294 if (!child_frame.get() || !child_frame->frame.get()) |
| 280 return; | 295 return; |
| 281 | 296 |
| 282 cc::CompositorFrameAck frame_ack; | 297 cc::CompositorFrameAck frame_ack; |
| 283 cc::TransferableResource::ReturnResources( | 298 cc::TransferableResource::ReturnResources( |
| 284 child_frame->frame->delegated_frame_data->resource_list, | 299 child_frame->frame->delegated_frame_data->resource_list, |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 } | 446 } |
| 432 | 447 |
| 433 void BrowserViewRenderer::OnComputeScroll(base::TimeTicks animation_time) { | 448 void BrowserViewRenderer::OnComputeScroll(base::TimeTicks animation_time) { |
| 434 if (!compositor_) | 449 if (!compositor_) |
| 435 return; | 450 return; |
| 436 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnComputeScroll"); | 451 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnComputeScroll"); |
| 437 compositor_->OnComputeScroll(animation_time); | 452 compositor_->OnComputeScroll(animation_time); |
| 438 } | 453 } |
| 439 | 454 |
| 440 void BrowserViewRenderer::ReleaseHardware() { | 455 void BrowserViewRenderer::ReleaseHardware() { |
| 441 if (compositor_frame_consumer_) { | 456 for (auto compositor_frame_consumer_ : compositor_frame_consumers_) { |
|
boliu
2016/05/10 15:18:18
no _ suffix for local variables
Tobias Sargeant
2016/05/13 13:23:56
Acknowledged.
| |
| 442 ReturnUnusedResource( | 457 ReturnUnusedResource( |
| 443 compositor_frame_consumer_->PassUncommittedFrameOnUI()); | 458 compositor_frame_consumer_->PassUncommittedFrameOnUI()); |
| 444 ReturnResourceFromParent(compositor_frame_consumer_); | 459 ReturnResourceFromParent(compositor_frame_consumer_); |
| 445 DCHECK(compositor_frame_consumer_->ReturnedResourcesEmptyOnUI()); | 460 DCHECK(compositor_frame_consumer_->ReturnedResourcesEmptyOnUI()); |
| 446 } | 461 } |
| 447 hardware_enabled_ = false; | 462 hardware_enabled_ = false; |
| 448 UpdateMemoryPolicy(); | 463 UpdateMemoryPolicy(); |
| 449 } | 464 } |
| 450 | 465 |
| 451 bool BrowserViewRenderer::IsVisible() const { | 466 bool BrowserViewRenderer::IsVisible() const { |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 720 base::StringAppendF(&str, | 735 base::StringAppendF(&str, |
| 721 "overscroll_rounding_error_: %s ", | 736 "overscroll_rounding_error_: %s ", |
| 722 overscroll_rounding_error_.ToString().c_str()); | 737 overscroll_rounding_error_.ToString().c_str()); |
| 723 base::StringAppendF( | 738 base::StringAppendF( |
| 724 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); | 739 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); |
| 725 base::StringAppendF(&str, "clear_view: %d ", clear_view_); | 740 base::StringAppendF(&str, "clear_view: %d ", clear_view_); |
| 726 return str; | 741 return str; |
| 727 } | 742 } |
| 728 | 743 |
| 729 } // namespace android_webview | 744 } // namespace android_webview |
| OLD | NEW |