From 2af3f87bb6f466c6557990835da27db3bcda3f82 Mon Sep 17 00:00:00 2001 From: Botond Ballo Date: Mon, 29 Aug 2016 16:51:43 -0400 Subject: [PATCH] Bug 1288686 - Avoid X11's |#define None 0L| intruding on other parts of the code. r=jrmuizel MozReview-Commit-ID: 9rD0KLTLg7l --HG-- extra : rebase_source : a537ba1913b6959e74fc4fcaf58f51f759cc5882 extra : source : 9278e13a7d664e787f763a7c21a32833700899e1 --- dom/plugins/base/npapi.h | 1 + dom/plugins/base/nsPluginInstanceOwner.cpp | 12 ++++----- dom/plugins/base/nsPluginNativeWindowGtk.cpp | 2 +- dom/plugins/ipc/PluginInstanceChild.cpp | 2 +- dom/plugins/test/testplugin/nptest_gtk2.cpp | 4 +-- gfx/2d/BorrowedContext.h | 5 ++-- gfx/2d/DrawTargetCairo.cpp | 6 ++--- gfx/gl/GLContextProviderGLX.cpp | 17 ++++++------ gfx/layers/ipc/ShadowLayerUtilsX11.cpp | 5 ++-- gfx/src/X11UndefineNone.h | 27 ++++++++++++++++++++ gfx/src/X11Util.cpp | 2 +- gfx/src/X11Util.h | 1 + gfx/src/moz.build | 1 + gfx/thebes/gfxXlibSurface.cpp | 14 +++++----- gfx/thebes/gfxXlibSurface.h | 7 ++--- widget/gtk/nsClipboard.cpp | 2 +- widget/gtk/nsWindow.cpp | 4 +-- 17 files changed, 73 insertions(+), 39 deletions(-) create mode 100644 gfx/src/X11UndefineNone.h diff --git a/dom/plugins/base/npapi.h b/dom/plugins/base/npapi.h index 798ee20aad6b..93600a80a1de 100644 --- a/dom/plugins/base/npapi.h +++ b/dom/plugins/base/npapi.h @@ -46,6 +46,7 @@ #if defined(MOZ_X11) #include #include +#include "X11UndefineNone.h" #endif #endif diff --git a/dom/plugins/base/nsPluginInstanceOwner.cpp b/dom/plugins/base/nsPluginInstanceOwner.cpp index 270d25ace62a..36049f71573a 100644 --- a/dom/plugins/base/nsPluginInstanceOwner.cpp +++ b/dom/plugins/base/nsPluginInstanceOwner.cpp @@ -2610,7 +2610,7 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) #ifdef MOZ_WIDGET_GTK Window root = GDK_ROOT_WINDOW(); #else - Window root = None; // Could XQueryTree, but this is not important. + Window root = X11None; // Could XQueryTree, but this is not important. #endif switch (anEvent.mMessage) { @@ -2628,7 +2628,7 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) event.y_root = rootPoint.y; event.state = XInputEventState(mouseEvent); // information lost - event.subwindow = None; + event.subwindow = X11None; event.mode = -1; event.detail = NotifyDetailNone; event.same_screen = True; @@ -2647,7 +2647,7 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) event.y_root = rootPoint.y; event.state = XInputEventState(mouseEvent); // information lost - event.subwindow = None; + event.subwindow = X11None; event.is_hint = NotifyNormal; event.same_screen = True; } @@ -2678,7 +2678,7 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) break; } // information lost: - event.subwindow = None; + event.subwindow = X11None; event.same_screen = True; } break; @@ -2722,7 +2722,7 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) // Information that could be obtained from pluginEvent but we may not // want to promise to provide: - event.subwindow = None; + event.subwindow = X11None; event.x = 0; event.y = 0; event.x_root = -1; @@ -2764,7 +2764,7 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) XAnyEvent& event = pluginEvent.xany; event.display = widget ? static_cast(widget->GetNativeData(NS_NATIVE_DISPLAY)) : nullptr; - event.window = None; // not a real window + event.window = X11None; // not a real window // information lost: event.serial = 0; event.send_event = False; diff --git a/dom/plugins/base/nsPluginNativeWindowGtk.cpp b/dom/plugins/base/nsPluginNativeWindowGtk.cpp index 1aa66c6b8f96..bfb9510e07c0 100644 --- a/dom/plugins/base/nsPluginNativeWindowGtk.cpp +++ b/dom/plugins/base/nsPluginNativeWindowGtk.cpp @@ -217,7 +217,7 @@ nsresult nsPluginNativeWindowGtk::CreateXEmbedWindow(bool aEnableXtFocus) { GdkVisual* gdkVisual = gdk_drawable_get_visual(gdkWindow); mWsInfo.depth = gdkVisual->depth; #else - mWsInfo.colormap = None; + mWsInfo.colormap = X11None; GdkVisual* gdkVisual = gdk_window_get_visual(gdkWindow); mWsInfo.depth = gdk_visual_get_depth(gdkVisual); #endif diff --git a/dom/plugins/ipc/PluginInstanceChild.cpp b/dom/plugins/ipc/PluginInstanceChild.cpp index 3dc717fac8ab..f51fbac8c7c7 100644 --- a/dom/plugins/ipc/PluginInstanceChild.cpp +++ b/dom/plugins/ipc/PluginInstanceChild.cpp @@ -1282,7 +1282,7 @@ PluginInstanceChild::AnswerNPP_SetWindow(const NPRemoteWindow& aWindow) } } - if (aWindow.visualID != None + if (aWindow.visualID != X11None && gtk_check_version(2, 12, 10) != nullptr) { // older // Workaround for a bug in Gtk+ (prior to 2.12.10) where deleting // a foreign GdkColormap will also free the XColormap. diff --git a/dom/plugins/test/testplugin/nptest_gtk2.cpp b/dom/plugins/test/testplugin/nptest_gtk2.cpp index e1ce16e97728..772dfb1e40fe 100644 --- a/dom/plugins/test/testplugin/nptest_gtk2.cpp +++ b/dom/plugins/test/testplugin/nptest_gtk2.cpp @@ -81,7 +81,7 @@ pluginInstanceInit(InstanceData* instanceData) instanceData->platformData->display = nullptr; instanceData->platformData->visual = nullptr; - instanceData->platformData->colormap = None; + instanceData->platformData->colormap = X11None; instanceData->platformData->plug = nullptr; return NPERR_NO_ERROR; @@ -97,7 +97,7 @@ pluginInstanceShutdown(InstanceData* instanceData) if (instanceData->hasWidget) { Window window = reinterpret_cast(instanceData->window.window); - if (window != None) { + if (window != X11None) { // This window XID should still be valid. // See bug 429604 and bug 454756. XWindowAttributes attributes; diff --git a/gfx/2d/BorrowedContext.h b/gfx/2d/BorrowedContext.h index 73b624c27d87..ee50bf7c7315 100644 --- a/gfx/2d/BorrowedContext.h +++ b/gfx/2d/BorrowedContext.h @@ -11,6 +11,7 @@ #ifdef MOZ_X11 #include #include +#include "X11UndefineNone.h" #endif struct _cairo; @@ -87,7 +88,7 @@ public: BorrowedXlibDrawable() : mDT(nullptr), mDisplay(nullptr), - mDrawable(None), + mDrawable(X11None), mScreen(nullptr), mVisual(nullptr), mXRenderFormat(nullptr) @@ -96,7 +97,7 @@ public: explicit BorrowedXlibDrawable(DrawTarget *aDT) : mDT(nullptr), mDisplay(nullptr), - mDrawable(None), + mDrawable(X11None), mScreen(nullptr), mVisual(nullptr), mXRenderFormat(nullptr) diff --git a/gfx/2d/DrawTargetCairo.cpp b/gfx/2d/DrawTargetCairo.cpp index bcd1f88ba732..7d2cc76b3b6c 100644 --- a/gfx/2d/DrawTargetCairo.cpp +++ b/gfx/2d/DrawTargetCairo.cpp @@ -2163,7 +2163,7 @@ DrawTargetCairo::Draw3DTransformedSurface(SourceSurface* aSurface, const Matrix4 0, nullptr); XRenderComposite(display, PictOpSrc, - srcPict, None, dstPict, + srcPict, X11None, dstPict, 0, 0, 0, 0, 0, 0, xformBounds.width, xformBounds.height); @@ -2313,7 +2313,7 @@ BorrowedXlibDrawable::Init(DrawTarget* aDT) MOZ_ASSERT(aDT, "Caller should check for nullptr"); MOZ_ASSERT(!mDT, "Can't initialize twice!"); mDT = aDT; - mDrawable = None; + mDrawable = X11None; #ifdef CAIRO_HAS_XLIB_SURFACE if (aDT->GetBackendType() != BackendType::CAIRO || @@ -2356,7 +2356,7 @@ BorrowedXlibDrawable::Finish() cairo_surface_t* surf = cairo_get_group_target(cairoDT->mContext); cairo_surface_mark_dirty(surf); if (mDrawable) { - mDrawable = None; + mDrawable = X11None; } } #endif diff --git a/gfx/gl/GLContextProviderGLX.cpp b/gfx/gl/GLContextProviderGLX.cpp index 638e55aaedf8..916c4016d0a5 100644 --- a/gfx/gl/GLContextProviderGLX.cpp +++ b/gfx/gl/GLContextProviderGLX.cpp @@ -11,6 +11,7 @@ #include #include +#include "X11UndefineNone.h" #include "mozilla/MathAlgorithms.h" #include "mozilla/StaticPtr.h" @@ -308,13 +309,13 @@ GLXPixmap GLXLibrary::CreatePixmap(gfxASurface* aSurface) { if (!SupportsTextureFromPixmap(aSurface)) { - return None; + return X11None; } gfxXlibSurface* xs = static_cast(aSurface); const XRenderPictFormat* format = xs->XRenderFormat(); if (!format || format->type != PictTypeDirect) { - return None; + return X11None; } const XRenderDirectFormat& direct = format->direct; int alphaSize = FloorLog2(direct.alphaMask + 1); @@ -327,7 +328,7 @@ GLXLibrary::CreatePixmap(gfxASurface* aSurface) (alphaSize ? LOCAL_GLX_BIND_TO_TEXTURE_RGBA_EXT : LOCAL_GLX_BIND_TO_TEXTURE_RGB_EXT), True, LOCAL_GLX_RENDER_TYPE, LOCAL_GLX_RGBA_BIT, - None }; + X11None }; int numConfigs = 0; Display* display = xs->XDisplay(); @@ -351,7 +352,7 @@ GLXLibrary::CreatePixmap(gfxASurface* aSurface) ~(redMask | greenMask | blueMask) != -1UL << format->depth; for (int i = 0; i < numConfigs; i++) { - int id = None; + int id = X11None; sGLXLibrary.xGetFBConfigAttrib(display, cfgs[i], LOCAL_GLX_VISUAL_ID, &id); Visual* visual; int depth; @@ -424,14 +425,14 @@ GLXLibrary::CreatePixmap(gfxASurface* aSurface) // caller should deal with this situation. NS_WARN_IF_FALSE(format->depth == 8, "[GLX] Couldn't find a FBConfig matching Pixmap format"); - return None; + return X11None; } int pixmapAttribs[] = { LOCAL_GLX_TEXTURE_TARGET_EXT, LOCAL_GLX_TEXTURE_2D_EXT, LOCAL_GLX_TEXTURE_FORMAT_EXT, (alphaSize ? LOCAL_GLX_TEXTURE_FORMAT_RGBA_EXT : LOCAL_GLX_TEXTURE_FORMAT_RGB_EXT), - None}; + X11None}; GLXPixmap glxpixmap = xCreatePixmap(display, cfgs[matchIndex], @@ -900,7 +901,7 @@ GLContextGLX::~GLContextGLX() #ifdef DEBUG bool success = #endif - mGLX->xMakeCurrent(mDisplay, None, nullptr); + mGLX->xMakeCurrent(mDisplay, X11None, nullptr); MOZ_ASSERT(success, "glXMakeCurrent failed to release GL context before we call " "glXDestroyContext!"); @@ -1242,7 +1243,7 @@ GLContextGLX::FindFBConfigForWindow(Display* display, int screen, Window window, #endif for (int i = 0; i < numConfigs; i++) { - int visid = None; + int visid = X11None; sGLXLibrary.xGetFBConfigAttrib(display, cfgs[i], LOCAL_GLX_VISUAL_ID, &visid); if (!visid) { continue; diff --git a/gfx/layers/ipc/ShadowLayerUtilsX11.cpp b/gfx/layers/ipc/ShadowLayerUtilsX11.cpp index f4d9c8d5c674..6b966005452d 100644 --- a/gfx/layers/ipc/ShadowLayerUtilsX11.cpp +++ b/gfx/layers/ipc/ShadowLayerUtilsX11.cpp @@ -11,6 +11,7 @@ #include // for XRenderPictFormat, etc #include // for PictFormat #include "cairo-xlib.h" +#include "X11UndefineNone.h" #include // for uint32_t #include "GLDefs.h" // for GLenum #include "gfxPlatform.h" // for gfxPlatform @@ -65,7 +66,7 @@ SurfaceDescriptorX11::SurfaceDescriptorX11(gfxXlibSurface* aSurf, bool aForwardGLX) : mId(aSurf->XDrawable()) , mSize(aSurf->GetSize()) - , mGLXPixmap(None) + , mGLXPixmap(X11None) { const XRenderPictFormat *pictFormat = aSurf->XRenderFormat(); if (pictFormat) { @@ -86,7 +87,7 @@ SurfaceDescriptorX11::SurfaceDescriptorX11(Drawable aDrawable, XID aFormatID, : mId(aDrawable) , mFormat(aFormatID) , mSize(aSize) - , mGLXPixmap(None) + , mGLXPixmap(X11None) { } already_AddRefed diff --git a/gfx/src/X11UndefineNone.h b/gfx/src/X11UndefineNone.h new file mode 100644 index 000000000000..cc0bf83255a5 --- /dev/null +++ b/gfx/src/X11UndefineNone.h @@ -0,0 +1,27 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef MOZILLA_GFX_X11UNDEFINENONE_H_ +#define MOZILLA_GFX_X11UNDEFINENONE_H_ + +// The header defines "None" as a macro that expands to "0L". +// This is terrible because many enumerations have an enumerator named "None". +// To work around this, we undefine the macro "None", and define a replacement +// macro named "X11None". +// Include this header after including X11 headers, where necessary. +#ifdef None +# undef None +# define X11None 0L +// also defines "RevertToNone" as a macro that expands to "(int)None". +// Since we are undefining "None", that stops working. To keep it working, +// we undefine "RevertToNone" and redefine it in terms of "X11None". +# ifdef RevertToNone +# undef RevertToNone +# define RevertToNone (int)X11None +# endif +#endif + +#endif /* MOZILLA_GFX_X11UNDEFINENONE_H_ */ diff --git a/gfx/src/X11Util.cpp b/gfx/src/X11Util.cpp index dd1f025d4d96..41f2a95db4ea 100644 --- a/gfx/src/X11Util.cpp +++ b/gfx/src/X11Util.cpp @@ -29,7 +29,7 @@ FindVisualAndDepth(Display* aDisplay, VisualID aVisualID, } } - NS_ASSERTION(aVisualID == None, "VisualID not on Screen."); + NS_ASSERTION(aVisualID == X11None, "VisualID not on Screen."); *aVisual = nullptr; *aDepth = 0; return; diff --git a/gfx/src/X11Util.h b/gfx/src/X11Util.h index 9868d7ca593a..dff855ff23f9 100644 --- a/gfx/src/X11Util.h +++ b/gfx/src/X11Util.h @@ -13,6 +13,7 @@ #if defined(MOZ_WIDGET_GTK) # include # include +# include "X11UndefineNone.h" #else # error Unknown toolkit #endif diff --git a/gfx/src/moz.build b/gfx/src/moz.build index dd519c7a944c..3678eee7abbd 100644 --- a/gfx/src/moz.build +++ b/gfx/src/moz.build @@ -39,6 +39,7 @@ EXPORTS += [ 'nsTransform2D.h', 'PingPongRegion.h', 'RegionBuilder.h', + 'X11UndefineNone.h' ] EXPORTS.mozilla += [ diff --git a/gfx/thebes/gfxXlibSurface.cpp b/gfx/thebes/gfxXlibSurface.cpp index 99206b87210b..12891c4549d5 100644 --- a/gfx/thebes/gfxXlibSurface.cpp +++ b/gfx/thebes/gfxXlibSurface.cpp @@ -25,7 +25,7 @@ using namespace mozilla::gfx; gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual) : mPixmapTaken(false), mDisplay(dpy), mDrawable(drawable) #if defined(GL_PROVIDER_GLX) - , mGLXPixmap(None) + , mGLXPixmap(X11None) #endif { const gfx::IntSize size = DoSizeQuery(); @@ -36,7 +36,7 @@ gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual) gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual, const gfx::IntSize& size) : mPixmapTaken(false), mDisplay(dpy), mDrawable(drawable) #if defined(GL_PROVIDER_GLX) - , mGLXPixmap(None) + , mGLXPixmap(X11None) #endif { NS_ASSERTION(Factory::CheckSurfaceSize(size, XLIB_IMAGE_SIDE_SIZE_LIMIT), @@ -51,7 +51,7 @@ gfxXlibSurface::gfxXlibSurface(Screen *screen, Drawable drawable, XRenderPictFor : mPixmapTaken(false), mDisplay(DisplayOfScreen(screen)), mDrawable(drawable) #if defined(GL_PROVIDER_GLX) - , mGLXPixmap(None) + , mGLXPixmap(X11None) #endif { NS_ASSERTION(Factory::CheckSurfaceSize(size, XLIB_IMAGE_SIDE_SIZE_LIMIT), @@ -67,7 +67,7 @@ gfxXlibSurface::gfxXlibSurface(Screen *screen, Drawable drawable, XRenderPictFor gfxXlibSurface::gfxXlibSurface(cairo_surface_t *csurf) : mPixmapTaken(false) #if defined(GL_PROVIDER_GLX) - , mGLXPixmap(None) + , mGLXPixmap(X11None) #endif { NS_PRECONDITION(cairo_surface_status(csurf) == 0, @@ -97,9 +97,9 @@ CreatePixmap(Screen *screen, const gfx::IntSize& size, unsigned int depth, Drawable relatedDrawable) { if (!Factory::CheckSurfaceSize(size, XLIB_IMAGE_SIDE_SIZE_LIMIT)) - return None; + return X11None; - if (relatedDrawable == None) { + if (relatedDrawable == X11None) { relatedDrawable = RootWindowOfScreen(screen); } Display *dpy = DisplayOfScreen(screen); @@ -274,7 +274,7 @@ gfxXlibSurface::Finish() #if defined(GL_PROVIDER_GLX) if (mPixmapTaken && mGLXPixmap) { gl::sGLXLibrary.DestroyPixmap(mDisplay, mGLXPixmap); - mGLXPixmap = None; + mGLXPixmap = X11None; } #endif gfxASurface::Finish(); diff --git a/gfx/thebes/gfxXlibSurface.h b/gfx/thebes/gfxXlibSurface.h index 8c5e8f9a36d2..499bc5e966b7 100644 --- a/gfx/thebes/gfxXlibSurface.h +++ b/gfx/thebes/gfxXlibSurface.h @@ -10,6 +10,7 @@ #include #include +#include "X11UndefineNone.h" #if defined(GL_PROVIDER_GLX) #include "GLXLibrary.h" @@ -46,13 +47,13 @@ public: // |screen| (if specified). static already_AddRefed Create(Screen *screen, Visual *visual, const mozilla::gfx::IntSize& size, - Drawable relatedDrawable = None); + Drawable relatedDrawable = X11None); static cairo_surface_t * CreateCairoSurface(Screen *screen, Visual *visual, const mozilla::gfx::IntSize& size, - Drawable relatedDrawable = None); + Drawable relatedDrawable = X11None); static already_AddRefed Create(Screen* screen, XRenderPictFormat *format, const mozilla::gfx::IntSize& size, - Drawable relatedDrawable = None); + Drawable relatedDrawable = X11None); virtual ~gfxXlibSurface(); diff --git a/widget/gtk/nsClipboard.cpp b/widget/gtk/nsClipboard.cpp index 9db14808f93c..23d1b62b9246 100644 --- a/widget/gtk/nsClipboard.cpp +++ b/widget/gtk/nsClipboard.cpp @@ -1030,7 +1030,7 @@ selection_request_filter(GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data) { XEvent *xevent = static_cast(gdk_xevent); if (xevent->xany.type == SelectionRequest) { - if (xevent->xselectionrequest.requestor == None) + if (xevent->xselectionrequest.requestor == X11None) return GDK_FILTER_REMOVE; GdkDisplay *display = gdk_x11_lookup_xdisplay( diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index ff6ea552d4da..7b55314d674f 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -452,7 +452,7 @@ nsWindow::nsWindow() mOldFocusWindow = 0; mXDisplay = nullptr; - mXWindow = None; + mXWindow = X11None; mXVisual = nullptr; mXDepth = 0; #endif /* MOZ_X11 */ @@ -4587,7 +4587,7 @@ nsWindow::ClearTransparencyBitmap() Display* xDisplay = GDK_WINDOW_XDISPLAY(mGdkWindow); Window xWindow = gdk_x11_window_get_xid(mGdkWindow); - XShapeCombineMask(xDisplay, xWindow, ShapeBounding, 0, 0, None, ShapeSet); + XShapeCombineMask(xDisplay, xWindow, ShapeBounding, 0, 0, X11None, ShapeSet); #endif }