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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 window_(NULL), | 240 window_(NULL), |
241 surface_id_(0), | 241 surface_id_(0), |
242 client_(client), | 242 client_(client), |
243 root_window_(root_window), | 243 root_window_(root_window), |
244 did_post_swapbuffers_(false), | 244 did_post_swapbuffers_(false), |
245 ignore_schedule_composite_(false), | 245 ignore_schedule_composite_(false), |
246 needs_composite_(false), | 246 needs_composite_(false), |
247 needs_animate_(false), | 247 needs_animate_(false), |
248 will_composite_immediately_(false), | 248 will_composite_immediately_(false), |
249 composite_on_vsync_trigger_(DO_NOT_COMPOSITE), | 249 composite_on_vsync_trigger_(DO_NOT_COMPOSITE), |
250 pending_swapbuffers_(0U) { | 250 pending_swapbuffers_(0U), |
| 251 weak_factory_(this) { |
251 DCHECK(client); | 252 DCHECK(client); |
252 DCHECK(root_window); | 253 DCHECK(root_window); |
253 ImageTransportFactoryAndroid::AddObserver(this); | 254 ImageTransportFactoryAndroid::AddObserver(this); |
254 root_window->AttachCompositor(this); | 255 root_window->AttachCompositor(this); |
255 } | 256 } |
256 | 257 |
257 CompositorImpl::~CompositorImpl() { | 258 CompositorImpl::~CompositorImpl() { |
258 root_window_->DetachCompositor(); | 259 root_window_->DetachCompositor(); |
259 ImageTransportFactoryAndroid::RemoveObserver(this); | 260 ImageTransportFactoryAndroid::RemoveObserver(this); |
260 // Clean-up any surface references. | 261 // Clean-up any surface references. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 current_composite_task_->Cancel(); | 316 current_composite_task_->Cancel(); |
316 | 317 |
317 // Unretained because we cancel the task on shutdown. | 318 // Unretained because we cancel the task on shutdown. |
318 current_composite_task_.reset(new base::CancelableClosure( | 319 current_composite_task_.reset(new base::CancelableClosure( |
319 base::Bind(&CompositorImpl::Composite, base::Unretained(this), trigger))); | 320 base::Bind(&CompositorImpl::Composite, base::Unretained(this), trigger))); |
320 base::MessageLoop::current()->PostDelayedTask( | 321 base::MessageLoop::current()->PostDelayedTask( |
321 FROM_HERE, current_composite_task_->callback(), delay); | 322 FROM_HERE, current_composite_task_->callback(), delay); |
322 } | 323 } |
323 | 324 |
324 void CompositorImpl::Composite(CompositingTrigger trigger) { | 325 void CompositorImpl::Composite(CompositingTrigger trigger) { |
| 326 BrowserGpuChannelHostFactory* factory = |
| 327 BrowserGpuChannelHostFactory::instance(); |
| 328 if (!factory->GetGpuChannel() || factory->GetGpuChannel()->IsLost()) { |
| 329 CauseForGpuLaunch cause = |
| 330 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; |
| 331 factory->EstablishGpuChannel( |
| 332 cause, |
| 333 base::Bind(&CompositorImpl::OnGpuChannelEstablished, |
| 334 weak_factory_.GetWeakPtr())); |
| 335 return; |
| 336 } |
| 337 |
325 DCHECK(host_); | 338 DCHECK(host_); |
326 DCHECK(trigger == COMPOSITE_IMMEDIATELY || trigger == COMPOSITE_EVENTUALLY); | 339 DCHECK(trigger == COMPOSITE_IMMEDIATELY || trigger == COMPOSITE_EVENTUALLY); |
327 DCHECK(needs_composite_); | 340 DCHECK(needs_composite_); |
328 DCHECK(!DidCompositeThisFrame()); | 341 DCHECK(!DidCompositeThisFrame()); |
329 | 342 |
330 if (trigger == COMPOSITE_IMMEDIATELY) | 343 if (trigger == COMPOSITE_IMMEDIATELY) |
331 will_composite_immediately_ = false; | 344 will_composite_immediately_ = false; |
332 | 345 |
333 DCHECK_LE(pending_swapbuffers_, kMaxSwapBuffers); | 346 DCHECK_LE(pending_swapbuffers_, kMaxSwapBuffers); |
334 if (pending_swapbuffers_ == kMaxSwapBuffers) { | 347 if (pending_swapbuffers_ == kMaxSwapBuffers) { |
(...skipping 24 matching lines...) Expand all Loading... |
359 | 372 |
360 did_post_swapbuffers_ = false; | 373 did_post_swapbuffers_ = false; |
361 host_->Composite(frame_time); | 374 host_->Composite(frame_time); |
362 if (did_post_swapbuffers_) | 375 if (did_post_swapbuffers_) |
363 pending_swapbuffers_++; | 376 pending_swapbuffers_++; |
364 | 377 |
365 // Need to track vsync to avoid compositing more than once per frame. | 378 // Need to track vsync to avoid compositing more than once per frame. |
366 root_window_->RequestVSyncUpdate(); | 379 root_window_->RequestVSyncUpdate(); |
367 } | 380 } |
368 | 381 |
| 382 void CompositorImpl::OnGpuChannelEstablished() { |
| 383 ScheduleComposite(); |
| 384 } |
| 385 |
369 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { | 386 void CompositorImpl::SetRootLayer(scoped_refptr<cc::Layer> root_layer) { |
370 root_layer_->RemoveAllChildren(); | 387 root_layer_->RemoveAllChildren(); |
371 if (root_layer) | 388 if (root_layer) |
372 root_layer_->AddChild(root_layer); | 389 root_layer_->AddChild(root_layer); |
373 } | 390 } |
374 | 391 |
375 void CompositorImpl::SetWindowSurface(ANativeWindow* window) { | 392 void CompositorImpl::SetWindowSurface(ANativeWindow* window) { |
376 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); | 393 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); |
377 | 394 |
378 if (window_) { | 395 if (window_) { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 } | 559 } |
543 | 560 |
544 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) { | 561 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) { |
545 UIResourceMap::iterator it = ui_resource_map_.find(resource_id); | 562 UIResourceMap::iterator it = ui_resource_map_.find(resource_id); |
546 if (it != ui_resource_map_.end()) | 563 if (it != ui_resource_map_.end()) |
547 ui_resource_map_.erase(it); | 564 ui_resource_map_.erase(it); |
548 } | 565 } |
549 | 566 |
550 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> | 567 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
551 CreateGpuProcessViewContext( | 568 CreateGpuProcessViewContext( |
| 569 const scoped_refptr<GpuChannelHost>& gpu_channel_host, |
552 const blink::WebGraphicsContext3D::Attributes attributes, | 570 const blink::WebGraphicsContext3D::Attributes attributes, |
553 int surface_id) { | 571 int surface_id) { |
554 BrowserGpuChannelHostFactory* factory = | 572 DCHECK(gpu_channel_host); |
555 BrowserGpuChannelHostFactory::instance(); | |
556 CauseForGpuLaunch cause = | |
557 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | |
558 scoped_refptr<GpuChannelHost> gpu_channel_host( | |
559 factory->EstablishGpuChannelSync(cause)); | |
560 if (!gpu_channel_host) | |
561 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); | |
562 | 573 |
563 GURL url("chrome://gpu/Compositor::createContext3D"); | 574 GURL url("chrome://gpu/Compositor::createContext3D"); |
564 static const size_t kBytesPerPixel = 4; | 575 static const size_t kBytesPerPixel = 4; |
565 gfx::DeviceDisplayInfo display_info; | 576 gfx::DeviceDisplayInfo display_info; |
566 size_t full_screen_texture_size_in_bytes = | 577 size_t full_screen_texture_size_in_bytes = |
567 display_info.GetDisplayHeight() * | 578 display_info.GetDisplayHeight() * |
568 display_info.GetDisplayWidth() * | 579 display_info.GetDisplayWidth() * |
569 kBytesPerPixel; | 580 kBytesPerPixel; |
570 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits; | 581 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits; |
571 limits.command_buffer_size = 64 * 1024; | 582 limits.command_buffer_size = 64 * 1024; |
(...skipping 18 matching lines...) Expand all Loading... |
590 // to stop calling it ourselves in CompositorImpl::Composite(). | 601 // to stop calling it ourselves in CompositorImpl::Composite(). |
591 NOTREACHED(); | 602 NOTREACHED(); |
592 client_->Layout(); | 603 client_->Layout(); |
593 } | 604 } |
594 | 605 |
595 scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface( | 606 scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface( |
596 bool fallback) { | 607 bool fallback) { |
597 blink::WebGraphicsContext3D::Attributes attrs; | 608 blink::WebGraphicsContext3D::Attributes attrs; |
598 attrs.shareResources = true; | 609 attrs.shareResources = true; |
599 attrs.noAutomaticFlushes = true; | 610 attrs.noAutomaticFlushes = true; |
| 611 pending_swapbuffers_ = 0; |
600 | 612 |
601 DCHECK(window_); | 613 DCHECK(window_); |
602 DCHECK(surface_id_); | 614 DCHECK(surface_id_); |
603 | 615 |
604 scoped_refptr<ContextProviderCommandBuffer> context_provider = | 616 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
605 ContextProviderCommandBuffer::Create( | 617 BrowserGpuChannelHostFactory* factory = |
606 CreateGpuProcessViewContext(attrs, surface_id_), "BrowserCompositor"); | 618 BrowserGpuChannelHostFactory::instance(); |
| 619 scoped_refptr<GpuChannelHost> gpu_channel_host = factory->GetGpuChannel(); |
| 620 if (gpu_channel_host && !gpu_channel_host->IsLost()) { |
| 621 context_provider = ContextProviderCommandBuffer::Create( |
| 622 CreateGpuProcessViewContext(gpu_channel_host, attrs, surface_id_), |
| 623 "BrowserCompositor"); |
| 624 } |
607 if (!context_provider.get()) { | 625 if (!context_provider.get()) { |
608 LOG(ERROR) << "Failed to create 3D context for compositor."; | 626 LOG(ERROR) << "Failed to create 3D context for compositor."; |
609 return scoped_ptr<cc::OutputSurface>(); | 627 return scoped_ptr<cc::OutputSurface>(); |
610 } | 628 } |
611 | 629 |
612 return scoped_ptr<cc::OutputSurface>( | 630 return scoped_ptr<cc::OutputSurface>( |
613 new OutputSurfaceWithoutParent(context_provider)); | 631 new OutputSurfaceWithoutParent(context_provider)); |
614 } | 632 } |
615 | 633 |
616 void CompositorImpl::OnLostResources() { | 634 void CompositorImpl::OnLostResources() { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 void CompositorImpl::DidCompleteSwapBuffers() { | 668 void CompositorImpl::DidCompleteSwapBuffers() { |
651 TRACE_EVENT0("compositor", "CompositorImpl::DidCompleteSwapBuffers"); | 669 TRACE_EVENT0("compositor", "CompositorImpl::DidCompleteSwapBuffers"); |
652 DCHECK_GT(pending_swapbuffers_, 0U); | 670 DCHECK_GT(pending_swapbuffers_, 0U); |
653 if (pending_swapbuffers_-- == kMaxSwapBuffers && needs_composite_) | 671 if (pending_swapbuffers_-- == kMaxSwapBuffers && needs_composite_) |
654 PostComposite(COMPOSITE_IMMEDIATELY); | 672 PostComposite(COMPOSITE_IMMEDIATELY); |
655 client_->OnSwapBuffersCompleted(pending_swapbuffers_); | 673 client_->OnSwapBuffersCompleted(pending_swapbuffers_); |
656 } | 674 } |
657 | 675 |
658 void CompositorImpl::DidAbortSwapBuffers() { | 676 void CompositorImpl::DidAbortSwapBuffers() { |
659 TRACE_EVENT0("compositor", "CompositorImpl::DidAbortSwapBuffers"); | 677 TRACE_EVENT0("compositor", "CompositorImpl::DidAbortSwapBuffers"); |
660 DCHECK_GT(pending_swapbuffers_, 0U); | 678 // This really gets called only once from |
661 if (pending_swapbuffers_-- == kMaxSwapBuffers && needs_composite_) | 679 // SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() when the |
662 PostComposite(COMPOSITE_IMMEDIATELY); | 680 // context was lost. |
663 client_->OnSwapBuffersCompleted(pending_swapbuffers_); | 681 client_->OnSwapBuffersCompleted(0); |
664 } | 682 } |
665 | 683 |
666 void CompositorImpl::DidCommit() { | 684 void CompositorImpl::DidCommit() { |
667 root_window_->OnCompositingDidCommit(); | 685 root_window_->OnCompositingDidCommit(); |
668 } | 686 } |
669 | 687 |
670 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) { | 688 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) { |
671 root_layer_->AddChild(layer); | 689 root_layer_->AddChild(layer); |
672 } | 690 } |
673 | 691 |
(...skipping 24 matching lines...) Expand all Loading... |
698 } | 716 } |
699 | 717 |
700 void CompositorImpl::SetNeedsAnimate() { | 718 void CompositorImpl::SetNeedsAnimate() { |
701 if (!host_) | 719 if (!host_) |
702 return; | 720 return; |
703 | 721 |
704 host_->SetNeedsAnimate(); | 722 host_->SetNeedsAnimate(); |
705 } | 723 } |
706 | 724 |
707 } // namespace content | 725 } // namespace content |
OLD | NEW |