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)
}
NativeViewportClientImpl::~NativeViewportClientImpl() {
service_->Close();
}
void NativeViewportClientImpl::Open() {
......
......@@ -19,7 +19,7 @@ SampleGLES2Delegate::~SampleGLES2Delegate() {
}
void SampleGLES2Delegate::DidCreateContext(
GLES2* gl, uint32_t width, uint32_t height) {
GLES2ClientImpl* gl, uint32_t width, uint32_t height) {
gl_ = gl;
cube_.Init(width, height);
last_time_ = base::Time::Now();
......@@ -36,9 +36,9 @@ void SampleGLES2Delegate::Draw() {
gl_->SwapBuffers();
}
void SampleGLES2Delegate::ContextLost(GLES2* gl) {
timer_.Stop();
void SampleGLES2Delegate::ContextLost(GLES2ClientImpl* gl) {
gl_ = NULL;
timer_.Stop();
}
} // namespace examples
......
......@@ -19,15 +19,15 @@ class SampleGLES2Delegate : public GLES2Delegate {
private:
virtual void DidCreateContext(
GLES2* gl, uint32_t width, uint32_t height) MOJO_OVERRIDE;
virtual void ContextLost(GLES2* gl) MOJO_OVERRIDE;
GLES2ClientImpl* gl, uint32_t width, uint32_t height) MOJO_OVERRIDE;
virtual void ContextLost(GLES2ClientImpl* gl) MOJO_OVERRIDE;
void Draw();
base::Time last_time_;
base::RepeatingTimer<SampleGLES2Delegate> timer_;
GLES2* gl_;
SpinningCube cube_;
GLES2ClientImpl* gl_;
};
} // namespace examples
......
......@@ -19,10 +19,10 @@ GLES2Delegate::~GLES2Delegate() {
}
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,
......@@ -34,6 +34,7 @@ GLES2ClientImpl::GLES2ClientImpl(GLES2Delegate* delegate,
}
GLES2ClientImpl::~GLES2ClientImpl() {
gl_->Destroy();
}
void GLES2ClientImpl::Initialize() {
......@@ -48,6 +49,10 @@ void GLES2ClientImpl::Terminate() {
g_gles2_initialized = false;
}
void GLES2ClientImpl::SwapBuffers() {
gles2::GetGLContext()->SwapBuffers();
}
void GLES2ClientImpl::DidCreateContext(
uint64_t encoded, uint32_t width, uint32_t height) {
// Ack, Hans! It's the giant hack.
......@@ -60,11 +65,11 @@ void GLES2ClientImpl::DidCreateContext(
static_cast<uintptr_t>(encoded));
gles2::SetGLContext(gl_interface);
delegate_->DidCreateContext(gl(), width, height);
delegate_->DidCreateContext(this, width, height);
}
void GLES2ClientImpl::ContextLost() {
delegate_->ContextLost(gl());
delegate_->ContextLost(this);
}
} // mojo
......@@ -9,12 +9,14 @@
#include "mojom/gles2.h"
namespace mojo {
class GLES2ClientImpl;
class GLES2Delegate {
public:
virtual ~GLES2Delegate();
virtual void DidCreateContext(GLES2* gl, uint32_t width, uint32_t height);
virtual void ContextLost(GLES2* gl);
virtual void DidCreateContext(
GLES2ClientImpl* gl, uint32_t width, uint32_t height);
virtual void ContextLost(GLES2ClientImpl* gl);
};
class GLES2ClientImpl : public GLES2ClientStub {
......@@ -26,9 +28,7 @@ class GLES2ClientImpl : public GLES2ClientStub {
static void Initialize();
static void Terminate();
GLES2* gl() {
return gl_.get();
}
void SwapBuffers();
private:
virtual void DidCreateContext(
......
......@@ -6,7 +6,7 @@ module mojo {
[Peer=GLES2Client]
interface GLES2 {
void SwapBuffers();
void Destroy();
};
[Peer=GLES2]
......
......@@ -19,10 +19,8 @@ GLES2Impl::GLES2Impl(ScopedMessagePipeHandle client)
GLES2Impl::~GLES2Impl() {
}
void GLES2Impl::SwapBuffers() {
if (!gl_context_)
return;
gl_context_->GetImplementation()->SwapBuffers();
void GLES2Impl::Destroy() {
gl_context_.reset();
}
void GLES2Impl::CreateContext(gfx::AcceleratedWidget widget,
......
......@@ -24,7 +24,7 @@ class GLES2Impl : public GLES2Stub {
explicit GLES2Impl(ScopedMessagePipeHandle client);
virtual ~GLES2Impl();
virtual void SwapBuffers() OVERRIDE;
virtual void Destroy() OVERRIDE;
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