OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "cc/resources/video_resource_updater.h" | 5 #include "cc/resources/video_resource_updater.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 VideoFrameExternalResources::VideoFrameExternalResources( | 171 VideoFrameExternalResources::VideoFrameExternalResources( |
172 const VideoFrameExternalResources& other) = default; | 172 const VideoFrameExternalResources& other) = default; |
173 | 173 |
174 VideoFrameExternalResources::~VideoFrameExternalResources() {} | 174 VideoFrameExternalResources::~VideoFrameExternalResources() {} |
175 | 175 |
176 VideoResourceUpdater::VideoResourceUpdater(ContextProvider* context_provider, | 176 VideoResourceUpdater::VideoResourceUpdater(ContextProvider* context_provider, |
177 ResourceProvider* resource_provider, | 177 ResourceProvider* resource_provider, |
178 bool use_stream_video_draw_quad) | 178 bool use_stream_video_draw_quad) |
179 : context_provider_(context_provider), | 179 : context_provider_(context_provider), |
180 resource_provider_(resource_provider), | 180 resource_provider_(resource_provider), |
181 use_stream_video_draw_quad_(use_stream_video_draw_quad) {} | 181 use_stream_video_draw_quad_(use_stream_video_draw_quad), |
| 182 weak_ptr_factory_(this) {} |
182 | 183 |
183 VideoResourceUpdater::~VideoResourceUpdater() { | 184 VideoResourceUpdater::~VideoResourceUpdater() { |
184 for (const PlaneResource& plane_resource : all_resources_) | 185 for (const PlaneResource& plane_resource : all_resources_) |
185 resource_provider_->DeleteResource(plane_resource.resource_id()); | 186 resource_provider_->DeleteResource(plane_resource.resource_id()); |
186 } | 187 } |
187 | 188 |
188 VideoResourceUpdater::ResourceList::iterator | 189 VideoResourceUpdater::ResourceList::iterator |
189 VideoResourceUpdater::RecycleOrAllocateResource( | 190 VideoResourceUpdater::RecycleOrAllocateResource( |
190 const gfx::Size& resource_size, | 191 const gfx::Size& resource_size, |
191 ResourceFormat resource_format, | 192 ResourceFormat resource_format, |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 resource_provider_->CopyToResource(plane_resource.resource_id(), | 415 resource_provider_->CopyToResource(plane_resource.resource_id(), |
415 &upload_pixels_[0], | 416 &upload_pixels_[0], |
416 plane_resource.resource_size()); | 417 plane_resource.resource_size()); |
417 } | 418 } |
418 plane_resource.SetUniqueId(video_frame->unique_id(), 0); | 419 plane_resource.SetUniqueId(video_frame->unique_id(), 0); |
419 } | 420 } |
420 | 421 |
421 if (software_compositor) { | 422 if (software_compositor) { |
422 external_resources.software_resources.push_back( | 423 external_resources.software_resources.push_back( |
423 plane_resource.resource_id()); | 424 plane_resource.resource_id()); |
424 external_resources.software_release_callback = base::Bind( | 425 external_resources.software_release_callback = |
425 &RecycleResource, AsWeakPtr(), plane_resource.resource_id()); | 426 base::Bind(&RecycleResource, weak_ptr_factory_.GetWeakPtr(), |
| 427 plane_resource.resource_id()); |
426 external_resources.type = VideoFrameExternalResources::SOFTWARE_RESOURCE; | 428 external_resources.type = VideoFrameExternalResources::SOFTWARE_RESOURCE; |
427 } else { | 429 } else { |
428 // VideoResourceUpdater shares a context with the compositor so | 430 // VideoResourceUpdater shares a context with the compositor so |
429 // a sync token is not required. | 431 // a sync token is not required. |
430 TextureMailbox mailbox(plane_resource.mailbox(), gpu::SyncToken(), | 432 TextureMailbox mailbox(plane_resource.mailbox(), gpu::SyncToken(), |
431 resource_provider_->GetResourceTextureTarget( | 433 resource_provider_->GetResourceTextureTarget( |
432 plane_resource.resource_id())); | 434 plane_resource.resource_id())); |
433 mailbox.set_color_space(output_color_space); | 435 mailbox.set_color_space(output_color_space); |
434 external_resources.mailboxes.push_back(mailbox); | 436 external_resources.mailboxes.push_back(mailbox); |
435 external_resources.release_callbacks.push_back(base::Bind( | 437 external_resources.release_callbacks.push_back( |
436 &RecycleResource, AsWeakPtr(), plane_resource.resource_id())); | 438 base::Bind(&RecycleResource, weak_ptr_factory_.GetWeakPtr(), |
| 439 plane_resource.resource_id())); |
437 external_resources.type = VideoFrameExternalResources::RGBA_RESOURCE; | 440 external_resources.type = VideoFrameExternalResources::RGBA_RESOURCE; |
438 } | 441 } |
439 return external_resources; | 442 return external_resources; |
440 } | 443 } |
441 | 444 |
442 std::unique_ptr<media::HalfFloatMaker> half_float_maker; | 445 std::unique_ptr<media::HalfFloatMaker> half_float_maker; |
443 if (resource_provider_->YuvResourceFormat(bits_per_channel) == | 446 if (resource_provider_->YuvResourceFormat(bits_per_channel) == |
444 LUMINANCE_F16) { | 447 LUMINANCE_F16) { |
445 half_float_maker = | 448 half_float_maker = |
446 media::HalfFloatMaker::NewHalfFloatMaker(bits_per_channel); | 449 media::HalfFloatMaker::NewHalfFloatMaker(bits_per_channel); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 plane_resource.SetUniqueId(video_frame->unique_id(), i); | 531 plane_resource.SetUniqueId(video_frame->unique_id(), i); |
529 } | 532 } |
530 | 533 |
531 // VideoResourceUpdater shares a context with the compositor so a | 534 // VideoResourceUpdater shares a context with the compositor so a |
532 // sync token is not required. | 535 // sync token is not required. |
533 TextureMailbox mailbox(plane_resource.mailbox(), gpu::SyncToken(), | 536 TextureMailbox mailbox(plane_resource.mailbox(), gpu::SyncToken(), |
534 resource_provider_->GetResourceTextureTarget( | 537 resource_provider_->GetResourceTextureTarget( |
535 plane_resource.resource_id())); | 538 plane_resource.resource_id())); |
536 mailbox.set_color_space(output_color_space); | 539 mailbox.set_color_space(output_color_space); |
537 external_resources.mailboxes.push_back(mailbox); | 540 external_resources.mailboxes.push_back(mailbox); |
538 external_resources.release_callbacks.push_back(base::Bind( | 541 external_resources.release_callbacks.push_back( |
539 &RecycleResource, AsWeakPtr(), plane_resource.resource_id())); | 542 base::Bind(&RecycleResource, weak_ptr_factory_.GetWeakPtr(), |
| 543 plane_resource.resource_id())); |
540 } | 544 } |
541 | 545 |
542 external_resources.type = VideoFrameExternalResources::YUV_RESOURCE; | 546 external_resources.type = VideoFrameExternalResources::YUV_RESOURCE; |
543 return external_resources; | 547 return external_resources; |
544 } | 548 } |
545 | 549 |
546 // static | 550 // static |
547 void VideoResourceUpdater::ReturnTexture( | 551 void VideoResourceUpdater::ReturnTexture( |
548 base::WeakPtr<VideoResourceUpdater> updater, | 552 base::WeakPtr<VideoResourceUpdater> updater, |
549 const scoped_refptr<media::VideoFrame>& video_frame, | 553 const scoped_refptr<media::VideoFrame>& video_frame, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 video_frame->UpdateReleaseSyncToken(&client); | 609 video_frame->UpdateReleaseSyncToken(&client); |
606 | 610 |
607 // VideoResourceUpdater shares a context with the compositor so a | 611 // VideoResourceUpdater shares a context with the compositor so a |
608 // sync token is not required. | 612 // sync token is not required. |
609 TextureMailbox mailbox(resource->mailbox(), gpu::SyncToken(), GL_TEXTURE_2D, | 613 TextureMailbox mailbox(resource->mailbox(), gpu::SyncToken(), GL_TEXTURE_2D, |
610 video_frame->coded_size(), false, false); | 614 video_frame->coded_size(), false, false); |
611 mailbox.set_color_space(resource_color_space); | 615 mailbox.set_color_space(resource_color_space); |
612 external_resources->mailboxes.push_back(mailbox); | 616 external_resources->mailboxes.push_back(mailbox); |
613 | 617 |
614 external_resources->release_callbacks.push_back( | 618 external_resources->release_callbacks.push_back( |
615 base::Bind(&RecycleResource, AsWeakPtr(), resource->resource_id())); | 619 base::Bind(&RecycleResource, weak_ptr_factory_.GetWeakPtr(), |
| 620 resource->resource_id())); |
616 } | 621 } |
617 | 622 |
618 VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( | 623 VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( |
619 scoped_refptr<media::VideoFrame> video_frame) { | 624 scoped_refptr<media::VideoFrame> video_frame) { |
620 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForHardwarePlanes"); | 625 TRACE_EVENT0("cc", "VideoResourceUpdater::CreateForHardwarePlanes"); |
621 DCHECK(video_frame->HasTextures()); | 626 DCHECK(video_frame->HasTextures()); |
622 if (!context_provider_) | 627 if (!context_provider_) |
623 return VideoFrameExternalResources(); | 628 return VideoFrameExternalResources(); |
624 | 629 |
625 VideoFrameExternalResources external_resources; | 630 VideoFrameExternalResources external_resources; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 media::VideoFrameMetadata::ALLOW_OVERLAY), | 662 media::VideoFrameMetadata::ALLOW_OVERLAY), |
658 false); | 663 false); |
659 mailbox.set_color_space(resource_color_space); | 664 mailbox.set_color_space(resource_color_space); |
660 #if defined(OS_ANDROID) | 665 #if defined(OS_ANDROID) |
661 mailbox.set_is_backed_by_surface_texture(video_frame->metadata()->IsTrue( | 666 mailbox.set_is_backed_by_surface_texture(video_frame->metadata()->IsTrue( |
662 media::VideoFrameMetadata::SURFACE_TEXTURE)); | 667 media::VideoFrameMetadata::SURFACE_TEXTURE)); |
663 mailbox.set_wants_promotion_hint(video_frame->metadata()->IsTrue( | 668 mailbox.set_wants_promotion_hint(video_frame->metadata()->IsTrue( |
664 media::VideoFrameMetadata::WANTS_PROMOTION_HINT)); | 669 media::VideoFrameMetadata::WANTS_PROMOTION_HINT)); |
665 #endif | 670 #endif |
666 external_resources.mailboxes.push_back(mailbox); | 671 external_resources.mailboxes.push_back(mailbox); |
667 external_resources.release_callbacks.push_back( | 672 external_resources.release_callbacks.push_back(base::Bind( |
668 base::Bind(&ReturnTexture, AsWeakPtr(), video_frame)); | 673 &ReturnTexture, weak_ptr_factory_.GetWeakPtr(), video_frame)); |
669 } | 674 } |
670 } | 675 } |
671 return external_resources; | 676 return external_resources; |
672 } | 677 } |
673 | 678 |
674 // static | 679 // static |
675 void VideoResourceUpdater::RecycleResource( | 680 void VideoResourceUpdater::RecycleResource( |
676 base::WeakPtr<VideoResourceUpdater> updater, | 681 base::WeakPtr<VideoResourceUpdater> updater, |
677 ResourceId resource_id, | 682 ResourceId resource_id, |
678 const gpu::SyncToken& sync_token, | 683 const gpu::SyncToken& sync_token, |
(...skipping 20 matching lines...) Expand all Loading... |
699 if (lost_resource) { | 704 if (lost_resource) { |
700 resource_it->clear_refs(); | 705 resource_it->clear_refs(); |
701 updater->DeleteResource(resource_it); | 706 updater->DeleteResource(resource_it); |
702 return; | 707 return; |
703 } | 708 } |
704 | 709 |
705 resource_it->remove_ref(); | 710 resource_it->remove_ref(); |
706 } | 711 } |
707 | 712 |
708 } // namespace cc | 713 } // namespace cc |
OLD | NEW |