Commit 69a78e6d by Jonah Ryan-Davis Committed by Commit Bot

CGL: Add basic multithreading support

Adds first step to allowing multithreaded contexts: letting multiple threads use ANGLE as long as only one thread has a current context at a time. Bug: angleproject:4724 Bug: angleproject:4725 Bug: chromium:1087084 Change-Id: Ia6ca48c5fa838b93e49fc9ea259d626029439ca3 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2257273 Commit-Queue: Jonah Ryan-Davis <jonahr@google.com> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 4eb2f6dc
......@@ -9,6 +9,8 @@
#ifndef LIBANGLE_RENDERER_GL_CGL_DISPLAYCGL_H_
#define LIBANGLE_RENDERER_GL_CGL_DISPLAYCGL_H_
#include <thread>
#include "libANGLE/renderer/gl/DisplayGL.h"
struct _CGLContextObject;
......@@ -101,6 +103,7 @@ class DisplayCGL : public DisplayGL
egl::Display *mEGLDisplay;
CGLContextObj mContext;
std::unordered_map<std::thread::id, CGLContextObj> mCurrentContexts;
CGLPixelFormatObj mPixelFormat;
bool mSupportsGPUSwitching;
uint64_t mCurrentGPUID;
......
......@@ -184,6 +184,8 @@ egl::Error DisplayCGL::initialize(egl::Display *display)
CGLSetCurrentContext(mContext);
mCurrentContexts[std::this_thread::get_id()] = mContext;
// There is no equivalent getProcAddress in CGL so we open the dylib directly
void *handle = dlopen(kDefaultOpenGLDylibName, RTLD_NOW);
if (!handle)
......@@ -219,6 +221,7 @@ void DisplayCGL::terminate()
CGLDestroyPixelFormat(mPixelFormat);
mPixelFormat = nullptr;
}
mCurrentContexts.clear();
if (mContext != nullptr)
{
CGLSetCurrentContext(nullptr);
......@@ -238,6 +241,18 @@ egl::Error DisplayCGL::makeCurrent(egl::Surface *drawSurface,
gl::Context *context)
{
checkDiscreteGPUStatus();
// If the thread that's calling makeCurrent does not have the correct
// context current (either mContext or 0), we need to set it current.
CGLContextObj newContext = 0;
if (context)
{
newContext = mContext;
}
if (newContext != mCurrentContexts[std::this_thread::get_id()])
{
CGLSetCurrentContext(newContext);
mCurrentContexts[std::this_thread::get_id()] = newContext;
}
return DisplayGL::makeCurrent(drawSurface, readSurface, context);
}
......
......@@ -204,8 +204,8 @@ TEST_P(MultithreadingTest, MultiContextDraw)
TEST_P(MultithreadingTest, MultiCreateContext)
{
// Supported by WGL and GLX (https://anglebug.com/4725)
ANGLE_SKIP_TEST_IF(!IsWindows() && !IsLinux());
// Supported by CGL, GLX, and WGL (https://anglebug.com/4725)
ANGLE_SKIP_TEST_IF(!IsWindows() && !IsLinux() && !IsOSX());
EGLWindow *window = getEGLWindow();
EGLDisplay dpy = window->getDisplay();
......
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