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 ReturnResourceFromParent(compositor_frame_consumer_); | |
boliu
2016/04/21 18:16:38
Basicaclly need to do ReleaseHardwareRenderer here
Tobias Sargeant
2016/04/22 11:42:22
But then we'd flicker, right?
boliu
2016/04/22 15:34:37
Yes, but we are not fixing flicker in this CL. Up
| |
125 compositor_frame_consumer_->SetCompositorFrameProducer(nullptr); | |
126 } | |
127 compositor_frame_consumer_ = compositor_frame_consumer; | |
128 if (compositor_frame_consumer_) { | |
129 compositor_frame_consumer_->SetCompositorFrameProducer(this); | |
130 } | |
119 } | 131 } |
120 | 132 |
121 void BrowserViewRenderer::RegisterWithWebContents( | 133 void BrowserViewRenderer::RegisterWithWebContents( |
122 content::WebContents* web_contents) { | 134 content::WebContents* web_contents) { |
123 web_contents->SetUserData(kBrowserViewRendererUserDataKey, | 135 web_contents->SetUserData(kBrowserViewRendererUserDataKey, |
124 new BrowserViewRendererUserData(this)); | 136 new BrowserViewRendererUserData(this)); |
125 } | 137 } |
126 | 138 |
127 void BrowserViewRenderer::TrimMemory() { | 139 void BrowserViewRenderer::TrimMemory() { |
128 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 140 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 if (clear_view_) { | 192 if (clear_view_) { |
181 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_ClearView", | 193 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_ClearView", |
182 TRACE_EVENT_SCOPE_THREAD); | 194 TRACE_EVENT_SCOPE_THREAD); |
183 return false; | 195 return false; |
184 } | 196 } |
185 | 197 |
186 return true; | 198 return true; |
187 } | 199 } |
188 | 200 |
189 bool BrowserViewRenderer::OnDrawHardware() { | 201 bool BrowserViewRenderer::OnDrawHardware() { |
190 DCHECK(render_thread_manager_); | 202 DCHECK(compositor_frame_consumer_); |
191 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware"); | 203 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware"); |
192 | 204 |
193 render_thread_manager_->InitializeHardwareDrawIfNeededOnUI(); | 205 compositor_frame_consumer_->InitializeHardwareDrawIfNeededOnUI(); |
194 | 206 |
195 if (!CanOnDraw()) { | 207 if (!CanOnDraw()) { |
196 return false; | 208 return false; |
197 } | 209 } |
198 | 210 |
199 render_thread_manager_->SetScrollOffsetOnUI(last_on_draw_scroll_offset_); | 211 compositor_frame_consumer_->SetScrollOffsetOnUI(last_on_draw_scroll_offset_); |
200 hardware_enabled_ = true; | 212 hardware_enabled_ = true; |
201 | 213 |
202 external_draw_constraints_ = | 214 external_draw_constraints_ = |
203 render_thread_manager_->GetParentDrawConstraintsOnUI(); | 215 compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); |
204 | 216 |
205 ReturnResourceFromParent(); | 217 ReturnResourceFromParent(compositor_frame_consumer_); |
206 UpdateMemoryPolicy(); | 218 UpdateMemoryPolicy(); |
207 | 219 |
208 gfx::Size surface_size(size_); | 220 gfx::Size surface_size(size_); |
209 gfx::Rect viewport(surface_size); | 221 gfx::Rect viewport(surface_size); |
210 gfx::Rect clip = viewport; | 222 gfx::Rect clip = viewport; |
211 gfx::Transform transform_for_tile_priority = | 223 gfx::Transform transform_for_tile_priority = |
212 external_draw_constraints_.transform; | 224 external_draw_constraints_.transform; |
213 | 225 |
214 // If the WebView is on a layer, WebView does not know what transform is | 226 // 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. | 227 // applied onto the layer so global visible rect does not make sense here. |
216 // In this case, just use the surface rect for tiling. | 228 // In this case, just use the surface rect for tiling. |
217 gfx::Rect viewport_rect_for_tile_priority; | 229 gfx::Rect viewport_rect_for_tile_priority; |
218 | 230 |
219 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. | 231 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. |
220 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { | 232 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { |
221 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; | 233 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; |
222 } | 234 } |
223 | 235 |
224 content::SynchronousCompositor::Frame frame = | 236 content::SynchronousCompositor::Frame frame = |
225 compositor_->DemandDrawHw(surface_size, | 237 compositor_->DemandDrawHw(surface_size, |
226 gfx::Transform(), | 238 gfx::Transform(), |
227 viewport, | 239 viewport, |
228 clip, | 240 clip, |
229 viewport_rect_for_tile_priority, | 241 viewport_rect_for_tile_priority, |
230 transform_for_tile_priority); | 242 transform_for_tile_priority); |
231 if (!frame.frame.get()) { | 243 if (!frame.frame.get()) { |
232 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame", | 244 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame", |
233 TRACE_EVENT_SCOPE_THREAD); | 245 TRACE_EVENT_SCOPE_THREAD); |
234 hardware_enabled_ = render_thread_manager_->HasFrameOnUI(); | 246 hardware_enabled_ = compositor_frame_consumer_->HasFrameOnUI(); |
235 if (!hardware_enabled_) | 247 if (!hardware_enabled_) |
236 UpdateMemoryPolicy(); | 248 UpdateMemoryPolicy(); |
237 return hardware_enabled_; | 249 return hardware_enabled_; |
238 } | 250 } |
239 | 251 |
240 std::unique_ptr<ChildFrame> child_frame = base::WrapUnique(new ChildFrame( | 252 std::unique_ptr<ChildFrame> child_frame = base::WrapUnique(new ChildFrame( |
241 frame.output_surface_id, std::move(frame.frame), | 253 frame.output_surface_id, std::move(frame.frame), |
242 GetCompositorID(compositor_), viewport_rect_for_tile_priority.IsEmpty(), | 254 GetCompositorID(compositor_), viewport_rect_for_tile_priority.IsEmpty(), |
243 transform_for_tile_priority, offscreen_pre_raster_, | 255 transform_for_tile_priority, offscreen_pre_raster_, |
244 external_draw_constraints_.is_layer)); | 256 external_draw_constraints_.is_layer)); |
245 | 257 |
246 ReturnUnusedResource(render_thread_manager_->PassUncommittedFrameOnUI()); | 258 ReturnUnusedResource(compositor_frame_consumer_->PassUncommittedFrameOnUI()); |
247 render_thread_manager_->SetFrameOnUI(std::move(child_frame)); | 259 compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame)); |
248 return true; | 260 return true; |
249 } | 261 } |
250 | 262 |
251 void BrowserViewRenderer::OnParentDrawConstraintsUpdated() { | 263 void BrowserViewRenderer::OnParentDrawConstraintsUpdated() { |
252 DCHECK(render_thread_manager_); | 264 DCHECK(compositor_frame_consumer_); |
253 PostInvalidate(); | 265 PostInvalidate(); |
254 external_draw_constraints_ = | 266 external_draw_constraints_ = |
255 render_thread_manager_->GetParentDrawConstraintsOnUI(); | 267 compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); |
256 UpdateMemoryPolicy(); | 268 UpdateMemoryPolicy(); |
257 } | 269 } |
258 | 270 |
271 void BrowserViewRenderer::OnCompositorFrameConsumerWillDestroy() { | |
272 DCHECK(compositor_frame_consumer_); | |
273 SetCompositorFrameConsumer(nullptr); | |
274 } | |
275 | |
259 void BrowserViewRenderer::ReturnUnusedResource( | 276 void BrowserViewRenderer::ReturnUnusedResource( |
260 std::unique_ptr<ChildFrame> child_frame) { | 277 std::unique_ptr<ChildFrame> child_frame) { |
261 if (!child_frame.get() || !child_frame->frame.get()) | 278 if (!child_frame.get() || !child_frame->frame.get()) |
262 return; | 279 return; |
263 | 280 |
264 cc::CompositorFrameAck frame_ack; | 281 cc::CompositorFrameAck frame_ack; |
265 cc::TransferableResource::ReturnResources( | 282 cc::TransferableResource::ReturnResources( |
266 child_frame->frame->delegated_frame_data->resource_list, | 283 child_frame->frame->delegated_frame_data->resource_list, |
267 &frame_ack.resources); | 284 &frame_ack.resources); |
268 content::SynchronousCompositor* compositor = | 285 content::SynchronousCompositor* compositor = |
269 compositor_map_[child_frame->compositor_id]; | 286 compositor_map_[child_frame->compositor_id]; |
270 if (compositor && !frame_ack.resources.empty()) | 287 if (compositor && !frame_ack.resources.empty()) |
271 compositor->ReturnResources(child_frame->output_surface_id, frame_ack); | 288 compositor->ReturnResources(child_frame->output_surface_id, frame_ack); |
272 } | 289 } |
273 | 290 |
274 void BrowserViewRenderer::ReturnResourceFromParent() { | 291 void BrowserViewRenderer::ReturnResourceFromParent( |
275 DCHECK(render_thread_manager_); | 292 CompositorFrameConsumer* compositor_frame_consumer) { |
276 RenderThreadManager::ReturnedResourcesMap returned_resource_map; | 293 CompositorFrameConsumer::ReturnedResourcesMap returned_resource_map; |
277 render_thread_manager_->SwapReturnedResourcesOnUI(&returned_resource_map); | 294 compositor_frame_consumer->SwapReturnedResourcesOnUI(&returned_resource_map); |
278 for (auto iterator = returned_resource_map.begin(); | 295 for (auto iterator = returned_resource_map.begin(); |
279 iterator != returned_resource_map.end(); iterator++) { | 296 iterator != returned_resource_map.end(); iterator++) { |
280 uint32_t compositor_id = iterator->first; | 297 uint32_t compositor_id = iterator->first; |
281 content::SynchronousCompositor* compositor = compositor_map_[compositor_id]; | 298 content::SynchronousCompositor* compositor = compositor_map_[compositor_id]; |
282 cc::CompositorFrameAck frame_ack; | 299 cc::CompositorFrameAck frame_ack; |
283 frame_ack.resources.swap(iterator->second.resources); | 300 frame_ack.resources.swap(iterator->second.resources); |
284 | 301 |
285 if (compositor && !frame_ack.resources.empty()) { | 302 if (compositor && !frame_ack.resources.empty()) { |
286 compositor->ReturnResources(iterator->second.output_surface_id, | 303 compositor->ReturnResources(iterator->second.output_surface_id, |
287 frame_ack); | 304 frame_ack); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 } | 430 } |
414 | 431 |
415 void BrowserViewRenderer::OnComputeScroll(base::TimeTicks animation_time) { | 432 void BrowserViewRenderer::OnComputeScroll(base::TimeTicks animation_time) { |
416 if (!compositor_) | 433 if (!compositor_) |
417 return; | 434 return; |
418 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnComputeScroll"); | 435 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnComputeScroll"); |
419 compositor_->OnComputeScroll(animation_time); | 436 compositor_->OnComputeScroll(animation_time); |
420 } | 437 } |
421 | 438 |
422 void BrowserViewRenderer::ReleaseHardware() { | 439 void BrowserViewRenderer::ReleaseHardware() { |
423 ReturnUnusedResource(render_thread_manager_->PassUncommittedFrameOnUI()); | 440 if (compositor_frame_consumer_) { |
424 ReturnResourceFromParent(); | 441 ReturnUnusedResource( |
425 DCHECK(render_thread_manager_->ReturnedResourcesEmptyOnUI()); | 442 compositor_frame_consumer_->PassUncommittedFrameOnUI()); |
443 ReturnResourceFromParent(compositor_frame_consumer_); | |
444 DCHECK(compositor_frame_consumer_->ReturnedResourcesEmptyOnUI()); | |
445 } | |
426 hardware_enabled_ = false; | 446 hardware_enabled_ = false; |
427 UpdateMemoryPolicy(); | 447 UpdateMemoryPolicy(); |
428 } | 448 } |
429 | 449 |
430 bool BrowserViewRenderer::IsVisible() const { | 450 bool BrowserViewRenderer::IsVisible() const { |
431 // Ignore |window_visible_| if |attached_to_window_| is false. | 451 // Ignore |window_visible_| if |attached_to_window_| is false. |
432 return view_visible_ && (!attached_to_window_ || window_visible_); | 452 return view_visible_ && (!attached_to_window_ || window_visible_); |
433 } | 453 } |
434 | 454 |
435 bool BrowserViewRenderer::IsClientVisible() const { | 455 bool BrowserViewRenderer::IsClientVisible() const { |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
702 base::StringAppendF(&str, | 722 base::StringAppendF(&str, |
703 "overscroll_rounding_error_: %s ", | 723 "overscroll_rounding_error_: %s ", |
704 overscroll_rounding_error_.ToString().c_str()); | 724 overscroll_rounding_error_.ToString().c_str()); |
705 base::StringAppendF( | 725 base::StringAppendF( |
706 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); | 726 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); |
707 base::StringAppendF(&str, "clear_view: %d ", clear_view_); | 727 base::StringAppendF(&str, "clear_view: %d ", clear_view_); |
708 return str; | 728 return str; |
709 } | 729 } |
710 | 730 |
711 } // namespace android_webview | 731 } // namespace android_webview |
OLD | NEW |