Commit 5ad68f63 authored by abarth@chromium.org's avatar abarth@chromium.org

[Mojo] Fix race condition in sample_app's SwapBuffers

The in-process command buffer expects all of its callers to be on a single
thread. Prior to this CL, we were bouncing back to the shell thread to call
swap buffers. Now we call SwapBuffers from sample_app's thread.

R=davemoore@chromium.org

Review URL: https://codereview.chromium.org/99323005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238223 0039d316-1c4b-4281-b951-d872f2087c98
parent 357edd26
...@@ -17,6 +17,7 @@ NativeViewportClientImpl::NativeViewportClientImpl(ScopedMessagePipeHandle pipe) ...@@ -17,6 +17,7 @@ NativeViewportClientImpl::NativeViewportClientImpl(ScopedMessagePipeHandle pipe)
} }
NativeViewportClientImpl::~NativeViewportClientImpl() { NativeViewportClientImpl::~NativeViewportClientImpl() {
service_->Close();
} }
void NativeViewportClientImpl::Open() { void NativeViewportClientImpl::Open() {
......
...@@ -19,7 +19,7 @@ SampleGLES2Delegate::~SampleGLES2Delegate() { ...@@ -19,7 +19,7 @@ SampleGLES2Delegate::~SampleGLES2Delegate() {
} }
void SampleGLES2Delegate::DidCreateContext( void SampleGLES2Delegate::DidCreateContext(
GLES2* gl, uint32_t width, uint32_t height) { GLES2ClientImpl* gl, uint32_t width, uint32_t height) {
gl_ = gl; gl_ = gl;
cube_.Init(width, height); cube_.Init(width, height);
last_time_ = base::Time::Now(); last_time_ = base::Time::Now();
...@@ -36,9 +36,9 @@ void SampleGLES2Delegate::Draw() { ...@@ -36,9 +36,9 @@ void SampleGLES2Delegate::Draw() {
gl_->SwapBuffers(); gl_->SwapBuffers();
} }
void SampleGLES2Delegate::ContextLost(GLES2* gl) { void SampleGLES2Delegate::ContextLost(GLES2ClientImpl* gl) {
timer_.Stop();
gl_ = NULL; gl_ = NULL;
timer_.Stop();
} }
} // namespace examples } // namespace examples
......
...@@ -19,15 +19,15 @@ class SampleGLES2Delegate : public GLES2Delegate { ...@@ -19,15 +19,15 @@ class SampleGLES2Delegate : public GLES2Delegate {
private: private:
virtual void DidCreateContext( virtual void DidCreateContext(
GLES2* gl, uint32_t width, uint32_t height) MOJO_OVERRIDE; GLES2ClientImpl* gl, uint32_t width, uint32_t height) MOJO_OVERRIDE;
virtual void ContextLost(GLES2* gl) MOJO_OVERRIDE; virtual void ContextLost(GLES2ClientImpl* gl) MOJO_OVERRIDE;
void Draw(); void Draw();
base::Time last_time_; base::Time last_time_;
base::RepeatingTimer<SampleGLES2Delegate> timer_; base::RepeatingTimer<SampleGLES2Delegate> timer_;
GLES2* gl_;
SpinningCube cube_; SpinningCube cube_;
GLES2ClientImpl* gl_;
}; };
} // namespace examples } // namespace examples
......
...@@ -19,10 +19,10 @@ GLES2Delegate::~GLES2Delegate() { ...@@ -19,10 +19,10 @@ GLES2Delegate::~GLES2Delegate() {
} }
void GLES2Delegate::DidCreateContext( void GLES2Delegate::DidCreateContext(
GLES2* gl, uint32_t width, uint32_t height) { GLES2ClientImpl* gl, uint32_t width, uint32_t height) {
} }
void GLES2Delegate::ContextLost(GLES2* gl) { void GLES2Delegate::ContextLost(GLES2ClientImpl* gl) {
} }
GLES2ClientImpl::GLES2ClientImpl(GLES2Delegate* delegate, GLES2ClientImpl::GLES2ClientImpl(GLES2Delegate* delegate,
...@@ -34,6 +34,7 @@ GLES2ClientImpl::GLES2ClientImpl(GLES2Delegate* delegate, ...@@ -34,6 +34,7 @@ GLES2ClientImpl::GLES2ClientImpl(GLES2Delegate* delegate,
} }
GLES2ClientImpl::~GLES2ClientImpl() { GLES2ClientImpl::~GLES2ClientImpl() {
gl_->Destroy();
} }
void GLES2ClientImpl::Initialize() { void GLES2ClientImpl::Initialize() {
...@@ -48,6 +49,10 @@ void GLES2ClientImpl::Terminate() { ...@@ -48,6 +49,10 @@ void GLES2ClientImpl::Terminate() {
g_gles2_initialized = false; g_gles2_initialized = false;
} }
void GLES2ClientImpl::SwapBuffers() {
gles2::GetGLContext()->SwapBuffers();
}
void GLES2ClientImpl::DidCreateContext( void GLES2ClientImpl::DidCreateContext(
uint64_t encoded, uint32_t width, uint32_t height) { uint64_t encoded, uint32_t width, uint32_t height) {
// Ack, Hans! It's the giant hack. // Ack, Hans! It's the giant hack.
...@@ -60,11 +65,11 @@ void GLES2ClientImpl::DidCreateContext( ...@@ -60,11 +65,11 @@ void GLES2ClientImpl::DidCreateContext(
static_cast<uintptr_t>(encoded)); static_cast<uintptr_t>(encoded));
gles2::SetGLContext(gl_interface); gles2::SetGLContext(gl_interface);
delegate_->DidCreateContext(gl(), width, height); delegate_->DidCreateContext(this, width, height);
} }
void GLES2ClientImpl::ContextLost() { void GLES2ClientImpl::ContextLost() {
delegate_->ContextLost(gl()); delegate_->ContextLost(this);
} }
} // mojo } // mojo
...@@ -9,12 +9,14 @@ ...@@ -9,12 +9,14 @@
#include "mojom/gles2.h" #include "mojom/gles2.h"
namespace mojo { namespace mojo {
class GLES2ClientImpl;
class GLES2Delegate { class GLES2Delegate {
public: public:
virtual ~GLES2Delegate(); virtual ~GLES2Delegate();
virtual void DidCreateContext(GLES2* gl, uint32_t width, uint32_t height); virtual void DidCreateContext(
virtual void ContextLost(GLES2* gl); GLES2ClientImpl* gl, uint32_t width, uint32_t height);
virtual void ContextLost(GLES2ClientImpl* gl);
}; };
class GLES2ClientImpl : public GLES2ClientStub { class GLES2ClientImpl : public GLES2ClientStub {
...@@ -26,9 +28,7 @@ class GLES2ClientImpl : public GLES2ClientStub { ...@@ -26,9 +28,7 @@ class GLES2ClientImpl : public GLES2ClientStub {
static void Initialize(); static void Initialize();
static void Terminate(); static void Terminate();
GLES2* gl() { void SwapBuffers();
return gl_.get();
}
private: private:
virtual void DidCreateContext( virtual void DidCreateContext(
......
...@@ -6,7 +6,7 @@ module mojo { ...@@ -6,7 +6,7 @@ module mojo {
[Peer=GLES2Client] [Peer=GLES2Client]
interface GLES2 { interface GLES2 {
void SwapBuffers(); void Destroy();
}; };
[Peer=GLES2] [Peer=GLES2]
......
...@@ -19,10 +19,8 @@ GLES2Impl::GLES2Impl(ScopedMessagePipeHandle client) ...@@ -19,10 +19,8 @@ GLES2Impl::GLES2Impl(ScopedMessagePipeHandle client)
GLES2Impl::~GLES2Impl() { GLES2Impl::~GLES2Impl() {
} }
void GLES2Impl::SwapBuffers() { void GLES2Impl::Destroy() {
if (!gl_context_) gl_context_.reset();
return;
gl_context_->GetImplementation()->SwapBuffers();
} }
void GLES2Impl::CreateContext(gfx::AcceleratedWidget widget, void GLES2Impl::CreateContext(gfx::AcceleratedWidget widget,
......
...@@ -24,7 +24,7 @@ class GLES2Impl : public GLES2Stub { ...@@ -24,7 +24,7 @@ class GLES2Impl : public GLES2Stub {
explicit GLES2Impl(ScopedMessagePipeHandle client); explicit GLES2Impl(ScopedMessagePipeHandle client);
virtual ~GLES2Impl(); virtual ~GLES2Impl();
virtual void SwapBuffers() OVERRIDE; virtual void Destroy() OVERRIDE;
void CreateContext(gfx::AcceleratedWidget widget, const gfx::Size& size); void CreateContext(gfx::AcceleratedWidget widget, const gfx::Size& size);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment