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