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