Skip to content

Commit

Permalink
Revert "Bug 1286317 - part 1 - remove Qt widget usage from gfx. r=jrm…
Browse files Browse the repository at this point in the history
…uizel"

This reverts commit 16ca322.
  • Loading branch information
rainemak committed May 27, 2020
1 parent 089fddd commit 11732c7
Show file tree
Hide file tree
Showing 21 changed files with 512 additions and 12 deletions.
4 changes: 3 additions & 1 deletion accessible/base/TextAttrs.cpp
Expand Up @@ -659,7 +659,9 @@ TextAttrsMgr::FontWeightTextAttr::
// font->GetStyle()->weight will give the absolute weight requested of the
// font face. The gfxPangoFontGroup code uses the gfxFontEntry constructor
// which doesn't initialize the weight field.
#if defined(MOZ_WIDGET_GTK)
#if defined(MOZ_WIDGET_QT)
useFontEntryWeight = false;
#elif defined(MOZ_WIDGET_GTK)
useFontEntryWeight = gfxPlatformGtk::UseFcFontList();
#endif

Expand Down
4 changes: 2 additions & 2 deletions gfx/2d/moz.build
Expand Up @@ -207,12 +207,12 @@ FINAL_LIBRARY = 'xul'
for var in ('USE_CAIRO', 'MOZ2D_HAS_MOZ_CAIRO'):
DEFINES[var] = True

if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk2', 'gtk3'):
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk2', 'gtk3', 'qt'):
DEFINES['MOZ_ENABLE_FREETYPE'] = True

CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS']

if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk2', 'gtk3'):
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk2', 'gtk3', 'qt'):
CXXFLAGS += CONFIG['CAIRO_FT_CFLAGS']

LOCAL_INCLUDES += CONFIG['SKIA_INCLUDES']
Expand Down
2 changes: 2 additions & 0 deletions gfx/gl/GLContextProviderEGL.cpp
Expand Up @@ -7,6 +7,8 @@
#include <gdk/gdkx.h>
// we're using default display for now
#define GET_NATIVE_WINDOW(aWidget) ((EGLNativeWindowType)GDK_WINDOW_XID((GdkWindow*)aWidget->GetNativeData(NS_NATIVE_WINDOW)))
#elif defined(MOZ_WIDGET_QT)
#define GET_NATIVE_WINDOW(aWidget) ((EGLNativeWindowType)aWidget->GetNativeData(NS_NATIVE_SHAREABLE_WINDOW))
#else
#define GET_NATIVE_WINDOW(aWidget) ((EGLNativeWindowType)aWidget->GetNativeData(NS_NATIVE_WINDOW))
#endif
Expand Down
2 changes: 2 additions & 0 deletions gfx/gl/GLContextProviderGLX.cpp
Expand Up @@ -7,6 +7,8 @@
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#define GET_NATIVE_WINDOW(aWidget) GDK_WINDOW_XID((GdkWindow*) aWidget->GetNativeData(NS_NATIVE_WINDOW))
#elif defined(MOZ_WIDGET_QT)
#define GET_NATIVE_WINDOW(aWidget) (Window)(aWidget->GetNativeData(NS_NATIVE_SHAREABLE_WINDOW))
#endif

#include <X11/Xlib.h>
Expand Down
2 changes: 2 additions & 0 deletions gfx/gl/moz.build
Expand Up @@ -17,6 +17,8 @@ elif 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']:
gl_provider = 'EGL'
else:
gl_provider = 'GLX'
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'qt':
gl_provider = 'GLX'
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
gl_provider = 'EGL'

