Bug 1732443 - Remove remaining XRender leftovers,r=emilio,stransky

The few cases where we still use Xlib most likely benefit little
from Xrender. Lets drop the support for it.

Differential Revision: https://phabricator.services.mozilla.com/D126970
This commit is contained in:
Robert Mader 2021-09-30 14:14:13 +00:00
Родитель 0889ec3bb3
Коммит ea68cb4546
8 изменённых файлов: 14 добавлений и 316 удалений

Просмотреть файл

@ -1029,7 +1029,6 @@ if CONFIG['MOZ_X11']:
'X11/extensions/Xdamage.h',
'X11/extensions/Xfixes.h',
'X11/extensions/Xrandr.h',
'X11/extensions/Xrender.h',
'X11/extensions/XShm.h',
'X11/ImUtil.h',
'X11/Intrinsic.h',

Просмотреть файл

@ -10,7 +10,6 @@
#include "2D.h"
#ifdef MOZ_X11
# include <X11/extensions/Xrender.h>
# include <X11/Xlib.h>
# include "X11UndefineNone.h"
#endif
@ -33,16 +32,14 @@ class BorrowedXlibDrawable {
mDisplay(nullptr),
mDrawable(X11None),
mScreen(nullptr),
mVisual(nullptr),
mXRenderFormat(nullptr) {}
mVisual(nullptr) {}
explicit BorrowedXlibDrawable(DrawTarget* aDT)
: mDT(nullptr),
mDisplay(nullptr),
mDrawable(X11None),
mScreen(nullptr),
mVisual(nullptr),
mXRenderFormat(nullptr) {
mVisual(nullptr) {
Init(aDT);
}
@ -67,15 +64,12 @@ class BorrowedXlibDrawable {
IntSize GetSize() const { return mSize; }
Point GetOffset() const { return mOffset; }
XRenderPictFormat* GetXRenderFormat() const { return mXRenderFormat; }
private:
DrawTarget* mDT;
Display* mDisplay;
Drawable mDrawable;
Screen* mScreen;
Visual* mVisual;
XRenderPictFormat* mXRenderFormat;
IntSize mSize;
Point mOffset;
};

Просмотреть файл

@ -34,7 +34,6 @@
#ifdef CAIRO_HAS_XLIB_SURFACE
# include "cairo-xlib.h"
# include "cairo-xlib-xrender.h"
#endif
#ifdef CAIRO_HAS_WIN32_SURFACE
@ -1702,101 +1701,9 @@ already_AddRefed<SourceSurface> DrawTargetCairo::CreateSourceSurfaceFromData(
return source_surf.forget();
}
#ifdef CAIRO_HAS_XLIB_SURFACE
static cairo_user_data_key_t gDestroyPixmapKey;
struct DestroyPixmapClosure {
DestroyPixmapClosure(Drawable d, Screen* s) : mPixmap(d), mScreen(s) {}
~DestroyPixmapClosure() { XFreePixmap(DisplayOfScreen(mScreen), mPixmap); }
Drawable mPixmap;
Screen* mScreen;
};
static void DestroyPixmap(void* data) {
delete static_cast<DestroyPixmapClosure*>(data);
}
#endif
already_AddRefed<SourceSurface> DrawTargetCairo::OptimizeSourceSurface(
SourceSurface* aSurface) const {
RefPtr<SourceSurface> surface(aSurface);
#ifdef CAIRO_HAS_XLIB_SURFACE
cairo_surface_type_t ctype = cairo_surface_get_type(mSurface);
if (aSurface->GetType() == SurfaceType::CAIRO &&
cairo_surface_get_type(
static_cast<SourceSurfaceCairo*>(aSurface)->GetSurface()) == ctype) {
return surface.forget();
}
if (ctype != CAIRO_SURFACE_TYPE_XLIB) {
return surface.forget();
}
IntSize size = aSurface->GetSize();
if (!size.width || !size.height) {
return surface.forget();
}
// Although the dimension parameters in the xCreatePixmapReq wire protocol are
// 16-bit unsigned integers, the server's CreatePixmap returns BadAlloc if
// either dimension cannot be represented by a 16-bit *signed* integer.
# define XLIB_IMAGE_SIDE_SIZE_LIMIT 0x7fff
if (size.width > XLIB_IMAGE_SIDE_SIZE_LIMIT ||
size.height > XLIB_IMAGE_SIDE_SIZE_LIMIT) {
return surface.forget();
}
SurfaceFormat format = aSurface->GetFormat();
Screen* screen = cairo_xlib_surface_get_screen(mSurface);
Display* dpy = DisplayOfScreen(screen);
XRenderPictFormat* xrenderFormat = nullptr;
switch (format) {
case SurfaceFormat::A8R8G8B8_UINT32:
xrenderFormat = XRenderFindStandardFormat(dpy, PictStandardARGB32);
break;
case SurfaceFormat::X8R8G8B8_UINT32:
xrenderFormat = XRenderFindStandardFormat(dpy, PictStandardRGB24);
break;
case SurfaceFormat::A8:
xrenderFormat = XRenderFindStandardFormat(dpy, PictStandardA8);
break;
default:
return surface.forget();
}
if (!xrenderFormat) {
return surface.forget();
}
Drawable pixmap = XCreatePixmap(dpy, RootWindowOfScreen(screen), size.width,
size.height, xrenderFormat->depth);
if (!pixmap) {
return surface.forget();
}
auto closure = MakeUnique<DestroyPixmapClosure>(pixmap, screen);
ScopedCairoSurface csurf(cairo_xlib_surface_create_with_xrender_format(
dpy, pixmap, screen, xrenderFormat, size.width, size.height));
if (!csurf || cairo_surface_status(csurf)) {
return surface.forget();
}
cairo_surface_set_user_data(csurf, &gDestroyPixmapKey, closure.release(),
DestroyPixmap);
RefPtr<DrawTargetCairo> dt = new DrawTargetCairo();
if (!dt->Init(csurf, size, &format)) {
return surface.forget();
}
dt->CopySurface(aSurface, IntRect(0, 0, size.width, size.height),
IntPoint(0, 0));
dt->Flush();
surface = new SourceSurfaceCairo(csurf, size, format);
#endif
return surface.forget();
}
@ -1954,129 +1861,9 @@ already_AddRefed<DrawTarget> DrawTargetCairo::CreateShadowDrawTarget(
return nullptr;
}
#ifdef CAIRO_HAS_XLIB_SURFACE
static inline bool GfxMatrixToPixmanTransform(const Matrix4x4& aMatrix,
pixman_transform* aResult) {
pixman_f_transform fTransform = {{{aMatrix._11, aMatrix._21, aMatrix._41},
{aMatrix._12, aMatrix._22, aMatrix._42},
{aMatrix._14, aMatrix._24, aMatrix._44}}};
return pixman_transform_from_pixman_f_transform(aResult, &fTransform);
}
static bool gXRenderInitialized = false;
static bool gXRenderHasTransform = false;
static bool SupportsXRender(cairo_surface_t* surface) {
if (!surface || cairo_surface_get_type(surface) != CAIRO_SURFACE_TYPE_XLIB ||
!cairo_xlib_surface_get_xrender_format(surface)) {
return false;
}
if (gXRenderInitialized) {
return true;
}
gXRenderInitialized = true;
cairo_device_t* device = cairo_surface_get_device(surface);
if (cairo_device_acquire(device) != CAIRO_STATUS_SUCCESS) {
return false;
}
Display* display = cairo_xlib_surface_get_display(surface);
int major, minor;
if (XRenderQueryVersion(display, &major, &minor)) {
if (major > 0 || (major == 0 && minor >= 6)) {
gXRenderHasTransform = true;
}
}
cairo_device_release(device);
return true;
}
#endif
bool DrawTargetCairo::Draw3DTransformedSurface(SourceSurface* aSurface,
const Matrix4x4& aMatrix) {
#if CAIRO_HAS_XLIB_SURFACE
cairo_surface_t* srcSurf =
aSurface->GetType() == SurfaceType::CAIRO
? static_cast<SourceSurfaceCairo*>(aSurface)->GetSurface()
: nullptr;
if (!SupportsXRender(srcSurf) || !gXRenderHasTransform) {
return DrawTarget::Draw3DTransformedSurface(aSurface, aMatrix);
}
Matrix4x4 fullMat = aMatrix * Matrix4x4::From2D(mTransform);
IntRect xformBounds = RoundedOut(fullMat.TransformAndClipBounds(
Rect(Point(0, 0), Size(aSurface->GetSize())),
Rect(Point(0, 0), Size(GetSize()))));
if (xformBounds.IsEmpty()) {
return true;
}
fullMat.PostTranslate(-xformBounds.X(), -xformBounds.Y(), 0);
if (!fullMat.Invert()) {
return false;
}
pixman_transform xform;
if (!GfxMatrixToPixmanTransform(fullMat, &xform)) {
return false;
}
cairo_surface_t* xformSurf =
cairo_surface_create_similar(srcSurf, CAIRO_CONTENT_COLOR_ALPHA,
xformBounds.Width(), xformBounds.Height());
if (!SupportsXRender(xformSurf)) {
cairo_surface_destroy(xformSurf);
return false;
}
cairo_device_t* device = cairo_surface_get_device(xformSurf);
if (cairo_device_acquire(device) != CAIRO_STATUS_SUCCESS) {
cairo_surface_destroy(xformSurf);
return false;
}
Display* display = cairo_xlib_surface_get_display(xformSurf);
Picture srcPict = XRenderCreatePicture(
display, cairo_xlib_surface_get_drawable(srcSurf),
cairo_xlib_surface_get_xrender_format(srcSurf), 0, nullptr);
XRenderSetPictureFilter(display, srcPict, FilterBilinear, nullptr, 0);
XRenderSetPictureTransform(display, srcPict, (XTransform*)&xform);
Picture dstPict = XRenderCreatePicture(
display, cairo_xlib_surface_get_drawable(xformSurf),
cairo_xlib_surface_get_xrender_format(xformSurf), 0, nullptr);
XRenderComposite(display, PictOpSrc, srcPict, X11None, dstPict, 0, 0, 0, 0, 0,
0, xformBounds.Width(), xformBounds.Height());
XRenderFreePicture(display, srcPict);
XRenderFreePicture(display, dstPict);
cairo_device_release(device);
cairo_surface_mark_dirty(xformSurf);
AutoPrepareForDrawing(this, mContext);
cairo_identity_matrix(mContext);
cairo_set_operator(mContext, CAIRO_OPERATOR_OVER);
cairo_set_antialias(mContext, CAIRO_ANTIALIAS_DEFAULT);
cairo_set_source_surface(mContext, xformSurf, xformBounds.X(),
xformBounds.Y());
cairo_new_path(mContext);
cairo_rectangle(mContext, xformBounds.X(), xformBounds.Y(),
xformBounds.Width(), xformBounds.Height());
cairo_fill(mContext);
cairo_surface_destroy(xformSurf);
return true;
#else
return DrawTarget::Draw3DTransformedSurface(aSurface, aMatrix);
#endif
}
bool DrawTargetCairo::Init(cairo_surface_t* aSurface, const IntSize& aSize,
@ -2165,7 +1952,6 @@ bool BorrowedXlibDrawable::Init(DrawTarget* aDT) {
mDrawable = cairo_xlib_surface_get_drawable(surf);
mScreen = cairo_xlib_surface_get_screen(surf);
mVisual = cairo_xlib_surface_get_visual(surf);
mXRenderFormat = cairo_xlib_surface_get_xrender_format(surf);
mSize.width = cairo_xlib_surface_get_width(surf);
mSize.height = cairo_xlib_surface_get_height(surf);

Просмотреть файл

@ -57,7 +57,7 @@
#ifdef MOZ_X11
#define CAIRO_HAS_PS_SURFACE 1
#define CAIRO_HAS_XLIB_XRENDER_SURFACE 1
#define CAIRO_HAS_XLIB_XRENDER_SURFACE 0
#define CAIRO_HAS_XLIB_SURFACE 1
#endif

Просмотреть файл

@ -7,7 +7,6 @@
#include "cairo.h"
#include "cairo-xlib.h"
#include "cairo-xlib-xrender.h"
#include <X11/Xlibint.h> /* For XESetCloseDisplay */
#undef max // Xlibint.h defines this and it breaks std::max
#undef min // Xlibint.h defines this and it breaks std::min
@ -49,20 +48,6 @@ gfxXlibSurface::gfxXlibSurface(const std::shared_ptr<XlibDisplay>& dpy,
Init(surf);
}
gfxXlibSurface::gfxXlibSurface(Screen* screen, Drawable drawable,
XRenderPictFormat* format,
const gfx::IntSize& size)
: mPixmapTaken(false),
mDisplay(XlibDisplay::Borrow(DisplayOfScreen(screen))),
mDrawable(drawable) {
NS_ASSERTION(Factory::CheckSurfaceSize(size, XLIB_IMAGE_SIDE_SIZE_LIMIT),
"Bad Size");
cairo_surface_t* surf = cairo_xlib_surface_create_with_xrender_format(
*mDisplay, drawable, screen, format, size.width, size.height);
Init(surf);
}
gfxXlibSurface::gfxXlibSurface(cairo_surface_t* csurf) : mPixmapTaken(false) {
MOZ_ASSERT(cairo_surface_status(csurf) == 0,
"Not expecting an error surface");
@ -213,16 +198,14 @@ const gfx::IntSize gfxXlibSurface::DoSizeQuery() {
class DisplayTable {
public:
static bool GetColormapAndVisual(Screen* screen, XRenderPictFormat* format,
Visual* visual, Colormap* colormap,
static bool GetColormapAndVisual(Screen* screen, Visual* visual,
Colormap* colormap,
Visual** visualForColormap);
private:
struct ColormapEntry {
XRenderPictFormat* mFormat;
// The Screen is needed here because colormaps (and their visuals) may
// only be used on one Screen, but XRenderPictFormats are not unique
// to any one Screen.
// only be used on one Screen
Screen* mScreen;
Visual* mVisual;
Colormap mColormap;
@ -275,9 +258,8 @@ DisplayTable* DisplayTable::sDisplayTable;
// should only be used with their visual.
/* static */
bool DisplayTable::GetColormapAndVisual(Screen* aScreen,
XRenderPictFormat* aFormat,
Visual* aVisual, Colormap* aColormap,
bool DisplayTable::GetColormapAndVisual(Screen* aScreen, Visual* aVisual,
Colormap* aColormap,
Visual** aVisualForColormap)
{
@ -285,8 +267,7 @@ bool DisplayTable::GetColormapAndVisual(Screen* aScreen,
// Use the default colormap if the default visual matches.
Visual* defaultVisual = DefaultVisualOfScreen(aScreen);
if (aVisual == defaultVisual ||
(aFormat && aFormat == XRenderFindVisualFormat(display, defaultVisual))) {
if (aVisual == defaultVisual) {
*aColormap = DefaultColormapOfScreen(aScreen);
*aVisualForColormap = defaultVisual;
return true;
@ -320,11 +301,7 @@ bool DisplayTable::GetColormapAndVisual(Screen* aScreen,
// simple linear search.
for (uint32_t i = 0; i < entries->Length(); ++i) {
const ColormapEntry& entry = entries->ElementAt(i);
// Only the format and screen need to match. (The visual may differ.)
// If there is no format (e.g. no RENDER extension) then just compare
// the visual.
if ((aFormat && entry.mFormat == aFormat && entry.mScreen == aScreen) ||
aVisual == entry.mVisual) {
if (aVisual == entry.mVisual) {
*aColormap = entry.mColormap;
*aVisualForColormap = entry.mVisual;
return true;
@ -335,7 +312,6 @@ bool DisplayTable::GetColormapAndVisual(Screen* aScreen,
Colormap colormap =
XCreateColormap(display, RootWindowOfScreen(aScreen), aVisual, AllocNone);
ColormapEntry* newEntry = entries->AppendElement();
newEntry->mFormat = aFormat;
newEntry->mScreen = aScreen;
newEntry->mVisual = aVisual;
newEntry->mColormap = colormap;
@ -361,13 +337,10 @@ int DisplayTable::DisplayClosing(Display* display, XExtCodes* codes) {
bool gfxXlibSurface::GetColormapAndVisual(cairo_surface_t* aXlibSurface,
Colormap* aColormap,
Visual** aVisual) {
XRenderPictFormat* format =
cairo_xlib_surface_get_xrender_format(aXlibSurface);
Screen* screen = cairo_xlib_surface_get_screen(aXlibSurface);
Visual* visual = cairo_xlib_surface_get_visual(aXlibSurface);
return DisplayTable::GetColormapAndVisual(screen, format, visual, aColormap,
aVisual);
return DisplayTable::GetColormapAndVisual(screen, visual, aColormap, aVisual);
}
bool gfxXlibSurface::GetColormapAndVisual(Colormap* aColormap,
@ -434,35 +407,6 @@ Visual* gfxXlibSurface::FindVisual(Screen* screen, gfxImageFormat format) {
return nullptr;
}
/* static */
XRenderPictFormat* gfxXlibSurface::FindRenderFormat(Display* dpy,
gfxImageFormat format) {
switch (format) {
case gfx::SurfaceFormat::A8R8G8B8_UINT32:
return XRenderFindStandardFormat(dpy, PictStandardARGB32);
case gfx::SurfaceFormat::X8R8G8B8_UINT32:
return XRenderFindStandardFormat(dpy, PictStandardRGB24);
case gfx::SurfaceFormat::R5G6B5_UINT16: {
// PictStandardRGB16_565 is not standard Xrender format
// we should try to find related visual
// and find xrender format by visual
Visual* visual = FindVisual(DefaultScreenOfDisplay(dpy), format);
if (!visual) return nullptr;
return XRenderFindVisualFormat(dpy, visual);
}
case gfx::SurfaceFormat::A8:
return XRenderFindStandardFormat(dpy, PictStandardA8);
default:
break;
}
return nullptr;
}
Screen* gfxXlibSurface::XScreen() {
return cairo_xlib_surface_get_screen(CairoSurface());
}
XRenderPictFormat* gfxXlibSurface::XRenderFormat() {
return cairo_xlib_surface_get_xrender_format(CairoSurface());
}

Просмотреть файл

@ -8,7 +8,6 @@
#include "gfxASurface.h"
#include <X11/extensions/Xrender.h>
#include <X11/Xlib.h>
#include "X11UndefineNone.h"
@ -36,11 +35,6 @@ class gfxXlibSurface final : public gfxASurface {
Drawable drawable, Visual* visual,
const mozilla::gfx::IntSize& size);
// construct a wrapper around the specified drawable with dpy/format,
// and known width/height.
gfxXlibSurface(::Screen* screen, Drawable drawable, XRenderPictFormat* format,
const mozilla::gfx::IntSize& size);
explicit gfxXlibSurface(cairo_surface_t* csurf);
// create a new Pixmap and wrapper surface.
@ -67,12 +61,9 @@ class gfxXlibSurface final : public gfxASurface {
Display* XDisplay() { return *mDisplay; }
::Screen* XScreen();
Drawable XDrawable() { return mDrawable; }
XRenderPictFormat* XRenderFormat();
static int DepthOfVisual(const ::Screen* screen, const Visual* visual);
static Visual* FindVisual(::Screen* screen, gfxImageFormat format);
static XRenderPictFormat* FindRenderFormat(Display* dpy,
gfxImageFormat format);
static bool GetColormapAndVisual(cairo_surface_t* aXlibSurface,
Colormap* colormap, Visual** visual);

Просмотреть файл

@ -1183,7 +1183,6 @@ def x11_libs(webrtc):
"x11-xcb",
"xext",
"xrandr >= 1.4.0",
"xrender",
]
if webrtc:
# third_party/libwebrtc/webrtc/webrtc_gn/moz.build adds those

Просмотреть файл

@ -49,9 +49,6 @@
# ifdef CAIRO_HAS_XLIB_SURFACE
# include "cairo-xlib.h"
# endif
# ifdef CAIRO_HAS_XLIB_XRENDER_SURFACE
# include "cairo-xlib-xrender.h"
# endif
#endif
#include <algorithm>
@ -847,21 +844,9 @@ static void DrawThemeWithCairo(gfxContext* aContext, DrawTarget* aDrawTarget,
BorrowedXlibDrawable borrow(aDrawTarget);
if (borrow.GetDrawable()) {
nsIntSize size = borrow.GetSize();
cairo_surface_t* surf = nullptr;
// Check if the surface is using XRender.
# ifdef CAIRO_HAS_XLIB_XRENDER_SURFACE
if (borrow.GetXRenderFormat()) {
surf = cairo_xlib_surface_create_with_xrender_format(
borrow.GetDisplay(), borrow.GetDrawable(), borrow.GetScreen(),
borrow.GetXRenderFormat(), size.width, size.height);
} else {
# else
if (!borrow.GetXRenderFormat()) {
# endif
surf = cairo_xlib_surface_create(
borrow.GetDisplay(), borrow.GetDrawable(), borrow.GetVisual(),
size.width, size.height);
}
cairo_surface_t* surf = cairo_xlib_surface_create(
borrow.GetDisplay(), borrow.GetDrawable(), borrow.GetVisual(),
size.width, size.height);
if (!NS_WARN_IF(!surf)) {
Point offset = borrow.GetOffset();
if (offset != Point()) {