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

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

Issue 2741993004: Fix Android tab navigation "stretch" regression. (Closed)
Patch Set: 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 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { 521 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) {
522 // Ignore the given size as only the Java code has the power to 522 // Ignore the given size as only the Java code has the power to
523 // resize the view on Android. 523 // resize the view on Android.
524 default_bounds_ = gfx::Rect(default_bounds_.origin(), size); 524 default_bounds_ = gfx::Rect(default_bounds_.origin(), size);
525 } 525 }
526 526
527 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { 527 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) {
528 default_bounds_ = rect; 528 default_bounds_ = rect;
529 } 529 }
530 530
531 void RenderWidgetHostViewAndroid::GetScaledContentBitmap(
532 float scale,
533 SkColorType preferred_color_type,
534 gfx::Rect src_subrect,
535 const ReadbackRequestCallback& result_callback) {
536 if (!host_ || host_->is_hidden() || !IsSurfaceAvailableForCopy()) {
537 result_callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE);
538 return;
539 }
540 gfx::Size bounds = current_surface_size_;
541 if (src_subrect.IsEmpty())
542 src_subrect = gfx::Rect(bounds);
543 DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width());
544 DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height());
545 const display::Display& display =
546 display::Screen::GetScreen()->GetDisplayNearestWindow(GetNativeView());
547 float device_scale_factor = display.device_scale_factor();
548 DCHECK_GT(device_scale_factor, 0);
549 gfx::Size dst_size(
550 gfx::ScaleToCeiledSize(src_subrect.size(), scale / device_scale_factor));
551 src_subrect = gfx::ConvertRectToDIP(device_scale_factor, src_subrect);
552
553 CopyFromSurface(src_subrect, dst_size, result_callback, preferred_color_type);
554 }
555
556 bool RenderWidgetHostViewAndroid::HasValidFrame() const { 531 bool RenderWidgetHostViewAndroid::HasValidFrame() const {
557 if (!content_view_core_) 532 if (!content_view_core_)
558 return false; 533 return false;
559 534
560 if (current_surface_size_.IsEmpty()) 535 if (current_surface_size_.IsEmpty())
561 return false; 536 return false;
562 // This tell us whether a valid frame has arrived or not. 537 // This tell us whether a valid frame has arrived or not.
563 if (!frame_evictor_->HasFrame()) 538 if (!frame_evictor_->HasFrame())
564 return false; 539 return false;
565 540
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 callback.Run(SkBitmap(), READBACK_FAILED); 902 callback.Run(SkBitmap(), READBACK_FAILED);
928 return; 903 return;
929 } 904 }
930 905
931 base::TimeTicks start_time = base::TimeTicks::Now(); 906 base::TimeTicks start_time = base::TimeTicks::Now();
932 const display::Display& display = 907 const display::Display& display =
933 display::Screen::GetScreen()->GetDisplayNearestWindow(GetNativeView()); 908 display::Screen::GetScreen()->GetDisplayNearestWindow(GetNativeView());
934 float device_scale_factor = display.device_scale_factor(); 909 float device_scale_factor = display.device_scale_factor();
935 gfx::Size dst_size_in_pixel = 910 gfx::Size dst_size_in_pixel =
936 gfx::ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); 911 gfx::ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size();
937 gfx::Rect src_subrect_in_pixel = 912 // Note: When |src_subrect| is empty, a conversion from the view size must be
938 gfx::ConvertRectToPixel(device_scale_factor, src_subrect); 913 // made instead of using |current_frame_size_|. The latter sometimes also
914 // includes extra height for the toolbar UI, which is not intended for
915 // capture.
916 gfx::Rect src_subrect_in_pixel = gfx::ConvertRectToPixel(
917 device_scale_factor, src_subrect.IsEmpty()
918 ? gfx::Rect(GetVisibleViewportSize())
919 : src_subrect);
939 920
940 if (!using_browser_compositor_) { 921 if (!using_browser_compositor_) {
941 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, 922 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback,
942 preferred_color_type); 923 preferred_color_type);
943 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", 924 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous",
944 base::TimeTicks::Now() - start_time); 925 base::TimeTicks::Now() - start_time);
945 return; 926 return;
946 } 927 }
947 928
948 ui::WindowAndroidCompositor* compositor = 929 ui::WindowAndroidCompositor* compositor =
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 // context) to ensure proper handle theming. 1158 // context) to ensure proper handle theming.
1178 activityContext.is_null() ? base::android::GetApplicationContext() 1159 activityContext.is_null() ? base::android::GetApplicationContext()
1179 : activityContext)); 1160 : activityContext));
1180 } 1161 }
1181 1162
1182 void RenderWidgetHostViewAndroid::SynchronousCopyContents( 1163 void RenderWidgetHostViewAndroid::SynchronousCopyContents(
1183 const gfx::Rect& src_subrect_in_pixel, 1164 const gfx::Rect& src_subrect_in_pixel,
1184 const gfx::Size& dst_size_in_pixel, 1165 const gfx::Size& dst_size_in_pixel,
1185 const ReadbackRequestCallback& callback, 1166 const ReadbackRequestCallback& callback,
1186 const SkColorType color_type) { 1167 const SkColorType color_type) {
1187 gfx::Size input_size_in_pixel; 1168 // TODO(crbug/698974): [BUG] Current implementation does not support read-back
1188 if (src_subrect_in_pixel.IsEmpty()) 1169 // of regions that do not originate at (0,0).
1189 input_size_in_pixel = current_surface_size_; 1170 const gfx::Size& input_size_in_pixel = src_subrect_in_pixel.size();
1190 else 1171 DCHECK(!input_size_in_pixel.IsEmpty());
1191 input_size_in_pixel = src_subrect_in_pixel.size();
1192 1172
1193 gfx::Size output_size_in_pixel; 1173 gfx::Size output_size_in_pixel;
1194 if (dst_size_in_pixel.IsEmpty()) 1174 if (dst_size_in_pixel.IsEmpty())
1195 output_size_in_pixel = input_size_in_pixel; 1175 output_size_in_pixel = input_size_in_pixel;
1196 else 1176 else
1197 output_size_in_pixel = dst_size_in_pixel; 1177 output_size_in_pixel = dst_size_in_pixel;
1198 int output_width = output_size_in_pixel.width(); 1178 int output_width = output_size_in_pixel.width();
1199 int output_height = output_size_in_pixel.height(); 1179 int output_height = output_size_in_pixel.height();
1200 1180
1201 if (!sync_compositor_) { 1181 if (!sync_compositor_) {
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
1968 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); 1948 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor();
1969 if (!compositor) 1949 if (!compositor)
1970 return; 1950 return;
1971 1951
1972 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( 1952 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>(
1973 overscroll_refresh_handler, compositor, 1953 overscroll_refresh_handler, compositor,
1974 ui::GetScaleFactorForNativeView(GetNativeView())); 1954 ui::GetScaleFactorForNativeView(GetNativeView()));
1975 } 1955 }
1976 1956
1977 } // namespace content 1957 } // 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