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 "content/browser/compositor/delegated_frame_host.h" | 5 #include "content/browser/compositor/delegated_frame_host.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/time/default_tick_clock.h" | 9 #include "base/time/default_tick_clock.h" |
10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 base::Bind(callback, present_time))); | 293 base::Bind(callback, present_time))); |
294 // Setting the source in this copy request asks that the layer abort any prior | 294 // Setting the source in this copy request asks that the layer abort any prior |
295 // uncommitted copy requests made on behalf of the same frame subscriber. | 295 // uncommitted copy requests made on behalf of the same frame subscriber. |
296 // This will not affect any of the copy requests spawned elsewhere from | 296 // This will not affect any of the copy requests spawned elsewhere from |
297 // DelegatedFrameHost (e.g., a call to CopyFromCompositingSurface() for | 297 // DelegatedFrameHost (e.g., a call to CopyFromCompositingSurface() for |
298 // screenshots) since those copy requests do not specify |frame_subscriber()| | 298 // screenshots) since those copy requests do not specify |frame_subscriber()| |
299 // as a source. | 299 // as a source. |
300 request->set_source(frame_subscriber()); | 300 request->set_source(frame_subscriber()); |
301 request->set_area(gfx::Rect(current_frame_size_in_dip_)); | 301 request->set_area(gfx::Rect(current_frame_size_in_dip_)); |
302 if (subscriber_texture.get()) { | 302 if (subscriber_texture.get()) { |
303 request->SetTextureMailbox( | 303 request->SetTextureMailbox(cc::TextureMailbox( |
304 cc::TextureMailbox(subscriber_texture->mailbox(), | 304 subscriber_texture->mailbox(), subscriber_texture->sync_token(), |
305 subscriber_texture->target(), | 305 subscriber_texture->target())); |
306 subscriber_texture->sync_point())); | |
307 } | 306 } |
308 RequestCopyOfOutput(request.Pass()); | 307 RequestCopyOfOutput(request.Pass()); |
309 } | 308 } |
310 | 309 |
311 void DelegatedFrameHost::SwapDelegatedFrame( | 310 void DelegatedFrameHost::SwapDelegatedFrame( |
312 uint32 output_surface_id, | 311 uint32 output_surface_id, |
313 scoped_ptr<cc::DelegatedFrameData> frame_data, | 312 scoped_ptr<cc::DelegatedFrameData> frame_data, |
314 float frame_device_scale_factor, | 313 float frame_device_scale_factor, |
315 const std::vector<ui::LatencyInfo>& latency_info, | 314 const std::vector<ui::LatencyInfo>& latency_info, |
316 std::vector<uint32_t>* satisfies_sequences) { | 315 std::vector<uint32_t>* satisfies_sequences) { |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 } | 583 } |
585 | 584 |
586 static void CopyFromCompositingSurfaceFinished( | 585 static void CopyFromCompositingSurfaceFinished( |
587 const ReadbackRequestCallback& callback, | 586 const ReadbackRequestCallback& callback, |
588 scoped_ptr<cc::SingleReleaseCallback> release_callback, | 587 scoped_ptr<cc::SingleReleaseCallback> release_callback, |
589 scoped_ptr<SkBitmap> bitmap, | 588 scoped_ptr<SkBitmap> bitmap, |
590 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock, | 589 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock, |
591 bool result) { | 590 bool result) { |
592 bitmap_pixels_lock.reset(); | 591 bitmap_pixels_lock.reset(); |
593 | 592 |
594 uint32 sync_point = 0; | 593 gpu::SyncToken sync_token; |
595 if (result) { | 594 if (result) { |
596 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); | 595 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); |
597 if (gl_helper) | 596 if (gl_helper) |
598 sync_point = gl_helper->InsertSyncPoint(); | 597 sync_token = gpu::SyncToken(gl_helper->InsertSyncPoint()); |
599 } | 598 } |
600 bool lost_resource = sync_point == 0; | 599 const bool lost_resource = !sync_token.HasData(); |
601 release_callback->Run(sync_point, lost_resource); | 600 release_callback->Run(sync_token, lost_resource); |
602 | 601 |
603 callback.Run(*bitmap, | 602 callback.Run(*bitmap, |
604 result ? content::READBACK_SUCCESS : content::READBACK_FAILED); | 603 result ? content::READBACK_SUCCESS : content::READBACK_FAILED); |
605 } | 604 } |
606 | 605 |
607 // static | 606 // static |
608 void DelegatedFrameHost::PrepareTextureCopyOutputResult( | 607 void DelegatedFrameHost::PrepareTextureCopyOutputResult( |
609 const gfx::Size& dst_size_in_pixel, | 608 const gfx::Size& dst_size_in_pixel, |
610 const SkColorType color_type, | 609 const SkColorType color_type, |
611 const ReadbackRequestCallback& callback, | 610 const ReadbackRequestCallback& callback, |
(...skipping 24 matching lines...) Expand all Loading... |
636 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); | 635 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); |
637 | 636 |
638 cc::TextureMailbox texture_mailbox; | 637 cc::TextureMailbox texture_mailbox; |
639 scoped_ptr<cc::SingleReleaseCallback> release_callback; | 638 scoped_ptr<cc::SingleReleaseCallback> release_callback; |
640 result->TakeTexture(&texture_mailbox, &release_callback); | 639 result->TakeTexture(&texture_mailbox, &release_callback); |
641 DCHECK(texture_mailbox.IsTexture()); | 640 DCHECK(texture_mailbox.IsTexture()); |
642 | 641 |
643 ignore_result(scoped_callback_runner.Release()); | 642 ignore_result(scoped_callback_runner.Release()); |
644 | 643 |
645 gl_helper->CropScaleReadbackAndCleanMailbox( | 644 gl_helper->CropScaleReadbackAndCleanMailbox( |
646 texture_mailbox.mailbox(), | 645 texture_mailbox.mailbox(), texture_mailbox.sync_token(), result->size(), |
647 texture_mailbox.sync_point(), | 646 gfx::Rect(result->size()), dst_size_in_pixel, pixels, color_type, |
648 result->size(), | 647 base::Bind(&CopyFromCompositingSurfaceFinished, callback, |
649 gfx::Rect(result->size()), | 648 base::Passed(&release_callback), base::Passed(&bitmap), |
650 dst_size_in_pixel, | |
651 pixels, | |
652 color_type, | |
653 base::Bind(&CopyFromCompositingSurfaceFinished, | |
654 callback, | |
655 base::Passed(&release_callback), | |
656 base::Passed(&bitmap), | |
657 base::Passed(&bitmap_pixels_lock)), | 649 base::Passed(&bitmap_pixels_lock)), |
658 GLHelper::SCALER_QUALITY_GOOD); | 650 GLHelper::SCALER_QUALITY_GOOD); |
659 } | 651 } |
660 | 652 |
661 // static | 653 // static |
662 void DelegatedFrameHost::PrepareBitmapCopyOutputResult( | 654 void DelegatedFrameHost::PrepareBitmapCopyOutputResult( |
663 const gfx::Size& dst_size_in_pixel, | 655 const gfx::Size& dst_size_in_pixel, |
664 const SkColorType preferred_color_type, | 656 const SkColorType preferred_color_type, |
665 const ReadbackRequestCallback& callback, | 657 const ReadbackRequestCallback& callback, |
666 scoped_ptr<cc::CopyOutputResult> result) { | 658 scoped_ptr<cc::CopyOutputResult> result) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 skia::AdoptRef(SkLumaColorFilter::Create()); | 698 skia::AdoptRef(SkLumaColorFilter::Create()); |
707 paint.setColorFilter(filter.get()); | 699 paint.setColorFilter(filter.get()); |
708 canvas.drawBitmap(scaled_bitmap, SkIntToScalar(0), SkIntToScalar(0), &paint); | 700 canvas.drawBitmap(scaled_bitmap, SkIntToScalar(0), SkIntToScalar(0), &paint); |
709 callback.Run(grayscale_bitmap, READBACK_SUCCESS); | 701 callback.Run(grayscale_bitmap, READBACK_SUCCESS); |
710 } | 702 } |
711 | 703 |
712 // static | 704 // static |
713 void DelegatedFrameHost::ReturnSubscriberTexture( | 705 void DelegatedFrameHost::ReturnSubscriberTexture( |
714 base::WeakPtr<DelegatedFrameHost> dfh, | 706 base::WeakPtr<DelegatedFrameHost> dfh, |
715 scoped_refptr<OwnedMailbox> subscriber_texture, | 707 scoped_refptr<OwnedMailbox> subscriber_texture, |
716 uint32 sync_point) { | 708 const gpu::SyncToken& sync_token) { |
717 if (!subscriber_texture.get()) | 709 if (!subscriber_texture.get()) |
718 return; | 710 return; |
719 if (!dfh) | 711 if (!dfh) |
720 return; | 712 return; |
721 | 713 |
722 subscriber_texture->UpdateSyncPoint(sync_point); | 714 subscriber_texture->UpdateSyncToken(sync_token); |
723 | 715 |
724 if (dfh->frame_subscriber_ && subscriber_texture->texture_id()) | 716 if (dfh->frame_subscriber_ && subscriber_texture->texture_id()) |
725 dfh->idle_frame_subscriber_textures_.push_back(subscriber_texture); | 717 dfh->idle_frame_subscriber_textures_.push_back(subscriber_texture); |
726 } | 718 } |
727 | 719 |
728 // static | 720 // static |
729 void DelegatedFrameHost::CopyFromCompositingSurfaceFinishedForVideo( | 721 void DelegatedFrameHost::CopyFromCompositingSurfaceFinishedForVideo( |
730 base::WeakPtr<DelegatedFrameHost> dfh, | 722 base::WeakPtr<DelegatedFrameHost> dfh, |
731 const base::Callback<void(bool)>& callback, | 723 const base::Callback<void(bool)>& callback, |
732 scoped_refptr<OwnedMailbox> subscriber_texture, | 724 scoped_refptr<OwnedMailbox> subscriber_texture, |
733 scoped_ptr<cc::SingleReleaseCallback> release_callback, | 725 scoped_ptr<cc::SingleReleaseCallback> release_callback, |
734 bool result) { | 726 bool result) { |
735 callback.Run(result); | 727 callback.Run(result); |
736 | 728 |
737 uint32 sync_point = 0; | 729 gpu::SyncToken sync_token; |
738 if (result) { | 730 if (result) { |
739 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); | 731 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); |
740 sync_point = gl_helper->InsertSyncPoint(); | 732 sync_token = gpu::SyncToken(gl_helper->InsertSyncPoint()); |
741 } | 733 } |
742 if (release_callback) { | 734 if (release_callback) { |
743 // A release callback means the texture came from the compositor, so there | 735 // A release callback means the texture came from the compositor, so there |
744 // should be no |subscriber_texture|. | 736 // should be no |subscriber_texture|. |
745 DCHECK(!subscriber_texture.get()); | 737 DCHECK(!subscriber_texture.get()); |
746 bool lost_resource = sync_point == 0; | 738 const bool lost_resource = !sync_token.HasData(); |
747 release_callback->Run(sync_point, lost_resource); | 739 release_callback->Run(sync_token, lost_resource); |
748 } | 740 } |
749 ReturnSubscriberTexture(dfh, subscriber_texture, sync_point); | 741 ReturnSubscriberTexture(dfh, subscriber_texture, sync_token); |
750 } | 742 } |
751 | 743 |
752 // static | 744 // static |
753 void DelegatedFrameHost::CopyFromCompositingSurfaceHasResultForVideo( | 745 void DelegatedFrameHost::CopyFromCompositingSurfaceHasResultForVideo( |
754 base::WeakPtr<DelegatedFrameHost> dfh, | 746 base::WeakPtr<DelegatedFrameHost> dfh, |
755 scoped_refptr<OwnedMailbox> subscriber_texture, | 747 scoped_refptr<OwnedMailbox> subscriber_texture, |
756 scoped_refptr<media::VideoFrame> video_frame, | 748 scoped_refptr<media::VideoFrame> video_frame, |
757 const base::Callback<void(bool)>& callback, | 749 const base::Callback<void(bool)>& callback, |
758 scoped_ptr<cc::CopyOutputResult> result) { | 750 scoped_ptr<cc::CopyOutputResult> result) { |
759 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); | 751 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); |
760 base::ScopedClosureRunner scoped_return_subscriber_texture( | 752 base::ScopedClosureRunner scoped_return_subscriber_texture(base::Bind( |
761 base::Bind(&ReturnSubscriberTexture, dfh, subscriber_texture, 0)); | 753 &ReturnSubscriberTexture, dfh, subscriber_texture, gpu::SyncToken())); |
762 | 754 |
763 if (!dfh) | 755 if (!dfh) |
764 return; | 756 return; |
765 if (result->IsEmpty()) | 757 if (result->IsEmpty()) |
766 return; | 758 return; |
767 if (result->size().IsEmpty()) | 759 if (result->size().IsEmpty()) |
768 return; | 760 return; |
769 | 761 |
770 // Compute the dest size we want after the letterboxing resize. Make the | 762 // Compute the dest size we want after the letterboxing resize. Make the |
771 // coordinates and sizes even because we letterbox in YUV space | 763 // coordinates and sizes even because we letterbox in YUV space |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 } | 851 } |
860 | 852 |
861 ignore_result(scoped_callback_runner.Release()); | 853 ignore_result(scoped_callback_runner.Release()); |
862 ignore_result(scoped_return_subscriber_texture.Release()); | 854 ignore_result(scoped_return_subscriber_texture.Release()); |
863 base::Callback<void(bool result)> finished_callback = base::Bind( | 855 base::Callback<void(bool result)> finished_callback = base::Bind( |
864 &DelegatedFrameHost::CopyFromCompositingSurfaceFinishedForVideo, | 856 &DelegatedFrameHost::CopyFromCompositingSurfaceFinishedForVideo, |
865 dfh->AsWeakPtr(), | 857 dfh->AsWeakPtr(), |
866 callback, | 858 callback, |
867 subscriber_texture, | 859 subscriber_texture, |
868 base::Passed(&release_callback)); | 860 base::Passed(&release_callback)); |
869 yuv_readback_pipeline->ReadbackYUV(texture_mailbox.mailbox(), | 861 yuv_readback_pipeline->ReadbackYUV( |
870 texture_mailbox.sync_point(), | 862 texture_mailbox.mailbox(), texture_mailbox.sync_token(), |
871 video_frame.get(), | 863 video_frame.get(), region_in_frame.origin(), finished_callback); |
872 region_in_frame.origin(), | |
873 finished_callback); | |
874 } | 864 } |
875 | 865 |
876 //////////////////////////////////////////////////////////////////////////////// | 866 //////////////////////////////////////////////////////////////////////////////// |
877 // DelegatedFrameHost, ui::CompositorObserver implementation: | 867 // DelegatedFrameHost, ui::CompositorObserver implementation: |
878 | 868 |
879 void DelegatedFrameHost::OnCompositingDidCommit( | 869 void DelegatedFrameHost::OnCompositingDidCommit( |
880 ui::Compositor* compositor) { | 870 ui::Compositor* compositor) { |
881 if (can_lock_compositor_ == NO_PENDING_COMMIT) { | 871 if (can_lock_compositor_ == NO_PENDING_COMMIT) { |
882 can_lock_compositor_ = YES_CAN_LOCK; | 872 can_lock_compositor_ = YES_CAN_LOCK; |
883 if (resize_lock_.get() && resize_lock_->GrabDeferredLock()) | 873 if (resize_lock_.get() && resize_lock_->GrabDeferredLock()) |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 cc::SurfaceManager* manager = factory->GetSurfaceManager(); | 1034 cc::SurfaceManager* manager = factory->GetSurfaceManager(); |
1045 new_layer->SetShowSurface( | 1035 new_layer->SetShowSurface( |
1046 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), | 1036 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), |
1047 base::Bind(&RequireCallback, base::Unretained(manager)), | 1037 base::Bind(&RequireCallback, base::Unretained(manager)), |
1048 current_surface_size_, current_scale_factor_, | 1038 current_surface_size_, current_scale_factor_, |
1049 current_frame_size_in_dip_); | 1039 current_frame_size_in_dip_); |
1050 } | 1040 } |
1051 } | 1041 } |
1052 | 1042 |
1053 } // namespace content | 1043 } // namespace content |
OLD | NEW |