Index: content/common/gpu/image_transport_surface_mac.cc |
diff --git a/content/common/gpu/image_transport_surface_mac.cc b/content/common/gpu/image_transport_surface_mac.cc |
index c6511046901ff3f949b1168f058c10dd8d717a5f..1a09be004771b726ebc1b812e3c71068727825cd 100644 |
--- a/content/common/gpu/image_transport_surface_mac.cc |
+++ b/content/common/gpu/image_transport_surface_mac.cc |
@@ -6,6 +6,7 @@ |
#include "base/mac/scoped_cftyperef.h" |
#include "base/memory/scoped_ptr.h" |
+#include "content/common/gpu/gpu_command_buffer_stub.h" |
#include "content/common/gpu/gpu_messages.h" |
#include "ui/gfx/native_widget_types.h" |
#include "ui/gl/gl_bindings.h" |
@@ -33,8 +34,10 @@ int RoundUpSurfaceDimension(int number) { |
// We are backed by an offscreen surface for the purposes of creating |
// a context, but use FBOs to render to texture backed IOSurface |
-class IOSurfaceImageTransportSurface : public gfx::NoOpGLSurfaceCGL, |
- public ImageTransportSurface { |
+class IOSurfaceImageTransportSurface |
+ : public gfx::NoOpGLSurfaceCGL, |
+ public ImageTransportSurface, |
+ public GpuCommandBufferStub::DestructionObserver { |
public: |
IOSurfaceImageTransportSurface(GpuChannelManager* manager, |
GpuCommandBufferStub* stub, |
@@ -62,6 +65,9 @@ class IOSurfaceImageTransportSurface : public gfx::NoOpGLSurfaceCGL, |
virtual void OnResize(gfx::Size size, float scale_factor) OVERRIDE; |
virtual void SetLatencyInfo(const ui::LatencyInfo&) OVERRIDE; |
+ // GpuCommandBufferStub::DestructionObserver implementation. |
+ virtual void OnWillDestroyStub() OVERRIDE; |
+ |
private: |
virtual ~IOSurfaceImageTransportSurface() OVERRIDE; |
@@ -101,6 +107,8 @@ class IOSurfaceImageTransportSurface : public gfx::NoOpGLSurfaceCGL, |
scoped_ptr<ImageTransportHelper> helper_; |
+ bool added_observer_; |
+ |
DISALLOW_COPY_AND_ASSIGN(IOSurfaceImageTransportSurface); |
}; |
@@ -133,12 +141,12 @@ IOSurfaceImageTransportSurface::IOSurfaceImageTransportSurface( |
scale_factor_(1.f), |
made_current_(false), |
is_swap_buffers_pending_(false), |
- did_unschedule_(false) { |
+ did_unschedule_(false), |
+ added_observer_(false) { |
helper_.reset(new ImageTransportHelper(this, manager, stub, handle)); |
} |
IOSurfaceImageTransportSurface::~IOSurfaceImageTransportSurface() { |
- Destroy(); |
} |
bool IOSurfaceImageTransportSurface::Initialize() { |
@@ -313,6 +321,11 @@ void IOSurfaceImageTransportSurface::SetLatencyInfo( |
latency_info_ = latency_info; |
} |
+void IOSurfaceImageTransportSurface::OnWillDestroyStub() { |
+ helper_->stub()->RemoveDestructionObserver(this); |
+ Destroy(); |
+} |
+ |
void IOSurfaceImageTransportSurface::UnrefIOSurface() { |
// If we have resources to destroy, then make sure that we have a current |
// context which we can use to delete the resources. |
@@ -340,6 +353,11 @@ void IOSurfaceImageTransportSurface::CreateIOSurface() { |
gfx::Size new_rounded_size(RoundUpSurfaceDimension(size_.width()), |
RoundUpSurfaceDimension(size_.height())); |
+ if (!added_observer_) { |
+ helper_->stub()->AddDestructionObserver(this); |
piman
2013/06/05 00:05:33
Why not do that always in Initialize?
Destroy seem
no sievers
2013/06/05 00:19:05
Done.
I think I was under the false impression th
|
+ added_observer_ = true; |
+ } |
+ |
// Only recreate surface when the rounded up size has changed. |
if (io_surface_.get() && new_rounded_size == rounded_size_) |
return; |