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