Index: ui/gl/gl_surface_glx.cc |
diff --git a/ui/gl/gl_surface_glx.cc b/ui/gl/gl_surface_glx.cc |
index 87dffe9e5ba8f450c9ebcafc2fb43319096cdcf8..71adc9475e359eb789a3645c453295fd53c6c0cd 100644 |
--- a/ui/gl/gl_surface_glx.cc |
+++ b/ui/gl/gl_surface_glx.cc |
@@ -123,8 +123,7 @@ class SGIVideoSyncThread |
DISALLOW_COPY_AND_ASSIGN(SGIVideoSyncThread); |
}; |
-class SGIVideoSyncProviderThreadShim |
- : public base::SupportsWeakPtr<SGIVideoSyncProviderThreadShim> { |
+class SGIVideoSyncProviderThreadShim { |
public: |
explicit SGIVideoSyncProviderThreadShim(XID window) |
: window_(window), |
@@ -137,6 +136,13 @@ class SGIVideoSyncProviderThreadShim |
XSync(g_display, False); |
} |
+ virtual ~SGIVideoSyncProviderThreadShim() { |
+ if (context_) { |
+ glXDestroyContext(display_, context_); |
+ context_ = NULL; |
+ } |
+ } |
+ |
base::CancellationFlag* cancel_vsync_flag() { |
return &cancel_vsync_flag_; |
} |
@@ -174,14 +180,6 @@ class SGIVideoSyncProviderThreadShim |
DCHECK(NULL != context_); |
} |
- void Destroy() { |
- if (context_) { |
- glXDestroyContext(display_, context_); |
- context_ = NULL; |
- } |
- delete this; |
- } |
- |
void GetVSyncParameters(const VSyncProvider::UpdateVSyncCallback& callback) { |
base::TimeTicks now; |
{ |
@@ -215,9 +213,6 @@ class SGIVideoSyncProviderThreadShim |
// the sandbox goes up. |
friend class gfx::GLSurfaceGLX; |
- virtual ~SGIVideoSyncProviderThreadShim() { |
- } |
- |
static Display* display_; |
XID window_; |
@@ -237,15 +232,13 @@ class SGIVideoSyncVSyncProvider |
public: |
explicit SGIVideoSyncVSyncProvider(gfx::AcceleratedWidget window) |
: vsync_thread_(SGIVideoSyncThread::Create()), |
- shim_((new SGIVideoSyncProviderThreadShim(window))->AsWeakPtr()), |
+ shim_(new SGIVideoSyncProviderThreadShim(window)), |
cancel_vsync_flag_(shim_->cancel_vsync_flag()), |
vsync_lock_(shim_->vsync_lock()) { |
- // The WeakPtr is bound to the SGIVideoSyncThread. We only use it for |
- // PostTask. |
- shim_->DetachFromThread(); |
vsync_thread_->message_loop()->PostTask( |
FROM_HERE, |
- base::Bind(&SGIVideoSyncProviderThreadShim::Initialize, shim_)); |
+ base::Bind(&SGIVideoSyncProviderThreadShim::Initialize, |
+ base::Unretained(shim_.get()))); |
} |
virtual ~SGIVideoSyncVSyncProvider() { |
@@ -253,9 +246,11 @@ class SGIVideoSyncVSyncProvider |
base::AutoLock locked(*vsync_lock_); |
cancel_vsync_flag_->Set(); |
} |
- vsync_thread_->message_loop()->PostTask( |
+ |
+ // Hand-off |shim_| to be deleted on the |vsync_thread_|. |
+ vsync_thread_->message_loop()->DeleteSoon( |
FROM_HERE, |
- base::Bind(&SGIVideoSyncProviderThreadShim::Destroy, shim_)); |
+ shim_.release()); |
} |
virtual void GetVSyncParameters( |
@@ -267,7 +262,8 @@ class SGIVideoSyncVSyncProvider |
vsync_thread_->message_loop()->PostTask( |
FROM_HERE, |
base::Bind(&SGIVideoSyncProviderThreadShim::GetVSyncParameters, |
- shim_, base::Bind( |
+ base::Unretained(shim_.get()), |
+ base::Bind( |
&SGIVideoSyncVSyncProvider::PendingCallbackRunner, |
AsWeakPtr()))); |
} |
@@ -282,7 +278,9 @@ class SGIVideoSyncVSyncProvider |
} |
scoped_refptr<SGIVideoSyncThread> vsync_thread_; |
- base::WeakPtr<SGIVideoSyncProviderThreadShim> shim_; |
+ |
+ // Thread shim through which the sync provider is accessed on |vsync_thread_|. |
+ scoped_ptr<SGIVideoSyncProviderThreadShim> shim_; |
scoped_ptr<VSyncProvider::UpdateVSyncCallback> pending_callback_; |