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