diff options
author | kbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-23 21:05:52 +0000 |
---|---|---|
committer | kbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-23 21:05:52 +0000 |
commit | 722ed48734460567be2c97590a036480c4667815 (patch) | |
tree | c95d74142f98742f76eec5fd077ca2e36c467808 | |
parent | 3921d1954d9dfe490d179fe2c750bcab4980d533 (diff) | |
download | chromium_src-722ed48734460567be2c97590a036480c4667815.zip chromium_src-722ed48734460567be2c97590a036480c4667815.tar.gz chromium_src-722ed48734460567be2c97590a036480c4667815.tar.bz2 |
Fixed missing code in EnqueueTextureForDeletion.
BUG=38945
TEST=reloaded Pepper 3D plugins repeatedly
NOTE: encountered unrelated problems while testing. These changes
should be stress tested with CA plugins.
Review URL: http://codereview.chromium.org/1110011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42380 0039d316-1c4b-4281-b951-d872f2087c98
3 files changed, 48 insertions, 29 deletions
diff --git a/chrome/browser/renderer_host/accelerated_surface_container_mac.cc b/chrome/browser/renderer_host/accelerated_surface_container_mac.cc index f77ad3d..3d1972f 100644 --- a/chrome/browser/renderer_host/accelerated_surface_container_mac.cc +++ b/chrome/browser/renderer_host/accelerated_surface_container_mac.cc @@ -9,8 +9,10 @@ #include "webkit/glue/webplugin.h" #include "chrome/browser/renderer_host/accelerated_surface_container_manager_mac.h" -AcceleratedSurfaceContainerMac::AcceleratedSurfaceContainerMac() - : x_(0), +AcceleratedSurfaceContainerMac::AcceleratedSurfaceContainerMac( + AcceleratedSurfaceContainerManagerMac* manager) + : manager_(manager), + x_(0), y_(0), surface_(NULL), width_(0), @@ -20,6 +22,7 @@ AcceleratedSurfaceContainerMac::AcceleratedSurfaceContainerMac() } AcceleratedSurfaceContainerMac::~AcceleratedSurfaceContainerMac() { + EnqueueTextureForDeletion(); ReleaseIOSurface(); } @@ -33,14 +36,13 @@ void AcceleratedSurfaceContainerMac::ReleaseIOSurface() { void AcceleratedSurfaceContainerMac::SetSizeAndIOSurface( int32 width, int32 height, - uint64 io_surface_identifier, - AcceleratedSurfaceContainerManagerMac* manager) { + uint64 io_surface_identifier) { ReleaseIOSurface(); IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); if (io_surface_support) { surface_ = io_surface_support->IOSurfaceLookup( static_cast<uint32>(io_surface_identifier)); - EnqueueTextureForDeletion(manager); + EnqueueTextureForDeletion(); width_ = width; height_ = height; } @@ -49,11 +51,10 @@ void AcceleratedSurfaceContainerMac::SetSizeAndIOSurface( void AcceleratedSurfaceContainerMac::SetSizeAndTransportDIB( int32 width, int32 height, - TransportDIB::Handle transport_dib, - AcceleratedSurfaceContainerManagerMac* manager) { + TransportDIB::Handle transport_dib) { if (TransportDIB::is_valid(transport_dib)) { transport_dib_.reset(TransportDIB::Map(transport_dib)); - EnqueueTextureForDeletion(manager); + EnqueueTextureForDeletion(); width_ = width; height_ = height; } @@ -154,9 +155,10 @@ void AcceleratedSurfaceContainerMac::Draw(CGLContextObj context) { } } -void AcceleratedSurfaceContainerMac::EnqueueTextureForDeletion( - AcceleratedSurfaceContainerManagerMac* manager) { - manager->EnqueueTextureForDeletion(texture_); - texture_ = 0; +void AcceleratedSurfaceContainerMac::EnqueueTextureForDeletion() { + if (texture_) { + manager_->EnqueueTextureForDeletion(texture_); + texture_ = 0; + } } diff --git a/chrome/browser/renderer_host/accelerated_surface_container_mac.h b/chrome/browser/renderer_host/accelerated_surface_container_mac.h index 1778ea9..26f0e30 100644 --- a/chrome/browser/renderer_host/accelerated_surface_container_mac.h +++ b/chrome/browser/renderer_host/accelerated_surface_container_mac.h @@ -42,7 +42,8 @@ class AcceleratedSurfaceContainerManagerMac; class AcceleratedSurfaceContainerMac { public: - AcceleratedSurfaceContainerMac(); + AcceleratedSurfaceContainerMac( + AcceleratedSurfaceContainerManagerMac* manager); virtual ~AcceleratedSurfaceContainerMac(); // Sets the backing store and size of this accelerated surface container. @@ -51,12 +52,10 @@ class AcceleratedSurfaceContainerMac { // used on Mac OS X 10.5 and earlier. void SetSizeAndIOSurface(int32 width, int32 height, - uint64 io_surface_identifier, - AcceleratedSurfaceContainerManagerMac* manager); + uint64 io_surface_identifier); void SetSizeAndTransportDIB(int32 width, int32 height, - TransportDIB::Handle transport_dib, - AcceleratedSurfaceContainerManagerMac* manager); + TransportDIB::Handle transport_dib); // Tells the accelerated surface container that it has moved relative to the // origin of the window, for example because of a scroll event. @@ -71,18 +70,14 @@ class AcceleratedSurfaceContainerMac { // time the drawing context has changed. void ForceTextureReload() { texture_needs_upload_ = true; } - // Enqueue our texture for later deletion. Call this before deleting - // this object. - void EnqueueTextureForDeletion( - AcceleratedSurfaceContainerManagerMac* manager); - private: + // The manager of this accelerated surface container. + AcceleratedSurfaceContainerManagerMac* manager_; + // The x and y coordinates of the plugin window on the web page. int x_; int y_; - void ReleaseIOSurface(); - // The IOSurfaceRef, if any, that has been handed from the GPU // plugin process back to the browser process for drawing. // This is held as a CFTypeRef because we can't refer to the @@ -111,6 +106,12 @@ class AcceleratedSurfaceContainerMac { // True if we need to upload the texture again during the next draw. bool texture_needs_upload_; + // Releases the IOSurface reference, if any, retained by this object. + void ReleaseIOSurface(); + + // Enqueue our texture for later deletion. + void EnqueueTextureForDeletion(); + DISALLOW_COPY_AND_ASSIGN(AcceleratedSurfaceContainerMac); }; diff --git a/chrome/browser/renderer_host/accelerated_surface_container_manager_mac.cc b/chrome/browser/renderer_host/accelerated_surface_container_manager_mac.cc index 2afbb0f..88275b0 100644 --- a/chrome/browser/renderer_host/accelerated_surface_container_manager_mac.cc +++ b/chrome/browser/renderer_host/accelerated_surface_container_manager_mac.cc @@ -15,7 +15,7 @@ AcceleratedSurfaceContainerManagerMac::AcceleratedSurfaceContainerManagerMac() gfx::PluginWindowHandle AcceleratedSurfaceContainerManagerMac::AllocateFakePluginWindowHandle() { AcceleratedSurfaceContainerMac* container = - new AcceleratedSurfaceContainerMac(); + new AcceleratedSurfaceContainerMac(this); gfx::PluginWindowHandle res = static_cast<gfx::PluginWindowHandle>(++current_id_); plugin_window_to_container_map_.insert(std::make_pair(res, container)); @@ -37,8 +37,7 @@ void AcceleratedSurfaceContainerManagerMac::SetSizeAndIOSurface( uint64 io_surface_identifier) { AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); if (container) - container->SetSizeAndIOSurface(width, height, - io_surface_identifier, this); + container->SetSizeAndIOSurface(width, height, io_surface_identifier); } void AcceleratedSurfaceContainerManagerMac::SetSizeAndTransportDIB( @@ -48,8 +47,7 @@ void AcceleratedSurfaceContainerManagerMac::SetSizeAndTransportDIB( TransportDIB::Handle transport_dib) { AcceleratedSurfaceContainerMac* container = MapIDToContainer(id); if (container) - container->SetSizeAndTransportDIB(width, height, - transport_dib, this); + container->SetSizeAndTransportDIB(width, height, transport_dib); } void AcceleratedSurfaceContainerManagerMac::MovePluginContainer( @@ -60,6 +58,24 @@ void AcceleratedSurfaceContainerManagerMac::MovePluginContainer( } void AcceleratedSurfaceContainerManagerMac::Draw(CGLContextObj context) { + // Clean up old texture objects. This is essentially a pre-emptive + // cleanup, as the resources will be released when the OpenGL + // context associated with the CAOpenGLLayer is destroyed. However, + // if we render many plugins in the same layer, we should try to + // eagerly reclaim their resources. Note also that the OpenGL + // context must be current when performing the deletion, and it + // seems risky to make the OpenGL context current at an arbitrary + // point in time, which is why the deletion does not occur in the + // container's destructor. + for (std::vector<GLuint>::iterator iter = + textures_pending_deletion_.begin(); + iter != textures_pending_deletion_.end(); + ++iter) { + GLuint texture = *iter; + glDeleteTextures(1, &texture); + } + textures_pending_deletion_.clear(); + glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |