gfx/thebes/gfxQtPlatform.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  * This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include <QPixmap>
     7 #include <QWindow>
     8 #ifdef MOZ_X11
     9 #include <qpa/qplatformnativeinterface.h>
    10 #include <qpa/qplatformintegration.h>
    11 #endif
    12 #include <QGuiApplication>
    13 #include <QScreen>
    15 #include "gfxQtPlatform.h"
    17 #include "gfxFontconfigUtils.h"
    19 #include "mozilla/gfx/2D.h"
    21 #include "cairo.h"
    23 #include "gfxImageSurface.h"
    24 #include "gfxQPainterSurface.h"
    25 #include "nsUnicodeProperties.h"
    27 #include "gfxPangoFonts.h"
    28 #include "gfxContext.h"
    29 #include "gfxUserFontSet.h"
    31 #include "nsUnicharUtils.h"
    33 #include "nsMathUtils.h"
    34 #include "nsTArray.h"
    35 #ifdef MOZ_X11
    36 #include "gfxXlibSurface.h"
    37 #include "prenv.h"
    38 #endif
    40 #include "qcms.h"
    42 #include "mozilla/Preferences.h"
    44 using namespace mozilla;
    45 using namespace mozilla::unicode;
    46 using namespace mozilla::gfx;
    48 gfxFontconfigUtils *gfxQtPlatform::sFontconfigUtils = nullptr;
    49 #ifdef MOZ_X11
    50 bool gfxQtPlatform::sUseXRender = true;
    51 #endif
    53 static gfxImageFormat sOffscreenFormat = gfxImageFormat::RGB24;
    55 gfxQtPlatform::gfxQtPlatform()
    56 {
    57 #ifdef MOZ_X11
    58     sUseXRender = mozilla::Preferences::GetBool("gfx.xrender.enabled");
    59 #endif
    60     if (!sFontconfigUtils)
    61         sFontconfigUtils = gfxFontconfigUtils::GetFontconfigUtils();
    63     mScreenDepth = qApp->primaryScreen()->depth();
    64     if (mScreenDepth == 16) {
    65         sOffscreenFormat = gfxImageFormat::RGB16_565;
    66     }
    67     uint32_t canvasMask = BackendTypeBit(BackendType::CAIRO) | BackendTypeBit(BackendType::SKIA);
    68     uint32_t contentMask = BackendTypeBit(BackendType::CAIRO) | BackendTypeBit(BackendType::SKIA);
    69     InitBackendPrefs(canvasMask, BackendType::CAIRO,
    70                      contentMask, BackendType::CAIRO);
    71 }
    73 gfxQtPlatform::~gfxQtPlatform()
    74 {
    75     gfxFontconfigUtils::Shutdown();
    76     sFontconfigUtils = nullptr;
    78     gfxPangoFontGroup::Shutdown();
    79 }
    81 #ifdef MOZ_X11
    82 Display*
    83 gfxQtPlatform::GetXDisplay(QWindow* aWindow)
    84 {
    85     return (Display*)(qApp->platformNativeInterface()->
    86         nativeResourceForScreen("display", aWindow ? aWindow->screen() : qApp->primaryScreen()));
    87 }
    89 Screen*
    90 gfxQtPlatform::GetXScreen(QWindow* aWindow)
    91 {
    92     return ScreenOfDisplay(GetXDisplay(aWindow),
    93         (int)(intptr_t)qApp->platformNativeInterface()->
    94             nativeResourceForScreen("screen", aWindow ? aWindow->screen() : qApp->primaryScreen()));
    95 }
    96 #endif
    98 already_AddRefed<gfxASurface>
    99 gfxQtPlatform::CreateOffscreenSurface(const IntSize& size,
   100                                       gfxContentType contentType)
   101 {
   102     gfxImageFormat imageFormat = OptimalFormatForContent(contentType);
   104     nsRefPtr<gfxASurface> newSurface =
   105         new gfxImageSurface(gfxIntSize(size.width, size.height), imageFormat);
   107     return newSurface.forget();
   108 }
   110 already_AddRefed<gfxASurface>
   111 gfxQtPlatform::OptimizeImage(gfxImageSurface *aSurface,
   112                              gfxImageFormat format)
   113 {
   114     /* Qt have no special offscreen surfaces so we can avoid a copy */
   115     if (OptimalFormatForContent(gfxASurface::ContentFromFormat(format)) ==
   116         format) {
   117         return nullptr;
   118     }
   120     return gfxPlatform::OptimizeImage(aSurface, format);
   121 }
   124 nsresult
   125 gfxQtPlatform::GetFontList(nsIAtom *aLangGroup,
   126                            const nsACString& aGenericFamily,
   127                            nsTArray<nsString>& aListOfFonts)
   128 {
   129     return sFontconfigUtils->GetFontList(aLangGroup, aGenericFamily,
   130                                          aListOfFonts);
   131 }
   133 nsresult
   134 gfxQtPlatform::UpdateFontList()
   135 {
   136     return sFontconfigUtils->UpdateFontList();
   137 }
   139 nsresult
   140 gfxQtPlatform::ResolveFontName(const nsAString& aFontName,
   141                                 FontResolverCallback aCallback,
   142                                 void *aClosure,
   143                                 bool& aAborted)
   144 {
   145     return sFontconfigUtils->ResolveFontName(aFontName, aCallback,
   146                                              aClosure, aAborted);
   147 }
   149 nsresult
   150 gfxQtPlatform::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName)
   151 {
   152     return sFontconfigUtils->GetStandardFamilyName(aFontName, aFamilyName);
   153 }
   155 gfxFontGroup *
   156 gfxQtPlatform::CreateFontGroup(const nsAString &aFamilies,
   157                                const gfxFontStyle *aStyle,
   158                                gfxUserFontSet* aUserFontSet)
   159 {
   160     return new gfxPangoFontGroup(aFamilies, aStyle, aUserFontSet);
   161 }
   163 gfxFontEntry*
   164 gfxQtPlatform::LookupLocalFont(const gfxProxyFontEntry *aProxyEntry,
   165                                 const nsAString& aFontName)
   166 {
   167     return gfxPangoFontGroup::NewFontEntry(*aProxyEntry, aFontName);
   168 }
   170 gfxFontEntry*
   171 gfxQtPlatform::MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
   172                                  const uint8_t *aFontData, uint32_t aLength)
   173 {
   174     // passing ownership of the font data to the new font entry
   175     return gfxPangoFontGroup::NewFontEntry(*aProxyEntry,
   176                                            aFontData, aLength);
   177 }
   179 bool
   180 gfxQtPlatform::SupportsOffMainThreadCompositing()
   181 {
   182 #if defined(MOZ_X11) && !defined(NIGHTLY_BUILD)
   183   return (PR_GetEnv("MOZ_USE_OMTC") != nullptr) ||
   184          (PR_GetEnv("MOZ_OMTC_ENABLED") != nullptr);
   185 #else
   186   return true;
   187 #endif
   188 }
   190 bool
   191 gfxQtPlatform::IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags)
   192 {
   193     // check for strange format flags
   194     NS_ASSERTION(!(aFormatFlags & gfxUserFontSet::FLAG_FORMAT_NOT_USED),
   195                  "strange font format hint set");
   197     // accept supported formats
   198     // Pango doesn't apply features from AAT TrueType extensions.
   199     // Assume that if this is the only SFNT format specified,
   200     // then AAT extensions are required for complex script support.
   201     if (aFormatFlags & (gfxUserFontSet::FLAG_FORMAT_WOFF     |
   202                         gfxUserFontSet::FLAG_FORMAT_OPENTYPE |
   203                         gfxUserFontSet::FLAG_FORMAT_TRUETYPE)) {
   204         return true;
   205     }
   207     // reject all other formats, known and unknown
   208     if (aFormatFlags != 0) {
   209         return false;
   210     }
   212     // no format hint set, need to look at data
   213     return true;
   214 }
   216 void
   217 gfxQtPlatform::GetPlatformCMSOutputProfile(void *&mem, size_t &size)
   218 {
   219     mem = nullptr;
   220     size = 0;
   221 }
   223 int32_t
   224 gfxQtPlatform::GetDPI()
   225 {
   226     return qApp->primaryScreen()->logicalDotsPerInch();
   227 }
   229 gfxImageFormat
   230 gfxQtPlatform::GetOffscreenFormat()
   231 {
   232     return sOffscreenFormat;
   233 }
   235 int
   236 gfxQtPlatform::GetScreenDepth() const
   237 {
   238     return mScreenDepth;
   239 }
   241 TemporaryRef<ScaledFont>
   242 gfxQtPlatform::GetScaledFontForFont(DrawTarget* aTarget, gfxFont* aFont)
   243 {
   244     return GetScaledFontForFontWithCairoSkia(aTarget, aFont);
   245 }

mercurial