| 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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 | 392 |
| 393 gl_helper->CropScaleReadbackAndCleanMailbox( | 393 gl_helper->CropScaleReadbackAndCleanMailbox( |
| 394 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(), | 394 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(), |
| 395 gfx::Rect(result->size()), output_size_in_pixel, pixels, color_type, | 395 gfx::Rect(result->size()), output_size_in_pixel, pixels, color_type, |
| 396 base::Bind(&CopyFromCompositingSurfaceFinished, callback, | 396 base::Bind(&CopyFromCompositingSurfaceFinished, callback, |
| 397 base::Passed(&release_callback), base::Passed(&bitmap), | 397 base::Passed(&release_callback), base::Passed(&bitmap), |
| 398 start_time, base::Passed(&bitmap_pixels_lock), readback_lock), | 398 start_time, base::Passed(&bitmap_pixels_lock), readback_lock), |
| 399 display_compositor::GLHelper::SCALER_QUALITY_GOOD); | 399 display_compositor::GLHelper::SCALER_QUALITY_GOOD); |
| 400 } | 400 } |
| 401 | 401 |
| 402 bool FloatEquals(float a, float b) { |
| 403 return std::abs(a - b) < FLT_EPSILON; |
| 404 } |
| 405 |
| 402 } // namespace | 406 } // namespace |
| 403 | 407 |
| 404 void RenderWidgetHostViewAndroid::OnContextLost() { | 408 void RenderWidgetHostViewAndroid::OnContextLost() { |
| 405 std::unique_ptr<RenderWidgetHostIterator> widgets( | 409 std::unique_ptr<RenderWidgetHostIterator> widgets( |
| 406 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); | 410 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); |
| 407 while (RenderWidgetHost* widget = widgets->GetNextHost()) { | 411 while (RenderWidgetHost* widget = widgets->GetNextHost()) { |
| 408 if (widget->GetView()) { | 412 if (widget->GetView()) { |
| 409 static_cast<RenderWidgetHostViewAndroid*>(widget->GetView()) | 413 static_cast<RenderWidgetHostViewAndroid*>(widget->GetView()) |
| 410 ->OnLostResources(); | 414 ->OnLostResources(); |
| 411 } | 415 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 427 cached_background_color_(SK_ColorWHITE), | 431 cached_background_color_(SK_ColorWHITE), |
| 428 last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId), | 432 last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId), |
| 429 gesture_provider_(ui::GetGestureProviderConfig( | 433 gesture_provider_(ui::GetGestureProviderConfig( |
| 430 ui::GestureProviderConfigType::CURRENT_PLATFORM), | 434 ui::GestureProviderConfigType::CURRENT_PLATFORM), |
| 431 this), | 435 this), |
| 432 stylus_text_selector_(this), | 436 stylus_text_selector_(this), |
| 433 using_browser_compositor_(CompositorImpl::IsInitialized()), | 437 using_browser_compositor_(CompositorImpl::IsInitialized()), |
| 434 synchronous_compositor_client_(nullptr), | 438 synchronous_compositor_client_(nullptr), |
| 435 frame_evictor_(new DelegatedFrameEvictor(this)), | 439 frame_evictor_(new DelegatedFrameEvictor(this)), |
| 436 observing_root_window_(false), | 440 observing_root_window_(false), |
| 441 prev_top_shown_pix_(0.f), |
| 442 prev_bottom_shown_pix_(0.f), |
| 437 weak_ptr_factory_(this) { | 443 weak_ptr_factory_(this) { |
| 438 // Set the layer which will hold the content layer for this view. The content | 444 // Set the layer which will hold the content layer for this view. The content |
| 439 // layer is managed by the DelegatedFrameHost. | 445 // layer is managed by the DelegatedFrameHost. |
| 440 view_.SetLayer(cc::Layer::Create()); | 446 view_.SetLayer(cc::Layer::Create()); |
| 441 if (using_browser_compositor_) { | 447 if (using_browser_compositor_) { |
| 442 cc::FrameSinkId frame_sink_id = | 448 cc::FrameSinkId frame_sink_id = |
| 443 host_->AllocateFrameSinkId(false /* is_guest_view_hack */); | 449 host_->AllocateFrameSinkId(false /* is_guest_view_hack */); |
| 444 delegated_frame_host_.reset(new ui::DelegatedFrameHostAndroid( | 450 delegated_frame_host_.reset(new ui::DelegatedFrameHostAndroid( |
| 445 &view_, cached_background_color_, this, frame_sink_id)); | 451 &view_, cached_background_color_, this, frame_sink_id)); |
| 446 } | 452 } |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 | 783 |
| 778 void RenderWidgetHostViewAndroid::UpdateBackgroundColor(SkColor color) { | 784 void RenderWidgetHostViewAndroid::UpdateBackgroundColor(SkColor color) { |
| 779 if (cached_background_color_ == color) | 785 if (cached_background_color_ == color) |
| 780 return; | 786 return; |
| 781 | 787 |
| 782 cached_background_color_ = color; | 788 cached_background_color_ = color; |
| 783 | 789 |
| 784 if (delegated_frame_host_) | 790 if (delegated_frame_host_) |
| 785 delegated_frame_host_->UpdateBackgroundColor(color); | 791 delegated_frame_host_->UpdateBackgroundColor(color); |
| 786 | 792 |
| 787 if (content_view_core_) | 793 view_.OnBackgroundColorChanged(color); |
| 788 content_view_core_->OnBackgroundColorChanged(color); | |
| 789 } | 794 } |
| 790 | 795 |
| 791 void RenderWidgetHostViewAndroid::SetNeedsBeginFrames(bool needs_begin_frames) { | 796 void RenderWidgetHostViewAndroid::SetNeedsBeginFrames(bool needs_begin_frames) { |
| 792 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::SetNeedsBeginFrames", | 797 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::SetNeedsBeginFrames", |
| 793 "needs_begin_frames", needs_begin_frames); | 798 "needs_begin_frames", needs_begin_frames); |
| 794 if (needs_begin_frames) | 799 if (needs_begin_frames) |
| 795 AddBeginFrameRequest(PERSISTENT_BEGIN_FRAME); | 800 AddBeginFrameRequest(PERSISTENT_BEGIN_FRAME); |
| 796 else | 801 else |
| 797 ClearBeginFrameRequest(PERSISTENT_BEGIN_FRAME); | 802 ClearBeginFrameRequest(PERSISTENT_BEGIN_FRAME); |
| 798 } | 803 } |
| 799 | 804 |
| 800 void RenderWidgetHostViewAndroid::OnStartContentIntent( | 805 void RenderWidgetHostViewAndroid::OnStartContentIntent( |
| 801 const GURL& content_url, bool is_main_frame) { | 806 const GURL& content_url, bool is_main_frame) { |
| 802 if (content_view_core_) | 807 view_.StartContentIntent(content_url, is_main_frame); |
| 803 content_view_core_->StartContentIntent(content_url, is_main_frame); | |
| 804 } | 808 } |
| 805 | 809 |
| 806 bool RenderWidgetHostViewAndroid::OnTouchEvent( | 810 bool RenderWidgetHostViewAndroid::OnTouchEvent( |
| 807 const ui::MotionEvent& event) { | 811 const ui::MotionEvent& event) { |
| 808 if (!host_) | 812 if (!host_) |
| 809 return false; | 813 return false; |
| 810 | 814 |
| 811 ComputeEventLatencyOSTouchHistograms(event); | 815 ComputeEventLatencyOSTouchHistograms(event); |
| 812 | 816 |
| 813 // If a browser-based widget consumes the touch event, it's critical that | 817 // 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 Loading... |
| 1261 selection_controller_->OnViewportChanged(viewport_rect); | 1265 selection_controller_->OnViewportChanged(viewport_rect); |
| 1262 } | 1266 } |
| 1263 | 1267 |
| 1264 UpdateBackgroundColor(is_transparent ? SK_ColorTRANSPARENT | 1268 UpdateBackgroundColor(is_transparent ? SK_ColorTRANSPARENT |
| 1265 : frame_metadata.root_background_color); | 1269 : frame_metadata.root_background_color); |
| 1266 | 1270 |
| 1267 view_.set_content_offset(gfx::Vector2dF(0.0f, | 1271 view_.set_content_offset(gfx::Vector2dF(0.0f, |
| 1268 frame_metadata.top_controls_height * | 1272 frame_metadata.top_controls_height * |
| 1269 frame_metadata.top_controls_shown_ratio)); | 1273 frame_metadata.top_controls_shown_ratio)); |
| 1270 | 1274 |
| 1275 float dip_scale = ui::GetScaleFactorForNativeView(GetNativeView()); |
| 1276 float top_controls_pix = frame_metadata.top_controls_height * dip_scale; |
| 1277 float top_shown_pix = |
| 1278 top_controls_pix * frame_metadata.top_controls_shown_ratio; |
| 1279 bool top_changed = !FloatEquals(top_shown_pix, prev_top_shown_pix_); |
| 1280 |
| 1281 float bottom_controls_pix = frame_metadata.bottom_controls_height * dip_scale; |
| 1282 float bottom_shown_pix = |
| 1283 bottom_controls_pix * frame_metadata.bottom_controls_shown_ratio; |
| 1284 bool bottom_changed = !FloatEquals(bottom_shown_pix, prev_bottom_shown_pix_); |
| 1285 |
| 1286 if (top_changed) { |
| 1287 float translate = top_shown_pix - top_controls_pix; |
| 1288 view_.OnTopControlsChanged(translate, top_shown_pix); |
| 1289 prev_top_shown_pix_ = top_shown_pix; |
| 1290 } |
| 1291 if (bottom_changed) { |
| 1292 float translate = bottom_controls_pix - bottom_shown_pix; |
| 1293 view_.OnBottomControlsChanged(translate, bottom_shown_pix); |
| 1294 prev_bottom_shown_pix_ = bottom_shown_pix; |
| 1295 } |
| 1296 |
| 1271 // All offsets and sizes are in CSS pixels. | 1297 // All offsets and sizes are in CSS pixels. |
| 1272 content_view_core_->UpdateFrameInfo( | 1298 content_view_core_->UpdateFrameInfo( |
| 1273 frame_metadata.root_scroll_offset, | 1299 frame_metadata.root_scroll_offset, |
| 1274 frame_metadata.page_scale_factor, | 1300 frame_metadata.page_scale_factor, |
| 1275 gfx::Vector2dF(frame_metadata.min_page_scale_factor, | 1301 gfx::Vector2dF(frame_metadata.min_page_scale_factor, |
| 1276 frame_metadata.max_page_scale_factor), | 1302 frame_metadata.max_page_scale_factor), |
| 1277 frame_metadata.root_layer_size, | 1303 frame_metadata.root_layer_size, |
| 1278 frame_metadata.scrollable_viewport_size, | 1304 frame_metadata.scrollable_viewport_size, |
| 1279 frame_metadata.top_controls_height, | 1305 frame_metadata.top_controls_height, |
| 1280 frame_metadata.top_controls_shown_ratio, | 1306 frame_metadata.top_controls_shown_ratio, |
| 1281 frame_metadata.bottom_controls_height, | |
| 1282 frame_metadata.bottom_controls_shown_ratio, | |
| 1283 is_mobile_optimized, | 1307 is_mobile_optimized, |
| 1284 frame_metadata.selection.start); | 1308 frame_metadata.selection.start); |
| 1285 } | 1309 } |
| 1286 | 1310 |
| 1287 void RenderWidgetHostViewAndroid::ShowInternal() { | 1311 void RenderWidgetHostViewAndroid::ShowInternal() { |
| 1288 bool show = is_showing_ && is_window_activity_started_ && is_window_visible_; | 1312 bool show = is_showing_ && is_window_activity_started_ && is_window_visible_; |
| 1289 if (!show) | 1313 if (!show) |
| 1290 return; | 1314 return; |
| 1291 | 1315 |
| 1292 if (!host_ || !host_->is_hidden()) | 1316 if (!host_ || !host_->is_hidden()) |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1968 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); | 1992 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); |
| 1969 if (!compositor) | 1993 if (!compositor) |
| 1970 return; | 1994 return; |
| 1971 | 1995 |
| 1972 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( | 1996 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( |
| 1973 overscroll_refresh_handler, compositor, | 1997 overscroll_refresh_handler, compositor, |
| 1974 ui::GetScaleFactorForNativeView(GetNativeView())); | 1998 ui::GetScaleFactorForNativeView(GetNativeView())); |
| 1975 } | 1999 } |
| 1976 | 2000 |
| 1977 } // namespace content | 2001 } // namespace content |
| OLD | NEW |