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

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

Issue 2658293002: content: Remove Lock/Unlock CompositingSurface API from RWH. (Closed)
Patch Set: last_frame_info 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 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 } // namespace 403 } // namespace
404 404
405 RenderWidgetHostViewAndroid::LastFrameInfo::LastFrameInfo(
406 uint32_t compositor_frame_sink_id,
407 cc::CompositorFrame output_frame)
408 : compositor_frame_sink_id(compositor_frame_sink_id),
409 frame(std::move(output_frame)) {}
410
411 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {}
412
413 void RenderWidgetHostViewAndroid::OnContextLost() { 405 void RenderWidgetHostViewAndroid::OnContextLost() {
414 std::unique_ptr<RenderWidgetHostIterator> widgets( 406 std::unique_ptr<RenderWidgetHostIterator> widgets(
415 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); 407 RenderWidgetHostImpl::GetAllRenderWidgetHosts());
416 while (RenderWidgetHost* widget = widgets->GetNextHost()) { 408 while (RenderWidgetHost* widget = widgets->GetNextHost()) {
417 if (widget->GetView()) { 409 if (widget->GetView()) {
418 static_cast<RenderWidgetHostViewAndroid*>(widget->GetView()) 410 static_cast<RenderWidgetHostViewAndroid*>(widget->GetView())
419 ->OnLostResources(); 411 ->OnLostResources();
420 } 412 }
421 } 413 }
422 } 414 }
(...skipping 12 matching lines...) Expand all
435 ime_adapter_android_(this), 427 ime_adapter_android_(this),
436 cached_background_color_(SK_ColorWHITE), 428 cached_background_color_(SK_ColorWHITE),
437 last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId), 429 last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId),
438 gesture_provider_(ui::GetGestureProviderConfig( 430 gesture_provider_(ui::GetGestureProviderConfig(
439 ui::GestureProviderConfigType::CURRENT_PLATFORM), 431 ui::GestureProviderConfigType::CURRENT_PLATFORM),
440 this), 432 this),
441 stylus_text_selector_(this), 433 stylus_text_selector_(this),
442 using_browser_compositor_(CompositorImpl::IsInitialized()), 434 using_browser_compositor_(CompositorImpl::IsInitialized()),
443 synchronous_compositor_client_(nullptr), 435 synchronous_compositor_client_(nullptr),
444 frame_evictor_(new DelegatedFrameEvictor(this)), 436 frame_evictor_(new DelegatedFrameEvictor(this)),
445 locks_on_frame_count_(0),
446 observing_root_window_(false), 437 observing_root_window_(false),
447 weak_ptr_factory_(this) { 438 weak_ptr_factory_(this) {
448 // Set the layer which will hold the content layer for this view. The content 439 // Set the layer which will hold the content layer for this view. The content
449 // layer is managed by the DelegatedFrameHost. 440 // layer is managed by the DelegatedFrameHost.
450 view_.SetLayer(cc::Layer::Create()); 441 view_.SetLayer(cc::Layer::Create());
451 if (using_browser_compositor_) { 442 if (using_browser_compositor_) {
452 // This FrameSinkId must be unique with ContextProviderFactory's FrameSinkId 443 // This FrameSinkId must be unique with ContextProviderFactory's FrameSinkId
453 // allocation. 444 // allocation.
454 // TODO(crbug.com/685777): Centralize allocation in one place for easier 445 // TODO(crbug.com/685777): Centralize allocation in one place for easier
455 // maintenance. 446 // maintenance.
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 HideInternal(); 621 HideInternal();
631 } 622 }
632 623
633 bool RenderWidgetHostViewAndroid::IsShowing() { 624 bool RenderWidgetHostViewAndroid::IsShowing() {
634 // ContentViewCoreImpl represents the native side of the Java 625 // ContentViewCoreImpl represents the native side of the Java
635 // ContentViewCore. It being NULL means that it is not attached 626 // ContentViewCore. It being NULL means that it is not attached
636 // to the View system yet, so we treat this RWHVA as hidden. 627 // to the View system yet, so we treat this RWHVA as hidden.
637 return is_showing_ && content_view_core_; 628 return is_showing_ && content_view_core_;
638 } 629 }
639 630
640 void RenderWidgetHostViewAndroid::LockCompositingSurface() {
641 DCHECK(HasValidFrame());
642 DCHECK(host_);
643 DCHECK(frame_evictor_->HasFrame());
644 frame_evictor_->LockFrame();
645 locks_on_frame_count_++;
646 }
647
648 void RenderWidgetHostViewAndroid::UnlockCompositingSurface() {
649 if (!frame_evictor_->HasFrame()) {
650 DCHECK_EQ(locks_on_frame_count_, 0u);
651 return;
652 }
653
654 DCHECK_GT(locks_on_frame_count_, 0u);
655 locks_on_frame_count_--;
656 frame_evictor_->UnlockFrame();
657
658 if (locks_on_frame_count_ == 0) {
659 if (last_frame_info_) {
660 InternalSwapCompositorFrame(last_frame_info_->compositor_frame_sink_id,
661 std::move(last_frame_info_->frame));
662 last_frame_info_.reset();
663 }
664
665 view_.GetLayer()->SetHideLayerAndSubtree(!is_showing_);
666 }
667 }
668
669 void RenderWidgetHostViewAndroid::OnShowUnhandledTapUIIfNeeded(int x_dip, 631 void RenderWidgetHostViewAndroid::OnShowUnhandledTapUIIfNeeded(int x_dip,
670 int y_dip) { 632 int y_dip) {
671 if (!content_view_core_) 633 if (!content_view_core_)
672 return; 634 return;
673 // Validate the coordinates are within the viewport. 635 // Validate the coordinates are within the viewport.
674 gfx::Size viewport_size = content_view_core_->GetViewportSizeDip(); 636 gfx::Size viewport_size = content_view_core_->GetViewportSizeDip();
675 if (x_dip < 0 || x_dip > viewport_size.width() || 637 if (x_dip < 0 || x_dip > viewport_size.width() ||
676 y_dip < 0 || y_dip > viewport_size.height()) 638 y_dip < 0 || y_dip > viewport_size.height())
677 return; 639 return;
678 content_view_core_->OnShowUnhandledTapUIIfNeeded(x_dip, y_dip); 640 content_view_core_->OnShowUnhandledTapUIIfNeeded(x_dip, y_dip);
679 } 641 }
680 642
681 void RenderWidgetHostViewAndroid::ReleaseLocksOnSurface() {
682 if (!frame_evictor_->HasFrame()) {
683 DCHECK_EQ(locks_on_frame_count_, 0u);
684 return;
685 }
686 while (locks_on_frame_count_ > 0) {
687 UnlockCompositingSurface();
688 }
689 RunAckCallbacks();
690 }
691
692 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { 643 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const {
693 if (!content_view_core_) 644 if (!content_view_core_)
694 return default_bounds_; 645 return default_bounds_;
695 646
696 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 647 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
697 switches::kEnableOSKOverscroll)) 648 switches::kEnableOSKOverscroll))
698 return gfx::Rect(content_view_core_->GetViewSizeWithOSKHidden()); 649 return gfx::Rect(content_view_core_->GetViewSizeWithOSKHidden());
699 650
700 return gfx::Rect(content_view_core_->GetViewSize()); 651 return gfx::Rect(content_view_core_->GetViewSize());
701 } 652 }
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 false /* is_swap_ack */); 1042 false /* is_swap_ack */);
1092 1043
1093 last_compositor_frame_sink_id_ = compositor_frame_sink_id; 1044 last_compositor_frame_sink_id_ = compositor_frame_sink_id;
1094 } 1045 }
1095 1046
1096 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( 1047 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame(
1097 uint32_t compositor_frame_sink_id, 1048 uint32_t compositor_frame_sink_id,
1098 cc::CompositorFrame frame) { 1049 cc::CompositorFrame frame) {
1099 last_scroll_offset_ = frame.metadata.root_scroll_offset; 1050 last_scroll_offset_ = frame.metadata.root_scroll_offset;
1100 DCHECK(delegated_frame_host_); 1051 DCHECK(delegated_frame_host_);
1101
1102 if (locks_on_frame_count_ > 0) {
1103 DCHECK(HasValidFrame());
1104 RetainFrame(compositor_frame_sink_id, std::move(frame));
1105 return;
1106 }
1107
1108 DCHECK(!frame.render_pass_list.empty()); 1052 DCHECK(!frame.render_pass_list.empty());
1109 1053
1110 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); 1054 cc::RenderPass* root_pass = frame.render_pass_list.back().get();
1111 current_surface_size_ = root_pass->output_rect.size(); 1055 current_surface_size_ = root_pass->output_rect.size();
1112 bool is_transparent = root_pass->has_transparent_background; 1056 bool is_transparent = root_pass->has_transparent_background;
1113 1057
1114 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); 1058 cc::CompositorFrameMetadata metadata = frame.metadata.Clone();
1115 1059
1116 CheckCompositorFrameSinkChanged(compositor_frame_sink_id); 1060 CheckCompositorFrameSinkChanged(compositor_frame_sink_id);
1117 bool has_content = !current_surface_size_.IsEmpty(); 1061 bool has_content = !current_surface_size_.IsEmpty();
(...skipping 21 matching lines...) Expand all
1139 1083
1140 // As the metadata update may trigger view invalidation, always call it after 1084 // As the metadata update may trigger view invalidation, always call it after
1141 // any potential compositor scheduling. 1085 // any potential compositor scheduling.
1142 OnFrameMetadataUpdated(std::move(metadata), is_transparent); 1086 OnFrameMetadataUpdated(std::move(metadata), is_transparent);
1143 } 1087 }
1144 1088
1145 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() { 1089 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() {
1146 DCHECK(!delegated_frame_host_ || 1090 DCHECK(!delegated_frame_host_ ||
1147 delegated_frame_host_->HasDelegatedContent() == 1091 delegated_frame_host_->HasDelegatedContent() ==
1148 frame_evictor_->HasFrame()); 1092 frame_evictor_->HasFrame());
1149 DCHECK_EQ(locks_on_frame_count_, 0u);
1150 1093
1151 if (!delegated_frame_host_) 1094 if (!delegated_frame_host_)
1152 return; 1095 return;
1153 1096
1154 if (!delegated_frame_host_->HasDelegatedContent()) 1097 if (!delegated_frame_host_->HasDelegatedContent())
1155 return; 1098 return;
1156 1099
1157 frame_evictor_->DiscardedFrame(); 1100 frame_evictor_->DiscardedFrame();
1158 delegated_frame_host_->DestroyDelegatedContent(); 1101 delegated_frame_host_->DestroyDelegatedContent();
1159 } 1102 }
1160 1103
1161 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( 1104 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame(
1162 uint32_t compositor_frame_sink_id, 1105 uint32_t compositor_frame_sink_id,
1163 cc::CompositorFrame frame) { 1106 cc::CompositorFrame frame) {
1164 InternalSwapCompositorFrame(compositor_frame_sink_id, std::move(frame)); 1107 InternalSwapCompositorFrame(compositor_frame_sink_id, std::move(frame));
1165 } 1108 }
1166 1109
1167 void RenderWidgetHostViewAndroid::ClearCompositorFrame() { 1110 void RenderWidgetHostViewAndroid::ClearCompositorFrame() {
1168 DestroyDelegatedContent(); 1111 DestroyDelegatedContent();
1169 } 1112 }
1170 1113
1171 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t compositor_frame_sink_id,
1172 cc::CompositorFrame frame) {
1173 DCHECK(locks_on_frame_count_);
1174
1175 // Store the incoming frame so that it can be swapped when all the locks have
1176 // been released. If there is already a stored frame, then replace and skip
1177 // the previous one but make sure we still eventually send the ACK. Holding
1178 // the ACK also blocks the renderer when its max_frames_pending is reached.
1179 if (last_frame_info_) {
1180 base::Closure ack_callback = base::Bind(
1181 &RenderWidgetHostViewAndroid::SendReclaimCompositorResources,
1182 weak_ptr_factory_.GetWeakPtr(),
1183 last_frame_info_->compositor_frame_sink_id, true /* is_swap_ack */);
1184
1185 ack_callbacks_.push(ack_callback);
1186 }
1187
1188 last_frame_info_.reset(
1189 new LastFrameInfo(compositor_frame_sink_id, std::move(frame)));
1190 }
1191
1192 void RenderWidgetHostViewAndroid::SynchronousFrameMetadata( 1114 void RenderWidgetHostViewAndroid::SynchronousFrameMetadata(
1193 cc::CompositorFrameMetadata frame_metadata) { 1115 cc::CompositorFrameMetadata frame_metadata) {
1194 if (!content_view_core_) 1116 if (!content_view_core_)
1195 return; 1117 return;
1196 1118
1197 bool is_mobile_optimized = IsMobileOptimizedFrame(frame_metadata); 1119 bool is_mobile_optimized = IsMobileOptimizedFrame(frame_metadata);
1198 1120
1199 if (host_ && host_->input_router()) { 1121 if (host_ && host_->input_router()) {
1200 host_->input_router()->NotifySiteIsMobileOptimized( 1122 host_->input_router()->NotifySiteIsMobileOptimized(
1201 is_mobile_optimized); 1123 is_mobile_optimized);
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 // window is still visible. This avoids visual artificts when transitioning 1331 // window is still visible. This avoids visual artificts when transitioning
1410 // between activities. 1332 // between activities.
1411 bool hide_frontbuffer = is_window_activity_started_ || !is_window_visible_; 1333 bool hide_frontbuffer = is_window_activity_started_ || !is_window_visible_;
1412 1334
1413 // Only stop observing the root window if the widget has been explicitly 1335 // Only stop observing the root window if the widget has been explicitly
1414 // hidden and the frontbuffer is being cleared. This allows window visibility 1336 // hidden and the frontbuffer is being cleared. This allows window visibility
1415 // notifications to eventually clear the frontbuffer. 1337 // notifications to eventually clear the frontbuffer.
1416 bool stop_observing_root_window = !is_showing_ && hide_frontbuffer; 1338 bool stop_observing_root_window = !is_showing_ && hide_frontbuffer;
1417 1339
1418 if (hide_frontbuffer) { 1340 if (hide_frontbuffer) {
1419 if (locks_on_frame_count_ == 0) 1341 view_.GetLayer()->SetHideLayerAndSubtree(true);
1420 view_.GetLayer()->SetHideLayerAndSubtree(true);
1421
1422 frame_evictor_->SetVisible(false); 1342 frame_evictor_->SetVisible(false);
1423 } 1343 }
1424 1344
1425 if (stop_observing_root_window) { 1345 if (stop_observing_root_window) {
1426 DCHECK(!is_showing_); 1346 DCHECK(!is_showing_);
1427 StopObservingRootWindow(); 1347 StopObservingRootWindow();
1428 } 1348 }
1429 1349
1430 if (!host_ || host_->is_hidden()) 1350 if (!host_ || host_->is_hidden())
1431 return; 1351 return;
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 1705
1786 void RenderWidgetHostViewAndroid::SetContentViewCore( 1706 void RenderWidgetHostViewAndroid::SetContentViewCore(
1787 ContentViewCoreImpl* content_view_core) { 1707 ContentViewCoreImpl* content_view_core) {
1788 DCHECK(!content_view_core || !content_view_core_ || 1708 DCHECK(!content_view_core || !content_view_core_ ||
1789 (content_view_core_ == content_view_core)); 1709 (content_view_core_ == content_view_core));
1790 StopObservingRootWindow(); 1710 StopObservingRootWindow();
1791 1711
1792 bool resize = false; 1712 bool resize = false;
1793 if (content_view_core != content_view_core_) { 1713 if (content_view_core != content_view_core_) {
1794 selection_controller_.reset(); 1714 selection_controller_.reset();
1795 ReleaseLocksOnSurface(); 1715 RunAckCallbacks();
1796 // TODO(yusufo) : Get rid of the below conditions and have a better handling 1716 // TODO(yusufo) : Get rid of the below conditions and have a better handling
1797 // for resizing after crbug.com/628302 is handled. 1717 // for resizing after crbug.com/628302 is handled.
1798 bool is_size_initialized = !content_view_core 1718 bool is_size_initialized = !content_view_core
1799 || content_view_core->GetViewportSizeDip().width() != 0 1719 || content_view_core->GetViewportSizeDip().width() != 0
1800 || content_view_core->GetViewportSizeDip().height() != 0; 1720 || content_view_core->GetViewportSizeDip().height() != 0;
1801 if (content_view_core_ || is_size_initialized) 1721 if (content_view_core_ || is_size_initialized)
1802 resize = true; 1722 resize = true;
1803 if (content_view_core_) { 1723 if (content_view_core_) {
1804 content_view_core_->RemoveObserver(this); 1724 content_view_core_->RemoveObserver(this);
1805 view_.RemoveFromParent(); 1725 view_.RemoveFromParent();
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1974 } 1894 }
1975 1895
1976 void RenderWidgetHostViewAndroid::OnActivityStarted() { 1896 void RenderWidgetHostViewAndroid::OnActivityStarted() {
1977 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityStarted"); 1897 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityStarted");
1978 DCHECK(observing_root_window_); 1898 DCHECK(observing_root_window_);
1979 is_window_activity_started_ = true; 1899 is_window_activity_started_ = true;
1980 ShowInternal(); 1900 ShowInternal();
1981 } 1901 }
1982 1902
1983 void RenderWidgetHostViewAndroid::OnLostResources() { 1903 void RenderWidgetHostViewAndroid::OnLostResources() {
1984 ReleaseLocksOnSurface();
1985 DestroyDelegatedContent(); 1904 DestroyDelegatedContent();
1986 DCHECK(ack_callbacks_.empty()); 1905 DCHECK(ack_callbacks_.empty());
1987 } 1906 }
1988 1907
1989 void RenderWidgetHostViewAndroid::OnStylusSelectBegin(float x0, 1908 void RenderWidgetHostViewAndroid::OnStylusSelectBegin(float x0,
1990 float y0, 1909 float y0,
1991 float x1, 1910 float x1,
1992 float y1) { 1911 float y1) {
1993 SelectBetweenCoordinates(gfx::PointF(x0, y0), gfx::PointF(x1, y1)); 1912 SelectBetweenCoordinates(gfx::PointF(x0, y0), gfx::PointF(x1, y1));
1994 } 1913 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2067 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); 1986 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor();
2068 if (!compositor) 1987 if (!compositor)
2069 return; 1988 return;
2070 1989
2071 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( 1990 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>(
2072 overscroll_refresh_handler, compositor, 1991 overscroll_refresh_handler, compositor,
2073 ui::GetScaleFactorForNativeView(GetNativeView())); 1992 ui::GetScaleFactorForNativeView(GetNativeView()));
2074 } 1993 }
2075 1994
2076 } // namespace content 1995 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698