2008-04-19 08:02:52 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* 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/. */
|
2008-04-19 08:02:52 -07:00
|
|
|
|
|
|
|
#include <QPixmap>
|
2014-02-20 18:09:02 -08:00
|
|
|
#include <QWindow>
|
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include <qpa/qplatformnativeinterface.h>
|
|
|
|
#include <qpa/qplatformintegration.h>
|
2012-03-22 16:24:40 -07:00
|
|
|
#endif
|
2014-02-20 18:09:02 -08:00
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QScreen>
|
2008-04-19 08:02:52 -07:00
|
|
|
|
|
|
|
#include "gfxQtPlatform.h"
|
|
|
|
|
|
|
|
#include "gfxFontconfigUtils.h"
|
|
|
|
|
2012-03-22 13:24:57 -07:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
|
2008-04-19 08:02:52 -07:00
|
|
|
#include "cairo.h"
|
|
|
|
|
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
#include "gfxQPainterSurface.h"
|
2012-03-08 19:10:05 -08:00
|
|
|
#include "nsUnicodeProperties.h"
|
2008-04-19 08:02:52 -07:00
|
|
|
|
2010-03-06 05:29:55 -08:00
|
|
|
#include "gfxPangoFonts.h"
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxUserFontSet.h"
|
2008-04-19 08:02:52 -07:00
|
|
|
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
|
|
|
|
#include "nsMathUtils.h"
|
2009-01-18 12:14:14 -08:00
|
|
|
#include "nsTArray.h"
|
2010-02-19 19:46:54 -08:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include "gfxXlibSurface.h"
|
2014-02-20 18:09:02 -08:00
|
|
|
#include "prenv.h"
|
2010-02-19 19:46:54 -08:00
|
|
|
#endif
|
2008-04-19 08:02:52 -07:00
|
|
|
|
2009-04-07 09:02:11 -07:00
|
|
|
#include "qcms.h"
|
2008-04-19 08:02:52 -07:00
|
|
|
|
2011-06-11 19:30:16 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2012-03-08 19:10:05 -08:00
|
|
|
using namespace mozilla::unicode;
|
2012-03-22 13:24:57 -07:00
|
|
|
using namespace mozilla::gfx;
|
2010-02-19 19:46:54 -08:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
gfxFontconfigUtils *gfxQtPlatform::sFontconfigUtils = nullptr;
|
2008-04-19 08:02:52 -07:00
|
|
|
|
2014-01-23 10:26:40 -08:00
|
|
|
static gfxImageFormat sOffscreenFormat = gfxImageFormat::RGB24;
|
2012-03-12 02:23:34 -07:00
|
|
|
|
2008-04-19 08:02:52 -07:00
|
|
|
gfxQtPlatform::gfxQtPlatform()
|
|
|
|
{
|
|
|
|
if (!sFontconfigUtils)
|
|
|
|
sFontconfigUtils = gfxFontconfigUtils::GetFontconfigUtils();
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
mScreenDepth = qApp->primaryScreen()->depth();
|
|
|
|
if (mScreenDepth == 16) {
|
2014-01-23 10:26:40 -08:00
|
|
|
sOffscreenFormat = gfxImageFormat::RGB16_565;
|
2012-03-12 02:23:34 -07:00
|
|
|
}
|
2014-01-29 23:01:16 -08:00
|
|
|
uint32_t canvasMask = BackendTypeBit(BackendType::CAIRO) | BackendTypeBit(BackendType::SKIA);
|
|
|
|
uint32_t contentMask = BackendTypeBit(BackendType::CAIRO) | BackendTypeBit(BackendType::SKIA);
|
|
|
|
InitBackendPrefs(canvasMask, BackendType::CAIRO,
|
|
|
|
contentMask, BackendType::CAIRO);
|
2008-04-19 08:02:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxQtPlatform::~gfxQtPlatform()
|
|
|
|
{
|
|
|
|
gfxFontconfigUtils::Shutdown();
|
2012-07-30 07:20:58 -07:00
|
|
|
sFontconfigUtils = nullptr;
|
2008-04-19 08:02:52 -07:00
|
|
|
|
2010-03-06 05:29:55 -08:00
|
|
|
gfxPangoFontGroup::Shutdown();
|
2008-04-19 08:02:52 -07:00
|
|
|
}
|
|
|
|
|
2012-03-22 16:24:40 -07:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
Display*
|
2014-02-20 18:09:02 -08:00
|
|
|
gfxQtPlatform::GetXDisplay(QWindow* aWindow)
|
2012-03-22 16:24:40 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
return (Display*)(qApp->platformNativeInterface()->
|
|
|
|
nativeResourceForScreen("display", aWindow ? aWindow->screen() : qApp->primaryScreen()));
|
2012-03-22 16:24:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Screen*
|
2014-02-20 18:09:02 -08:00
|
|
|
gfxQtPlatform::GetXScreen(QWindow* aWindow)
|
2012-03-22 16:24:40 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
return ScreenOfDisplay(GetXDisplay(aWindow),
|
|
|
|
(int)(intptr_t)qApp->platformNativeInterface()->
|
|
|
|
nativeResourceForScreen("screen", aWindow ? aWindow->screen() : qApp->primaryScreen()));
|
2012-03-22 16:24:40 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-04-19 08:02:52 -07:00
|
|
|
already_AddRefed<gfxASurface>
|
2014-02-09 00:04:38 -08:00
|
|
|
gfxQtPlatform::CreateOffscreenSurface(const IntSize& size,
|
2013-09-24 13:45:13 -07:00
|
|
|
gfxContentType contentType)
|
2008-04-19 08:02:52 -07:00
|
|
|
{
|
2013-09-24 13:45:13 -07:00
|
|
|
gfxImageFormat imageFormat = OptimalFormatForContent(contentType);
|
2010-06-11 02:33:22 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
nsRefPtr<gfxASurface> newSurface =
|
|
|
|
new gfxImageSurface(gfxIntSize(size.width, size.height), imageFormat);
|
2010-02-19 19:46:54 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
return newSurface.forget();
|
|
|
|
}
|
2010-02-19 19:46:54 -08:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
gfxQtPlatform::OptimizeImage(gfxImageSurface *aSurface,
|
|
|
|
gfxImageFormat format)
|
|
|
|
{
|
|
|
|
/* Qt have no special offscreen surfaces so we can avoid a copy */
|
|
|
|
if (OptimalFormatForContent(gfxASurface::ContentFromFormat(format)) ==
|
|
|
|
format) {
|
|
|
|
return nullptr;
|
2010-02-19 19:46:54 -08:00
|
|
|
}
|
2008-04-19 08:02:52 -07:00
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
return gfxPlatform::OptimizeImage(aSurface, format);
|
2008-04-19 08:02:52 -07:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
|
2008-04-19 08:02:52 -07:00
|
|
|
nsresult
|
2010-02-24 09:57:57 -08:00
|
|
|
gfxQtPlatform::GetFontList(nsIAtom *aLangGroup,
|
|
|
|
const nsACString& aGenericFamily,
|
|
|
|
nsTArray<nsString>& aListOfFonts)
|
2008-04-19 08:02:52 -07:00
|
|
|
{
|
|
|
|
return sFontconfigUtils->GetFontList(aLangGroup, aGenericFamily,
|
|
|
|
aListOfFonts);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxQtPlatform::UpdateFontList()
|
|
|
|
{
|
|
|
|
return sFontconfigUtils->UpdateFontList();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxQtPlatform::ResolveFontName(const nsAString& aFontName,
|
|
|
|
FontResolverCallback aCallback,
|
|
|
|
void *aClosure,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool& aAborted)
|
2008-04-19 08:02:52 -07:00
|
|
|
{
|
2010-03-06 05:29:55 -08:00
|
|
|
return sFontconfigUtils->ResolveFontName(aFontName, aCallback,
|
|
|
|
aClosure, aAborted);
|
2008-04-19 08:02:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxQtPlatform::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName)
|
|
|
|
{
|
|
|
|
return sFontconfigUtils->GetStandardFamilyName(aFontName, aFamilyName);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFontGroup *
|
|
|
|
gfxQtPlatform::CreateFontGroup(const nsAString &aFamilies,
|
2008-10-08 07:06:09 -07:00
|
|
|
const gfxFontStyle *aStyle,
|
|
|
|
gfxUserFontSet* aUserFontSet)
|
2008-04-19 08:02:52 -07:00
|
|
|
{
|
2010-03-06 05:29:55 -08:00
|
|
|
return new gfxPangoFontGroup(aFamilies, aStyle, aUserFontSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFontEntry*
|
|
|
|
gfxQtPlatform::LookupLocalFont(const gfxProxyFontEntry *aProxyEntry,
|
|
|
|
const nsAString& aFontName)
|
|
|
|
{
|
|
|
|
return gfxPangoFontGroup::NewFontEntry(*aProxyEntry, aFontName);
|
2008-04-19 08:02:52 -07:00
|
|
|
}
|
|
|
|
|
2010-03-06 05:29:55 -08:00
|
|
|
gfxFontEntry*
|
|
|
|
gfxQtPlatform::MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint8_t *aFontData, uint32_t aLength)
|
2010-03-06 05:29:55 -08:00
|
|
|
{
|
|
|
|
// passing ownership of the font data to the new font entry
|
|
|
|
return gfxPangoFontGroup::NewFontEntry(*aProxyEntry,
|
|
|
|
aFontData, aLength);
|
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
bool
|
|
|
|
gfxQtPlatform::SupportsOffMainThreadCompositing()
|
|
|
|
{
|
|
|
|
#if defined(MOZ_X11) && !defined(NIGHTLY_BUILD)
|
|
|
|
return (PR_GetEnv("MOZ_USE_OMTC") != nullptr) ||
|
|
|
|
(PR_GetEnv("MOZ_OMTC_ENABLED") != nullptr);
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
gfxQtPlatform::IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags)
|
2010-03-06 05:29:55 -08:00
|
|
|
{
|
|
|
|
// check for strange format flags
|
|
|
|
NS_ASSERTION(!(aFormatFlags & gfxUserFontSet::FLAG_FORMAT_NOT_USED),
|
|
|
|
"strange font format hint set");
|
|
|
|
|
|
|
|
// accept supported formats
|
|
|
|
// Pango doesn't apply features from AAT TrueType extensions.
|
|
|
|
// Assume that if this is the only SFNT format specified,
|
|
|
|
// then AAT extensions are required for complex script support.
|
|
|
|
if (aFormatFlags & (gfxUserFontSet::FLAG_FORMAT_WOFF |
|
|
|
|
gfxUserFontSet::FLAG_FORMAT_OPENTYPE |
|
|
|
|
gfxUserFontSet::FLAG_FORMAT_TRUETYPE)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-03-06 05:29:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// reject all other formats, known and unknown
|
|
|
|
if (aFormatFlags != 0) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-03-06 05:29:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// no format hint set, need to look at data
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-03-06 05:29:55 -08:00
|
|
|
}
|
|
|
|
|
2014-02-20 18:09:02 -08:00
|
|
|
void
|
|
|
|
gfxQtPlatform::GetPlatformCMSOutputProfile(void *&mem, size_t &size)
|
2008-04-19 08:02:52 -07:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
mem = nullptr;
|
|
|
|
size = 0;
|
2008-04-19 08:02:52 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2010-08-13 02:58:01 -07:00
|
|
|
gfxQtPlatform::GetDPI()
|
2010-03-10 06:36:47 -08:00
|
|
|
{
|
2014-02-20 18:09:02 -08:00
|
|
|
return qApp->primaryScreen()->logicalDotsPerInch();
|
2010-03-10 06:36:47 -08:00
|
|
|
}
|
2010-12-15 10:17:26 -08:00
|
|
|
|
|
|
|
gfxImageFormat
|
|
|
|
gfxQtPlatform::GetOffscreenFormat()
|
|
|
|
{
|
2012-03-12 02:23:34 -07:00
|
|
|
return sOffscreenFormat;
|
2010-12-15 10:17:26 -08:00
|
|
|
}
|
2012-03-22 13:24:57 -07:00
|
|
|
|
2012-08-01 12:00:24 -07:00
|
|
|
int
|
|
|
|
gfxQtPlatform::GetScreenDepth() const
|
|
|
|
{
|
|
|
|
return mScreenDepth;
|
|
|
|
}
|
|
|
|
|
2014-01-29 23:01:16 -08:00
|
|
|
TemporaryRef<ScaledFont>
|
|
|
|
gfxQtPlatform::GetScaledFontForFont(DrawTarget* aTarget, gfxFont* aFont)
|
|
|
|
{
|
|
|
|
return GetScaledFontForFontWithCairoSkia(aTarget, aFont);
|
|
|
|
}
|