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->target(), |
305 subscriber_texture->target(), | 305 subscriber_texture->sync_point(), subscriber_texture->sync_token())); |
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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 bool result) { | 591 bool result) { |
593 bitmap_pixels_lock.reset(); | 592 bitmap_pixels_lock.reset(); |
594 | 593 |
595 uint32 sync_point = 0; | 594 uint32 sync_point = 0; |
596 if (result) { | 595 if (result) { |
597 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); | 596 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); |
598 if (gl_helper) | 597 if (gl_helper) |
599 sync_point = gl_helper->InsertSyncPoint(); | 598 sync_point = gl_helper->InsertSyncPoint(); |
600 } | 599 } |
601 bool lost_resource = sync_point == 0; | 600 bool lost_resource = sync_point == 0; |
602 release_callback->Run(sync_point, lost_resource); | 601 release_callback->Run(sync_point, gpu::SyncToken(), lost_resource); |
603 | 602 |
604 callback.Run(*bitmap, | 603 callback.Run(*bitmap, |
605 result ? content::READBACK_SUCCESS : content::READBACK_FAILED); | 604 result ? content::READBACK_SUCCESS : content::READBACK_FAILED); |
606 } | 605 } |
607 | 606 |
608 // static | 607 // static |
609 void DelegatedFrameHost::PrepareTextureCopyOutputResult( | 608 void DelegatedFrameHost::PrepareTextureCopyOutputResult( |
610 const gfx::Size& dst_size_in_pixel, | 609 const gfx::Size& dst_size_in_pixel, |
611 const SkColorType color_type, | 610 const SkColorType color_type, |
612 const ReadbackRequestCallback& callback, | 611 const ReadbackRequestCallback& callback, |
(...skipping 24 matching lines...) Expand all Loading... |
637 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); | 636 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); |
638 | 637 |
639 cc::TextureMailbox texture_mailbox; | 638 cc::TextureMailbox texture_mailbox; |
640 scoped_ptr<cc::SingleReleaseCallback> release_callback; | 639 scoped_ptr<cc::SingleReleaseCallback> release_callback; |
641 result->TakeTexture(&texture_mailbox, &release_callback); | 640 result->TakeTexture(&texture_mailbox, &release_callback); |
642 DCHECK(texture_mailbox.IsTexture()); | 641 DCHECK(texture_mailbox.IsTexture()); |
643 | 642 |
644 ignore_result(scoped_callback_runner.Release()); | 643 ignore_result(scoped_callback_runner.Release()); |
645 | 644 |
646 gl_helper->CropScaleReadbackAndCleanMailbox( | 645 gl_helper->CropScaleReadbackAndCleanMailbox( |
647 texture_mailbox.mailbox(), | 646 texture_mailbox.mailbox(), texture_mailbox.sync_point(), |
648 texture_mailbox.sync_point(), | 647 texture_mailbox.sync_token(), result->size(), gfx::Rect(result->size()), |
649 result->size(), | 648 dst_size_in_pixel, pixels, color_type, |
650 gfx::Rect(result->size()), | 649 base::Bind(&CopyFromCompositingSurfaceFinished, callback, |
651 dst_size_in_pixel, | 650 base::Passed(&release_callback), base::Passed(&bitmap), |
652 pixels, | |
653 color_type, | |
654 base::Bind(&CopyFromCompositingSurfaceFinished, | |
655 callback, | |
656 base::Passed(&release_callback), | |
657 base::Passed(&bitmap), | |
658 base::Passed(&bitmap_pixels_lock)), | 651 base::Passed(&bitmap_pixels_lock)), |
659 GLHelper::SCALER_QUALITY_GOOD); | 652 GLHelper::SCALER_QUALITY_GOOD); |
660 } | 653 } |
661 | 654 |
662 // static | 655 // static |
663 void DelegatedFrameHost::PrepareBitmapCopyOutputResult( | 656 void DelegatedFrameHost::PrepareBitmapCopyOutputResult( |
664 const gfx::Size& dst_size_in_pixel, | 657 const gfx::Size& dst_size_in_pixel, |
665 const SkColorType preferred_color_type, | 658 const SkColorType preferred_color_type, |
666 const ReadbackRequestCallback& callback, | 659 const ReadbackRequestCallback& callback, |
667 scoped_ptr<cc::CopyOutputResult> result) { | 660 scoped_ptr<cc::CopyOutputResult> result) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 skia::AdoptRef(SkLumaColorFilter::Create()); | 700 skia::AdoptRef(SkLumaColorFilter::Create()); |
708 paint.setColorFilter(filter.get()); | 701 paint.setColorFilter(filter.get()); |
709 canvas.drawBitmap(scaled_bitmap, SkIntToScalar(0), SkIntToScalar(0), &paint); | 702 canvas.drawBitmap(scaled_bitmap, SkIntToScalar(0), SkIntToScalar(0), &paint); |
710 callback.Run(grayscale_bitmap, READBACK_SUCCESS); | 703 callback.Run(grayscale_bitmap, READBACK_SUCCESS); |
711 } | 704 } |
712 | 705 |
713 // static | 706 // static |
714 void DelegatedFrameHost::ReturnSubscriberTexture( | 707 void DelegatedFrameHost::ReturnSubscriberTexture( |
715 base::WeakPtr<DelegatedFrameHost> dfh, | 708 base::WeakPtr<DelegatedFrameHost> dfh, |
716 scoped_refptr<OwnedMailbox> subscriber_texture, | 709 scoped_refptr<OwnedMailbox> subscriber_texture, |
717 uint32 sync_point) { | 710 uint32 sync_point, |
| 711 const gpu::SyncToken& sync_token) { |
718 if (!subscriber_texture.get()) | 712 if (!subscriber_texture.get()) |
719 return; | 713 return; |
720 if (!dfh) | 714 if (!dfh) |
721 return; | 715 return; |
722 | 716 |
723 subscriber_texture->UpdateSyncPoint(sync_point); | 717 subscriber_texture->UpdateSyncPoint(sync_point, sync_token); |
724 | 718 |
725 if (dfh->frame_subscriber_ && subscriber_texture->texture_id()) | 719 if (dfh->frame_subscriber_ && subscriber_texture->texture_id()) |
726 dfh->idle_frame_subscriber_textures_.push_back(subscriber_texture); | 720 dfh->idle_frame_subscriber_textures_.push_back(subscriber_texture); |
727 } | 721 } |
728 | 722 |
729 // static | 723 // static |
730 void DelegatedFrameHost::CopyFromCompositingSurfaceFinishedForVideo( | 724 void DelegatedFrameHost::CopyFromCompositingSurfaceFinishedForVideo( |
731 base::WeakPtr<DelegatedFrameHost> dfh, | 725 base::WeakPtr<DelegatedFrameHost> dfh, |
732 const base::Callback<void(bool)>& callback, | 726 const base::Callback<void(bool)>& callback, |
733 scoped_refptr<OwnedMailbox> subscriber_texture, | 727 scoped_refptr<OwnedMailbox> subscriber_texture, |
734 scoped_ptr<cc::SingleReleaseCallback> release_callback, | 728 scoped_ptr<cc::SingleReleaseCallback> release_callback, |
735 bool result) { | 729 bool result) { |
736 callback.Run(result); | 730 callback.Run(result); |
737 | 731 |
738 uint32 sync_point = 0; | 732 uint32 sync_point = 0; |
739 if (result) { | 733 if (result) { |
740 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); | 734 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); |
741 sync_point = gl_helper->InsertSyncPoint(); | 735 sync_point = gl_helper->InsertSyncPoint(); |
742 } | 736 } |
743 if (release_callback) { | 737 if (release_callback) { |
744 // A release callback means the texture came from the compositor, so there | 738 // A release callback means the texture came from the compositor, so there |
745 // should be no |subscriber_texture|. | 739 // should be no |subscriber_texture|. |
746 DCHECK(!subscriber_texture.get()); | 740 DCHECK(!subscriber_texture.get()); |
747 bool lost_resource = sync_point == 0; | 741 bool lost_resource = sync_point == 0; |
748 release_callback->Run(sync_point, lost_resource); | 742 release_callback->Run(sync_point, gpu::SyncToken(), lost_resource); |
749 } | 743 } |
750 ReturnSubscriberTexture(dfh, subscriber_texture, sync_point); | 744 ReturnSubscriberTexture(dfh, subscriber_texture, sync_point, |
| 745 gpu::SyncToken()); |
751 } | 746 } |
752 | 747 |
753 // static | 748 // static |
754 void DelegatedFrameHost::CopyFromCompositingSurfaceHasResultForVideo( | 749 void DelegatedFrameHost::CopyFromCompositingSurfaceHasResultForVideo( |
755 base::WeakPtr<DelegatedFrameHost> dfh, | 750 base::WeakPtr<DelegatedFrameHost> dfh, |
756 scoped_refptr<OwnedMailbox> subscriber_texture, | 751 scoped_refptr<OwnedMailbox> subscriber_texture, |
757 scoped_refptr<media::VideoFrame> video_frame, | 752 scoped_refptr<media::VideoFrame> video_frame, |
758 const base::Callback<void(bool)>& callback, | 753 const base::Callback<void(bool)>& callback, |
759 scoped_ptr<cc::CopyOutputResult> result) { | 754 scoped_ptr<cc::CopyOutputResult> result) { |
760 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); | 755 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); |
761 base::ScopedClosureRunner scoped_return_subscriber_texture( | 756 base::ScopedClosureRunner scoped_return_subscriber_texture(base::Bind( |
762 base::Bind(&ReturnSubscriberTexture, dfh, subscriber_texture, 0)); | 757 &ReturnSubscriberTexture, dfh, subscriber_texture, 0, gpu::SyncToken())); |
763 | 758 |
764 if (!dfh) | 759 if (!dfh) |
765 return; | 760 return; |
766 if (result->IsEmpty()) | 761 if (result->IsEmpty()) |
767 return; | 762 return; |
768 if (result->size().IsEmpty()) | 763 if (result->size().IsEmpty()) |
769 return; | 764 return; |
770 | 765 |
771 // Compute the dest size we want after the letterboxing resize. Make the | 766 // Compute the dest size we want after the letterboxing resize. Make the |
772 // coordinates and sizes even because we letterbox in YUV space | 767 // coordinates and sizes even because we letterbox in YUV space |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 } | 855 } |
861 | 856 |
862 ignore_result(scoped_callback_runner.Release()); | 857 ignore_result(scoped_callback_runner.Release()); |
863 ignore_result(scoped_return_subscriber_texture.Release()); | 858 ignore_result(scoped_return_subscriber_texture.Release()); |
864 base::Callback<void(bool result)> finished_callback = base::Bind( | 859 base::Callback<void(bool result)> finished_callback = base::Bind( |
865 &DelegatedFrameHost::CopyFromCompositingSurfaceFinishedForVideo, | 860 &DelegatedFrameHost::CopyFromCompositingSurfaceFinishedForVideo, |
866 dfh->AsWeakPtr(), | 861 dfh->AsWeakPtr(), |
867 callback, | 862 callback, |
868 subscriber_texture, | 863 subscriber_texture, |
869 base::Passed(&release_callback)); | 864 base::Passed(&release_callback)); |
870 yuv_readback_pipeline->ReadbackYUV(texture_mailbox.mailbox(), | 865 yuv_readback_pipeline->ReadbackYUV( |
871 texture_mailbox.sync_point(), | 866 texture_mailbox.mailbox(), texture_mailbox.sync_point(), |
872 video_frame.get(), | 867 texture_mailbox.sync_token(), video_frame.get(), region_in_frame.origin(), |
873 region_in_frame.origin(), | 868 finished_callback); |
874 finished_callback); | |
875 } | 869 } |
876 | 870 |
877 //////////////////////////////////////////////////////////////////////////////// | 871 //////////////////////////////////////////////////////////////////////////////// |
878 // DelegatedFrameHost, ui::CompositorObserver implementation: | 872 // DelegatedFrameHost, ui::CompositorObserver implementation: |
879 | 873 |
880 void DelegatedFrameHost::OnCompositingDidCommit( | 874 void DelegatedFrameHost::OnCompositingDidCommit( |
881 ui::Compositor* compositor) { | 875 ui::Compositor* compositor) { |
882 if (can_lock_compositor_ == NO_PENDING_COMMIT) { | 876 if (can_lock_compositor_ == NO_PENDING_COMMIT) { |
883 can_lock_compositor_ = YES_CAN_LOCK; | 877 can_lock_compositor_ = YES_CAN_LOCK; |
884 if (resize_lock_.get() && resize_lock_->GrabDeferredLock()) | 878 if (resize_lock_.get() && resize_lock_->GrabDeferredLock()) |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 cc::SurfaceManager* manager = factory->GetSurfaceManager(); | 1039 cc::SurfaceManager* manager = factory->GetSurfaceManager(); |
1046 new_layer->SetShowSurface( | 1040 new_layer->SetShowSurface( |
1047 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), | 1041 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), |
1048 base::Bind(&RequireCallback, base::Unretained(manager)), | 1042 base::Bind(&RequireCallback, base::Unretained(manager)), |
1049 current_surface_size_, current_scale_factor_, | 1043 current_surface_size_, current_scale_factor_, |
1050 current_frame_size_in_dip_); | 1044 current_frame_size_in_dip_); |
1051 } | 1045 } |
1052 } | 1046 } |
1053 | 1047 |
1054 } // namespace content | 1048 } // namespace content |
OLD | NEW |