gfx/thebes/gfxPlatform.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/thebes/gfxPlatform.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,688 @@
     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 +#ifndef GFX_PLATFORM_H
    1.10 +#define GFX_PLATFORM_H
    1.11 +
    1.12 +#include "prlog.h"
    1.13 +#include "nsTArray.h"
    1.14 +#include "nsString.h"
    1.15 +#include "nsCOMPtr.h"
    1.16 +#include "nsAutoPtr.h"
    1.17 +
    1.18 +#include "gfxTypes.h"
    1.19 +#include "nsRect.h"
    1.20 +
    1.21 +#include "qcms.h"
    1.22 +
    1.23 +#include "mozilla/RefPtr.h"
    1.24 +#include "GfxInfoCollector.h"
    1.25 +
    1.26 +#include "mozilla/layers/CompositorTypes.h"
    1.27 +
    1.28 +class gfxASurface;
    1.29 +class gfxImageSurface;
    1.30 +class gfxFont;
    1.31 +class gfxFontGroup;
    1.32 +struct gfxFontStyle;
    1.33 +class gfxUserFontSet;
    1.34 +class gfxFontEntry;
    1.35 +class gfxProxyFontEntry;
    1.36 +class gfxPlatformFontList;
    1.37 +class gfxTextRun;
    1.38 +class nsIURI;
    1.39 +class nsIAtom;
    1.40 +class nsIObserver;
    1.41 +struct gfxRGBA;
    1.42 +
    1.43 +namespace mozilla {
    1.44 +namespace gl {
    1.45 +class GLContext;
    1.46 +class SkiaGLGlue;
    1.47 +}
    1.48 +namespace gfx {
    1.49 +class DrawTarget;
    1.50 +class SourceSurface;
    1.51 +class DataSourceSurface;
    1.52 +class ScaledFont;
    1.53 +class DrawEventRecorder;
    1.54 +
    1.55 +inline uint32_t
    1.56 +BackendTypeBit(BackendType b)
    1.57 +{
    1.58 +  return 1 << uint8_t(b);
    1.59 +}
    1.60 +}
    1.61 +}
    1.62 +
    1.63 +extern cairo_user_data_key_t kDrawTarget;
    1.64 +
    1.65 +// pref lang id's for font prefs
    1.66 +// !!! needs to match the list of pref font.default.xx entries listed in all.js !!!
    1.67 +// !!! don't use as bit mask, this may grow larger !!!
    1.68 +
    1.69 +enum eFontPrefLang {
    1.70 +    eFontPrefLang_Western     =  0,
    1.71 +    eFontPrefLang_CentEuro    =  1,
    1.72 +    eFontPrefLang_Japanese    =  2,
    1.73 +    eFontPrefLang_ChineseTW   =  3,
    1.74 +    eFontPrefLang_ChineseCN   =  4,
    1.75 +    eFontPrefLang_ChineseHK   =  5,
    1.76 +    eFontPrefLang_Korean      =  6,
    1.77 +    eFontPrefLang_Cyrillic    =  7,
    1.78 +    eFontPrefLang_Baltic      =  8,
    1.79 +    eFontPrefLang_Greek       =  9,
    1.80 +    eFontPrefLang_Turkish     = 10,
    1.81 +    eFontPrefLang_Thai        = 11,
    1.82 +    eFontPrefLang_Hebrew      = 12,
    1.83 +    eFontPrefLang_Arabic      = 13,
    1.84 +    eFontPrefLang_Devanagari  = 14,
    1.85 +    eFontPrefLang_Tamil       = 15,
    1.86 +    eFontPrefLang_Armenian    = 16,
    1.87 +    eFontPrefLang_Bengali     = 17,
    1.88 +    eFontPrefLang_Canadian    = 18,
    1.89 +    eFontPrefLang_Ethiopic    = 19,
    1.90 +    eFontPrefLang_Georgian    = 20,
    1.91 +    eFontPrefLang_Gujarati    = 21,
    1.92 +    eFontPrefLang_Gurmukhi    = 22,
    1.93 +    eFontPrefLang_Khmer       = 23,
    1.94 +    eFontPrefLang_Malayalam   = 24,
    1.95 +    eFontPrefLang_Oriya       = 25,
    1.96 +    eFontPrefLang_Telugu      = 26,
    1.97 +    eFontPrefLang_Kannada     = 27,
    1.98 +    eFontPrefLang_Sinhala     = 28,
    1.99 +    eFontPrefLang_Tibetan     = 29,
   1.100 +
   1.101 +    eFontPrefLang_Others      = 30, // x-unicode
   1.102 +
   1.103 +    eFontPrefLang_CJKSet      = 31  // special code for CJK set
   1.104 +};
   1.105 +
   1.106 +enum eCMSMode {
   1.107 +    eCMSMode_Off          = 0,     // No color management
   1.108 +    eCMSMode_All          = 1,     // Color manage everything
   1.109 +    eCMSMode_TaggedOnly   = 2,     // Color manage tagged Images Only
   1.110 +    eCMSMode_AllCount     = 3
   1.111 +};
   1.112 +
   1.113 +enum eGfxLog {
   1.114 +    // all font enumerations, localized names, fullname/psnames, cmap loads
   1.115 +    eGfxLog_fontlist         = 0,
   1.116 +    // timing info on font initialization
   1.117 +    eGfxLog_fontinit         = 1,
   1.118 +    // dump text runs, font matching, system fallback for content
   1.119 +    eGfxLog_textrun          = 2,
   1.120 +    // dump text runs, font matching, system fallback for chrome
   1.121 +    eGfxLog_textrunui        = 3,
   1.122 +    // dump cmap coverage data as they are loaded
   1.123 +    eGfxLog_cmapdata         = 4,
   1.124 +    // text perf data
   1.125 +    eGfxLog_textperf         = 5
   1.126 +};
   1.127 +
   1.128 +// when searching through pref langs, max number of pref langs
   1.129 +const uint32_t kMaxLenPrefLangList = 32;
   1.130 +
   1.131 +#define UNINITIALIZED_VALUE  (-1)
   1.132 +
   1.133 +inline const char*
   1.134 +GetBackendName(mozilla::gfx::BackendType aBackend)
   1.135 +{
   1.136 +  switch (aBackend) {
   1.137 +      case mozilla::gfx::BackendType::DIRECT2D:
   1.138 +        return "direct2d";
   1.139 +      case mozilla::gfx::BackendType::COREGRAPHICS_ACCELERATED:
   1.140 +        return "quartz accelerated";
   1.141 +      case mozilla::gfx::BackendType::COREGRAPHICS:
   1.142 +        return "quartz";
   1.143 +      case mozilla::gfx::BackendType::CAIRO:
   1.144 +        return "cairo";
   1.145 +      case mozilla::gfx::BackendType::SKIA:
   1.146 +        return "skia";
   1.147 +      case mozilla::gfx::BackendType::RECORDING:
   1.148 +        return "recording";
   1.149 +      case mozilla::gfx::BackendType::DIRECT2D1_1:
   1.150 +        return "direct2d 1.1";
   1.151 +      case mozilla::gfx::BackendType::NONE:
   1.152 +        return "none";
   1.153 +  }
   1.154 +  MOZ_CRASH("Incomplete switch");
   1.155 +}
   1.156 +
   1.157 +class gfxPlatform {
   1.158 +public:
   1.159 +    typedef mozilla::gfx::IntSize IntSize;
   1.160 +
   1.161 +    /**
   1.162 +     * Return a pointer to the current active platform.
   1.163 +     * This is a singleton; it contains mostly convenience
   1.164 +     * functions to obtain platform-specific objects.
   1.165 +     */
   1.166 +    static gfxPlatform *GetPlatform();
   1.167 +
   1.168 +
   1.169 +    /**
   1.170 +     * Shut down Thebes.
   1.171 +     * Init() arranges for this to be called at an appropriate time.
   1.172 +     */
   1.173 +    static void Shutdown();
   1.174 +
   1.175 +    /**
   1.176 +     * Create an offscreen surface of the given dimensions
   1.177 +     * and image format.
   1.178 +     */
   1.179 +    virtual already_AddRefed<gfxASurface>
   1.180 +      CreateOffscreenSurface(const IntSize& size,
   1.181 +                             gfxContentType contentType) = 0;
   1.182 +
   1.183 +    /**
   1.184 +     * Create an offscreen surface of the given dimensions and image format which
   1.185 +     * can be converted to a gfxImageSurface without copying. If we can provide
   1.186 +     * a platform-hosted surface, then we will return that instead of an actual
   1.187 +     * gfxImageSurface.
   1.188 +     * Sub-classes should override this method if CreateOffscreenSurface returns a
   1.189 +     * surface which implements GetAsImageSurface
   1.190 +     */
   1.191 +    virtual already_AddRefed<gfxASurface>
   1.192 +      CreateOffscreenImageSurface(const gfxIntSize& aSize,
   1.193 +                                  gfxContentType aContentType);
   1.194 +
   1.195 +    virtual already_AddRefed<gfxASurface> OptimizeImage(gfxImageSurface *aSurface,
   1.196 +                                                        gfxImageFormat format);
   1.197 +
   1.198 +    /**
   1.199 +     * Beware that these methods may return DrawTargets which are not fully supported
   1.200 +     * on the current platform and might fail silently in subtle ways. This is a massive
   1.201 +     * potential footgun. You should only use these methods for canvas drawing really.
   1.202 +     * Use extreme caution if you use them for content where you are not 100% sure we
   1.203 +     * support the DrawTarget we get back.
   1.204 +     * See SupportsAzureContentForDrawTarget.
   1.205 +     */
   1.206 +    virtual mozilla::RefPtr<mozilla::gfx::DrawTarget>
   1.207 +      CreateDrawTargetForSurface(gfxASurface *aSurface, const mozilla::gfx::IntSize& aSize);
   1.208 +
   1.209 +    virtual mozilla::RefPtr<mozilla::gfx::DrawTarget>
   1.210 +      CreateDrawTargetForUpdateSurface(gfxASurface *aSurface, const mozilla::gfx::IntSize& aSize);
   1.211 +
   1.212 +    /*
   1.213 +     * Creates a SourceSurface for a gfxASurface. This function does no caching,
   1.214 +     * so the caller should cache the gfxASurface if it will be used frequently.
   1.215 +     * The returned surface keeps a reference to aTarget, so it is OK to keep the
   1.216 +     * surface, even if aTarget changes.
   1.217 +     * aTarget should not keep a reference to the returned surface because that
   1.218 +     * will cause a cycle.
   1.219 +     */
   1.220 +    virtual mozilla::RefPtr<mozilla::gfx::SourceSurface>
   1.221 +      GetSourceSurfaceForSurface(mozilla::gfx::DrawTarget *aTarget, gfxASurface *aSurface);
   1.222 +
   1.223 +    static void ClearSourceSurfaceForSurface(gfxASurface *aSurface);
   1.224 +
   1.225 +    static mozilla::RefPtr<mozilla::gfx::DataSourceSurface>
   1.226 +        GetWrappedDataSourceSurface(gfxASurface *aSurface);
   1.227 +
   1.228 +    virtual mozilla::TemporaryRef<mozilla::gfx::ScaledFont>
   1.229 +      GetScaledFontForFont(mozilla::gfx::DrawTarget* aTarget, gfxFont *aFont);
   1.230 +
   1.231 +    virtual already_AddRefed<gfxASurface>
   1.232 +      GetThebesSurfaceForDrawTarget(mozilla::gfx::DrawTarget *aTarget);
   1.233 +
   1.234 +    mozilla::RefPtr<mozilla::gfx::DrawTarget>
   1.235 +      CreateOffscreenContentDrawTarget(const mozilla::gfx::IntSize& aSize, mozilla::gfx::SurfaceFormat aFormat);
   1.236 +
   1.237 +    mozilla::RefPtr<mozilla::gfx::DrawTarget>
   1.238 +      CreateOffscreenCanvasDrawTarget(const mozilla::gfx::IntSize& aSize, mozilla::gfx::SurfaceFormat aFormat);
   1.239 +
   1.240 +    virtual mozilla::RefPtr<mozilla::gfx::DrawTarget>
   1.241 +      CreateDrawTargetForData(unsigned char* aData, const mozilla::gfx::IntSize& aSize, 
   1.242 +                              int32_t aStride, mozilla::gfx::SurfaceFormat aFormat);
   1.243 +
   1.244 +    /**
   1.245 +     * Returns true if we should use Azure to render content with aTarget. For
   1.246 +     * example, it is possible that we are using Direct2D for rendering and thus
   1.247 +     * using Azure. But we want to render to a CairoDrawTarget, in which case
   1.248 +     * SupportsAzureContent will return true but SupportsAzureContentForDrawTarget
   1.249 +     * will return false.
   1.250 +     */
   1.251 +    bool SupportsAzureContentForDrawTarget(mozilla::gfx::DrawTarget* aTarget);
   1.252 +
   1.253 +    bool SupportsAzureContentForType(mozilla::gfx::BackendType aType) {
   1.254 +      return BackendTypeBit(aType) & mContentBackendBitmask;
   1.255 +    }
   1.256 +
   1.257 +    virtual bool UseAcceleratedSkiaCanvas();
   1.258 +    virtual void InitializeSkiaCacheLimits();
   1.259 +
   1.260 +    void GetAzureBackendInfo(mozilla::widget::InfoObject &aObj) {
   1.261 +      aObj.DefineProperty("AzureCanvasBackend", GetBackendName(mPreferredCanvasBackend));
   1.262 +      aObj.DefineProperty("AzureSkiaAccelerated", UseAcceleratedSkiaCanvas());
   1.263 +      aObj.DefineProperty("AzureFallbackCanvasBackend", GetBackendName(mFallbackCanvasBackend));
   1.264 +      aObj.DefineProperty("AzureContentBackend", GetBackendName(mContentBackend));
   1.265 +    }
   1.266 +
   1.267 +    mozilla::gfx::BackendType GetContentBackend() {
   1.268 +      return mContentBackend;
   1.269 +    }
   1.270 +
   1.271 +    mozilla::gfx::BackendType GetPreferredCanvasBackend() {
   1.272 +      return mPreferredCanvasBackend;
   1.273 +    }
   1.274 +
   1.275 +    /*
   1.276 +     * Font bits
   1.277 +     */
   1.278 +
   1.279 +    virtual void SetupClusterBoundaries(gfxTextRun *aTextRun, const char16_t *aString);
   1.280 +
   1.281 +    /**
   1.282 +     * Fill aListOfFonts with the results of querying the list of font names
   1.283 +     * that correspond to the given language group or generic font family
   1.284 +     * (or both, or neither).
   1.285 +     */
   1.286 +    virtual nsresult GetFontList(nsIAtom *aLangGroup,
   1.287 +                                 const nsACString& aGenericFamily,
   1.288 +                                 nsTArray<nsString>& aListOfFonts);
   1.289 +
   1.290 +    /**
   1.291 +     * Rebuilds the any cached system font lists
   1.292 +     */
   1.293 +    virtual nsresult UpdateFontList();
   1.294 +
   1.295 +    /**
   1.296 +     * Create the platform font-list object (gfxPlatformFontList concrete subclass).
   1.297 +     * This function is responsible to create the appropriate subclass of
   1.298 +     * gfxPlatformFontList *and* to call its InitFontList() method.
   1.299 +     */
   1.300 +    virtual gfxPlatformFontList *CreatePlatformFontList() {
   1.301 +        NS_NOTREACHED("oops, this platform doesn't have a gfxPlatformFontList implementation");
   1.302 +        return nullptr;
   1.303 +    }
   1.304 +
   1.305 +    /**
   1.306 +     * Font name resolver, this returns actual font name(s) by the callback
   1.307 +     * function. If the font doesn't exist, the callback function is not called.
   1.308 +     * If the callback function returns false, the aAborted value is set to
   1.309 +     * true, otherwise, false.
   1.310 +     */
   1.311 +    typedef bool (*FontResolverCallback) (const nsAString& aName,
   1.312 +                                            void *aClosure);
   1.313 +    virtual nsresult ResolveFontName(const nsAString& aFontName,
   1.314 +                                     FontResolverCallback aCallback,
   1.315 +                                     void *aClosure,
   1.316 +                                     bool& aAborted) = 0;
   1.317 +
   1.318 +    /**
   1.319 +     * Resolving a font name to family name. The result MUST be in the result of GetFontList().
   1.320 +     * If the name doesn't in the system, aFamilyName will be empty string, but not failed.
   1.321 +     */
   1.322 +    virtual nsresult GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName) = 0;
   1.323 +
   1.324 +    /**
   1.325 +     * Create the appropriate platform font group
   1.326 +     */
   1.327 +    virtual gfxFontGroup *CreateFontGroup(const nsAString& aFamilies,
   1.328 +                                          const gfxFontStyle *aStyle,
   1.329 +                                          gfxUserFontSet *aUserFontSet) = 0;
   1.330 +                                          
   1.331 +                                          
   1.332 +    /**
   1.333 +     * Look up a local platform font using the full font face name.
   1.334 +     * (Needed to support @font-face src local().)
   1.335 +     * Ownership of the returned gfxFontEntry is passed to the caller,
   1.336 +     * who must either AddRef() or delete.
   1.337 +     */
   1.338 +    virtual gfxFontEntry* LookupLocalFont(const gfxProxyFontEntry *aProxyEntry,
   1.339 +                                          const nsAString& aFontName)
   1.340 +    { return nullptr; }
   1.341 +
   1.342 +    /**
   1.343 +     * Activate a platform font.  (Needed to support @font-face src url().)
   1.344 +     * aFontData is a NS_Malloc'ed block that must be freed by this function
   1.345 +     * (or responsibility passed on) when it is no longer needed; the caller
   1.346 +     * will NOT free it.
   1.347 +     * Ownership of the returned gfxFontEntry is passed to the caller,
   1.348 +     * who must either AddRef() or delete.
   1.349 +     */
   1.350 +    virtual gfxFontEntry* MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
   1.351 +                                           const uint8_t *aFontData,
   1.352 +                                           uint32_t aLength);
   1.353 +
   1.354 +    /**
   1.355 +     * Whether to allow downloadable fonts via @font-face rules
   1.356 +     */
   1.357 +    bool DownloadableFontsEnabled();
   1.358 +
   1.359 +    /**
   1.360 +     * True when hinting should be enabled.  This setting shouldn't
   1.361 +     * change per gecko process, while the process is live.  If so the
   1.362 +     * results are not defined.
   1.363 +     *
   1.364 +     * NB: this bit is only honored by the FT2 backend, currently.
   1.365 +     */
   1.366 +    virtual bool FontHintingEnabled() { return true; }
   1.367 +
   1.368 +    /**
   1.369 +     * True when zooming should not require reflow, so glyph metrics and
   1.370 +     * positioning should not be adjusted for device pixels.
   1.371 +     * If this is TRUE, then FontHintingEnabled() should be FALSE,
   1.372 +     * but the converse is not necessarily required; in particular,
   1.373 +     * B2G always has FontHintingEnabled FALSE, but RequiresLinearZoom
   1.374 +     * is only true for the browser process, not Gaia or other apps.
   1.375 +     *
   1.376 +     * Like FontHintingEnabled (above), this setting shouldn't
   1.377 +     * change per gecko process, while the process is live.  If so the
   1.378 +     * results are not defined.
   1.379 +     *
   1.380 +     * NB: this bit is only honored by the FT2 backend, currently.
   1.381 +     */
   1.382 +    virtual bool RequiresLinearZoom() { return false; }
   1.383 +
   1.384 +    /**
   1.385 +     * Whether to check all font cmaps during system font fallback
   1.386 +     */
   1.387 +    bool UseCmapsDuringSystemFallback();
   1.388 +
   1.389 +    /**
   1.390 +     * Whether to render SVG glyphs within an OpenType font wrapper
   1.391 +     */
   1.392 +    bool OpenTypeSVGEnabled();
   1.393 +
   1.394 +    /**
   1.395 +     * Max character length of words in the word cache
   1.396 +     */
   1.397 +    uint32_t WordCacheCharLimit();
   1.398 +
   1.399 +    /**
   1.400 +     * Max number of entries in word cache
   1.401 +     */
   1.402 +    uint32_t WordCacheMaxEntries();
   1.403 +
   1.404 +    /**
   1.405 +     * Whether to use the SIL Graphite rendering engine
   1.406 +     * (for fonts that include Graphite tables)
   1.407 +     */
   1.408 +    bool UseGraphiteShaping();
   1.409 +
   1.410 +    /**
   1.411 +     * Whether to use the harfbuzz shaper (depending on script complexity).
   1.412 +     *
   1.413 +     * This allows harfbuzz to be enabled selectively via the preferences.
   1.414 +     */
   1.415 +    bool UseHarfBuzzForScript(int32_t aScriptCode);
   1.416 +
   1.417 +    // check whether format is supported on a platform or not (if unclear, returns true)
   1.418 +    virtual bool IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags) { return false; }
   1.419 +
   1.420 +    void GetPrefFonts(nsIAtom *aLanguage, nsString& array, bool aAppendUnicode = true);
   1.421 +
   1.422 +    // in some situations, need to make decisions about ambiguous characters, may need to look at multiple pref langs
   1.423 +    void GetLangPrefs(eFontPrefLang aPrefLangs[], uint32_t &aLen, eFontPrefLang aCharLang, eFontPrefLang aPageLang);
   1.424 +    
   1.425 +    /**
   1.426 +     * Iterate over pref fonts given a list of lang groups.  For a single lang
   1.427 +     * group, multiple pref fonts are possible.  If error occurs, returns false,
   1.428 +     * true otherwise.  Callback returns false to abort process.
   1.429 +     */
   1.430 +    typedef bool (*PrefFontCallback) (eFontPrefLang aLang, const nsAString& aName,
   1.431 +                                        void *aClosure);
   1.432 +    static bool ForEachPrefFont(eFontPrefLang aLangArray[], uint32_t aLangArrayLen,
   1.433 +                                  PrefFontCallback aCallback,
   1.434 +                                  void *aClosure);
   1.435 +
   1.436 +    // convert a lang group to enum constant (i.e. "zh-TW" ==> eFontPrefLang_ChineseTW)
   1.437 +    static eFontPrefLang GetFontPrefLangFor(const char* aLang);
   1.438 +
   1.439 +    // convert a lang group atom to enum constant
   1.440 +    static eFontPrefLang GetFontPrefLangFor(nsIAtom *aLang);
   1.441 +
   1.442 +    // convert a enum constant to lang group string (i.e. eFontPrefLang_ChineseTW ==> "zh-TW")
   1.443 +    static const char* GetPrefLangName(eFontPrefLang aLang);
   1.444 +   
   1.445 +    // map a Unicode range (based on char code) to a font language for Preferences
   1.446 +    static eFontPrefLang GetFontPrefLangFor(uint8_t aUnicodeRange);
   1.447 +
   1.448 +    // returns true if a pref lang is CJK
   1.449 +    static bool IsLangCJK(eFontPrefLang aLang);
   1.450 +    
   1.451 +    // helper method to add a pref lang to an array, if not already in array
   1.452 +    static void AppendPrefLang(eFontPrefLang aPrefLangs[], uint32_t& aLen, eFontPrefLang aAddLang);
   1.453 +
   1.454 +    // returns a list of commonly used fonts for a given character
   1.455 +    // these are *possible* matches, no cmap-checking is done at this level
   1.456 +    virtual void GetCommonFallbackFonts(const uint32_t /*aCh*/,
   1.457 +                                        int32_t /*aRunScript*/,
   1.458 +                                        nsTArray<const char*>& /*aFontList*/)
   1.459 +    {
   1.460 +        // platform-specific override, by default do nothing
   1.461 +    }
   1.462 +
   1.463 +    static bool OffMainThreadCompositingEnabled();
   1.464 +
   1.465 +    /** Use gfxPlatform::GetPref* methods instead of direct calls to Preferences
   1.466 +     * to get the values for layers preferences.  These will only be evaluated
   1.467 +     * only once, and remain the same until restart.
   1.468 +     */
   1.469 +    static bool GetPrefLayersOffMainThreadCompositionEnabled();
   1.470 +    static bool CanUseDirect3D9();
   1.471 +
   1.472 +    static bool OffMainThreadCompositionRequired();
   1.473 +
   1.474 +    /**
   1.475 +     * Is it possible to use buffer rotation.  Note that these
   1.476 +     * check the preference, but also allow for the override to
   1.477 +     * disable it using DisableBufferRotation.
   1.478 +     */
   1.479 +    static bool BufferRotationEnabled();
   1.480 +    static void DisableBufferRotation();
   1.481 +
   1.482 +    /**
   1.483 +     * Are we going to try color management?
   1.484 +     */
   1.485 +    static eCMSMode GetCMSMode();
   1.486 +
   1.487 +    /**
   1.488 +     * Determines the rendering intent for color management.
   1.489 +     *
   1.490 +     * If the value in the pref gfx.color_management.rendering_intent is a
   1.491 +     * valid rendering intent as defined in gfx/qcms/qcms.h, that
   1.492 +     * value is returned. Otherwise, -1 is returned and the embedded intent
   1.493 +     * should be used.
   1.494 +     *
   1.495 +     * See bug 444014 for details.
   1.496 +     */
   1.497 +    static int GetRenderingIntent();
   1.498 +
   1.499 +    /**
   1.500 +     * Convert a pixel using a cms transform in an endian-aware manner.
   1.501 +     *
   1.502 +     * Sets 'out' to 'in' if transform is nullptr.
   1.503 +     */
   1.504 +    static void TransformPixel(const gfxRGBA& in, gfxRGBA& out, qcms_transform *transform);
   1.505 +
   1.506 +    /**
   1.507 +     * Return the output device ICC profile.
   1.508 +     */
   1.509 +    static qcms_profile* GetCMSOutputProfile();
   1.510 +
   1.511 +    /**
   1.512 +     * Return the sRGB ICC profile.
   1.513 +     */
   1.514 +    static qcms_profile* GetCMSsRGBProfile();
   1.515 +
   1.516 +    /**
   1.517 +     * Return sRGB -> output device transform.
   1.518 +     */
   1.519 +    static qcms_transform* GetCMSRGBTransform();
   1.520 +
   1.521 +    /**
   1.522 +     * Return output -> sRGB device transform.
   1.523 +     */
   1.524 +    static qcms_transform* GetCMSInverseRGBTransform();
   1.525 +
   1.526 +    /**
   1.527 +     * Return sRGBA -> output device transform.
   1.528 +     */
   1.529 +    static qcms_transform* GetCMSRGBATransform();
   1.530 +
   1.531 +    virtual void FontsPrefsChanged(const char *aPref);
   1.532 +
   1.533 +    int32_t GetBidiNumeralOption();
   1.534 +
   1.535 +    /**
   1.536 +     * Returns a 1x1 surface that can be used to create graphics contexts
   1.537 +     * for measuring text etc as if they will be rendered to the screen
   1.538 +     */
   1.539 +    gfxASurface* ScreenReferenceSurface() { return mScreenReferenceSurface; }
   1.540 +    mozilla::gfx::DrawTarget* ScreenReferenceDrawTarget() { return mScreenReferenceDrawTarget; }
   1.541 +
   1.542 +    virtual mozilla::gfx::SurfaceFormat Optimal2DFormatForContent(gfxContentType aContent);
   1.543 +
   1.544 +    virtual gfxImageFormat OptimalFormatForContent(gfxContentType aContent);
   1.545 +
   1.546 +    virtual gfxImageFormat GetOffscreenFormat()
   1.547 +    { return gfxImageFormat::RGB24; }
   1.548 +
   1.549 +    /**
   1.550 +     * Returns a logger if one is available and logging is enabled
   1.551 +     */
   1.552 +    static PRLogModuleInfo* GetLog(eGfxLog aWhichLog);
   1.553 +
   1.554 +    virtual int GetScreenDepth() const;
   1.555 +
   1.556 +    /**
   1.557 +     * Return the layer debugging options to use browser-wide.
   1.558 +     */
   1.559 +    mozilla::layers::DiagnosticTypes GetLayerDiagnosticTypes();
   1.560 +
   1.561 +    static nsIntRect FrameCounterBounds() {
   1.562 +      int bits = 16;
   1.563 +      int sizeOfBit = 3;
   1.564 +      return nsIntRect(0, 0, bits * sizeOfBit, sizeOfBit);
   1.565 +    }
   1.566 +
   1.567 +    /**
   1.568 +     * Returns true if we should use raw memory to send data to the compositor
   1.569 +     * rather than using shmems.
   1.570 +     *
   1.571 +     * This method should not be called from the compositor thread.
   1.572 +     */
   1.573 +    bool PreferMemoryOverShmem() const;
   1.574 +
   1.575 +    mozilla::gl::SkiaGLGlue* GetSkiaGLGlue();
   1.576 +    void PurgeSkiaCache();
   1.577 +
   1.578 +    virtual bool IsInGonkEmulator() const { return false; }
   1.579 +
   1.580 +protected:
   1.581 +    gfxPlatform();
   1.582 +    virtual ~gfxPlatform();
   1.583 +
   1.584 +    void AppendCJKPrefLangs(eFontPrefLang aPrefLangs[], uint32_t &aLen, 
   1.585 +                            eFontPrefLang aCharLang, eFontPrefLang aPageLang);
   1.586 +
   1.587 +    /**
   1.588 +     * Helper method, creates a draw target for a specific Azure backend.
   1.589 +     * Used by CreateOffscreenDrawTarget.
   1.590 +     */
   1.591 +    mozilla::RefPtr<mozilla::gfx::DrawTarget>
   1.592 +      CreateDrawTargetForBackend(mozilla::gfx::BackendType aBackend,
   1.593 +                                 const mozilla::gfx::IntSize& aSize,
   1.594 +                                 mozilla::gfx::SurfaceFormat aFormat);
   1.595 +
   1.596 +    /**
   1.597 +     * Initialise the preferred and fallback canvas backends
   1.598 +     * aBackendBitmask specifies the backends which are acceptable to the caller.
   1.599 +     * The backend used is determined by aBackendBitmask and the order specified
   1.600 +     * by the gfx.canvas.azure.backends pref.
   1.601 +     */
   1.602 +    void InitBackendPrefs(uint32_t aCanvasBitmask, mozilla::gfx::BackendType aCanvasDefault,
   1.603 +                          uint32_t aContentBitmask, mozilla::gfx::BackendType aContentDefault);
   1.604 +
   1.605 +    /**
   1.606 +     * returns the first backend named in the pref gfx.canvas.azure.backends
   1.607 +     * which is a component of aBackendBitmask, a bitmask of backend types
   1.608 +     */
   1.609 +    static mozilla::gfx::BackendType GetCanvasBackendPref(uint32_t aBackendBitmask);
   1.610 +
   1.611 +    /**
   1.612 +     * returns the first backend named in the pref gfx.content.azure.backend
   1.613 +     * which is a component of aBackendBitmask, a bitmask of backend types
   1.614 +     */
   1.615 +    static mozilla::gfx::BackendType GetContentBackendPref(uint32_t &aBackendBitmask);
   1.616 +
   1.617 +    /**
   1.618 +     * Will return the first backend named in aBackendPrefName
   1.619 +     * allowed by aBackendBitmask, a bitmask of backend types.
   1.620 +     * It also modifies aBackendBitmask to only include backends that are
   1.621 +     * allowed given the prefs.
   1.622 +     */
   1.623 +    static mozilla::gfx::BackendType GetBackendPref(const char* aBackendPrefName,
   1.624 +                                                    uint32_t &aBackendBitmask);
   1.625 +    /**
   1.626 +     * Decode the backend enumberation from a string.
   1.627 +     */
   1.628 +    static mozilla::gfx::BackendType BackendTypeForName(const nsCString& aName);
   1.629 +
   1.630 +    static mozilla::TemporaryRef<mozilla::gfx::ScaledFont>
   1.631 +      GetScaledFontForFontWithCairoSkia(mozilla::gfx::DrawTarget* aTarget, gfxFont* aFont);
   1.632 +
   1.633 +    int8_t  mAllowDownloadableFonts;
   1.634 +    int8_t  mGraphiteShapingEnabled;
   1.635 +    int8_t  mOpenTypeSVGEnabled;
   1.636 +
   1.637 +    int8_t  mBidiNumeralOption;
   1.638 +
   1.639 +    // whether to always search font cmaps globally 
   1.640 +    // when doing system font fallback
   1.641 +    int8_t  mFallbackUsesCmaps;
   1.642 +
   1.643 +    // which scripts should be shaped with harfbuzz
   1.644 +    int32_t mUseHarfBuzzScripts;
   1.645 +
   1.646 +    // max character limit for words in word cache
   1.647 +    int32_t mWordCacheCharLimit;
   1.648 +
   1.649 +    // max number of entries in word cache
   1.650 +    int32_t mWordCacheMaxEntries;
   1.651 +
   1.652 +private:
   1.653 +    /**
   1.654 +     * Start up Thebes.
   1.655 +     */
   1.656 +    static void Init();
   1.657 +
   1.658 +    static void CreateCMSOutputProfile();
   1.659 +
   1.660 +    static void GetCMSOutputProfileData(void *&mem, size_t &size);
   1.661 +
   1.662 +    friend void RecordingPrefChanged(const char *aPrefName, void *aClosure);
   1.663 +
   1.664 +    virtual void GetPlatformCMSOutputProfile(void *&mem, size_t &size);
   1.665 +
   1.666 +    virtual bool SupportsOffMainThreadCompositing() { return true; }
   1.667 +
   1.668 +    nsRefPtr<gfxASurface> mScreenReferenceSurface;
   1.669 +    mozilla::RefPtr<mozilla::gfx::DrawTarget> mScreenReferenceDrawTarget;
   1.670 +    nsTArray<uint32_t> mCJKPrefLangs;
   1.671 +    nsCOMPtr<nsIObserver> mSRGBOverrideObserver;
   1.672 +    nsCOMPtr<nsIObserver> mFontPrefsObserver;
   1.673 +    nsCOMPtr<nsIObserver> mMemoryPressureObserver;
   1.674 +
   1.675 +    // The preferred draw target backend to use for canvas
   1.676 +    mozilla::gfx::BackendType mPreferredCanvasBackend;
   1.677 +    // The fallback draw target backend to use for canvas, if the preferred backend fails
   1.678 +    mozilla::gfx::BackendType mFallbackCanvasBackend;
   1.679 +    // The backend to use for content
   1.680 +    mozilla::gfx::BackendType mContentBackend;
   1.681 +    // Bitmask of backend types we can use to render content
   1.682 +    uint32_t mContentBackendBitmask;
   1.683 +
   1.684 +    mozilla::widget::GfxInfoCollector<gfxPlatform> mAzureCanvasBackendCollector;
   1.685 +
   1.686 +    mozilla::RefPtr<mozilla::gfx::DrawEventRecorder> mRecorder;
   1.687 +    bool mLayersPreferMemoryOverShmem;
   1.688 +    mozilla::RefPtr<mozilla::gl::SkiaGLGlue> mSkiaGlue;
   1.689 +};
   1.690 +
   1.691 +#endif /* GFX_PLATFORM_H */

mercurial