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

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

Issue 2708703004: Reland "Refactor ContentViewClient (4/6)" (Closed)
Patch Set: - Created 3 years, 10 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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 393
394 gl_helper->CropScaleReadbackAndCleanMailbox( 394 gl_helper->CropScaleReadbackAndCleanMailbox(
395 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(), 395 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(),
396 gfx::Rect(result->size()), output_size_in_pixel, pixels, color_type, 396 gfx::Rect(result->size()), output_size_in_pixel, pixels, color_type,
397 base::Bind(&CopyFromCompositingSurfaceFinished, callback, 397 base::Bind(&CopyFromCompositingSurfaceFinished, callback,
398 base::Passed(&release_callback), base::Passed(&bitmap), 398 base::Passed(&release_callback), base::Passed(&bitmap),
399 start_time, base::Passed(&bitmap_pixels_lock), readback_lock), 399 start_time, base::Passed(&bitmap_pixels_lock), readback_lock),
400 display_compositor::GLHelper::SCALER_QUALITY_GOOD); 400 display_compositor::GLHelper::SCALER_QUALITY_GOOD);
401 } 401 }
402 402
403 bool FloatEquals(float a, float b) {
David Trainor- moved to gerrit 2017/02/24 02:17:34 Does this method already exist somewhere in Chrome
Jinsuk Kim 2017/02/24 02:32:08 I searched the codebase before for the one I can u
404 return std::abs(a - b) < FLT_EPSILON;
405 }
406
403 } // namespace 407 } // namespace
404 408
405 void RenderWidgetHostViewAndroid::OnContextLost() { 409 void RenderWidgetHostViewAndroid::OnContextLost() {
406 std::unique_ptr<RenderWidgetHostIterator> widgets( 410 std::unique_ptr<RenderWidgetHostIterator> widgets(
407 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); 411 RenderWidgetHostImpl::GetAllRenderWidgetHosts());
408 while (RenderWidgetHost* widget = widgets->GetNextHost()) { 412 while (RenderWidgetHost* widget = widgets->GetNextHost()) {
409 if (widget->GetView()) { 413 if (widget->GetView()) {
410 static_cast<RenderWidgetHostViewAndroid*>(widget->GetView()) 414 static_cast<RenderWidgetHostViewAndroid*>(widget->GetView())
411 ->OnLostResources(); 415 ->OnLostResources();
412 } 416 }
(...skipping 15 matching lines...) Expand all
428 cached_background_color_(SK_ColorWHITE), 432 cached_background_color_(SK_ColorWHITE),
429 last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId), 433 last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId),
430 gesture_provider_(ui::GetGestureProviderConfig( 434 gesture_provider_(ui::GetGestureProviderConfig(
431 ui::GestureProviderConfigType::CURRENT_PLATFORM), 435 ui::GestureProviderConfigType::CURRENT_PLATFORM),
432 this), 436 this),
433 stylus_text_selector_(this), 437 stylus_text_selector_(this),
434 using_browser_compositor_(CompositorImpl::IsInitialized()), 438 using_browser_compositor_(CompositorImpl::IsInitialized()),
435 synchronous_compositor_client_(nullptr), 439 synchronous_compositor_client_(nullptr),
436 frame_evictor_(new DelegatedFrameEvictor(this)), 440 frame_evictor_(new DelegatedFrameEvictor(this)),
437 observing_root_window_(false), 441 observing_root_window_(false),
442 prev_top_shown_pix_(0.f),
443 prev_bottom_shown_pix_(0.f),
438 weak_ptr_factory_(this) { 444 weak_ptr_factory_(this) {
439 // Set the layer which will hold the content layer for this view. The content 445 // Set the layer which will hold the content layer for this view. The content
440 // layer is managed by the DelegatedFrameHost. 446 // layer is managed by the DelegatedFrameHost.
441 view_.SetLayer(cc::Layer::Create()); 447 view_.SetLayer(cc::Layer::Create());
442 if (using_browser_compositor_) { 448 if (using_browser_compositor_) {
443 // This FrameSinkId must be unique with ContextProviderFactory's FrameSinkId 449 // This FrameSinkId must be unique with ContextProviderFactory's FrameSinkId
444 // allocation. 450 // allocation.
445 // TODO(crbug.com/685777): Centralize allocation in one place for easier 451 // TODO(crbug.com/685777): Centralize allocation in one place for easier
446 // maintenance. 452 // maintenance.
447 cc::FrameSinkId frame_sink_id = cc::FrameSinkId( 453 cc::FrameSinkId frame_sink_id = cc::FrameSinkId(
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 789
784 void RenderWidgetHostViewAndroid::UpdateBackgroundColor(SkColor color) { 790 void RenderWidgetHostViewAndroid::UpdateBackgroundColor(SkColor color) {
785 if (cached_background_color_ == color) 791 if (cached_background_color_ == color)
786 return; 792 return;
787 793
788 cached_background_color_ = color; 794 cached_background_color_ = color;
789 795
790 if (delegated_frame_host_) 796 if (delegated_frame_host_)
791 delegated_frame_host_->UpdateBackgroundColor(color); 797 delegated_frame_host_->UpdateBackgroundColor(color);
792 798
793 if (content_view_core_) 799 view_.OnBackgroundColorChanged(color);
794 content_view_core_->OnBackgroundColorChanged(color);
795 } 800 }
796 801
797 void RenderWidgetHostViewAndroid::SetNeedsBeginFrames(bool needs_begin_frames) { 802 void RenderWidgetHostViewAndroid::SetNeedsBeginFrames(bool needs_begin_frames) {
798 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::SetNeedsBeginFrames", 803 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::SetNeedsBeginFrames",
799 "needs_begin_frames", needs_begin_frames); 804 "needs_begin_frames", needs_begin_frames);
800 if (needs_begin_frames) 805 if (needs_begin_frames)
801 AddBeginFrameRequest(PERSISTENT_BEGIN_FRAME); 806 AddBeginFrameRequest(PERSISTENT_BEGIN_FRAME);
802 else 807 else
803 ClearBeginFrameRequest(PERSISTENT_BEGIN_FRAME); 808 ClearBeginFrameRequest(PERSISTENT_BEGIN_FRAME);
804 } 809 }
805 810
806 void RenderWidgetHostViewAndroid::OnStartContentIntent( 811 void RenderWidgetHostViewAndroid::OnStartContentIntent(
807 const GURL& content_url, bool is_main_frame) { 812 const GURL& content_url, bool is_main_frame) {
808 if (content_view_core_) 813 view_.StartContentIntent(content_url, is_main_frame);
809 content_view_core_->StartContentIntent(content_url, is_main_frame);
810 } 814 }
811 815
812 bool RenderWidgetHostViewAndroid::OnTouchEvent( 816 bool RenderWidgetHostViewAndroid::OnTouchEvent(
813 const ui::MotionEvent& event) { 817 const ui::MotionEvent& event) {
814 if (!host_) 818 if (!host_)
815 return false; 819 return false;
816 820
817 ComputeEventLatencyOSTouchHistograms(event); 821 ComputeEventLatencyOSTouchHistograms(event);
818 822
819 // If a browser-based widget consumes the touch event, it's critical that 823 // If a browser-based widget consumes the touch event, it's critical that
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 selection_controller_->OnViewportChanged(viewport_rect); 1271 selection_controller_->OnViewportChanged(viewport_rect);
1268 } 1272 }
1269 1273
1270 UpdateBackgroundColor(is_transparent ? SK_ColorTRANSPARENT 1274 UpdateBackgroundColor(is_transparent ? SK_ColorTRANSPARENT
1271 : frame_metadata.root_background_color); 1275 : frame_metadata.root_background_color);
1272 1276
1273 view_.set_content_offset(gfx::Vector2dF(0.0f, 1277 view_.set_content_offset(gfx::Vector2dF(0.0f,
1274 frame_metadata.top_controls_height * 1278 frame_metadata.top_controls_height *
1275 frame_metadata.top_controls_shown_ratio)); 1279 frame_metadata.top_controls_shown_ratio));
1276 1280
1281 float dip_scale = ui::GetScaleFactorForNativeView(GetNativeView());
1282 float top_controls_pix = frame_metadata.top_controls_height * dip_scale;
1283 float top_shown_pix =
1284 top_controls_pix * frame_metadata.top_controls_shown_ratio;
1285 bool top_changed = !FloatEquals(top_shown_pix, prev_top_shown_pix_);
1286
1287 float bottom_controls_pix = frame_metadata.bottom_controls_height * dip_scale;
1288 float bottom_shown_pix =
1289 bottom_controls_pix * frame_metadata.bottom_controls_shown_ratio;
1290 bool bottom_changed = !FloatEquals(bottom_shown_pix, prev_bottom_shown_pix_);
1291
1292 if (top_changed) {
1293 float translate = top_shown_pix - top_controls_pix;
1294 view_.OnTopControlsChanged(translate, top_shown_pix);
1295 prev_top_shown_pix_ = top_shown_pix;
1296 }
1297 if (bottom_changed) {
1298 float translate = bottom_controls_pix - bottom_shown_pix;
1299 view_.OnBottomControlsChanged(translate, bottom_shown_pix);
1300 prev_bottom_shown_pix_ = bottom_shown_pix;
1301 }
1302
1277 // All offsets and sizes are in CSS pixels. 1303 // All offsets and sizes are in CSS pixels.
1278 content_view_core_->UpdateFrameInfo( 1304 content_view_core_->UpdateFrameInfo(
1279 frame_metadata.root_scroll_offset, 1305 frame_metadata.root_scroll_offset,
1280 frame_metadata.page_scale_factor, 1306 frame_metadata.page_scale_factor,
1281 gfx::Vector2dF(frame_metadata.min_page_scale_factor, 1307 gfx::Vector2dF(frame_metadata.min_page_scale_factor,
1282 frame_metadata.max_page_scale_factor), 1308 frame_metadata.max_page_scale_factor),
1283 frame_metadata.root_layer_size, 1309 frame_metadata.root_layer_size,
1284 frame_metadata.scrollable_viewport_size, 1310 frame_metadata.scrollable_viewport_size,
1285 frame_metadata.top_controls_height, 1311 frame_metadata.top_controls_height,
1286 frame_metadata.top_controls_shown_ratio, 1312 frame_metadata.top_controls_shown_ratio,
1287 frame_metadata.bottom_controls_height,
1288 frame_metadata.bottom_controls_shown_ratio,
1289 is_mobile_optimized, 1313 is_mobile_optimized,
1290 frame_metadata.selection.start); 1314 frame_metadata.selection.start);
1291 } 1315 }
1292 1316
1293 void RenderWidgetHostViewAndroid::ShowInternal() { 1317 void RenderWidgetHostViewAndroid::ShowInternal() {
1294 bool show = is_showing_ && is_window_activity_started_ && is_window_visible_; 1318 bool show = is_showing_ && is_window_activity_started_ && is_window_visible_;
1295 if (!show) 1319 if (!show)
1296 return; 1320 return;
1297 1321
1298 if (!host_ || !host_->is_hidden()) 1322 if (!host_ || !host_->is_hidden())
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
1974 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); 1998 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor();
1975 if (!compositor) 1999 if (!compositor)
1976 return; 2000 return;
1977 2001
1978 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( 2002 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>(
1979 overscroll_refresh_handler, compositor, 2003 overscroll_refresh_handler, compositor,
1980 ui::GetScaleFactorForNativeView(GetNativeView())); 2004 ui::GetScaleFactorForNativeView(GetNativeView()));
1981 } 2005 }
1982 2006
1983 } // namespace content 2007 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698