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(
context_->SetGLVersionString(normalized_init.gl_version.c_str());
context_->GLContextStubWithExtensions::MakeCurrent(surface_.get());
gl::GLSurfaceTestSupport::InitializeDynamicMockBindings(context_.get());
TestHelper::SetupContextGroupInitExpectations(
gl_.get(),
......
......@@ -37,7 +37,6 @@ void GpuServiceTest::SetUpWithGLVersion(const char* gl_version,
context_->SetGLVersionString(gl_version);
surface_ = new gl::GLSurfaceStub;
context_->MakeCurrent(surface_.get());
gl::GLSurfaceTestSupport::InitializeDynamicMockBindings(context_.get());
ran_setup_ = true;
}
......
......@@ -118,23 +118,12 @@ class GpuChannelTest : public GpuChannelTestCommon {
.Times(AnyNumber())
.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();
}
void TearDown() override {
GpuChannelTestCommon::TearDown();
stub_context_ = nullptr;
stub_surface_ = nullptr;
gl::MockGLInterface::SetGLInterface(nullptr);
gl::init::ClearGLBindings();
gl_interface_ = nullptr;
......@@ -192,8 +181,6 @@ class GpuChannelTest : public GpuChannelTestCommon {
private:
base::TestMessageLoop message_loop_;
std::unique_ptr<gl::MockGLInterface> gl_interface_;
scoped_refptr<gl::GLContextStub> stub_context_;
scoped_refptr<gl::GLSurfaceStub> stub_surface_;
};
#if defined(OS_WIN)
......
......@@ -179,12 +179,9 @@ bool GLContext::WasAllocatedUsingRobustnessExtension() {
return false;
}
bool GLContext::InitializeDynamicBindings() {
void GLContext::InitializeDynamicBindings() {
DCHECK(IsCurrent(nullptr));
bool initialized = InitializeDynamicGLBindings(GetGLImplementation(), this);
if (!initialized)
LOG(ERROR) << "Could not initialize dynamic bindings.";
return initialized;
InitializeDynamicGLBindingsGL(this);
}
bool GLContext::MakeVirtuallyCurrent(
......
......@@ -153,7 +153,7 @@ class GL_EXPORT GLContext : public base::RefCounted<GLContext> {
// Initialize function pointers to functions where the bound version depends
// on GL version or supported extensions. Should be called immediately after
// this context is made current.
bool InitializeDynamicBindings();
void InitializeDynamicBindings();
// Returns the last real (non-virtual) GLContext made current.
static GLContext* GetRealCurrent();
......
......@@ -232,9 +232,7 @@ bool GLContextCGL::MakeCurrent(GLSurface* surface) {
SetRealGLApi();
SetCurrent(surface);
if (!InitializeDynamicBindings()) {
return false;
}
InitializeDynamicBindings();
if (!surface->OnMakeCurrent(this)) {
LOG(ERROR) << "Unable to make gl context current.";
......
......@@ -132,9 +132,7 @@ bool GLContextEGL::MakeCurrent(GLSurface* surface) {
SetRealGLApi();
SetCurrent(surface);
if (!InitializeDynamicBindings()) {
return false;
}
InitializeDynamicBindings();
if (!surface->OnMakeCurrent(this)) {
LOG(ERROR) << "Could not make current.";
......
......@@ -114,10 +114,7 @@ bool GLContextGLX::MakeCurrent(GLSurface* surface) {
SetRealGLApi();
SetCurrent(surface);
if (!InitializeDynamicBindings()) {
Destroy();
return false;
}
InitializeDynamicBindings();
if (!surface->OnMakeCurrent(this)) {
LOG(ERROR) << "Could not make current.";
......
......@@ -83,9 +83,7 @@ bool GLContextOSMesa::MakeCurrent(GLSurface* surface) {
OSMesaPixelStore(OSMESA_Y_UP, 0);
SetCurrent(surface);
if (!InitializeDynamicBindings()) {
return false;
}
InitializeDynamicBindings();
if (!surface->OnMakeCurrent(this)) {
LOG(ERROR) << "Could not make current.";
......
......@@ -16,8 +16,9 @@ bool GLContextStub::Initialize(
}
bool GLContextStub::MakeCurrent(GLSurface* surface) {
SetCurrent(surface);
SetRealGLApi();
SetCurrent(surface);
InitializeDynamicBindings();
return true;
}
......
......@@ -103,9 +103,7 @@ bool GLContextWGL::MakeCurrent(GLSurface* surface) {
SetRealGLApi();
SetCurrent(surface);
if (!InitializeDynamicBindings()) {
return false;
}
InitializeDynamicBindings();
if (!surface->OnMakeCurrent(this)) {
LOG(ERROR) << "Could not make current.";
......
......@@ -46,11 +46,6 @@ typedef void* (WINAPI *GLGetProcAddressProc)(const char* name);
typedef void* (*GLGetProcAddressProc)(const char* name);
#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
// null draw bindings default to enabled, so that draw operations do nothing.
GL_EXPORT void InitializeNullDrawGLBindings();
......
......@@ -18,31 +18,6 @@ void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) {
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) {
switch (GetGLImplementation()) {
case kGLImplementationEGLGLES2:
......
......@@ -22,32 +22,6 @@ void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) {
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) {
return false;
}
......
......@@ -17,30 +17,6 @@ void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) {
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) {
switch (GetGLImplementation()) {
case kGLImplementationEGLGLES2:
......
......@@ -18,31 +18,6 @@ void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) {
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) {
switch (GetGLImplementation()) {
case kGLImplementationDesktopGL:
......
......@@ -19,31 +19,6 @@ void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) {
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) {
switch (GetGLImplementation()) {
case kGLImplementationDesktopGL:
......
......@@ -60,7 +60,6 @@ class GPUTimingTest : public testing::Test {
surface_ = new GLSurfaceStub;
context_->MakeCurrent(surface_.get());
gpu_timing_fake_queries_.Reset();
GLSurfaceTestSupport::InitializeDynamicMockBindings(context_.get());
setup_ = true;
}
......
......@@ -86,9 +86,4 @@ void GLSurfaceTestSupport::InitializeOneOffWithMockBindings() {
InitializeOneOffImplementation(kGLImplementationMockGL, false);
}
// static
void GLSurfaceTestSupport::InitializeDynamicMockBindings(GLContext* context) {
CHECK(InitializeDynamicGLBindings(kGLImplementationMockGL, context));
}
} // namespace gl
......@@ -17,7 +17,6 @@ class GLSurfaceTestSupport {
static void InitializeOneOffImplementation(GLImplementation impl,
bool fallback_to_osmesa);
static void InitializeOneOffWithMockBindings();
static void InitializeDynamicMockBindings(GLContext* context);
};
} // 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