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 "android_webview/browser/aw_gl_methods.h" | |
7 #include "android_webview/browser/browser_view_renderer_client.h" | 8 #include "android_webview/browser/browser_view_renderer_client.h" |
8 #include "android_webview/browser/shared_renderer_state.h" | 9 #include "android_webview/browser/browser_view_renderer_proxy.h" |
9 #include "android_webview/common/aw_switches.h" | 10 #include "android_webview/common/aw_switches.h" |
10 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/debug/trace_event_argument.h" | 13 #include "base/debug/trace_event_argument.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
16 #include "cc/output/compositor_frame.h" | 17 #include "cc/output/compositor_frame.h" |
18 #include "cc/output/compositor_frame_ack.h" | |
17 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
18 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
19 #include "gpu/command_buffer/service/gpu_switches.h" | 21 #include "gpu/command_buffer/service/gpu_switches.h" |
20 #include "third_party/skia/include/core/SkBitmap.h" | 22 #include "third_party/skia/include/core/SkBitmap.h" |
21 #include "third_party/skia/include/core/SkCanvas.h" | 23 #include "third_party/skia/include/core/SkCanvas.h" |
22 #include "third_party/skia/include/core/SkPicture.h" | 24 #include "third_party/skia/include/core/SkPicture.h" |
23 #include "third_party/skia/include/core/SkPictureRecorder.h" | 25 #include "third_party/skia/include/core/SkPictureRecorder.h" |
24 #include "ui/gfx/vector2d_conversions.h" | 26 #include "ui/gfx/vector2d_conversions.h" |
25 | 27 |
26 using content::SynchronousCompositorMemoryPolicy; | 28 using content::SynchronousCompositorMemoryPolicy; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 switches::kForceGpuMemAvailableMb), | 61 switches::kForceGpuMemAvailableMb), |
60 &g_memory_override_in_bytes); | 62 &g_memory_override_in_bytes); |
61 g_memory_override_in_bytes *= 1024 * 1024; | 63 g_memory_override_in_bytes *= 1024 * 1024; |
62 } | 64 } |
63 | 65 |
64 // Also use a high tile limit since there are no file descriptor issues. | 66 // Also use a high tile limit since there are no file descriptor issues. |
65 GlobalTileManager::GetInstance()->SetTileLimit(1000); | 67 GlobalTileManager::GetInstance()->SetTileLimit(1000); |
66 } | 68 } |
67 | 69 |
68 BrowserViewRenderer::BrowserViewRenderer( | 70 BrowserViewRenderer::BrowserViewRenderer( |
71 AwGLMethods* gl_methods, | |
69 BrowserViewRendererClient* client, | 72 BrowserViewRendererClient* client, |
70 SharedRendererState* shared_renderer_state, | 73 BrowserViewRendererProxy* proxy, |
71 content::WebContents* web_contents, | 74 content::WebContents* web_contents, |
72 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) | 75 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) |
73 : client_(client), | 76 : gl_methods_(gl_methods), |
74 shared_renderer_state_(shared_renderer_state), | 77 client_(client), |
78 proxy_(proxy), | |
75 web_contents_(web_contents), | 79 web_contents_(web_contents), |
76 ui_task_runner_(ui_task_runner), | 80 ui_task_runner_(ui_task_runner), |
77 compositor_(NULL), | 81 compositor_(NULL), |
78 is_paused_(false), | 82 is_paused_(false), |
79 view_visible_(false), | 83 view_visible_(false), |
80 window_visible_(false), | 84 window_visible_(false), |
81 attached_to_window_(false), | 85 attached_to_window_(false), |
82 hardware_enabled_(false), | 86 hardware_enabled_(false), |
83 dip_scale_(0.0), | 87 dip_scale_(0.0), |
84 page_scale_factor_(1.0), | 88 page_scale_factor_(1.0), |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 | 208 |
205 // Perform a software draw | 209 // Perform a software draw |
206 return OnDrawSoftware(java_canvas); | 210 return OnDrawSoftware(java_canvas); |
207 } | 211 } |
208 | 212 |
209 bool BrowserViewRenderer::OnDrawHardware(jobject java_canvas) { | 213 bool BrowserViewRenderer::OnDrawHardware(jobject java_canvas) { |
210 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware"); | 214 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware"); |
211 if (!compositor_) | 215 if (!compositor_) |
212 return false; | 216 return false; |
213 | 217 |
214 shared_renderer_state_->SetScrollOffset(last_on_draw_scroll_offset_); | 218 proxy_->SetScrollOffset(last_on_draw_scroll_offset_); |
215 | 219 |
216 if (!hardware_enabled_) { | 220 if (!hardware_enabled_) { |
217 hardware_enabled_ = compositor_->InitializeHwDraw(); | 221 hardware_enabled_ = compositor_->InitializeHwDraw(); |
218 if (hardware_enabled_) { | 222 if (hardware_enabled_) { |
219 tile_manager_key_ = GlobalTileManager::GetInstance()->PushBack(this); | 223 tile_manager_key_ = GlobalTileManager::GetInstance()->PushBack(this); |
220 } | 224 } |
221 } | 225 } |
222 if (!hardware_enabled_) | 226 if (!hardware_enabled_) |
223 return false; | 227 return false; |
224 | 228 |
225 if (last_on_draw_global_visible_rect_.IsEmpty() && | 229 if (last_on_draw_global_visible_rect_.IsEmpty() && |
226 parent_draw_constraints_.surface_rect.IsEmpty()) { | 230 parent_draw_constraints_.surface_rect.IsEmpty()) { |
227 TRACE_EVENT_INSTANT0("android_webview", | 231 TRACE_EVENT_INSTANT0("android_webview", |
228 "EarlyOut_EmptyVisibleRect", | 232 "EarlyOut_EmptyVisibleRect", |
229 TRACE_EVENT_SCOPE_THREAD); | 233 TRACE_EVENT_SCOPE_THREAD); |
230 shared_renderer_state_->SetForceInvalidateOnNextDrawGL(true); | 234 proxy_->SetForceInvalidateOnNextDrawGL(true); |
231 return client_->RequestDrawGL(java_canvas, false); | 235 return gl_methods_->RequestDrawGL(java_canvas, false); |
232 } | 236 } |
233 | 237 |
234 ReturnResourceFromParent(); | 238 ReturnResourceFromParent(); |
235 if (shared_renderer_state_->HasCompositorFrame()) { | 239 if (proxy_->HasCompositorFrame()) { |
236 TRACE_EVENT_INSTANT0("android_webview", | 240 TRACE_EVENT_INSTANT0("android_webview", |
237 "EarlyOut_PreviousFrameUnconsumed", | 241 "EarlyOut_PreviousFrameUnconsumed", |
238 TRACE_EVENT_SCOPE_THREAD); | 242 TRACE_EVENT_SCOPE_THREAD); |
239 DidSkipCompositeInDraw(); | 243 DidSkipCompositeInDraw(); |
240 return client_->RequestDrawGL(java_canvas, false); | 244 return gl_methods_->RequestDrawGL(java_canvas, false); |
241 } | 245 } |
242 | 246 |
243 scoped_ptr<cc::CompositorFrame> frame = CompositeHw(); | 247 scoped_ptr<cc::CompositorFrame> frame = CompositeHw(); |
244 if (!frame.get()) | 248 if (!frame.get()) |
245 return false; | 249 return false; |
246 | 250 |
247 shared_renderer_state_->SetCompositorFrame(frame.Pass(), false); | 251 proxy_->SetCompositorFrame(frame.Pass(), false); |
248 GlobalTileManager::GetInstance()->DidUse(tile_manager_key_); | 252 GlobalTileManager::GetInstance()->DidUse(tile_manager_key_); |
249 return client_->RequestDrawGL(java_canvas, false); | 253 return gl_methods_->RequestDrawGL(java_canvas, false); |
250 } | 254 } |
251 | 255 |
252 scoped_ptr<cc::CompositorFrame> BrowserViewRenderer::CompositeHw() { | 256 scoped_ptr<cc::CompositorFrame> BrowserViewRenderer::CompositeHw() { |
253 SynchronousCompositorMemoryPolicy new_policy = CalculateDesiredMemoryPolicy(); | 257 SynchronousCompositorMemoryPolicy new_policy = CalculateDesiredMemoryPolicy(); |
254 RequestMemoryPolicy(new_policy); | 258 RequestMemoryPolicy(new_policy); |
255 compositor_->SetMemoryPolicy(memory_policy_); | 259 compositor_->SetMemoryPolicy(memory_policy_); |
256 | 260 |
257 parent_draw_constraints_ = shared_renderer_state_->ParentDrawConstraints(); | 261 parent_draw_constraints_ = proxy_->GetParentDrawConstraints(); |
258 gfx::Size surface_size(width_, height_); | 262 gfx::Size surface_size(width_, height_); |
259 gfx::Rect viewport(surface_size); | 263 gfx::Rect viewport(surface_size); |
260 gfx::Rect clip = viewport; | 264 gfx::Rect clip = viewport; |
261 gfx::Transform transform_for_tile_priority = | 265 gfx::Transform transform_for_tile_priority = |
262 parent_draw_constraints_.transform; | 266 parent_draw_constraints_.transform; |
263 | 267 |
264 // If the WebView is on a layer, WebView does not know what transform is | 268 // If the WebView is on a layer, WebView does not know what transform is |
265 // applied onto the layer so global visible rect does not make sense here. | 269 // applied onto the layer so global visible rect does not make sense here. |
266 // In this case, just use the surface rect for tiling. | 270 // In this case, just use the surface rect for tiling. |
267 gfx::Rect viewport_rect_for_tile_priority; | 271 gfx::Rect viewport_rect_for_tile_priority; |
268 if (parent_draw_constraints_.is_layer || | 272 if (parent_draw_constraints_.is_layer || |
269 last_on_draw_global_visible_rect_.IsEmpty()) { | 273 last_on_draw_global_visible_rect_.IsEmpty()) { |
270 viewport_rect_for_tile_priority = parent_draw_constraints_.surface_rect; | 274 viewport_rect_for_tile_priority = parent_draw_constraints_.surface_rect; |
271 } else { | 275 } else { |
272 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; | 276 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; |
273 } | 277 } |
274 | 278 |
275 scoped_ptr<cc::CompositorFrame> frame = | 279 scoped_ptr<cc::CompositorFrame> frame = |
276 compositor_->DemandDrawHw(surface_size, | 280 compositor_->DemandDrawHw(surface_size, |
277 gfx::Transform(), | 281 gfx::Transform(), |
278 viewport, | 282 viewport, |
279 clip, | 283 clip, |
280 viewport_rect_for_tile_priority, | 284 viewport_rect_for_tile_priority, |
281 transform_for_tile_priority); | 285 transform_for_tile_priority); |
282 if (frame.get()) | 286 if (frame.get()) |
283 DidComposite(); | 287 DidComposite(); |
284 return frame.Pass(); | 288 return frame.Pass(); |
285 } | 289 } |
286 | 290 |
287 void BrowserViewRenderer::UpdateParentDrawConstraints() { | 291 void BrowserViewRenderer::SetParentDrawConstraints() { |
288 // Post an invalidate if the parent draw constraints are stale and there is | 292 // Post an invalidate if the parent draw constraints are stale and there is |
289 // no pending invalidate. | 293 // no pending invalidate. |
290 bool needs_force_invalidate = | 294 bool needs_force_invalidate = proxy_->NeedsForceInvalidateOnNextDrawGL(); |
291 shared_renderer_state_->NeedsForceInvalidateOnNextDrawGL(); | |
292 if (needs_force_invalidate || | 295 if (needs_force_invalidate || |
293 !parent_draw_constraints_.Equals( | 296 !parent_draw_constraints_.Equals(proxy_->GetParentDrawConstraints())) { |
294 shared_renderer_state_->ParentDrawConstraints())) { | 297 proxy_->SetForceInvalidateOnNextDrawGL(false); |
295 shared_renderer_state_->SetForceInvalidateOnNextDrawGL(false); | |
296 EnsureContinuousInvalidation(true, needs_force_invalidate); | 298 EnsureContinuousInvalidation(true, needs_force_invalidate); |
297 } | 299 } |
298 } | 300 } |
299 | 301 |
300 void BrowserViewRenderer::ReturnUnusedResource( | |
301 scoped_ptr<cc::CompositorFrame> frame) { | |
302 if (!frame.get()) | |
303 return; | |
304 | |
305 cc::CompositorFrameAck frame_ack; | |
306 cc::TransferableResource::ReturnResources( | |
307 frame->delegated_frame_data->resource_list, &frame_ack.resources); | |
308 if (compositor_ && !frame_ack.resources.empty()) | |
309 compositor_->ReturnResources(frame_ack); | |
310 } | |
311 | |
312 void BrowserViewRenderer::ReturnResourceFromParent() { | 302 void BrowserViewRenderer::ReturnResourceFromParent() { |
313 cc::CompositorFrameAck frame_ack; | 303 cc::CompositorFrameAck frame_ack; |
314 shared_renderer_state_->SwapReturnedResources(&frame_ack.resources); | 304 proxy_->SwapReturnedResources(&frame_ack.resources); |
315 if (compositor_ && !frame_ack.resources.empty()) { | 305 if (compositor_ && !frame_ack.resources.empty()) { |
316 compositor_->ReturnResources(frame_ack); | 306 compositor_->ReturnResources(frame_ack); |
317 } | 307 } |
318 } | 308 } |
319 | 309 |
320 void BrowserViewRenderer::DidSkipCommitFrame() { | 310 void BrowserViewRenderer::DidSkipCommitFrame() { |
321 // Treat it the same way as skipping onDraw. | 311 // Treat it the same way as skipping onDraw. |
322 DidSkipCompositeInDraw(); | 312 DidSkipCompositeInDraw(); |
323 } | 313 } |
324 | 314 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
437 } | 427 } |
438 | 428 |
439 void BrowserViewRenderer::OnDetachedFromWindow() { | 429 void BrowserViewRenderer::OnDetachedFromWindow() { |
440 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDetachedFromWindow"); | 430 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDetachedFromWindow"); |
441 attached_to_window_ = false; | 431 attached_to_window_ = false; |
442 DCHECK(!hardware_enabled_); | 432 DCHECK(!hardware_enabled_); |
443 } | 433 } |
444 | 434 |
445 void BrowserViewRenderer::ReleaseHardware() { | 435 void BrowserViewRenderer::ReleaseHardware() { |
446 DCHECK(hardware_enabled_); | 436 DCHECK(hardware_enabled_); |
447 ReturnUnusedResource(shared_renderer_state_->PassCompositorFrame()); | 437 // Unused resource held by proxy_ will be returned by the proxy. |
boliu
2014/10/23 16:40:05
Can we not do this in this CL?
If there's somethi
hush (inactive)
2014/10/24 21:31:33
I put this back. I guess I will do this in part 2,
| |
448 ReturnResourceFromParent(); | 438 ReturnResourceFromParent(); |
449 DCHECK(shared_renderer_state_->ReturnedResourcesEmpty()); | |
450 | 439 |
451 if (compositor_) { | 440 if (compositor_) { |
452 compositor_->ReleaseHwDraw(); | 441 compositor_->ReleaseHwDraw(); |
453 SynchronousCompositorMemoryPolicy zero_policy; | 442 SynchronousCompositorMemoryPolicy zero_policy; |
454 RequestMemoryPolicy(zero_policy); | 443 RequestMemoryPolicy(zero_policy); |
455 } | 444 } |
456 | 445 |
457 hardware_enabled_ = false; | 446 hardware_enabled_ = false; |
458 GlobalTileManager::GetInstance()->Remove(tile_manager_key_); | 447 GlobalTileManager::GetInstance()->Remove(tile_manager_key_); |
459 } | 448 } |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
736 "compositor_needs_continuous_invalidate_", | 725 "compositor_needs_continuous_invalidate_", |
737 compositor_needs_continuous_invalidate_); | 726 compositor_needs_continuous_invalidate_); |
738 | 727 |
739 // This should only be called if OnDraw or DrawGL did not come in time, which | 728 // This should only be called if OnDraw or DrawGL did not come in time, which |
740 // means block_invalidates_ must still be true. | 729 // means block_invalidates_ must still be true. |
741 DCHECK(block_invalidates_); | 730 DCHECK(block_invalidates_); |
742 fallback_tick_pending_ = false; | 731 fallback_tick_pending_ = false; |
743 if (compositor_needs_continuous_invalidate_ && compositor_) { | 732 if (compositor_needs_continuous_invalidate_ && compositor_) { |
744 if (hardware_enabled_) { | 733 if (hardware_enabled_) { |
745 ReturnResourceFromParent(); | 734 ReturnResourceFromParent(); |
746 ReturnUnusedResource(shared_renderer_state_->PassCompositorFrame()); | |
747 scoped_ptr<cc::CompositorFrame> frame = CompositeHw(); | 735 scoped_ptr<cc::CompositorFrame> frame = CompositeHw(); |
748 if (frame.get()) { | 736 if (frame.get()) { |
749 shared_renderer_state_->SetCompositorFrame(frame.Pass(), true); | 737 // The resources in the current uncommitted frame held by |
738 // BrowserViewRendererProxy will be | |
739 // returned by BrowserViewRenderProxy | |
740 proxy_->SetCompositorFrame(frame.Pass(), true); | |
750 } | 741 } |
751 } else { | 742 } else { |
752 ForceFakeCompositeSW(); | 743 ForceFakeCompositeSW(); |
753 } | 744 } |
754 } else { | 745 } else { |
755 // Pretend we just composited to unblock further invalidates. | 746 // Pretend we just composited to unblock further invalidates. |
756 DidComposite(); | 747 DidComposite(); |
757 } | 748 } |
758 } | 749 } |
759 | 750 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
808 base::StringAppendF(&str, | 799 base::StringAppendF(&str, |
809 "overscroll_rounding_error_: %s ", | 800 "overscroll_rounding_error_: %s ", |
810 overscroll_rounding_error_.ToString().c_str()); | 801 overscroll_rounding_error_.ToString().c_str()); |
811 base::StringAppendF( | 802 base::StringAppendF( |
812 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); | 803 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); |
813 base::StringAppendF(&str, "clear_view: %d ", clear_view_); | 804 base::StringAppendF(&str, "clear_view: %d ", clear_view_); |
814 return str; | 805 return str; |
815 } | 806 } |
816 | 807 |
817 } // namespace android_webview | 808 } // namespace android_webview |
OLD | NEW |