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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 view_visible_(false), | 102 view_visible_(false), |
103 window_visible_(false), | 103 window_visible_(false), |
104 attached_to_window_(false), | 104 attached_to_window_(false), |
105 hardware_enabled_(false), | 105 hardware_enabled_(false), |
106 dip_scale_(0.f), | 106 dip_scale_(0.f), |
107 page_scale_factor_(1.f), | 107 page_scale_factor_(1.f), |
108 min_page_scale_factor_(0.f), | 108 min_page_scale_factor_(0.f), |
109 max_page_scale_factor_(0.f), | 109 max_page_scale_factor_(0.f), |
110 on_new_picture_enable_(false), | 110 on_new_picture_enable_(false), |
111 clear_view_(false), | 111 clear_view_(false), |
112 offscreen_pre_raster_(false) {} | 112 offscreen_pre_raster_(false), |
| 113 allow_async_draw_(false) {} |
113 | 114 |
114 BrowserViewRenderer::~BrowserViewRenderer() { | 115 BrowserViewRenderer::~BrowserViewRenderer() { |
115 DCHECK(compositor_map_.empty()); | 116 DCHECK(compositor_map_.empty()); |
116 SetCurrentCompositorFrameConsumer(nullptr); | 117 SetCurrentCompositorFrameConsumer(nullptr); |
117 while (compositor_frame_consumers_.size()) { | 118 while (compositor_frame_consumers_.size()) { |
118 RemoveCompositorFrameConsumer(*compositor_frame_consumers_.begin()); | 119 RemoveCompositorFrameConsumer(*compositor_frame_consumers_.begin()); |
119 } | 120 } |
120 } | 121 } |
121 | 122 |
122 void BrowserViewRenderer::SetCurrentCompositorFrameConsumer( | 123 void BrowserViewRenderer::SetCurrentCompositorFrameConsumer( |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 | 226 |
226 ReturnResourceFromParent(current_compositor_frame_consumer_); | 227 ReturnResourceFromParent(current_compositor_frame_consumer_); |
227 UpdateMemoryPolicy(); | 228 UpdateMemoryPolicy(); |
228 | 229 |
229 gfx::Transform transform_for_tile_priority = | 230 gfx::Transform transform_for_tile_priority = |
230 external_draw_constraints_.transform; | 231 external_draw_constraints_.transform; |
231 | 232 |
232 gfx::Rect viewport_rect_for_tile_priority = | 233 gfx::Rect viewport_rect_for_tile_priority = |
233 ComputeViewportRectForTilePriority(); | 234 ComputeViewportRectForTilePriority(); |
234 | 235 |
235 if (async_on_draw_hardware_) { | 236 scoped_refptr<content::SynchronousCompositor::FrameFuture> future; // Async. |
236 compositor_->DemandDrawHwAsync(size_, viewport_rect_for_tile_priority, | 237 content::SynchronousCompositor::Frame frame; // Sync. |
237 transform_for_tile_priority); | 238 bool async = async_on_draw_hardware_ && allow_async_draw_; |
238 return current_compositor_frame_consumer_->HasFrameOnUI(); | 239 if (async) { |
| 240 future = compositor_->DemandDrawHwAsync( |
| 241 size_, viewport_rect_for_tile_priority, transform_for_tile_priority); |
| 242 } else { |
| 243 frame = compositor_->DemandDrawHw(size_, viewport_rect_for_tile_priority, |
| 244 transform_for_tile_priority); |
239 } | 245 } |
240 | 246 |
241 content::SynchronousCompositor::Frame frame = compositor_->DemandDrawHw( | 247 if (!frame.frame && !future) { |
242 size_, viewport_rect_for_tile_priority, transform_for_tile_priority); | |
243 if (!frame.frame) { | |
244 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame", | 248 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame", |
245 TRACE_EVENT_SCOPE_THREAD); | 249 TRACE_EVENT_SCOPE_THREAD); |
246 return current_compositor_frame_consumer_->HasFrameOnUI(); | 250 return current_compositor_frame_consumer_->HasFrameOnUI(); |
247 } | 251 } |
248 | 252 |
| 253 allow_async_draw_ = true; |
249 std::unique_ptr<ChildFrame> child_frame = base::MakeUnique<ChildFrame>( | 254 std::unique_ptr<ChildFrame> child_frame = base::MakeUnique<ChildFrame>( |
250 frame.compositor_frame_sink_id, std::move(frame.frame), compositor_id_, | 255 frame.compositor_frame_sink_id, std::move(frame.frame), compositor_id_, |
251 viewport_rect_for_tile_priority.IsEmpty(), transform_for_tile_priority, | 256 viewport_rect_for_tile_priority.IsEmpty(), transform_for_tile_priority, |
252 offscreen_pre_raster_, external_draw_constraints_.is_layer); | 257 offscreen_pre_raster_, external_draw_constraints_.is_layer); |
253 | 258 |
254 ReturnUnusedResource( | 259 ReturnUnusedResource( |
255 current_compositor_frame_consumer_->PassUncommittedFrameOnUI()); | 260 current_compositor_frame_consumer_->PassUncommittedFrameOnUI()); |
256 current_compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame), | 261 current_compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame), |
257 nullptr); | 262 std::move(future)); |
258 | |
259 return true; | 263 return true; |
260 } | 264 } |
261 | 265 |
262 void BrowserViewRenderer::OnDrawHardwareProcessFrameFuture( | |
263 const scoped_refptr<content::SynchronousCompositor::FrameFuture>& | |
264 frame_future) { | |
265 gfx::Transform transform_for_tile_priority = | |
266 external_draw_constraints_.transform; | |
267 gfx::Rect viewport_rect_for_tile_priority = | |
268 ComputeViewportRectForTilePriority(); | |
269 | |
270 ReturnUnusedResource( | |
271 current_compositor_frame_consumer_->PassUncommittedFrameOnUI()); | |
272 current_compositor_frame_consumer_->SetFrameOnUI( | |
273 base::MakeUnique<ChildFrame>( | |
274 0, nullptr, compositor_id_, viewport_rect_for_tile_priority.IsEmpty(), | |
275 transform_for_tile_priority, offscreen_pre_raster_, | |
276 external_draw_constraints_.is_layer), | |
277 frame_future); | |
278 } | |
279 | |
280 gfx::Rect BrowserViewRenderer::ComputeViewportRectForTilePriority() { | 266 gfx::Rect BrowserViewRenderer::ComputeViewportRectForTilePriority() { |
281 // If the WebView is on a layer, WebView does not know what transform is | 267 // If the WebView is on a layer, WebView does not know what transform is |
282 // applied onto the layer so global visible rect does not make sense here. | 268 // applied onto the layer so global visible rect does not make sense here. |
283 // In this case, just use the surface rect for tiling. | 269 // In this case, just use the surface rect for tiling. |
284 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. | 270 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. |
285 gfx::Rect viewport_rect_for_tile_priority; | 271 gfx::Rect viewport_rect_for_tile_priority; |
286 | 272 |
287 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { | 273 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { |
288 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; | 274 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; |
289 } | 275 } |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 base::StringAppendF(&str, | 759 base::StringAppendF(&str, |
774 "overscroll_rounding_error_: %s ", | 760 "overscroll_rounding_error_: %s ", |
775 overscroll_rounding_error_.ToString().c_str()); | 761 overscroll_rounding_error_.ToString().c_str()); |
776 base::StringAppendF( | 762 base::StringAppendF( |
777 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); | 763 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); |
778 base::StringAppendF(&str, "clear_view: %d ", clear_view_); | 764 base::StringAppendF(&str, "clear_view: %d ", clear_view_); |
779 return str; | 765 return str; |
780 } | 766 } |
781 | 767 |
782 } // namespace android_webview | 768 } // namespace android_webview |
OLD | NEW |