Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_host_view_android.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
| 6 | 6 |
| 7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 if (!host_ || host_->is_hidden() || !IsSurfaceAvailableForCopy()) { | 545 if (!host_ || host_->is_hidden() || !IsSurfaceAvailableForCopy()) { |
| 546 result_callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); | 546 result_callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); |
| 547 return; | 547 return; |
| 548 } | 548 } |
| 549 gfx::Size bounds = current_surface_size_; | 549 gfx::Size bounds = current_surface_size_; |
| 550 if (src_subrect.IsEmpty()) | 550 if (src_subrect.IsEmpty()) |
| 551 src_subrect = gfx::Rect(bounds); | 551 src_subrect = gfx::Rect(bounds); |
| 552 DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width()); | 552 DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width()); |
| 553 DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height()); | 553 DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height()); |
| 554 const display::Display& display = | 554 const display::Display& display = |
| 555 display::Screen::GetScreen()->GetDisplayNearestWindow(GetNativeView()); | 555 display::Screen::GetScreen()->GetDisplayNearestWindow( |
| 556 GetNativeView()->GetWindowAndroid()); | |
| 556 float device_scale_factor = display.device_scale_factor(); | 557 float device_scale_factor = display.device_scale_factor(); |
| 557 DCHECK_GT(device_scale_factor, 0); | 558 DCHECK_GT(device_scale_factor, 0); |
| 558 gfx::Size dst_size( | 559 gfx::Size dst_size( |
| 559 gfx::ScaleToCeiledSize(src_subrect.size(), scale / device_scale_factor)); | 560 gfx::ScaleToCeiledSize(src_subrect.size(), scale / device_scale_factor)); |
| 560 src_subrect = gfx::ConvertRectToDIP(device_scale_factor, src_subrect); | 561 src_subrect = gfx::ConvertRectToDIP(device_scale_factor, src_subrect); |
| 561 | 562 |
| 562 CopyFromCompositingSurface(src_subrect, dst_size, result_callback, | 563 CopyFromCompositingSurface(src_subrect, dst_size, result_callback, |
| 563 preferred_color_type); | 564 preferred_color_type); |
| 564 } | 565 } |
| 565 | 566 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 659 if (!content_view_core_) | 660 if (!content_view_core_) |
| 660 return default_bounds_.size(); | 661 return default_bounds_.size(); |
| 661 | 662 |
| 662 return content_view_core_->GetViewSize(); | 663 return content_view_core_->GetViewSize(); |
| 663 } | 664 } |
| 664 | 665 |
| 665 gfx::Size RenderWidgetHostViewAndroid::GetPhysicalBackingSize() const { | 666 gfx::Size RenderWidgetHostViewAndroid::GetPhysicalBackingSize() const { |
| 666 if (!content_view_core_) { | 667 if (!content_view_core_) { |
| 667 if (default_bounds_.IsEmpty()) return gfx::Size(); | 668 if (default_bounds_.IsEmpty()) return gfx::Size(); |
| 668 | 669 |
| 669 return gfx::Size(default_bounds_.right() | 670 return gfx::Size(default_bounds_.right() * GetScaleFactorForNativeView(), |
|
tapted
2017/02/15 00:36:10
gfx::ScaleToFlooredSize() ?
Jinsuk Kim
2017/02/16 10:11:25
Done.
| |
| 670 * ui::GetScaleFactorForNativeView(GetNativeView()), | 671 default_bounds_.bottom() * GetScaleFactorForNativeView()); |
| 671 default_bounds_.bottom() | |
| 672 * ui::GetScaleFactorForNativeView(GetNativeView())); | |
| 673 } | 672 } |
| 674 | 673 |
| 675 return content_view_core_->GetPhysicalBackingSize(); | 674 return content_view_core_->GetPhysicalBackingSize(); |
| 676 } | 675 } |
| 677 | 676 |
| 678 bool RenderWidgetHostViewAndroid::DoBrowserControlsShrinkBlinkSize() const { | 677 bool RenderWidgetHostViewAndroid::DoBrowserControlsShrinkBlinkSize() const { |
| 679 // Whether or not Blink's viewport size should be shrunk by the height of the | 678 // Whether or not Blink's viewport size should be shrunk by the height of the |
| 680 // URL-bar. | 679 // URL-bar. |
| 681 return content_view_core_ && | 680 return content_view_core_ && |
| 682 content_view_core_->DoBrowserControlsShrinkBlinkSize(); | 681 content_view_core_->DoBrowserControlsShrinkBlinkSize(); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 941 callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); | 940 callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); |
| 942 return; | 941 return; |
| 943 } | 942 } |
| 944 if (!(view_.GetWindowAndroid())) { | 943 if (!(view_.GetWindowAndroid())) { |
| 945 callback.Run(SkBitmap(), READBACK_FAILED); | 944 callback.Run(SkBitmap(), READBACK_FAILED); |
| 946 return; | 945 return; |
| 947 } | 946 } |
| 948 | 947 |
| 949 base::TimeTicks start_time = base::TimeTicks::Now(); | 948 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 950 const display::Display& display = | 949 const display::Display& display = |
| 951 display::Screen::GetScreen()->GetDisplayNearestWindow(GetNativeView()); | 950 display::Screen::GetScreen()->GetDisplayNearestWindow( |
| 951 GetNativeView()->GetWindowAndroid()); | |
| 952 float device_scale_factor = display.device_scale_factor(); | 952 float device_scale_factor = display.device_scale_factor(); |
| 953 gfx::Size dst_size_in_pixel = | 953 gfx::Size dst_size_in_pixel = |
| 954 gfx::ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); | 954 gfx::ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); |
| 955 gfx::Rect src_subrect_in_pixel = | 955 gfx::Rect src_subrect_in_pixel = |
| 956 gfx::ConvertRectToPixel(device_scale_factor, src_subrect); | 956 gfx::ConvertRectToPixel(device_scale_factor, src_subrect); |
| 957 | 957 |
| 958 if (!using_browser_compositor_) { | 958 if (!using_browser_compositor_) { |
| 959 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, | 959 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, |
| 960 preferred_color_type); | 960 preferred_color_type); |
| 961 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", | 961 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1195 if (!sync_compositor_) | 1195 if (!sync_compositor_) |
| 1196 return nullptr; | 1196 return nullptr; |
| 1197 return std::unique_ptr<ui::TouchHandleDrawable>( | 1197 return std::unique_ptr<ui::TouchHandleDrawable>( |
| 1198 sync_compositor_->client()->CreateDrawable()); | 1198 sync_compositor_->client()->CreateDrawable()); |
| 1199 } | 1199 } |
| 1200 base::android::ScopedJavaLocalRef<jobject> activityContext = | 1200 base::android::ScopedJavaLocalRef<jobject> activityContext = |
| 1201 content_view_core_->GetContext(); | 1201 content_view_core_->GetContext(); |
| 1202 return std::unique_ptr<ui::TouchHandleDrawable>( | 1202 return std::unique_ptr<ui::TouchHandleDrawable>( |
| 1203 new CompositedTouchHandleDrawable( | 1203 new CompositedTouchHandleDrawable( |
| 1204 content_view_core_->GetViewAndroid()->GetLayer(), | 1204 content_view_core_->GetViewAndroid()->GetLayer(), |
| 1205 ui::GetScaleFactorForNativeView(GetNativeView()), | 1205 GetScaleFactorForNativeView(), |
| 1206 // Use the activity context where possible (instead of the application | 1206 // Use the activity context where possible (instead of the application |
| 1207 // context) to ensure proper handle theming. | 1207 // context) to ensure proper handle theming. |
| 1208 activityContext.is_null() ? base::android::GetApplicationContext() | 1208 activityContext.is_null() ? base::android::GetApplicationContext() |
| 1209 : activityContext)); | 1209 : activityContext)); |
| 1210 } | 1210 } |
| 1211 | 1211 |
| 1212 void RenderWidgetHostViewAndroid::SynchronousCopyContents( | 1212 void RenderWidgetHostViewAndroid::SynchronousCopyContents( |
| 1213 const gfx::Rect& src_subrect_in_pixel, | 1213 const gfx::Rect& src_subrect_in_pixel, |
| 1214 const gfx::Size& dst_size_in_pixel, | 1214 const gfx::Size& dst_size_in_pixel, |
| 1215 const ReadbackRequestCallback& callback, | 1215 const ReadbackRequestCallback& callback, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1271 selection_controller_->OnViewportChanged(viewport_rect); | 1271 selection_controller_->OnViewportChanged(viewport_rect); |
| 1272 } | 1272 } |
| 1273 | 1273 |
| 1274 UpdateBackgroundColor(is_transparent ? SK_ColorTRANSPARENT | 1274 UpdateBackgroundColor(is_transparent ? SK_ColorTRANSPARENT |
| 1275 : frame_metadata.root_background_color); | 1275 : frame_metadata.root_background_color); |
| 1276 | 1276 |
| 1277 view_.set_content_offset(gfx::Vector2dF(0.0f, | 1277 view_.set_content_offset(gfx::Vector2dF(0.0f, |
| 1278 frame_metadata.top_controls_height * | 1278 frame_metadata.top_controls_height * |
| 1279 frame_metadata.top_controls_shown_ratio)); | 1279 frame_metadata.top_controls_shown_ratio)); |
| 1280 | 1280 |
| 1281 float dip_scale = ui::GetScaleFactorForNativeView(GetNativeView()); | 1281 float dip_scale = GetScaleFactorForNativeView(); |
| 1282 float top_controls_pix = frame_metadata.top_controls_height * dip_scale; | 1282 float top_controls_pix = frame_metadata.top_controls_height * dip_scale; |
| 1283 float top_shown_pix = top_controls_pix | 1283 float top_shown_pix = top_controls_pix |
| 1284 * frame_metadata.top_controls_shown_ratio; | 1284 * frame_metadata.top_controls_shown_ratio; |
| 1285 bool top_changed = !FloatEquals(top_shown_pix, prev_top_shown_pix_); | 1285 bool top_changed = !FloatEquals(top_shown_pix, prev_top_shown_pix_); |
| 1286 | 1286 |
| 1287 float bottom_controls_pix = frame_metadata.bottom_controls_height * dip_scale; | 1287 float bottom_controls_pix = frame_metadata.bottom_controls_height * dip_scale; |
| 1288 float bottom_shown_pix = bottom_controls_pix | 1288 float bottom_shown_pix = bottom_controls_pix |
| 1289 * frame_metadata.bottom_controls_shown_ratio; | 1289 * frame_metadata.bottom_controls_shown_ratio; |
| 1290 bool bottom_changed = !FloatEquals(bottom_shown_pix, prev_bottom_shown_pix_); | 1290 bool bottom_changed = !FloatEquals(bottom_shown_pix, prev_bottom_shown_pix_); |
| 1291 | 1291 |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1993 // OverscrollController. | 1993 // OverscrollController. |
| 1994 ui::WindowAndroid* window_android = content_view_core_->GetWindowAndroid(); | 1994 ui::WindowAndroid* window_android = content_view_core_->GetWindowAndroid(); |
| 1995 if (!window_android) | 1995 if (!window_android) |
| 1996 return; | 1996 return; |
| 1997 | 1997 |
| 1998 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); | 1998 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); |
| 1999 if (!compositor) | 1999 if (!compositor) |
| 2000 return; | 2000 return; |
| 2001 | 2001 |
| 2002 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( | 2002 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( |
| 2003 overscroll_refresh_handler, compositor, | 2003 overscroll_refresh_handler, compositor, GetScaleFactorForNativeView()); |
| 2004 ui::GetScaleFactorForNativeView(GetNativeView())); | |
| 2005 } | 2004 } |
| 2006 | 2005 |
| 2007 } // namespace content | 2006 } // namespace content |
| OLD | NEW |