Check GLFW window creation before discovering GL adapters

GLFW window creation can fail. If so, we should not attempt to
make the context current and create adapters on it.

Bug: dawn:1375
Change-Id: Ie1a94a42d1f56514b41a715add7a2b4eebb763f0
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87460
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Austin Eng 2022-04-20 20:56:15 +00:00 committed by Dawn LUCI CQ
parent 2363ad16ea
commit 775fee6b6a
1 changed files with 13 additions and 11 deletions

View File

@ -429,11 +429,12 @@ std::unique_ptr<dawn::native::Instance> DawnTestEnvironment::CreateInstanceAndDi
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
mOpenGLWindow = glfwCreateWindow(400, 400, "Dawn OpenGL test window", nullptr, nullptr);
if (mOpenGLWindow != nullptr) {
glfwMakeContextCurrent(mOpenGLWindow);
dawn::native::opengl::AdapterDiscoveryOptions adapterOptions;
adapterOptions.getProc = reinterpret_cast<void* (*)(const char*)>(glfwGetProcAddress);
instance->DiscoverAdapters(&adapterOptions);
}
#endif // DAWN_ENABLE_BACKEND_DESKTOP_GL
#ifdef DAWN_ENABLE_BACKEND_OPENGLES
@ -454,12 +455,13 @@ std::unique_ptr<dawn::native::Instance> DawnTestEnvironment::CreateInstanceAndDi
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
mOpenGLESWindow = glfwCreateWindow(400, 400, "Dawn OpenGLES test window", nullptr, nullptr);
if (mOpenGLESWindow != nullptr) {
glfwMakeContextCurrent(mOpenGLESWindow);
dawn::native::opengl::AdapterDiscoveryOptionsES adapterOptionsES;
adapterOptionsES.getProc = reinterpret_cast<void* (*)(const char*)>(glfwGetProcAddress);
instance->DiscoverAdapters(&adapterOptionsES);
glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE);
}
#endif // DAWN_ENABLE_BACKEND_OPENGLES
return instance;