Skip to content

Commit

Permalink
Added ability to force a GLContext SwapInterval to zero.
Browse files Browse the repository at this point in the history
This will be important for consistency once we allow the SwapInterval to be set dynamically through dev tools.

BUG=437172

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

Cr-Commit-Position: refs/heads/master@{#307835}
  • Loading branch information
toji authored and Commit bot committed Dec 11, 2014
1 parent a4facb7 commit 81068dd
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 19 deletions.
4 changes: 2 additions & 2 deletions content/common/gpu/image_transport_surface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ void ImageTransportHelper::SetSwapInterval(gfx::GLContext* context) {
// If Aero Glass is enabled, then the renderer will handle ratelimiting and
// there's no tearing, so waiting for vsync is unnecessary.
if (ui::win::IsAeroGlassEnabled()) {
context->SetSwapInterval(0);
context->ForceSwapIntervalZero(true);
return;
}
#endif
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableGpuVsync))
context->SetSwapInterval(0);
context->ForceSwapIntervalZero(true);
else
context->SetSwapInterval(1);
}
Expand Down
2 changes: 1 addition & 1 deletion gpu/command_buffer/service/gl_context_virtual.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void* GLContextVirtual::GetHandle() {
return shared_context_->GetHandle();
}

void GLContextVirtual::SetSwapInterval(int interval) {
void GLContextVirtual::OnSetSwapInterval(int interval) {
shared_context_->SetSwapInterval(interval);
}

Expand Down
2 changes: 1 addition & 1 deletion gpu/command_buffer/service/gl_context_virtual.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class GPU_EXPORT GLContextVirtual : public gfx::GLContext {
void ReleaseCurrent(gfx::GLSurface* surface) override;
bool IsCurrent(gfx::GLSurface* surface) override;
void* GetHandle() override;
void SetSwapInterval(int interval) override;
void OnSetSwapInterval(int interval) override;
std::string GetExtensions() override;
bool GetTotalGpuMemory(size_t* bytes) override;
void SetSafeToForceGpuSwitch() override;
Expand Down
15 changes: 14 additions & 1 deletion ui/gl/gl_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ bool GLContext::FlushEvent::IsSignaled() {
return flag_.IsSet();
}

GLContext::GLContext(GLShareGroup* share_group) : share_group_(share_group) {
GLContext::GLContext(GLShareGroup* share_group) :
share_group_(share_group),
swap_interval_(1),
force_swap_interval_zero_(false) {
if (!share_group_.get())
share_group_ = new GLShareGroup;

Expand Down Expand Up @@ -178,6 +181,16 @@ void GLContext::SetGLStateRestorer(GLStateRestorer* state_restorer) {
state_restorer_ = make_scoped_ptr(state_restorer);
}

void GLContext::SetSwapInterval(int interval) {
swap_interval_ = interval;
OnSetSwapInterval(force_swap_interval_zero_ ? 0 : swap_interval_);
}

void GLContext::ForceSwapIntervalZero(bool force) {
force_swap_interval_zero_ = force;
OnSetSwapInterval(force_swap_interval_zero_ ? 0 : swap_interval_);
}

bool GLContext::WasAllocatedUsingRobustnessExtension() {
return false;
}
Expand Down
11 changes: 10 additions & 1 deletion ui/gl/gl_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ class GL_EXPORT GLContext : public base::RefCounted<GLContext> {
void SetGLStateRestorer(GLStateRestorer* state_restorer);

// Set swap interval. This context must be current.
virtual void SetSwapInterval(int interval) = 0;
void SetSwapInterval(int interval);

// Forces the swap interval to zero (no vsync) regardless of any future values
// passed to SetSwapInterval.
void ForceSwapIntervalZero(bool force);

// Returns space separated list of extensions. The context must be current.
virtual std::string GetExtensions();
Expand Down Expand Up @@ -169,6 +173,8 @@ class GL_EXPORT GLContext : public base::RefCounted<GLContext> {
// Returns the last real (non-virtual) GLContext made current.
static GLContext* GetRealCurrent();

virtual void OnSetSwapInterval(int interval) = 0;

private:
friend class base::RefCounted<GLContext>;

Expand All @@ -182,6 +188,9 @@ class GL_EXPORT GLContext : public base::RefCounted<GLContext> {

std::vector<scoped_refptr<FlushEvent> > flush_events_;

int swap_interval_;
bool force_swap_interval_zero_;

DISALLOW_COPY_AND_ASSIGN(GLContext);
};

Expand Down
2 changes: 1 addition & 1 deletion ui/gl/gl_context_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class GLNonOwnedContext : public GLContextReal {
virtual void ReleaseCurrent(GLSurface* surface) override {}
virtual bool IsCurrent(GLSurface* surface) override { return true; }
virtual void* GetHandle() override { return NULL; }
virtual void SetSwapInterval(int interval) override {}
virtual void OnSetSwapInterval(int interval) override {}
virtual std::string GetExtensions() override;

protected:
Expand Down
2 changes: 1 addition & 1 deletion ui/gl/gl_context_cgl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void* GLContextCGL::GetHandle() {
return context_;
}

void GLContextCGL::SetSwapInterval(int interval) {
void GLContextCGL::OnSetSwapInterval(int interval) {
DCHECK(IsCurrent(NULL));
}

Expand Down
2 changes: 1 addition & 1 deletion ui/gl/gl_context_cgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class GLContextCGL : public GLContextReal {
void ReleaseCurrent(GLSurface* surface) override;
bool IsCurrent(GLSurface* surface) override;
void* GetHandle() override;
void SetSwapInterval(int interval) override;
void OnSetSwapInterval(int interval) override;
bool GetTotalGpuMemory(size_t* bytes) override;
void SetSafeToForceGpuSwitch() override;
bool ForceGpuSwitchIfNeeded() override;
Expand Down
2 changes: 1 addition & 1 deletion ui/gl/gl_context_egl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void* GLContextEGL::GetHandle() {
return context_;
}

void GLContextEGL::SetSwapInterval(int interval) {
void GLContextEGL::OnSetSwapInterval(int interval) {
DCHECK(IsCurrent(NULL) && GLSurface::GetCurrent());

// This is a surfaceless context. eglSwapInterval doesn't take any effect in
Expand Down
2 changes: 1 addition & 1 deletion ui/gl/gl_context_egl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class GLContextEGL : public GLContextReal {
void ReleaseCurrent(GLSurface* surface) override;
bool IsCurrent(GLSurface* surface) override;
void* GetHandle() override;
void SetSwapInterval(int interval) override;
void OnSetSwapInterval(int interval) override;
std::string GetExtensions() override;
bool WasAllocatedUsingRobustnessExtension() override;
bool GetTotalGpuMemory(size_t* bytes) override;
Expand Down
2 changes: 1 addition & 1 deletion ui/gl/gl_context_glx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void* GLContextGLX::GetHandle() {
return context_;
}

void GLContextGLX::SetSwapInterval(int interval) {
void GLContextGLX::OnSetSwapInterval(int interval) {
DCHECK(IsCurrent(NULL));
if (HasExtension("GLX_EXT_swap_control") &&
g_driver_glx.fn.glXSwapIntervalEXTFn) {
Expand Down
2 changes: 1 addition & 1 deletion ui/gl/gl_context_glx.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class GL_EXPORT GLContextGLX : public GLContextReal {
void ReleaseCurrent(GLSurface* surface) override;
bool IsCurrent(GLSurface* surface) override;
void* GetHandle() override;
void SetSwapInterval(int interval) override;
void OnSetSwapInterval(int interval) override;
std::string GetExtensions() override;
bool GetTotalGpuMemory(size_t* bytes) override;
bool WasAllocatedUsingRobustnessExtension() override;
Expand Down
2 changes: 1 addition & 1 deletion ui/gl/gl_context_osmesa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void* GLContextOSMesa::GetHandle() {
return context_;
}

void GLContextOSMesa::SetSwapInterval(int interval) {
void GLContextOSMesa::OnSetSwapInterval(int interval) {
DCHECK(IsCurrent(NULL));
}

Expand Down
2 changes: 1 addition & 1 deletion ui/gl/gl_context_osmesa.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class GLContextOSMesa : public GLContextReal {
void ReleaseCurrent(GLSurface* surface) override;
bool IsCurrent(GLSurface* surface) override;
void* GetHandle() override;
void SetSwapInterval(int interval) override;
void OnSetSwapInterval(int interval) override;

protected:
~GLContextOSMesa() override;
Expand Down
2 changes: 1 addition & 1 deletion ui/gl/gl_context_stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void* GLContextStub::GetHandle() {
return NULL;
}

void GLContextStub::SetSwapInterval(int interval) {
void GLContextStub::OnSetSwapInterval(int interval) {
}

std::string GLContextStub::GetExtensions() {
Expand Down
2 changes: 1 addition & 1 deletion ui/gl/gl_context_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GL_EXPORT GLContextStub : public GLContextReal {
void ReleaseCurrent(GLSurface* surface) override;
bool IsCurrent(GLSurface* surface) override;
void* GetHandle() override;
void SetSwapInterval(int interval) override;
void OnSetSwapInterval(int interval) override;
std::string GetExtensions() override;
std::string GetGLRenderer() override;

Expand Down
2 changes: 1 addition & 1 deletion ui/gl/gl_context_wgl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void* GLContextWGL::GetHandle() {
return context_;
}

void GLContextWGL::SetSwapInterval(int interval) {
void GLContextWGL::OnSetSwapInterval(int interval) {
DCHECK(IsCurrent(NULL));
if (gfx::g_driver_wgl.ext.b_WGL_EXT_swap_control) {
wglSwapIntervalEXT(interval);
Expand Down
2 changes: 1 addition & 1 deletion ui/gl/gl_context_wgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class GLContextWGL : public GLContextReal {
virtual void ReleaseCurrent(GLSurface* surface);
virtual bool IsCurrent(GLSurface* surface);
virtual void* GetHandle();
virtual void SetSwapInterval(int interval);
virtual void OnSetSwapInterval(int interval);
virtual std::string GetExtensions();

private:
Expand Down

0 comments on commit 81068dd

Please sign in to comment.