OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/in_process_view_renderer.h" | 5 #include "android_webview/browser/in_process_view_renderer.h" |
6 | 6 |
7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
8 | 8 |
9 #include "android_webview/public/browser/draw_gl.h" | 9 #include "android_webview/public/browser/draw_gl.h" |
10 #include "android_webview/public/browser/draw_sw.h" | 10 #include "android_webview/public/browser/draw_sw.h" |
11 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "content/public/browser/android/content_view_core.h" | 15 #include "content/public/browser/android/content_view_core.h" |
16 #include "content/public/browser/android/synchronous_compositor.h" | 16 #include "content/public/browser/android/synchronous_compositor.h" |
17 #include "content/public/browser/render_view_host.h" | 17 #include "content/public/browser/render_view_host.h" |
18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
19 #include "skia/ext/refptr.h" | 19 #include "skia/ext/refptr.h" |
20 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
21 #include "third_party/skia/include/core/SkCanvas.h" | 21 #include "third_party/skia/include/core/SkCanvas.h" |
22 #include "third_party/skia/include/core/SkDevice.h" | 22 #include "third_party/skia/include/core/SkDevice.h" |
23 #include "third_party/skia/include/core/SkGraphics.h" | 23 #include "third_party/skia/include/core/SkGraphics.h" |
24 #include "third_party/skia/include/core/SkPicture.h" | 24 #include "third_party/skia/include/core/SkPicture.h" |
25 #include "ui/gfx/size_conversions.h" | 25 #include "ui/gfx/size_conversions.h" |
26 #include "ui/gfx/skia_util.h" | 26 #include "ui/gfx/skia_util.h" |
27 #include "ui/gfx/transform.h" | 27 #include "ui/gfx/transform.h" |
| 28 #include "ui/gfx/vector2d_conversions.h" |
28 #include "ui/gfx/vector2d_f.h" | 29 #include "ui/gfx/vector2d_f.h" |
29 #include "ui/gl/gl_bindings.h" | 30 #include "ui/gl/gl_bindings.h" |
30 | 31 |
31 // TODO(leandrogracia): Borrowed from gl2ext.h. Cannot be included due to | 32 // TODO(leandrogracia): Borrowed from gl2ext.h. Cannot be included due to |
32 // conflicts with gl_bindings.h and the EGL library methods | 33 // conflicts with gl_bindings.h and the EGL library methods |
33 // (eglGetCurrentContext). | 34 // (eglGetCurrentContext). |
34 #ifndef GL_TEXTURE_EXTERNAL_OES | 35 #ifndef GL_TEXTURE_EXTERNAL_OES |
35 #define GL_TEXTURE_EXTERNAL_OES 0x8D65 | 36 #define GL_TEXTURE_EXTERNAL_OES 0x8D65 |
36 #endif | 37 #endif |
37 | 38 |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 | 300 |
300 InProcessViewRenderer::InProcessViewRenderer( | 301 InProcessViewRenderer::InProcessViewRenderer( |
301 BrowserViewRenderer::Client* client, | 302 BrowserViewRenderer::Client* client, |
302 JavaHelper* java_helper, | 303 JavaHelper* java_helper, |
303 content::WebContents* web_contents) | 304 content::WebContents* web_contents) |
304 : client_(client), | 305 : client_(client), |
305 java_helper_(java_helper), | 306 java_helper_(java_helper), |
306 web_contents_(web_contents), | 307 web_contents_(web_contents), |
307 compositor_(NULL), | 308 compositor_(NULL), |
308 view_visible_(false), | 309 view_visible_(false), |
| 310 dip_scale_(0.0), |
309 continuous_invalidate_(false), | 311 continuous_invalidate_(false), |
310 block_invalidates_(false), | 312 block_invalidates_(false), |
311 width_(0), | 313 width_(0), |
312 height_(0), | 314 height_(0), |
313 attached_to_window_(false), | 315 attached_to_window_(false), |
314 hardware_initialized_(false), | 316 hardware_initialized_(false), |
315 hardware_failed_(false), | 317 hardware_failed_(false), |
316 last_egl_context_(NULL) { | 318 last_egl_context_(NULL) { |
317 CHECK(web_contents_); | 319 CHECK(web_contents_); |
318 web_contents_->SetUserData(kUserDataKey, new UserData(this)); | 320 web_contents_->SetUserData(kUserDataKey, new UserData(this)); |
(...skipping 15 matching lines...) Expand all Loading... |
334 return UserData::GetInstance(contents); | 336 return UserData::GetInstance(contents); |
335 } | 337 } |
336 | 338 |
337 void InProcessViewRenderer::WebContentsGone() { | 339 void InProcessViewRenderer::WebContentsGone() { |
338 web_contents_ = NULL; | 340 web_contents_ = NULL; |
339 compositor_ = NULL; | 341 compositor_ = NULL; |
340 } | 342 } |
341 | 343 |
342 bool InProcessViewRenderer::OnDraw(jobject java_canvas, | 344 bool InProcessViewRenderer::OnDraw(jobject java_canvas, |
343 bool is_hardware_canvas, | 345 bool is_hardware_canvas, |
344 const gfx::Point& scroll, | 346 const gfx::Vector2d& scroll, |
345 const gfx::Rect& clip) { | 347 const gfx::Rect& clip) { |
346 scroll_at_start_of_frame_ = scroll; | 348 scroll_at_start_of_frame_ = scroll; |
347 if (is_hardware_canvas && attached_to_window_ && compositor_ && | 349 if (is_hardware_canvas && attached_to_window_ && compositor_ && |
348 HardwareEnabled() && client_->RequestDrawGL(java_canvas)) { | 350 HardwareEnabled() && client_->RequestDrawGL(java_canvas)) { |
349 // All set: we'll get a call on DrawGL when the time comes. | 351 // All set: we'll get a call on DrawGL when the time comes. |
350 return true; | 352 return true; |
351 } | 353 } |
352 // Perform a software draw | 354 // Perform a software draw |
353 block_invalidates_ = true; | 355 block_invalidates_ = true; |
354 bool result = DrawSWInternal(java_canvas, clip); | 356 bool result = DrawSWInternal(java_canvas, clip); |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 TRACE_EVENT_INSTANT1("android_webview", | 638 TRACE_EVENT_INSTANT1("android_webview", |
637 "InProcessViewRenderer::SetContinuousInvalidate", | 639 "InProcessViewRenderer::SetContinuousInvalidate", |
638 TRACE_EVENT_SCOPE_THREAD, | 640 TRACE_EVENT_SCOPE_THREAD, |
639 "invalidate", | 641 "invalidate", |
640 invalidate); | 642 invalidate); |
641 continuous_invalidate_ = invalidate; | 643 continuous_invalidate_ = invalidate; |
642 // TODO(boliu): Handle if not attached to window case. | 644 // TODO(boliu): Handle if not attached to window case. |
643 EnsureContinuousInvalidation(NULL); | 645 EnsureContinuousInvalidation(NULL); |
644 } | 646 } |
645 | 647 |
| 648 void InProcessViewRenderer::SetDipScale(float dip_scale) { |
| 649 dip_scale_ = dip_scale; |
| 650 CHECK(dip_scale_ > 0); |
| 651 } |
| 652 |
| 653 void InProcessViewRenderer::ScrollTo(gfx::Vector2d new_value) { |
| 654 DCHECK(dip_scale_ > 0); |
| 655 // In general we don't guarantee that the scroll offset transforms are |
| 656 // symmetrical. That is if scrolling from JS to offset1 results in a native |
| 657 // offset2 then scrolling from UI to offset2 results in JS being scrolled to |
| 658 // offset1 again. |
| 659 // The reason we explicitly do rounding here is that it seems to yeld the |
| 660 // most stabile transformation. |
| 661 gfx::Vector2dF new_value_css = gfx::ToRoundedVector2d( |
| 662 gfx::ScaleVector2d(new_value, 1.0f / dip_scale_)); |
| 663 |
| 664 DCHECK(scroll_offset_css_ != new_value_css); |
| 665 |
| 666 scroll_offset_css_ = new_value_css; |
| 667 |
| 668 if (compositor_) |
| 669 compositor_->DidChangeRootLayerScrollOffset(); |
| 670 } |
| 671 |
646 void InProcessViewRenderer::SetTotalRootLayerScrollOffset( | 672 void InProcessViewRenderer::SetTotalRootLayerScrollOffset( |
647 gfx::Vector2dF new_value) { | 673 gfx::Vector2dF new_value_css) { |
648 // TODO(mkosiba): Plumb this all the way through to the view. | 674 // TOOD(mkosiba): Add a DCHECK to say that this does _not_ get called during |
649 scroll_offset_ = new_value; | 675 // DrawGl when http://crbug.com/249972 is fixed. |
| 676 if (scroll_offset_css_ == new_value_css) |
| 677 return; |
| 678 |
| 679 scroll_offset_css_ = new_value_css; |
| 680 |
| 681 DCHECK(dip_scale_ > 0); |
| 682 |
| 683 gfx::Vector2d scroll_offset = |
| 684 gfx::ToRoundedVector2d(gfx::ScaleVector2d(new_value_css, dip_scale_)); |
| 685 |
| 686 client_->ScrollContainerViewTo(scroll_offset); |
650 } | 687 } |
651 | 688 |
652 gfx::Vector2dF InProcessViewRenderer::GetTotalRootLayerScrollOffset() { | 689 gfx::Vector2dF InProcessViewRenderer::GetTotalRootLayerScrollOffset() { |
653 return scroll_offset_; | 690 return scroll_offset_css_; |
654 } | 691 } |
655 | 692 |
656 void InProcessViewRenderer::EnsureContinuousInvalidation( | 693 void InProcessViewRenderer::EnsureContinuousInvalidation( |
657 AwDrawGLInfo* draw_info) { | 694 AwDrawGLInfo* draw_info) { |
658 if (continuous_invalidate_ && !block_invalidates_) { | 695 if (continuous_invalidate_ && !block_invalidates_) { |
659 if (draw_info) { | 696 if (draw_info) { |
660 draw_info->dirty_left = draw_info->clip_left; | 697 draw_info->dirty_left = draw_info->clip_left; |
661 draw_info->dirty_top = draw_info->clip_top; | 698 draw_info->dirty_top = draw_info->clip_top; |
662 draw_info->dirty_right = draw_info->clip_right; | 699 draw_info->dirty_right = draw_info->clip_right; |
663 draw_info->dirty_bottom = draw_info->clip_bottom; | 700 draw_info->dirty_bottom = draw_info->clip_bottom; |
664 draw_info->status_mask |= AwDrawGLInfo::kStatusMaskDraw; | 701 draw_info->status_mask |= AwDrawGLInfo::kStatusMaskDraw; |
665 } else { | 702 } else { |
666 client_->PostInvalidate(); | 703 client_->PostInvalidate(); |
667 } | 704 } |
668 block_invalidates_ = true; | 705 block_invalidates_ = true; |
669 } | 706 } |
670 } | 707 } |
671 | 708 |
672 bool InProcessViewRenderer::RenderSW(SkCanvas* canvas) { | 709 bool InProcessViewRenderer::RenderSW(SkCanvas* canvas) { |
673 // TODO(joth): BrowserViewRendererImpl had a bunch of logic for dpi and page | 710 // TODO(joth): BrowserViewRendererImpl had a bunch of logic for dpi and page |
674 // scale here. Determine what if any needs bringing over to this class. | 711 // scale here. Determine what if any needs bringing over to this class. |
675 return CompositeSW(canvas); | 712 return CompositeSW(canvas); |
676 } | 713 } |
677 | 714 |
678 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) { | 715 bool InProcessViewRenderer::CompositeSW(SkCanvas* canvas) { |
679 return compositor_ && compositor_->DemandDrawSw(canvas); | 716 return compositor_ && compositor_->DemandDrawSw(canvas); |
680 } | 717 } |
681 | 718 |
682 } // namespace android_webview | 719 } // namespace android_webview |
OLD | NEW |