OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "android_webview/browser/browser_view_renderer.h" | 5 #include "android_webview/browser/browser_view_renderer.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "android_webview/browser/browser_view_renderer_client.h" | 9 #include "android_webview/browser/browser_view_renderer_client.h" |
10 #include "android_webview/browser/child_frame.h" | 10 #include "android_webview/browser/child_frame.h" |
11 #include "android_webview/browser/compositor_frame_consumer.h" | |
11 #include "base/auto_reset.h" | 12 #include "base/auto_reset.h" |
12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
17 #include "base/supports_user_data.h" | 18 #include "base/supports_user_data.h" |
18 #include "base/trace_event/trace_event_argument.h" | 19 #include "base/trace_event/trace_event_argument.h" |
19 #include "cc/output/compositor_frame.h" | 20 #include "cc/output/compositor_frame.h" |
20 #include "cc/output/compositor_frame_ack.h" | 21 #include "cc/output/compositor_frame_ack.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 content::WebContents* web_contents) { | 86 content::WebContents* web_contents) { |
86 return BrowserViewRendererUserData::GetBrowserViewRenderer(web_contents); | 87 return BrowserViewRendererUserData::GetBrowserViewRenderer(web_contents); |
87 } | 88 } |
88 | 89 |
89 BrowserViewRenderer::BrowserViewRenderer( | 90 BrowserViewRenderer::BrowserViewRenderer( |
90 BrowserViewRendererClient* client, | 91 BrowserViewRendererClient* client, |
91 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, | 92 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, |
92 bool disable_page_visibility) | 93 bool disable_page_visibility) |
93 : client_(client), | 94 : client_(client), |
94 ui_task_runner_(ui_task_runner), | 95 ui_task_runner_(ui_task_runner), |
95 render_thread_manager_(nullptr), | 96 compositor_frame_consumer_(nullptr), |
96 disable_page_visibility_(disable_page_visibility), | 97 disable_page_visibility_(disable_page_visibility), |
97 compositor_(NULL), | 98 compositor_(NULL), |
98 is_paused_(false), | 99 is_paused_(false), |
99 view_visible_(false), | 100 view_visible_(false), |
100 window_visible_(false), | 101 window_visible_(false), |
101 attached_to_window_(false), | 102 attached_to_window_(false), |
102 hardware_enabled_(false), | 103 hardware_enabled_(false), |
103 dip_scale_(0.f), | 104 dip_scale_(0.f), |
104 page_scale_factor_(1.f), | 105 page_scale_factor_(1.f), |
105 min_page_scale_factor_(0.f), | 106 min_page_scale_factor_(0.f), |
106 max_page_scale_factor_(0.f), | 107 max_page_scale_factor_(0.f), |
107 on_new_picture_enable_(false), | 108 on_new_picture_enable_(false), |
108 clear_view_(false), | 109 clear_view_(false), |
109 offscreen_pre_raster_(false), | 110 offscreen_pre_raster_(false), |
110 next_compositor_id_(1) {} | 111 next_compositor_id_(1) {} |
111 | 112 |
112 BrowserViewRenderer::~BrowserViewRenderer() { | 113 BrowserViewRenderer::~BrowserViewRenderer() { |
113 DCHECK(compositor_map_.empty()); | 114 DCHECK(compositor_map_.empty()); |
115 SetCompositorFrameConsumer(nullptr); | |
114 } | 116 } |
115 | 117 |
116 void BrowserViewRenderer::SetRenderThreadManager( | 118 void BrowserViewRenderer::SetCompositorFrameConsumer( |
117 RenderThreadManager* render_thread_manager) { | 119 CompositorFrameConsumer* compositor_frame_consumer) { |
118 render_thread_manager_ = render_thread_manager; | 120 if (compositor_frame_consumer == compositor_frame_consumer_) { |
121 return; | |
122 } | |
123 if (compositor_frame_consumer_) { | |
124 compositor_frame_consumer_->SetCompositorFrameProducer(nullptr); | |
125 } | |
126 compositor_frame_consumer_ = compositor_frame_consumer; | |
127 if (compositor_frame_consumer_) { | |
128 compositor_frame_consumer_->SetCompositorFrameProducer(this); | |
129 } | |
119 } | 130 } |
120 | 131 |
121 void BrowserViewRenderer::RegisterWithWebContents( | 132 void BrowserViewRenderer::RegisterWithWebContents( |
122 content::WebContents* web_contents) { | 133 content::WebContents* web_contents) { |
123 web_contents->SetUserData(kBrowserViewRendererUserDataKey, | 134 web_contents->SetUserData(kBrowserViewRendererUserDataKey, |
124 new BrowserViewRendererUserData(this)); | 135 new BrowserViewRendererUserData(this)); |
125 } | 136 } |
126 | 137 |
127 void BrowserViewRenderer::TrimMemory() { | 138 void BrowserViewRenderer::TrimMemory() { |
128 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 139 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 if (clear_view_) { | 191 if (clear_view_) { |
181 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_ClearView", | 192 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_ClearView", |
182 TRACE_EVENT_SCOPE_THREAD); | 193 TRACE_EVENT_SCOPE_THREAD); |
183 return false; | 194 return false; |
184 } | 195 } |
185 | 196 |
186 return true; | 197 return true; |
187 } | 198 } |
188 | 199 |
189 bool BrowserViewRenderer::OnDrawHardware() { | 200 bool BrowserViewRenderer::OnDrawHardware() { |
190 DCHECK(render_thread_manager_); | |
191 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware"); | 201 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware"); |
202 if (!compositor_frame_consumer_) { | |
203 return false; | |
204 } | |
192 | 205 |
193 render_thread_manager_->InitializeHardwareDrawIfNeededOnUI(); | 206 compositor_frame_consumer_->InitializeHardwareDrawIfNeededOnUI(); |
194 | 207 |
195 if (!CanOnDraw()) { | 208 if (!CanOnDraw()) { |
196 return false; | 209 return false; |
197 } | 210 } |
198 | 211 |
199 render_thread_manager_->SetScrollOffsetOnUI(last_on_draw_scroll_offset_); | 212 compositor_frame_consumer_->SetScrollOffsetOnUI(last_on_draw_scroll_offset_); |
200 hardware_enabled_ = true; | 213 hardware_enabled_ = true; |
201 | 214 |
202 external_draw_constraints_ = | 215 external_draw_constraints_ = |
203 render_thread_manager_->GetParentDrawConstraintsOnUI(); | 216 compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); |
204 | 217 |
205 ReturnResourceFromParent(); | 218 ReturnResourceFromParent(compositor_frame_consumer_); |
206 UpdateMemoryPolicy(); | 219 UpdateMemoryPolicy(); |
207 | 220 |
208 gfx::Size surface_size(size_); | 221 gfx::Size surface_size(size_); |
209 gfx::Rect viewport(surface_size); | 222 gfx::Rect viewport(surface_size); |
210 gfx::Rect clip = viewport; | 223 gfx::Rect clip = viewport; |
211 gfx::Transform transform_for_tile_priority = | 224 gfx::Transform transform_for_tile_priority = |
212 external_draw_constraints_.transform; | 225 external_draw_constraints_.transform; |
213 | 226 |
214 // If the WebView is on a layer, WebView does not know what transform is | 227 // If the WebView is on a layer, WebView does not know what transform is |
215 // applied onto the layer so global visible rect does not make sense here. | 228 // applied onto the layer so global visible rect does not make sense here. |
216 // In this case, just use the surface rect for tiling. | 229 // In this case, just use the surface rect for tiling. |
217 gfx::Rect viewport_rect_for_tile_priority; | 230 gfx::Rect viewport_rect_for_tile_priority; |
218 | 231 |
219 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. | 232 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. |
220 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { | 233 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { |
221 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; | 234 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; |
222 } | 235 } |
223 | 236 |
224 content::SynchronousCompositor::Frame frame = | 237 content::SynchronousCompositor::Frame frame = |
225 compositor_->DemandDrawHw(surface_size, | 238 compositor_->DemandDrawHw(surface_size, |
226 gfx::Transform(), | 239 gfx::Transform(), |
227 viewport, | 240 viewport, |
228 clip, | 241 clip, |
229 viewport_rect_for_tile_priority, | 242 viewport_rect_for_tile_priority, |
230 transform_for_tile_priority); | 243 transform_for_tile_priority); |
231 if (!frame.frame.get()) { | 244 if (!frame.frame.get()) { |
232 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame", | 245 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame", |
233 TRACE_EVENT_SCOPE_THREAD); | 246 TRACE_EVENT_SCOPE_THREAD); |
234 hardware_enabled_ = render_thread_manager_->HasFrameOnUI(); | 247 hardware_enabled_ = compositor_frame_consumer_->HasFrameOnUI(); |
235 if (!hardware_enabled_) | 248 if (!hardware_enabled_) |
236 UpdateMemoryPolicy(); | 249 UpdateMemoryPolicy(); |
237 return hardware_enabled_; | 250 return hardware_enabled_; |
238 } | 251 } |
239 | 252 |
240 std::unique_ptr<ChildFrame> child_frame = base::WrapUnique(new ChildFrame( | 253 std::unique_ptr<ChildFrame> child_frame = base::WrapUnique(new ChildFrame( |
241 frame.output_surface_id, std::move(frame.frame), | 254 frame.output_surface_id, std::move(frame.frame), |
242 GetCompositorID(compositor_), viewport_rect_for_tile_priority.IsEmpty(), | 255 GetCompositorID(compositor_), viewport_rect_for_tile_priority.IsEmpty(), |
243 transform_for_tile_priority, offscreen_pre_raster_, | 256 transform_for_tile_priority, offscreen_pre_raster_, |
244 external_draw_constraints_.is_layer)); | 257 external_draw_constraints_.is_layer)); |
245 | 258 |
246 ReturnUnusedResource(render_thread_manager_->PassUncommittedFrameOnUI()); | 259 ReturnUnusedResource(compositor_frame_consumer_->PassUncommittedFrameOnUI()); |
247 render_thread_manager_->SetFrameOnUI(std::move(child_frame)); | 260 compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame)); |
248 return true; | 261 return true; |
249 } | 262 } |
250 | 263 |
251 void BrowserViewRenderer::OnParentDrawConstraintsUpdated() { | 264 void BrowserViewRenderer::OnParentDrawConstraintsUpdated() { |
252 DCHECK(render_thread_manager_); | 265 DCHECK(compositor_frame_consumer_); |
253 PostInvalidate(); | 266 PostInvalidate(); |
254 external_draw_constraints_ = | 267 external_draw_constraints_ = |
255 render_thread_manager_->GetParentDrawConstraintsOnUI(); | 268 compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); |
256 UpdateMemoryPolicy(); | 269 UpdateMemoryPolicy(); |
257 } | 270 } |
258 | 271 |
272 void BrowserViewRenderer::OnCompositorFrameConsumerWillDestroy() { | |
273 DCHECK(compositor_frame_consumer_); | |
274 SetCompositorFrameConsumer(nullptr); | |
275 } | |
276 | |
259 void BrowserViewRenderer::ReturnUnusedResource( | 277 void BrowserViewRenderer::ReturnUnusedResource( |
260 std::unique_ptr<ChildFrame> child_frame) { | 278 std::unique_ptr<ChildFrame> child_frame) { |
261 if (!child_frame.get() || !child_frame->frame.get()) | 279 if (!child_frame.get() || !child_frame->frame.get()) |
262 return; | 280 return; |
263 | 281 |
264 cc::CompositorFrameAck frame_ack; | 282 cc::CompositorFrameAck frame_ack; |
265 cc::TransferableResource::ReturnResources( | 283 cc::TransferableResource::ReturnResources( |
266 child_frame->frame->delegated_frame_data->resource_list, | 284 child_frame->frame->delegated_frame_data->resource_list, |
267 &frame_ack.resources); | 285 &frame_ack.resources); |
268 content::SynchronousCompositor* compositor = | 286 content::SynchronousCompositor* compositor = |
269 compositor_map_[child_frame->compositor_id]; | 287 compositor_map_[child_frame->compositor_id]; |
270 if (compositor && !frame_ack.resources.empty()) | 288 if (compositor && !frame_ack.resources.empty()) |
271 compositor->ReturnResources(child_frame->output_surface_id, frame_ack); | 289 compositor->ReturnResources(child_frame->output_surface_id, frame_ack); |
272 } | 290 } |
273 | 291 |
274 void BrowserViewRenderer::ReturnResourceFromParent() { | 292 void BrowserViewRenderer::ReturnResourceFromParent( |
275 DCHECK(render_thread_manager_); | 293 CompositorFrameConsumer* compositor_frame_consumer) { |
276 RenderThreadManager::ReturnedResourcesMap returned_resource_map; | 294 CompositorFrameConsumer::ReturnedResourcesMap returned_resource_map; |
277 render_thread_manager_->SwapReturnedResourcesOnUI(&returned_resource_map); | 295 compositor_frame_consumer->SwapReturnedResourcesOnUI(&returned_resource_map); |
278 for (auto iterator = returned_resource_map.begin(); | 296 for (auto iterator = returned_resource_map.begin(); |
279 iterator != returned_resource_map.end(); iterator++) { | 297 iterator != returned_resource_map.end(); iterator++) { |
280 uint32_t compositor_id = iterator->first; | 298 uint32_t compositor_id = iterator->first; |
281 content::SynchronousCompositor* compositor = compositor_map_[compositor_id]; | 299 content::SynchronousCompositor* compositor = compositor_map_[compositor_id]; |
282 cc::CompositorFrameAck frame_ack; | 300 cc::CompositorFrameAck frame_ack; |
283 frame_ack.resources.swap(iterator->second.resources); | 301 frame_ack.resources.swap(iterator->second.resources); |
284 | 302 |
285 if (compositor && !frame_ack.resources.empty()) { | 303 if (compositor && !frame_ack.resources.empty()) { |
286 compositor->ReturnResources(iterator->second.output_surface_id, | 304 compositor->ReturnResources(iterator->second.output_surface_id, |
287 frame_ack); | 305 frame_ack); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 } | 431 } |
414 | 432 |
415 void BrowserViewRenderer::OnComputeScroll(base::TimeTicks animation_time) { | 433 void BrowserViewRenderer::OnComputeScroll(base::TimeTicks animation_time) { |
416 if (!compositor_) | 434 if (!compositor_) |
417 return; | 435 return; |
418 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnComputeScroll"); | 436 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnComputeScroll"); |
419 compositor_->OnComputeScroll(animation_time); | 437 compositor_->OnComputeScroll(animation_time); |
420 } | 438 } |
421 | 439 |
422 void BrowserViewRenderer::ReleaseHardware() { | 440 void BrowserViewRenderer::ReleaseHardware() { |
423 ReturnUnusedResource(render_thread_manager_->PassUncommittedFrameOnUI()); | 441 if (compositor_frame_consumer_) { |
424 ReturnResourceFromParent(); | 442 ReturnUnusedResource( |
425 DCHECK(render_thread_manager_->ReturnedResourcesEmptyOnUI()); | 443 compositor_frame_consumer_->PassUncommittedFrameOnUI()); |
444 ReturnResourceFromParent(compositor_frame_consumer_); | |
445 DCHECK(compositor_frame_consumer_->ReturnedResourcesEmptyOnUI()); | |
boliu
2016/04/21 18:01:32
This at the moment still assumes RTM outlives BVR
| |
446 } | |
426 hardware_enabled_ = false; | 447 hardware_enabled_ = false; |
427 UpdateMemoryPolicy(); | 448 UpdateMemoryPolicy(); |
428 } | 449 } |
429 | 450 |
430 bool BrowserViewRenderer::IsVisible() const { | 451 bool BrowserViewRenderer::IsVisible() const { |
431 // Ignore |window_visible_| if |attached_to_window_| is false. | 452 // Ignore |window_visible_| if |attached_to_window_| is false. |
432 return view_visible_ && (!attached_to_window_ || window_visible_); | 453 return view_visible_ && (!attached_to_window_ || window_visible_); |
433 } | 454 } |
434 | 455 |
435 bool BrowserViewRenderer::IsClientVisible() const { | 456 bool BrowserViewRenderer::IsClientVisible() const { |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
702 base::StringAppendF(&str, | 723 base::StringAppendF(&str, |
703 "overscroll_rounding_error_: %s ", | 724 "overscroll_rounding_error_: %s ", |
704 overscroll_rounding_error_.ToString().c_str()); | 725 overscroll_rounding_error_.ToString().c_str()); |
705 base::StringAppendF( | 726 base::StringAppendF( |
706 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); | 727 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); |
707 base::StringAppendF(&str, "clear_view: %d ", clear_view_); | 728 base::StringAppendF(&str, "clear_view: %d ", clear_view_); |
708 return str; | 729 return str; |
709 } | 730 } |
710 | 731 |
711 } // namespace android_webview | 732 } // namespace android_webview |
OLD | NEW |