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