Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1328)

Side by Side Diff: content/renderer/pepper/pepper_plugin_instance_impl.cc

Issue 2012303002: [Merge to 2743] Revert "[Reland 2] Pepper takes ownership of a mailbox before passing it to the tex… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 738 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 container_->scrollRect(rect); 749 container_->scrollRect(rect);
750 } else { 750 } else {
751 // Can't do optimized scrolling since there could be other elements on top 751 // Can't do optimized scrolling since there could be other elements on top
752 // of us or the view renders via the accelerated compositor which is 752 // of us or the view renders via the accelerated compositor which is
753 // incompatible with the move and backfill scrolling model. 753 // incompatible with the move and backfill scrolling model.
754 InvalidateRect(rect); 754 InvalidateRect(rect);
755 } 755 }
756 } 756 }
757 } 757 }
758 758
759 void PepperPluginInstanceImpl::CommitTextureMailbox( 759 void PepperPluginInstanceImpl::CommitBackingTexture() {
760 const cc::TextureMailbox& texture_mailbox) {
761 if (committed_texture_.IsValid() && !IsTextureInUse(committed_texture_)) {
762 committed_texture_graphics_3d_->ReturnFrontBuffer(
763 committed_texture_.mailbox(), committed_texture_consumed_sync_token_,
764 false);
765 }
766
767 committed_texture_ = texture_mailbox;
768 committed_texture_graphics_3d_ = bound_graphics_3d_;
769 committed_texture_consumed_sync_token_ = gpu::SyncToken();
770
771 if (!texture_layer_) { 760 if (!texture_layer_) {
772 UpdateLayer(true); 761 UpdateLayer(true);
773 return; 762 return;
774 } 763 }
775 764
776 PassCommittedTextureToTextureLayer(); 765 gpu::Mailbox mailbox;
766 gpu::SyncToken sync_token;
767 bound_graphics_3d_->GetBackingMailbox(&mailbox, &sync_token);
768 DCHECK(!mailbox.IsZero());
769 DCHECK(sync_token.HasData());
770 texture_layer_->SetTextureMailboxWithoutReleaseCallback(
771 cc::TextureMailbox(mailbox, sync_token, GL_TEXTURE_2D));
777 texture_layer_->SetNeedsDisplay(); 772 texture_layer_->SetNeedsDisplay();
778 } 773 }
779 774
780 void PepperPluginInstanceImpl::PassCommittedTextureToTextureLayer() {
781 DCHECK(bound_graphics_3d_);
782
783 if (!committed_texture_.IsValid())
784 return;
785
786 std::unique_ptr<cc::SingleReleaseCallback> callback(
787 cc::SingleReleaseCallback::Create(base::Bind(
788 &PepperPluginInstanceImpl::FinishedConsumingCommittedTexture,
789 weak_factory_.GetWeakPtr(), committed_texture_,
790 committed_texture_graphics_3d_)));
791
792 IncrementTextureReferenceCount(committed_texture_);
793 texture_layer_->SetTextureMailbox(committed_texture_, std::move(callback));
794 }
795
796 void PepperPluginInstanceImpl::FinishedConsumingCommittedTexture(
797 const cc::TextureMailbox& texture_mailbox,
798 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d,
799 const gpu::SyncToken& sync_token,
800 bool is_lost) {
801 bool removed = DecrementTextureReferenceCount(texture_mailbox);
802 bool is_committed_texture =
803 committed_texture_.mailbox() == texture_mailbox.mailbox();
804
805 if (is_committed_texture && !is_lost) {
806 committed_texture_consumed_sync_token_ = sync_token;
807 return;
808 }
809
810 if (removed && !is_committed_texture) {
811 graphics_3d->ReturnFrontBuffer(texture_mailbox.mailbox(), sync_token,
812 is_lost);
813 }
814 }
815
816 void PepperPluginInstanceImpl::InstanceCrashed() { 775 void PepperPluginInstanceImpl::InstanceCrashed() {
817 // Force free all resources and vars. 776 // Force free all resources and vars.
818 HostGlobals::Get()->InstanceCrashed(pp_instance()); 777 HostGlobals::Get()->InstanceCrashed(pp_instance());
819 778
820 // Free any associated graphics. 779 // Free any associated graphics.
821 SetFullscreen(false); 780 SetFullscreen(false);
822 FlashSetFullscreen(false, false); 781 FlashSetFullscreen(false, false);
823 // Unbind current 2D or 3D graphics context. 782 // Unbind current 2D or 3D graphics context.
824 BindGraphics(pp_instance(), 0); 783 BindGraphics(pp_instance(), 0);
825 InvalidateRect(gfx::Rect()); 784 InvalidateRect(gfx::Rect());
(...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after
2034 1993
2035 NOTREACHED(); 1994 NOTREACHED();
2036 #endif // ENABLE_PRINTING 1995 #endif // ENABLE_PRINTING
2037 return false; 1996 return false;
2038 } 1997 }
2039 1998
2040 void PepperPluginInstanceImpl::UpdateLayer(bool force_creation) { 1999 void PepperPluginInstanceImpl::UpdateLayer(bool force_creation) {
2041 if (!container_) 2000 if (!container_)
2042 return; 2001 return;
2043 2002
2044 bool want_3d_layer = !!bound_graphics_3d_.get(); 2003 gpu::Mailbox mailbox;
2004 gpu::SyncToken sync_token;
2005 if (bound_graphics_3d_.get()) {
2006 bound_graphics_3d_->GetBackingMailbox(&mailbox, &sync_token);
2007 }
2008 bool want_3d_layer = !mailbox.IsZero() && sync_token.HasData();
2045 bool want_2d_layer = !!bound_graphics_2d_platform_; 2009 bool want_2d_layer = !!bound_graphics_2d_platform_;
2046 bool want_texture_layer = want_3d_layer || want_2d_layer; 2010 bool want_texture_layer = want_3d_layer || want_2d_layer;
2047 bool want_compositor_layer = !!bound_compositor_; 2011 bool want_compositor_layer = !!bound_compositor_;
2048 2012
2049 if (throttler_ && throttler_->IsHiddenForPlaceholder()) { 2013 if (throttler_ && throttler_->IsHiddenForPlaceholder()) {
2050 want_3d_layer = false; 2014 want_3d_layer = false;
2051 want_2d_layer = false; 2015 want_2d_layer = false;
2052 want_texture_layer = false; 2016 want_texture_layer = false;
2053 want_compositor_layer = false; 2017 want_compositor_layer = false;
2054 } 2018 }
(...skipping 18 matching lines...) Expand all
2073 } 2037 }
2074 compositor_layer_ = NULL; 2038 compositor_layer_ = NULL;
2075 } 2039 }
2076 2040
2077 if (want_texture_layer) { 2041 if (want_texture_layer) {
2078 bool opaque = false; 2042 bool opaque = false;
2079 if (want_3d_layer) { 2043 if (want_3d_layer) {
2080 DCHECK(bound_graphics_3d_.get()); 2044 DCHECK(bound_graphics_3d_.get());
2081 texture_layer_ = cc::TextureLayer::CreateForMailbox(NULL); 2045 texture_layer_ = cc::TextureLayer::CreateForMailbox(NULL);
2082 opaque = bound_graphics_3d_->IsOpaque(); 2046 opaque = bound_graphics_3d_->IsOpaque();
2083 2047 texture_layer_->SetTextureMailboxWithoutReleaseCallback(
2084 PassCommittedTextureToTextureLayer(); 2048 cc::TextureMailbox(mailbox, sync_token, GL_TEXTURE_2D));
2085 } else { 2049 } else {
2086 DCHECK(bound_graphics_2d_platform_); 2050 DCHECK(bound_graphics_2d_platform_);
2087 texture_layer_ = cc::TextureLayer::CreateForMailbox(this); 2051 texture_layer_ = cc::TextureLayer::CreateForMailbox(this);
2088 bound_graphics_2d_platform_->AttachedToNewLayer(); 2052 bound_graphics_2d_platform_->AttachedToNewLayer();
2089 opaque = bound_graphics_2d_platform_->IsAlwaysOpaque(); 2053 opaque = bound_graphics_2d_platform_->IsAlwaysOpaque();
2090 texture_layer_->SetFlipped(false); 2054 texture_layer_->SetFlipped(false);
2091 } 2055 }
2092 2056
2093 // Ignore transparency in fullscreen, since that's what Flash always 2057 // Ignore transparency in fullscreen, since that's what Flash always
2094 // wants to do, and that lets it not recreate a context if 2058 // wants to do, and that lets it not recreate a context if
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after
3366 rect->size.height *= viewport_to_dip_scale_; 3330 rect->size.height *= viewport_to_dip_scale_;
3367 } 3331 }
3368 3332
3369 void PepperPluginInstanceImpl::ConvertDIPToViewport(gfx::Rect* rect) const { 3333 void PepperPluginInstanceImpl::ConvertDIPToViewport(gfx::Rect* rect) const {
3370 rect->set_x(rect->x() / viewport_to_dip_scale_); 3334 rect->set_x(rect->x() / viewport_to_dip_scale_);
3371 rect->set_y(rect->y() / viewport_to_dip_scale_); 3335 rect->set_y(rect->y() / viewport_to_dip_scale_);
3372 rect->set_width(rect->width() / viewport_to_dip_scale_); 3336 rect->set_width(rect->width() / viewport_to_dip_scale_);
3373 rect->set_height(rect->height() / viewport_to_dip_scale_); 3337 rect->set_height(rect->height() / viewport_to_dip_scale_);
3374 } 3338 }
3375 3339
3376 void PepperPluginInstanceImpl::IncrementTextureReferenceCount(
3377 const cc::TextureMailbox& mailbox) {
3378 auto it =
3379 std::find_if(texture_ref_counts_.begin(), texture_ref_counts_.end(),
3380 [&mailbox](const TextureMailboxRefCount& ref_count) {
3381 return ref_count.first.mailbox() == mailbox.mailbox();
3382 });
3383 if (it == texture_ref_counts_.end()) {
3384 texture_ref_counts_.push_back(std::make_pair(mailbox, 1));
3385 return;
3386 }
3387
3388 it->second++;
3389 }
3390
3391 bool PepperPluginInstanceImpl::DecrementTextureReferenceCount(
3392 const cc::TextureMailbox& mailbox) {
3393 auto it =
3394 std::find_if(texture_ref_counts_.begin(), texture_ref_counts_.end(),
3395 [&mailbox](const TextureMailboxRefCount& ref_count) {
3396 return ref_count.first.mailbox() == mailbox.mailbox();
3397 });
3398 DCHECK(it != texture_ref_counts_.end());
3399
3400 if (it->second == 1) {
3401 texture_ref_counts_.erase(it);
3402 return true;
3403 }
3404
3405 it->second--;
3406 return false;
3407 }
3408
3409 bool PepperPluginInstanceImpl::IsTextureInUse(
3410 const cc::TextureMailbox& mailbox) const {
3411 auto it =
3412 std::find_if(texture_ref_counts_.begin(), texture_ref_counts_.end(),
3413 [&mailbox](const TextureMailboxRefCount& ref_count) {
3414 return ref_count.first.mailbox() == mailbox.mailbox();
3415 });
3416 return it != texture_ref_counts_.end();
3417 }
3418
3419 } // namespace content 3340 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_plugin_instance_impl.h ('k') | content/renderer/pepper/ppb_graphics_3d_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698