Commit 50f5ff68 authored by sievers@google.com's avatar sievers@google.com

Add common GLFence::IsSupported() check

Cconsolidate the logic inside gl_fence.cc
to allow checking if a GLFence can be created.

R=reveman@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278860 0039d316-1c4b-4281-b951-d872f2087c98
parent d3833fe8
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "gpu/command_buffer/service/gl_utils.h" #include "gpu/command_buffer/service/gl_utils.h"
#include "gpu/command_buffer/service/gpu_switches.h" #include "gpu/command_buffer/service/gpu_switches.h"
#include "ui/gl/gl_fence.h"
#include "ui/gl/gl_implementation.h" #include "ui/gl/gl_implementation.h"
namespace gpu { namespace gpu {
...@@ -789,18 +790,14 @@ void FeatureInfo::InitializeFeatures() { ...@@ -789,18 +790,14 @@ void FeatureInfo::InitializeFeatures() {
feature_flags_.ext_shader_texture_lod = true; feature_flags_.ext_shader_texture_lod = true;
} }
bool egl_khr_fence_sync = false;
#if !defined(OS_MACOSX) #if !defined(OS_MACOSX)
if (workarounds_.disable_egl_khr_fence_sync) { if (workarounds_.disable_egl_khr_fence_sync) {
gfx::g_driver_egl.ext.b_EGL_KHR_fence_sync = false; gfx::g_driver_egl.ext.b_EGL_KHR_fence_sync = false;
} }
egl_khr_fence_sync = gfx::g_driver_egl.ext.b_EGL_KHR_fence_sync;
#endif #endif
if (workarounds_.disable_arb_sync) if (workarounds_.disable_arb_sync)
gfx::g_driver_gl.ext.b_GL_ARB_sync = false; gfx::g_driver_gl.ext.b_GL_ARB_sync = false;
bool ui_gl_fence_works = is_es3 || extensions.Contains("GL_NV_fence") || bool ui_gl_fence_works = gfx::GLFence::IsSupported();
gfx::g_driver_gl.ext.b_GL_ARB_sync ||
egl_khr_fence_sync;
UMA_HISTOGRAM_BOOLEAN("GPU.FenceSupport", ui_gl_fence_works); UMA_HISTOGRAM_BOOLEAN("GPU.FenceSupport", ui_gl_fence_works);
feature_flags_.map_buffer_range = feature_flags_.map_buffer_range =
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "gpu/command_buffer/service/texture_manager.h" #include "gpu/command_buffer/service/texture_manager.h"
#include "gpu/config/gpu_driver_bug_workaround_type.h" #include "gpu/config/gpu_driver_bug_workaround_type.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/gl/gl_fence.h"
#include "ui/gl/gl_implementation.h" #include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_mock.h" #include "ui/gl/gl_mock.h"
...@@ -46,6 +47,7 @@ class FeatureInfoTest : public GpuServiceTest { ...@@ -46,6 +47,7 @@ class FeatureInfoTest : public GpuServiceTest {
void SetupInitExpectationsWithGLVersion( void SetupInitExpectationsWithGLVersion(
const char* extensions, const char* renderer, const char* version) { const char* extensions, const char* renderer, const char* version) {
GpuServiceTest::SetUpWithGLVersion(version, extensions);
TestHelper::SetupFeatureInfoInitExpectationsWithGLVersion( TestHelper::SetupFeatureInfoInitExpectationsWithGLVersion(
gl_.get(), extensions, renderer, version); gl_.get(), extensions, renderer, version);
info_ = new FeatureInfo(); info_ = new FeatureInfo();
...@@ -53,11 +55,13 @@ class FeatureInfoTest : public GpuServiceTest { ...@@ -53,11 +55,13 @@ class FeatureInfoTest : public GpuServiceTest {
} }
void SetupWithCommandLine(const CommandLine& command_line) { void SetupWithCommandLine(const CommandLine& command_line) {
GpuServiceTest::SetUp();
info_ = new FeatureInfo(command_line); info_ = new FeatureInfo(command_line);
} }
void SetupInitExpectationsWithCommandLine( void SetupInitExpectationsWithCommandLine(
const char* extensions, const CommandLine& command_line) { const char* extensions, const CommandLine& command_line) {
GpuServiceTest::SetUpWithGLVersion("2.0", extensions);
TestHelper::SetupFeatureInfoInitExpectationsWithGLVersion( TestHelper::SetupFeatureInfoInitExpectationsWithGLVersion(
gl_.get(), extensions, "", ""); gl_.get(), extensions, "", "");
info_ = new FeatureInfo(command_line); info_ = new FeatureInfo(command_line);
...@@ -65,11 +69,16 @@ class FeatureInfoTest : public GpuServiceTest { ...@@ -65,11 +69,16 @@ class FeatureInfoTest : public GpuServiceTest {
} }
void SetupWithoutInit() { void SetupWithoutInit() {
GpuServiceTest::SetUp();
info_ = new FeatureInfo(); info_ = new FeatureInfo();
} }
protected: protected:
virtual void TearDown() { virtual void SetUp() OVERRIDE {
// Do nothing here, since we are using the explicit Setup*() functions.
}
virtual void TearDown() OVERRIDE {
info_ = NULL; info_ = NULL;
GpuServiceTest::TearDown(); GpuServiceTest::TearDown();
} }
...@@ -310,6 +319,7 @@ TEST_F(FeatureInfoTest, InitializeNoExtensions) { ...@@ -310,6 +319,7 @@ TEST_F(FeatureInfoTest, InitializeNoExtensions) {
GL_DEPTH24_STENCIL8_OES)); GL_DEPTH24_STENCIL8_OES));
EXPECT_FALSE(info_->validators()->equation.IsValid(GL_MIN_EXT)); EXPECT_FALSE(info_->validators()->equation.IsValid(GL_MIN_EXT));
EXPECT_FALSE(info_->validators()->equation.IsValid(GL_MAX_EXT)); EXPECT_FALSE(info_->validators()->equation.IsValid(GL_MAX_EXT));
EXPECT_FALSE(info_->feature_flags().chromium_sync_query);
} }
TEST_F(FeatureInfoTest, InitializeWithANGLE) { TEST_F(FeatureInfoTest, InitializeWithANGLE) {
...@@ -1007,6 +1017,8 @@ TEST_F(FeatureInfoTest, InitializeWithES3) { ...@@ -1007,6 +1017,8 @@ TEST_F(FeatureInfoTest, InitializeWithES3) {
EXPECT_TRUE( EXPECT_TRUE(
info_->validators()->texture_internal_format.IsValid(GL_DEPTH_STENCIL)); info_->validators()->texture_internal_format.IsValid(GL_DEPTH_STENCIL));
EXPECT_TRUE(info_->validators()->texture_format.IsValid(GL_DEPTH_STENCIL)); EXPECT_TRUE(info_->validators()->texture_format.IsValid(GL_DEPTH_STENCIL));
EXPECT_TRUE(info_->feature_flags().chromium_sync_query);
EXPECT_TRUE(gfx::GLFence::IsSupported());
} }
TEST_F(FeatureInfoTest, InitializeWithoutSamplers) { TEST_F(FeatureInfoTest, InitializeWithoutSamplers) {
...@@ -1014,11 +1026,6 @@ TEST_F(FeatureInfoTest, InitializeWithoutSamplers) { ...@@ -1014,11 +1026,6 @@ TEST_F(FeatureInfoTest, InitializeWithoutSamplers) {
EXPECT_FALSE(info_->feature_flags().enable_samplers); EXPECT_FALSE(info_->feature_flags().enable_samplers);
} }
TEST_F(FeatureInfoTest, InitializeWithES3AndFences) {
SetupInitExpectationsWithGLVersion("EGL_KHR_fence_sync", "", "OpenGL ES 3.0");
EXPECT_TRUE(info_->feature_flags().use_async_readpixels);
}
TEST_F(FeatureInfoTest, ParseDriverBugWorkaroundsSingle) { TEST_F(FeatureInfoTest, ParseDriverBugWorkaroundsSingle) {
CommandLine command_line(0, NULL); CommandLine command_line(0, NULL);
command_line.AppendSwitchASCII( command_line.AppendSwitchASCII(
...@@ -1043,5 +1050,27 @@ TEST_F(FeatureInfoTest, ParseDriverBugWorkaroundsMultiple) { ...@@ -1043,5 +1050,27 @@ TEST_F(FeatureInfoTest, ParseDriverBugWorkaroundsMultiple) {
EXPECT_EQ(4096, info_->workarounds().max_texture_size); EXPECT_EQ(4096, info_->workarounds().max_texture_size);
} }
TEST_F(FeatureInfoTest, InitializeWithARBSync) {
SetupInitExpectations("GL_ARB_sync");
EXPECT_TRUE(info_->feature_flags().chromium_sync_query);
EXPECT_TRUE(gfx::GLFence::IsSupported());
}
TEST_F(FeatureInfoTest, InitializeWithNVFence) {
SetupInitExpectations("GL_NV_fence");
EXPECT_TRUE(info_->feature_flags().chromium_sync_query);
EXPECT_TRUE(gfx::GLFence::IsSupported());
}
TEST_F(FeatureInfoTest, ARBSyncDisabled) {
CommandLine command_line(0, NULL);
command_line.AppendSwitchASCII(
switches::kGpuDriverBugWorkarounds,
base::IntToString(gpu::DISABLE_ARB_SYNC));
SetupInitExpectationsWithCommandLine("GL_ARB_sync", command_line);
EXPECT_FALSE(info_->feature_flags().chromium_sync_query);
EXPECT_FALSE(gfx::GLFence::IsSupported());
}
} // namespace gles2 } // namespace gles2
} // namespace gpu } // namespace gpu
...@@ -21,7 +21,8 @@ GpuServiceTest::~GpuServiceTest() { ...@@ -21,7 +21,8 @@ GpuServiceTest::~GpuServiceTest() {
DCHECK(ran_teardown_); DCHECK(ran_teardown_);
} }
void GpuServiceTest::SetUp() { void GpuServiceTest::SetUpWithGLVersion(const char* gl_version,
const char* gl_extensions) {
testing::Test::SetUp(); testing::Test::SetUp();
gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress); gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress);
...@@ -30,12 +31,16 @@ void GpuServiceTest::SetUp() { ...@@ -30,12 +31,16 @@ void GpuServiceTest::SetUp() {
::gfx::MockGLInterface::SetGLInterface(gl_.get()); ::gfx::MockGLInterface::SetGLInterface(gl_.get());
context_ = new gfx::GLContextStubWithExtensions; context_ = new gfx::GLContextStubWithExtensions;
context_->AddExtensionsString(NULL); context_->AddExtensionsString(gl_extensions);
context_->SetGLVersionString("3.0"); context_->SetGLVersionString(gl_version);
gfx::GLSurface::InitializeDynamicMockBindingsForTests(context_); gfx::GLSurface::InitializeDynamicMockBindingsForTests(context_);
ran_setup_ = true; ran_setup_ = true;
} }
void GpuServiceTest::SetUp() {
SetUpWithGLVersion("2.0", NULL);
}
void GpuServiceTest::TearDown() { void GpuServiceTest::TearDown() {
DCHECK(ran_setup_); DCHECK(ran_setup_);
::gfx::MockGLInterface::SetGLInterface(NULL); ::gfx::MockGLInterface::SetGLInterface(NULL);
......
...@@ -25,6 +25,7 @@ class GpuServiceTest : public testing::Test { ...@@ -25,6 +25,7 @@ class GpuServiceTest : public testing::Test {
virtual ~GpuServiceTest(); virtual ~GpuServiceTest();
protected: protected:
void SetUpWithGLVersion(const char* gl_version, const char* gl_extensions);
virtual void SetUp() OVERRIDE; virtual void SetUp() OVERRIDE;
virtual void TearDown() OVERRIDE; virtual void TearDown() OVERRIDE;
......
...@@ -7,11 +7,14 @@ ...@@ -7,11 +7,14 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_context.h" #include "ui/gl/gl_context.h"
#include "ui/gl/gl_gl_api_implementation.h"
#include "ui/gl/gl_version_info.h" #include "ui/gl/gl_version_info.h"
namespace gfx {
namespace { namespace {
class GLFenceNVFence: public gfx::GLFence { class GLFenceNVFence: public GLFence {
public: public:
GLFenceNVFence(bool flush) { GLFenceNVFence(bool flush) {
// What if either of these GL calls fails? TestFenceNV will return true. // What if either of these GL calls fails? TestFenceNV will return true.
...@@ -29,7 +32,7 @@ class GLFenceNVFence: public gfx::GLFence { ...@@ -29,7 +32,7 @@ class GLFenceNVFence: public gfx::GLFence {
if (flush) { if (flush) {
glFlush(); glFlush();
} else { } else {
flush_event_ = gfx::GLContext::GetCurrent()->SignalFlush(); flush_event_ = GLContext::GetCurrent()->SignalFlush();
} }
} }
...@@ -55,17 +58,17 @@ class GLFenceNVFence: public gfx::GLFence { ...@@ -55,17 +58,17 @@ class GLFenceNVFence: public gfx::GLFence {
} }
GLuint fence_; GLuint fence_;
scoped_refptr<gfx::GLContext::FlushEvent> flush_event_; scoped_refptr<GLContext::FlushEvent> flush_event_;
}; };
class GLFenceARBSync: public gfx::GLFence { class GLFenceARBSync: public GLFence {
public: public:
GLFenceARBSync(bool flush) { GLFenceARBSync(bool flush) {
sync_ = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); sync_ = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
if (flush) { if (flush) {
glFlush(); glFlush();
} else { } else {
flush_event_ = gfx::GLContext::GetCurrent()->SignalFlush(); flush_event_ = GLContext::GetCurrent()->SignalFlush();
} }
} }
...@@ -102,11 +105,11 @@ class GLFenceARBSync: public gfx::GLFence { ...@@ -102,11 +105,11 @@ class GLFenceARBSync: public gfx::GLFence {
} }
GLsync sync_; GLsync sync_;
scoped_refptr<gfx::GLContext::FlushEvent> flush_event_; scoped_refptr<GLContext::FlushEvent> flush_event_;
}; };
#if !defined(OS_MACOSX) #if !defined(OS_MACOSX)
class EGLFenceSync : public gfx::GLFence { class EGLFenceSync : public GLFence {
public: public:
EGLFenceSync(bool flush) { EGLFenceSync(bool flush) {
display_ = eglGetCurrentDisplay(); display_ = eglGetCurrentDisplay();
...@@ -114,7 +117,7 @@ class EGLFenceSync : public gfx::GLFence { ...@@ -114,7 +117,7 @@ class EGLFenceSync : public gfx::GLFence {
if (flush) { if (flush) {
glFlush(); glFlush();
} else { } else {
flush_event_ = gfx::GLContext::GetCurrent()->SignalFlush(); flush_event_ = GLContext::GetCurrent()->SignalFlush();
} }
} }
...@@ -152,38 +155,49 @@ class EGLFenceSync : public gfx::GLFence { ...@@ -152,38 +155,49 @@ class EGLFenceSync : public gfx::GLFence {
EGLSyncKHR sync_; EGLSyncKHR sync_;
EGLDisplay display_; EGLDisplay display_;
scoped_refptr<gfx::GLContext::FlushEvent> flush_event_; scoped_refptr<GLContext::FlushEvent> flush_event_;
}; };
#endif // !OS_MACOSX #endif // !OS_MACOSX
// static // static
gfx::GLFence* CreateFence(bool flush) { GLFence* CreateFence(bool flush) {
DCHECK(gfx::GLContext::GetCurrent()) DCHECK(GLContext::GetCurrent())
<< "Trying to create fence with no context"; << "Trying to create fence with no context";
scoped_ptr<GLFence> fence;
// Prefer ARB_sync which supports server-side wait. // Prefer ARB_sync which supports server-side wait.
if (gfx::g_driver_gl.ext.b_GL_ARB_sync || if (g_driver_gl.ext.b_GL_ARB_sync ||
gfx::GLContext::GetCurrent()->GetVersionInfo()->is_es3) GetGLVersionInfo()->is_es3) {
return new GLFenceARBSync(flush); fence.reset(new GLFenceARBSync(flush));
#if !defined(OS_MACOSX) #if !defined(OS_MACOSX)
if (gfx::g_driver_egl.ext.b_EGL_KHR_fence_sync) } else if (g_driver_egl.ext.b_EGL_KHR_fence_sync) {
return new EGLFenceSync(flush); fence.reset(new EGLFenceSync(flush));
#endif #endif
if (gfx::g_driver_gl.ext.b_GL_NV_fence) } else if (g_driver_gl.ext.b_GL_NV_fence) {
return new GLFenceNVFence(flush); fence.reset(new GLFenceNVFence(flush));
return NULL; }
DCHECK_EQ(!!fence.get(), GLFence::IsSupported());
return fence.release();
} }
} // namespace } // namespace
namespace gfx {
GLFence::GLFence() { GLFence::GLFence() {
} }
GLFence::~GLFence() { GLFence::~GLFence() {
} }
bool GLFence::IsSupported() {
DCHECK(GetGLVersionInfo());
return g_driver_gl.ext.b_GL_ARB_sync || GetGLVersionInfo()->is_es3 ||
#if !defined(OS_MACOSX)
g_driver_egl.ext.b_EGL_KHR_fence_sync ||
#endif
g_driver_gl.ext.b_GL_NV_fence;
}
GLFence* GLFence::Create() { GLFence* GLFence::Create() {
return CreateFence(true); return CreateFence(true);
} }
......
...@@ -15,6 +15,7 @@ class GL_EXPORT GLFence { ...@@ -15,6 +15,7 @@ class GL_EXPORT GLFence {
GLFence(); GLFence();
virtual ~GLFence(); virtual ~GLFence();
static bool IsSupported();
static GLFence* Create(); static GLFence* Create();
// Creates a fence that is not guaranteed to signal until the current context // Creates a fence that is not guaranteed to signal until the current context
......
...@@ -288,6 +288,10 @@ void SetGLApiToNoContext() { ...@@ -288,6 +288,10 @@ void SetGLApiToNoContext() {
SetGLApi(g_no_context_gl); SetGLApi(g_no_context_gl);
} }
const GLVersionInfo* GetGLVersionInfo() {
return g_version_info;
}
void InitializeDynamicGLBindingsGL(GLContext* context) { void InitializeDynamicGLBindingsGL(GLContext* context) {
g_driver_gl.InitializeCustomDynamicBindings(context); g_driver_gl.InitializeCustomDynamicBindings(context);
DCHECK(context && context->IsCurrent(NULL) && !g_version_info); DCHECK(context && context->IsCurrent(NULL) && !g_version_info);
......
...@@ -17,6 +17,7 @@ namespace gfx { ...@@ -17,6 +17,7 @@ namespace gfx {
class GLContext; class GLContext;
class GLSurface; class GLSurface;
struct GLVersionInfo;
void InitializeStaticGLBindingsGL(); void InitializeStaticGLBindingsGL();
void InitializeDynamicGLBindingsGL(GLContext* context); void InitializeDynamicGLBindingsGL(GLContext* context);
...@@ -29,6 +30,7 @@ void ClearGLBindingsGL(); ...@@ -29,6 +30,7 @@ void ClearGLBindingsGL();
void SetGLToRealGLApi(); void SetGLToRealGLApi();
void SetGLApi(GLApi* api); void SetGLApi(GLApi* api);
void SetGLApiToNoContext(); void SetGLApiToNoContext();
const GLVersionInfo* GetGLVersionInfo();
class GLApiBase : public GLApi { class GLApiBase : public GLApi {
public: public:
......
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