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/compositor_impl_android.h" | 5 #include "content/browser/renderer_host/compositor_impl_android.h" |
6 | 6 |
7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
8 #include <android/native_window_jni.h> | 8 #include <android/native_window_jni.h> |
9 | 9 |
10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 DCHECK(command_buffer_proxy); | 135 DCHECK(command_buffer_proxy); |
136 return command_buffer_proxy; | 136 return command_buffer_proxy; |
137 } | 137 } |
138 | 138 |
139 void OnSwapBuffersCompleted(const std::vector<ui::LatencyInfo>& latency_info, | 139 void OnSwapBuffersCompleted(const std::vector<ui::LatencyInfo>& latency_info, |
140 gfx::SwapResult result) { | 140 gfx::SwapResult result) { |
141 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); | 141 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); |
142 OutputSurface::OnSwapBuffersComplete(); | 142 OutputSurface::OnSwapBuffersComplete(); |
143 } | 143 } |
144 | 144 |
145 void OnUpdateVSyncParameters(base::TimeTicks timebase, | 145 void OnVSync(base::TimeTicks timebase, base::TimeDelta interval) override { |
146 base::TimeDelta interval) override { | |
147 CommitVSyncParameters(timebase, interval); | 146 CommitVSyncParameters(timebase, interval); |
148 } | 147 } |
149 | 148 |
150 CompositorImpl* compositor_; | 149 CompositorImpl* compositor_; |
151 base::Callback<void(gpu::Capabilities)> populate_gpu_capabilities_callback_; | 150 base::Callback<void(gpu::Capabilities)> populate_gpu_capabilities_callback_; |
152 base::CancelableCallback<void(const std::vector<ui::LatencyInfo>&, | 151 base::CancelableCallback<void(const std::vector<ui::LatencyInfo>&, |
153 gfx::SwapResult)> | 152 gfx::SwapResult)> |
154 swap_buffers_completion_callback_; | 153 swap_buffers_completion_callback_; |
155 scoped_ptr<cc::OverlayCandidateValidator> overlay_candidate_validator_; | 154 scoped_ptr<cc::OverlayCandidateValidator> overlay_candidate_validator_; |
156 }; | 155 }; |
157 | 156 |
157 class ExternalBeginFrameSource : public cc::BeginFrameSourceBase, | |
158 public CompositorImpl::VSyncObserver { | |
159 public: | |
160 ExternalBeginFrameSource(CompositorImpl* compositor) | |
161 : compositor_(compositor) { | |
162 compositor_->AddObserver(this); | |
163 } | |
164 | |
165 ~ExternalBeginFrameSource() { | |
166 compositor_->RemoveObserver(this); | |
167 } | |
168 | |
169 // cc::BeginFrameSourceBase implementation: | |
170 void OnNeedsBeginFramesChange( | |
171 bool needs_begin_frames) override { | |
172 compositor_->OnNeedsBeginFramesChange(needs_begin_frames); | |
173 } | |
174 | |
175 // CompositorImpl::VSyncObserver implementation: | |
176 void OnVSync(base::TimeTicks frame_time, | |
177 base::TimeDelta vsync_period) override { | |
178 if (NeedsBeginFrames()) { | |
brianderson
2015/12/12 01:41:46
This check shouldn't be needed. The scheduler shou
no sievers
2015/12/17 00:52:32
Done.
| |
179 CallOnBeginFrame(cc::BeginFrameArgs::Create( | |
180 BEGINFRAME_FROM_HERE, frame_time, base::TimeTicks::Now(), | |
181 vsync_period, cc::BeginFrameArgs::NORMAL)); | |
182 } | |
183 } | |
184 | |
185 private: | |
186 CompositorImpl* compositor_; | |
187 }; | |
188 | |
158 static bool g_initialized = false; | 189 static bool g_initialized = false; |
159 | 190 |
160 bool g_use_surface_manager = false; | 191 bool g_use_surface_manager = false; |
161 base::LazyInstance<cc::SurfaceManager> g_surface_manager = | 192 base::LazyInstance<cc::SurfaceManager> g_surface_manager = |
162 LAZY_INSTANCE_INITIALIZER; | 193 LAZY_INSTANCE_INITIALIZER; |
163 | 194 |
164 int g_surface_id_namespace = 0; | 195 int g_surface_id_namespace = 0; |
165 | 196 |
166 class SingleThreadTaskGraphRunner : public cc::SingleThreadTaskGraphRunner { | 197 class SingleThreadTaskGraphRunner : public cc::SingleThreadTaskGraphRunner { |
167 public: | 198 public: |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 : root_layer_(cc::Layer::Create(Compositor::LayerSettings())), | 261 : root_layer_(cc::Layer::Create(Compositor::LayerSettings())), |
231 resource_manager_(root_window), | 262 resource_manager_(root_window), |
232 surface_id_allocator_(GetSurfaceManager() ? CreateSurfaceIdAllocator() | 263 surface_id_allocator_(GetSurfaceManager() ? CreateSurfaceIdAllocator() |
233 : nullptr), | 264 : nullptr), |
234 has_transparent_background_(false), | 265 has_transparent_background_(false), |
235 device_scale_factor_(1), | 266 device_scale_factor_(1), |
236 window_(NULL), | 267 window_(NULL), |
237 surface_id_(0), | 268 surface_id_(0), |
238 client_(client), | 269 client_(client), |
239 root_window_(root_window), | 270 root_window_(root_window), |
240 did_post_swapbuffers_(false), | |
241 ignore_schedule_composite_(false), | |
242 needs_composite_(false), | |
243 needs_animate_(false), | 271 needs_animate_(false), |
244 will_composite_immediately_(false), | |
245 composite_on_vsync_trigger_(DO_NOT_COMPOSITE), | |
246 pending_swapbuffers_(0U), | 272 pending_swapbuffers_(0U), |
247 num_successive_context_creation_failures_(0), | 273 num_successive_context_creation_failures_(0), |
248 output_surface_request_pending_(false), | 274 output_surface_request_pending_(false), |
275 needs_begin_frames_(false), | |
249 weak_factory_(this) { | 276 weak_factory_(this) { |
250 DCHECK(client); | 277 DCHECK(client); |
251 DCHECK(root_window); | 278 DCHECK(root_window); |
252 root_window->AttachCompositor(this); | 279 root_window->AttachCompositor(this); |
253 CreateLayerTreeHost(); | 280 CreateLayerTreeHost(); |
254 resource_manager_.Init(host_.get()); | 281 resource_manager_.Init(host_.get()); |
255 } | 282 } |
256 | 283 |
257 CompositorImpl::~CompositorImpl() { | 284 CompositorImpl::~CompositorImpl() { |
258 root_window_->DetachCompositor(); | 285 root_window_->DetachCompositor(); |
259 // Clean-up any surface references. | 286 // Clean-up any surface references. |
260 SetSurface(NULL); | 287 SetSurface(NULL); |
261 } | 288 } |
262 | 289 |
263 void CompositorImpl::PostComposite(CompositingTrigger trigger) { | |
264 DCHECK(host_->visible()); | |
265 DCHECK(needs_composite_); | |
266 DCHECK(trigger == COMPOSITE_IMMEDIATELY || trigger == COMPOSITE_EVENTUALLY); | |
267 | |
268 if (will_composite_immediately_ || | |
269 (trigger == COMPOSITE_EVENTUALLY && WillComposite())) { | |
270 // We will already composite soon enough. | |
271 DCHECK(WillComposite()); | |
272 return; | |
273 } | |
274 | |
275 if (DidCompositeThisFrame()) { | |
276 DCHECK(!WillCompositeThisFrame()); | |
277 if (composite_on_vsync_trigger_ != COMPOSITE_IMMEDIATELY) { | |
278 composite_on_vsync_trigger_ = trigger; | |
279 root_window_->RequestVSyncUpdate(); | |
280 } | |
281 DCHECK(WillComposite()); | |
282 return; | |
283 } | |
284 | |
285 base::TimeDelta delay; | |
286 if (trigger == COMPOSITE_IMMEDIATELY) { | |
287 will_composite_immediately_ = true; | |
288 composite_on_vsync_trigger_ = DO_NOT_COMPOSITE; | |
289 } else { | |
290 DCHECK(!WillComposite()); | |
291 const base::TimeDelta estimated_composite_time = vsync_period_ / 4; | |
292 const base::TimeTicks now = base::TimeTicks::Now(); | |
293 | |
294 if (!last_vsync_.is_null() && (now - last_vsync_) < vsync_period_) { | |
295 base::TimeTicks next_composite = | |
296 last_vsync_ + vsync_period_ - estimated_composite_time; | |
297 if (next_composite < now) { | |
298 // It's too late, we will reschedule composite as needed on the next | |
299 // vsync. | |
300 composite_on_vsync_trigger_ = COMPOSITE_EVENTUALLY; | |
301 root_window_->RequestVSyncUpdate(); | |
302 DCHECK(WillComposite()); | |
303 return; | |
304 } | |
305 | |
306 delay = next_composite - now; | |
307 } | |
308 } | |
309 TRACE_EVENT2("cc,benchmark", "CompositorImpl::PostComposite", | |
310 "trigger", trigger, | |
311 "delay", delay.InMillisecondsF()); | |
312 | |
313 DCHECK(composite_on_vsync_trigger_ == DO_NOT_COMPOSITE); | |
314 if (current_composite_task_) | |
315 current_composite_task_->Cancel(); | |
316 | |
317 // Unretained because we cancel the task on shutdown. | |
318 current_composite_task_.reset(new base::CancelableClosure( | |
319 base::Bind(&CompositorImpl::Composite, base::Unretained(this), trigger))); | |
320 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
321 FROM_HERE, current_composite_task_->callback(), delay); | |
322 } | |
323 | |
324 void CompositorImpl::Composite(CompositingTrigger trigger) { | |
325 if (trigger == COMPOSITE_IMMEDIATELY) | |
326 will_composite_immediately_ = false; | |
327 | |
328 DCHECK(host_->visible()); | |
329 DCHECK(trigger == COMPOSITE_IMMEDIATELY || trigger == COMPOSITE_EVENTUALLY); | |
330 DCHECK(needs_composite_); | |
331 DCHECK(!DidCompositeThisFrame()); | |
332 | |
333 DCHECK_LE(pending_swapbuffers_, kMaxUiSwapBuffers); | |
334 // Swap Ack accounting is unreliable if the OutputSurface was lost. | |
335 // In that case still attempt to composite, which will cause creation of a | |
336 // new OutputSurface and reset pending_swapbuffers_. | |
337 if (pending_swapbuffers_ == kMaxUiSwapBuffers && | |
338 !host_->output_surface_lost()) { | |
339 TRACE_EVENT0("compositor", "CompositorImpl_SwapLimit"); | |
340 return; | |
341 } | |
342 | |
343 // Reset state before Layout+Composite since that might create more | |
344 // requests to Composite that we need to respect. | |
345 needs_composite_ = false; | |
346 | |
347 // Only allow compositing once per vsync. | |
348 current_composite_task_->Cancel(); | |
349 DCHECK(DidCompositeThisFrame() && !WillComposite()); | |
350 | |
351 const base::TimeTicks frame_time = base::TimeTicks::Now(); | |
352 if (needs_animate_) { | |
353 base::AutoReset<bool> auto_reset_ignore_schedule( | |
354 &ignore_schedule_composite_, true); | |
355 needs_animate_ = false; | |
356 root_window_->Animate(frame_time); | |
357 } | |
358 | |
359 did_post_swapbuffers_ = false; | |
360 host_->Composite(frame_time); | |
361 if (did_post_swapbuffers_) | |
362 pending_swapbuffers_++; | |
363 | |
364 // Need to track vsync to avoid compositing more than once per frame. | |
365 root_window_->RequestVSyncUpdate(); | |
366 } | |
367 | |
368 ui::UIResourceProvider& CompositorImpl::GetUIResourceProvider() { | 290 ui::UIResourceProvider& CompositorImpl::GetUIResourceProvider() { |
369 return *this; | 291 return *this; |
370 } | 292 } |
371 | 293 |
372 ui::ResourceManager& CompositorImpl::GetResourceManager() { | 294 ui::ResourceManager& CompositorImpl::GetResourceManager() { |
373 return resource_manager_; | 295 return resource_manager_; |
374 } | 296 } |
375 | 297 |
376 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { | 298 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { |
377 if (subroot_layer_.get()) { | 299 if (subroot_layer_.get()) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 gfx::GLSurfaceHandle(surface_id_, gfx::NATIVE_DIRECT)); | 340 gfx::GLSurfaceHandle(surface_id_, gfx::NATIVE_DIRECT)); |
419 // Register first, SetVisible() might create an OutputSurface. | 341 // Register first, SetVisible() might create an OutputSurface. |
420 RegisterViewSurface(surface_id_, j_surface.obj()); | 342 RegisterViewSurface(surface_id_, j_surface.obj()); |
421 SetVisible(true); | 343 SetVisible(true); |
422 ANativeWindow_release(window); | 344 ANativeWindow_release(window); |
423 } | 345 } |
424 } | 346 } |
425 | 347 |
426 void CompositorImpl::CreateLayerTreeHost() { | 348 void CompositorImpl::CreateLayerTreeHost() { |
427 DCHECK(!host_); | 349 DCHECK(!host_); |
428 DCHECK(!WillCompositeThisFrame()); | |
429 | |
430 // Just in case, since we immediately hide the LTH in this function, | |
431 // and we do not want to end up with a pending Composite task when the | |
432 // host is hidden. | |
433 base::AutoReset<bool> auto_reset_ignore_schedule(&ignore_schedule_composite_, | |
434 true); | |
435 | 350 |
436 cc::LayerTreeSettings settings; | 351 cc::LayerTreeSettings settings; |
437 settings.renderer_settings.refresh_rate = 60.0; | 352 settings.renderer_settings.refresh_rate = 60.0; |
438 settings.renderer_settings.allow_antialiasing = false; | 353 settings.renderer_settings.allow_antialiasing = false; |
439 settings.renderer_settings.highp_threshold_min = 2048; | 354 settings.renderer_settings.highp_threshold_min = 2048; |
440 settings.use_zero_copy = true; | 355 settings.use_zero_copy = true; |
356 settings.use_external_begin_frame_source = true; | |
441 | 357 |
442 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 358 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
443 settings.initial_debug_state.SetRecordRenderingStats( | 359 settings.initial_debug_state.SetRecordRenderingStats( |
444 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); | 360 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); |
445 if (command_line->HasSwitch(cc::switches::kDisableCompositorPropertyTrees)) | 361 if (command_line->HasSwitch(cc::switches::kDisableCompositorPropertyTrees)) |
446 settings.use_property_trees = false; | 362 settings.use_property_trees = false; |
447 // TODO(enne): Update this this compositor to use the scheduler. | 363 settings.single_thread_proxy_scheduler = true; |
448 settings.single_thread_proxy_scheduler = false; | |
449 | 364 |
450 settings.use_compositor_animation_timelines = !command_line->HasSwitch( | 365 settings.use_compositor_animation_timelines = !command_line->HasSwitch( |
451 switches::kDisableAndroidCompositorAnimationTimelines); | 366 switches::kDisableAndroidCompositorAnimationTimelines); |
452 | 367 |
453 cc::LayerTreeHost::InitParams params; | 368 cc::LayerTreeHost::InitParams params; |
454 params.client = this; | 369 params.client = this; |
455 params.shared_bitmap_manager = HostSharedBitmapManager::current(); | 370 params.shared_bitmap_manager = HostSharedBitmapManager::current(); |
456 params.gpu_memory_buffer_manager = BrowserGpuMemoryBufferManager::current(); | 371 params.gpu_memory_buffer_manager = BrowserGpuMemoryBufferManager::current(); |
457 params.task_graph_runner = g_task_graph_runner.Pointer(); | 372 params.task_graph_runner = g_task_graph_runner.Pointer(); |
458 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); | 373 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); |
459 params.settings = &settings; | 374 params.settings = &settings; |
375 params.external_begin_frame_source.reset(new ExternalBeginFrameSource(this)); | |
460 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, ¶ms); | 376 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, ¶ms); |
461 DCHECK(!host_->visible()); | 377 DCHECK(!host_->visible()); |
462 host_->SetRootLayer(root_layer_); | 378 host_->SetRootLayer(root_layer_); |
463 host_->SetViewportSize(size_); | 379 host_->SetViewportSize(size_); |
464 host_->set_has_transparent_background(has_transparent_background_); | 380 host_->set_has_transparent_background(has_transparent_background_); |
465 host_->SetDeviceScaleFactor(device_scale_factor_); | 381 host_->SetDeviceScaleFactor(device_scale_factor_); |
466 | 382 |
467 if (needs_animate_) | 383 if (needs_animate_) |
468 host_->SetNeedsAnimate(); | 384 host_->SetNeedsAnimate(); |
469 } | 385 } |
470 | 386 |
471 void CompositorImpl::SetVisible(bool visible) { | 387 void CompositorImpl::SetVisible(bool visible) { |
472 TRACE_EVENT1("cc", "CompositorImpl::SetVisible", "visible", visible); | 388 TRACE_EVENT1("cc", "CompositorImpl::SetVisible", "visible", visible); |
473 if (!visible) { | 389 if (!visible) { |
474 DCHECK(host_->visible()); | 390 DCHECK(host_->visible()); |
475 // Look for any layers that were attached to the root for readback | |
476 // and are waiting for Composite() to happen. | |
477 bool readback_pending = false; | |
478 for (size_t i = 0; i < root_layer_->children().size(); ++i) { | |
479 if (root_layer_->children()[i]->HasCopyRequest()) { | |
480 readback_pending = true; | |
481 break; | |
482 } | |
483 } | |
484 if (readback_pending) { | |
brianderson
2015/12/12 01:41:46
Does this break readbacks at all?
no sievers
2015/12/17 00:52:32
The pending requests will still signal completion
| |
485 base::AutoReset<bool> auto_reset_ignore_schedule( | |
486 &ignore_schedule_composite_, true); | |
487 host_->Composite(base::TimeTicks::Now()); | |
488 } | |
489 if (WillComposite()) | |
490 CancelComposite(); | |
491 host_->SetVisible(false); | 391 host_->SetVisible(false); |
492 if (!host_->output_surface_lost()) | 392 if (!host_->output_surface_lost()) |
493 host_->ReleaseOutputSurface(); | 393 host_->ReleaseOutputSurface(); |
494 pending_swapbuffers_ = 0; | 394 pending_swapbuffers_ = 0; |
495 needs_composite_ = false; | |
496 composite_on_vsync_trigger_ = DO_NOT_COMPOSITE; | |
497 establish_gpu_channel_timeout_.Stop(); | 395 establish_gpu_channel_timeout_.Stop(); |
498 display_client_.reset(); | 396 display_client_.reset(); |
499 if (current_composite_task_) { | |
500 current_composite_task_->Cancel(); | |
501 current_composite_task_.reset(); | |
502 } | |
503 } else { | 397 } else { |
504 host_->SetVisible(true); | 398 host_->SetVisible(true); |
505 if (output_surface_request_pending_) | 399 if (output_surface_request_pending_) |
506 RequestNewOutputSurface(); | 400 RequestNewOutputSurface(); |
507 SetNeedsComposite(); | 401 host_->SetNeedsCommit(); |
brianderson
2015/12/12 01:41:46
Is this needed? I think the impl side requests it
no sievers
2015/12/17 00:52:32
You're right, not needed. Removed.
| |
508 } | 402 } |
509 } | 403 } |
510 | 404 |
511 void CompositorImpl::setDeviceScaleFactor(float factor) { | 405 void CompositorImpl::setDeviceScaleFactor(float factor) { |
512 device_scale_factor_ = factor; | 406 device_scale_factor_ = factor; |
513 if (host_) | 407 if (host_) |
514 host_->SetDeviceScaleFactor(factor); | 408 host_->SetDeviceScaleFactor(factor); |
515 } | 409 } |
516 | 410 |
517 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { | 411 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { |
(...skipping 10 matching lines...) Expand all Loading... | |
528 | 422 |
529 void CompositorImpl::SetHasTransparentBackground(bool flag) { | 423 void CompositorImpl::SetHasTransparentBackground(bool flag) { |
530 has_transparent_background_ = flag; | 424 has_transparent_background_ = flag; |
531 if (host_) | 425 if (host_) |
532 host_->set_has_transparent_background(flag); | 426 host_->set_has_transparent_background(flag); |
533 } | 427 } |
534 | 428 |
535 void CompositorImpl::SetNeedsComposite() { | 429 void CompositorImpl::SetNeedsComposite() { |
536 if (!host_->visible()) | 430 if (!host_->visible()) |
537 return; | 431 return; |
538 DCHECK(!needs_composite_ || WillComposite()); | 432 host_->SetNeedsCommit(); |
brianderson
2015/12/12 01:41:46
Was this why the SetNeedsCommit was needed above?
no sievers
2015/12/17 00:52:32
This is actually what the browser will call if it
| |
539 | |
540 needs_composite_ = true; | |
541 PostComposite(COMPOSITE_IMMEDIATELY); | |
542 } | 433 } |
543 | 434 |
544 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> | 435 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
545 CreateGpuProcessViewContext( | 436 CreateGpuProcessViewContext( |
546 const scoped_refptr<GpuChannelHost>& gpu_channel_host, | 437 const scoped_refptr<GpuChannelHost>& gpu_channel_host, |
547 const blink::WebGraphicsContext3D::Attributes attributes, | 438 const blink::WebGraphicsContext3D::Attributes attributes, |
548 int surface_id) { | 439 int surface_id) { |
549 GURL url("chrome://gpu/Compositor::createContext3D"); | 440 GURL url("chrome://gpu/Compositor::createContext3D"); |
550 static const size_t kBytesPerPixel = 4; | 441 static const size_t kBytesPerPixel = 4; |
551 gfx::DeviceDisplayInfo display_info; | 442 gfx::DeviceDisplayInfo display_info; |
(...skipping 13 matching lines...) Expand all Loading... | |
565 new WebGraphicsContext3DCommandBufferImpl(surface_id, | 456 new WebGraphicsContext3DCommandBufferImpl(surface_id, |
566 url, | 457 url, |
567 gpu_channel_host.get(), | 458 gpu_channel_host.get(), |
568 attributes, | 459 attributes, |
569 lose_context_when_out_of_memory, | 460 lose_context_when_out_of_memory, |
570 limits, | 461 limits, |
571 NULL)); | 462 NULL)); |
572 } | 463 } |
573 | 464 |
574 void CompositorImpl::UpdateLayerTreeHost() { | 465 void CompositorImpl::UpdateLayerTreeHost() { |
575 base::AutoReset<bool> auto_reset_ignore_schedule(&ignore_schedule_composite_, | |
576 true); | |
577 client_->UpdateLayerTreeHost(); | 466 client_->UpdateLayerTreeHost(); |
467 if (needs_animate_) { | |
468 needs_animate_ = false; | |
469 root_window_->Animate(base::TimeTicks::Now()); | |
470 } | |
578 } | 471 } |
579 | 472 |
580 void CompositorImpl::OnGpuChannelEstablished() { | 473 void CompositorImpl::OnGpuChannelEstablished() { |
581 establish_gpu_channel_timeout_.Stop(); | 474 establish_gpu_channel_timeout_.Stop(); |
582 CreateOutputSurface(); | 475 CreateOutputSurface(); |
583 } | 476 } |
584 | 477 |
585 void CompositorImpl::OnGpuChannelTimeout() { | 478 void CompositorImpl::OnGpuChannelTimeout() { |
586 LOG(FATAL) << "Timed out waiting for GPU channel."; | 479 LOG(FATAL) << "Timed out waiting for GPU channel."; |
587 } | 480 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
697 } | 590 } |
698 | 591 |
699 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) { | 592 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) { |
700 host_->DeleteUIResource(resource_id); | 593 host_->DeleteUIResource(resource_id); |
701 } | 594 } |
702 | 595 |
703 bool CompositorImpl::SupportsETC1NonPowerOfTwo() const { | 596 bool CompositorImpl::SupportsETC1NonPowerOfTwo() const { |
704 return gpu_capabilities_.texture_format_etc1_npot; | 597 return gpu_capabilities_.texture_format_etc1_npot; |
705 } | 598 } |
706 | 599 |
707 void CompositorImpl::ScheduleComposite() { | |
708 if (ignore_schedule_composite_ || !host_->visible()) | |
709 return; | |
710 | |
711 DCHECK(!needs_composite_ || WillComposite()); | |
712 needs_composite_ = true; | |
713 // We currently expect layer tree invalidations at most once per frame | |
714 // during normal operation and therefore try to composite immediately | |
715 // to minimize latency. | |
716 PostComposite(COMPOSITE_IMMEDIATELY); | |
717 } | |
718 | |
719 void CompositorImpl::ScheduleAnimation() { | |
720 needs_animate_ = true; | |
721 | |
722 if (!host_->visible()) | |
723 return; | |
724 | |
725 if (needs_composite_) { | |
726 DCHECK(WillComposite()); | |
727 return; | |
728 } | |
729 | |
730 TRACE_EVENT0("cc", "CompositorImpl::ScheduleAnimation"); | |
731 needs_composite_ = true; | |
732 PostComposite(COMPOSITE_EVENTUALLY); | |
733 } | |
734 | |
735 void CompositorImpl::DidPostSwapBuffers() { | 600 void CompositorImpl::DidPostSwapBuffers() { |
736 TRACE_EVENT0("compositor", "CompositorImpl::DidPostSwapBuffers"); | 601 TRACE_EVENT0("compositor", "CompositorImpl::DidPostSwapBuffers"); |
737 did_post_swapbuffers_ = true; | 602 pending_swapbuffers_++; |
738 } | 603 } |
739 | 604 |
740 void CompositorImpl::DidCompleteSwapBuffers() { | 605 void CompositorImpl::DidCompleteSwapBuffers() { |
741 TRACE_EVENT0("compositor", "CompositorImpl::DidCompleteSwapBuffers"); | 606 TRACE_EVENT0("compositor", "CompositorImpl::DidCompleteSwapBuffers"); |
742 DCHECK_GT(pending_swapbuffers_, 0U); | 607 DCHECK_GT(pending_swapbuffers_, 0U); |
743 if (pending_swapbuffers_-- == kMaxUiSwapBuffers && needs_composite_) | 608 pending_swapbuffers_--; |
744 PostComposite(COMPOSITE_IMMEDIATELY); | |
745 client_->OnSwapBuffersCompleted(pending_swapbuffers_); | 609 client_->OnSwapBuffersCompleted(pending_swapbuffers_); |
brianderson
2015/12/12 01:41:46
It doesn't look like any implementers look at pend
no sievers
2015/12/17 00:52:32
Unfortunately this is used in CompositorViewHolder
brianderson
2015/12/17 06:14:53
Ok. I see where it's used now and am okay keeping
| |
746 } | 610 } |
747 | 611 |
748 void CompositorImpl::DidAbortSwapBuffers() { | 612 void CompositorImpl::DidAbortSwapBuffers() { |
749 TRACE_EVENT0("compositor", "CompositorImpl::DidAbortSwapBuffers"); | 613 TRACE_EVENT0("compositor", "CompositorImpl::DidAbortSwapBuffers"); |
750 // This really gets called only once from | 614 // This really gets called only once from |
751 // SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() when the | 615 // SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() when the |
752 // context was lost. | 616 // context was lost. |
753 ScheduleComposite(); | 617 ScheduleComposite(); |
754 client_->OnSwapBuffersCompleted(0); | 618 client_->OnSwapBuffersCompleted(0); |
755 } | 619 } |
756 | 620 |
757 void CompositorImpl::DidCommit() { | 621 void CompositorImpl::DidCommit() { |
758 root_window_->OnCompositingDidCommit(); | 622 root_window_->OnCompositingDidCommit(); |
759 } | 623 } |
760 | 624 |
761 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) { | 625 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) { |
762 root_layer_->AddChild(layer); | 626 root_layer_->AddChild(layer); |
763 } | 627 } |
764 | 628 |
765 void CompositorImpl::RequestCopyOfOutputOnRootLayer( | 629 void CompositorImpl::RequestCopyOfOutputOnRootLayer( |
766 scoped_ptr<cc::CopyOutputRequest> request) { | 630 scoped_ptr<cc::CopyOutputRequest> request) { |
767 root_layer_->RequestCopyOfOutput(request.Pass()); | 631 root_layer_->RequestCopyOfOutput(request.Pass()); |
768 } | 632 } |
769 | 633 |
770 void CompositorImpl::OnVSync(base::TimeTicks frame_time, | 634 void CompositorImpl::OnVSync(base::TimeTicks frame_time, |
771 base::TimeDelta vsync_period) { | 635 base::TimeDelta vsync_period) { |
772 vsync_period_ = vsync_period; | 636 FOR_EACH_OBSERVER(VSyncObserver, observer_list_, |
773 last_vsync_ = frame_time; | 637 OnVSync(frame_time, vsync_period)); |
638 if (needs_begin_frames_) | |
639 root_window_->RequestVSyncUpdate(); | |
640 } | |
774 | 641 |
775 if (WillCompositeThisFrame()) { | 642 void CompositorImpl::OnNeedsBeginFramesChange(bool needs_begin_frames) { |
776 // We somehow missed the last vsync interval, so reschedule for deadline. | 643 if (needs_begin_frames_ == needs_begin_frames) |
777 // We cannot schedule immediately, or will get us out-of-phase with new | 644 return; |
778 // renderer frames. | |
779 CancelComposite(); | |
780 composite_on_vsync_trigger_ = COMPOSITE_EVENTUALLY; | |
781 } else { | |
782 current_composite_task_.reset(); | |
783 } | |
784 | 645 |
785 DCHECK(!DidCompositeThisFrame() && !WillCompositeThisFrame()); | 646 needs_begin_frames_ = needs_begin_frames; |
786 if (composite_on_vsync_trigger_ != DO_NOT_COMPOSITE) { | 647 if (needs_begin_frames_) |
787 CompositingTrigger trigger = composite_on_vsync_trigger_; | 648 root_window_->RequestVSyncUpdate(); |
788 composite_on_vsync_trigger_ = DO_NOT_COMPOSITE; | |
789 PostComposite(trigger); | |
790 } | |
791 | |
792 FOR_EACH_OBSERVER(VSyncObserver, observer_list_, | |
793 OnUpdateVSyncParameters(frame_time, vsync_period)); | |
794 } | 649 } |
795 | 650 |
796 void CompositorImpl::SetNeedsAnimate() { | 651 void CompositorImpl::SetNeedsAnimate() { |
797 needs_animate_ = true; | 652 needs_animate_ = true; |
798 if (!host_->visible()) | 653 if (!host_->visible()) |
799 return; | 654 return; |
800 | 655 |
801 host_->SetNeedsAnimate(); | 656 host_->SetNeedsAnimate(); |
802 } | 657 } |
803 | 658 |
804 } // namespace content | 659 } // namespace content |
OLD | NEW |