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 "android_webview/browser/browser_view_renderer_client.h" | 7 #include "android_webview/browser/browser_view_renderer_client.h" |
| 8 #include "android_webview/browser/shared_renderer_state.h" | 8 #include "android_webview/browser/shared_renderer_state.h" |
| 9 #include "android_webview/public/browser/draw_gl.h" | 9 #include "android_webview/public/browser/draw_gl.h" |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 TRACE_EVENT0("android_webview", "BrowserViewRenderer::CapturePicture"); | 286 TRACE_EVENT0("android_webview", "BrowserViewRenderer::CapturePicture"); |
| 287 | 287 |
| 288 // Return empty Picture objects for empty SkPictures. | 288 // Return empty Picture objects for empty SkPictures. |
| 289 if (width <= 0 || height <= 0) { | 289 if (width <= 0 || height <= 0) { |
| 290 return skia::AdoptRef(new SkPicture); | 290 return skia::AdoptRef(new SkPicture); |
| 291 } | 291 } |
| 292 | 292 |
| 293 // Reset scroll back to the origin, will go back to the old | 293 // Reset scroll back to the origin, will go back to the old |
| 294 // value when scroll_reset is out of scope. | 294 // value when scroll_reset is out of scope. |
| 295 AutoResetWithLock scroll_reset( | 295 AutoResetWithLock scroll_reset( |
| 296 &scroll_offset_dip_, gfx::Vector2dF(), scroll_offset_dip_lock_); | 296 &scroll_offset_dip_, gfx::Vector2dF(), render_thread_lock_); |
| 297 | 297 |
| 298 SkPictureRecorder recorder; | 298 SkPictureRecorder recorder; |
| 299 SkCanvas* rec_canvas = recorder.beginRecording(width, height, NULL, 0); | 299 SkCanvas* rec_canvas = recorder.beginRecording(width, height, NULL, 0); |
| 300 if (has_compositor_) | 300 if (has_compositor_) |
| 301 CompositeSW(rec_canvas); | 301 CompositeSW(rec_canvas); |
| 302 return skia::AdoptRef(recorder.endRecording()); | 302 return skia::AdoptRef(recorder.endRecording()); |
| 303 } | 303 } |
| 304 | 304 |
| 305 void BrowserViewRenderer::EnableOnNewPicture(bool enabled) { | 305 void BrowserViewRenderer::EnableOnNewPicture(bool enabled) { |
| 306 on_new_picture_enable_ = enabled; | 306 on_new_picture_enable_ = enabled; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 410 void BrowserViewRenderer::DidDestroyCompositor( | 410 void BrowserViewRenderer::DidDestroyCompositor( |
| 411 content::SynchronousCompositor* compositor) { | 411 content::SynchronousCompositor* compositor) { |
| 412 TRACE_EVENT0("android_webview", "BrowserViewRenderer::DidDestroyCompositor"); | 412 TRACE_EVENT0("android_webview", "BrowserViewRenderer::DidDestroyCompositor"); |
| 413 DCHECK(has_compositor_); | 413 DCHECK(has_compositor_); |
| 414 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 414 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 415 has_compositor_ = false; | 415 has_compositor_ = false; |
| 416 shared_renderer_state_->SetCompositorOnUiThread(NULL); | 416 shared_renderer_state_->SetCompositorOnUiThread(NULL); |
| 417 SynchronousCompositorMemoryPolicy zero_policy; | 417 SynchronousCompositorMemoryPolicy zero_policy; |
| 418 DCHECK(shared_renderer_state_->GetMemoryPolicy() == zero_policy); | 418 DCHECK(shared_renderer_state_->GetMemoryPolicy() == zero_policy); |
| 419 } | 419 } |
| 420 | 420 |
|
sgurun-gerrit only
2014/05/05 17:11:01
Please add explanation here why you need to set th
boliu
2014/05/05 17:13:41
There is already a comment in the header saying th
sgurun-gerrit only
2014/05/05 17:24:53
If it is temporary it is ok, otherwise the explana
| |
| 421 void BrowserViewRenderer::SetContinuousInvalidate(bool invalidate) { | 421 void BrowserViewRenderer::SetContinuousInvalidate(bool invalidate) { |
| 422 if (!ui_task_runner_->BelongsToCurrentThread()) { | 422 { |
| 423 ui_task_runner_->PostTask( | 423 base::AutoLock lock(render_thread_lock_); |
| 424 FROM_HERE, | 424 if (compositor_needs_continuous_invalidate_ == invalidate) |
| 425 base::Bind(&BrowserViewRenderer::SetContinuousInvalidate, | 425 return; |
| 426 ui_thread_weak_ptr_, | 426 |
| 427 invalidate)); | 427 TRACE_EVENT_INSTANT1("android_webview", |
| 428 "BrowserViewRenderer::SetContinuousInvalidate", | |
| 429 TRACE_EVENT_SCOPE_THREAD, | |
| 430 "invalidate", | |
| 431 invalidate); | |
| 432 compositor_needs_continuous_invalidate_ = invalidate; | |
| 433 } | |
| 434 | |
| 435 if (ui_task_runner_->BelongsToCurrentThread()) { | |
| 436 EnsureContinuousInvalidation(false); | |
| 428 return; | 437 return; |
| 429 } | 438 } |
| 430 if (compositor_needs_continuous_invalidate_ == invalidate) | 439 ui_task_runner_->PostTask( |
| 431 return; | 440 FROM_HERE, |
| 432 | 441 base::Bind(&BrowserViewRenderer::EnsureContinuousInvalidation, |
| 433 TRACE_EVENT_INSTANT1("android_webview", | 442 ui_thread_weak_ptr_, |
| 434 "BrowserViewRenderer::SetContinuousInvalidate", | 443 false)); |
| 435 TRACE_EVENT_SCOPE_THREAD, | |
| 436 "invalidate", | |
| 437 invalidate); | |
| 438 compositor_needs_continuous_invalidate_ = invalidate; | |
| 439 EnsureContinuousInvalidation(false); | |
| 440 } | 444 } |
| 441 | 445 |
| 442 void BrowserViewRenderer::SetDipScale(float dip_scale) { | 446 void BrowserViewRenderer::SetDipScale(float dip_scale) { |
| 443 dip_scale_ = dip_scale; | 447 dip_scale_ = dip_scale; |
| 444 CHECK(dip_scale_ > 0); | 448 CHECK(dip_scale_ > 0); |
| 445 } | 449 } |
| 446 | 450 |
| 447 gfx::Vector2d BrowserViewRenderer::max_scroll_offset() const { | 451 gfx::Vector2d BrowserViewRenderer::max_scroll_offset() const { |
| 448 DCHECK_GT(dip_scale_, 0); | 452 DCHECK_GT(dip_scale_, 0); |
| 449 return gfx::ToCeiledVector2d(gfx::ScaleVector2d( | 453 return gfx::ToCeiledVector2d(gfx::ScaleVector2d( |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 465 scroll_offset_dip.set_y((scroll_offset.y() * max_scroll_offset_dip_.y()) / | 469 scroll_offset_dip.set_y((scroll_offset.y() * max_scroll_offset_dip_.y()) / |
| 466 max_offset.y()); | 470 max_offset.y()); |
| 467 } | 471 } |
| 468 | 472 |
| 469 DCHECK_LE(0, scroll_offset_dip.x()); | 473 DCHECK_LE(0, scroll_offset_dip.x()); |
| 470 DCHECK_LE(0, scroll_offset_dip.y()); | 474 DCHECK_LE(0, scroll_offset_dip.y()); |
| 471 DCHECK_LE(scroll_offset_dip.x(), max_scroll_offset_dip_.x()); | 475 DCHECK_LE(scroll_offset_dip.x(), max_scroll_offset_dip_.x()); |
| 472 DCHECK_LE(scroll_offset_dip.y(), max_scroll_offset_dip_.y()); | 476 DCHECK_LE(scroll_offset_dip.y(), max_scroll_offset_dip_.y()); |
| 473 | 477 |
| 474 { | 478 { |
| 475 base::AutoLock lock(scroll_offset_dip_lock_); | 479 base::AutoLock lock(render_thread_lock_); |
| 476 if (scroll_offset_dip_ == scroll_offset_dip) | 480 if (scroll_offset_dip_ == scroll_offset_dip) |
| 477 return; | 481 return; |
| 478 | 482 |
| 479 scroll_offset_dip_ = scroll_offset_dip; | 483 scroll_offset_dip_ = scroll_offset_dip; |
| 480 } | 484 } |
| 481 | 485 |
| 482 if (has_compositor_) | 486 if (has_compositor_) |
| 483 shared_renderer_state_->GetCompositor()-> | 487 shared_renderer_state_->GetCompositor()-> |
| 484 DidChangeRootLayerScrollOffset(); | 488 DidChangeRootLayerScrollOffset(); |
| 485 } | 489 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 if (!ui_task_runner_->BelongsToCurrentThread()) { | 527 if (!ui_task_runner_->BelongsToCurrentThread()) { |
| 524 ui_task_runner_->PostTask( | 528 ui_task_runner_->PostTask( |
| 525 FROM_HERE, | 529 FROM_HERE, |
| 526 base::Bind(&BrowserViewRenderer::SetTotalRootLayerScrollOffset, | 530 base::Bind(&BrowserViewRenderer::SetTotalRootLayerScrollOffset, |
| 527 ui_thread_weak_ptr_, | 531 ui_thread_weak_ptr_, |
| 528 scroll_offset_dip)); | 532 scroll_offset_dip)); |
| 529 return; | 533 return; |
| 530 } | 534 } |
| 531 | 535 |
| 532 { | 536 { |
| 533 base::AutoLock lock(scroll_offset_dip_lock_); | 537 base::AutoLock lock(render_thread_lock_); |
| 534 // TOOD(mkosiba): Add a DCHECK to say that this does _not_ get called during | 538 // TOOD(mkosiba): Add a DCHECK to say that this does _not_ get called during |
| 535 // DrawGl when http://crbug.com/249972 is fixed. | 539 // DrawGl when http://crbug.com/249972 is fixed. |
| 536 if (scroll_offset_dip_ == scroll_offset_dip) | 540 if (scroll_offset_dip_ == scroll_offset_dip) |
| 537 return; | 541 return; |
| 538 | 542 |
| 539 scroll_offset_dip_ = scroll_offset_dip; | 543 scroll_offset_dip_ = scroll_offset_dip; |
| 540 } | 544 } |
| 541 | 545 |
| 542 gfx::Vector2d max_offset = max_scroll_offset(); | 546 gfx::Vector2d max_offset = max_scroll_offset(); |
| 543 gfx::Vector2d scroll_offset; | 547 gfx::Vector2d scroll_offset; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 557 DCHECK(0 <= scroll_offset.y()); | 561 DCHECK(0 <= scroll_offset.y()); |
| 558 // Disabled because the conditions are being violated while running | 562 // Disabled because the conditions are being violated while running |
| 559 // AwZoomTest.testMagnification, see http://crbug.com/340648 | 563 // AwZoomTest.testMagnification, see http://crbug.com/340648 |
| 560 // DCHECK(scroll_offset.x() <= max_offset.x()); | 564 // DCHECK(scroll_offset.x() <= max_offset.x()); |
| 561 // DCHECK(scroll_offset.y() <= max_offset.y()); | 565 // DCHECK(scroll_offset.y() <= max_offset.y()); |
| 562 | 566 |
| 563 client_->ScrollContainerViewTo(scroll_offset); | 567 client_->ScrollContainerViewTo(scroll_offset); |
| 564 } | 568 } |
| 565 | 569 |
| 566 gfx::Vector2dF BrowserViewRenderer::GetTotalRootLayerScrollOffset() { | 570 gfx::Vector2dF BrowserViewRenderer::GetTotalRootLayerScrollOffset() { |
| 567 base::AutoLock lock(scroll_offset_dip_lock_); | 571 base::AutoLock lock(render_thread_lock_); |
| 568 return scroll_offset_dip_; | 572 return scroll_offset_dip_; |
| 569 } | 573 } |
| 570 | 574 |
| 571 bool BrowserViewRenderer::IsExternalFlingActive() const { | 575 bool BrowserViewRenderer::IsExternalFlingActive() const { |
| 572 if (!ui_task_runner_->BelongsToCurrentThread()) { | 576 if (!ui_task_runner_->BelongsToCurrentThread()) { |
| 573 // TODO(boliu): This is short term hack since we cannot call into | 577 // TODO(boliu): This is short term hack since we cannot call into |
| 574 // view system on non-UI thread. | 578 // view system on non-UI thread. |
| 575 return false; | 579 return false; |
| 576 } | 580 } |
| 577 return client_->IsFlingActive(); | 581 return client_->IsFlingActive(); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 746 base::StringAppendF(&str, | 750 base::StringAppendF(&str, |
| 747 "surface width height: [%d %d] ", | 751 "surface width height: [%d %d] ", |
| 748 draw_info->width, | 752 draw_info->width, |
| 749 draw_info->height); | 753 draw_info->height); |
| 750 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); | 754 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); |
| 751 } | 755 } |
| 752 return str; | 756 return str; |
| 753 } | 757 } |
| 754 | 758 |
| 755 } // namespace android_webview | 759 } // namespace android_webview |
| OLD | NEW |