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/renderer/pepper/pepper_plugin_instance_impl.h" | 5 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bit_cast.h" | 10 #include "base/bit_cast.h" |
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 container_->scrollRect(rect); | 768 container_->scrollRect(rect); |
769 } else { | 769 } else { |
770 // Can't do optimized scrolling since there could be other elements on top | 770 // Can't do optimized scrolling since there could be other elements on top |
771 // of us or the view renders via the accelerated compositor which is | 771 // of us or the view renders via the accelerated compositor which is |
772 // incompatible with the move and backfill scrolling model. | 772 // incompatible with the move and backfill scrolling model. |
773 InvalidateRect(rect); | 773 InvalidateRect(rect); |
774 } | 774 } |
775 } | 775 } |
776 } | 776 } |
777 | 777 |
778 void PepperPluginInstanceImpl::CommitBackingTexture() { | 778 void PepperPluginInstanceImpl::CommitTextureMailbox( |
| 779 const cc::TextureMailbox& texture_mailbox) { |
| 780 if (committed_texture_.IsValid() && !IsTextureInUse(committed_texture_)) { |
| 781 committed_texture_graphics_3d_->ReturnFrontBuffer( |
| 782 committed_texture_.mailbox(), committed_texture_consumed_sync_token_, |
| 783 false); |
| 784 } |
| 785 |
| 786 committed_texture_ = texture_mailbox; |
| 787 committed_texture_graphics_3d_ = bound_graphics_3d_; |
| 788 committed_texture_consumed_sync_token_ = gpu::SyncToken(); |
| 789 |
779 if (!texture_layer_) { | 790 if (!texture_layer_) { |
780 UpdateLayer(true); | 791 UpdateLayer(true); |
781 return; | 792 return; |
782 } | 793 } |
783 | 794 |
784 gpu::Mailbox mailbox; | 795 PassCommittedTextureToTextureLayer(); |
785 gpu::SyncToken sync_token; | |
786 bound_graphics_3d_->GetBackingMailbox(&mailbox, &sync_token); | |
787 DCHECK(!mailbox.IsZero()); | |
788 DCHECK(sync_token.HasData()); | |
789 texture_layer_->SetTextureMailboxWithoutReleaseCallback( | |
790 cc::TextureMailbox(mailbox, sync_token, GL_TEXTURE_2D)); | |
791 texture_layer_->SetNeedsDisplay(); | 796 texture_layer_->SetNeedsDisplay(); |
792 } | 797 } |
793 | 798 |
| 799 void PepperPluginInstanceImpl::PassCommittedTextureToTextureLayer() { |
| 800 DCHECK(bound_graphics_3d_); |
| 801 |
| 802 if (!committed_texture_.IsValid()) |
| 803 return; |
| 804 |
| 805 std::unique_ptr<cc::SingleReleaseCallback> callback( |
| 806 cc::SingleReleaseCallback::Create(base::Bind( |
| 807 &PepperPluginInstanceImpl::FinishedConsumingCommittedTexture, |
| 808 weak_factory_.GetWeakPtr(), committed_texture_, |
| 809 committed_texture_graphics_3d_))); |
| 810 |
| 811 IncrementTextureReferenceCount(committed_texture_); |
| 812 texture_layer_->SetTextureMailbox(committed_texture_, std::move(callback)); |
| 813 } |
| 814 |
| 815 void PepperPluginInstanceImpl::FinishedConsumingCommittedTexture( |
| 816 const cc::TextureMailbox& texture_mailbox, |
| 817 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d, |
| 818 const gpu::SyncToken& sync_token, |
| 819 bool is_lost) { |
| 820 bool removed = DecrementTextureReferenceCount(texture_mailbox); |
| 821 bool is_committed_texture = |
| 822 committed_texture_.mailbox() == texture_mailbox.mailbox(); |
| 823 |
| 824 if (is_committed_texture && !is_lost) { |
| 825 committed_texture_consumed_sync_token_ = sync_token; |
| 826 return; |
| 827 } |
| 828 |
| 829 if (removed && !is_committed_texture) { |
| 830 graphics_3d->ReturnFrontBuffer(texture_mailbox.mailbox(), sync_token, |
| 831 is_lost); |
| 832 } |
| 833 } |
| 834 |
794 void PepperPluginInstanceImpl::InstanceCrashed() { | 835 void PepperPluginInstanceImpl::InstanceCrashed() { |
795 // Force free all resources and vars. | 836 // Force free all resources and vars. |
796 HostGlobals::Get()->InstanceCrashed(pp_instance()); | 837 HostGlobals::Get()->InstanceCrashed(pp_instance()); |
797 | 838 |
798 // Free any associated graphics. | 839 // Free any associated graphics. |
799 SetFullscreen(false); | 840 SetFullscreen(false); |
800 FlashSetFullscreen(false, false); | 841 FlashSetFullscreen(false, false); |
801 // Unbind current 2D or 3D graphics context. | 842 // Unbind current 2D or 3D graphics context. |
802 BindGraphics(pp_instance(), 0); | 843 BindGraphics(pp_instance(), 0); |
803 InvalidateRect(gfx::Rect()); | 844 InvalidateRect(gfx::Rect()); |
(...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2004 | 2045 |
2005 NOTREACHED(); | 2046 NOTREACHED(); |
2006 #endif // ENABLE_PRINTING | 2047 #endif // ENABLE_PRINTING |
2007 return false; | 2048 return false; |
2008 } | 2049 } |
2009 | 2050 |
2010 void PepperPluginInstanceImpl::UpdateLayer(bool force_creation) { | 2051 void PepperPluginInstanceImpl::UpdateLayer(bool force_creation) { |
2011 if (!container_) | 2052 if (!container_) |
2012 return; | 2053 return; |
2013 | 2054 |
2014 gpu::Mailbox mailbox; | 2055 bool want_3d_layer = !!bound_graphics_3d_.get(); |
2015 gpu::SyncToken sync_token; | |
2016 if (bound_graphics_3d_.get()) { | |
2017 bound_graphics_3d_->GetBackingMailbox(&mailbox, &sync_token); | |
2018 } | |
2019 bool want_3d_layer = !mailbox.IsZero() && sync_token.HasData(); | |
2020 bool want_2d_layer = !!bound_graphics_2d_platform_; | 2056 bool want_2d_layer = !!bound_graphics_2d_platform_; |
2021 bool want_texture_layer = want_3d_layer || want_2d_layer; | 2057 bool want_texture_layer = want_3d_layer || want_2d_layer; |
2022 bool want_compositor_layer = !!bound_compositor_; | 2058 bool want_compositor_layer = !!bound_compositor_; |
2023 | 2059 |
2024 if (throttler_ && throttler_->IsHiddenForPlaceholder()) { | 2060 if (throttler_ && throttler_->IsHiddenForPlaceholder()) { |
2025 want_3d_layer = false; | 2061 want_3d_layer = false; |
2026 want_2d_layer = false; | 2062 want_2d_layer = false; |
2027 want_texture_layer = false; | 2063 want_texture_layer = false; |
2028 want_compositor_layer = false; | 2064 want_compositor_layer = false; |
2029 } | 2065 } |
(...skipping 18 matching lines...) Expand all Loading... |
2048 } | 2084 } |
2049 compositor_layer_ = NULL; | 2085 compositor_layer_ = NULL; |
2050 } | 2086 } |
2051 | 2087 |
2052 if (want_texture_layer) { | 2088 if (want_texture_layer) { |
2053 bool opaque = false; | 2089 bool opaque = false; |
2054 if (want_3d_layer) { | 2090 if (want_3d_layer) { |
2055 DCHECK(bound_graphics_3d_.get()); | 2091 DCHECK(bound_graphics_3d_.get()); |
2056 texture_layer_ = cc::TextureLayer::CreateForMailbox(NULL); | 2092 texture_layer_ = cc::TextureLayer::CreateForMailbox(NULL); |
2057 opaque = bound_graphics_3d_->IsOpaque(); | 2093 opaque = bound_graphics_3d_->IsOpaque(); |
2058 texture_layer_->SetTextureMailboxWithoutReleaseCallback( | 2094 |
2059 cc::TextureMailbox(mailbox, sync_token, GL_TEXTURE_2D)); | 2095 PassCommittedTextureToTextureLayer(); |
2060 } else { | 2096 } else { |
2061 DCHECK(bound_graphics_2d_platform_); | 2097 DCHECK(bound_graphics_2d_platform_); |
2062 texture_layer_ = cc::TextureLayer::CreateForMailbox(this); | 2098 texture_layer_ = cc::TextureLayer::CreateForMailbox(this); |
2063 bound_graphics_2d_platform_->AttachedToNewLayer(); | 2099 bound_graphics_2d_platform_->AttachedToNewLayer(); |
2064 opaque = bound_graphics_2d_platform_->IsAlwaysOpaque(); | 2100 opaque = bound_graphics_2d_platform_->IsAlwaysOpaque(); |
2065 texture_layer_->SetFlipped(false); | 2101 texture_layer_->SetFlipped(false); |
2066 } | 2102 } |
2067 | 2103 |
2068 // Ignore transparency in fullscreen, since that's what Flash always | 2104 // Ignore transparency in fullscreen, since that's what Flash always |
2069 // wants to do, and that lets it not recreate a context if | 2105 // wants to do, and that lets it not recreate a context if |
(...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3339 rect->size.height *= viewport_to_dip_scale_; | 3375 rect->size.height *= viewport_to_dip_scale_; |
3340 } | 3376 } |
3341 | 3377 |
3342 void PepperPluginInstanceImpl::ConvertDIPToViewport(gfx::Rect* rect) const { | 3378 void PepperPluginInstanceImpl::ConvertDIPToViewport(gfx::Rect* rect) const { |
3343 rect->set_x(rect->x() / viewport_to_dip_scale_); | 3379 rect->set_x(rect->x() / viewport_to_dip_scale_); |
3344 rect->set_y(rect->y() / viewport_to_dip_scale_); | 3380 rect->set_y(rect->y() / viewport_to_dip_scale_); |
3345 rect->set_width(rect->width() / viewport_to_dip_scale_); | 3381 rect->set_width(rect->width() / viewport_to_dip_scale_); |
3346 rect->set_height(rect->height() / viewport_to_dip_scale_); | 3382 rect->set_height(rect->height() / viewport_to_dip_scale_); |
3347 } | 3383 } |
3348 | 3384 |
| 3385 void PepperPluginInstanceImpl::IncrementTextureReferenceCount( |
| 3386 const cc::TextureMailbox& mailbox) { |
| 3387 auto it = |
| 3388 std::find_if(texture_ref_counts_.begin(), texture_ref_counts_.end(), |
| 3389 [&mailbox](const TextureMailboxRefCount& ref_count) { |
| 3390 return ref_count.first.mailbox() == mailbox.mailbox(); |
| 3391 }); |
| 3392 if (it == texture_ref_counts_.end()) { |
| 3393 texture_ref_counts_.push_back(std::make_pair(mailbox, 1)); |
| 3394 return; |
| 3395 } |
| 3396 |
| 3397 it->second++; |
| 3398 } |
| 3399 |
| 3400 bool PepperPluginInstanceImpl::DecrementTextureReferenceCount( |
| 3401 const cc::TextureMailbox& mailbox) { |
| 3402 auto it = |
| 3403 std::find_if(texture_ref_counts_.begin(), texture_ref_counts_.end(), |
| 3404 [&mailbox](const TextureMailboxRefCount& ref_count) { |
| 3405 return ref_count.first.mailbox() == mailbox.mailbox(); |
| 3406 }); |
| 3407 DCHECK(it != texture_ref_counts_.end()); |
| 3408 |
| 3409 if (it->second == 1) { |
| 3410 texture_ref_counts_.erase(it); |
| 3411 return true; |
| 3412 } |
| 3413 |
| 3414 it->second--; |
| 3415 return false; |
| 3416 } |
| 3417 |
| 3418 bool PepperPluginInstanceImpl::IsTextureInUse( |
| 3419 const cc::TextureMailbox& mailbox) const { |
| 3420 auto it = |
| 3421 std::find_if(texture_ref_counts_.begin(), texture_ref_counts_.end(), |
| 3422 [&mailbox](const TextureMailboxRefCount& ref_count) { |
| 3423 return ref_count.first.mailbox() == mailbox.mailbox(); |
| 3424 }); |
| 3425 return it != texture_ref_counts_.end(); |
| 3426 } |
| 3427 |
3349 } // namespace content | 3428 } // namespace content |
OLD | NEW |