Expand Down
8 changes: 6 additions & 2 deletions gfx/skia/generate_mozbuild.py
Expand Up @@ -73,6 +73,7 @@
'gtk2',
'gtk3',
'uikit',
'qt',
}:
DEFINES['SK_FONTHOST_DOES_NOT_USE_FONTMGR'] = 1
Expand Down Expand Up @@ -140,11 +141,11 @@
'-Wno-unused-private-field',
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3', 'android'):
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3', 'android', 'qt'):
CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS']
CXXFLAGS += CONFIG['CAIRO_FT_CFLAGS']
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3'):
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3', 'qt'):
CXXFLAGS += CONFIG['MOZ_PANGO_CFLAGS']
"""

Expand Down Expand Up @@ -461,6 +462,9 @@ def write_mozbuild(sources):
f.write("if 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']:\n")
write_sources(f, sources['linux'], 4)

f.write("if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'qt':\n")
write_sources(f, sources['linux'], 4)

f.write("if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':\n")
# Windows-specific files don't get unification because of nasty headers.
# Luckily there are not many files in this.
Expand Down
17 changes: 15 additions & 2 deletions gfx/skia/moz.build
Expand Up @@ -553,6 +553,18 @@ if 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']:
'skia/src/ports/SkFontHost_cairo.cpp',
'skia/src/ports/SkFontHost_FreeType_common.cpp',
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'qt':
UNIFIED_SOURCES += [
'skia/src/ports/SkDebug_stdio.cpp',
'skia/src/ports/SkOSFile_posix.cpp',
'skia/src/ports/SkOSLibrary_posix.cpp',
'skia/src/ports/SkTLS_pthread.cpp',
'skia/src/utils/SkThreadUtils_pthread.cpp',
]
SOURCES += [
'skia/src/ports/SkFontHost_cairo.cpp',
'skia/src/ports/SkFontHost_FreeType_common.cpp',
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
SOURCES += [
'skia/src/ports/SkDebug_win.cpp',
Expand Down Expand Up @@ -683,6 +695,7 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] in {
'gtk2',
'gtk3',
'uikit',
'qt',
}:
DEFINES['SK_FONTHOST_DOES_NOT_USE_FONTMGR'] = 1

Expand Down Expand Up @@ -750,9 +763,9 @@ if CONFIG['CLANG_CXX'] or CONFIG['CLANG_CL']:
'-Wno-unused-private-field',
]

if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3', 'android'):
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3', 'android', 'qt'):
CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS']
CXXFLAGS += CONFIG['CAIRO_FT_CFLAGS']

if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3'):
if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3', 'qt'):
CXXFLAGS += CONFIG['MOZ_PANGO_CFLAGS']
8 changes: 7 additions & 1 deletion gfx/src/X11Util.h
Expand Up @@ -14,9 +14,13 @@
# include <gdk/gdk.h>
# include <gdk/gdkx.h>
# include "X11UndefineNone.h"
#elif defined(MOZ_WIDGET_QT)
#include "gfxQtPlatform.h"
#undef CursorShape
# include <X11/Xlib.h>
#else
# error Unknown toolkit
#endif
#endif

#include <string.h> // for memset
#include "mozilla/Scoped.h" // for SCOPED_TEMPLATE
Expand All @@ -31,6 +35,8 @@ DefaultXDisplay()
{
#if defined(MOZ_WIDGET_GTK)
return GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
#elif defined(MOZ_WIDGET_QT)
return gfxQtPlatform::GetXDisplay();
#endif
}

Expand Down
2 changes: 2 additions & 0 deletions gfx/thebes/gfxASurface.cpp
Expand Up @@ -151,6 +151,8 @@ gfxASurface::Wrap (cairo_surface_t *csurf, const IntSize& aSize)
/* No wrapper; figure out the surface type and create it */
cairo_surface_type_t stype = cairo_surface_get_type(csurf);

MOZ_ASSERT(stype != CAIRO_SURFACE_TYPE_QT);

if (stype == CAIRO_SURFACE_TYPE_IMAGE) {
result = new gfxImageSurface(csurf);
}
Expand Down
4 changes: 4 additions & 0 deletions gfx/thebes/gfxFT2Fonts.cpp
Expand Up @@ -6,6 +6,10 @@
#if defined(MOZ_WIDGET_GTK)
#include "gfxPlatformGtk.h"
#define gfxToolkitPlatform gfxPlatformGtk
#elif defined(MOZ_WIDGET_QT)
#include <qfontinfo.h>
#include "gfxQtPlatform.h"
#define gfxToolkitPlatform gfxQtPlatform
#elif defined(XP_WIN)
#include "gfxWindowsPlatform.h"
#define gfxToolkitPlatform gfxWindowsPlatform
Expand Down
2 changes: 1 addition & 1 deletion gfx/thebes/gfxFont.h
Expand Up @@ -58,7 +58,7 @@ class gfxMathTable;
// we use a platform-dependent value to harmonize with the platform's own APIs.
#ifdef XP_WIN
#define OBLIQUE_SKEW_FACTOR 0.3
#elif defined(MOZ_WIDGET_GTK)
#elif defined(MOZ_WIDGET_GTK) || defined(MOZ_WIDGET_QT)
#define OBLIQUE_SKEW_FACTOR 0.2
#else
#define OBLIQUE_SKEW_FACTOR 0.25
Expand Down
3 changes: 3 additions & 0 deletions gfx/thebes/gfxFontconfigFonts.cpp
Expand Up @@ -12,6 +12,9 @@
#ifdef MOZ_WIDGET_GTK
#include "gfxPlatformGtk.h"
#endif
#ifdef MOZ_WIDGET_QT
#include "gfxQtPlatform.h"
#endif
#include "gfxFontconfigFonts.h"
#include "gfxFT2FontBase.h"
#include "gfxFT2Utils.h"
Expand Down
6 changes: 6 additions & 0 deletions gfx/thebes/gfxPlatform.cpp
Expand Up @@ -44,6 +44,8 @@
#include "gfxQuartzSurface.h"
#elif defined(MOZ_WIDGET_GTK)
#include "gfxPlatformGtk.h"
#elif defined(MOZ_WIDGET_QT)
#include "gfxQtPlatform.h"
#elif defined(ANDROID)
#include "gfxAndroidPlatform.h"
#endif
Expand Down Expand Up @@ -683,6 +685,8 @@ gfxPlatform::Init()
gPlatform = new gfxPlatformMac;
#elif defined(MOZ_WIDGET_GTK)
gPlatform = new gfxPlatformGtk;
#elif defined(MOZ_WIDGET_QT)
gPlatform = new gfxQtPlatform;
#elif defined(ANDROID)
gPlatform = new gfxAndroidPlatform;
#else
Expand Down Expand Up @@ -724,6 +728,8 @@ gfxPlatform::Init()
bool usePlatformFontList = true;
#if defined(MOZ_WIDGET_GTK)
usePlatformFontList = gfxPlatformGtk::UseFcFontList();
#elif defined(MOZ_WIDGET_QT)
usePlatformFontList = false;
#endif

if (usePlatformFontList) {
Expand Down
48 changes: 48 additions & 0 deletions gfx/thebes/gfxQtNativeRenderer.cpp
@@ -0,0 +1,48 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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/. */

#include "gfxQtNativeRenderer.h"
#include "gfxContext.h"
#include "gfxUtils.h"
#include "gfxXlibSurface.h"

nsresult
gfxQtNativeRenderer::Draw(gfxContext* ctx, mozilla::gfx::IntSize size,
uint32_t flags, Screen* screen, Visual* visual)
{
Display *dpy = DisplayOfScreen(screen);
bool isOpaque = (flags & DRAW_IS_OPAQUE) ? true : false;
int screenNumber = screen - ScreenOfDisplay(dpy, 0);

if (!isOpaque) {
int depth = 32;
XVisualInfo vinfo;
int foundVisual = XMatchVisualInfo(dpy, screenNumber,
depth, TrueColor,
&vinfo);
if (!foundVisual)
return NS_ERROR_FAILURE;

visual = vinfo.visual;
}

RefPtr<gfxXlibSurface> xsurf =
gfxXlibSurface::Create(screen, visual,
mozilla::gfx::IntSize(size.width, size.height));

if (!isOpaque) {
gfxUtils::ClearThebesSurface(xsurf);
}

nsresult rv = DrawWithXlib(xsurf->CairoSurface(), nsIntPoint(0, 0), nullptr, 0);

if (NS_FAILED(rv))
return rv;

ctx->SetSource(xsurf);
ctx->Paint();

return rv;
}
68 changes: 68 additions & 0 deletions gfx/thebes/gfxQtNativeRenderer.h
@@ -0,0 +1,68 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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 GFXQTNATIVERENDER_H_
#define GFXQTNATIVERENDER_H_

#include "gfxContext.h"
#include "gfxXlibSurface.h"
#include "mozilla/gfx/Rect.h"

/**
* This class lets us take code that draws into an Xlib surface drawable and lets us
* use it to draw into any Thebes context. The user should subclass this class,
* override NativeDraw, and then call Draw(). The drawing will be subjected
* to all Thebes transformations, clipping etc.
*/
class gfxQtNativeRenderer {
public:
/**
* Perform the native drawing.
* @param offsetX draw at this offset into the given drawable
* @param offsetY draw at this offset into the given drawable
* @param clipRects an array of rects; clip to the union
* @param numClipRects the number of rects in the array, or zero if
* no clipping is required
*/
virtual nsresult DrawWithXlib(cairo_surface_t* surface,
nsIntPoint offset,
mozilla::gfx::IntRect* clipRects,
uint32_t numClipRects) = 0;

enum {
// If set, then Draw() is opaque, i.e., every pixel in the intersection
// of the clipRect and (offset.x,offset.y,bounds.width,bounds.height)
// will be set and there is no dependence on what the existing pixels
// in the drawable are set to.
DRAW_IS_OPAQUE = 0x01,
// If set, then numClipRects can be zero or one
DRAW_SUPPORTS_CLIP_RECT = 0x04,
// If set, then numClipRects can be any value. If neither this
// nor CLIP_RECT are set, then numClipRects will be zero
DRAW_SUPPORTS_CLIP_LIST = 0x08,
// If set, then the visual passed in can be any visual, otherwise the
// visual passed in must be the default visual for dpy's default screen
DRAW_SUPPORTS_ALTERNATE_VISUAL = 0x10,
// If set, then the Screen 'screen' in the callback can be different
// from the default Screen of the display passed to 'Draw' and can be
// on a different display.
DRAW_SUPPORTS_ALTERNATE_SCREEN = 0x20
};

/**
* @param flags see above
* @param size Draw()'s drawing is guaranteed to be restricted to
* the rectangle (offset.x,offset.y,size.width,size.height)
* @param dpy a display to use for the drawing if ctx doesn't have one
* @param resultSurface if non-null, we will try to capture a copy of the
* rendered image into a surface similar to the surface of ctx; if
* successful, a pointer to the new gfxASurface is stored in *resultSurface,
* otherwise *resultSurface is set to nullptr.
*/
nsresult Draw(gfxContext* ctx, mozilla::gfx::IntSize size,
uint32_t flags, Screen* screen, Visual* visual);
};

#endif /*GFXQTNATIVERENDER_H_*/

0 comments on commit 11732c7

Please sign in to comment.