gfx/thebes/gfxQtPlatform.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/thebes/gfxQtPlatform.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,245 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include <QPixmap>
    1.10 +#include <QWindow>
    1.11 +#ifdef MOZ_X11
    1.12 +#include <qpa/qplatformnativeinterface.h>
    1.13 +#include <qpa/qplatformintegration.h>
    1.14 +#endif
    1.15 +#include <QGuiApplication>
    1.16 +#include <QScreen>
    1.17 +
    1.18 +#include "gfxQtPlatform.h"
    1.19 +
    1.20 +#include "gfxFontconfigUtils.h"
    1.21 +
    1.22 +#include "mozilla/gfx/2D.h"
    1.23 +
    1.24 +#include "cairo.h"
    1.25 +
    1.26 +#include "gfxImageSurface.h"
    1.27 +#include "gfxQPainterSurface.h"
    1.28 +#include "nsUnicodeProperties.h"
    1.29 +
    1.30 +#include "gfxPangoFonts.h"
    1.31 +#include "gfxContext.h"
    1.32 +#include "gfxUserFontSet.h"
    1.33 +
    1.34 +#include "nsUnicharUtils.h"
    1.35 +
    1.36 +#include "nsMathUtils.h"
    1.37 +#include "nsTArray.h"
    1.38 +#ifdef MOZ_X11
    1.39 +#include "gfxXlibSurface.h"
    1.40 +#include "prenv.h"
    1.41 +#endif
    1.42 +
    1.43 +#include "qcms.h"
    1.44 +
    1.45 +#include "mozilla/Preferences.h"
    1.46 +
    1.47 +using namespace mozilla;
    1.48 +using namespace mozilla::unicode;
    1.49 +using namespace mozilla::gfx;
    1.50 +
    1.51 +gfxFontconfigUtils *gfxQtPlatform::sFontconfigUtils = nullptr;
    1.52 +#ifdef MOZ_X11
    1.53 +bool gfxQtPlatform::sUseXRender = true;
    1.54 +#endif
    1.55 +
    1.56 +static gfxImageFormat sOffscreenFormat = gfxImageFormat::RGB24;
    1.57 +
    1.58 +gfxQtPlatform::gfxQtPlatform()
    1.59 +{
    1.60 +#ifdef MOZ_X11
    1.61 +    sUseXRender = mozilla::Preferences::GetBool("gfx.xrender.enabled");
    1.62 +#endif
    1.63 +    if (!sFontconfigUtils)
    1.64 +        sFontconfigUtils = gfxFontconfigUtils::GetFontconfigUtils();
    1.65 +
    1.66 +    mScreenDepth = qApp->primaryScreen()->depth();
    1.67 +    if (mScreenDepth == 16) {
    1.68 +        sOffscreenFormat = gfxImageFormat::RGB16_565;
    1.69 +    }
    1.70 +    uint32_t canvasMask = BackendTypeBit(BackendType::CAIRO) | BackendTypeBit(BackendType::SKIA);
    1.71 +    uint32_t contentMask = BackendTypeBit(BackendType::CAIRO) | BackendTypeBit(BackendType::SKIA);
    1.72 +    InitBackendPrefs(canvasMask, BackendType::CAIRO,
    1.73 +                     contentMask, BackendType::CAIRO);
    1.74 +}
    1.75 +
    1.76 +gfxQtPlatform::~gfxQtPlatform()
    1.77 +{
    1.78 +    gfxFontconfigUtils::Shutdown();
    1.79 +    sFontconfigUtils = nullptr;
    1.80 +
    1.81 +    gfxPangoFontGroup::Shutdown();
    1.82 +}
    1.83 +
    1.84 +#ifdef MOZ_X11
    1.85 +Display*
    1.86 +gfxQtPlatform::GetXDisplay(QWindow* aWindow)
    1.87 +{
    1.88 +    return (Display*)(qApp->platformNativeInterface()->
    1.89 +        nativeResourceForScreen("display", aWindow ? aWindow->screen() : qApp->primaryScreen()));
    1.90 +}
    1.91 +
    1.92 +Screen*
    1.93 +gfxQtPlatform::GetXScreen(QWindow* aWindow)
    1.94 +{
    1.95 +    return ScreenOfDisplay(GetXDisplay(aWindow),
    1.96 +        (int)(intptr_t)qApp->platformNativeInterface()->
    1.97 +            nativeResourceForScreen("screen", aWindow ? aWindow->screen() : qApp->primaryScreen()));
    1.98 +}
    1.99 +#endif
   1.100 +
   1.101 +already_AddRefed<gfxASurface>
   1.102 +gfxQtPlatform::CreateOffscreenSurface(const IntSize& size,
   1.103 +                                      gfxContentType contentType)
   1.104 +{
   1.105 +    gfxImageFormat imageFormat = OptimalFormatForContent(contentType);
   1.106 +
   1.107 +    nsRefPtr<gfxASurface> newSurface =
   1.108 +        new gfxImageSurface(gfxIntSize(size.width, size.height), imageFormat);
   1.109 +
   1.110 +    return newSurface.forget();
   1.111 +}
   1.112 +
   1.113 +already_AddRefed<gfxASurface>
   1.114 +gfxQtPlatform::OptimizeImage(gfxImageSurface *aSurface,
   1.115 +                             gfxImageFormat format)
   1.116 +{
   1.117 +    /* Qt have no special offscreen surfaces so we can avoid a copy */
   1.118 +    if (OptimalFormatForContent(gfxASurface::ContentFromFormat(format)) ==
   1.119 +        format) {
   1.120 +        return nullptr;
   1.121 +    }
   1.122 +
   1.123 +    return gfxPlatform::OptimizeImage(aSurface, format);
   1.124 +}
   1.125 +
   1.126 +
   1.127 +nsresult
   1.128 +gfxQtPlatform::GetFontList(nsIAtom *aLangGroup,
   1.129 +                           const nsACString& aGenericFamily,
   1.130 +                           nsTArray<nsString>& aListOfFonts)
   1.131 +{
   1.132 +    return sFontconfigUtils->GetFontList(aLangGroup, aGenericFamily,
   1.133 +                                         aListOfFonts);
   1.134 +}
   1.135 +
   1.136 +nsresult
   1.137 +gfxQtPlatform::UpdateFontList()
   1.138 +{
   1.139 +    return sFontconfigUtils->UpdateFontList();
   1.140 +}
   1.141 +
   1.142 +nsresult
   1.143 +gfxQtPlatform::ResolveFontName(const nsAString& aFontName,
   1.144 +                                FontResolverCallback aCallback,
   1.145 +                                void *aClosure,
   1.146 +                                bool& aAborted)
   1.147 +{
   1.148 +    return sFontconfigUtils->ResolveFontName(aFontName, aCallback,
   1.149 +                                             aClosure, aAborted);
   1.150 +}
   1.151 +
   1.152 +nsresult
   1.153 +gfxQtPlatform::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName)
   1.154 +{
   1.155 +    return sFontconfigUtils->GetStandardFamilyName(aFontName, aFamilyName);
   1.156 +}
   1.157 +
   1.158 +gfxFontGroup *
   1.159 +gfxQtPlatform::CreateFontGroup(const nsAString &aFamilies,
   1.160 +                               const gfxFontStyle *aStyle,
   1.161 +                               gfxUserFontSet* aUserFontSet)
   1.162 +{
   1.163 +    return new gfxPangoFontGroup(aFamilies, aStyle, aUserFontSet);
   1.164 +}
   1.165 +
   1.166 +gfxFontEntry*
   1.167 +gfxQtPlatform::LookupLocalFont(const gfxProxyFontEntry *aProxyEntry,
   1.168 +                                const nsAString& aFontName)
   1.169 +{
   1.170 +    return gfxPangoFontGroup::NewFontEntry(*aProxyEntry, aFontName);
   1.171 +}
   1.172 +
   1.173 +gfxFontEntry*
   1.174 +gfxQtPlatform::MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
   1.175 +                                 const uint8_t *aFontData, uint32_t aLength)
   1.176 +{
   1.177 +    // passing ownership of the font data to the new font entry
   1.178 +    return gfxPangoFontGroup::NewFontEntry(*aProxyEntry,
   1.179 +                                           aFontData, aLength);
   1.180 +}
   1.181 +
   1.182 +bool
   1.183 +gfxQtPlatform::SupportsOffMainThreadCompositing()
   1.184 +{
   1.185 +#if defined(MOZ_X11) && !defined(NIGHTLY_BUILD)
   1.186 +  return (PR_GetEnv("MOZ_USE_OMTC") != nullptr) ||
   1.187 +         (PR_GetEnv("MOZ_OMTC_ENABLED") != nullptr);
   1.188 +#else
   1.189 +  return true;
   1.190 +#endif
   1.191 +}
   1.192 +
   1.193 +bool
   1.194 +gfxQtPlatform::IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags)
   1.195 +{
   1.196 +    // check for strange format flags
   1.197 +    NS_ASSERTION(!(aFormatFlags & gfxUserFontSet::FLAG_FORMAT_NOT_USED),
   1.198 +                 "strange font format hint set");
   1.199 +
   1.200 +    // accept supported formats
   1.201 +    // Pango doesn't apply features from AAT TrueType extensions.
   1.202 +    // Assume that if this is the only SFNT format specified,
   1.203 +    // then AAT extensions are required for complex script support.
   1.204 +    if (aFormatFlags & (gfxUserFontSet::FLAG_FORMAT_WOFF     |
   1.205 +                        gfxUserFontSet::FLAG_FORMAT_OPENTYPE |
   1.206 +                        gfxUserFontSet::FLAG_FORMAT_TRUETYPE)) {
   1.207 +        return true;
   1.208 +    }
   1.209 +
   1.210 +    // reject all other formats, known and unknown
   1.211 +    if (aFormatFlags != 0) {
   1.212 +        return false;
   1.213 +    }
   1.214 +
   1.215 +    // no format hint set, need to look at data
   1.216 +    return true;
   1.217 +}
   1.218 +
   1.219 +void
   1.220 +gfxQtPlatform::GetPlatformCMSOutputProfile(void *&mem, size_t &size)
   1.221 +{
   1.222 +    mem = nullptr;
   1.223 +    size = 0;
   1.224 +}
   1.225 +
   1.226 +int32_t
   1.227 +gfxQtPlatform::GetDPI()
   1.228 +{
   1.229 +    return qApp->primaryScreen()->logicalDotsPerInch();
   1.230 +}
   1.231 +
   1.232 +gfxImageFormat
   1.233 +gfxQtPlatform::GetOffscreenFormat()
   1.234 +{
   1.235 +    return sOffscreenFormat;
   1.236 +}
   1.237 +
   1.238 +int
   1.239 +gfxQtPlatform::GetScreenDepth() const
   1.240 +{
   1.241 +    return mScreenDepth;
   1.242 +}
   1.243 +
   1.244 +TemporaryRef<ScaledFont>
   1.245 +gfxQtPlatform::GetScaledFontForFont(DrawTarget* aTarget, gfxFont* aFont)
   1.246 +{
   1.247 +    return GetScaledFontForFontWithCairoSkia(aTarget, aFont);
   1.248 +}

mercurial