Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
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 | #ifndef GFX_PLATFORM_H |
michael@0 | 7 | #define GFX_PLATFORM_H |
michael@0 | 8 | |
michael@0 | 9 | #include "prlog.h" |
michael@0 | 10 | #include "nsTArray.h" |
michael@0 | 11 | #include "nsString.h" |
michael@0 | 12 | #include "nsCOMPtr.h" |
michael@0 | 13 | #include "nsAutoPtr.h" |
michael@0 | 14 | |
michael@0 | 15 | #include "gfxTypes.h" |
michael@0 | 16 | #include "nsRect.h" |
michael@0 | 17 | |
michael@0 | 18 | #include "qcms.h" |
michael@0 | 19 | |
michael@0 | 20 | #include "mozilla/RefPtr.h" |
michael@0 | 21 | #include "GfxInfoCollector.h" |
michael@0 | 22 | |
michael@0 | 23 | #include "mozilla/layers/CompositorTypes.h" |
michael@0 | 24 | |
michael@0 | 25 | class gfxASurface; |
michael@0 | 26 | class gfxImageSurface; |
michael@0 | 27 | class gfxFont; |
michael@0 | 28 | class gfxFontGroup; |
michael@0 | 29 | struct gfxFontStyle; |
michael@0 | 30 | class gfxUserFontSet; |
michael@0 | 31 | class gfxFontEntry; |
michael@0 | 32 | class gfxProxyFontEntry; |
michael@0 | 33 | class gfxPlatformFontList; |
michael@0 | 34 | class gfxTextRun; |
michael@0 | 35 | class nsIURI; |
michael@0 | 36 | class nsIAtom; |
michael@0 | 37 | class nsIObserver; |
michael@0 | 38 | struct gfxRGBA; |
michael@0 | 39 | |
michael@0 | 40 | namespace mozilla { |
michael@0 | 41 | namespace gl { |
michael@0 | 42 | class GLContext; |
michael@0 | 43 | class SkiaGLGlue; |
michael@0 | 44 | } |
michael@0 | 45 | namespace gfx { |
michael@0 | 46 | class DrawTarget; |
michael@0 | 47 | class SourceSurface; |
michael@0 | 48 | class DataSourceSurface; |
michael@0 | 49 | class ScaledFont; |
michael@0 | 50 | class DrawEventRecorder; |
michael@0 | 51 | |
michael@0 | 52 | inline uint32_t |
michael@0 | 53 | BackendTypeBit(BackendType b) |
michael@0 | 54 | { |
michael@0 | 55 | return 1 << uint8_t(b); |
michael@0 | 56 | } |
michael@0 | 57 | } |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | extern cairo_user_data_key_t kDrawTarget; |
michael@0 | 61 | |
michael@0 | 62 | // pref lang id's for font prefs |
michael@0 | 63 | // !!! needs to match the list of pref font.default.xx entries listed in all.js !!! |
michael@0 | 64 | // !!! don't use as bit mask, this may grow larger !!! |
michael@0 | 65 | |
michael@0 | 66 | enum eFontPrefLang { |
michael@0 | 67 | eFontPrefLang_Western = 0, |
michael@0 | 68 | eFontPrefLang_CentEuro = 1, |
michael@0 | 69 | eFontPrefLang_Japanese = 2, |
michael@0 | 70 | eFontPrefLang_ChineseTW = 3, |
michael@0 | 71 | eFontPrefLang_ChineseCN = 4, |
michael@0 | 72 | eFontPrefLang_ChineseHK = 5, |
michael@0 | 73 | eFontPrefLang_Korean = 6, |
michael@0 | 74 | eFontPrefLang_Cyrillic = 7, |
michael@0 | 75 | eFontPrefLang_Baltic = 8, |
michael@0 | 76 | eFontPrefLang_Greek = 9, |
michael@0 | 77 | eFontPrefLang_Turkish = 10, |
michael@0 | 78 | eFontPrefLang_Thai = 11, |
michael@0 | 79 | eFontPrefLang_Hebrew = 12, |
michael@0 | 80 | eFontPrefLang_Arabic = 13, |
michael@0 | 81 | eFontPrefLang_Devanagari = 14, |
michael@0 | 82 | eFontPrefLang_Tamil = 15, |
michael@0 | 83 | eFontPrefLang_Armenian = 16, |
michael@0 | 84 | eFontPrefLang_Bengali = 17, |
michael@0 | 85 | eFontPrefLang_Canadian = 18, |
michael@0 | 86 | eFontPrefLang_Ethiopic = 19, |
michael@0 | 87 | eFontPrefLang_Georgian = 20, |
michael@0 | 88 | eFontPrefLang_Gujarati = 21, |
michael@0 | 89 | eFontPrefLang_Gurmukhi = 22, |
michael@0 | 90 | eFontPrefLang_Khmer = 23, |
michael@0 | 91 | eFontPrefLang_Malayalam = 24, |
michael@0 | 92 | eFontPrefLang_Oriya = 25, |
michael@0 | 93 | eFontPrefLang_Telugu = 26, |
michael@0 | 94 | eFontPrefLang_Kannada = 27, |
michael@0 | 95 | eFontPrefLang_Sinhala = 28, |
michael@0 | 96 | eFontPrefLang_Tibetan = 29, |
michael@0 | 97 | |
michael@0 | 98 | eFontPrefLang_Others = 30, // x-unicode |
michael@0 | 99 | |
michael@0 | 100 | eFontPrefLang_CJKSet = 31 // special code for CJK set |
michael@0 | 101 | }; |
michael@0 | 102 | |
michael@0 | 103 | enum eCMSMode { |
michael@0 | 104 | eCMSMode_Off = 0, // No color management |
michael@0 | 105 | eCMSMode_All = 1, // Color manage everything |
michael@0 | 106 | eCMSMode_TaggedOnly = 2, // Color manage tagged Images Only |
michael@0 | 107 | eCMSMode_AllCount = 3 |
michael@0 | 108 | }; |
michael@0 | 109 | |
michael@0 | 110 | enum eGfxLog { |
michael@0 | 111 | // all font enumerations, localized names, fullname/psnames, cmap loads |
michael@0 | 112 | eGfxLog_fontlist = 0, |
michael@0 | 113 | // timing info on font initialization |
michael@0 | 114 | eGfxLog_fontinit = 1, |
michael@0 | 115 | // dump text runs, font matching, system fallback for content |
michael@0 | 116 | eGfxLog_textrun = 2, |
michael@0 | 117 | // dump text runs, font matching, system fallback for chrome |
michael@0 | 118 | eGfxLog_textrunui = 3, |
michael@0 | 119 | // dump cmap coverage data as they are loaded |
michael@0 | 120 | eGfxLog_cmapdata = 4, |
michael@0 | 121 | // text perf data |
michael@0 | 122 | eGfxLog_textperf = 5 |
michael@0 | 123 | }; |
michael@0 | 124 | |
michael@0 | 125 | // when searching through pref langs, max number of pref langs |
michael@0 | 126 | const uint32_t kMaxLenPrefLangList = 32; |
michael@0 | 127 | |
michael@0 | 128 | #define UNINITIALIZED_VALUE (-1) |
michael@0 | 129 | |
michael@0 | 130 | inline const char* |
michael@0 | 131 | GetBackendName(mozilla::gfx::BackendType aBackend) |
michael@0 | 132 | { |
michael@0 | 133 | switch (aBackend) { |
michael@0 | 134 | case mozilla::gfx::BackendType::DIRECT2D: |
michael@0 | 135 | return "direct2d"; |
michael@0 | 136 | case mozilla::gfx::BackendType::COREGRAPHICS_ACCELERATED: |
michael@0 | 137 | return "quartz accelerated"; |
michael@0 | 138 | case mozilla::gfx::BackendType::COREGRAPHICS: |
michael@0 | 139 | return "quartz"; |
michael@0 | 140 | case mozilla::gfx::BackendType::CAIRO: |
michael@0 | 141 | return "cairo"; |
michael@0 | 142 | case mozilla::gfx::BackendType::SKIA: |
michael@0 | 143 | return "skia"; |
michael@0 | 144 | case mozilla::gfx::BackendType::RECORDING: |
michael@0 | 145 | return "recording"; |
michael@0 | 146 | case mozilla::gfx::BackendType::DIRECT2D1_1: |
michael@0 | 147 | return "direct2d 1.1"; |
michael@0 | 148 | case mozilla::gfx::BackendType::NONE: |
michael@0 | 149 | return "none"; |
michael@0 | 150 | } |
michael@0 | 151 | MOZ_CRASH("Incomplete switch"); |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | class gfxPlatform { |
michael@0 | 155 | public: |
michael@0 | 156 | typedef mozilla::gfx::IntSize IntSize; |
michael@0 | 157 | |
michael@0 | 158 | /** |
michael@0 | 159 | * Return a pointer to the current active platform. |
michael@0 | 160 | * This is a singleton; it contains mostly convenience |
michael@0 | 161 | * functions to obtain platform-specific objects. |
michael@0 | 162 | */ |
michael@0 | 163 | static gfxPlatform *GetPlatform(); |
michael@0 | 164 | |
michael@0 | 165 | |
michael@0 | 166 | /** |
michael@0 | 167 | * Shut down Thebes. |
michael@0 | 168 | * Init() arranges for this to be called at an appropriate time. |
michael@0 | 169 | */ |
michael@0 | 170 | static void Shutdown(); |
michael@0 | 171 | |
michael@0 | 172 | /** |
michael@0 | 173 | * Create an offscreen surface of the given dimensions |
michael@0 | 174 | * and image format. |
michael@0 | 175 | */ |
michael@0 | 176 | virtual already_AddRefed<gfxASurface> |
michael@0 | 177 | CreateOffscreenSurface(const IntSize& size, |
michael@0 | 178 | gfxContentType contentType) = 0; |
michael@0 | 179 | |
michael@0 | 180 | /** |
michael@0 | 181 | * Create an offscreen surface of the given dimensions and image format which |
michael@0 | 182 | * can be converted to a gfxImageSurface without copying. If we can provide |
michael@0 | 183 | * a platform-hosted surface, then we will return that instead of an actual |
michael@0 | 184 | * gfxImageSurface. |
michael@0 | 185 | * Sub-classes should override this method if CreateOffscreenSurface returns a |
michael@0 | 186 | * surface which implements GetAsImageSurface |
michael@0 | 187 | */ |
michael@0 | 188 | virtual already_AddRefed<gfxASurface> |
michael@0 | 189 | CreateOffscreenImageSurface(const gfxIntSize& aSize, |
michael@0 | 190 | gfxContentType aContentType); |
michael@0 | 191 | |
michael@0 | 192 | virtual already_AddRefed<gfxASurface> OptimizeImage(gfxImageSurface *aSurface, |
michael@0 | 193 | gfxImageFormat format); |
michael@0 | 194 | |
michael@0 | 195 | /** |
michael@0 | 196 | * Beware that these methods may return DrawTargets which are not fully supported |
michael@0 | 197 | * on the current platform and might fail silently in subtle ways. This is a massive |
michael@0 | 198 | * potential footgun. You should only use these methods for canvas drawing really. |
michael@0 | 199 | * Use extreme caution if you use them for content where you are not 100% sure we |
michael@0 | 200 | * support the DrawTarget we get back. |
michael@0 | 201 | * See SupportsAzureContentForDrawTarget. |
michael@0 | 202 | */ |
michael@0 | 203 | virtual mozilla::RefPtr<mozilla::gfx::DrawTarget> |
michael@0 | 204 | CreateDrawTargetForSurface(gfxASurface *aSurface, const mozilla::gfx::IntSize& aSize); |
michael@0 | 205 | |
michael@0 | 206 | virtual mozilla::RefPtr<mozilla::gfx::DrawTarget> |
michael@0 | 207 | CreateDrawTargetForUpdateSurface(gfxASurface *aSurface, const mozilla::gfx::IntSize& aSize); |
michael@0 | 208 | |
michael@0 | 209 | /* |
michael@0 | 210 | * Creates a SourceSurface for a gfxASurface. This function does no caching, |
michael@0 | 211 | * so the caller should cache the gfxASurface if it will be used frequently. |
michael@0 | 212 | * The returned surface keeps a reference to aTarget, so it is OK to keep the |
michael@0 | 213 | * surface, even if aTarget changes. |
michael@0 | 214 | * aTarget should not keep a reference to the returned surface because that |
michael@0 | 215 | * will cause a cycle. |
michael@0 | 216 | */ |
michael@0 | 217 | virtual mozilla::RefPtr<mozilla::gfx::SourceSurface> |
michael@0 | 218 | GetSourceSurfaceForSurface(mozilla::gfx::DrawTarget *aTarget, gfxASurface *aSurface); |
michael@0 | 219 | |
michael@0 | 220 | static void ClearSourceSurfaceForSurface(gfxASurface *aSurface); |
michael@0 | 221 | |
michael@0 | 222 | static mozilla::RefPtr<mozilla::gfx::DataSourceSurface> |
michael@0 | 223 | GetWrappedDataSourceSurface(gfxASurface *aSurface); |
michael@0 | 224 | |
michael@0 | 225 | virtual mozilla::TemporaryRef<mozilla::gfx::ScaledFont> |
michael@0 | 226 | GetScaledFontForFont(mozilla::gfx::DrawTarget* aTarget, gfxFont *aFont); |
michael@0 | 227 | |
michael@0 | 228 | virtual already_AddRefed<gfxASurface> |
michael@0 | 229 | GetThebesSurfaceForDrawTarget(mozilla::gfx::DrawTarget *aTarget); |
michael@0 | 230 | |
michael@0 | 231 | mozilla::RefPtr<mozilla::gfx::DrawTarget> |
michael@0 | 232 | CreateOffscreenContentDrawTarget(const mozilla::gfx::IntSize& aSize, mozilla::gfx::SurfaceFormat aFormat); |
michael@0 | 233 | |
michael@0 | 234 | mozilla::RefPtr<mozilla::gfx::DrawTarget> |
michael@0 | 235 | CreateOffscreenCanvasDrawTarget(const mozilla::gfx::IntSize& aSize, mozilla::gfx::SurfaceFormat aFormat); |
michael@0 | 236 | |
michael@0 | 237 | virtual mozilla::RefPtr<mozilla::gfx::DrawTarget> |
michael@0 | 238 | CreateDrawTargetForData(unsigned char* aData, const mozilla::gfx::IntSize& aSize, |
michael@0 | 239 | int32_t aStride, mozilla::gfx::SurfaceFormat aFormat); |
michael@0 | 240 | |
michael@0 | 241 | /** |
michael@0 | 242 | * Returns true if we should use Azure to render content with aTarget. For |
michael@0 | 243 | * example, it is possible that we are using Direct2D for rendering and thus |
michael@0 | 244 | * using Azure. But we want to render to a CairoDrawTarget, in which case |
michael@0 | 245 | * SupportsAzureContent will return true but SupportsAzureContentForDrawTarget |
michael@0 | 246 | * will return false. |
michael@0 | 247 | */ |
michael@0 | 248 | bool SupportsAzureContentForDrawTarget(mozilla::gfx::DrawTarget* aTarget); |
michael@0 | 249 | |
michael@0 | 250 | bool SupportsAzureContentForType(mozilla::gfx::BackendType aType) { |
michael@0 | 251 | return BackendTypeBit(aType) & mContentBackendBitmask; |
michael@0 | 252 | } |
michael@0 | 253 | |
michael@0 | 254 | virtual bool UseAcceleratedSkiaCanvas(); |
michael@0 | 255 | virtual void InitializeSkiaCacheLimits(); |
michael@0 | 256 | |
michael@0 | 257 | void GetAzureBackendInfo(mozilla::widget::InfoObject &aObj) { |
michael@0 | 258 | aObj.DefineProperty("AzureCanvasBackend", GetBackendName(mPreferredCanvasBackend)); |
michael@0 | 259 | aObj.DefineProperty("AzureSkiaAccelerated", UseAcceleratedSkiaCanvas()); |
michael@0 | 260 | aObj.DefineProperty("AzureFallbackCanvasBackend", GetBackendName(mFallbackCanvasBackend)); |
michael@0 | 261 | aObj.DefineProperty("AzureContentBackend", GetBackendName(mContentBackend)); |
michael@0 | 262 | } |
michael@0 | 263 | |
michael@0 | 264 | mozilla::gfx::BackendType GetContentBackend() { |
michael@0 | 265 | return mContentBackend; |
michael@0 | 266 | } |
michael@0 | 267 | |
michael@0 | 268 | mozilla::gfx::BackendType GetPreferredCanvasBackend() { |
michael@0 | 269 | return mPreferredCanvasBackend; |
michael@0 | 270 | } |
michael@0 | 271 | |
michael@0 | 272 | /* |
michael@0 | 273 | * Font bits |
michael@0 | 274 | */ |
michael@0 | 275 | |
michael@0 | 276 | virtual void SetupClusterBoundaries(gfxTextRun *aTextRun, const char16_t *aString); |
michael@0 | 277 | |
michael@0 | 278 | /** |
michael@0 | 279 | * Fill aListOfFonts with the results of querying the list of font names |
michael@0 | 280 | * that correspond to the given language group or generic font family |
michael@0 | 281 | * (or both, or neither). |
michael@0 | 282 | */ |
michael@0 | 283 | virtual nsresult GetFontList(nsIAtom *aLangGroup, |
michael@0 | 284 | const nsACString& aGenericFamily, |
michael@0 | 285 | nsTArray<nsString>& aListOfFonts); |
michael@0 | 286 | |
michael@0 | 287 | /** |
michael@0 | 288 | * Rebuilds the any cached system font lists |
michael@0 | 289 | */ |
michael@0 | 290 | virtual nsresult UpdateFontList(); |
michael@0 | 291 | |
michael@0 | 292 | /** |
michael@0 | 293 | * Create the platform font-list object (gfxPlatformFontList concrete subclass). |
michael@0 | 294 | * This function is responsible to create the appropriate subclass of |
michael@0 | 295 | * gfxPlatformFontList *and* to call its InitFontList() method. |
michael@0 | 296 | */ |
michael@0 | 297 | virtual gfxPlatformFontList *CreatePlatformFontList() { |
michael@0 | 298 | NS_NOTREACHED("oops, this platform doesn't have a gfxPlatformFontList implementation"); |
michael@0 | 299 | return nullptr; |
michael@0 | 300 | } |
michael@0 | 301 | |
michael@0 | 302 | /** |
michael@0 | 303 | * Font name resolver, this returns actual font name(s) by the callback |
michael@0 | 304 | * function. If the font doesn't exist, the callback function is not called. |
michael@0 | 305 | * If the callback function returns false, the aAborted value is set to |
michael@0 | 306 | * true, otherwise, false. |
michael@0 | 307 | */ |
michael@0 | 308 | typedef bool (*FontResolverCallback) (const nsAString& aName, |
michael@0 | 309 | void *aClosure); |
michael@0 | 310 | virtual nsresult ResolveFontName(const nsAString& aFontName, |
michael@0 | 311 | FontResolverCallback aCallback, |
michael@0 | 312 | void *aClosure, |
michael@0 | 313 | bool& aAborted) = 0; |
michael@0 | 314 | |
michael@0 | 315 | /** |
michael@0 | 316 | * Resolving a font name to family name. The result MUST be in the result of GetFontList(). |
michael@0 | 317 | * If the name doesn't in the system, aFamilyName will be empty string, but not failed. |
michael@0 | 318 | */ |
michael@0 | 319 | virtual nsresult GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName) = 0; |
michael@0 | 320 | |
michael@0 | 321 | /** |
michael@0 | 322 | * Create the appropriate platform font group |
michael@0 | 323 | */ |
michael@0 | 324 | virtual gfxFontGroup *CreateFontGroup(const nsAString& aFamilies, |
michael@0 | 325 | const gfxFontStyle *aStyle, |
michael@0 | 326 | gfxUserFontSet *aUserFontSet) = 0; |
michael@0 | 327 | |
michael@0 | 328 | |
michael@0 | 329 | /** |
michael@0 | 330 | * Look up a local platform font using the full font face name. |
michael@0 | 331 | * (Needed to support @font-face src local().) |
michael@0 | 332 | * Ownership of the returned gfxFontEntry is passed to the caller, |
michael@0 | 333 | * who must either AddRef() or delete. |
michael@0 | 334 | */ |
michael@0 | 335 | virtual gfxFontEntry* LookupLocalFont(const gfxProxyFontEntry *aProxyEntry, |
michael@0 | 336 | const nsAString& aFontName) |
michael@0 | 337 | { return nullptr; } |
michael@0 | 338 | |
michael@0 | 339 | /** |
michael@0 | 340 | * Activate a platform font. (Needed to support @font-face src url().) |
michael@0 | 341 | * aFontData is a NS_Malloc'ed block that must be freed by this function |
michael@0 | 342 | * (or responsibility passed on) when it is no longer needed; the caller |
michael@0 | 343 | * will NOT free it. |
michael@0 | 344 | * Ownership of the returned gfxFontEntry is passed to the caller, |
michael@0 | 345 | * who must either AddRef() or delete. |
michael@0 | 346 | */ |
michael@0 | 347 | virtual gfxFontEntry* MakePlatformFont(const gfxProxyFontEntry *aProxyEntry, |
michael@0 | 348 | const uint8_t *aFontData, |
michael@0 | 349 | uint32_t aLength); |
michael@0 | 350 | |
michael@0 | 351 | /** |
michael@0 | 352 | * Whether to allow downloadable fonts via @font-face rules |
michael@0 | 353 | */ |
michael@0 | 354 | bool DownloadableFontsEnabled(); |
michael@0 | 355 | |
michael@0 | 356 | /** |
michael@0 | 357 | * True when hinting should be enabled. This setting shouldn't |
michael@0 | 358 | * change per gecko process, while the process is live. If so the |
michael@0 | 359 | * results are not defined. |
michael@0 | 360 | * |
michael@0 | 361 | * NB: this bit is only honored by the FT2 backend, currently. |
michael@0 | 362 | */ |
michael@0 | 363 | virtual bool FontHintingEnabled() { return true; } |
michael@0 | 364 | |
michael@0 | 365 | /** |
michael@0 | 366 | * True when zooming should not require reflow, so glyph metrics and |
michael@0 | 367 | * positioning should not be adjusted for device pixels. |
michael@0 | 368 | * If this is TRUE, then FontHintingEnabled() should be FALSE, |
michael@0 | 369 | * but the converse is not necessarily required; in particular, |
michael@0 | 370 | * B2G always has FontHintingEnabled FALSE, but RequiresLinearZoom |
michael@0 | 371 | * is only true for the browser process, not Gaia or other apps. |
michael@0 | 372 | * |
michael@0 | 373 | * Like FontHintingEnabled (above), this setting shouldn't |
michael@0 | 374 | * change per gecko process, while the process is live. If so the |
michael@0 | 375 | * results are not defined. |
michael@0 | 376 | * |
michael@0 | 377 | * NB: this bit is only honored by the FT2 backend, currently. |
michael@0 | 378 | */ |
michael@0 | 379 | virtual bool RequiresLinearZoom() { return false; } |
michael@0 | 380 | |
michael@0 | 381 | /** |
michael@0 | 382 | * Whether to check all font cmaps during system font fallback |
michael@0 | 383 | */ |
michael@0 | 384 | bool UseCmapsDuringSystemFallback(); |
michael@0 | 385 | |
michael@0 | 386 | /** |
michael@0 | 387 | * Whether to render SVG glyphs within an OpenType font wrapper |
michael@0 | 388 | */ |
michael@0 | 389 | bool OpenTypeSVGEnabled(); |
michael@0 | 390 | |
michael@0 | 391 | /** |
michael@0 | 392 | * Max character length of words in the word cache |
michael@0 | 393 | */ |
michael@0 | 394 | uint32_t WordCacheCharLimit(); |
michael@0 | 395 | |
michael@0 | 396 | /** |
michael@0 | 397 | * Max number of entries in word cache |
michael@0 | 398 | */ |
michael@0 | 399 | uint32_t WordCacheMaxEntries(); |
michael@0 | 400 | |
michael@0 | 401 | /** |
michael@0 | 402 | * Whether to use the SIL Graphite rendering engine |
michael@0 | 403 | * (for fonts that include Graphite tables) |
michael@0 | 404 | */ |
michael@0 | 405 | bool UseGraphiteShaping(); |
michael@0 | 406 | |
michael@0 | 407 | /** |
michael@0 | 408 | * Whether to use the harfbuzz shaper (depending on script complexity). |
michael@0 | 409 | * |
michael@0 | 410 | * This allows harfbuzz to be enabled selectively via the preferences. |
michael@0 | 411 | */ |
michael@0 | 412 | bool UseHarfBuzzForScript(int32_t aScriptCode); |
michael@0 | 413 | |
michael@0 | 414 | // check whether format is supported on a platform or not (if unclear, returns true) |
michael@0 | 415 | virtual bool IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags) { return false; } |
michael@0 | 416 | |
michael@0 | 417 | void GetPrefFonts(nsIAtom *aLanguage, nsString& array, bool aAppendUnicode = true); |
michael@0 | 418 | |
michael@0 | 419 | // in some situations, need to make decisions about ambiguous characters, may need to look at multiple pref langs |
michael@0 | 420 | void GetLangPrefs(eFontPrefLang aPrefLangs[], uint32_t &aLen, eFontPrefLang aCharLang, eFontPrefLang aPageLang); |
michael@0 | 421 | |
michael@0 | 422 | /** |
michael@0 | 423 | * Iterate over pref fonts given a list of lang groups. For a single lang |
michael@0 | 424 | * group, multiple pref fonts are possible. If error occurs, returns false, |
michael@0 | 425 | * true otherwise. Callback returns false to abort process. |
michael@0 | 426 | */ |
michael@0 | 427 | typedef bool (*PrefFontCallback) (eFontPrefLang aLang, const nsAString& aName, |
michael@0 | 428 | void *aClosure); |
michael@0 | 429 | static bool ForEachPrefFont(eFontPrefLang aLangArray[], uint32_t aLangArrayLen, |
michael@0 | 430 | PrefFontCallback aCallback, |
michael@0 | 431 | void *aClosure); |
michael@0 | 432 | |
michael@0 | 433 | // convert a lang group to enum constant (i.e. "zh-TW" ==> eFontPrefLang_ChineseTW) |
michael@0 | 434 | static eFontPrefLang GetFontPrefLangFor(const char* aLang); |
michael@0 | 435 | |
michael@0 | 436 | // convert a lang group atom to enum constant |
michael@0 | 437 | static eFontPrefLang GetFontPrefLangFor(nsIAtom *aLang); |
michael@0 | 438 | |
michael@0 | 439 | // convert a enum constant to lang group string (i.e. eFontPrefLang_ChineseTW ==> "zh-TW") |
michael@0 | 440 | static const char* GetPrefLangName(eFontPrefLang aLang); |
michael@0 | 441 | |
michael@0 | 442 | // map a Unicode range (based on char code) to a font language for Preferences |
michael@0 | 443 | static eFontPrefLang GetFontPrefLangFor(uint8_t aUnicodeRange); |
michael@0 | 444 | |
michael@0 | 445 | // returns true if a pref lang is CJK |
michael@0 | 446 | static bool IsLangCJK(eFontPrefLang aLang); |
michael@0 | 447 | |
michael@0 | 448 | // helper method to add a pref lang to an array, if not already in array |
michael@0 | 449 | static void AppendPrefLang(eFontPrefLang aPrefLangs[], uint32_t& aLen, eFontPrefLang aAddLang); |
michael@0 | 450 | |
michael@0 | 451 | // returns a list of commonly used fonts for a given character |
michael@0 | 452 | // these are *possible* matches, no cmap-checking is done at this level |
michael@0 | 453 | virtual void GetCommonFallbackFonts(const uint32_t /*aCh*/, |
michael@0 | 454 | int32_t /*aRunScript*/, |
michael@0 | 455 | nsTArray<const char*>& /*aFontList*/) |
michael@0 | 456 | { |
michael@0 | 457 | // platform-specific override, by default do nothing |
michael@0 | 458 | } |
michael@0 | 459 | |
michael@0 | 460 | static bool OffMainThreadCompositingEnabled(); |
michael@0 | 461 | |
michael@0 | 462 | /** Use gfxPlatform::GetPref* methods instead of direct calls to Preferences |
michael@0 | 463 | * to get the values for layers preferences. These will only be evaluated |
michael@0 | 464 | * only once, and remain the same until restart. |
michael@0 | 465 | */ |
michael@0 | 466 | static bool GetPrefLayersOffMainThreadCompositionEnabled(); |
michael@0 | 467 | static bool CanUseDirect3D9(); |
michael@0 | 468 | |
michael@0 | 469 | static bool OffMainThreadCompositionRequired(); |
michael@0 | 470 | |
michael@0 | 471 | /** |
michael@0 | 472 | * Is it possible to use buffer rotation. Note that these |
michael@0 | 473 | * check the preference, but also allow for the override to |
michael@0 | 474 | * disable it using DisableBufferRotation. |
michael@0 | 475 | */ |
michael@0 | 476 | static bool BufferRotationEnabled(); |
michael@0 | 477 | static void DisableBufferRotation(); |
michael@0 | 478 | |
michael@0 | 479 | /** |
michael@0 | 480 | * Are we going to try color management? |
michael@0 | 481 | */ |
michael@0 | 482 | static eCMSMode GetCMSMode(); |
michael@0 | 483 | |
michael@0 | 484 | /** |
michael@0 | 485 | * Determines the rendering intent for color management. |
michael@0 | 486 | * |
michael@0 | 487 | * If the value in the pref gfx.color_management.rendering_intent is a |
michael@0 | 488 | * valid rendering intent as defined in gfx/qcms/qcms.h, that |
michael@0 | 489 | * value is returned. Otherwise, -1 is returned and the embedded intent |
michael@0 | 490 | * should be used. |
michael@0 | 491 | * |
michael@0 | 492 | * See bug 444014 for details. |
michael@0 | 493 | */ |
michael@0 | 494 | static int GetRenderingIntent(); |
michael@0 | 495 | |
michael@0 | 496 | /** |
michael@0 | 497 | * Convert a pixel using a cms transform in an endian-aware manner. |
michael@0 | 498 | * |
michael@0 | 499 | * Sets 'out' to 'in' if transform is nullptr. |
michael@0 | 500 | */ |
michael@0 | 501 | static void TransformPixel(const gfxRGBA& in, gfxRGBA& out, qcms_transform *transform); |
michael@0 | 502 | |
michael@0 | 503 | /** |
michael@0 | 504 | * Return the output device ICC profile. |
michael@0 | 505 | */ |
michael@0 | 506 | static qcms_profile* GetCMSOutputProfile(); |
michael@0 | 507 | |
michael@0 | 508 | /** |
michael@0 | 509 | * Return the sRGB ICC profile. |
michael@0 | 510 | */ |
michael@0 | 511 | static qcms_profile* GetCMSsRGBProfile(); |
michael@0 | 512 | |
michael@0 | 513 | /** |
michael@0 | 514 | * Return sRGB -> output device transform. |
michael@0 | 515 | */ |
michael@0 | 516 | static qcms_transform* GetCMSRGBTransform(); |
michael@0 | 517 | |
michael@0 | 518 | /** |
michael@0 | 519 | * Return output -> sRGB device transform. |
michael@0 | 520 | */ |
michael@0 | 521 | static qcms_transform* GetCMSInverseRGBTransform(); |
michael@0 | 522 | |
michael@0 | 523 | /** |
michael@0 | 524 | * Return sRGBA -> output device transform. |
michael@0 | 525 | */ |
michael@0 | 526 | static qcms_transform* GetCMSRGBATransform(); |
michael@0 | 527 | |
michael@0 | 528 | virtual void FontsPrefsChanged(const char *aPref); |
michael@0 | 529 | |
michael@0 | 530 | int32_t GetBidiNumeralOption(); |
michael@0 | 531 | |
michael@0 | 532 | /** |
michael@0 | 533 | * Returns a 1x1 surface that can be used to create graphics contexts |
michael@0 | 534 | * for measuring text etc as if they will be rendered to the screen |
michael@0 | 535 | */ |
michael@0 | 536 | gfxASurface* ScreenReferenceSurface() { return mScreenReferenceSurface; } |
michael@0 | 537 | mozilla::gfx::DrawTarget* ScreenReferenceDrawTarget() { return mScreenReferenceDrawTarget; } |
michael@0 | 538 | |
michael@0 | 539 | virtual mozilla::gfx::SurfaceFormat Optimal2DFormatForContent(gfxContentType aContent); |
michael@0 | 540 | |
michael@0 | 541 | virtual gfxImageFormat OptimalFormatForContent(gfxContentType aContent); |
michael@0 | 542 | |
michael@0 | 543 | virtual gfxImageFormat GetOffscreenFormat() |
michael@0 | 544 | { return gfxImageFormat::RGB24; } |
michael@0 | 545 | |
michael@0 | 546 | /** |
michael@0 | 547 | * Returns a logger if one is available and logging is enabled |
michael@0 | 548 | */ |
michael@0 | 549 | static PRLogModuleInfo* GetLog(eGfxLog aWhichLog); |
michael@0 | 550 | |
michael@0 | 551 | virtual int GetScreenDepth() const; |
michael@0 | 552 | |
michael@0 | 553 | /** |
michael@0 | 554 | * Return the layer debugging options to use browser-wide. |
michael@0 | 555 | */ |
michael@0 | 556 | mozilla::layers::DiagnosticTypes GetLayerDiagnosticTypes(); |
michael@0 | 557 | |
michael@0 | 558 | static nsIntRect FrameCounterBounds() { |
michael@0 | 559 | int bits = 16; |
michael@0 | 560 | int sizeOfBit = 3; |
michael@0 | 561 | return nsIntRect(0, 0, bits * sizeOfBit, sizeOfBit); |
michael@0 | 562 | } |
michael@0 | 563 | |
michael@0 | 564 | /** |
michael@0 | 565 | * Returns true if we should use raw memory to send data to the compositor |
michael@0 | 566 | * rather than using shmems. |
michael@0 | 567 | * |
michael@0 | 568 | * This method should not be called from the compositor thread. |
michael@0 | 569 | */ |
michael@0 | 570 | bool PreferMemoryOverShmem() const; |
michael@0 | 571 | |
michael@0 | 572 | mozilla::gl::SkiaGLGlue* GetSkiaGLGlue(); |
michael@0 | 573 | void PurgeSkiaCache(); |
michael@0 | 574 | |
michael@0 | 575 | virtual bool IsInGonkEmulator() const { return false; } |
michael@0 | 576 | |
michael@0 | 577 | protected: |
michael@0 | 578 | gfxPlatform(); |
michael@0 | 579 | virtual ~gfxPlatform(); |
michael@0 | 580 | |
michael@0 | 581 | void AppendCJKPrefLangs(eFontPrefLang aPrefLangs[], uint32_t &aLen, |
michael@0 | 582 | eFontPrefLang aCharLang, eFontPrefLang aPageLang); |
michael@0 | 583 | |
michael@0 | 584 | /** |
michael@0 | 585 | * Helper method, creates a draw target for a specific Azure backend. |
michael@0 | 586 | * Used by CreateOffscreenDrawTarget. |
michael@0 | 587 | */ |
michael@0 | 588 | mozilla::RefPtr<mozilla::gfx::DrawTarget> |
michael@0 | 589 | CreateDrawTargetForBackend(mozilla::gfx::BackendType aBackend, |
michael@0 | 590 | const mozilla::gfx::IntSize& aSize, |
michael@0 | 591 | mozilla::gfx::SurfaceFormat aFormat); |
michael@0 | 592 | |
michael@0 | 593 | /** |
michael@0 | 594 | * Initialise the preferred and fallback canvas backends |
michael@0 | 595 | * aBackendBitmask specifies the backends which are acceptable to the caller. |
michael@0 | 596 | * The backend used is determined by aBackendBitmask and the order specified |
michael@0 | 597 | * by the gfx.canvas.azure.backends pref. |
michael@0 | 598 | */ |
michael@0 | 599 | void InitBackendPrefs(uint32_t aCanvasBitmask, mozilla::gfx::BackendType aCanvasDefault, |
michael@0 | 600 | uint32_t aContentBitmask, mozilla::gfx::BackendType aContentDefault); |
michael@0 | 601 | |
michael@0 | 602 | /** |
michael@0 | 603 | * returns the first backend named in the pref gfx.canvas.azure.backends |
michael@0 | 604 | * which is a component of aBackendBitmask, a bitmask of backend types |
michael@0 | 605 | */ |
michael@0 | 606 | static mozilla::gfx::BackendType GetCanvasBackendPref(uint32_t aBackendBitmask); |
michael@0 | 607 | |
michael@0 | 608 | /** |
michael@0 | 609 | * returns the first backend named in the pref gfx.content.azure.backend |
michael@0 | 610 | * which is a component of aBackendBitmask, a bitmask of backend types |
michael@0 | 611 | */ |
michael@0 | 612 | static mozilla::gfx::BackendType GetContentBackendPref(uint32_t &aBackendBitmask); |
michael@0 | 613 | |
michael@0 | 614 | /** |
michael@0 | 615 | * Will return the first backend named in aBackendPrefName |
michael@0 | 616 | * allowed by aBackendBitmask, a bitmask of backend types. |
michael@0 | 617 | * It also modifies aBackendBitmask to only include backends that are |
michael@0 | 618 | * allowed given the prefs. |
michael@0 | 619 | */ |
michael@0 | 620 | static mozilla::gfx::BackendType GetBackendPref(const char* aBackendPrefName, |
michael@0 | 621 | uint32_t &aBackendBitmask); |
michael@0 | 622 | /** |
michael@0 | 623 | * Decode the backend enumberation from a string. |
michael@0 | 624 | */ |
michael@0 | 625 | static mozilla::gfx::BackendType BackendTypeForName(const nsCString& aName); |
michael@0 | 626 | |
michael@0 | 627 | static mozilla::TemporaryRef<mozilla::gfx::ScaledFont> |
michael@0 | 628 | GetScaledFontForFontWithCairoSkia(mozilla::gfx::DrawTarget* aTarget, gfxFont* aFont); |
michael@0 | 629 | |
michael@0 | 630 | int8_t mAllowDownloadableFonts; |
michael@0 | 631 | int8_t mGraphiteShapingEnabled; |
michael@0 | 632 | int8_t mOpenTypeSVGEnabled; |
michael@0 | 633 | |
michael@0 | 634 | int8_t mBidiNumeralOption; |
michael@0 | 635 | |
michael@0 | 636 | // whether to always search font cmaps globally |
michael@0 | 637 | // when doing system font fallback |
michael@0 | 638 | int8_t mFallbackUsesCmaps; |
michael@0 | 639 | |
michael@0 | 640 | // which scripts should be shaped with harfbuzz |
michael@0 | 641 | int32_t mUseHarfBuzzScripts; |
michael@0 | 642 | |
michael@0 | 643 | // max character limit for words in word cache |
michael@0 | 644 | int32_t mWordCacheCharLimit; |
michael@0 | 645 | |
michael@0 | 646 | // max number of entries in word cache |
michael@0 | 647 | int32_t mWordCacheMaxEntries; |
michael@0 | 648 | |
michael@0 | 649 | private: |
michael@0 | 650 | /** |
michael@0 | 651 | * Start up Thebes. |
michael@0 | 652 | */ |
michael@0 | 653 | static void Init(); |
michael@0 | 654 | |
michael@0 | 655 | static void CreateCMSOutputProfile(); |
michael@0 | 656 | |
michael@0 | 657 | static void GetCMSOutputProfileData(void *&mem, size_t &size); |
michael@0 | 658 | |
michael@0 | 659 | friend void RecordingPrefChanged(const char *aPrefName, void *aClosure); |
michael@0 | 660 | |
michael@0 | 661 | virtual void GetPlatformCMSOutputProfile(void *&mem, size_t &size); |
michael@0 | 662 | |
michael@0 | 663 | virtual bool SupportsOffMainThreadCompositing() { return true; } |
michael@0 | 664 | |
michael@0 | 665 | nsRefPtr<gfxASurface> mScreenReferenceSurface; |
michael@0 | 666 | mozilla::RefPtr<mozilla::gfx::DrawTarget> mScreenReferenceDrawTarget; |
michael@0 | 667 | nsTArray<uint32_t> mCJKPrefLangs; |
michael@0 | 668 | nsCOMPtr<nsIObserver> mSRGBOverrideObserver; |
michael@0 | 669 | nsCOMPtr<nsIObserver> mFontPrefsObserver; |
michael@0 | 670 | nsCOMPtr<nsIObserver> mMemoryPressureObserver; |
michael@0 | 671 | |
michael@0 | 672 | // The preferred draw target backend to use for canvas |
michael@0 | 673 | mozilla::gfx::BackendType mPreferredCanvasBackend; |
michael@0 | 674 | // The fallback draw target backend to use for canvas, if the preferred backend fails |
michael@0 | 675 | mozilla::gfx::BackendType mFallbackCanvasBackend; |
michael@0 | 676 | // The backend to use for content |
michael@0 | 677 | mozilla::gfx::BackendType mContentBackend; |
michael@0 | 678 | // Bitmask of backend types we can use to render content |
michael@0 | 679 | uint32_t mContentBackendBitmask; |
michael@0 | 680 | |
michael@0 | 681 | mozilla::widget::GfxInfoCollector<gfxPlatform> mAzureCanvasBackendCollector; |
michael@0 | 682 | |
michael@0 | 683 | mozilla::RefPtr<mozilla::gfx::DrawEventRecorder> mRecorder; |
michael@0 | 684 | bool mLayersPreferMemoryOverShmem; |
michael@0 | 685 | mozilla::RefPtr<mozilla::gl::SkiaGLGlue> mSkiaGlue; |
michael@0 | 686 | }; |
michael@0 | 687 | |
michael@0 | 688 | #endif /* GFX_PLATFORM_H */ |