Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_android.cc

Issue 2734043003: Fix Android tab navigation "stretch" regression. (Closed)
Patch Set: REBASE Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { 540 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) {
541 // Ignore the given size as only the Java code has the power to 541 // Ignore the given size as only the Java code has the power to
542 // resize the view on Android. 542 // resize the view on Android.
543 default_bounds_ = gfx::Rect(default_bounds_.origin(), size); 543 default_bounds_ = gfx::Rect(default_bounds_.origin(), size);
544 } 544 }
545 545
546 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { 546 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) {
547 default_bounds_ = rect; 547 default_bounds_ = rect;
548 } 548 }
549 549
550 void RenderWidgetHostViewAndroid::GetScaledContentBitmap(
551 float scale,
552 SkColorType preferred_color_type,
553 gfx::Rect src_subrect,
554 const ReadbackRequestCallback& result_callback) {
555 if (!host_ || host_->is_hidden() || !IsSurfaceAvailableForCopy()) {
556 result_callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE);
557 return;
558 }
559 gfx::Size bounds = current_surface_size_;
560 if (src_subrect.IsEmpty())
561 src_subrect = gfx::Rect(bounds);
562 DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width());
563 DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height());
564 const display::Display& display =
565 display::Screen::GetScreen()->GetDisplayNearestWindow(GetNativeView());
566 float device_scale_factor = display.device_scale_factor();
567 DCHECK_GT(device_scale_factor, 0);
568 gfx::Size dst_size(
569 gfx::ScaleToCeiledSize(src_subrect.size(), scale / device_scale_factor));
570 src_subrect = gfx::ConvertRectToDIP(device_scale_factor, src_subrect);
571
572 CopyFromSurface(src_subrect, dst_size, result_callback, preferred_color_type);
573 }
574
575 bool RenderWidgetHostViewAndroid::HasValidFrame() const { 550 bool RenderWidgetHostViewAndroid::HasValidFrame() const {
576 if (!content_view_core_) 551 if (!content_view_core_)
577 return false; 552 return false;
578 553
579 if (current_surface_size_.IsEmpty()) 554 if (current_surface_size_.IsEmpty())
580 return false; 555 return false;
581 // This tell us whether a valid frame has arrived or not. 556 // This tell us whether a valid frame has arrived or not.
582 if (!frame_evictor_->HasFrame()) 557 if (!frame_evictor_->HasFrame())
583 return false; 558 return false;
584 559
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 callback.Run(SkBitmap(), READBACK_FAILED); 1041 callback.Run(SkBitmap(), READBACK_FAILED);
1067 return; 1042 return;
1068 } 1043 }
1069 1044
1070 base::TimeTicks start_time = base::TimeTicks::Now(); 1045 base::TimeTicks start_time = base::TimeTicks::Now();
1071 const display::Display& display = 1046 const display::Display& display =
1072 display::Screen::GetScreen()->GetDisplayNearestWindow(GetNativeView()); 1047 display::Screen::GetScreen()->GetDisplayNearestWindow(GetNativeView());
1073 float device_scale_factor = display.device_scale_factor(); 1048 float device_scale_factor = display.device_scale_factor();
1074 gfx::Size dst_size_in_pixel = 1049 gfx::Size dst_size_in_pixel =
1075 gfx::ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); 1050 gfx::ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size();
1076 gfx::Rect src_subrect_in_pixel = 1051 // Note: When |src_subrect| is empty, a conversion from the view size must be
1077 gfx::ConvertRectToPixel(device_scale_factor, src_subrect); 1052 // made instead of using |current_frame_size_|. The latter sometimes also
1053 // includes extra height for the toolbar UI, which is not intended for
1054 // capture.
1055 gfx::Rect src_subrect_in_pixel = gfx::ConvertRectToPixel(
1056 device_scale_factor, src_subrect.IsEmpty()
1057 ? gfx::Rect(GetVisibleViewportSize())
1058 : src_subrect);
1078 1059
1079 if (!using_browser_compositor_) { 1060 if (!using_browser_compositor_) {
1080 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, 1061 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback,
1081 preferred_color_type); 1062 preferred_color_type);
1082 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", 1063 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous",
1083 base::TimeTicks::Now() - start_time); 1064 base::TimeTicks::Now() - start_time);
1084 return; 1065 return;
1085 } 1066 }
1086 1067
1087 ui::WindowAndroidCompositor* compositor = 1068 ui::WindowAndroidCompositor* compositor =
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 // context) to ensure proper handle theming. 1297 // context) to ensure proper handle theming.
1317 activityContext.is_null() ? base::android::GetApplicationContext() 1298 activityContext.is_null() ? base::android::GetApplicationContext()
1318 : activityContext)); 1299 : activityContext));
1319 } 1300 }
1320 1301
1321 void RenderWidgetHostViewAndroid::SynchronousCopyContents( 1302 void RenderWidgetHostViewAndroid::SynchronousCopyContents(
1322 const gfx::Rect& src_subrect_in_pixel, 1303 const gfx::Rect& src_subrect_in_pixel,
1323 const gfx::Size& dst_size_in_pixel, 1304 const gfx::Size& dst_size_in_pixel,
1324 const ReadbackRequestCallback& callback, 1305 const ReadbackRequestCallback& callback,
1325 const SkColorType color_type) { 1306 const SkColorType color_type) {
1326 gfx::Size input_size_in_pixel; 1307 // TODO(crbug/698974): [BUG] Current implementation does not support read-back
1327 if (src_subrect_in_pixel.IsEmpty()) 1308 // of regions that do not originate at (0,0).
1328 input_size_in_pixel = current_surface_size_; 1309 const gfx::Size& input_size_in_pixel = src_subrect_in_pixel.size();
1329 else 1310 DCHECK(!input_size_in_pixel.IsEmpty());
1330 input_size_in_pixel = src_subrect_in_pixel.size();
1331 1311
1332 gfx::Size output_size_in_pixel; 1312 gfx::Size output_size_in_pixel;
1333 if (dst_size_in_pixel.IsEmpty()) 1313 if (dst_size_in_pixel.IsEmpty())
1334 output_size_in_pixel = input_size_in_pixel; 1314 output_size_in_pixel = input_size_in_pixel;
1335 else 1315 else
1336 output_size_in_pixel = dst_size_in_pixel; 1316 output_size_in_pixel = dst_size_in_pixel;
1337 int output_width = output_size_in_pixel.width(); 1317 int output_width = output_size_in_pixel.width();
1338 int output_height = output_size_in_pixel.height(); 1318 int output_height = output_size_in_pixel.height();
1339 1319
1340 if (!sync_compositor_) { 1320 if (!sync_compositor_) {
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
2128 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); 2108 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor();
2129 if (!compositor) 2109 if (!compositor)
2130 return; 2110 return;
2131 2111
2132 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( 2112 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>(
2133 overscroll_refresh_handler, compositor, 2113 overscroll_refresh_handler, compositor,
2134 ui::GetScaleFactorForNativeView(GetNativeView())); 2114 ui::GetScaleFactorForNativeView(GetNativeView()));
2135 } 2115 }
2136 2116
2137 } // namespace content 2117 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_android.h ('k') | content/browser/web_contents/web_contents_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698