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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 BrowserViewRenderer* BrowserViewRenderer::FromWebContents( | 87 BrowserViewRenderer* BrowserViewRenderer::FromWebContents( |
87 content::WebContents* web_contents) { | 88 content::WebContents* web_contents) { |
88 return BrowserViewRendererUserData::GetBrowserViewRenderer(web_contents); | 89 return BrowserViewRendererUserData::GetBrowserViewRenderer(web_contents); |
89 } | 90 } |
90 | 91 |
91 BrowserViewRenderer::BrowserViewRenderer( | 92 BrowserViewRenderer::BrowserViewRenderer( |
92 BrowserViewRendererClient* client, | 93 BrowserViewRendererClient* client, |
93 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) | 94 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) |
94 : client_(client), | 95 : client_(client), |
95 ui_task_runner_(ui_task_runner), | 96 ui_task_runner_(ui_task_runner), |
| 97 async_on_draw_hardware_(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 98 switches::kAsyncOnDrawHardware)), |
96 current_compositor_frame_consumer_(nullptr), | 99 current_compositor_frame_consumer_(nullptr), |
97 compositor_(nullptr), | 100 compositor_(nullptr), |
98 is_paused_(false), | 101 is_paused_(false), |
99 view_visible_(false), | 102 view_visible_(false), |
100 window_visible_(false), | 103 window_visible_(false), |
101 attached_to_window_(false), | 104 attached_to_window_(false), |
102 hardware_enabled_(false), | 105 hardware_enabled_(false), |
103 dip_scale_(0.f), | 106 dip_scale_(0.f), |
104 page_scale_factor_(1.f), | 107 page_scale_factor_(1.f), |
105 min_page_scale_factor_(0.f), | 108 min_page_scale_factor_(0.f), |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 gfx::Transform transform_for_tile_priority = |
227 external_draw_constraints_.transform; | 230 external_draw_constraints_.transform; |
228 | 231 |
229 // If the WebView is on a layer, WebView does not know what transform is | 232 gfx::Rect viewport_rect_for_tile_priority = |
230 // applied onto the layer so global visible rect does not make sense here. | 233 ComputeViewportRectForTilePriority(); |
231 // 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 if (async_on_draw_hardware_) { |
235 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { | 236 compositor_->DemandDrawHwAsync(size_, viewport_rect_for_tile_priority, |
236 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; | 237 transform_for_tile_priority); |
| 238 return current_compositor_frame_consumer_->HasFrameOnUI(); |
237 } | 239 } |
238 | 240 |
239 content::SynchronousCompositor::Frame frame = compositor_->DemandDrawHw( | 241 content::SynchronousCompositor::Frame frame = compositor_->DemandDrawHw( |
240 size_, viewport_rect_for_tile_priority, transform_for_tile_priority); | 242 size_, viewport_rect_for_tile_priority, transform_for_tile_priority); |
241 if (!frame.frame.get()) { | 243 if (!frame.frame) { |
242 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame", | 244 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame", |
243 TRACE_EVENT_SCOPE_THREAD); | 245 TRACE_EVENT_SCOPE_THREAD); |
244 return current_compositor_frame_consumer_->HasFrameOnUI(); | 246 return current_compositor_frame_consumer_->HasFrameOnUI(); |
245 } | 247 } |
246 | 248 |
| 249 OnDrawHardwareProcessFrame(std::move(frame)); |
| 250 return true; |
| 251 } |
| 252 |
| 253 void BrowserViewRenderer::OnDrawHardwareProcessFrame( |
| 254 content::SynchronousCompositor::Frame frame) { |
| 255 TRACE_EVENT0("android_webview", |
| 256 "BrowserViewRenderer::OnDrawHardwareProcessFrame"); |
| 257 if (!frame.frame) |
| 258 return; |
| 259 |
| 260 gfx::Transform transform_for_tile_priority = |
| 261 external_draw_constraints_.transform; |
| 262 gfx::Rect viewport_rect_for_tile_priority = |
| 263 ComputeViewportRectForTilePriority(); |
247 std::unique_ptr<ChildFrame> child_frame = base::MakeUnique<ChildFrame>( | 264 std::unique_ptr<ChildFrame> child_frame = base::MakeUnique<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; | 272 } |
| 273 |
| 274 gfx::Rect BrowserViewRenderer::ComputeViewportRectForTilePriority() { |
| 275 // If the WebView is on a layer, WebView does not know what transform is |
| 276 // applied onto the layer so global visible rect does not make sense here. |
| 277 // In this case, just use the surface rect for tiling. |
| 278 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. |
| 279 gfx::Rect viewport_rect_for_tile_priority; |
| 280 |
| 281 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { |
| 282 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; |
| 283 } |
| 284 return viewport_rect_for_tile_priority; |
256 } | 285 } |
257 | 286 |
258 void BrowserViewRenderer::OnParentDrawConstraintsUpdated( | 287 void BrowserViewRenderer::OnParentDrawConstraintsUpdated( |
259 CompositorFrameConsumer* compositor_frame_consumer) { | 288 CompositorFrameConsumer* compositor_frame_consumer) { |
260 DCHECK(compositor_frame_consumer); | 289 DCHECK(compositor_frame_consumer); |
261 if (compositor_frame_consumer != current_compositor_frame_consumer_) | 290 if (compositor_frame_consumer != current_compositor_frame_consumer_) |
262 return; | 291 return; |
263 PostInvalidate(compositor_); | 292 PostInvalidate(compositor_); |
264 external_draw_constraints_ = | 293 external_draw_constraints_ = |
265 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); | 294 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 base::StringAppendF(&str, | 765 base::StringAppendF(&str, |
737 "overscroll_rounding_error_: %s ", | 766 "overscroll_rounding_error_: %s ", |
738 overscroll_rounding_error_.ToString().c_str()); | 767 overscroll_rounding_error_.ToString().c_str()); |
739 base::StringAppendF( | 768 base::StringAppendF( |
740 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); | 769 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); |
741 base::StringAppendF(&str, "clear_view: %d ", clear_view_); | 770 base::StringAppendF(&str, "clear_view: %d ", clear_view_); |
742 return str; | 771 return str; |
743 } | 772 } |
744 | 773 |
745 } // namespace android_webview | 774 } // namespace android_webview |
OLD | NEW |