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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 #include "ui/gfx/android/java_bitmap.h" | 94 #include "ui/gfx/android/java_bitmap.h" |
95 #include "ui/gfx/android/view_configuration.h" | 95 #include "ui/gfx/android/view_configuration.h" |
96 #include "ui/gfx/geometry/dip_util.h" | 96 #include "ui/gfx/geometry/dip_util.h" |
97 #include "ui/gfx/geometry/size_conversions.h" | 97 #include "ui/gfx/geometry/size_conversions.h" |
98 #include "ui/touch_selection/touch_selection_controller.h" | 98 #include "ui/touch_selection/touch_selection_controller.h" |
99 | 99 |
100 namespace content { | 100 namespace content { |
101 | 101 |
102 namespace { | 102 namespace { |
103 | 103 |
104 const int kUndefinedCompositorFrameSinkId = -1; | |
105 | |
106 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime"; | 104 static const char kAsyncReadBackString[] = "Compositing.CopyFromSurfaceTime"; |
107 | 105 |
108 class PendingReadbackLock; | 106 class PendingReadbackLock; |
109 | 107 |
110 PendingReadbackLock* g_pending_readback_lock = nullptr; | 108 PendingReadbackLock* g_pending_readback_lock = nullptr; |
111 | 109 |
112 class PendingReadbackLock : public base::RefCounted<PendingReadbackLock> { | 110 class PendingReadbackLock : public base::RefCounted<PendingReadbackLock> { |
113 public: | 111 public: |
114 PendingReadbackLock() { | 112 PendingReadbackLock() { |
115 DCHECK_EQ(g_pending_readback_lock, nullptr); | 113 DCHECK_EQ(g_pending_readback_lock, nullptr); |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 begin_frame_source_(nullptr), | 444 begin_frame_source_(nullptr), |
447 outstanding_begin_frame_requests_(0), | 445 outstanding_begin_frame_requests_(0), |
448 is_showing_(!widget_host->is_hidden()), | 446 is_showing_(!widget_host->is_hidden()), |
449 is_window_visible_(true), | 447 is_window_visible_(true), |
450 is_window_activity_started_(true), | 448 is_window_activity_started_(true), |
451 is_in_vr_(false), | 449 is_in_vr_(false), |
452 content_view_core_(nullptr), | 450 content_view_core_(nullptr), |
453 ime_adapter_android_(nullptr), | 451 ime_adapter_android_(nullptr), |
454 cached_background_color_(SK_ColorWHITE), | 452 cached_background_color_(SK_ColorWHITE), |
455 view_(this), | 453 view_(this), |
456 last_compositor_frame_sink_id_(kUndefinedCompositorFrameSinkId), | |
457 gesture_provider_(ui::GetGestureProviderConfig( | 454 gesture_provider_(ui::GetGestureProviderConfig( |
458 ui::GestureProviderConfigType::CURRENT_PLATFORM), | 455 ui::GestureProviderConfigType::CURRENT_PLATFORM), |
459 this), | 456 this), |
460 stylus_text_selector_(this), | 457 stylus_text_selector_(this), |
461 using_browser_compositor_(CompositorImpl::IsInitialized()), | 458 using_browser_compositor_(CompositorImpl::IsInitialized()), |
462 synchronous_compositor_client_(nullptr), | 459 synchronous_compositor_client_(nullptr), |
463 frame_evictor_(new DelegatedFrameEvictor(this)), | 460 frame_evictor_(new DelegatedFrameEvictor(this)), |
464 observing_root_window_(false), | 461 observing_root_window_(false), |
465 prev_top_shown_pix_(0.f), | 462 prev_top_shown_pix_(0.f), |
466 prev_bottom_shown_pix_(0.f), | 463 prev_bottom_shown_pix_(0.f), |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 } | 1092 } |
1096 | 1093 |
1097 std::unique_ptr<SyntheticGestureTarget> | 1094 std::unique_ptr<SyntheticGestureTarget> |
1098 RenderWidgetHostViewAndroid::CreateSyntheticGestureTarget() { | 1095 RenderWidgetHostViewAndroid::CreateSyntheticGestureTarget() { |
1099 return std::unique_ptr<SyntheticGestureTarget>( | 1096 return std::unique_ptr<SyntheticGestureTarget>( |
1100 new SyntheticGestureTargetAndroid( | 1097 new SyntheticGestureTargetAndroid( |
1101 host_, content_view_core_->CreateMotionEventSynthesizer())); | 1098 host_, content_view_core_->CreateMotionEventSynthesizer())); |
1102 } | 1099 } |
1103 | 1100 |
1104 void RenderWidgetHostViewAndroid::SendReclaimCompositorResources( | 1101 void RenderWidgetHostViewAndroid::SendReclaimCompositorResources( |
1105 uint32_t compositor_frame_sink_id, | |
1106 bool is_swap_ack) { | 1102 bool is_swap_ack) { |
1107 DCHECK(host_); | 1103 DCHECK(host_); |
1108 host_->Send(new ViewMsg_ReclaimCompositorResources( | 1104 host_->SendReclaimCompositorResources(is_swap_ack, |
1109 host_->GetRoutingID(), compositor_frame_sink_id, is_swap_ack, | 1105 surface_returned_resources_); |
1110 surface_returned_resources_)); | |
1111 surface_returned_resources_.clear(); | 1106 surface_returned_resources_.clear(); |
1112 } | 1107 } |
1113 | 1108 |
1114 void RenderWidgetHostViewAndroid::DidReceiveCompositorFrameAck() { | 1109 void RenderWidgetHostViewAndroid::DidReceiveCompositorFrameAck() { |
1115 RunAckCallbacks(); | 1110 RunAckCallbacks(); |
1116 } | 1111 } |
1117 | 1112 |
1118 void RenderWidgetHostViewAndroid::ReclaimResources( | 1113 void RenderWidgetHostViewAndroid::ReclaimResources( |
1119 const cc::ReturnedResourceArray& resources) { | 1114 const cc::ReturnedResourceArray& resources) { |
1120 if (resources.empty()) | 1115 if (resources.empty()) |
1121 return; | 1116 return; |
1122 std::copy(resources.begin(), resources.end(), | 1117 std::copy(resources.begin(), resources.end(), |
1123 std::back_inserter(surface_returned_resources_)); | 1118 std::back_inserter(surface_returned_resources_)); |
1124 if (ack_callbacks_.empty()) | 1119 if (ack_callbacks_.empty()) |
1125 SendReclaimCompositorResources(last_compositor_frame_sink_id_, | 1120 SendReclaimCompositorResources(false /* is_swap_ack */); |
1126 false /* is_swap_ack */); | |
1127 } | 1121 } |
1128 | 1122 |
1129 void RenderWidgetHostViewAndroid::CheckCompositorFrameSinkChanged( | 1123 void RenderWidgetHostViewAndroid::DidCreateNewRendererCompositorFrameSink() { |
1130 uint32_t compositor_frame_sink_id) { | |
1131 if (compositor_frame_sink_id == last_compositor_frame_sink_id_) | |
1132 return; | |
1133 | |
1134 delegated_frame_host_->CompositorFrameSinkChanged(); | 1124 delegated_frame_host_->CompositorFrameSinkChanged(); |
1135 | 1125 // Accumulated resources belong to the old RendererCompositorFrameSink and |
1136 if (!surface_returned_resources_.empty()) | 1126 // should not be returned. |
1137 SendReclaimCompositorResources(last_compositor_frame_sink_id_, | 1127 surface_returned_resources_.clear(); |
1138 false /* is_swap_ack */); | |
1139 | |
1140 last_compositor_frame_sink_id_ = compositor_frame_sink_id; | |
1141 } | 1128 } |
1142 | 1129 |
1143 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( | 1130 void RenderWidgetHostViewAndroid::SubmitCompositorFrame( |
1144 uint32_t compositor_frame_sink_id, | |
1145 const cc::LocalSurfaceId& local_surface_id, | 1131 const cc::LocalSurfaceId& local_surface_id, |
1146 cc::CompositorFrame frame) { | 1132 cc::CompositorFrame frame) { |
1147 last_scroll_offset_ = frame.metadata.root_scroll_offset; | 1133 last_scroll_offset_ = frame.metadata.root_scroll_offset; |
1148 DCHECK(delegated_frame_host_); | 1134 DCHECK(delegated_frame_host_); |
1149 DCHECK(!frame.render_pass_list.empty()); | 1135 DCHECK(!frame.render_pass_list.empty()); |
1150 | 1136 |
1151 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); | 1137 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); |
1152 current_surface_size_ = root_pass->output_rect.size(); | 1138 current_surface_size_ = root_pass->output_rect.size(); |
1153 bool is_transparent = root_pass->has_transparent_background; | 1139 bool is_transparent = root_pass->has_transparent_background; |
1154 | 1140 |
1155 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); | 1141 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); |
1156 | 1142 |
1157 CheckCompositorFrameSinkChanged(compositor_frame_sink_id); | |
1158 bool has_content = !current_surface_size_.IsEmpty(); | 1143 bool has_content = !current_surface_size_.IsEmpty(); |
1159 | 1144 |
1160 base::Closure ack_callback = | 1145 base::Closure ack_callback = |
1161 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources, | 1146 base::Bind(&RenderWidgetHostViewAndroid::SendReclaimCompositorResources, |
1162 weak_ptr_factory_.GetWeakPtr(), compositor_frame_sink_id, | 1147 weak_ptr_factory_.GetWeakPtr(), true /* is_swap_ack */); |
1163 true /* is_swap_ack */); | |
1164 | 1148 |
1165 ack_callbacks_.push(ack_callback); | 1149 ack_callbacks_.push(ack_callback); |
1166 | 1150 |
1167 if (!has_content) { | 1151 if (!has_content) { |
1168 DestroyDelegatedContent(); | 1152 DestroyDelegatedContent(); |
1169 } else { | 1153 } else { |
1170 delegated_frame_host_->SubmitCompositorFrame(local_surface_id, | 1154 delegated_frame_host_->SubmitCompositorFrame(local_surface_id, |
1171 std::move(frame)); | 1155 std::move(frame)); |
1172 frame_evictor_->SwappedFrame(!host_->is_hidden()); | 1156 frame_evictor_->SwappedFrame(!host_->is_hidden()); |
1173 } | 1157 } |
(...skipping 14 matching lines...) Expand all Loading... |
1188 if (!delegated_frame_host_) | 1172 if (!delegated_frame_host_) |
1189 return; | 1173 return; |
1190 | 1174 |
1191 if (!delegated_frame_host_->HasDelegatedContent()) | 1175 if (!delegated_frame_host_->HasDelegatedContent()) |
1192 return; | 1176 return; |
1193 | 1177 |
1194 frame_evictor_->DiscardedFrame(); | 1178 frame_evictor_->DiscardedFrame(); |
1195 delegated_frame_host_->DestroyDelegatedContent(); | 1179 delegated_frame_host_->DestroyDelegatedContent(); |
1196 } | 1180 } |
1197 | 1181 |
1198 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( | |
1199 uint32_t compositor_frame_sink_id, | |
1200 const cc::LocalSurfaceId& local_surface_id, | |
1201 cc::CompositorFrame frame) { | |
1202 InternalSwapCompositorFrame(compositor_frame_sink_id, local_surface_id, | |
1203 std::move(frame)); | |
1204 } | |
1205 | |
1206 void RenderWidgetHostViewAndroid::ClearCompositorFrame() { | 1182 void RenderWidgetHostViewAndroid::ClearCompositorFrame() { |
1207 DestroyDelegatedContent(); | 1183 DestroyDelegatedContent(); |
1208 } | 1184 } |
1209 | 1185 |
1210 void RenderWidgetHostViewAndroid::SynchronousFrameMetadata( | 1186 void RenderWidgetHostViewAndroid::SynchronousFrameMetadata( |
1211 cc::CompositorFrameMetadata frame_metadata) { | 1187 cc::CompositorFrameMetadata frame_metadata) { |
1212 if (!content_view_core_) | 1188 if (!content_view_core_) |
1213 return; | 1189 return; |
1214 | 1190 |
1215 bool is_mobile_optimized = IsMobileOptimizedFrame(frame_metadata); | 1191 bool is_mobile_optimized = IsMobileOptimizedFrame(frame_metadata); |
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2140 | 2116 |
2141 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); | 2117 ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); |
2142 if (!compositor) | 2118 if (!compositor) |
2143 return; | 2119 return; |
2144 | 2120 |
2145 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( | 2121 overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>( |
2146 overscroll_refresh_handler, compositor, view_.GetDipScale()); | 2122 overscroll_refresh_handler, compositor, view_.GetDipScale()); |
2147 } | 2123 } |
2148 | 2124 |
2149 } // namespace content | 2125 } // namespace content |
OLD | NEW |