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::CommitBackingTexture() { | 784 void PepperPluginInstanceImpl::CommitTextureMailbox( |
| 785 const cc::TextureMailbox& texture_mailbox) { |
| 786 if (committed_texture_.IsValid() && !committed_texture_in_use_) { |
| 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_in_use_ = false; |
| 794 |
785 if (!texture_layer_) { | 795 if (!texture_layer_) { |
786 UpdateLayer(true); | 796 UpdateLayer(true); |
787 return; | 797 return; |
788 } | 798 } |
789 | 799 |
790 gpu::Mailbox mailbox; | 800 PassCommittedTextureToTextureLayer(); |
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)); | |
797 texture_layer_->SetNeedsDisplay(); | 801 texture_layer_->SetNeedsDisplay(); |
798 } | 802 } |
799 | 803 |
| 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 committed_texture_in_use_ = true; |
| 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 if (committed_texture_.mailbox() == texture_mailbox.mailbox() && !is_lost) { |
| 824 committed_texture_in_use_ = false; |
| 825 committed_texture_consumed_sync_token_ = sync_token; |
| 826 return; |
| 827 } |
| 828 |
| 829 bound_graphics_3d_->ReturnFrontBuffer(texture_mailbox.mailbox(), sync_token, |
| 830 is_lost); |
| 831 } |
| 832 |
800 void PepperPluginInstanceImpl::InstanceCrashed() { | 833 void PepperPluginInstanceImpl::InstanceCrashed() { |
801 // Force free all resources and vars. | 834 // Force free all resources and vars. |
802 HostGlobals::Get()->InstanceCrashed(pp_instance()); | 835 HostGlobals::Get()->InstanceCrashed(pp_instance()); |
803 | 836 |
804 // Free any associated graphics. | 837 // Free any associated graphics. |
805 SetFullscreen(false); | 838 SetFullscreen(false); |
806 FlashSetFullscreen(false, false); | 839 FlashSetFullscreen(false, false); |
807 // Unbind current 2D or 3D graphics context. | 840 // Unbind current 2D or 3D graphics context. |
808 BindGraphics(pp_instance(), 0); | 841 BindGraphics(pp_instance(), 0); |
809 InvalidateRect(gfx::Rect()); | 842 InvalidateRect(gfx::Rect()); |
(...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2010 | 2043 |
2011 NOTREACHED(); | 2044 NOTREACHED(); |
2012 #endif // ENABLE_PRINTING | 2045 #endif // ENABLE_PRINTING |
2013 return false; | 2046 return false; |
2014 } | 2047 } |
2015 | 2048 |
2016 void PepperPluginInstanceImpl::UpdateLayer(bool force_creation) { | 2049 void PepperPluginInstanceImpl::UpdateLayer(bool force_creation) { |
2017 if (!container_) | 2050 if (!container_) |
2018 return; | 2051 return; |
2019 | 2052 |
2020 gpu::Mailbox mailbox; | 2053 bool want_3d_layer = !!bound_graphics_3d_.get(); |
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(); | |
2026 bool want_2d_layer = !!bound_graphics_2d_platform_; | 2054 bool want_2d_layer = !!bound_graphics_2d_platform_; |
2027 bool want_texture_layer = want_3d_layer || want_2d_layer; | 2055 bool want_texture_layer = want_3d_layer || want_2d_layer; |
2028 bool want_compositor_layer = !!bound_compositor_; | 2056 bool want_compositor_layer = !!bound_compositor_; |
2029 | 2057 |
2030 if (throttler_ && throttler_->IsHiddenForPlaceholder()) { | 2058 if (throttler_ && throttler_->IsHiddenForPlaceholder()) { |
2031 want_3d_layer = false; | 2059 want_3d_layer = false; |
2032 want_2d_layer = false; | 2060 want_2d_layer = false; |
2033 want_texture_layer = false; | 2061 want_texture_layer = false; |
2034 want_compositor_layer = false; | 2062 want_compositor_layer = false; |
2035 } | 2063 } |
(...skipping 18 matching lines...) Expand all Loading... |
2054 } | 2082 } |
2055 compositor_layer_ = NULL; | 2083 compositor_layer_ = NULL; |
2056 } | 2084 } |
2057 | 2085 |
2058 if (want_texture_layer) { | 2086 if (want_texture_layer) { |
2059 bool opaque = false; | 2087 bool opaque = false; |
2060 if (want_3d_layer) { | 2088 if (want_3d_layer) { |
2061 DCHECK(bound_graphics_3d_.get()); | 2089 DCHECK(bound_graphics_3d_.get()); |
2062 texture_layer_ = cc::TextureLayer::CreateForMailbox(NULL); | 2090 texture_layer_ = cc::TextureLayer::CreateForMailbox(NULL); |
2063 opaque = bound_graphics_3d_->IsOpaque(); | 2091 opaque = bound_graphics_3d_->IsOpaque(); |
2064 texture_layer_->SetTextureMailboxWithoutReleaseCallback( | 2092 |
2065 cc::TextureMailbox(mailbox, sync_token, GL_TEXTURE_2D)); | 2093 PassCommittedTextureToTextureLayer(); |
2066 } else { | 2094 } else { |
2067 DCHECK(bound_graphics_2d_platform_); | 2095 DCHECK(bound_graphics_2d_platform_); |
2068 texture_layer_ = cc::TextureLayer::CreateForMailbox(this); | 2096 texture_layer_ = cc::TextureLayer::CreateForMailbox(this); |
2069 bound_graphics_2d_platform_->AttachedToNewLayer(); | 2097 bound_graphics_2d_platform_->AttachedToNewLayer(); |
2070 opaque = bound_graphics_2d_platform_->IsAlwaysOpaque(); | 2098 opaque = bound_graphics_2d_platform_->IsAlwaysOpaque(); |
2071 texture_layer_->SetFlipped(false); | 2099 texture_layer_->SetFlipped(false); |
2072 } | 2100 } |
2073 | 2101 |
2074 // Ignore transparency in fullscreen, since that's what Flash always | 2102 // Ignore transparency in fullscreen, since that's what Flash always |
2075 // wants to do, and that lets it not recreate a context if | 2103 // wants to do, and that lets it not recreate a context if |
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3347 } | 3375 } |
3348 | 3376 |
3349 void PepperPluginInstanceImpl::ConvertDIPToViewport(gfx::Rect* rect) const { | 3377 void PepperPluginInstanceImpl::ConvertDIPToViewport(gfx::Rect* rect) const { |
3350 rect->set_x(rect->x() / viewport_to_dip_scale_); | 3378 rect->set_x(rect->x() / viewport_to_dip_scale_); |
3351 rect->set_y(rect->y() / viewport_to_dip_scale_); | 3379 rect->set_y(rect->y() / viewport_to_dip_scale_); |
3352 rect->set_width(rect->width() / viewport_to_dip_scale_); | 3380 rect->set_width(rect->width() / viewport_to_dip_scale_); |
3353 rect->set_height(rect->height() / viewport_to_dip_scale_); | 3381 rect->set_height(rect->height() / viewport_to_dip_scale_); |
3354 } | 3382 } |
3355 | 3383 |
3356 } // namespace content | 3384 } // namespace content |
OLD | NEW |