michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include michael@0: #ifdef MOZ_X11 michael@0: #include michael@0: #include michael@0: #endif michael@0: #include michael@0: #include michael@0: michael@0: #include "gfxQtPlatform.h" michael@0: michael@0: #include "gfxFontconfigUtils.h" michael@0: michael@0: #include "mozilla/gfx/2D.h" michael@0: michael@0: #include "cairo.h" michael@0: michael@0: #include "gfxImageSurface.h" michael@0: #include "gfxQPainterSurface.h" michael@0: #include "nsUnicodeProperties.h" michael@0: michael@0: #include "gfxPangoFonts.h" michael@0: #include "gfxContext.h" michael@0: #include "gfxUserFontSet.h" michael@0: michael@0: #include "nsUnicharUtils.h" michael@0: michael@0: #include "nsMathUtils.h" michael@0: #include "nsTArray.h" michael@0: #ifdef MOZ_X11 michael@0: #include "gfxXlibSurface.h" michael@0: #include "prenv.h" michael@0: #endif michael@0: michael@0: #include "qcms.h" michael@0: michael@0: #include "mozilla/Preferences.h" michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::unicode; michael@0: using namespace mozilla::gfx; michael@0: michael@0: gfxFontconfigUtils *gfxQtPlatform::sFontconfigUtils = nullptr; michael@0: #ifdef MOZ_X11 michael@0: bool gfxQtPlatform::sUseXRender = true; michael@0: #endif michael@0: michael@0: static gfxImageFormat sOffscreenFormat = gfxImageFormat::RGB24; michael@0: michael@0: gfxQtPlatform::gfxQtPlatform() michael@0: { michael@0: #ifdef MOZ_X11 michael@0: sUseXRender = mozilla::Preferences::GetBool("gfx.xrender.enabled"); michael@0: #endif michael@0: if (!sFontconfigUtils) michael@0: sFontconfigUtils = gfxFontconfigUtils::GetFontconfigUtils(); michael@0: michael@0: mScreenDepth = qApp->primaryScreen()->depth(); michael@0: if (mScreenDepth == 16) { michael@0: sOffscreenFormat = gfxImageFormat::RGB16_565; michael@0: } michael@0: uint32_t canvasMask = BackendTypeBit(BackendType::CAIRO) | BackendTypeBit(BackendType::SKIA); michael@0: uint32_t contentMask = BackendTypeBit(BackendType::CAIRO) | BackendTypeBit(BackendType::SKIA); michael@0: InitBackendPrefs(canvasMask, BackendType::CAIRO, michael@0: contentMask, BackendType::CAIRO); michael@0: } michael@0: michael@0: gfxQtPlatform::~gfxQtPlatform() michael@0: { michael@0: gfxFontconfigUtils::Shutdown(); michael@0: sFontconfigUtils = nullptr; michael@0: michael@0: gfxPangoFontGroup::Shutdown(); michael@0: } michael@0: michael@0: #ifdef MOZ_X11 michael@0: Display* michael@0: gfxQtPlatform::GetXDisplay(QWindow* aWindow) michael@0: { michael@0: return (Display*)(qApp->platformNativeInterface()-> michael@0: nativeResourceForScreen("display", aWindow ? aWindow->screen() : qApp->primaryScreen())); michael@0: } michael@0: michael@0: Screen* michael@0: gfxQtPlatform::GetXScreen(QWindow* aWindow) michael@0: { michael@0: return ScreenOfDisplay(GetXDisplay(aWindow), michael@0: (int)(intptr_t)qApp->platformNativeInterface()-> michael@0: nativeResourceForScreen("screen", aWindow ? aWindow->screen() : qApp->primaryScreen())); michael@0: } michael@0: #endif michael@0: michael@0: already_AddRefed michael@0: gfxQtPlatform::CreateOffscreenSurface(const IntSize& size, michael@0: gfxContentType contentType) michael@0: { michael@0: gfxImageFormat imageFormat = OptimalFormatForContent(contentType); michael@0: michael@0: nsRefPtr newSurface = michael@0: new gfxImageSurface(gfxIntSize(size.width, size.height), imageFormat); michael@0: michael@0: return newSurface.forget(); michael@0: } michael@0: michael@0: already_AddRefed michael@0: gfxQtPlatform::OptimizeImage(gfxImageSurface *aSurface, michael@0: gfxImageFormat format) michael@0: { michael@0: /* Qt have no special offscreen surfaces so we can avoid a copy */ michael@0: if (OptimalFormatForContent(gfxASurface::ContentFromFormat(format)) == michael@0: format) { michael@0: return nullptr; michael@0: } michael@0: michael@0: return gfxPlatform::OptimizeImage(aSurface, format); michael@0: } michael@0: michael@0: michael@0: nsresult michael@0: gfxQtPlatform::GetFontList(nsIAtom *aLangGroup, michael@0: const nsACString& aGenericFamily, michael@0: nsTArray& aListOfFonts) michael@0: { michael@0: return sFontconfigUtils->GetFontList(aLangGroup, aGenericFamily, michael@0: aListOfFonts); michael@0: } michael@0: michael@0: nsresult michael@0: gfxQtPlatform::UpdateFontList() michael@0: { michael@0: return sFontconfigUtils->UpdateFontList(); michael@0: } michael@0: michael@0: nsresult michael@0: gfxQtPlatform::ResolveFontName(const nsAString& aFontName, michael@0: FontResolverCallback aCallback, michael@0: void *aClosure, michael@0: bool& aAborted) michael@0: { michael@0: return sFontconfigUtils->ResolveFontName(aFontName, aCallback, michael@0: aClosure, aAborted); michael@0: } michael@0: michael@0: nsresult michael@0: gfxQtPlatform::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName) michael@0: { michael@0: return sFontconfigUtils->GetStandardFamilyName(aFontName, aFamilyName); michael@0: } michael@0: michael@0: gfxFontGroup * michael@0: gfxQtPlatform::CreateFontGroup(const nsAString &aFamilies, michael@0: const gfxFontStyle *aStyle, michael@0: gfxUserFontSet* aUserFontSet) michael@0: { michael@0: return new gfxPangoFontGroup(aFamilies, aStyle, aUserFontSet); michael@0: } michael@0: michael@0: gfxFontEntry* michael@0: gfxQtPlatform::LookupLocalFont(const gfxProxyFontEntry *aProxyEntry, michael@0: const nsAString& aFontName) michael@0: { michael@0: return gfxPangoFontGroup::NewFontEntry(*aProxyEntry, aFontName); michael@0: } michael@0: michael@0: gfxFontEntry* michael@0: gfxQtPlatform::MakePlatformFont(const gfxProxyFontEntry *aProxyEntry, michael@0: const uint8_t *aFontData, uint32_t aLength) michael@0: { michael@0: // passing ownership of the font data to the new font entry michael@0: return gfxPangoFontGroup::NewFontEntry(*aProxyEntry, michael@0: aFontData, aLength); michael@0: } michael@0: michael@0: bool michael@0: gfxQtPlatform::SupportsOffMainThreadCompositing() michael@0: { michael@0: #if defined(MOZ_X11) && !defined(NIGHTLY_BUILD) michael@0: return (PR_GetEnv("MOZ_USE_OMTC") != nullptr) || michael@0: (PR_GetEnv("MOZ_OMTC_ENABLED") != nullptr); michael@0: #else michael@0: return true; michael@0: #endif michael@0: } michael@0: michael@0: bool michael@0: gfxQtPlatform::IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags) michael@0: { michael@0: // check for strange format flags michael@0: NS_ASSERTION(!(aFormatFlags & gfxUserFontSet::FLAG_FORMAT_NOT_USED), michael@0: "strange font format hint set"); michael@0: michael@0: // accept supported formats michael@0: // Pango doesn't apply features from AAT TrueType extensions. michael@0: // Assume that if this is the only SFNT format specified, michael@0: // then AAT extensions are required for complex script support. michael@0: if (aFormatFlags & (gfxUserFontSet::FLAG_FORMAT_WOFF | michael@0: gfxUserFontSet::FLAG_FORMAT_OPENTYPE | michael@0: gfxUserFontSet::FLAG_FORMAT_TRUETYPE)) { michael@0: return true; michael@0: } michael@0: michael@0: // reject all other formats, known and unknown michael@0: if (aFormatFlags != 0) { michael@0: return false; michael@0: } michael@0: michael@0: // no format hint set, need to look at data michael@0: return true; michael@0: } michael@0: michael@0: void michael@0: gfxQtPlatform::GetPlatformCMSOutputProfile(void *&mem, size_t &size) michael@0: { michael@0: mem = nullptr; michael@0: size = 0; michael@0: } michael@0: michael@0: int32_t michael@0: gfxQtPlatform::GetDPI() michael@0: { michael@0: return qApp->primaryScreen()->logicalDotsPerInch(); michael@0: } michael@0: michael@0: gfxImageFormat michael@0: gfxQtPlatform::GetOffscreenFormat() michael@0: { michael@0: return sOffscreenFormat; michael@0: } michael@0: michael@0: int michael@0: gfxQtPlatform::GetScreenDepth() const michael@0: { michael@0: return mScreenDepth; michael@0: } michael@0: michael@0: TemporaryRef michael@0: gfxQtPlatform::GetScaledFontForFont(DrawTarget* aTarget, gfxFont* aFont) michael@0: { michael@0: return GetScaledFontForFontWithCairoSkia(aTarget, aFont); michael@0: }