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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 | 225 |
| 226 ReturnResourceFromParent(current_compositor_frame_consumer_); | 226 ReturnResourceFromParent(current_compositor_frame_consumer_); |
| 227 UpdateMemoryPolicy(); | 227 UpdateMemoryPolicy(); |
| 228 | 228 |
| 229 gfx::Transform transform_for_tile_priority = | 229 gfx::Transform transform_for_tile_priority = |
| 230 external_draw_constraints_.transform; | 230 external_draw_constraints_.transform; |
| 231 | 231 |
| 232 gfx::Rect viewport_rect_for_tile_priority = | 232 gfx::Rect viewport_rect_for_tile_priority = |
| 233 ComputeViewportRectForTilePriority(); | 233 ComputeViewportRectForTilePriority(); |
| 234 | 234 |
| 235 scoped_refptr<content::SynchronousCompositor::FrameFuture> frame_future; | |
| 236 | |
| 235 if (async_on_draw_hardware_) { | 237 if (async_on_draw_hardware_) { |
| 236 compositor_->DemandDrawHwAsync(size_, viewport_rect_for_tile_priority, | 238 frame_future = compositor_->DemandDrawHwAsync( |
| 237 transform_for_tile_priority); | 239 size_, viewport_rect_for_tile_priority, transform_for_tile_priority); |
| 238 return current_compositor_frame_consumer_->HasFrameOnUI(); | 240 return current_compositor_frame_consumer_->HasFrameOnUI(); |
| 241 } else { | |
| 242 frame_future = compositor_->DemandDrawHw( | |
| 243 size_, viewport_rect_for_tile_priority, transform_for_tile_priority); | |
| 239 } | 244 } |
| 240 | 245 |
| 241 content::SynchronousCompositor::Frame frame = compositor_->DemandDrawHw( | 246 if (!(frame_future && frame_future->getFrame() && |
| 242 size_, viewport_rect_for_tile_priority, transform_for_tile_priority); | 247 frame_future->getFrame()->frame)) { |
|
boliu
2016/09/20 00:27:56
can't call getFrame here because we will want to h
| |
| 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 |
| 249 OnDrawHardwareProcessFrame(std::move(frame)); | 253 OnDrawHardwareProcessFrame(std::move(frame_future)); |
| 250 return true; | 254 return true; |
| 251 } | 255 } |
| 252 | 256 |
| 253 void BrowserViewRenderer::OnDrawHardwareProcessFrame( | 257 void BrowserViewRenderer::OnDrawHardwareProcessFrame( |
| 254 content::SynchronousCompositor::Frame frame) { | 258 scoped_refptr<content::SynchronousCompositor::FrameFuture> frame_future) { |
| 255 TRACE_EVENT0("android_webview", | |
| 256 "BrowserViewRenderer::OnDrawHardwareProcessFrame"); | |
| 257 if (!frame.frame) | |
| 258 return; | |
| 259 | |
| 260 gfx::Transform transform_for_tile_priority = | 259 gfx::Transform transform_for_tile_priority = |
| 261 external_draw_constraints_.transform; | 260 external_draw_constraints_.transform; |
| 262 gfx::Rect viewport_rect_for_tile_priority = | 261 gfx::Rect viewport_rect_for_tile_priority = |
| 263 ComputeViewportRectForTilePriority(); | 262 ComputeViewportRectForTilePriority(); |
| 264 std::unique_ptr<ChildFrame> child_frame = base::MakeUnique<ChildFrame>( | |
| 265 frame.compositor_frame_sink_id, std::move(frame.frame), compositor_id_, | |
| 266 viewport_rect_for_tile_priority.IsEmpty(), transform_for_tile_priority, | |
| 267 offscreen_pre_raster_, external_draw_constraints_.is_layer); | |
| 268 | 263 |
| 269 ReturnUnusedResource( | 264 ReturnUnusedResource( |
| 270 current_compositor_frame_consumer_->PassUncommittedFrameOnUI()); | 265 current_compositor_frame_consumer_->PassUncommittedFrameOnUI()); |
| 271 current_compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame)); | 266 |
| 267 current_compositor_frame_consumer_->SetFrameOnUI(base::MakeUnique<ChildFrame>( | |
| 268 std::move(frame_future), compositor_id_, | |
| 269 viewport_rect_for_tile_priority.IsEmpty(), transform_for_tile_priority, | |
| 270 offscreen_pre_raster_, external_draw_constraints_.is_layer)); | |
| 272 } | 271 } |
| 273 | 272 |
| 274 gfx::Rect BrowserViewRenderer::ComputeViewportRectForTilePriority() { | 273 gfx::Rect BrowserViewRenderer::ComputeViewportRectForTilePriority() { |
| 275 // If the WebView is on a layer, WebView does not know what transform is | 274 // 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. | 275 // applied onto the layer so global visible rect does not make sense here. |
| 277 // In this case, just use the surface rect for tiling. | 276 // In this case, just use the surface rect for tiling. |
| 278 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. | 277 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. |
| 279 gfx::Rect viewport_rect_for_tile_priority; | 278 gfx::Rect viewport_rect_for_tile_priority; |
| 280 | 279 |
| 281 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { | 280 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 306 // At this point the compositor frame consumer has to hand back all resources | 305 // At this point the compositor frame consumer has to hand back all resources |
| 307 // to the child compositor. | 306 // to the child compositor. |
| 308 compositor_frame_consumer->DeleteHardwareRendererOnUI(); | 307 compositor_frame_consumer->DeleteHardwareRendererOnUI(); |
| 309 ReturnUnusedResource(compositor_frame_consumer->PassUncommittedFrameOnUI()); | 308 ReturnUnusedResource(compositor_frame_consumer->PassUncommittedFrameOnUI()); |
| 310 ReturnResourceFromParent(compositor_frame_consumer); | 309 ReturnResourceFromParent(compositor_frame_consumer); |
| 311 compositor_frame_consumer->SetCompositorFrameProducer(nullptr); | 310 compositor_frame_consumer->SetCompositorFrameProducer(nullptr); |
| 312 } | 311 } |
| 313 | 312 |
| 314 void BrowserViewRenderer::ReturnUnusedResource( | 313 void BrowserViewRenderer::ReturnUnusedResource( |
| 315 std::unique_ptr<ChildFrame> child_frame) { | 314 std::unique_ptr<ChildFrame> child_frame) { |
| 316 if (!child_frame.get() || !child_frame->frame.get()) | 315 if (!child_frame.get() || !child_frame->frame_future->hasFrame()) |
| 317 return; | 316 return; |
| 318 | 317 |
| 319 cc::ReturnedResourceArray resources; | 318 cc::ReturnedResourceArray resources; |
| 320 cc::TransferableResource::ReturnResources( | 319 cc::TransferableResource::ReturnResources( |
| 321 child_frame->frame->delegated_frame_data->resource_list, &resources); | 320 child_frame->frame_future->getFrame() |
| 321 ->frame->delegated_frame_data->resource_list, | |
| 322 &resources); | |
| 322 content::SynchronousCompositor* compositor = | 323 content::SynchronousCompositor* compositor = |
| 323 FindCompositor(child_frame->compositor_id); | 324 FindCompositor(child_frame->compositor_id); |
| 324 if (compositor && !resources.empty()) | 325 if (compositor && !resources.empty()) |
| 325 compositor->ReturnResources(child_frame->compositor_frame_sink_id, | 326 compositor->ReturnResources( |
| 326 resources); | 327 child_frame->frame_future->getFrame()->compositor_frame_sink_id, |
| 328 resources); | |
| 327 } | 329 } |
| 328 | 330 |
| 329 void BrowserViewRenderer::ReturnResourceFromParent( | 331 void BrowserViewRenderer::ReturnResourceFromParent( |
| 330 CompositorFrameConsumer* compositor_frame_consumer) { | 332 CompositorFrameConsumer* compositor_frame_consumer) { |
| 331 CompositorFrameConsumer::ReturnedResourcesMap returned_resource_map; | 333 CompositorFrameConsumer::ReturnedResourcesMap returned_resource_map; |
| 332 compositor_frame_consumer->SwapReturnedResourcesOnUI(&returned_resource_map); | 334 compositor_frame_consumer->SwapReturnedResourcesOnUI(&returned_resource_map); |
| 333 for (auto& pair : returned_resource_map) { | 335 for (auto& pair : returned_resource_map) { |
| 334 CompositorID compositor_id = pair.first; | 336 CompositorID compositor_id = pair.first; |
| 335 content::SynchronousCompositor* compositor = FindCompositor(compositor_id); | 337 content::SynchronousCompositor* compositor = FindCompositor(compositor_id); |
| 336 cc::ReturnedResourceArray resources; | 338 cc::ReturnedResourceArray resources; |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 767 base::StringAppendF(&str, | 769 base::StringAppendF(&str, |
| 768 "overscroll_rounding_error_: %s ", | 770 "overscroll_rounding_error_: %s ", |
| 769 overscroll_rounding_error_.ToString().c_str()); | 771 overscroll_rounding_error_.ToString().c_str()); |
| 770 base::StringAppendF( | 772 base::StringAppendF( |
| 771 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); | 773 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); |
| 772 base::StringAppendF(&str, "clear_view: %d ", clear_view_); | 774 base::StringAppendF(&str, "clear_view: %d ", clear_view_); |
| 773 return str; | 775 return str; |
| 774 } | 776 } |
| 775 | 777 |
| 776 } // namespace android_webview | 778 } // namespace android_webview |
| OLD | NEW |