Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/gfxPlatform.h
Line
Count
Source (jump to first uncovered line)
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/. */
5
6
#ifndef GFX_PLATFORM_H
7
#define GFX_PLATFORM_H
8
9
#include "mozilla/FontPropertyTypes.h"
10
#include "mozilla/Logging.h"
11
#include "mozilla/gfx/Types.h"
12
#include "nsTArray.h"
13
#include "nsString.h"
14
#include "nsCOMPtr.h"
15
#include "nsUnicodeScriptCodes.h"
16
17
#include "gfxTypes.h"
18
#include "gfxFontFamilyList.h"
19
#include "gfxBlur.h"
20
#include "gfxSkipChars.h"
21
#include "nsRect.h"
22
23
#include "qcms.h"
24
25
#include "mozilla/RefPtr.h"
26
#include "GfxInfoCollector.h"
27
28
#include "mozilla/layers/CompositorTypes.h"
29
#include "mozilla/layers/MemoryPressureObserver.h"
30
31
class gfxASurface;
32
class gfxFont;
33
class gfxFontGroup;
34
struct gfxFontStyle;
35
class gfxUserFontSet;
36
class gfxFontEntry;
37
class gfxPlatformFontList;
38
class gfxTextRun;
39
class nsIURI;
40
class nsAtom;
41
class nsIObserver;
42
class SRGBOverrideObserver;
43
class gfxTextPerfMetrics;
44
typedef struct FT_LibraryRec_ *FT_Library;
45
46
namespace mozilla {
47
namespace gl {
48
class SkiaGLGlue;
49
} // namespace gl
50
namespace gfx {
51
class DrawTarget;
52
class SourceSurface;
53
class DataSourceSurface;
54
class ScaledFont;
55
class DrawEventRecorder;
56
class VsyncSource;
57
class ContentDeviceData;
58
class GPUDeviceData;
59
class FeatureState;
60
61
inline uint32_t
62
BackendTypeBit(BackendType b)
63
{
64
  return 1 << uint8_t(b);
65
}
66
67
} // namespace gfx
68
namespace dom {
69
class SystemFontListEntry;
70
}
71
} // namespace mozilla
72
73
#define MOZ_PERFORMANCE_WARNING(module, ...) \
74
0
  do { \
75
0
    if (gfxPlatform::PerfWarnings()) { \
76
0
      printf_stderr("[" module "] " __VA_ARGS__); \
77
0
    } \
78
0
  } while (0)
