Bug 1873507 - Replace ScopedXFree<GLXFBConfig> with MakeScopeExit. r=gfx-reviewers,aosmond

Differential Revision: https://phabricator.services.mozilla.com/D198089
This commit is contained in:
Kelsey Gilbert 2024-01-25 23:10:26 +00:00
parent c2b42175e7
commit 8a90064236
4 changed files with 15 additions and 28 deletions

View File

@ -26,7 +26,6 @@ class GLContextGLX : public GLContext {
// Finds a GLXFBConfig compatible with the provided window.
static bool FindFBConfigForWindow(
Display* display, int screen, Window window,
ScopedXFree<GLXFBConfig>* const out_scopedConfigArr,
GLXFBConfig* const out_config, int* const out_visid, bool aWebRender);
virtual ~GLContextGLX();

View File

@ -601,10 +601,9 @@ already_AddRefed<GLContext> CreateForWidget(Display* aXDisplay, Window aXWindow,
int xscreen = DefaultScreen(aXDisplay);
ScopedXFree<GLXFBConfig> cfgs;
GLXFBConfig config;
int visid;
if (!GLContextGLX::FindFBConfigForWindow(aXDisplay, xscreen, aXWindow, &cfgs,
if (!GLContextGLX::FindFBConfigForWindow(aXDisplay, xscreen, aXWindow,
&config, &visid,
aHardwareWebRender)) {
return nullptr;
@ -635,10 +634,7 @@ already_AddRefed<GLContext> GLContextProviderGLX::CreateForCompositorWidget(
}
static bool ChooseConfig(GLXLibrary* glx, Display* display, int screen,
ScopedXFree<GLXFBConfig>* const out_scopedConfigArr,
GLXFBConfig* const out_config, int* const out_visid) {
ScopedXFree<GLXFBConfig>& scopedConfigArr = *out_scopedConfigArr;
const int attribs[] = {
LOCAL_GLX_RENDER_TYPE,
LOCAL_GLX_RGBA_BIT,
@ -662,7 +658,12 @@ static bool ChooseConfig(GLXLibrary* glx, Display* display, int screen,
};
int numConfigs = 0;
scopedConfigArr = glx->fChooseFBConfig(display, screen, attribs, &numConfigs);
const auto scopedConfigArr = glx->fChooseFBConfig(display, screen, attribs, &numConfigs);
const auto freeConfigList = MakeScopeExit([&]() {
if (scopedConfigArr) {
XFree(scopedConfigArr);
}
});
if (!scopedConfigArr || !numConfigs) return false;
// Issues with glxChooseFBConfig selection and sorting:
@ -765,7 +766,6 @@ bool GLContextGLX::FindVisual(Display* display, int screen,
bool GLContextGLX::FindFBConfigForWindow(
Display* display, int screen, Window window,
ScopedXFree<GLXFBConfig>* const out_scopedConfigArr,
GLXFBConfig* const out_config, int* const out_visid, bool aWebRender) {
// XXX the visual ID is almost certainly the LOCAL_GLX_FBCONFIG_ID, so
// we could probably do this first and replace the glXGetFBConfigs
@ -776,7 +776,12 @@ bool GLContextGLX::FindFBConfigForWindow(
return false;
}
ScopedXFree<GLXFBConfig>& cfgs = *out_scopedConfigArr;
GLXFBConfig* cfgs = nullptr;
const auto freeConfigList = MakeScopeExit([&]() {
if (cfgs) {
XFree(cfgs);
}
});
int numConfigs;
const int webrenderAttribs[] = {LOCAL_GLX_ALPHA_SIZE,
windowAttrs.depth == 32 ? 8 : 0,
@ -850,10 +855,9 @@ static already_AddRefed<GLContextGLX> CreateOffscreenPixmapContext(
int screen = DefaultScreen(display->get());
ScopedXFree<GLXFBConfig> scopedConfigArr;
GLXFBConfig config;
int visid;
if (!ChooseConfig(glx, *display, screen, &scopedConfigArr, &config, &visid)) {
if (!ChooseConfig(glx, *display, screen, &config, &visid)) {
NS_WARNING("Failed to find a compatible config.");
return nullptr;
}

View File

@ -19,7 +19,6 @@
#endif
#include <string.h> // for memset
#include "mozilla/Scoped.h" // for SCOPED_TEMPLATE
namespace mozilla {
@ -56,20 +55,6 @@ void FindVisualAndDepth(Display* aDisplay, VisualID aVisualID, Visual** aVisual,
void FinishX(Display* aDisplay);
/**
* Invoke XFree() on a pointer to memory allocated by Xlib (if the
* pointer is nonnull) when this class goes out of scope.
*/
template <typename T>
struct ScopedXFreePtrTraits {
typedef T* type;
static T* empty() { return nullptr; }
static void release(T* ptr) {
if (ptr != nullptr) XFree(ptr);
}
};
SCOPED_TEMPLATE(ScopedXFree, ScopedXFreePtrTraits)
} // namespace mozilla
#endif // mozilla_X11Util_h

View File

@ -736,12 +736,11 @@ class GtkVsyncSource final : public VsyncSource {
Window root = DefaultRootWindow(mXDisplay);
int screen = DefaultScreen(mXDisplay);
ScopedXFree<GLXFBConfig> cfgs;
GLXFBConfig config;
int visid;
bool forWebRender = false;
if (!gl::GLContextGLX::FindFBConfigForWindow(
mXDisplay, screen, root, &cfgs, &config, &visid, forWebRender)) {
mXDisplay, screen, root, &config, &visid, forWebRender)) {
lock.NotifyAll();
return;
}