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" |
| 11 #include "android_webview/browser/compositor_frame_consumer.h" | 11 #include "android_webview/browser/compositor_frame_consumer.h" |
| 12 #include "android_webview/common/aw_switches.h" | |
| 12 #include "base/auto_reset.h" | 13 #include "base/auto_reset.h" |
| 13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 15 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 16 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 18 #include "base/supports_user_data.h" | 19 #include "base/supports_user_data.h" |
| 19 #include "base/trace_event/trace_event_argument.h" | 20 #include "base/trace_event/trace_event_argument.h" |
| 20 #include "cc/output/compositor_frame.h" | 21 #include "cc/output/compositor_frame.h" |
| 21 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 view_visible_(false), | 100 view_visible_(false), |
| 100 window_visible_(false), | 101 window_visible_(false), |
| 101 attached_to_window_(false), | 102 attached_to_window_(false), |
| 102 hardware_enabled_(false), | 103 hardware_enabled_(false), |
| 103 dip_scale_(0.f), | 104 dip_scale_(0.f), |
| 104 page_scale_factor_(1.f), | 105 page_scale_factor_(1.f), |
| 105 min_page_scale_factor_(0.f), | 106 min_page_scale_factor_(0.f), |
| 106 max_page_scale_factor_(0.f), | 107 max_page_scale_factor_(0.f), |
| 107 on_new_picture_enable_(false), | 108 on_new_picture_enable_(false), |
| 108 clear_view_(false), | 109 clear_view_(false), |
| 109 offscreen_pre_raster_(false) {} | 110 offscreen_pre_raster_(false), |
| 111 async_frame_messages_(base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 112 switches::kBVRAsyncFrameMessages)) {} | |
| 110 | 113 |
| 111 BrowserViewRenderer::~BrowserViewRenderer() { | 114 BrowserViewRenderer::~BrowserViewRenderer() { |
| 112 DCHECK(compositor_map_.empty()); | 115 DCHECK(compositor_map_.empty()); |
| 113 SetCurrentCompositorFrameConsumer(nullptr); | 116 SetCurrentCompositorFrameConsumer(nullptr); |
| 114 while (compositor_frame_consumers_.size()) { | 117 while (compositor_frame_consumers_.size()) { |
| 115 RemoveCompositorFrameConsumer(*compositor_frame_consumers_.begin()); | 118 RemoveCompositorFrameConsumer(*compositor_frame_consumers_.begin()); |
| 116 } | 119 } |
| 117 } | 120 } |
| 118 | 121 |
| 119 void BrowserViewRenderer::SetCurrentCompositorFrameConsumer( | 122 void BrowserViewRenderer::SetCurrentCompositorFrameConsumer( |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 current_compositor_frame_consumer_->SetScrollOffsetOnUI( | 219 current_compositor_frame_consumer_->SetScrollOffsetOnUI( |
| 217 last_on_draw_scroll_offset_); | 220 last_on_draw_scroll_offset_); |
| 218 hardware_enabled_ = true; | 221 hardware_enabled_ = true; |
| 219 | 222 |
| 220 external_draw_constraints_ = | 223 external_draw_constraints_ = |
| 221 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); | 224 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); |
| 222 | 225 |
| 223 ReturnResourceFromParent(current_compositor_frame_consumer_); | 226 ReturnResourceFromParent(current_compositor_frame_consumer_); |
| 224 UpdateMemoryPolicy(); | 227 UpdateMemoryPolicy(); |
| 225 | 228 |
| 226 gfx::Transform transform_for_tile_priority = | 229 transform_for_tile_priority_ = external_draw_constraints_.transform; |
| 227 external_draw_constraints_.transform; | |
| 228 | 230 |
| 229 // If the WebView is on a layer, WebView does not know what transform is | 231 // If the WebView is on a layer, WebView does not know what transform is |
| 230 // applied onto the layer so global visible rect does not make sense here. | 232 // applied onto the layer so global visible rect does not make sense here. |
| 231 // In this case, just use the surface rect for tiling. | 233 // In this case, just use the surface rect for tiling. |
| 232 gfx::Rect viewport_rect_for_tile_priority; | |
| 233 | 234 |
| 234 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. | 235 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. |
| 235 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { | 236 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { |
| 236 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; | 237 viewport_rect_for_tile_priority_ = last_on_draw_global_visible_rect_; |
| 237 } | 238 } |
| 238 | 239 |
| 239 content::SynchronousCompositor::Frame frame = compositor_->DemandDrawHw( | 240 if (async_frame_messages_) { |
| 240 size_, viewport_rect_for_tile_priority, transform_for_tile_priority); | 241 compositor_->DemandDrawHwAsync(size_, viewport_rect_for_tile_priority_, |
| 241 if (!frame.frame.get()) { | 242 transform_for_tile_priority_); |
| 242 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame", | |
| 243 TRACE_EVENT_SCOPE_THREAD); | |
| 244 return current_compositor_frame_consumer_->HasFrameOnUI(); | 243 return current_compositor_frame_consumer_->HasFrameOnUI(); |
| 245 } | 244 } |
| 246 | 245 |
| 246 frame_produced_ = false; | |
|
boliu
2016/08/23 02:39:52
you don't need this, just check the frame before c
ojars
2016/08/23 21:58:42
Done.
| |
| 247 content::SynchronousCompositor::Frame frame = compositor_->DemandDrawHw( | |
| 248 size_, viewport_rect_for_tile_priority_, transform_for_tile_priority_); | |
| 249 OnDrawHardwareProcessFrame(std::move(frame)); | |
| 250 | |
| 251 return (frame_produced_ || | |
| 252 current_compositor_frame_consumer_->HasFrameOnUI()); | |
| 253 } | |
| 254 | |
| 255 void BrowserViewRenderer::OnDrawHardwareProcessFrame( | |
| 256 content::SynchronousCompositor::Frame frame) { | |
| 257 TRACE_EVENT0("android_webview", | |
| 258 "BrowserViewRenderer::OnDrawHardwareProcessFrame"); | |
| 259 if (!frame.frame.get()) | |
| 260 return; | |
| 261 | |
| 262 frame_produced_ = true; | |
| 263 | |
| 247 std::unique_ptr<ChildFrame> child_frame = base::WrapUnique(new ChildFrame( | 264 std::unique_ptr<ChildFrame> child_frame = base::WrapUnique(new ChildFrame( |
| 248 frame.output_surface_id, std::move(frame.frame), compositor_id_, | 265 frame.output_surface_id, std::move(frame.frame), compositor_id_, |
| 249 viewport_rect_for_tile_priority.IsEmpty(), transform_for_tile_priority, | 266 viewport_rect_for_tile_priority_.IsEmpty(), transform_for_tile_priority_, |
| 250 offscreen_pre_raster_, external_draw_constraints_.is_layer)); | 267 offscreen_pre_raster_, external_draw_constraints_.is_layer)); |
| 251 | 268 |
| 252 ReturnUnusedResource( | 269 ReturnUnusedResource( |
| 253 current_compositor_frame_consumer_->PassUncommittedFrameOnUI()); | 270 current_compositor_frame_consumer_->PassUncommittedFrameOnUI()); |
| 254 current_compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame)); | 271 current_compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame)); |
| 255 return true; | |
| 256 } | 272 } |
| 257 | 273 |
| 258 void BrowserViewRenderer::OnParentDrawConstraintsUpdated( | 274 void BrowserViewRenderer::OnParentDrawConstraintsUpdated( |
| 259 CompositorFrameConsumer* compositor_frame_consumer) { | 275 CompositorFrameConsumer* compositor_frame_consumer) { |
| 260 DCHECK(compositor_frame_consumer); | 276 DCHECK(compositor_frame_consumer); |
| 261 if (compositor_frame_consumer != current_compositor_frame_consumer_) | 277 if (compositor_frame_consumer != current_compositor_frame_consumer_) |
| 262 return; | 278 return; |
| 263 PostInvalidate(compositor_); | 279 PostInvalidate(compositor_); |
| 264 external_draw_constraints_ = | 280 external_draw_constraints_ = |
| 265 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); | 281 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 732 base::StringAppendF(&str, | 748 base::StringAppendF(&str, |
| 733 "overscroll_rounding_error_: %s ", | 749 "overscroll_rounding_error_: %s ", |
| 734 overscroll_rounding_error_.ToString().c_str()); | 750 overscroll_rounding_error_.ToString().c_str()); |
| 735 base::StringAppendF( | 751 base::StringAppendF( |
| 736 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); | 752 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); |
| 737 base::StringAppendF(&str, "clear_view: %d ", clear_view_); | 753 base::StringAppendF(&str, "clear_view: %d ", clear_view_); |
| 738 return str; | 754 return str; |
| 739 } | 755 } |
| 740 | 756 |
| 741 } // namespace android_webview | 757 } // namespace android_webview |
| OLD | NEW |