79
80
enum eCMSMode {
81
    eCMSMode_Off          = 0,     // No color management
82
    eCMSMode_All          = 1,     // Color manage everything
83
    eCMSMode_TaggedOnly   = 2,     // Color manage tagged Images Only
84
    eCMSMode_AllCount     = 3
85
};
86
87
enum eGfxLog {
88
    // all font enumerations, localized names, fullname/psnames, cmap loads
89
    eGfxLog_fontlist         = 0,
90
    // timing info on font initialization
91
    eGfxLog_fontinit         = 1,
92
    // dump text runs, font matching, system fallback for content
93
    eGfxLog_textrun          = 2,
94
    // dump text runs, font matching, system fallback for chrome
95
    eGfxLog_textrunui        = 3,
96
    // dump cmap coverage data as they are loaded
97
    eGfxLog_cmapdata         = 4,
98
    // text perf data
99
    eGfxLog_textperf         = 5
100
};
101
102
// when searching through pref langs, max number of pref langs
103
const uint32_t kMaxLenPrefLangList = 32;
104
105
#define UNINITIALIZED_VALUE  (-1)
106
107
inline const char*
108
GetBackendName(mozilla::gfx::BackendType aBackend)
109
{
110
  switch (aBackend) {
111
      case mozilla::gfx::BackendType::DIRECT2D:
112
        return "direct2d";
113
      case mozilla::gfx::BackendType::CAIRO:
114
        return "cairo";
115
      case mozilla::gfx::BackendType::SKIA:
116
        return "skia";
117
      case mozilla::gfx::BackendType::RECORDING:
118
        return "recording";
119
      case mozilla::gfx::BackendType::DIRECT2D1_1:
120
        return "direct2d 1.1";
121
      case mozilla::gfx::BackendType::WEBRENDER_TEXT:
122
        return "webrender text";
123
      case mozilla::gfx::BackendType::NONE:
124
        return "none";
125
      case mozilla::gfx::BackendType::BACKEND_LAST:
126
        return "invalid";
127
  }
128
  MOZ_CRASH("Incomplete switch");
129
}
130
131
enum class DeviceResetReason
132
{
133
  OK = 0,
134
  HUNG,
135
  REMOVED,
136
  RESET,
137
  DRIVER_ERROR,
138
  INVALID_CALL,
139
  OUT_OF_MEMORY,
140
  FORCED_RESET,
141
  UNKNOWN,
142
  D3D9_RESET
143
};
144
145
enum class ForcedDeviceResetReason
146
{
147
  OPENSHAREDHANDLE = 0,
148
  COMPOSITOR_UPDATED,
149
};
150
151
struct BackendPrefsData
152
{
153
  uint32_t mCanvasBitmask = 0;
154
  mozilla::gfx::BackendType mCanvasDefault = mozilla::gfx::BackendType::NONE;
155
  uint32_t mContentBitmask = 0;
156
  mozilla::gfx::BackendType mContentDefault = mozilla::gfx::BackendType::NONE;
157
};
158
159
class gfxPlatform: public mozilla::layers::MemoryPressureListener {
160
    friend class SRGBOverrideObserver;
161
162
public:
163
    typedef mozilla::StretchRange StretchRange;
164
    typedef mozilla::SlantStyleRange SlantStyleRange;
165
    typedef mozilla::WeightRange WeightRange;
166
    typedef mozilla::gfx::Color Color;
167
    typedef mozilla::gfx::DataSourceSurface DataSourceSurface;
168
    typedef mozilla::gfx::DrawTarget DrawTarget;
169
    typedef mozilla::gfx::IntSize IntSize;
170
    typedef mozilla::gfx::SourceSurface SourceSurface;
171
    typedef mozilla::unicode::Script Script;
172
173
    /**
174
     * Return a pointer to the current active platform.
175
     * This is a singleton; it contains mostly convenience
176
     * functions to obtain platform-specific objects.
177
     */
178
    static gfxPlatform *GetPlatform();
179
180
    /**
181
     * Returns whether or not graphics has been initialized yet. This is
182
     * intended for Telemetry where we don't necessarily want to initialize
183
     * graphics just to observe its state.
184
     */
185
    static bool Initialized();
186
187
    /**
188
     * Shut down Thebes.
189
     * Init() arranges for this to be called at an appropriate time.
190
     */
191
    static void Shutdown();
192
193
    /**
194
     * Initialize gfxPlatform (if not already done) in a child process, with
195
     * the provided ContentDeviceData.
196
     */
197
    static void InitChild(const mozilla::gfx::ContentDeviceData& aData);
198
199
    static void InitLayersIPC();
200
    static void ShutdownLayersIPC();
201
202
    /**
203
     * Initialize ScrollMetadata statics. Does not depend on gfxPlatform.
204
     */
205
    static void InitNullMetadata();
206
207
    static int32_t MaxTextureSize();
208
    static int32_t MaxAllocSize();
209
    static void InitMoz2DLogging();
210
211
    static bool IsHeadless();
212
213
    /**
214
     * Create an offscreen surface of the given dimensions
215
     * and image format.
216
     */
217
    virtual already_AddRefed<gfxASurface>
218
      CreateOffscreenSurface(const IntSize& aSize,
219
                             gfxImageFormat aFormat) = 0;
220
221
    /**
222
     * Beware that this method may return DrawTargets which are not fully supported
223
     * on the current platform and might fail silently in subtle ways. This is a massive
224
     * potential footgun. You should only use these methods for canvas drawing really.
225
     * Use extreme caution if you use them for content where you are not 100% sure we
226
     * support the DrawTarget we get back.
227
     * See SupportsAzureContentForDrawTarget.
228
     */
229
    static already_AddRefed<DrawTarget>
230
      CreateDrawTargetForSurface(gfxASurface *aSurface, const mozilla::gfx::IntSize& aSize);
231
232
    /*
233
     * Creates a SourceSurface for a gfxASurface. This function does no caching,
234
     * so the caller should cache the gfxASurface if it will be used frequently.
235
     * The returned surface keeps a reference to aTarget, so it is OK to keep the
236
     * surface, even if aTarget changes.
237
     * aTarget should not keep a reference to the returned surface because that
238
     * will cause a cycle.
239
     *
240
     * This function is static so that it can be accessed from
241
     * PluginInstanceChild (where we can't call gfxPlatform::GetPlatform()
242
     * because the prefs service can only be accessed from the main process).
243
     *
244
     * aIsPlugin is used to tell the backend that they can optimize this surface
245
     * specifically because it's used for a plugin. This is mostly for Skia.
246
     */
247
    static already_AddRefed<SourceSurface> GetSourceSurfaceForSurface(
248
      RefPtr<mozilla::gfx::DrawTarget> aTarget,
249
      gfxASurface* aSurface,
250
      bool aIsPlugin = false);
251
252
    static void ClearSourceSurfaceForSurface(gfxASurface *aSurface);
253
254
    static already_AddRefed<DataSourceSurface>
255
        GetWrappedDataSourceSurface(gfxASurface *aSurface);
256
257
    already_AddRefed<DrawTarget> CreateOffscreenContentDrawTarget(
258
      const mozilla::gfx::IntSize& aSize,
259
      mozilla::gfx::SurfaceFormat aFormat,
260
      bool aFallback = false);
261
262
    already_AddRefed<DrawTarget>
263
      CreateOffscreenCanvasDrawTarget(const mozilla::gfx::IntSize& aSize, mozilla::gfx::SurfaceFormat aFormat);
264
265
    already_AddRefed<DrawTarget>
266
      CreateSimilarSoftwareDrawTarget(DrawTarget* aDT, const IntSize &aSize, mozilla::gfx::SurfaceFormat aFormat);
267
268
    static already_AddRefed<DrawTarget>
269
      CreateDrawTargetForData(unsigned char* aData,
270
                              const mozilla::gfx::IntSize& aSize,
271
                              int32_t aStride,
272
                              mozilla::gfx::SurfaceFormat aFormat,
273
                              bool aUninitialized = false);
274
275
    /**
276
     * Returns true if we should use Azure to render content with aTarget. For
277
     * example, it is possible that we are using Direct2D for rendering and thus
278
     * using Azure. But we want to render to a CairoDrawTarget, in which case
279
     * SupportsAzureContent will return true but SupportsAzureContentForDrawTarget
280
     * will return false.
281
     */
282
    bool SupportsAzureContentForDrawTarget(mozilla::gfx::DrawTarget* aTarget);
283
284
    bool SupportsAzureContentForType(mozilla::gfx::BackendType aType) {
285
      return BackendTypeBit(aType) & mContentBackendBitmask;
286
    }
287
288
    /// This function also lets us know if the current preferences/platform
289
    /// combination allows for both accelerated and not accelerated canvas
290
    /// implementations.  If it does, and other relevant preferences are
291
    /// asking for it, we will examine the commands in the first few seconds
292
    /// of the canvas usage, and potentially change to accelerated or
293
    /// non-accelerated canvas.
294
    virtual bool AllowOpenGLCanvas();
295
    virtual void InitializeSkiaCacheLimits();
296
297
    static bool AsyncPanZoomEnabled();
298
299
    virtual void GetAzureBackendInfo(mozilla::widget::InfoObject &aObj);
300
    void GetApzSupportInfo(mozilla::widget::InfoObject& aObj);
301
    void GetTilesSupportInfo(mozilla::widget::InfoObject& aObj);
302
303
    // Get the default content backend that will be used with the default
304
    // compositor. If the compositor is known when calling this function,
305
    // GetContentBackendFor() should be called instead.
306
0
    mozilla::gfx::BackendType GetDefaultContentBackend() const {
307
0
      return mContentBackend;
308
0
    }
309
310
    /// Return the software backend to use by default.
311
0
    mozilla::gfx::BackendType GetSoftwareBackend() {
312
0
        return mSoftwareBackend;
313
0
    }
314
315
    // Return the best content backend available that is compatible with the
316
    // given layers backend.
317
    virtual mozilla::gfx::BackendType GetContentBackendFor(mozilla::layers::LayersBackend aLayers) {
318
      return mContentBackend;
319
    }
320
321
    virtual mozilla::gfx::BackendType GetPreferredCanvasBackend() {
322
      return mPreferredCanvasBackend;
323
    }
324
0
    mozilla::gfx::BackendType GetFallbackCanvasBackend() {
325
0
      return mFallbackCanvasBackend;
326
0
    }
327
    /*
328
     * Font bits
329
     */
330
331
    virtual void SetupClusterBoundaries(gfxTextRun *aTextRun, const char16_t *aString);
332
333
    /**
334
     * Fill aListOfFonts with the results of querying the list of font names
335
     * that correspond to the given language group or generic font family
336
     * (or both, or neither).
337
     */
338
    virtual nsresult GetFontList(nsAtom *aLangGroup,
339
                                 const nsACString& aGenericFamily,
340
                                 nsTArray<nsString>& aListOfFonts);
341
342
    /**
343
     * Fill aFontList with a list of SystemFontListEntry records for the
344
     * available fonts on the platform; used to pass the list from chrome to
345
     * content process. Currently implemented only on MacOSX and Linux.
346
     */
347
    virtual void ReadSystemFontList(
348
      InfallibleTArray<mozilla::dom::SystemFontListEntry>* aFontList)
349
    { }
350
351
    /**
352
     * Rebuilds the any cached system font lists
353
     */
354
    virtual nsresult UpdateFontList();
355
356
    /**
357
     * Create the platform font-list object (gfxPlatformFontList concrete subclass).
358
     * This function is responsible to create the appropriate subclass of
359
     * gfxPlatformFontList *and* to call its InitFontList() method.
360
     */
361
    virtual gfxPlatformFontList *CreatePlatformFontList() {
362
        MOZ_ASSERT_UNREACHABLE("oops, this platform doesn't have a "
363
                               "gfxPlatformFontList implementation");
364
        return nullptr;
365
    }
366
367
    /**
368
     * Resolving a font name to family name. The result MUST be in the result of GetFontList().
369
     * If the name doesn't in the system, aFamilyName will be empty string, but not failed.
370
     */
371
    void GetStandardFamilyName(const nsCString& aFontName, nsACString& aFamilyName);
372
373
    /**
374
     * Returns default font name (localized family name) for aLangGroup and
375
     * aGenericFamily.  The result is typically the first font in
376
     * font.name-list.<aGenericFamily>.<aLangGroup>.  However, if it's not
377
     * available in the system, this may return second or later font in the
378
     * pref.  If there are no available fonts in the pref, returns empty string.
379
     */
380
    nsAutoCString GetDefaultFontName(const nsACString& aLangGroup,
381
                                     const nsACString& aGenericFamily);
382
383
    /**
384
     * Create the appropriate platform font group
385
     */
386
    virtual gfxFontGroup*
387
    CreateFontGroup(const mozilla::FontFamilyList& aFontFamilyList,
388
                    const gfxFontStyle *aStyle,
389
                    gfxTextPerfMetrics* aTextPerf,
390
                    gfxUserFontSet *aUserFontSet,
391
                    gfxFloat aDevToCssSize) = 0;
392
393
    /**
394
     * Look up a local platform font using the full font face name.
395
     * (Needed to support @font-face src local().)
396
     * Ownership of the returned gfxFontEntry is passed to the caller,
397
     * who must either AddRef() or delete.
398
     */
399
    gfxFontEntry* LookupLocalFont(const nsACString& aFontName,
400
                                  WeightRange aWeightForEntry,
401
                                  StretchRange aStretchForEntry,
402
                                  SlantStyleRange aStyleForEntry);
403
404
    /**
405
     * Activate a platform font.  (Needed to support @font-face src url().)
406
     * aFontData is a NS_Malloc'ed block that must be freed by this function
407
     * (or responsibility passed on) when it is no longer needed; the caller
408
     * will NOT free it.
409
     * Ownership of the returned gfxFontEntry is passed to the caller,
410
     * who must either AddRef() or delete.
411
     */
412
    gfxFontEntry* MakePlatformFont(const nsACString& aFontName,
413
                                   WeightRange aWeightForEntry,
414
                                   StretchRange aStretchForEntry,
415
                                   SlantStyleRange aStyleForEntry,
416
                                   const uint8_t* aFontData,
417
                                   uint32_t aLength);
418
419
    /**
420
     * Whether to allow downloadable fonts via @font-face rules
421
     */
422
    bool DownloadableFontsEnabled();
423
424
    /**
425
     * True when hinting should be enabled.  This setting shouldn't
426
     * change per gecko process, while the process is live.  If so the
427
     * results are not defined.
428
     *
429
     * NB: this bit is only honored by the FT2 backend, currently.
430
     */
431
    virtual bool FontHintingEnabled() { return true; }
432
433
    /**
434
     * True when zooming should not require reflow, so glyph metrics and
435
     * positioning should not be adjusted for device pixels.
436
     * If this is TRUE, then FontHintingEnabled() should be FALSE,
437
     * but the converse is not necessarily required;
438
     *
439
     * Like FontHintingEnabled (above), this setting shouldn't
440
     * change per gecko process, while the process is live.  If so the
441
     * results are not defined.
442
     *
443
     * NB: this bit is only honored by the FT2 backend, currently.
444
     */
445
    virtual bool RequiresLinearZoom() { return false; }
446
447
    /**
448
     * Whether the frame->StyleFont().mFont.smoothing field is respected by
449
     * text rendering on this platform.
450
     */
451
    virtual bool RespectsFontStyleSmoothing() const { return false; }
452
453
    /**
454
     * Whether to check all font cmaps during system font fallback
455
     */
456
    bool UseCmapsDuringSystemFallback();
457
458
    /**
459
     * Whether to render SVG glyphs within an OpenType font wrapper
460
     */
461
    bool OpenTypeSVGEnabled();
462
463
    /**
464
     * Max character length of words in the word cache
465
     */
466
    uint32_t WordCacheCharLimit();
467
468
    /**
469
     * Max number of entries in word cache
470
     */
471
    uint32_t WordCacheMaxEntries();
472
473
    /**
474
     * Whether to use the SIL Graphite rendering engine
475
     * (for fonts that include Graphite tables)
476
     */
477
    bool UseGraphiteShaping();
478
479
    // Check whether format is supported on a platform (if unclear, returns true).
480
    // Default implementation checks for "common" formats that we support across
481
    // all platforms, but individual platform implementations may override.
482
    virtual bool IsFontFormatSupported(uint32_t aFormatFlags);
483
484
    virtual bool DidRenderingDeviceReset(DeviceResetReason* aResetReason = nullptr) { return false; }
485
486
    // returns a list of commonly used fonts for a given character
487
    // these are *possible* matches, no cmap-checking is done at this level
488
    virtual void GetCommonFallbackFonts(uint32_t /*aCh*/, uint32_t /*aNextCh*/,
489
                                        Script /*aRunScript*/,
490
                                        nsTArray<const char*>& /*aFontList*/)
491
    {
492
        // platform-specific override, by default do nothing
493
    }
494
495
    // Are we in safe mode?
496
    static bool InSafeMode();
497
498
    static bool OffMainThreadCompositingEnabled();
499
500
    void UpdateCanUseHardwareVideoDecoding();
501
502
    // Returns a prioritized list of all available compositor backends.
503
    void GetCompositorBackends(bool useAcceleration, nsTArray<mozilla::layers::LayersBackend>& aBackends);
504
505
    /**
506
     * Is it possible to use buffer rotation.  Note that these
507
     * check the preference, but also allow for the override to
508
     * disable it using DisableBufferRotation.
509
     */
510
    static bool BufferRotationEnabled();
511
    static void DisableBufferRotation();
512
513
    /**
514
     * Are we going to try color management?
515
     */
516
    static eCMSMode GetCMSMode();
517
518
    /**
519
     * Determines the rendering intent for color management.
520
     *
521
     * If the value in the pref gfx.color_management.rendering_intent is a
522
     * valid rendering intent as defined in gfx/qcms/qcms.h, that
523
     * value is returned. Otherwise, -1 is returned and the embedded intent
524
     * should be used.
525
     *
526
     * See bug 444014 for details.
527
     */
528
    static int GetRenderingIntent();
529
530
    /**
531
     * Convert a pixel using a cms transform in an endian-aware manner.
532
     *
533
     * Sets 'out' to 'in' if transform is nullptr.
534
     */
535
    static void TransformPixel(const Color& in, Color& out, qcms_transform *transform);
536
537
    /**
538
     * Return the output device ICC profile.
539
     */
540
    static qcms_profile* GetCMSOutputProfile();
541
542
    /**
543
     * Return the sRGB ICC profile.
544
     */
545
    static qcms_profile* GetCMSsRGBProfile();
546
547
    /**
548
     * Return sRGB -> output device transform.
549
     */
550
    static qcms_transform* GetCMSRGBTransform();
551
552
    /**
553
     * Return output -> sRGB device transform.
554
     */
555
    static qcms_transform* GetCMSInverseRGBTransform();
556
557
    /**
558
     * Return sRGBA -> output device transform.
559
     */
560
    static qcms_transform* GetCMSRGBATransform();
561
562
    virtual void FontsPrefsChanged(const char *aPref);
563
564
    int32_t GetBidiNumeralOption();
565
566
    /**
567
     * This is a bit ugly, but useful... force all presContexts to reflow,
568
     * by toggling a preference that they observe. This is used when
569
     * something about platform settings changes that might have an effect
570
     * on layout, such as font rendering settings that influence metrics.
571
     */
572
    static void ForceGlobalReflow();
573
574
    static void
575
    FlushFontAndWordCaches();
576
577
    /**
578
     * Returns a 1x1 surface that can be used to create graphics contexts
579
     * for measuring text etc as if they will be rendered to the screen
580
     */
581
0
    gfxASurface* ScreenReferenceSurface() { return mScreenReferenceSurface; }
582
583
    /**
584
     * Returns a 1x1 DrawTarget that can be used for measuring text etc. as
585
     * it would measure if rendered on-screen.  Guaranteed to return a
586
     * non-null and valid DrawTarget.
587
     */
588
    RefPtr<mozilla::gfx::DrawTarget> ScreenReferenceDrawTarget();
589
590
    virtual mozilla::gfx::SurfaceFormat Optimal2DFormatForContent(gfxContentType aContent);
591
592
    virtual gfxImageFormat OptimalFormatForContent(gfxContentType aContent);
593
594
    virtual gfxImageFormat GetOffscreenFormat()
595
    { return mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32; }
596
597
    /**
598
     * Returns whether the current process should use tiling for layers.
599
     */
600
    virtual bool UsesTiling() const;
601
602
    /**
603
     * Returns whether the content process will use tiling for layers. This is
604
     * only used by about:support.
605
     */
606
    virtual bool ContentUsesTiling() const;
607
608
    /**
609
     * Returns a logger if one is available and logging is enabled
610
     */
611
    static mozilla::LogModule* GetLog(eGfxLog aWhichLog);
612
613
0
    int GetScreenDepth() const { return mScreenDepth; }
614
    mozilla::gfx::IntSize GetScreenSize() const { return mScreenSize; }
615
616
    /**
617
     * Return the layer debugging options to use browser-wide.
618
     */
619
    mozilla::layers::DiagnosticTypes GetLayerDiagnosticTypes();
620
621
    mozilla::gl::SkiaGLGlue* GetSkiaGLGlue();
622
    void PurgeSkiaGPUCache();
623
    static void PurgeSkiaFontCache();
624
625
    static bool UsesOffMainThreadCompositing();
626
627
    bool HasEnoughTotalSystemMemoryForSkiaGL();
628
629
    /**
630
     * Get the hardware vsync source for each platform.
631
     * Should only exist and be valid on the parent process
632
     */
633
    virtual mozilla::gfx::VsyncSource* GetHardwareVsync() {
634
      MOZ_ASSERT(mVsyncSource != nullptr);
635
      MOZ_ASSERT(XRE_IsParentProcess() || mozilla::recordreplay::IsRecordingOrReplaying());
636
      return mVsyncSource;
637
    }
638
639
    /**
640
     * True if layout rendering should use ASAP mode, which means
641
     * the refresh driver and compositor should render ASAP.
642
     * Used for talos testing purposes
643
     */
644
    static bool IsInLayoutAsapMode();
645
646
    /**
647
     * Returns the software vsync rate to use.
648
     */
649
    static int GetSoftwareVsyncRate();
650
651
    /**
652
     * Returns whether or not a custom vsync rate is set.
653
     */
654
    static bool ForceSoftwareVsync();
655
656
    /**
657
     * Returns the default frame rate for the refresh driver / software vsync.
658
     */
659
    static int GetDefaultFrameRate();
660
661
    /**
662
     * Used to test which input types are handled via APZ.
663
     */
664
    virtual bool SupportsApzWheelInput() const {
665
      return false;
666
    }
667
    bool SupportsApzTouchInput() const;
668
    bool SupportsApzDragInput() const;
669
    bool SupportsApzKeyboardInput() const;
670
    bool SupportsApzAutoscrolling() const;
671
672
    virtual void FlushContentDrawing() {}
673
674
    // If a device reset has occurred, schedule any necessary paints in the
675
    // widget. This should only be used within nsRefreshDriver.
676
    virtual void SchedulePaintIfDeviceReset() {}
677
678
    /**
679
     * Helper method, creates a draw target for a specific Azure backend.
680
     * Used by CreateOffscreenDrawTarget.
681
     */
682
    already_AddRefed<DrawTarget>
683
      CreateDrawTargetForBackend(mozilla::gfx::BackendType aBackend,
684
                                 const mozilla::gfx::IntSize& aSize,
685
                                 mozilla::gfx::SurfaceFormat aFormat);
686
687
    /**
688
     * Wrapper around gfxPrefs::PerfWarnings().
689
     * Extracted into a function to avoid including gfxPrefs.h from this file.
690
     */
691
    static bool PerfWarnings();
692
693
    static void NotifyGPUProcessDisabled();
694
695
    void NotifyCompositorCreated(mozilla::layers::LayersBackend aBackend);
696
0
    mozilla::layers::LayersBackend GetCompositorBackend() const {
697
0
      return mCompositorBackend;
698
0
    }
699
700
    virtual void CompositorUpdated() {}
701
702
    // Plugin async drawing support.
703
    virtual bool SupportsPluginDirectBitmapDrawing() {
704
      return false;
705
    }
706
707
    // Some platforms don't support CompositorOGL in an unaccelerated OpenGL
708
    // context. These platforms should return true here.
709
    virtual bool RequiresAcceleratedGLContextForCompositorOGL() const {
710
      return false;
711
    }
712
713
    /**
714
     * Check the blocklist for a feature. Returns false if the feature is blocked
715
     * with an appropriate message and failure ID.
716
     * */
717
    static bool IsGfxInfoStatusOkay(int32_t aFeature, nsCString* aOutMessage,
718
                                    nsCString& aFailureId);
719
720
0
    const gfxSkipChars& EmptySkipChars() const { return kEmptySkipChars; }
721
722
    /**
723
     * Return information on how child processes should initialize graphics
724
     * devices.
725
     */
726
    virtual void BuildContentDeviceData(mozilla::gfx::ContentDeviceData* aOut);
727
728
    /**
729
     * Imports settings from the GPU process. This should only be called through
730
     * GPUProcessManager, in the UI process.
731
     */
732
    virtual void ImportGPUDeviceData(const mozilla::gfx::GPUDeviceData& aData);
733
734
    virtual FT_Library GetFTLibrary() {
735
      return nullptr;
736
    }
737
738
    bool HasVariationFontSupport() const {
739
      return mHasVariationFontSupport;
740
    }
741
742
    bool HasNativeColrFontSupport() const {
743
      return mHasNativeColrFontSupport;
744
    }
745
746
    // you probably want to use gfxVars::UseWebRender() instead of this
747
    static bool WebRenderPrefEnabled();
748
    // you probably want to use gfxVars::UseWebRender() instead of this
749
    static bool WebRenderEnvvarEnabled();
750
751
    virtual void
752
    OnMemoryPressure(mozilla::layers::MemoryPressureReason aWhy) override;
753
protected:
754
    gfxPlatform();
755
    virtual ~gfxPlatform();
756
757
    virtual void InitAcceleration();
758
    virtual void InitWebRenderConfig();
759
760
    /**
761
     * Called immediately before deleting the gfxPlatform object.
762
     */
763
    virtual void WillShutdown();
764
765
    /**
766
     * Initialized hardware vsync based on each platform.
767
     */
768
    virtual already_AddRefed<mozilla::gfx::VsyncSource> CreateHardwareVsyncSource();
769
770
    // Returns whether or not layers should be accelerated by default on this platform.
771
    virtual bool AccelerateLayersByDefault();
772
773
    // Returns a prioritized list of available compositor backends for acceleration.
774
    virtual void GetAcceleratedCompositorBackends(nsTArray<mozilla::layers::LayersBackend>& aBackends);
775
776
    // Returns preferences of canvas and content backends.
777
    virtual BackendPrefsData GetBackendPrefs() const;
778
779
    /**
780
     * Initialise the preferred and fallback canvas backends
781
     * aBackendBitmask specifies the backends which are acceptable to the caller.
782
     * The backend used is determined by aBackendBitmask and the order specified
783
     * by the gfx.canvas.azure.backends pref.
784
     */
785
    void InitBackendPrefs(BackendPrefsData&& aPrefsData);
786
787
    /**
788
     * Content-process only. Requests device preferences from the parent process
789
     * and updates any cached settings.
790
     */
791
    void FetchAndImportContentDeviceData();
792
    virtual void ImportContentDeviceData(const mozilla::gfx::ContentDeviceData& aData);
793
794
    /**
795
     * Increase the global device counter after a device has been removed/reset.
796
     */
797
    void BumpDeviceCounter();
798
799
    /**
800
     * returns the first backend named in the pref gfx.canvas.azure.backends
801
     * which is a component of aBackendBitmask, a bitmask of backend types
802
     */
803
    static mozilla::gfx::BackendType GetCanvasBackendPref(uint32_t aBackendBitmask);
804
805
    /**
806
     * returns the first backend named in the pref gfx.content.azure.backend
807
     * which is a component of aBackendBitmask, a bitmask of backend types
808
     */
809
    static mozilla::gfx::BackendType GetContentBackendPref(uint32_t &aBackendBitmask);
810
811
    /**
812
     * Will return the first backend named in aBackendPrefName
813
     * allowed by aBackendBitmask, a bitmask of backend types.
814
     * It also modifies aBackendBitmask to only include backends that are
815
     * allowed given the prefs.
816
     */
817
    static mozilla::gfx::BackendType GetBackendPref(const char* aBackendPrefName,
818
                                                    uint32_t &aBackendBitmask);
819
    /**
820
     * Decode the backend enumberation from a string.
821
     */
822
    static mozilla::gfx::BackendType BackendTypeForName(const nsCString& aName);
823
824
    virtual bool CanUseHardwareVideoDecoding();
825
826
    virtual bool CheckVariationFontSupport() = 0;
827
828
    int8_t  mAllowDownloadableFonts;
829
    int8_t  mGraphiteShapingEnabled;
830
    int8_t  mOpenTypeSVGEnabled;
831
832
    int8_t  mBidiNumeralOption;
833
834
    // whether to always search font cmaps globally
835
    // when doing system font fallback
836
    int8_t  mFallbackUsesCmaps;
837
838
    // Whether the platform supports rendering OpenType font variations
839
    bool    mHasVariationFontSupport;
840
841
    // Whether the platform font APIs have native support for COLR fonts.
842
    // Set to true during initialization on platforms that implement this.
843
    bool    mHasNativeColrFontSupport = false;
844
845
    // max character limit for words in word cache
846
    int32_t mWordCacheCharLimit;
847
848
    // max number of entries in word cache
849
    int32_t mWordCacheMaxEntries;
850
851
    uint64_t mTotalSystemMemory;
852
853
    // Hardware vsync source. Only valid on parent process
854
    RefPtr<mozilla::gfx::VsyncSource> mVsyncSource;
855
856
    RefPtr<mozilla::gfx::DrawTarget> mScreenReferenceDrawTarget;
857
858
private:
859
    /**
860
     * Start up Thebes.
861
     */
862
    static void Init();
863
864
    static void InitOpenGLConfig();
865
    static void CreateCMSOutputProfile();
866
867
    static void GetCMSOutputProfileData(void *&mem, size_t &size);
868
869
    friend void RecordingPrefChanged(const char *aPrefName, void *aClosure);
870
871
    virtual void GetPlatformCMSOutputProfile(void *&mem, size_t &size);
872
873
    /**
874
     * Calling this function will compute and set the ideal tile size for the
875
     * platform. This will only have an effect in the parent process; child processes
876
     * should be updated via SetTileSize to match the value computed in the parent.
877
     */
878
    void ComputeTileSize();
879
880
    /**
881
     * This uses nsIScreenManager to determine the screen size and color depth
882
     */
883
    void PopulateScreenInfo();
884
885
    void InitCompositorAccelerationPrefs();
886
    void InitGPUProcessPrefs();
887
    void InitOMTPConfig();
888
889
    static bool IsDXInterop2Blocked();
890
    static bool IsDXNV12Blocked();
891
892
    RefPtr<gfxASurface> mScreenReferenceSurface;
893
    nsCOMPtr<nsIObserver> mSRGBOverrideObserver;
894
    RefPtr<mozilla::layers::MemoryPressureObserver> mMemoryPressureObserver;
895
896
    // The preferred draw target backend to use for canvas
897
    mozilla::gfx::BackendType mPreferredCanvasBackend;
898
    // The fallback draw target backend to use for canvas, if the preferred backend fails
899
    mozilla::gfx::BackendType mFallbackCanvasBackend;
900
    // The backend to use for content
901
    mozilla::gfx::BackendType mContentBackend;
902
    // The backend to use when we need it not to be accelerated.
903
    mozilla::gfx::BackendType mSoftwareBackend;
904
    // Bitmask of backend types we can use to render content
905
    uint32_t mContentBackendBitmask;
906
907
    mozilla::widget::GfxInfoCollector<gfxPlatform> mAzureCanvasBackendCollector;
908
    mozilla::widget::GfxInfoCollector<gfxPlatform> mApzSupportCollector;
909
    mozilla::widget::GfxInfoCollector<gfxPlatform> mTilesInfoCollector;
910
911
    RefPtr<mozilla::gfx::DrawEventRecorder> mRecorder;
912
    RefPtr<mozilla::gl::SkiaGLGlue> mSkiaGlue;
913
914
    // Backend that we are compositing with. NONE, if no compositor has been
915
    // created yet.
916
    mozilla::layers::LayersBackend mCompositorBackend;
917
918
    int32_t mScreenDepth;
919
    mozilla::gfx::IntSize mScreenSize;
920
921
    // An instance of gfxSkipChars which is empty. It is used as the
922
    // basis for error-case iterators.
923
    const gfxSkipChars kEmptySkipChars;
924
};
925
926
#endif /* GFX_PLATFORM_H */