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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 // static | 220 // static |
221 scoped_ptr<cc::SurfaceIdAllocator> CompositorImpl::CreateSurfaceIdAllocator() { | 221 scoped_ptr<cc::SurfaceIdAllocator> CompositorImpl::CreateSurfaceIdAllocator() { |
222 scoped_ptr<cc::SurfaceIdAllocator> allocator( | 222 scoped_ptr<cc::SurfaceIdAllocator> allocator( |
223 new cc::SurfaceIdAllocator(++g_surface_id_namespace)); | 223 new cc::SurfaceIdAllocator(++g_surface_id_namespace)); |
224 cc::SurfaceManager* manager = GetSurfaceManager(); | 224 cc::SurfaceManager* manager = GetSurfaceManager(); |
225 DCHECK(manager); | 225 DCHECK(manager); |
226 allocator->RegisterSurfaceIdNamespace(manager); | 226 allocator->RegisterSurfaceIdNamespace(manager); |
227 return allocator.Pass(); | 227 return allocator.Pass(); |
228 } | 228 } |
229 | 229 |
230 CompositorImpl::CompositorImpl(CompositorClient* client, | 230 CompositorImpl::CompositorImpl(CompositorClient* client, |
danakj
2015/09/28 22:45:43
Style-guidey comment: This class should probably h
no sievers
2015/09/30 02:32:40
ui/compositor/compositor.cc is even heavier though
| |
231 gfx::NativeWindow root_window) | 231 gfx::NativeWindow root_window) |
232 : root_layer_(cc::Layer::Create(Compositor::LayerSettings())), | 232 : root_layer_(cc::Layer::Create(Compositor::LayerSettings())), |
233 resource_manager_(&ui_resource_provider_), | |
234 surface_id_allocator_(GetSurfaceManager() ? CreateSurfaceIdAllocator() | 233 surface_id_allocator_(GetSurfaceManager() ? CreateSurfaceIdAllocator() |
235 : nullptr), | 234 : nullptr), |
236 has_transparent_background_(false), | 235 has_transparent_background_(false), |
237 device_scale_factor_(1), | 236 device_scale_factor_(1), |
238 window_(NULL), | 237 window_(NULL), |
239 surface_id_(0), | 238 surface_id_(0), |
240 client_(client), | 239 client_(client), |
241 root_window_(root_window), | 240 root_window_(root_window), |
242 did_post_swapbuffers_(false), | 241 did_post_swapbuffers_(false), |
243 ignore_schedule_composite_(false), | 242 ignore_schedule_composite_(false), |
244 needs_composite_(false), | 243 needs_composite_(false), |
245 needs_animate_(false), | 244 needs_animate_(false), |
246 will_composite_immediately_(false), | 245 will_composite_immediately_(false), |
247 composite_on_vsync_trigger_(DO_NOT_COMPOSITE), | 246 composite_on_vsync_trigger_(DO_NOT_COMPOSITE), |
248 pending_swapbuffers_(0U), | 247 pending_swapbuffers_(0U), |
249 num_successive_context_creation_failures_(0), | 248 num_successive_context_creation_failures_(0), |
250 output_surface_request_pending_(false), | 249 output_surface_request_pending_(false), |
251 weak_factory_(this) { | 250 weak_factory_(this) { |
252 DCHECK(client); | 251 DCHECK(client); |
253 DCHECK(root_window); | 252 DCHECK(root_window); |
254 root_window->AttachCompositor(this); | 253 root_window->AttachCompositor(this); |
254 CreateLayerTreeHost(); | |
255 ui_resource_provider_.reset(new ui::UIResourceProvider(host_.get())); | |
danakj
2015/09/28 22:45:43
I'm wondering if this class had an Init, and maybe
no sievers
2015/09/30 02:32:40
Done.
| |
256 resource_manager_.reset( | |
257 new ui::ResourceManagerImpl(ui_resource_provider_.get())); | |
255 } | 258 } |
256 | 259 |
257 CompositorImpl::~CompositorImpl() { | 260 CompositorImpl::~CompositorImpl() { |
258 root_window_->DetachCompositor(); | 261 root_window_->DetachCompositor(); |
259 // Clean-up any surface references. | 262 // Clean-up any surface references. |
260 SetSurface(NULL); | 263 SetSurface(NULL); |
261 } | 264 } |
262 | 265 |
263 void CompositorImpl::PostComposite(CompositingTrigger trigger) { | 266 void CompositorImpl::PostComposite(CompositingTrigger trigger) { |
264 DCHECK(needs_composite_); | 267 DCHECK(needs_composite_); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 did_post_swapbuffers_ = false; | 365 did_post_swapbuffers_ = false; |
363 host_->Composite(frame_time); | 366 host_->Composite(frame_time); |
364 if (did_post_swapbuffers_) | 367 if (did_post_swapbuffers_) |
365 pending_swapbuffers_++; | 368 pending_swapbuffers_++; |
366 | 369 |
367 // Need to track vsync to avoid compositing more than once per frame. | 370 // Need to track vsync to avoid compositing more than once per frame. |
368 root_window_->RequestVSyncUpdate(); | 371 root_window_->RequestVSyncUpdate(); |
369 } | 372 } |
370 | 373 |
371 ui::UIResourceProvider& CompositorImpl::GetUIResourceProvider() { | 374 ui::UIResourceProvider& CompositorImpl::GetUIResourceProvider() { |
372 return ui_resource_provider_; | 375 return *ui_resource_provider_; |
373 } | 376 } |
374 | 377 |
375 ui::ResourceManager& CompositorImpl::GetResourceManager() { | 378 ui::ResourceManager& CompositorImpl::GetResourceManager() { |
376 return resource_manager_; | 379 return *resource_manager_; |
377 } | 380 } |
378 | 381 |
379 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { | 382 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { |
380 if (subroot_layer_.get()) { | 383 if (subroot_layer_.get()) { |
381 subroot_layer_->RemoveFromParent(); | 384 subroot_layer_->RemoveFromParent(); |
382 subroot_layer_ = NULL; | 385 subroot_layer_ = NULL; |
383 } | 386 } |
384 if (root_layer.get()) { | 387 if (root_layer.get()) { |
385 subroot_layer_ = root_layer; | 388 subroot_layer_ = root_layer; |
386 root_layer_->AddChild(root_layer); | 389 root_layer_->AddChild(root_layer); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
433 if (window) { | 436 if (window) { |
434 SetWindowSurface(window); | 437 SetWindowSurface(window); |
435 ANativeWindow_release(window); | 438 ANativeWindow_release(window); |
436 RegisterViewSurface(surface_id_, j_surface.obj()); | 439 RegisterViewSurface(surface_id_, j_surface.obj()); |
437 } | 440 } |
438 } | 441 } |
439 | 442 |
440 void CompositorImpl::CreateLayerTreeHost() { | 443 void CompositorImpl::CreateLayerTreeHost() { |
441 DCHECK(!host_); | 444 DCHECK(!host_); |
442 DCHECK(!WillCompositeThisFrame()); | 445 DCHECK(!WillCompositeThisFrame()); |
443 needs_composite_ = false; | |
444 pending_swapbuffers_ = 0; | |
445 cc::LayerTreeSettings settings; | 446 cc::LayerTreeSettings settings; |
446 settings.renderer_settings.refresh_rate = 60.0; | 447 settings.renderer_settings.refresh_rate = 60.0; |
447 settings.renderer_settings.allow_antialiasing = false; | 448 settings.renderer_settings.allow_antialiasing = false; |
448 settings.renderer_settings.highp_threshold_min = 2048; | 449 settings.renderer_settings.highp_threshold_min = 2048; |
449 settings.use_zero_copy = true; | 450 settings.use_zero_copy = true; |
450 | 451 |
451 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 452 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
452 settings.initial_debug_state.SetRecordRenderingStats( | 453 settings.initial_debug_state.SetRecordRenderingStats( |
453 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); | 454 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); |
454 settings.initial_debug_state.show_fps_counter = | 455 settings.initial_debug_state.show_fps_counter = |
455 command_line->HasSwitch(cc::switches::kUIShowFPSCounter); | 456 command_line->HasSwitch(cc::switches::kUIShowFPSCounter); |
456 // TODO(enne): Update this this compositor to use the scheduler. | 457 // TODO(enne): Update this this compositor to use the scheduler. |
457 settings.single_thread_proxy_scheduler = false; | 458 settings.single_thread_proxy_scheduler = false; |
458 | 459 |
459 if (command_line->HasSwitch( | 460 if (command_line->HasSwitch( |
460 switches::kEnableAndroidCompositorAnimationTimelines)) | 461 switches::kEnableAndroidCompositorAnimationTimelines)) |
461 settings.use_compositor_animation_timelines = true; | 462 settings.use_compositor_animation_timelines = true; |
462 | 463 |
463 cc::LayerTreeHost::InitParams params; | 464 cc::LayerTreeHost::InitParams params; |
464 params.client = this; | 465 params.client = this; |
465 params.shared_bitmap_manager = HostSharedBitmapManager::current(); | 466 params.shared_bitmap_manager = HostSharedBitmapManager::current(); |
466 params.gpu_memory_buffer_manager = BrowserGpuMemoryBufferManager::current(); | 467 params.gpu_memory_buffer_manager = BrowserGpuMemoryBufferManager::current(); |
467 params.task_graph_runner = g_task_graph_runner.Pointer(); | 468 params.task_graph_runner = g_task_graph_runner.Pointer(); |
468 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); | 469 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); |
469 params.settings = &settings; | 470 params.settings = &settings; |
470 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, ¶ms); | 471 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, ¶ms); |
471 host_->SetRootLayer(root_layer_); | 472 host_->SetRootLayer(root_layer_); |
472 | 473 host_->SetVisible(false); |
473 host_->SetVisible(true); | |
474 host_->SetLayerTreeHostClientReady(); | 474 host_->SetLayerTreeHostClientReady(); |
475 host_->SetViewportSize(size_); | 475 host_->SetViewportSize(size_); |
476 host_->set_has_transparent_background(has_transparent_background_); | 476 host_->set_has_transparent_background(has_transparent_background_); |
477 host_->SetDeviceScaleFactor(device_scale_factor_); | 477 host_->SetDeviceScaleFactor(device_scale_factor_); |
478 | 478 |
479 if (needs_animate_) | 479 if (needs_animate_) |
480 host_->SetNeedsAnimate(); | 480 host_->SetNeedsAnimate(); |
481 } | 481 } |
482 | 482 |
483 void CompositorImpl::SetVisible(bool visible) { | 483 void CompositorImpl::SetVisible(bool visible) { |
484 TRACE_EVENT1("cc", "CompositorImpl::SetVisible", "visible", visible); | 484 TRACE_EVENT1("cc", "CompositorImpl::SetVisible", "visible", visible); |
485 if (!visible) { | 485 if (!visible) { |
486 DCHECK(host_); | 486 DCHECK(host_); |
487 // Look for any layers that were attached to the root for readback | 487 // Look for any layers that were attached to the root for readback |
488 // and are waiting for Composite() to happen. | 488 // and are waiting for Composite() to happen. |
489 bool readback_pending = false; | 489 bool readback_pending = false; |
490 for (size_t i = 0; i < root_layer_->children().size(); ++i) { | 490 for (size_t i = 0; i < root_layer_->children().size(); ++i) { |
491 if (root_layer_->children()[i]->HasCopyRequest()) { | 491 if (root_layer_->children()[i]->HasCopyRequest()) { |
492 readback_pending = true; | 492 readback_pending = true; |
493 break; | 493 break; |
494 } | 494 } |
495 } | 495 } |
496 if (readback_pending) { | 496 if (readback_pending) { |
497 ignore_schedule_composite_ = true; | 497 ignore_schedule_composite_ = true; |
498 host_->Composite(base::TimeTicks::Now()); | 498 host_->Composite(base::TimeTicks::Now()); |
499 ignore_schedule_composite_ = false; | 499 ignore_schedule_composite_ = false; |
500 } | 500 } |
501 if (WillComposite()) | 501 if (WillComposite()) |
502 CancelComposite(); | 502 CancelComposite(); |
503 ui_resource_provider_.SetLayerTreeHost(NULL); | 503 host_->SetVisible(false); |
504 host_.reset(); | 504 host_->ReleaseOutputSurface(); |
505 pending_swapbuffers_ = 0; | |
danakj
2015/09/28 22:45:43
I don't really know what these are about, but thes
no sievers
2015/09/30 02:32:40
We just have to make sure the accounting doesn't b
| |
506 needs_composite_ = false; | |
507 ui_resource_provider_->OnUIResourcesEvicted(); | |
505 establish_gpu_channel_timeout_.Stop(); | 508 establish_gpu_channel_timeout_.Stop(); |
506 output_surface_request_pending_ = false; | 509 output_surface_request_pending_ = false; |
507 display_client_.reset(); | 510 display_client_.reset(); |
508 if (current_composite_task_) { | 511 if (current_composite_task_) { |
509 current_composite_task_->Cancel(); | 512 current_composite_task_->Cancel(); |
510 current_composite_task_.reset(); | 513 current_composite_task_.reset(); |
511 } | 514 } |
512 } else if (!host_) { | 515 } else { |
513 CreateLayerTreeHost(); | 516 host_->SetVisible(true); |
514 ui_resource_provider_.SetLayerTreeHost(host_.get()); | 517 SetNeedsComposite(); |
515 } | 518 } |
516 } | 519 } |
517 | 520 |
518 void CompositorImpl::setDeviceScaleFactor(float factor) { | 521 void CompositorImpl::setDeviceScaleFactor(float factor) { |
519 device_scale_factor_ = factor; | 522 device_scale_factor_ = factor; |
520 if (host_) | 523 if (host_) |
521 host_->SetDeviceScaleFactor(factor); | 524 host_->SetDeviceScaleFactor(factor); |
522 } | 525 } |
523 | 526 |
524 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { | 527 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { |
525 if (size_ == size) | 528 if (size_ == size) |
526 return; | 529 return; |
527 | 530 |
528 size_ = size; | 531 size_ = size; |
529 if (host_) | 532 if (host_) |
530 host_->SetViewportSize(size); | 533 host_->SetViewportSize(size); |
531 if (display_client_) | 534 if (display_client_) |
532 display_client_->display()->Resize(size); | 535 display_client_->display()->Resize(size); |
533 root_layer_->SetBounds(size); | 536 root_layer_->SetBounds(size); |
534 } | 537 } |
535 | 538 |
536 void CompositorImpl::SetHasTransparentBackground(bool flag) { | 539 void CompositorImpl::SetHasTransparentBackground(bool flag) { |
537 has_transparent_background_ = flag; | 540 has_transparent_background_ = flag; |
538 if (host_) | 541 if (host_) |
539 host_->set_has_transparent_background(flag); | 542 host_->set_has_transparent_background(flag); |
540 } | 543 } |
541 | 544 |
542 void CompositorImpl::SetNeedsComposite() { | 545 void CompositorImpl::SetNeedsComposite() { |
543 if (!host_.get()) | 546 if (!host_->visible()) |
544 return; | 547 return; |
545 DCHECK(!needs_composite_ || WillComposite()); | 548 DCHECK(!needs_composite_ || WillComposite()); |
546 | 549 |
547 needs_composite_ = true; | 550 needs_composite_ = true; |
548 PostComposite(COMPOSITE_IMMEDIATELY); | 551 PostComposite(COMPOSITE_IMMEDIATELY); |
549 } | 552 } |
550 | 553 |
551 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> | 554 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
552 CreateGpuProcessViewContext( | 555 CreateGpuProcessViewContext( |
553 const scoped_refptr<GpuChannelHost>& gpu_channel_host, | 556 const scoped_refptr<GpuChannelHost>& gpu_channel_host, |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
679 surface_output_surface->set_display_client(display_client_.get()); | 682 surface_output_surface->set_display_client(display_client_.get()); |
680 display_client_->display()->Resize(size_); | 683 display_client_->display()->Resize(size_); |
681 host_->SetOutputSurface(surface_output_surface.Pass()); | 684 host_->SetOutputSurface(surface_output_surface.Pass()); |
682 } else { | 685 } else { |
683 host_->SetOutputSurface(real_output_surface.Pass()); | 686 host_->SetOutputSurface(real_output_surface.Pass()); |
684 } | 687 } |
685 } | 688 } |
686 | 689 |
687 void CompositorImpl::PopulateGpuCapabilities( | 690 void CompositorImpl::PopulateGpuCapabilities( |
688 gpu::Capabilities gpu_capabilities) { | 691 gpu::Capabilities gpu_capabilities) { |
689 ui_resource_provider_.SetSupportsETC1NonPowerOfTwo( | 692 ui_resource_provider_->SetSupportsETC1NonPowerOfTwo( |
690 gpu_capabilities.texture_format_etc1_npot); | 693 gpu_capabilities.texture_format_etc1_npot); |
691 } | 694 } |
692 | 695 |
693 void CompositorImpl::AddObserver(VSyncObserver* observer) { | 696 void CompositorImpl::AddObserver(VSyncObserver* observer) { |
694 observer_list_.AddObserver(observer); | 697 observer_list_.AddObserver(observer); |
695 } | 698 } |
696 | 699 |
697 void CompositorImpl::RemoveObserver(VSyncObserver* observer) { | 700 void CompositorImpl::RemoveObserver(VSyncObserver* observer) { |
698 observer_list_.RemoveObserver(observer); | 701 observer_list_.RemoveObserver(observer); |
699 } | 702 } |
700 | 703 |
701 void CompositorImpl::ScheduleComposite() { | 704 void CompositorImpl::ScheduleComposite() { |
702 DCHECK(!needs_composite_ || WillComposite()); | 705 if (ignore_schedule_composite_ || !host_->visible()) |
703 if (ignore_schedule_composite_) | |
704 return; | 706 return; |
705 | 707 |
708 DCHECK_IMPLIES(needs_composite_, WillComposite()); | |
706 needs_composite_ = true; | 709 needs_composite_ = true; |
707 // We currently expect layer tree invalidations at most once per frame | 710 // We currently expect layer tree invalidations at most once per frame |
708 // during normal operation and therefore try to composite immediately | 711 // during normal operation and therefore try to composite immediately |
709 // to minimize latency. | 712 // to minimize latency. |
710 PostComposite(COMPOSITE_IMMEDIATELY); | 713 PostComposite(COMPOSITE_IMMEDIATELY); |
711 } | 714 } |
712 | 715 |
713 void CompositorImpl::ScheduleAnimation() { | 716 void CompositorImpl::ScheduleAnimation() { |
714 DCHECK(!needs_composite_ || WillComposite()); | 717 DCHECK_IMPLIES(needs_composite_, WillComposite()); |
715 needs_animate_ = true; | 718 needs_animate_ = true; |
716 | 719 |
717 if (needs_composite_) | 720 if (needs_composite_) |
718 return; | 721 return; |
719 | 722 |
720 TRACE_EVENT0("cc", "CompositorImpl::ScheduleAnimation"); | 723 TRACE_EVENT0("cc", "CompositorImpl::ScheduleAnimation"); |
721 needs_composite_ = true; | 724 needs_composite_ = true; |
722 PostComposite(COMPOSITE_EVENTUALLY); | 725 PostComposite(COMPOSITE_EVENTUALLY); |
723 } | 726 } |
724 | 727 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
778 composite_on_vsync_trigger_ = DO_NOT_COMPOSITE; | 781 composite_on_vsync_trigger_ = DO_NOT_COMPOSITE; |
779 PostComposite(trigger); | 782 PostComposite(trigger); |
780 } | 783 } |
781 | 784 |
782 FOR_EACH_OBSERVER(VSyncObserver, observer_list_, | 785 FOR_EACH_OBSERVER(VSyncObserver, observer_list_, |
783 OnUpdateVSyncParameters(frame_time, vsync_period)); | 786 OnUpdateVSyncParameters(frame_time, vsync_period)); |
784 } | 787 } |
785 | 788 |
786 void CompositorImpl::SetNeedsAnimate() { | 789 void CompositorImpl::SetNeedsAnimate() { |
787 needs_animate_ = true; | 790 needs_animate_ = true; |
788 if (!host_) | 791 if (!host_->visible()) |
789 return; | 792 return; |
790 | 793 |
791 host_->SetNeedsAnimate(); | 794 host_->SetNeedsAnimate(); |
792 } | 795 } |
793 | 796 |
794 } // namespace content | 797 } // namespace content |
OLD | NEW |