Commit f4863b70 by Corentin Wallez

Implement swapInterval for EGL on GLX

BUG=angleproject:892 Change-Id: I80d8d67270662c7f2be893f4a8318fbc0926f1fc Reviewed-on: https://chromium-review.googlesource.com/272677Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 7c2acaf3
......@@ -236,6 +236,7 @@ egl::ConfigSet DisplayGLX::generateConfigs() const
// GLX_EXT_texture_from_pixmap is required for the "bind to rgb(a)" attributes
bool hasTextureFromPixmap = mGLX.hasExtension("GLX_EXT_texture_from_pixmap");
bool hasSwapControl = mGLX.hasExtension("GLX_EXT_swap_control");
int attribList[] =
{
......@@ -332,9 +333,17 @@ egl::ConfigSet DisplayGLX::generateConfigs() const
(glxDrawable & GLX_PBUFFER_BIT ? EGL_PBUFFER_BIT : 0) |
(glxDrawable & GLX_PIXMAP_BIT ? EGL_PIXMAP_BIT : 0);
// In GLX_EXT_swap_control querying these is done on a GLXWindow so we just set a default value.
config.maxSwapInterval = 1;
config.minSwapInterval = 1;
if (hasSwapControl)
{
// In GLX_EXT_swap_control querying these is done on a GLXWindow so we just set a default value.
config.minSwapInterval = 0;
config.maxSwapInterval = 4;
}
else
{
config.minSwapInterval = 1;
config.maxSwapInterval = 1;
}
// TODO(cwallez) wildly guessing these formats, another TODO says they should be removed anyway
config.renderTargetFormat = GL_RGBA8;
config.depthStencilFormat = GL_DEPTH24_STENCIL8;
......
......@@ -50,7 +50,8 @@ struct FunctionsGLX::GLXFunctionTable
createPbufferPtr(nullptr),
destroyPbufferPtr(nullptr),
queryDrawablePtr(nullptr),
createContextAttribsARBPtr(nullptr)
createContextAttribsARBPtr(nullptr),
swapIntervalEXTPtr(nullptr)
{
}
......@@ -79,6 +80,9 @@ struct FunctionsGLX::GLXFunctionTable
// GLX_ARB_create_context
PFNGLXCREATECONTEXTATTRIBSARBPROC createContextAttribsARBPtr;
// GLX_EXT_swap_control
PFNGLXSWAPINTERVALEXTPROC swapIntervalEXTPtr;
};
FunctionsGLX::FunctionsGLX()
......@@ -191,6 +195,14 @@ bool FunctionsGLX::initialize(Display *xDisplay, int screen, std::string *errorS
{
mFnPtrs->createContextAttribsARBPtr = nullptr;
}
if (hasExtension("GLX_EXT_swap_control"))
{
GET_PROC_OR_ERROR(&mFnPtrs->swapIntervalEXTPtr, "glXSwapIntervalEXT");
}
else
{
mFnPtrs->swapIntervalEXTPtr = nullptr;
}
#undef GET_PROC_OR_ERROR
......@@ -315,4 +327,9 @@ glx::Context FunctionsGLX::createContextAttribsARB(glx::FBConfig config, glx::Co
return reinterpret_cast<glx::Context>(ctx);
}
void FunctionsGLX::swapIntervalEXT(glx::Drawable drawable, int intervals) const
{
mFnPtrs->swapIntervalEXTPtr(mXDisplay, drawable, intervals);
}
}
......@@ -62,6 +62,9 @@ class FunctionsGLX
// GLX_ARB_create_context
glx::Context createContextAttribsARB(glx::FBConfig config, glx::Context shareContext, Bool direct, const int *attribList) const;
// GLX_EXT_swap_control
void swapIntervalEXT(glx::Drawable drawable, int interval) const;
private:
// So as to isolate GLX from angle we do not include angleutils.h and cannot
// use angle::NonCopyable so we replicated it here instead.
......
......@@ -26,7 +26,8 @@ WindowSurfaceGLX::WindowSurfaceGLX(const FunctionsGLX &glx, const DisplayGLX &gl
mGLXDisplay(glxDisplay),
mContext(context),
mFBConfig(fbConfig),
mGLXWindow(0)
mGLXWindow(0),
mMaxSwapInterval(1)
{
}
......@@ -87,6 +88,11 @@ egl::Error WindowSurfaceGLX::initialize()
0, visualInfo->depth, InputOutput, visual, attributeMask, &attributes);
mGLXWindow = mGLX.createWindow(mFBConfig, mWindow, nullptr);
if (mGLX.hasExtension("GLX_EXT_swap_control"))
{
mGLX.queryDrawable(mGLXWindow, GLX_MAX_SWAP_INTERVAL_EXT, &mMaxSwapInterval);
}
XMapWindow(mDisplay, mWindow);
XFlush(mDisplay);
......@@ -141,7 +147,12 @@ egl::Error WindowSurfaceGLX::releaseTexImage(EGLint buffer)
void WindowSurfaceGLX::setSwapInterval(EGLint interval)
{
// TODO(cwallez) WGL has this, implement it
if (mGLX.hasExtension("GLX_EXT_swap_control"))
{
// TODO(cwallez) error checking?
const int realInterval = std::min(interval, static_cast<int>(mMaxSwapInterval));
mGLX.swapIntervalEXT(mGLXWindow, realInterval);
}
}
EGLint WindowSurfaceGLX::getWidth() const
......
......@@ -50,6 +50,7 @@ class WindowSurfaceGLX : public SurfaceGL
glx::Context mContext;
glx::FBConfig mFBConfig;
glx::Window mGLXWindow;
unsigned int mMaxSwapInterval;
};
}
......
......@@ -145,6 +145,10 @@
#define GLX_AUX7_EXT 0x20E9
#define GLX_AUX8_EXT 0x20EA
#define GLX_AUX9_EXT 0x20EB
// GLX_EXT_swap_control
#define GLX_SWAP_INTERVAL_EXT 0x20F1
#define GLX_MAX_SWAP_INTERVAL_EXT 0x20F2
#endif // !defined(ANGLE_SKIP_GLX_DEFINES)
// GLX typedefs depend on the X headers
......
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