Commit 608429d9 authored by piman's avatar piman Committed by Commit bot

Make dynamic mock bindings initialization consistent with other GL implementations

Various cleanup:
- Every context type except GLContextStub calls InitializeDynamicBindings in
  MakeCurrent. Make it consistent.
- In turn, it means we don't need an explicit InitializeDynamicMockBindings, so
  remove it.
- In some tests, we were creating a context just to be able to call
  InitializeDynamicMockBindings. This is not necessary any more - dynamic
  bindings will be initalized as the first useful context is made current
- Realizing that InitializeDynamicGLBindings is always called with a real
  context, remove the special cases for mock bindings. This makes it consistent
  with other GL implementations
- In turn InitializeDynamicGLBindings always does exactly
  InitializeDynamicGLBindingsGL for valid GLImplementations, and is only called
  with a valid GLImplementation, simplify. It also means it can't fail.

BUG=None
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_optional_gpu_tests_rel;tryserver.chromium.mac:mac_optional_gpu_tests_rel;tryserver.chromium.win:win_optional_gpu_tests_rel

Review-Url: https://codereview.chromium.org/2129043003
Cr-Commit-Position: refs/heads/master@{#404548}
parent 86a18e4e
...@@ -215,7 +215,6 @@ void GLES2DecoderTestBase::InitDecoderWithCommandLine( ...@@ -215,7 +215,6 @@ void GLES2DecoderTestBase::InitDecoderWithCommandLine(
context_->SetGLVersionString(normalized_init.gl_version.c_str()); context_->SetGLVersionString(normalized_init.gl_version.c_str());
context_->GLContextStubWithExtensions::MakeCurrent(surface_.get()); context_->GLContextStubWithExtensions::MakeCurrent(surface_.get());
gl::GLSurfaceTestSupport::InitializeDynamicMockBindings(context_.get());
TestHelper::SetupContextGroupInitExpectations( TestHelper::SetupContextGroupInitExpectations(
gl_.get(), gl_.get(),
......
...@@ -37,7 +37,6 @@ void GpuServiceTest::SetUpWithGLVersion(const char* gl_version, ...@@ -37,7 +37,6 @@ void GpuServiceTest::SetUpWithGLVersion(const char* gl_version,
context_->SetGLVersionString(gl_version); context_->SetGLVersionString(gl_version);
surface_ = new gl::GLSurfaceStub; surface_ = new gl::GLSurfaceStub;
context_->MakeCurrent(surface_.get()); context_->MakeCurrent(surface_.get());
gl::GLSurfaceTestSupport::InitializeDynamicMockBindings(context_.get());
ran_setup_ = true; ran_setup_ = true;
} }
......
...@@ -118,23 +118,12 @@ class GpuChannelTest : public GpuChannelTestCommon { ...@@ -118,23 +118,12 @@ class GpuChannelTest : public GpuChannelTestCommon {
.Times(AnyNumber()) .Times(AnyNumber())
.WillRepeatedly(Return(GL_FRAMEBUFFER_COMPLETE)); .WillRepeatedly(Return(GL_FRAMEBUFFER_COMPLETE));
// Dynamic bindings must be set up for the GLES2DecoderImpl, which requires
// a GLContext. Use a GLContextStub which does nothing but call through to
// our |gl_interface| above.
stub_context_ = new gl::GLContextStub;
stub_surface_ = new gl::GLSurfaceStub;
stub_context_->MakeCurrent(stub_surface_.get());
gl::GLSurfaceTestSupport::InitializeDynamicMockBindings(
stub_context_.get());
GpuChannelTestCommon::SetUp(); GpuChannelTestCommon::SetUp();
} }
void TearDown() override { void TearDown() override {
GpuChannelTestCommon::TearDown(); GpuChannelTestCommon::TearDown();
stub_context_ = nullptr;
stub_surface_ = nullptr;
gl::MockGLInterface::SetGLInterface(nullptr); gl::MockGLInterface::SetGLInterface(nullptr);
gl::init::ClearGLBindings(); gl::init::ClearGLBindings();
gl_interface_ = nullptr; gl_interface_ = nullptr;
...@@ -192,8 +181,6 @@ class GpuChannelTest : public GpuChannelTestCommon { ...@@ -192,8 +181,6 @@ class GpuChannelTest : public GpuChannelTestCommon {
private: private:
base::TestMessageLoop message_loop_; base::TestMessageLoop message_loop_;
std::unique_ptr<gl::MockGLInterface> gl_interface_; std::unique_ptr<gl::MockGLInterface> gl_interface_;
scoped_refptr<gl::GLContextStub> stub_context_;
scoped_refptr<gl::GLSurfaceStub> stub_surface_;
}; };
#if defined(OS_WIN) #if defined(OS_WIN)
......
...@@ -179,12 +179,9 @@ bool GLContext::WasAllocatedUsingRobustnessExtension() { ...@@ -179,12 +179,9 @@ bool GLContext::WasAllocatedUsingRobustnessExtension() {
return false; return false;
} }
bool GLContext::InitializeDynamicBindings() { void GLContext::InitializeDynamicBindings() {
DCHECK(IsCurrent(nullptr)); DCHECK(IsCurrent(nullptr));
bool initialized = InitializeDynamicGLBindings(GetGLImplementation(), this); InitializeDynamicGLBindingsGL(this);
if (!initialized)
LOG(ERROR) << "Could not initialize dynamic bindings.";
return initialized;
} }
bool GLContext::MakeVirtuallyCurrent( bool GLContext::MakeVirtuallyCurrent(
......
...@@ -153,7 +153,7 @@ class GL_EXPORT GLContext : public base::RefCounted<GLContext> { ...@@ -153,7 +153,7 @@ class GL_EXPORT GLContext : public base::RefCounted<GLContext> {
// Initialize function pointers to functions where the bound version depends // Initialize function pointers to functions where the bound version depends
// on GL version or supported extensions. Should be called immediately after // on GL version or supported extensions. Should be called immediately after
// this context is made current. // this context is made current.
bool InitializeDynamicBindings(); void InitializeDynamicBindings();
// Returns the last real (non-virtual) GLContext made current. // Returns the last real (non-virtual) GLContext made current.
static GLContext* GetRealCurrent(); static GLContext* GetRealCurrent();
......
...@@ -232,9 +232,7 @@ bool GLContextCGL::MakeCurrent(GLSurface* surface) { ...@@ -232,9 +232,7 @@ bool GLContextCGL::MakeCurrent(GLSurface* surface) {
SetRealGLApi(); SetRealGLApi();
SetCurrent(surface); SetCurrent(surface);
if (!InitializeDynamicBindings()) { InitializeDynamicBindings();
return false;
}
if (!surface->OnMakeCurrent(this)) { if (!surface->OnMakeCurrent(this)) {
LOG(ERROR) << "Unable to make gl context current."; LOG(ERROR) << "Unable to make gl context current.";
......
...@@ -132,9 +132,7 @@ bool GLContextEGL::MakeCurrent(GLSurface* surface) { ...@@ -132,9 +132,7 @@ bool GLContextEGL::MakeCurrent(GLSurface* surface) {
SetRealGLApi(); SetRealGLApi();
SetCurrent(surface); SetCurrent(surface);
if (!InitializeDynamicBindings()) { InitializeDynamicBindings();
return false;
}
if (!surface->OnMakeCurrent(this)) { if (!surface->OnMakeCurrent(this)) {
LOG(ERROR) << "Could not make current."; LOG(ERROR) << "Could not make current.";
......
...@@ -114,10 +114,7 @@ bool GLContextGLX::MakeCurrent(GLSurface* surface) { ...@@ -114,10 +114,7 @@ bool GLContextGLX::MakeCurrent(GLSurface* surface) {
SetRealGLApi(); SetRealGLApi();
SetCurrent(surface); SetCurrent(surface);
if (!InitializeDynamicBindings()) { InitializeDynamicBindings();
Destroy();
return false;
}
if (!surface->OnMakeCurrent(this)) { if (!surface->OnMakeCurrent(this)) {
LOG(ERROR) << "Could not make current."; LOG(ERROR) << "Could not make current.";
......
...@@ -83,9 +83,7 @@ bool GLContextOSMesa::MakeCurrent(GLSurface* surface) { ...@@ -83,9 +83,7 @@ bool GLContextOSMesa::MakeCurrent(GLSurface* surface) {
OSMesaPixelStore(OSMESA_Y_UP, 0); OSMesaPixelStore(OSMESA_Y_UP, 0);
SetCurrent(surface); SetCurrent(surface);
if (!InitializeDynamicBindings()) { InitializeDynamicBindings();
return false;
}
if (!surface->OnMakeCurrent(this)) { if (!surface->OnMakeCurrent(this)) {
LOG(ERROR) << "Could not make current."; LOG(ERROR) << "Could not make current.";
......
...@@ -16,8 +16,9 @@ bool GLContextStub::Initialize( ...@@ -16,8 +16,9 @@ bool GLContextStub::Initialize(
} }
bool GLContextStub::MakeCurrent(GLSurface* surface) { bool GLContextStub::MakeCurrent(GLSurface* surface) {
SetCurrent(surface);
SetRealGLApi(); SetRealGLApi();
SetCurrent(surface);
InitializeDynamicBindings();
return true; return true;
} }
......
...@@ -103,9 +103,7 @@ bool GLContextWGL::MakeCurrent(GLSurface* surface) { ...@@ -103,9 +103,7 @@ bool GLContextWGL::MakeCurrent(GLSurface* surface) {
SetRealGLApi(); SetRealGLApi();
SetCurrent(surface); SetCurrent(surface);
if (!InitializeDynamicBindings()) { InitializeDynamicBindings();
return false;
}
if (!surface->OnMakeCurrent(this)) { if (!surface->OnMakeCurrent(this)) {
LOG(ERROR) << "Could not make current."; LOG(ERROR) << "Could not make current.";
......
...@@ -46,11 +46,6 @@ typedef void* (WINAPI *GLGetProcAddressProc)(const char* name); ...@@ -46,11 +46,6 @@ typedef void* (WINAPI *GLGetProcAddressProc)(const char* name);
typedef void* (*GLGetProcAddressProc)(const char* name); typedef void* (*GLGetProcAddressProc)(const char* name);
#endif #endif
// Initialize function bindings that depend on the context for a GL
// implementation.
GL_EXPORT bool InitializeDynamicGLBindings(GLImplementation implementation,
GLContext* context);
// Initialize stub methods for drawing operations in the GL bindings. The // Initialize stub methods for drawing operations in the GL bindings. The
// null draw bindings default to enabled, so that draw operations do nothing. // null draw bindings default to enabled, so that draw operations do nothing.
GL_EXPORT void InitializeNullDrawGLBindings(); GL_EXPORT void InitializeNullDrawGLBindings();
......
...@@ -18,31 +18,6 @@ void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { ...@@ -18,31 +18,6 @@ void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) {
impls->push_back(kGLImplementationOSMesaGL); impls->push_back(kGLImplementationOSMesaGL);
} }
bool InitializeDynamicGLBindings(GLImplementation implementation,
GLContext* context) {
switch (implementation) {
case kGLImplementationEGLGLES2:
case kGLImplementationOSMesaGL:
InitializeDynamicGLBindingsGL(context);
break;
case kGLImplementationMockGL:
if (!context) {
scoped_refptr<GLContextStubWithExtensions> mock_context(
new GLContextStubWithExtensions());
mock_context->SetGLVersionString("opengl es 3.0");
InitializeDynamicGLBindingsGL(mock_context.get());
} else {
InitializeDynamicGLBindingsGL(context);
}
break;
default:
NOTREACHED() << "InitializeDynamicGLBindings on Android";
return false;
}
return true;
}
bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) {
switch (GetGLImplementation()) { switch (GetGLImplementation()) {
case kGLImplementationEGLGLES2: case kGLImplementationEGLGLES2:
......
...@@ -22,32 +22,6 @@ void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { ...@@ -22,32 +22,6 @@ void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) {
impls->push_back(kGLImplementationOSMesaGL); impls->push_back(kGLImplementationOSMesaGL);
} }
bool InitializeDynamicGLBindings(GLImplementation implementation,
GLContext* context) {
switch (implementation) {
case kGLImplementationOSMesaGL:
case kGLImplementationDesktopGL:
case kGLImplementationDesktopGLCoreProfile:
case kGLImplementationAppleGL:
InitializeDynamicGLBindingsGL(context);
break;
case kGLImplementationMockGL:
if (!context) {
scoped_refptr<GLContextStubWithExtensions> mock_context(
new GLContextStubWithExtensions());
mock_context->SetGLVersionString("3.0");
InitializeDynamicGLBindingsGL(mock_context.get());
} else {
InitializeDynamicGLBindingsGL(context);
}
break;
default:
return false;
}
return true;
}
bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) {
return false; return false;
} }
......
...@@ -17,30 +17,6 @@ void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { ...@@ -17,30 +17,6 @@ void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) {
impls->push_back(kGLImplementationOSMesaGL); impls->push_back(kGLImplementationOSMesaGL);
} }
bool InitializeDynamicGLBindings(GLImplementation implementation,
GLContext* context) {
switch (implementation) {
case kGLImplementationOSMesaGL:
case kGLImplementationEGLGLES2:
InitializeDynamicGLBindingsGL(context);
break;
case kGLImplementationMockGL:
if (!context) {
scoped_refptr<GLContextStubWithExtensions> mock_context(
new GLContextStubWithExtensions());
mock_context->SetGLVersionString("3.0");
InitializeDynamicGLBindingsGL(mock_context.get());
} else {
InitializeDynamicGLBindingsGL(context);
}
break;
default:
return false;
}
return true;
}
bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) {
switch (GetGLImplementation()) { switch (GetGLImplementation()) {
case kGLImplementationEGLGLES2: case kGLImplementationEGLGLES2:
......
...@@ -18,31 +18,6 @@ void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { ...@@ -18,31 +18,6 @@ void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) {
impls->push_back(kGLImplementationOSMesaGL); impls->push_back(kGLImplementationOSMesaGL);
} }
bool InitializeDynamicGLBindings(GLImplementation implementation,
GLContext* context) {
switch (implementation) {
case kGLImplementationOSMesaGL:
case kGLImplementationEGLGLES2:
case kGLImplementationDesktopGL:
InitializeDynamicGLBindingsGL(context);
break;
case kGLImplementationMockGL:
if (!context) {
scoped_refptr<GLContextStubWithExtensions> mock_context(
new GLContextStubWithExtensions());
mock_context->SetGLVersionString("3.0");
InitializeDynamicGLBindingsGL(mock_context.get());
} else {
InitializeDynamicGLBindingsGL(context);
}
break;
default:
return false;
}
return true;
}
bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) {
switch (GetGLImplementation()) { switch (GetGLImplementation()) {
case kGLImplementationDesktopGL: case kGLImplementationDesktopGL:
......
...@@ -19,31 +19,6 @@ void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { ...@@ -19,31 +19,6 @@ void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) {
impls->push_back(kGLImplementationOSMesaGL); impls->push_back(kGLImplementationOSMesaGL);
} }
bool InitializeDynamicGLBindings(GLImplementation implementation,
GLContext* context) {
switch (implementation) {
case kGLImplementationOSMesaGL:
case kGLImplementationDesktopGL:
case kGLImplementationEGLGLES2:
InitializeDynamicGLBindingsGL(context);
break;
case kGLImplementationMockGL:
if (!context) {
scoped_refptr<GLContextStubWithExtensions> mock_context(
new GLContextStubWithExtensions());
mock_context->SetGLVersionString("3.0");
InitializeDynamicGLBindingsGL(mock_context.get());
} else {
InitializeDynamicGLBindingsGL(context);
}
break;
default:
return false;
}
return true;
}
bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) {
switch (GetGLImplementation()) { switch (GetGLImplementation()) {
case kGLImplementationDesktopGL: case kGLImplementationDesktopGL:
......
...@@ -60,7 +60,6 @@ class GPUTimingTest : public testing::Test { ...@@ -60,7 +60,6 @@ class GPUTimingTest : public testing::Test {
surface_ = new GLSurfaceStub; surface_ = new GLSurfaceStub;
context_->MakeCurrent(surface_.get()); context_->MakeCurrent(surface_.get());
gpu_timing_fake_queries_.Reset(); gpu_timing_fake_queries_.Reset();
GLSurfaceTestSupport::InitializeDynamicMockBindings(context_.get());
setup_ = true; setup_ = true;
} }
......
...@@ -86,9 +86,4 @@ void GLSurfaceTestSupport::InitializeOneOffWithMockBindings() { ...@@ -86,9 +86,4 @@ void GLSurfaceTestSupport::InitializeOneOffWithMockBindings() {
InitializeOneOffImplementation(kGLImplementationMockGL, false); InitializeOneOffImplementation(kGLImplementationMockGL, false);
} }
// static
void GLSurfaceTestSupport::InitializeDynamicMockBindings(GLContext* context) {
CHECK(InitializeDynamicGLBindings(kGLImplementationMockGL, context));
}
} // namespace gl } // namespace gl
...@@ -17,7 +17,6 @@ class GLSurfaceTestSupport { ...@@ -17,7 +17,6 @@ class GLSurfaceTestSupport {
static void InitializeOneOffImplementation(GLImplementation impl, static void InitializeOneOffImplementation(GLImplementation impl,
bool fallback_to_osmesa); bool fallback_to_osmesa);
static void InitializeOneOffWithMockBindings(); static void InitializeOneOffWithMockBindings();
static void InitializeDynamicMockBindings(GLContext* context);
}; };
} // namespace gl } // namespace gl
......
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