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

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: mac 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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 ime_adapter_android_(this), 435 ime_adapter_android_(this),
436 cached_background_color_(SK_ColorWHITE), 436 cached_background_color_(SK_ColorWHITE),
437 last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId), 437 last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId),
438 gesture_provider_(ui::GetGestureProviderConfig( 438 gesture_provider_(ui::GetGestureProviderConfig(
439 ui::GestureProviderConfigType::CURRENT_PLATFORM), 439 ui::GestureProviderConfigType::CURRENT_PLATFORM),
440 this), 440 this),
441 stylus_text_selector_(this), 441 stylus_text_selector_(this),
442 using_browser_compositor_(CompositorImpl::IsInitialized()), 442 using_browser_compositor_(CompositorImpl::IsInitialized()),
443 synchronous_compositor_client_(nullptr), 443 synchronous_compositor_client_(nullptr),
444 frame_evictor_(new DelegatedFrameEvictor(this)), 444 frame_evictor_(new DelegatedFrameEvictor(this)),
445 locks_on_frame_count_(0),
446 observing_root_window_(false), 445 observing_root_window_(false),
447 weak_ptr_factory_(this) { 446 weak_ptr_factory_(this) {
448 // Set the layer which will hold the content layer for this view. The content 447 // Set the layer which will hold the content layer for this view. The content
449 // layer is managed by the DelegatedFrameHost. 448 // layer is managed by the DelegatedFrameHost.
450 view_.SetLayer(cc::Layer::Create()); 449 view_.SetLayer(cc::Layer::Create());
451 if (using_browser_compositor_) { 450 if (using_browser_compositor_) {
452 delegated_frame_host_.reset(new ui::DelegatedFrameHostAndroid( 451 delegated_frame_host_.reset(new ui::DelegatedFrameHostAndroid(
453 &view_, cached_background_color_, this)); 452 &view_, cached_background_color_, this));
454 } 453 }
455 454
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 HideInternal(); 622 HideInternal();
624 } 623 }
625 624
626 bool RenderWidgetHostViewAndroid::IsShowing() { 625 bool RenderWidgetHostViewAndroid::IsShowing() {
627 // ContentViewCoreImpl represents the native side of the Java 626 // ContentViewCoreImpl represents the native side of the Java
628 // ContentViewCore. It being NULL means that it is not attached 627 // ContentViewCore. It being NULL means that it is not attached
629 // to the View system yet, so we treat this RWHVA as hidden. 628 // to the View system yet, so we treat this RWHVA as hidden.
630 return is_showing_ && content_view_core_; 629 return is_showing_ && content_view_core_;
631 } 630 }
632 631
633 void RenderWidgetHostViewAndroid::LockCompositingSurface() {
634 DCHECK(HasValidFrame());
635 DCHECK(host_);
636 DCHECK(frame_evictor_->HasFrame());
637 frame_evictor_->LockFrame();
638 locks_on_frame_count_++;
639 }
640
641 void RenderWidgetHostViewAndroid::UnlockCompositingSurface() {
642 if (!frame_evictor_->HasFrame()) {
643 DCHECK_EQ(locks_on_frame_count_, 0u);
644 return;
645 }
646
647 DCHECK_GT(locks_on_frame_count_, 0u);
648 locks_on_frame_count_--;
649 frame_evictor_->UnlockFrame();
650
651 if (locks_on_frame_count_ == 0) {
652 if (last_frame_info_) {
boliu 2017/02/02 22:58:47 looks like last_frame_info_ can be removed too?
Khushal 2017/02/02 23:25:00 Yup. Done.
653 InternalSwapCompositorFrame(last_frame_info_->compositor_frame_sink_id,
654 std::move(last_frame_info_->frame));
655 last_frame_info_.reset();
656 }
657
658 view_.GetLayer()->SetHideLayerAndSubtree(!is_showing_);
659 }
660 }
661
662 void RenderWidgetHostViewAndroid::OnShowUnhandledTapUIIfNeeded(int x_dip, 632 void RenderWidgetHostViewAndroid::OnShowUnhandledTapUIIfNeeded(int x_dip,
663 int y_dip) { 633 int y_dip) {
664 if (!content_view_core_) 634 if (!content_view_core_)
665 return; 635 return;
666 // Validate the coordinates are within the viewport. 636 // Validate the coordinates are within the viewport.
667 gfx::Size viewport_size = content_view_core_->GetViewportSizeDip(); 637 gfx::Size viewport_size = content_view_core_->GetViewportSizeDip();
668 if (x_dip < 0 || x_dip > viewport_size.width() || 638 if (x_dip < 0 || x_dip > viewport_size.width() ||
669 y_dip < 0 || y_dip > viewport_size.height()) 639 y_dip < 0 || y_dip > viewport_size.height())
670 return; 640 return;
671 content_view_core_->OnShowUnhandledTapUIIfNeeded(x_dip, y_dip); 641 content_view_core_->OnShowUnhandledTapUIIfNeeded(x_dip, y_dip);
672 } 642 }
673 643
674 void RenderWidgetHostViewAndroid::ReleaseLocksOnSurface() {
675 if (!frame_evictor_->HasFrame()) {
676 DCHECK_EQ(locks_on_frame_count_, 0u);
677 return;
678 }
679 while (locks_on_frame_count_ > 0) {
680 UnlockCompositingSurface();
681 }
682 RunAckCallbacks();
683 }
684
685 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { 644 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const {
686 if (!content_view_core_) 645 if (!content_view_core_)
687 return default_bounds_; 646 return default_bounds_;
688 647
689 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 648 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
690 switches::kEnableOSKOverscroll)) 649 switches::kEnableOSKOverscroll))
691 return gfx::Rect(content_view_core_->GetViewSizeWithOSKHidden()); 650 return gfx::Rect(content_view_core_->GetViewSizeWithOSKHidden());
692 651
693 return gfx::Rect(content_view_core_->GetViewSize()); 652 return gfx::Rect(content_view_core_->GetViewSize());
694 } 653 }
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 false /* is_swap_ack */); 1043 false /* is_swap_ack */);
1085 1044
1086 last_compositor_frame_sink_id_ = compositor_frame_sink_id; 1045 last_compositor_frame_sink_id_ = compositor_frame_sink_id;
1087 } 1046 }
1088 1047
1089 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( 1048 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame(
1090 uint32_t compositor_frame_sink_id, 1049 uint32_t compositor_frame_sink_id,
1091 cc::CompositorFrame frame) { 1050 cc::CompositorFrame frame) {
1092 last_scroll_offset_ = frame.metadata.root_scroll_offset; 1051 last_scroll_offset_ = frame.metadata.root_scroll_offset;
1093 DCHECK(delegated_frame_host_); 1052 DCHECK(delegated_frame_host_);
1094
1095 if (locks_on_frame_count_ > 0) {
1096 DCHECK(HasValidFrame());
1097 RetainFrame(compositor_frame_sink_id, std::move(frame));
1098 return;
1099 }
1100
1101 DCHECK(!frame.render_pass_list.empty()); 1053 DCHECK(!frame.render_pass_list.empty());
1102 1054
1103 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); 1055 cc::RenderPass* root_pass = frame.render_pass_list.back().get();
1104 current_surface_size_ = root_pass->output_rect.size(); 1056 current_surface_size_ = root_pass->output_rect.size();
1105 bool is_transparent = root_pass->has_transparent_background; 1057 bool is_transparent = root_pass->has_transparent_background;
1106 1058
1107 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); 1059 cc::CompositorFrameMetadata metadata = frame.metadata.Clone();
1108 1060
1109 CheckCompositorFrameSinkChanged(compositor_frame_sink_id); 1061 CheckCompositorFrameSinkChanged(compositor_frame_sink_id);
1110 bool has_content = !current_surface_size_.IsEmpty(); 1062 bool has_content = !current_surface_size_.IsEmpty();
(...skipping 21 matching lines...) Expand all
1132 1084
1133 // As the metadata update may trigger view invalidation, always call it after 1085 // As the metadata update may trigger view invalidation, always call it after
1134 // any potential compositor scheduling. 1086 // any potential compositor scheduling.
1135 OnFrameMetadataUpdated(std::move(metadata), is_transparent); 1087 OnFrameMetadataUpdated(std::move(metadata), is_transparent);
1136 } 1088 }
1137 1089
1138 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() { 1090 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() {
1139 DCHECK(!delegated_frame_host_ || 1091 DCHECK(!delegated_frame_host_ ||
1140 delegated_frame_host_->HasDelegatedContent() == 1092 delegated_frame_host_->HasDelegatedContent() ==
1141 frame_evictor_->HasFrame()); 1093 frame_evictor_->HasFrame());
1142 DCHECK_EQ(locks_on_frame_count_, 0u);
1143 1094
1144 if (!delegated_frame_host_) 1095 if (!delegated_frame_host_)
1145 return; 1096 return;
1146 1097
1147 if (!delegated_frame_host_->HasDelegatedContent()) 1098 if (!delegated_frame_host_->HasDelegatedContent())
1148 return; 1099 return;
1149 1100
1150 frame_evictor_->DiscardedFrame(); 1101 frame_evictor_->DiscardedFrame();
1151 delegated_frame_host_->DestroyDelegatedContent(); 1102 delegated_frame_host_->DestroyDelegatedContent();
1152 } 1103 }
1153 1104
1154 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( 1105 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame(
1155 uint32_t compositor_frame_sink_id, 1106 uint32_t compositor_frame_sink_id,
1156 cc::CompositorFrame frame) { 1107 cc::CompositorFrame frame) {
1157 InternalSwapCompositorFrame(compositor_frame_sink_id, std::move(frame)); 1108 InternalSwapCompositorFrame(compositor_frame_sink_id, std::move(frame));
1158 } 1109 }
1159 1110
1160 void RenderWidgetHostViewAndroid::ClearCompositorFrame() { 1111 void RenderWidgetHostViewAndroid::ClearCompositorFrame() {
1161 DestroyDelegatedContent(); 1112 DestroyDelegatedContent();
1162 } 1113 }
1163 1114
1164 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t compositor_frame_sink_id,
1165 cc::CompositorFrame frame) {
1166 DCHECK(locks_on_frame_count_);
1167
1168 // Store the incoming frame so that it can be swapped when all the locks have
1169 // been released. If there is already a stored frame, then replace and skip
1170 // the previous one but make sure we still eventually send the ACK. Holding
1171 // the ACK also blocks the renderer when its max_frames_pending is reached.
1172 if (last_frame_info_) {
1173 base::Closure ack_callback = base::Bind(
1174 &RenderWidgetHostViewAndroid::SendReclaimCompositorResources,
1175 weak_ptr_factory_.GetWeakPtr(),
1176 last_frame_info_->compositor_frame_sink_id, true /* is_swap_ack */);
1177
1178 ack_callbacks_.push(ack_callback);
1179 }
1180
1181 last_frame_info_.reset(
1182 new LastFrameInfo(compositor_frame_sink_id, std::move(frame)));
1183 }
1184
1185 void RenderWidgetHostViewAndroid::SynchronousFrameMetadata( 1115 void RenderWidgetHostViewAndroid::SynchronousFrameMetadata(
1186 cc::CompositorFrameMetadata frame_metadata) { 1116 cc::CompositorFrameMetadata frame_metadata) {
1187 if (!content_view_core_) 1117 if (!content_view_core_)
1188 return; 1118 return;
1189 1119
1190 bool is_mobile_optimized = IsMobileOptimizedFrame(frame_metadata); 1120 bool is_mobile_optimized = IsMobileOptimizedFrame(frame_metadata);
1191 1121
1192 if (host_ && host_->input_router()) { 1122 if (host_ && host_->input_router()) {
1193 host_->input_router()->NotifySiteIsMobileOptimized( 1123 host_->input_router()->NotifySiteIsMobileOptimized(
1194 is_mobile_optimized); 1124 is_mobile_optimized);
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 // window is still visible. This avoids visual artificts when transitioning 1332 // window is still visible. This avoids visual artificts when transitioning
1403 // between activities. 1333 // between activities.
1404 bool hide_frontbuffer = is_window_activity_started_ || !is_window_visible_; 1334 bool hide_frontbuffer = is_window_activity_started_ || !is_window_visible_;
1405 1335
1406 // Only stop observing the root window if the widget has been explicitly 1336 // Only stop observing the root window if the widget has been explicitly
1407 // hidden and the frontbuffer is being cleared. This allows window visibility 1337 // hidden and the frontbuffer is being cleared. This allows window visibility
1408 // notifications to eventually clear the frontbuffer. 1338 // notifications to eventually clear the frontbuffer.
1409 bool stop_observing_root_window = !is_showing_ && hide_frontbuffer; 1339 bool stop_observing_root_window = !is_showing_ && hide_frontbuffer;
1410 1340
1411 if (hide_frontbuffer) { 1341 if (hide_frontbuffer) {
1412 if (locks_on_frame_count_ == 0) 1342 view_.GetLayer()->SetHideLayerAndSubtree(true);
1413 view_.GetLayer()->SetHideLayerAndSubtree(true);
1414
1415 frame_evictor_->SetVisible(false); 1343 frame_evictor_->SetVisible(false);
1416 } 1344 }
1417 1345
1418 if (stop_observing_root_window) { 1346 if (stop_observing_root_window) {
1419 DCHECK(!is_showing_); 1347 DCHECK(!is_showing_);
1420 StopObservingRootWindow(); 1348 StopObservingRootWindow();
1421 } 1349 }
1422 1350
1423 if (!host_ || host_->is_hidden()) 1351 if (!host_ || host_->is_hidden())
1424 return; 1352 return;
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1778 1706
1779 void RenderWidgetHostViewAndroid::SetContentViewCore( 1707 void RenderWidgetHostViewAndroid::SetContentViewCore(
1780 ContentViewCoreImpl* content_view_core) { 1708 ContentViewCoreImpl* content_view_core) {
1781 DCHECK(!content_view_core || !content_view_core_ || 1709 DCHECK(!content_view_core || !content_view_core_ ||
1782 (content_view_core_ == content_view_core)); 1710 (content_view_core_ == content_view_core));
1783 StopObservingRootWindow(); 1711 StopObservingRootWindow();
1784 1712
1785 bool resize = false; 1713 bool resize = false;
1786 if (content_view_core != content_view_core_) { 1714 if (content_view_core != content_view_core_) {
1787 selection_controller_.reset(); 1715 selection_controller_.reset();
1788 ReleaseLocksOnSurface(); 1716 RunAckCallbacks();
1789 // TODO(yusufo) : Get rid of the below conditions and have a better handling 1717 // TODO(yusufo) : Get rid of the below conditions and have a better handling
1790 // for resizing after crbug.com/628302 is handled. 1718 // for resizing after crbug.com/628302 is handled.
1791 bool is_size_initialized = !content_view_core 1719 bool is_size_initialized = !content_view_core
1792 || content_view_core->GetViewportSizeDip().width() != 0 1720 || content_view_core->GetViewportSizeDip().width() != 0
1793 || content_view_core->GetViewportSizeDip().height() != 0; 1721 || content_view_core->GetViewportSizeDip().height() != 0;
1794 if (content_view_core_ || is_size_initialized) 1722 if (content_view_core_ || is_size_initialized)
1795 resize = true; 1723 resize = true;
1796 if (content_view_core_) { 1724 if (content_view_core_) {
1797 content_view_core_->RemoveObserver(this); 1725 content_view_core_->RemoveObserver(this);
1798 view_.RemoveFromParent(); 1726 view_.RemoveFromParent();
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1971 } 1899 }
1972 1900
1973 void RenderWidgetHostViewAndroid::OnActivityStarted() { 1901 void RenderWidgetHostViewAndroid::OnActivityStarted() {
1974 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityStarted"); 1902 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityStarted");
1975 DCHECK(observing_root_window_); 1903 DCHECK(observing_root_window_);
1976 is_window_activity_started_ = true; 1904 is_window_activity_started_ = true;
1977 ShowInternal(); 1905 ShowInternal();
1978 } 1906 }
1979 1907
1980 void RenderWidgetHostViewAndroid::OnLostResources() { 1908 void RenderWidgetHostViewAndroid::OnLostResources() {
1981 ReleaseLocksOnSurface();
Khushal 2017/02/02 01:46:35 So at the other place where we were calling this,
1982 DestroyDelegatedContent(); 1909 DestroyDelegatedContent();
1983 DCHECK(ack_callbacks_.empty()); 1910 DCHECK(ack_callbacks_.empty());
1984 } 1911 }
1985 1912
1986 void RenderWidgetHostViewAndroid::OnStylusSelectBegin(float x0, 1913 void RenderWidgetHostViewAndroid::OnStylusSelectBegin(float x0,
1987 float y0, 1914 float y0,
1988 float x1, 1915 float x1,
1989 float y1) { 1916 float y1) {
1990 SelectBetweenCoordinates(gfx::PointF(x0, y0), gfx::PointF(x1, y1)); 1917 SelectBetweenCoordinates(gfx::PointF(x0, y0), gfx::PointF(x1, y1));
1991 } 1918 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2064 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); 1991 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor();
2065 if (!compositor) 1992 if (!compositor)
2066 return; 1993 return;
2067 1994
2068 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( 1995 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>(
2069 overscroll_refresh_handler, compositor, 1996 overscroll_refresh_handler, compositor,
2070 ui::GetScaleFactorForNativeView(GetNativeView())); 1997 ui::GetScaleFactorForNativeView(GetNativeView()));
2071 } 1998 }
2072 1999
2073 } // namespace content 2000 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698