2012-05-21 19:27:32 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-11-29 23:29:45 +03:00
|
|
|
|
2016-03-22 21:08:38 +03:00
|
|
|
#include "mozilla/layers/CompositorBridgeChild.h"
|
2016-05-16 09:38:34 +03:00
|
|
|
#include "mozilla/layers/CompositorThread.h"
|
2012-07-13 23:38:09 +04:00
|
|
|
#include "mozilla/layers/ImageBridgeChild.h"
|
2014-05-01 05:52:00 +04:00
|
|
|
#include "mozilla/layers/SharedBufferManagerChild.h"
|
2013-11-15 01:54:25 +04:00
|
|
|
#include "mozilla/layers/ISurfaceAllocator.h" // for GfxMemoryImageReporter
|
2016-08-04 21:33:42 +03:00
|
|
|
#include "mozilla/gfx/gfxVars.h"
|
2016-05-23 10:27:01 +03:00
|
|
|
#include "mozilla/gfx/GPUProcessManager.h"
|
2016-08-21 06:59:11 +03:00
|
|
|
#include "mozilla/gfx/GraphicsMessages.h"
|
2016-03-31 00:04:10 +03:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2015-10-14 09:24:00 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2015-12-30 13:47:00 +03:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2016-10-04 01:48:11 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2012-07-13 19:25:29 +04:00
|
|
|
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2015-07-08 23:51:09 +03:00
|
|
|
#include "mozilla/Services.h"
|
2011-01-21 19:44:33 +03:00
|
|
|
|
2016-01-18 20:56:38 +03:00
|
|
|
#include "gfxCrashReporterUtils.h"
|
2005-11-29 23:29:45 +03:00
|
|
|
#include "gfxPlatform.h"
|
2014-02-13 21:38:40 +04:00
|
|
|
#include "gfxPrefs.h"
|
2015-10-28 16:31:00 +03:00
|
|
|
#include "gfxEnv.h"
|
2014-09-16 13:58:12 +04:00
|
|
|
#include "gfxTextRun.h"
|
2016-04-29 07:52:54 +03:00
|
|
|
#include "gfxConfig.h"
|
2016-05-09 07:59:02 +03:00
|
|
|
#include "MediaPrefs.h"
|
2005-11-29 23:29:45 +03:00
|
|
|
|
2013-11-07 07:18:23 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <process.h>
|
|
|
|
#define getpid _getpid
|
2013-11-08 18:04:30 +04:00
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
2013-11-07 07:18:23 +04:00
|
|
|
#endif
|
|
|
|
|
2012-07-13 19:25:29 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2013-11-07 03:11:18 +04:00
|
|
|
#include "nsDirectoryServiceUtils.h"
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2012-07-13 19:25:29 +04:00
|
|
|
|
2005-11-29 23:29:45 +03:00
|
|
|
#if defined(XP_WIN)
|
2006-02-01 05:35:38 +03:00
|
|
|
#include "gfxWindowsPlatform.h"
|
2005-11-29 23:29:45 +03:00
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
#include "gfxPlatformMac.h"
|
2013-07-10 05:02:41 +04:00
|
|
|
#include "gfxQuartzSurface.h"
|
2012-06-28 04:15:32 +04:00
|
|
|
#elif defined(MOZ_WIDGET_GTK)
|
2005-11-29 23:29:45 +03:00
|
|
|
#include "gfxPlatformGtk.h"
|
2010-05-11 21:27:36 +04:00
|
|
|
#elif defined(ANDROID)
|
|
|
|
#include "gfxAndroidPlatform.h"
|
2005-11-29 23:29:45 +03:00
|
|
|
#endif
|
|
|
|
|
2016-01-13 20:10:51 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "mozilla/WindowsVersion.h"
|
|
|
|
#endif
|
|
|
|
|
2012-03-30 01:08:43 +04:00
|
|
|
#include "nsGkAtoms.h"
|
2009-08-16 17:52:12 +04:00
|
|
|
#include "gfxPlatformFontList.h"
|
2006-03-25 03:34:48 +03:00
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxImageSurface.h"
|
2012-02-24 14:15:46 +04:00
|
|
|
#include "nsUnicodeProperties.h"
|
2012-04-22 01:24:39 +04:00
|
|
|
#include "harfbuzz/hb.h"
|
2011-12-10 02:32:29 +04:00
|
|
|
#include "gfxGraphiteShaper.h"
|
2013-10-08 03:15:59 +04:00
|
|
|
#include "gfx2DGlue.h"
|
2013-11-08 08:50:39 +04:00
|
|
|
#include "gfxGradientCache.h"
|
2015-08-27 01:33:16 +03:00
|
|
|
#include "gfxUtils.h" // for NextPowerOfTwo
|
2006-03-25 03:34:48 +03:00
|
|
|
|
2009-10-07 19:26:58 +04:00
|
|
|
#include "nsUnicodeRange.h"
|
2006-09-26 08:20:41 +04:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2009-01-18 23:14:14 +03:00
|
|
|
#include "nsTArray.h"
|
2009-10-07 19:26:58 +04:00
|
|
|
#include "nsILocaleService.h"
|
2013-11-01 17:52:06 +04:00
|
|
|
#include "nsIObserverService.h"
|
2015-07-30 01:21:26 +03:00
|
|
|
#include "nsIScreenManager.h"
|
2016-03-31 00:04:10 +03:00
|
|
|
#include "FrameMetrics.h"
|
2013-11-27 11:33:39 +04:00
|
|
|
#include "MainThreadUtils.h"
|
2014-09-18 02:25:23 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2014-09-18 01:23:08 +04:00
|
|
|
#include "nsExceptionHandler.h"
|
2014-09-18 02:25:23 +04:00
|
|
|
#endif
|
2006-09-26 08:20:41 +04:00
|
|
|
|
2008-09-09 01:47:26 +04:00
|
|
|
#include "nsWeakReference.h"
|
|
|
|
|
2007-03-20 02:16:15 +03:00
|
|
|
#include "cairo.h"
|
2009-04-07 20:02:11 +04:00
|
|
|
#include "qcms.h"
|
2007-07-24 02:02:17 +04:00
|
|
|
|
2014-11-12 04:28:50 +03:00
|
|
|
#include "imgITools.h"
|
|
|
|
|
2008-01-31 03:23:36 +03:00
|
|
|
#include "plstr.h"
|
2009-10-07 18:13:40 +04:00
|
|
|
#include "nsCRT.h"
|
2010-07-20 08:05:42 +04:00
|
|
|
#include "GLContext.h"
|
|
|
|
#include "GLContextProvider.h"
|
2014-09-18 01:23:08 +04:00
|
|
|
#include "mozilla/gfx/Logging.h"
|
2007-03-20 02:16:15 +03:00
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
|
|
|
#include "gfxPlatformGtk.h" // xxx - for UseFcFontList
|
|
|
|
#endif
|
|
|
|
|
2012-07-20 23:20:51 +04:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
#include "TexturePoolOGL.h"
|
|
|
|
#endif
|
|
|
|
|
2014-11-13 01:55:13 +03:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
#include "mozilla/layers/GrallocTextureHost.h"
|
|
|
|
#endif
|
|
|
|
|
2014-04-15 23:07:42 +04:00
|
|
|
#ifdef USE_SKIA
|
2015-09-12 06:30:14 +03:00
|
|
|
# ifdef __GNUC__
|
|
|
|
# pragma GCC diagnostic push
|
|
|
|
# pragma GCC diagnostic ignored "-Wshadow"
|
|
|
|
# endif
|
|
|
|
# include "skia/include/core/SkGraphics.h"
|
2014-10-15 07:55:37 +04:00
|
|
|
# ifdef USE_SKIA_GPU
|
2015-08-08 05:27:14 +03:00
|
|
|
# include "skia/include/gpu/GrContext.h"
|
|
|
|
# include "skia/include/gpu/gl/GrGLInterface.h"
|
2014-10-15 07:55:37 +04:00
|
|
|
# include "SkiaGLGlue.h"
|
|
|
|
# endif
|
2016-07-20 22:06:29 +03:00
|
|
|
# ifdef MOZ_ENABLE_FREETYPE
|
|
|
|
# include "skia/include/ports/SkTypeface_cairo.h"
|
|
|
|
# endif
|
2015-09-12 06:30:14 +03:00
|
|
|
# ifdef __GNUC__
|
|
|
|
# pragma GCC diagnostic pop // -Wshadow
|
|
|
|
# endif
|
2016-03-21 19:08:34 +03:00
|
|
|
static const uint32_t kDefaultGlyphCacheSize = -1;
|
|
|
|
|
2014-10-15 07:55:37 +04:00
|
|
|
#endif
|
2014-03-06 01:49:37 +04:00
|
|
|
|
2014-10-15 07:55:37 +04:00
|
|
|
#if !defined(USE_SKIA) || !defined(USE_SKIA_GPU)
|
2014-04-15 23:07:42 +04:00
|
|
|
class mozilla::gl::SkiaGLGlue : public GenericAtomicRefCounted {
|
|
|
|
};
|
2013-06-29 06:48:35 +04:00
|
|
|
#endif
|
|
|
|
|
2011-06-12 06:30:16 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-05-15 23:41:20 +04:00
|
|
|
#include "mozilla/Assertions.h"
|
2016-05-12 12:24:43 +03:00
|
|
|
#include "mozilla/Atomics.h"
|
2012-06-13 08:14:28 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-08-04 11:46:17 +04:00
|
|
|
#include "mozilla/Mutex.h"
|
2010-04-06 06:28:54 +04:00
|
|
|
|
2015-12-09 00:42:43 +03:00
|
|
|
#include "nsAlgorithm.h"
|
2010-08-28 18:18:41 +04:00
|
|
|
#include "nsIGfxInfo.h"
|
2013-12-13 02:13:20 +04:00
|
|
|
#include "nsIXULRuntime.h"
|
2014-12-18 19:30:06 +03:00
|
|
|
#include "VsyncSource.h"
|
2015-01-09 02:12:47 +03:00
|
|
|
#include "SoftwareVsyncSource.h"
|
2015-07-31 22:11:48 +03:00
|
|
|
#include "nscore.h" // for NS_FREE_PERMANENT_DATA
|
2015-08-02 23:59:33 +03:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2015-09-18 00:23:13 +03:00
|
|
|
#include "gfxVR.h"
|
|
|
|
#include "VRManagerChild.h"
|
2016-06-11 05:27:24 +03:00
|
|
|
#include "mozilla/gfx/GPUParent.h"
|
2016-09-23 18:40:25 +03:00
|
|
|
#include "prsystem.h"
|
2010-08-28 18:18:41 +04:00
|
|
|
|
2014-03-28 21:20:57 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
2014-08-27 02:57:49 +04:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2014-03-28 21:20:57 +04:00
|
|
|
void InitGralloc();
|
2014-08-27 02:57:49 +04:00
|
|
|
#endif
|
|
|
|
void ShutdownTileCache();
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|
2014-03-28 21:20:57 +04:00
|
|
|
|
2011-06-12 06:30:16 +04:00
|
|
|
using namespace mozilla;
|
2012-07-13 19:25:29 +04:00
|
|
|
using namespace mozilla::layers;
|
2015-07-29 23:35:55 +03:00
|
|
|
using namespace mozilla::gl;
|
2016-04-29 07:52:54 +03:00
|
|
|
using namespace mozilla::gfx;
|
2011-06-12 06:30:16 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
gfxPlatform *gPlatform = nullptr;
|
2011-04-21 23:36:49 +04:00
|
|
|
static bool gEverInitialized = false;
|
2008-07-17 07:09:08 +04:00
|
|
|
|
2013-08-04 11:46:17 +04:00
|
|
|
static Mutex* gGfxPlatformPrefsLock = nullptr;
|
|
|
|
|
2013-09-07 07:08:36 +04:00
|
|
|
// These two may point to the same profile
|
|
|
|
static qcms_profile *gCMSOutputProfile = nullptr;
|
|
|
|
static qcms_profile *gCMSsRGBProfile = nullptr;
|
|
|
|
|
|
|
|
static qcms_transform *gCMSRGBTransform = nullptr;
|
|
|
|
static qcms_transform *gCMSInverseRGBTransform = nullptr;
|
|
|
|
static qcms_transform *gCMSRGBATransform = nullptr;
|
|
|
|
|
|
|
|
static bool gCMSInitialized = false;
|
|
|
|
static eCMSMode gCMSMode = eCMSMode_Off;
|
2014-03-06 01:25:09 +04:00
|
|
|
|
2013-09-07 07:08:36 +04:00
|
|
|
static void ShutdownCMS();
|
|
|
|
|
2011-06-24 21:41:18 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2014-06-17 13:08:23 +04:00
|
|
|
#include "mozilla/gfx/SourceSurfaceCairo.h"
|
2011-06-24 21:41:18 +04:00
|
|
|
using namespace mozilla::gfx;
|
2011-01-21 19:44:33 +03:00
|
|
|
|
2013-09-07 07:08:36 +04:00
|
|
|
/* Class to listen for pref changes so that chrome code can dynamically
|
|
|
|
force sRGB as an output profile. See Bug #452125. */
|
2015-03-21 19:28:04 +03:00
|
|
|
class SRGBOverrideObserver final : public nsIObserver,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsSupportsWeakReference
|
2013-09-07 07:08:36 +04:00
|
|
|
{
|
2014-06-23 22:49:07 +04:00
|
|
|
~SRGBOverrideObserver() {}
|
2013-09-07 07:08:36 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
};
|
|
|
|
|
2014-11-18 01:16:55 +03:00
|
|
|
/// This override of the LogForwarder, initially used for the critical graphics
|
|
|
|
/// errors, is sending the log to the crash annotations as well, but only
|
|
|
|
/// if the capacity set with the method below is >= 2. We always retain the
|
|
|
|
/// very first critical message, and the latest capacity-1 messages are
|
|
|
|
/// rotated through. Note that we don't expect the total number of times
|
|
|
|
/// this gets called to be large - it is meant for critical errors only.
|
|
|
|
|
2014-09-18 01:23:08 +04:00
|
|
|
class CrashStatsLogForwarder: public mozilla::gfx::LogForwarder
|
|
|
|
{
|
|
|
|
public:
|
2014-12-11 01:48:11 +03:00
|
|
|
explicit CrashStatsLogForwarder(const char* aKey);
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void Log(const std::string& aString) override;
|
2015-10-14 09:24:00 +03:00
|
|
|
virtual void CrashAction(LogReason aReason) override;
|
2016-02-17 02:07:37 +03:00
|
|
|
virtual bool UpdateStringsVector(const std::string& aString) override;
|
2014-11-18 01:16:55 +03:00
|
|
|
|
2015-12-30 13:47:00 +03:00
|
|
|
virtual LoggingRecord LoggingRecordCopy() override;
|
2015-01-14 05:19:25 +03:00
|
|
|
|
2014-11-18 01:16:55 +03:00
|
|
|
void SetCircularBufferSize(uint32_t aCapacity);
|
|
|
|
|
|
|
|
private:
|
2016-02-17 02:07:37 +03:00
|
|
|
// Helper for the Log()
|
2014-11-18 01:16:55 +03:00
|
|
|
void UpdateCrashReport();
|
|
|
|
|
|
|
|
private:
|
2015-12-30 13:47:00 +03:00
|
|
|
LoggingRecord mBuffer;
|
2014-11-18 01:16:55 +03:00
|
|
|
nsCString mCrashCriticalKey;
|
|
|
|
uint32_t mMaxCapacity;
|
|
|
|
int32_t mIndex;
|
2014-12-19 20:03:58 +03:00
|
|
|
Mutex mMutex;
|
2014-11-18 01:16:55 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
CrashStatsLogForwarder::CrashStatsLogForwarder(const char* aKey)
|
|
|
|
: mBuffer()
|
|
|
|
, mCrashCriticalKey(aKey)
|
|
|
|
, mMaxCapacity(0)
|
|
|
|
, mIndex(-1)
|
2014-12-19 20:03:58 +03:00
|
|
|
, mMutex("CrashStatsLogForwarder")
|
2014-11-18 01:16:55 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CrashStatsLogForwarder::SetCircularBufferSize(uint32_t aCapacity)
|
|
|
|
{
|
2014-12-19 20:03:58 +03:00
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
|
2014-11-18 01:16:55 +03:00
|
|
|
mMaxCapacity = aCapacity;
|
|
|
|
mBuffer.reserve(static_cast<size_t>(aCapacity));
|
|
|
|
}
|
|
|
|
|
2015-12-30 13:47:00 +03:00
|
|
|
LoggingRecord
|
|
|
|
CrashStatsLogForwarder::LoggingRecordCopy()
|
2015-01-14 05:19:25 +03:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
return mBuffer;
|
|
|
|
}
|
|
|
|
|
2014-11-18 01:16:55 +03:00
|
|
|
bool
|
|
|
|
CrashStatsLogForwarder::UpdateStringsVector(const std::string& aString)
|
|
|
|
{
|
|
|
|
// We want at least the first one and the last one. Otherwise, no point.
|
|
|
|
if (mMaxCapacity < 2) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mIndex += 1;
|
|
|
|
MOZ_ASSERT(mIndex >= 0);
|
|
|
|
|
|
|
|
// index will count 0, 1, 2, ..., max-1, 1, 2, ..., max-1, 1, 2, ...
|
|
|
|
int32_t index = mIndex ? (mIndex-1) % (mMaxCapacity-1) + 1 : 0;
|
|
|
|
MOZ_ASSERT(index >= 0 && index < (int32_t)mMaxCapacity);
|
|
|
|
MOZ_ASSERT(index <= mIndex && index <= (int32_t)mBuffer.size());
|
|
|
|
|
2015-12-30 13:47:00 +03:00
|
|
|
bool ignored;
|
|
|
|
double tStamp = (TimeStamp::NowLoRes()-TimeStamp::ProcessCreation(ignored)).ToSecondsSigDigits();
|
|
|
|
|
2014-11-18 01:16:55 +03:00
|
|
|
// Checking for index >= mBuffer.size(), rather than index == mBuffer.size()
|
|
|
|
// just out of paranoia, but we know index <= mBuffer.size().
|
2015-12-30 13:47:00 +03:00
|
|
|
LoggingRecordEntry newEntry(mIndex,aString,tStamp);
|
2014-11-18 01:16:55 +03:00
|
|
|
if (index >= static_cast<int32_t>(mBuffer.size())) {
|
|
|
|
mBuffer.push_back(newEntry);
|
|
|
|
} else {
|
|
|
|
mBuffer[index] = newEntry;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CrashStatsLogForwarder::UpdateCrashReport()
|
|
|
|
{
|
|
|
|
std::stringstream message;
|
2016-10-04 01:48:11 +03:00
|
|
|
std::string logAnnotation;
|
|
|
|
|
|
|
|
switch (XRE_GetProcessType()) {
|
|
|
|
case GeckoProcessType_Default:
|
|
|
|
logAnnotation = "|[";
|
|
|
|
break;
|
|
|
|
case GeckoProcessType_Content:
|
|
|
|
logAnnotation = "|[C";
|
|
|
|
break;
|
|
|
|
case GeckoProcessType_GPU:
|
|
|
|
logAnnotation = "|[G";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
logAnnotation = "|[X";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (LoggingRecord::iterator it = mBuffer.begin(); it != mBuffer.end(); ++it) {
|
|
|
|
message << logAnnotation << Get<0>(*it) << "]" << Get<1>(*it) << " (t=" << Get<2>(*it) << ") ";
|
2014-11-18 01:16:55 +03:00
|
|
|
}
|
|
|
|
|
2014-09-18 02:25:23 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2014-11-18 01:16:55 +03:00
|
|
|
nsCString reportString(message.str().c_str());
|
|
|
|
nsresult annotated = CrashReporter::AnnotateCrashReport(mCrashCriticalKey, reportString);
|
2014-09-18 02:25:23 +04:00
|
|
|
#else
|
2014-11-18 01:16:55 +03:00
|
|
|
nsresult annotated = NS_ERROR_NOT_IMPLEMENTED;
|
2014-09-18 02:25:23 +04:00
|
|
|
#endif
|
2014-11-18 01:16:55 +03:00
|
|
|
if (annotated != NS_OK) {
|
|
|
|
printf("Crash Annotation %s: %s",
|
|
|
|
mCrashCriticalKey.get(), message.str().c_str());
|
|
|
|
}
|
|
|
|
}
|
2015-07-31 22:11:48 +03:00
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class LogForwarderEvent : public Runnable
|
2016-02-17 02:07:37 +03:00
|
|
|
{
|
|
|
|
virtual ~LogForwarderEvent() {}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
explicit LogForwarderEvent(const nsCString& aMessage) : mMessage(aMessage) {}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() override {
|
2016-10-04 01:48:11 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread() && (XRE_IsContentProcess() || XRE_IsGPUProcess()));
|
|
|
|
|
|
|
|
if (XRE_IsContentProcess()) {
|
|
|
|
dom::ContentChild* cc = dom::ContentChild::GetSingleton();
|
|
|
|
Unused << cc->SendGraphicsError(mMessage);
|
|
|
|
} else if (XRE_IsGPUProcess()) {
|
|
|
|
GPUParent* gp = GPUParent::GetSingleton();
|
|
|
|
Unused << gp->SendGraphicsError(mMessage);
|
|
|
|
}
|
|
|
|
|
2016-02-17 02:07:37 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsCString mMessage;
|
|
|
|
};
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(LogForwarderEvent, Runnable);
|
2016-02-17 02:07:37 +03:00
|
|
|
|
2014-11-18 01:16:55 +03:00
|
|
|
void CrashStatsLogForwarder::Log(const std::string& aString)
|
|
|
|
{
|
2014-12-19 20:03:58 +03:00
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
|
2014-11-18 01:16:55 +03:00
|
|
|
if (UpdateStringsVector(aString)) {
|
|
|
|
UpdateCrashReport();
|
|
|
|
}
|
2016-02-17 02:07:37 +03:00
|
|
|
|
|
|
|
// Add it to the parent strings
|
|
|
|
if (!XRE_IsParentProcess()) {
|
|
|
|
nsCString stringToSend(aString.c_str());
|
|
|
|
if (NS_IsMainThread()) {
|
2016-10-04 01:48:11 +03:00
|
|
|
if (XRE_IsContentProcess()) {
|
|
|
|
dom::ContentChild* cc = dom::ContentChild::GetSingleton();
|
|
|
|
Unused << cc->SendGraphicsError(stringToSend);
|
|
|
|
} else if (XRE_IsGPUProcess()) {
|
|
|
|
GPUParent* gp = GPUParent::GetSingleton();
|
|
|
|
Unused << gp->SendGraphicsError(stringToSend);
|
|
|
|
}
|
2016-02-17 02:07:37 +03:00
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIRunnable> r1 = new LogForwarderEvent(stringToSend);
|
|
|
|
NS_DispatchToMainThread(r1);
|
|
|
|
}
|
|
|
|
}
|
2014-11-18 01:16:55 +03:00
|
|
|
}
|
2014-09-18 01:23:08 +04:00
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class CrashTelemetryEvent : public Runnable
|
2015-10-14 09:24:00 +03:00
|
|
|
{
|
|
|
|
virtual ~CrashTelemetryEvent() {}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
explicit CrashTelemetryEvent(uint32_t aReason) : mReason(aReason) {}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() override {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
Telemetry::Accumulate(Telemetry::GFX_CRASH, mReason);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
uint32_t mReason;
|
|
|
|
};
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(CrashTelemetryEvent, Runnable);
|
2015-10-14 09:24:00 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
CrashStatsLogForwarder::CrashAction(LogReason aReason)
|
|
|
|
{
|
2016-10-08 12:14:49 +03:00
|
|
|
#ifndef RELEASE_OR_BETA
|
2015-10-14 09:24:00 +03:00
|
|
|
// Non-release builds crash by default, but will use telemetry
|
|
|
|
// if this environment variable is present.
|
2015-11-09 09:28:00 +03:00
|
|
|
static bool useTelemetry = gfxEnv::GfxDevCrashTelemetry();
|
2015-10-14 09:24:00 +03:00
|
|
|
#else
|
2015-10-28 16:31:00 +03:00
|
|
|
// Release builds use telemetry by default, but will crash instead
|
|
|
|
// if this environment variable is present.
|
2015-11-09 09:28:00 +03:00
|
|
|
static bool useTelemetry = !gfxEnv::GfxDevCrashMozCrash();
|
2015-10-14 09:24:00 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (useTelemetry) {
|
|
|
|
// The callers need to assure that aReason is in the range
|
|
|
|
// that the telemetry call below supports.
|
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
Telemetry::Accumulate(Telemetry::GFX_CRASH, (uint32_t)aReason);
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIRunnable> r1 = new CrashTelemetryEvent((uint32_t)aReason);
|
|
|
|
NS_DispatchToMainThread(r1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// ignoring aReason, we can get the information we need from the stack
|
|
|
|
MOZ_CRASH("GFX_CRASH");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(SRGBOverrideObserver, nsIObserver, nsISupportsWeakReference)
|
2013-09-07 07:08:36 +04:00
|
|
|
|
2010-05-27 09:05:30 +04:00
|
|
|
#define GFX_DOWNLOADABLE_FONTS_ENABLED "gfx.downloadable_fonts.enabled"
|
|
|
|
|
2012-03-09 06:05:40 +04:00
|
|
|
#define GFX_PREF_FALLBACK_USE_CMAPS "gfx.font_rendering.fallback.always_use_cmaps"
|
2009-10-07 21:16:52 +04:00
|
|
|
|
2012-09-06 08:57:54 +04:00
|
|
|
#define GFX_PREF_OPENTYPE_SVG "gfx.font_rendering.opentype_svg.enabled"
|
|
|
|
|
2013-09-11 05:36:57 +04:00
|
|
|
#define GFX_PREF_WORD_CACHE_CHARLIMIT "gfx.font_rendering.wordcache.charlimit"
|
2013-09-11 05:36:57 +04:00
|
|
|
#define GFX_PREF_WORD_CACHE_MAXENTRIES "gfx.font_rendering.wordcache.maxentries"
|
2013-09-11 05:36:57 +04:00
|
|
|
|
2011-12-10 02:32:29 +04:00
|
|
|
#define GFX_PREF_GRAPHITE_SHAPING "gfx.font_rendering.graphite.enabled"
|
|
|
|
|
2011-12-06 16:39:19 +04:00
|
|
|
#define BIDI_NUMERAL_PREF "bidi.numeral"
|
|
|
|
|
2014-01-09 22:17:29 +04:00
|
|
|
#define GFX_PREF_CMS_FORCE_SRGB "gfx.color_management.force_srgb"
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
SRGBOverrideObserver::Observe(nsISupports *aSubject,
|
|
|
|
const char *aTopic,
|
|
|
|
const char16_t* someData)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_strcmp(someData,
|
2016-07-20 07:07:53 +03:00
|
|
|
(u"" GFX_PREF_CMS_FORCE_SRGB)) == 0,
|
2014-01-09 22:17:29 +04:00
|
|
|
"Restarting CMS on wrong pref!");
|
|
|
|
ShutdownCMS();
|
2015-02-06 02:18:00 +03:00
|
|
|
// Update current cms profile.
|
|
|
|
gfxPlatform::CreateCMSOutputProfile();
|
2014-01-09 22:17:29 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-12 06:30:16 +04:00
|
|
|
static const char* kObservedPrefs[] = {
|
|
|
|
"gfx.downloadable_fonts.",
|
|
|
|
"gfx.font_rendering.",
|
2014-01-09 22:17:29 +04:00
|
|
|
BIDI_NUMERAL_PREF,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr
|
2011-06-12 06:30:16 +04:00
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class FontPrefsObserver final : public nsIObserver
|
2010-05-27 09:05:30 +04:00
|
|
|
{
|
2014-06-23 22:49:07 +04:00
|
|
|
~FontPrefsObserver() {}
|
2010-05-27 09:05:30 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(FontPrefsObserver, nsIObserver)
|
2010-05-27 09:05:30 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
FontPrefsObserver::Observe(nsISupports *aSubject,
|
|
|
|
const char *aTopic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *someData)
|
2010-05-27 09:05:30 +04:00
|
|
|
{
|
2011-06-12 06:30:16 +04:00
|
|
|
if (!someData) {
|
2010-05-27 09:05:30 +04:00
|
|
|
NS_ERROR("font pref observer code broken");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2011-06-12 06:30:16 +04:00
|
|
|
NS_ASSERTION(gfxPlatform::GetPlatform(), "the singleton instance has gone");
|
|
|
|
gfxPlatform::GetPlatform()->FontsPrefsChanged(NS_ConvertUTF16toUTF8(someData).get());
|
2010-05-27 09:05:30 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class MemoryPressureObserver final : public nsIObserver
|
2013-11-01 17:52:06 +04:00
|
|
|
{
|
2014-06-23 22:49:07 +04:00
|
|
|
~MemoryPressureObserver() {}
|
2013-11-01 17:52:06 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(MemoryPressureObserver, nsIObserver)
|
2013-11-01 17:52:06 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MemoryPressureObserver::Observe(nsISupports *aSubject,
|
|
|
|
const char *aTopic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *someData)
|
2013-11-01 17:52:06 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(strcmp(aTopic, "memory-pressure") == 0, "unexpected event topic");
|
2013-12-05 08:52:03 +04:00
|
|
|
Factory::PurgeAllCaches();
|
2014-09-04 21:28:43 +04:00
|
|
|
gfxGradientCache::PurgeAllCaches();
|
2014-03-06 01:49:37 +04:00
|
|
|
|
2016-03-23 21:17:02 +03:00
|
|
|
gfxPlatform::PurgeSkiaFontCache();
|
|
|
|
gfxPlatform::GetPlatform()->PurgeSkiaGPUCache();
|
2013-11-01 17:52:06 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-27 09:05:30 +04:00
|
|
|
gfxPlatform::gfxPlatform()
|
2016-08-04 21:33:43 +03:00
|
|
|
: mAzureCanvasBackendCollector(this, &gfxPlatform::GetAzureBackendInfo)
|
2015-03-25 01:04:44 +03:00
|
|
|
, mApzSupportCollector(this, &gfxPlatform::GetApzSupportInfo)
|
2016-07-21 09:08:39 +03:00
|
|
|
, mTilesInfoCollector(this, &gfxPlatform::GetTilesSupportInfo)
|
2015-07-20 00:50:35 +03:00
|
|
|
, mCompositorBackend(layers::LayersBackend::LAYERS_NONE)
|
2015-08-27 01:33:16 +03:00
|
|
|
, mScreenDepth(0)
|
2016-03-01 00:41:35 +03:00
|
|
|
, mDeviceCounter(0)
|
2010-05-27 09:05:30 +04:00
|
|
|
{
|
|
|
|
mAllowDownloadableFonts = UNINITIALIZED_VALUE;
|
2012-03-09 06:05:40 +04:00
|
|
|
mFallbackUsesCmaps = UNINITIALIZED_VALUE;
|
|
|
|
|
2013-09-11 05:36:57 +04:00
|
|
|
mWordCacheCharLimit = UNINITIALIZED_VALUE;
|
2013-09-11 05:36:57 +04:00
|
|
|
mWordCacheMaxEntries = UNINITIALIZED_VALUE;
|
2011-12-10 02:32:29 +04:00
|
|
|
mGraphiteShapingEnabled = UNINITIALIZED_VALUE;
|
2013-05-16 20:32:41 +04:00
|
|
|
mOpenTypeSVGEnabled = UNINITIALIZED_VALUE;
|
2011-12-06 16:39:19 +04:00
|
|
|
mBidiNumeralOption = UNINITIALIZED_VALUE;
|
2012-01-28 02:38:00 +04:00
|
|
|
|
2014-03-06 01:49:37 +04:00
|
|
|
mSkiaGlue = nullptr;
|
|
|
|
|
2016-08-22 20:50:48 +03:00
|
|
|
uint32_t canvasMask = BackendTypeBit(BackendType::CAIRO);
|
2016-08-31 22:53:08 +03:00
|
|
|
uint32_t contentMask = BackendTypeBit(BackendType::CAIRO);
|
2016-08-22 20:50:48 +03:00
|
|
|
#ifdef USE_SKIA
|
|
|
|
canvasMask |= BackendTypeBit(BackendType::SKIA);
|
2016-08-31 22:53:08 +03:00
|
|
|
contentMask |= BackendTypeBit(BackendType::SKIA);
|
2016-08-22 20:50:48 +03:00
|
|
|
#endif
|
2014-01-10 23:06:16 +04:00
|
|
|
InitBackendPrefs(canvasMask, BackendType::CAIRO,
|
|
|
|
contentMask, BackendType::CAIRO);
|
2016-09-23 18:40:25 +03:00
|
|
|
|
|
|
|
mTotalSystemMemory = PR_GetPhysicalMemorySize();
|
2014-07-09 23:24:49 +04:00
|
|
|
|
2015-09-18 00:23:13 +03:00
|
|
|
VRManager::ManagerInit();
|
2010-05-27 09:05:30 +04:00
|
|
|
}
|
2008-01-31 03:23:36 +03:00
|
|
|
|
2005-11-29 23:29:45 +03:00
|
|
|
gfxPlatform*
|
|
|
|
gfxPlatform::GetPlatform()
|
|
|
|
{
|
2011-04-21 23:36:49 +04:00
|
|
|
if (!gPlatform) {
|
|
|
|
Init();
|
|
|
|
}
|
2007-03-30 01:48:46 +04:00
|
|
|
return gPlatform;
|
|
|
|
}
|
|
|
|
|
2015-07-20 00:50:35 +03:00
|
|
|
bool
|
|
|
|
gfxPlatform::Initialized()
|
|
|
|
{
|
|
|
|
return !!gPlatform;
|
|
|
|
}
|
|
|
|
|
2013-12-11 03:10:01 +04:00
|
|
|
void RecordingPrefChanged(const char *aPrefName, void *aClosure)
|
2013-04-09 21:37:56 +04:00
|
|
|
{
|
|
|
|
if (Preferences::GetBool("gfx.2d.recording", false)) {
|
|
|
|
nsAutoCString fileName;
|
|
|
|
nsAdoptingString prefFileName = Preferences::GetString("gfx.2d.recordingfile");
|
|
|
|
|
|
|
|
if (prefFileName) {
|
|
|
|
fileName.Append(NS_ConvertUTF16toUTF8(prefFileName));
|
|
|
|
} else {
|
2013-11-07 03:11:18 +04:00
|
|
|
nsCOMPtr<nsIFile> tmpFile;
|
|
|
|
if (NS_FAILED(NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tmpFile)))) {
|
2013-12-11 03:10:01 +04:00
|
|
|
return;
|
2013-11-07 03:11:18 +04:00
|
|
|
}
|
|
|
|
fileName.AppendPrintf("moz2drec_%i_%i.aer", XRE_GetProcessType(), getpid());
|
|
|
|
|
|
|
|
nsresult rv = tmpFile->AppendNative(fileName);
|
|
|
|
if (NS_FAILED(rv))
|
2013-12-11 03:10:01 +04:00
|
|
|
return;
|
2013-11-07 03:11:18 +04:00
|
|
|
|
|
|
|
rv = tmpFile->GetNativePath(fileName);
|
|
|
|
if (NS_FAILED(rv))
|
2013-12-11 03:10:01 +04:00
|
|
|
return;
|
2013-04-09 21:37:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gPlatform->mRecorder = Factory::CreateEventRecorderForFile(fileName.BeginReading());
|
2013-11-07 03:11:18 +04:00
|
|
|
printf_stderr("Recording to %s\n", fileName.get());
|
2013-04-09 21:37:56 +04:00
|
|
|
Factory::SetGlobalEventRecorder(gPlatform->mRecorder);
|
|
|
|
} else {
|
|
|
|
Factory::SetGlobalEventRecorder(nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-21 19:08:34 +03:00
|
|
|
#if defined(USE_SKIA)
|
|
|
|
static uint32_t GetSkiaGlyphCacheSize()
|
|
|
|
{
|
|
|
|
// Only increase font cache size on non-android to save memory.
|
|
|
|
#if !defined(MOZ_WIDGET_ANDROID)
|
|
|
|
// 10mb as the default cache size on desktop due to talos perf tweaking.
|
|
|
|
// Chromium uses 20mb and skia default uses 2mb.
|
|
|
|
// We don't need to change the font cache count since we usually
|
|
|
|
// cache thrash due to asian character sets in talos.
|
|
|
|
// Only increase memory on the content proces
|
|
|
|
uint32_t cacheSize = 10 * 1024 * 1024;
|
|
|
|
if (mozilla::BrowserTabsRemoteAutostart()) {
|
|
|
|
return XRE_IsContentProcess() ? cacheSize : kDefaultGlyphCacheSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cacheSize;
|
|
|
|
#else
|
|
|
|
return kDefaultGlyphCacheSize;
|
|
|
|
#endif // MOZ_WIDGET_ANDROID
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-04-21 23:36:53 +04:00
|
|
|
void
|
2007-03-30 01:48:46 +04:00
|
|
|
gfxPlatform::Init()
|
|
|
|
{
|
2016-06-06 18:17:23 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread(), "GFX: Not in main thread.");
|
2011-04-21 23:36:49 +04:00
|
|
|
if (gEverInitialized) {
|
|
|
|
NS_RUNTIMEABORT("Already started???");
|
|
|
|
}
|
|
|
|
gEverInitialized = true;
|
2010-02-24 20:57:57 +03:00
|
|
|
|
2014-03-04 21:26:33 +04:00
|
|
|
// Initialize the preferences by creating the singleton.
|
|
|
|
gfxPrefs::GetSingleton();
|
2016-05-09 07:59:02 +03:00
|
|
|
MediaPrefs::GetSingleton();
|
2016-08-04 21:33:42 +03:00
|
|
|
gfxVars::Initialize();
|
2014-02-13 21:38:40 +04:00
|
|
|
|
2016-06-03 21:54:56 +03:00
|
|
|
gfxConfig::Init();
|
|
|
|
|
2016-06-11 04:00:40 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
GPUProcessManager::Initialize();
|
|
|
|
}
|
2016-05-23 10:27:01 +03:00
|
|
|
|
2016-01-18 20:56:38 +03:00
|
|
|
// Drop a note in the crash report if we end up forcing an option that could
|
|
|
|
// destabilize things. New items should be appended at the end (of an existing
|
|
|
|
// or in a new section), so that we don't have to know the version to interpret
|
|
|
|
// these cryptic strings.
|
|
|
|
{
|
|
|
|
nsAutoCString forcedPrefs;
|
|
|
|
// D2D prefs
|
2016-08-12 00:02:11 +03:00
|
|
|
forcedPrefs.AppendPrintf("FP(D%d%d",
|
2016-01-18 20:56:38 +03:00
|
|
|
gfxPrefs::Direct2DDisabled(),
|
2016-08-12 00:02:11 +03:00
|
|
|
gfxPrefs::Direct2DForceEnabled());
|
2016-01-18 20:56:38 +03:00
|
|
|
// Layers prefs
|
2016-08-13 22:18:50 +03:00
|
|
|
forcedPrefs.AppendPrintf("-L%d%d%d%d",
|
2016-01-18 20:56:38 +03:00
|
|
|
gfxPrefs::LayersAMDSwitchableGfxEnabled(),
|
2016-04-29 07:52:54 +03:00
|
|
|
gfxPrefs::LayersAccelerationDisabledDoNotUseDirectly(),
|
|
|
|
gfxPrefs::LayersAccelerationForceEnabledDoNotUseDirectly(),
|
2016-04-05 17:55:17 +03:00
|
|
|
gfxPrefs::LayersD3D11ForceWARP());
|
2016-01-18 20:56:38 +03:00
|
|
|
// WebGL prefs
|
|
|
|
forcedPrefs.AppendPrintf("-W%d%d%d%d%d%d%d%d",
|
|
|
|
gfxPrefs::WebGLANGLEForceD3D11(),
|
|
|
|
gfxPrefs::WebGLANGLEForceWARP(),
|
|
|
|
gfxPrefs::WebGLDisabled(),
|
|
|
|
gfxPrefs::WebGLDisableANGLE(),
|
|
|
|
gfxPrefs::WebGLDXGLEnabled(),
|
|
|
|
gfxPrefs::WebGLForceEnabled(),
|
|
|
|
gfxPrefs::WebGLForceLayersReadback(),
|
|
|
|
gfxPrefs::WebGLForceMSAA());
|
|
|
|
// Prefs that don't fit into any of the other sections
|
|
|
|
forcedPrefs.AppendPrintf("-T%d%d%d%d) ",
|
|
|
|
gfxPrefs::AndroidRGB16Force(),
|
|
|
|
gfxPrefs::CanvasAzureAccelerated(),
|
|
|
|
gfxPrefs::DisableGralloc(),
|
|
|
|
gfxPrefs::ForceShmemTiles());
|
|
|
|
ScopedGfxFeatureReporter::AppNote(forcedPrefs);
|
|
|
|
}
|
|
|
|
|
2016-10-04 01:48:11 +03:00
|
|
|
InitMoz2DLogging();
|
2014-11-18 01:16:55 +03:00
|
|
|
|
2013-08-04 11:46:17 +04:00
|
|
|
gGfxPlatformPrefsLock = new Mutex("gfxPlatform::gGfxPlatformPrefsLock");
|
|
|
|
|
2010-08-28 18:18:41 +04:00
|
|
|
/* Initialize the GfxInfo service.
|
|
|
|
* Note: we can't call functions on GfxInfo that depend
|
|
|
|
* on gPlatform until after it has been initialized
|
|
|
|
* below. GfxInfo initialization annotates our
|
|
|
|
* crash reports so we want to do it before
|
|
|
|
* we try to load any drivers and do device detection
|
|
|
|
* incase that code crashes. See bug #591561. */
|
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo;
|
|
|
|
/* this currently will only succeed on Windows */
|
2015-07-08 23:51:09 +03:00
|
|
|
gfxInfo = services::GetGfxInfo();
|
2010-08-28 18:18:41 +04:00
|
|
|
|
2005-11-29 23:29:45 +03:00
|
|
|
#if defined(XP_WIN)
|
2007-03-30 01:48:46 +04:00
|
|
|
gPlatform = new gfxWindowsPlatform;
|
2005-11-29 23:29:45 +03:00
|
|
|
#elif defined(XP_MACOSX)
|
2007-03-30 01:48:46 +04:00
|
|
|
gPlatform = new gfxPlatformMac;
|
2012-06-28 04:15:32 +04:00
|
|
|
#elif defined(MOZ_WIDGET_GTK)
|
2007-03-30 01:48:46 +04:00
|
|
|
gPlatform = new gfxPlatformGtk;
|
2010-05-11 21:27:36 +04:00
|
|
|
#elif defined(ANDROID)
|
|
|
|
gPlatform = new gfxAndroidPlatform;
|
2011-04-17 05:22:41 +04:00
|
|
|
#else
|
|
|
|
#error "No gfxPlatform implementation available"
|
2005-11-29 23:29:45 +03:00
|
|
|
#endif
|
2016-04-29 07:52:54 +03:00
|
|
|
gPlatform->InitAcceleration();
|
2007-03-30 01:48:46 +04:00
|
|
|
|
2015-12-29 20:22:51 +03:00
|
|
|
#ifdef USE_SKIA
|
|
|
|
SkGraphics::Init();
|
2016-07-20 22:06:29 +03:00
|
|
|
# ifdef MOZ_ENABLE_FREETYPE
|
|
|
|
SkInitCairoFT(gPlatform->FontHintingEnabled());
|
|
|
|
# endif
|
2015-12-29 20:22:51 +03:00
|
|
|
#endif
|
|
|
|
|
2014-10-15 05:24:53 +04:00
|
|
|
#ifdef MOZ_GL_DEBUG
|
2015-07-29 23:35:55 +03:00
|
|
|
GLContext::StaticInit();
|
2012-05-13 03:23:56 +04:00
|
|
|
#endif
|
|
|
|
|
2014-06-06 17:51:24 +04:00
|
|
|
InitLayersIPC();
|
2013-06-21 01:32:04 +04:00
|
|
|
|
2015-08-27 01:37:48 +03:00
|
|
|
gPlatform->PopulateScreenInfo();
|
2015-08-07 22:37:56 +03:00
|
|
|
gPlatform->ComputeTileSize();
|
|
|
|
|
2007-03-30 01:48:46 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
bool usePlatformFontList = true;
|
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
|
|
|
usePlatformFontList = gfxPlatformGtk::UseFcFontList();
|
2015-05-12 13:21:09 +03:00
|
|
|
#endif
|
2015-05-12 11:44:16 +03:00
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
if (usePlatformFontList) {
|
|
|
|
rv = gfxPlatformFontList::Init();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RUNTIMEABORT("Could not initialize gfxPlatformFontList");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-08 14:02:27 +03:00
|
|
|
gPlatform->mScreenReferenceSurface =
|
2014-02-09 12:04:38 +04:00
|
|
|
gPlatform->CreateOffscreenSurface(IntSize(1, 1),
|
2016-01-08 07:57:38 +03:00
|
|
|
SurfaceFormat::A8R8G8B8_UINT32);
|
2010-11-08 14:02:27 +03:00
|
|
|
if (!gPlatform->mScreenReferenceSurface) {
|
2011-04-21 23:36:53 +04:00
|
|
|
NS_RUNTIMEABORT("Could not initialize mScreenReferenceSurface");
|
2010-11-08 14:02:27 +03:00
|
|
|
}
|
|
|
|
|
2014-03-19 06:36:58 +04:00
|
|
|
gPlatform->mScreenReferenceDrawTarget =
|
|
|
|
gPlatform->CreateOffscreenContentDrawTarget(IntSize(1, 1),
|
|
|
|
SurfaceFormat::B8G8R8A8);
|
2016-05-23 22:12:10 +03:00
|
|
|
if (!gPlatform->mScreenReferenceDrawTarget ||
|
|
|
|
!gPlatform->mScreenReferenceDrawTarget->IsValid()) {
|
2014-03-19 06:36:58 +04:00
|
|
|
NS_RUNTIMEABORT("Could not initialize mScreenReferenceDrawTarget");
|
2013-10-24 19:50:26 +04:00
|
|
|
}
|
|
|
|
|
2007-04-04 07:32:43 +04:00
|
|
|
rv = gfxFontCache::Init();
|
|
|
|
if (NS_FAILED(rv)) {
|
2011-04-21 23:36:53 +04:00
|
|
|
NS_RUNTIMEABORT("Could not initialize gfxFontCache");
|
2007-04-04 07:32:43 +04:00
|
|
|
}
|
|
|
|
|
2013-09-07 07:08:36 +04:00
|
|
|
/* Create and register our CMS Override observer. */
|
|
|
|
gPlatform->mSRGBOverrideObserver = new SRGBOverrideObserver();
|
2014-01-09 22:17:29 +04:00
|
|
|
Preferences::AddWeakObserver(gPlatform->mSRGBOverrideObserver, GFX_PREF_CMS_FORCE_SRGB);
|
2011-06-12 06:30:16 +04:00
|
|
|
|
|
|
|
gPlatform->mFontPrefsObserver = new FontPrefsObserver();
|
|
|
|
Preferences::AddStrongObservers(gPlatform->mFontPrefsObserver, kObservedPrefs);
|
2011-04-21 23:36:49 +04:00
|
|
|
|
2015-07-29 23:35:55 +03:00
|
|
|
GLContext::PlatformStartup();
|
2012-11-07 02:39:38 +04:00
|
|
|
|
2012-07-20 23:20:51 +04:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
// Texture pool init
|
2015-07-29 23:35:55 +03:00
|
|
|
TexturePoolOGL::Init();
|
2012-07-20 23:20:51 +04:00
|
|
|
#endif
|
|
|
|
|
2014-03-28 21:20:57 +04:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
mozilla::layers::InitGralloc();
|
|
|
|
#endif
|
|
|
|
|
2013-04-09 21:37:56 +04:00
|
|
|
Preferences::RegisterCallbackAndCall(RecordingPrefChanged, "gfx.2d.recording", nullptr);
|
2012-11-22 06:40:57 +04:00
|
|
|
|
2013-09-07 07:08:36 +04:00
|
|
|
CreateCMSOutputProfile();
|
2013-11-01 17:52:06 +04:00
|
|
|
|
|
|
|
// Listen to memory pressure event so we can purge DrawTarget caches
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
gPlatform->mMemoryPressureObserver = new MemoryPressureObserver();
|
|
|
|
obs->AddObserver(gPlatform->mMemoryPressureObserver, "memory-pressure", false);
|
|
|
|
}
|
2013-11-15 01:54:25 +04:00
|
|
|
|
2014-11-12 04:28:50 +03:00
|
|
|
// Request the imgITools service, implicitly initializing ImageLib.
|
|
|
|
nsCOMPtr<imgITools> imgTools = do_GetService("@mozilla.org/image/tools;1");
|
|
|
|
if (!imgTools) {
|
|
|
|
NS_RUNTIMEABORT("Could not initialize ImageLib");
|
|
|
|
}
|
|
|
|
|
2013-11-07 09:35:30 +04:00
|
|
|
RegisterStrongMemoryReporter(new GfxMemoryImageReporter());
|
2014-11-21 21:52:17 +03:00
|
|
|
|
2015-08-24 18:27:23 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
2015-09-15 18:13:57 +03:00
|
|
|
if (gfxPlatform::ForceSoftwareVsync()) {
|
|
|
|
gPlatform->mVsyncSource = (gPlatform)->gfxPlatform::CreateHardwareVsyncSource();
|
|
|
|
} else {
|
|
|
|
gPlatform->mVsyncSource = gPlatform->CreateHardwareVsyncSource();
|
|
|
|
}
|
2014-11-21 21:52:17 +03:00
|
|
|
}
|
2016-03-21 19:08:34 +03:00
|
|
|
|
|
|
|
#ifdef USE_SKIA
|
|
|
|
uint32_t skiaCacheSize = GetSkiaGlyphCacheSize();
|
|
|
|
if (skiaCacheSize != kDefaultGlyphCacheSize) {
|
|
|
|
SkGraphics::SetFontCacheLimit(skiaCacheSize);
|
|
|
|
}
|
|
|
|
#endif
|
2016-03-31 00:04:10 +03:00
|
|
|
|
2016-07-20 07:11:44 +03:00
|
|
|
InitNullMetadata();
|
2016-06-20 19:29:47 +03:00
|
|
|
InitOpenGLConfig();
|
|
|
|
|
2016-05-09 20:44:21 +03:00
|
|
|
if (obs) {
|
|
|
|
obs->NotifyObservers(nullptr, "gfx-features-ready", nullptr);
|
|
|
|
}
|
2005-11-29 23:29:45 +03:00
|
|
|
}
|
|
|
|
|
2016-10-04 01:48:11 +03:00
|
|
|
/* static */ void
|
|
|
|
gfxPlatform::InitMoz2DLogging()
|
|
|
|
{
|
|
|
|
auto fwd = new CrashStatsLogForwarder("GraphicsCriticalError");
|
|
|
|
fwd->SetCircularBufferSize(gfxPrefs::GfxLoggingCrashLength());
|
|
|
|
|
|
|
|
mozilla::gfx::Config cfg;
|
|
|
|
cfg.mLogForwarder = fwd;
|
|
|
|
cfg.mMaxTextureSize = gfxPrefs::MaxTextureSize();
|
|
|
|
cfg.mMaxAllocSize = gfxPrefs::MaxAllocSize();
|
|
|
|
|
|
|
|
gfx::Factory::Init(cfg);
|
|
|
|
}
|
|
|
|
|
2014-06-06 17:51:24 +04:00
|
|
|
static bool sLayersIPCIsUp = false;
|
|
|
|
|
2016-07-20 07:11:44 +03:00
|
|
|
/* static */ void
|
|
|
|
gfxPlatform::InitNullMetadata()
|
|
|
|
{
|
|
|
|
ScrollMetadata::sNullMetadata = new ScrollMetadata();
|
|
|
|
ClearOnShutdown(&ScrollMetadata::sNullMetadata);
|
|
|
|
}
|
|
|
|
|
2007-03-20 02:16:15 +03:00
|
|
|
void
|
|
|
|
gfxPlatform::Shutdown()
|
|
|
|
{
|
2016-06-06 20:07:29 +03:00
|
|
|
// In some cases, gPlatform may not be created but Shutdown() called,
|
|
|
|
// e.g., during xpcshell tests.
|
2014-06-06 17:51:24 +04:00
|
|
|
if (!gPlatform) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(!sLayersIPCIsUp);
|
|
|
|
|
2007-03-30 01:48:46 +04:00
|
|
|
// These may be called before the corresponding subsystems have actually
|
|
|
|
// started up. That's OK, they can handle it.
|
2007-04-04 07:32:43 +04:00
|
|
|
gfxFontCache::Shutdown();
|
2010-02-24 20:57:44 +03:00
|
|
|
gfxFontGroup::Shutdown();
|
2013-11-08 08:50:39 +04:00
|
|
|
gfxGradientCache::Shutdown();
|
2014-06-11 01:51:24 +04:00
|
|
|
gfxAlphaBoxBlur::ShutdownBlurCache();
|
2011-12-10 02:32:29 +04:00
|
|
|
gfxGraphiteShaper::Shutdown();
|
2009-08-16 17:52:12 +04:00
|
|
|
gfxPlatformFontList::Shutdown();
|
2014-08-27 02:57:49 +04:00
|
|
|
ShutdownTileCache();
|
2008-07-17 07:09:08 +04:00
|
|
|
|
|
|
|
// Free the various non-null transforms and loaded profiles
|
2013-09-07 07:08:36 +04:00
|
|
|
ShutdownCMS();
|
2008-07-17 07:09:08 +04:00
|
|
|
|
2016-06-06 20:07:29 +03:00
|
|
|
/* Unregister our CMS Override callback. */
|
|
|
|
NS_ASSERTION(gPlatform->mSRGBOverrideObserver, "mSRGBOverrideObserver has alreay gone");
|
|
|
|
Preferences::RemoveObserver(gPlatform->mSRGBOverrideObserver, GFX_PREF_CMS_FORCE_SRGB);
|
|
|
|
gPlatform->mSRGBOverrideObserver = nullptr;
|
|
|
|
|
|
|
|
NS_ASSERTION(gPlatform->mFontPrefsObserver, "mFontPrefsObserver has alreay gone");
|
|
|
|
Preferences::RemoveObservers(gPlatform->mFontPrefsObserver, kObservedPrefs);
|
|
|
|
gPlatform->mFontPrefsObserver = nullptr;
|
2013-11-01 17:52:06 +04:00
|
|
|
|
2016-06-06 20:07:29 +03:00
|
|
|
NS_ASSERTION(gPlatform->mMemoryPressureObserver, "mMemoryPressureObserver has already gone");
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->RemoveObserver(gPlatform->mMemoryPressureObserver, "memory-pressure");
|
|
|
|
}
|
|
|
|
|
|
|
|
gPlatform->mMemoryPressureObserver = nullptr;
|
|
|
|
gPlatform->mSkiaGlue = nullptr;
|
|
|
|
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
gPlatform->mVsyncSource->Shutdown();
|
2011-06-12 06:30:16 +04:00
|
|
|
}
|
2009-09-10 05:22:03 +04:00
|
|
|
|
2016-06-06 20:07:29 +03:00
|
|
|
gPlatform->mVsyncSource = nullptr;
|
|
|
|
|
2012-07-20 23:20:51 +04:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
// Shut down the texture pool
|
2015-07-29 23:35:55 +03:00
|
|
|
TexturePoolOGL::Shutdown();
|
2012-07-20 23:20:51 +04:00
|
|
|
#endif
|
|
|
|
|
2012-02-09 23:05:11 +04:00
|
|
|
// Shut down the default GL context provider.
|
2015-07-29 23:35:55 +03:00
|
|
|
GLContextProvider::Shutdown();
|
2012-02-09 23:05:11 +04:00
|
|
|
|
2012-02-07 07:09:28 +04:00
|
|
|
#if defined(XP_WIN)
|
2012-02-09 23:05:11 +04:00
|
|
|
// The above shutdown calls operate on the available context providers on
|
|
|
|
// most platforms. Windows is a "special snowflake", though, and has three
|
|
|
|
// context providers available, so we have to shut all of them down.
|
|
|
|
// We should only support the default GL provider on Windows; then, this
|
|
|
|
// could go away. Unfortunately, we currently support WGL (the default) for
|
|
|
|
// WebGL on Optimus.
|
2015-07-29 23:35:55 +03:00
|
|
|
GLContextProviderEGL::Shutdown();
|
2012-02-07 07:09:28 +04:00
|
|
|
#endif
|
2010-07-20 08:05:42 +04:00
|
|
|
|
2016-06-11 04:00:40 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
GPUProcessManager::Shutdown();
|
|
|
|
}
|
2016-05-23 10:27:01 +03:00
|
|
|
|
2015-11-18 18:59:11 +03:00
|
|
|
gfx::Factory::ShutDown();
|
|
|
|
|
2013-08-04 11:46:17 +04:00
|
|
|
delete gGfxPlatformPrefsLock;
|
|
|
|
|
2016-08-04 21:33:42 +03:00
|
|
|
gfxVars::Shutdown();
|
2014-03-04 21:26:33 +04:00
|
|
|
gfxPrefs::DestroySingleton();
|
2014-03-20 10:43:30 +04:00
|
|
|
gfxFont::DestroySingletons();
|
2014-02-13 21:38:40 +04:00
|
|
|
|
2016-06-03 21:54:56 +03:00
|
|
|
gfxConfig::Shutdown();
|
|
|
|
|
2016-08-21 04:25:03 +03:00
|
|
|
gPlatform->WillShutdown();
|
|
|
|
|
2007-03-20 02:16:15 +03:00
|
|
|
delete gPlatform;
|
2012-07-30 18:20:58 +04:00
|
|
|
gPlatform = nullptr;
|
2007-03-20 02:16:15 +03:00
|
|
|
}
|
|
|
|
|
2014-06-06 17:51:24 +04:00
|
|
|
/* static */ void
|
|
|
|
gfxPlatform::InitLayersIPC()
|
|
|
|
{
|
|
|
|
if (sLayersIPCIsUp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sLayersIPCIsUp = true;
|
|
|
|
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsParentProcess())
|
2014-06-06 17:51:24 +04:00
|
|
|
{
|
2016-05-16 09:38:34 +03:00
|
|
|
layers::CompositorThreadHolder::Start();
|
2015-07-08 10:28:48 +03:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2014-06-06 17:51:24 +04:00
|
|
|
SharedBufferManagerChild::StartUp();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
gfxPlatform::ShutdownLayersIPC()
|
|
|
|
{
|
|
|
|
if (!sLayersIPCIsUp) {
|
|
|
|
return;
|
|
|
|
}
|
2016-04-13 20:55:08 +03:00
|
|
|
sLayersIPCIsUp = false;
|
2014-06-06 17:51:24 +04:00
|
|
|
|
2015-11-24 05:33:32 +03:00
|
|
|
if (XRE_IsContentProcess()) {
|
|
|
|
gfx::VRManagerChild::ShutDown();
|
2016-04-07 16:47:35 +03:00
|
|
|
// cf bug 1215265.
|
|
|
|
if (gfxPrefs::ChildProcessShutdown()) {
|
|
|
|
layers::CompositorBridgeChild::ShutDown();
|
2016-04-25 06:54:07 +03:00
|
|
|
layers::ImageBridgeChild::ShutDown();
|
2016-04-07 16:47:35 +03:00
|
|
|
}
|
2015-11-24 05:33:32 +03:00
|
|
|
} else if (XRE_IsParentProcess()) {
|
|
|
|
gfx::VRManagerChild::ShutDown();
|
2015-11-24 04:50:51 +03:00
|
|
|
layers::CompositorBridgeChild::ShutDown();
|
2016-05-04 16:22:45 +03:00
|
|
|
layers::ImageBridgeChild::ShutDown();
|
2015-11-24 05:33:32 +03:00
|
|
|
|
2014-06-06 17:51:24 +04:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2015-11-24 05:33:32 +03:00
|
|
|
layers::SharedBufferManagerChild::ShutDown();
|
2014-06-06 17:51:24 +04:00
|
|
|
#endif
|
|
|
|
|
2015-11-24 05:33:32 +03:00
|
|
|
// This has to happen after shutting down the child protocols.
|
2016-05-16 09:38:34 +03:00
|
|
|
layers::CompositorThreadHolder::Shutdown();
|
2015-11-24 05:33:32 +03:00
|
|
|
} else {
|
|
|
|
// TODO: There are other kind of processes and we should make sure gfx
|
|
|
|
// stuff is either not created there or shut down properly.
|
|
|
|
}
|
2014-06-06 17:51:24 +04:00
|
|
|
}
|
|
|
|
|
2016-08-21 04:25:03 +03:00
|
|
|
void
|
|
|
|
gfxPlatform::WillShutdown()
|
2007-03-20 02:16:15 +03:00
|
|
|
{
|
2016-08-21 04:25:03 +03:00
|
|
|
// Destoy these first in case they depend on backend-specific resources.
|
|
|
|
// Otherwise, the backend's destructor would be called before the
|
|
|
|
// base gfxPlatform destructor.
|
2012-07-30 18:20:58 +04:00
|
|
|
mScreenReferenceSurface = nullptr;
|
2013-10-24 19:50:26 +04:00
|
|
|
mScreenReferenceDrawTarget = nullptr;
|
2016-08-21 04:25:03 +03:00
|
|
|
}
|
2012-05-12 01:21:41 +04:00
|
|
|
|
2016-08-21 04:25:03 +03:00
|
|
|
gfxPlatform::~gfxPlatform()
|
|
|
|
{
|
2007-03-20 02:16:15 +03:00
|
|
|
// The cairo folks think we should only clean up in debug builds,
|
|
|
|
// but we're generally in the habit of trying to shut down as
|
|
|
|
// cleanly as possible even in production code, so call this
|
|
|
|
// cairo_debug_* function unconditionally.
|
2007-10-26 05:21:50 +04:00
|
|
|
//
|
|
|
|
// because cairo can assert and thus crash on shutdown, don't do this in release builds
|
2015-07-31 22:11:48 +03:00
|
|
|
#ifdef NS_FREE_PERMANENT_DATA
|
2013-06-29 06:48:35 +04:00
|
|
|
#ifdef USE_SKIA
|
|
|
|
// must do Skia cleanup before Cairo cleanup, because Skia may be referencing
|
|
|
|
// Cairo objects e.g. through SkCairoFTTypeface
|
2015-12-18 21:53:25 +03:00
|
|
|
SkGraphics::PurgeFontCache();
|
2013-06-29 06:48:35 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if MOZ_TREE_CAIRO
|
2007-03-20 02:16:15 +03:00
|
|
|
cairo_debug_reset_static_data();
|
2007-10-26 05:21:50 +04:00
|
|
|
#endif
|
2013-06-29 06:48:35 +04:00
|
|
|
#endif
|
2007-03-20 02:16:15 +03:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<DrawTarget>
|
2012-07-24 14:18:38 +04:00
|
|
|
gfxPlatform::CreateDrawTargetForSurface(gfxASurface *aSurface, const IntSize& aSize)
|
2011-06-24 21:41:18 +04:00
|
|
|
{
|
2015-07-07 05:11:38 +03:00
|
|
|
SurfaceFormat format = aSurface->GetSurfaceFormat();
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DrawTarget> drawTarget = Factory::CreateDrawTargetForCairoSurface(aSurface->CairoSurface(), aSize, &format);
|
2015-03-09 22:48:20 +03:00
|
|
|
if (!drawTarget) {
|
|
|
|
gfxWarning() << "gfxPlatform::CreateDrawTargetForSurface failed in CreateDrawTargetForCairoSurface";
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-06-12 23:24:05 +04:00
|
|
|
return drawTarget.forget();
|
2011-06-24 21:41:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
cairo_user_data_key_t kSourceSurface;
|
|
|
|
|
2012-10-08 06:44:36 +04:00
|
|
|
/**
|
|
|
|
* Record the backend that was used to construct the SourceSurface.
|
|
|
|
* When getting the cached SourceSurface for a gfxASurface/DrawTarget pair,
|
|
|
|
* we check to make sure the DrawTarget's backend matches the backend
|
|
|
|
* for the cached SourceSurface, and only use it if they match. This
|
|
|
|
* can avoid expensive and unnecessary readbacks.
|
|
|
|
*/
|
|
|
|
struct SourceSurfaceUserData
|
2011-06-24 21:41:18 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface> mSrcSurface;
|
2012-10-08 06:44:36 +04:00
|
|
|
BackendType mBackendType;
|
|
|
|
};
|
|
|
|
|
|
|
|
void SourceBufferDestroy(void *srcSurfUD)
|
|
|
|
{
|
|
|
|
delete static_cast<SourceSurfaceUserData*>(srcSurfUD);
|
2011-06-24 21:41:18 +04:00
|
|
|
}
|
|
|
|
|
2014-03-05 07:04:05 +04:00
|
|
|
UserDataKey kThebesSurface;
|
|
|
|
|
|
|
|
struct DependentSourceSurfaceUserData
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxASurface> mSurface;
|
2014-03-05 07:04:05 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void SourceSurfaceDestroyed(void *aData)
|
|
|
|
{
|
|
|
|
delete static_cast<DependentSourceSurfaceUserData*>(aData);
|
|
|
|
}
|
|
|
|
|
2013-07-12 06:44:29 +04:00
|
|
|
void
|
|
|
|
gfxPlatform::ClearSourceSurfaceForSurface(gfxASurface *aSurface)
|
|
|
|
{
|
|
|
|
aSurface->SetData(&kSourceSurface, nullptr, nullptr);
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
/* static */ already_AddRefed<SourceSurface>
|
2016-08-05 20:29:12 +03:00
|
|
|
gfxPlatform::GetSourceSurfaceForSurface(DrawTarget *aTarget,
|
|
|
|
gfxASurface *aSurface,
|
|
|
|
bool aIsPlugin)
|
2011-06-24 21:41:18 +04:00
|
|
|
{
|
2013-10-24 18:35:29 +04:00
|
|
|
if (!aSurface->CairoSurface() || aSurface->CairoStatus()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-12-12 01:05:26 +04:00
|
|
|
if (!aTarget) {
|
2014-06-17 13:08:23 +04:00
|
|
|
aTarget = gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget();
|
2013-12-12 01:05:26 +04:00
|
|
|
}
|
|
|
|
|
2011-06-24 21:41:18 +04:00
|
|
|
void *userData = aSurface->GetData(&kSourceSurface);
|
|
|
|
|
|
|
|
if (userData) {
|
2012-10-08 06:44:36 +04:00
|
|
|
SourceSurfaceUserData *surf = static_cast<SourceSurfaceUserData*>(userData);
|
2012-07-28 04:33:08 +04:00
|
|
|
|
2014-06-20 00:35:33 +04:00
|
|
|
if (surf->mSrcSurface->IsValid() && surf->mBackendType == aTarget->GetBackendType()) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface> srcSurface(surf->mSrcSurface);
|
2015-05-01 16:14:16 +03:00
|
|
|
return srcSurface.forget();
|
2012-07-28 04:33:08 +04:00
|
|
|
}
|
|
|
|
// We can just continue here as when setting new user data the destroy
|
|
|
|
// function will be called for the old user data.
|
2011-06-24 21:41:18 +04:00
|
|
|
}
|
|
|
|
|
2015-07-07 05:11:38 +03:00
|
|
|
SurfaceFormat format = aSurface->GetSurfaceFormat();
|
2011-06-24 21:41:18 +04:00
|
|
|
|
2014-06-20 00:35:33 +04:00
|
|
|
if (aTarget->GetBackendType() == BackendType::CAIRO) {
|
2014-06-17 13:08:23 +04:00
|
|
|
// If we're going to be used with a CAIRO DrawTarget, then just create a
|
|
|
|
// SourceSurfaceCairo since we don't know the underlying type of the CAIRO
|
|
|
|
// DrawTarget and can't pick a better surface type. Doing this also avoids
|
|
|
|
// readback of aSurface's surface into memory if, for example, aSurface
|
|
|
|
// wraps an xlib cairo surface (which can be important to avoid a major
|
|
|
|
// slowdown).
|
2016-01-20 21:31:44 +03:00
|
|
|
//
|
2014-06-17 13:08:23 +04:00
|
|
|
// We return here regardless of whether CreateSourceSurfaceFromNativeSurface
|
|
|
|
// succeeds or not since we don't expect to be able to do any better below
|
|
|
|
// if it fails.
|
|
|
|
//
|
|
|
|
// Note that the returned SourceSurfaceCairo holds a strong reference to
|
|
|
|
// the cairo_surface_t* that it wraps, which essencially means it holds a
|
|
|
|
// strong reference to aSurface since aSurface shares its
|
|
|
|
// cairo_surface_t*'s reference count variable. As a result we can't cache
|
|
|
|
// srcBuffer on aSurface (see below) since aSurface would then hold a
|
|
|
|
// strong reference back to srcBuffer, creating a reference loop and a
|
|
|
|
// memory leak. Not caching is fine since wrapping is cheap enough (no
|
|
|
|
// copying) so we can just wrap again next time we're called.
|
2016-01-20 21:31:44 +03:00
|
|
|
return Factory::CreateSourceSurfaceForCairoSurface(aSurface->CairoSurface(),
|
|
|
|
aSurface->GetSize(), format);
|
2014-06-17 13:08:23 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface> srcBuffer;
|
2011-06-24 21:41:18 +04:00
|
|
|
|
2014-06-17 13:08:23 +04:00
|
|
|
// Currently no other DrawTarget types implement CreateSourceSurfaceFromNativeSurface
|
|
|
|
|
|
|
|
if (!srcBuffer) {
|
|
|
|
// If aSurface wraps data, we can create a SourceSurfaceRawData that wraps
|
|
|
|
// the same data, then optimize it for aTarget:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DataSourceSurface> surf = GetWrappedDataSourceSurface(aSurface);
|
2014-06-17 13:08:23 +04:00
|
|
|
if (surf) {
|
2016-08-05 20:29:12 +03:00
|
|
|
srcBuffer = aIsPlugin ? aTarget->OptimizeSourceSurfaceForUnknownAlpha(surf)
|
|
|
|
: aTarget->OptimizeSourceSurface(surf);
|
|
|
|
|
2014-06-17 13:08:23 +04:00
|
|
|
if (srcBuffer == surf) {
|
|
|
|
// GetWrappedDataSourceSurface returns a SourceSurface that holds a
|
|
|
|
// strong reference to aSurface since it wraps aSurface's data and
|
|
|
|
// needs it to stay alive. As a result we can't cache srcBuffer on
|
|
|
|
// aSurface (below) since aSurface would then hold a strong reference
|
|
|
|
// back to srcBuffer, creating a reference loop and a memory leak. Not
|
|
|
|
// caching is fine since wrapping is cheap enough (no copying) so we
|
|
|
|
// can just wrap again next time we're called.
|
|
|
|
//
|
|
|
|
// Note that the check below doesn't catch this since srcBuffer will be a
|
|
|
|
// SourceSurfaceRawData object (even if aSurface is not a gfxImageSurface
|
|
|
|
// object), which is why we need this separate check.
|
|
|
|
return srcBuffer.forget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!srcBuffer) {
|
2014-06-20 00:35:33 +04:00
|
|
|
MOZ_ASSERT(aTarget->GetBackendType() != BackendType::CAIRO,
|
2014-06-17 13:08:23 +04:00
|
|
|
"We already tried CreateSourceSurfaceFromNativeSurface with a "
|
|
|
|
"DrawTargetCairo above");
|
|
|
|
// We've run out of performant options. We now try creating a SourceSurface
|
|
|
|
// using a temporary DrawTargetCairo and then optimizing it to aTarget's
|
|
|
|
// actual type. The CreateSourceSurfaceFromNativeSurface() call will
|
|
|
|
// likely create a DataSourceSurface (possibly involving copying and/or
|
|
|
|
// readback), and the OptimizeSourceSurface may well copy again and upload
|
|
|
|
// to the GPU. So, while this code path is rarely hit, hitting it may be
|
|
|
|
// very slow.
|
2016-01-20 21:31:44 +03:00
|
|
|
srcBuffer = Factory::CreateSourceSurfaceForCairoSurface(aSurface->CairoSurface(),
|
|
|
|
aSurface->GetSize(), format);
|
2012-09-03 03:07:05 +04:00
|
|
|
if (srcBuffer) {
|
2014-06-17 13:08:23 +04:00
|
|
|
srcBuffer = aTarget->OptimizeSourceSurface(srcBuffer);
|
2012-09-03 03:07:05 +04:00
|
|
|
}
|
|
|
|
}
|
2011-06-24 21:41:18 +04:00
|
|
|
|
|
|
|
if (!srcBuffer) {
|
2014-06-17 13:08:23 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
2012-05-21 19:27:32 +04:00
|
|
|
|
2014-06-17 13:08:23 +04:00
|
|
|
if ((srcBuffer->GetType() == SurfaceType::CAIRO &&
|
|
|
|
static_cast<SourceSurfaceCairo*>(srcBuffer.get())->GetSurface() ==
|
|
|
|
aSurface->CairoSurface()) ||
|
|
|
|
(srcBuffer->GetType() == SurfaceType::CAIRO_IMAGE &&
|
|
|
|
static_cast<DataSourceSurfaceCairo*>(srcBuffer.get())->GetSurface() ==
|
|
|
|
aSurface->CairoSurface())) {
|
|
|
|
// See the "Note that the returned SourceSurfaceCairo..." comment above.
|
|
|
|
return srcBuffer.forget();
|
2011-06-24 21:41:18 +04:00
|
|
|
}
|
|
|
|
|
2014-04-15 06:36:26 +04:00
|
|
|
// Add user data to aSurface so we can cache lookups in the future.
|
|
|
|
SourceSurfaceUserData *srcSurfUD = new SourceSurfaceUserData;
|
2014-06-20 00:35:33 +04:00
|
|
|
srcSurfUD->mBackendType = aTarget->GetBackendType();
|
2014-04-15 06:36:26 +04:00
|
|
|
srcSurfUD->mSrcSurface = srcBuffer;
|
|
|
|
aSurface->SetData(&kSourceSurface, srcSurfUD, SourceBufferDestroy);
|
2011-06-24 21:41:18 +04:00
|
|
|
|
2014-06-12 23:24:05 +04:00
|
|
|
return srcBuffer.forget();
|
2011-06-24 21:41:18 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<DataSourceSurface>
|
2014-04-15 06:36:26 +04:00
|
|
|
gfxPlatform::GetWrappedDataSourceSurface(gfxASurface* aSurface)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxImageSurface> image = aSurface->GetAsImageSurface();
|
2014-04-15 06:36:26 +04:00
|
|
|
if (!image) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DataSourceSurface> result =
|
2014-04-15 06:36:26 +04:00
|
|
|
Factory::CreateWrappingDataSourceSurface(image->Data(),
|
|
|
|
image->Stride(),
|
2015-04-07 17:08:57 +03:00
|
|
|
image->GetSize(),
|
2014-04-15 06:36:26 +04:00
|
|
|
ImageFormatToSurfaceFormat(image->Format()));
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we wrapped the underlying data of aSurface, then we need to add user data
|
|
|
|
// to make sure aSurface stays alive until we are done with the data.
|
|
|
|
DependentSourceSurfaceUserData *srcSurfUD = new DependentSourceSurfaceUserData;
|
|
|
|
srcSurfUD->mSurface = aSurface;
|
|
|
|
result->AddUserData(&kThebesSurface, srcSurfUD, SourceSurfaceDestroyed);
|
|
|
|
|
2014-06-12 23:24:05 +04:00
|
|
|
return result.forget();
|
2014-04-15 06:36:26 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<ScaledFont>
|
2012-07-24 14:18:37 +04:00
|
|
|
gfxPlatform::GetScaledFontForFont(DrawTarget* aTarget, gfxFont *aFont)
|
2011-06-24 21:41:18 +04:00
|
|
|
{
|
2012-01-10 22:26:59 +04:00
|
|
|
NativeFont nativeFont;
|
2014-01-10 23:06:16 +04:00
|
|
|
nativeFont.mType = NativeFontType::CAIRO_FONT_FACE;
|
2012-07-24 14:18:39 +04:00
|
|
|
nativeFont.mFont = aFont->GetCairoScaledFont();
|
2015-05-01 16:14:16 +03:00
|
|
|
return Factory::CreateScaledFontForNativeFont(nativeFont,
|
|
|
|
aFont->GetAdjustedSize());
|
2011-06-24 21:41:18 +04:00
|
|
|
}
|
|
|
|
|
2014-11-13 01:55:13 +03:00
|
|
|
void
|
|
|
|
gfxPlatform::ComputeTileSize()
|
|
|
|
{
|
|
|
|
// The tile size should be picked in the parent processes
|
|
|
|
// and sent to the child processes over IPDL GetTileSize.
|
2015-07-04 04:29:00 +03:00
|
|
|
if (!XRE_IsParentProcess()) {
|
2015-08-07 22:37:56 +03:00
|
|
|
return;
|
2014-11-13 01:55:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t w = gfxPrefs::LayersTileWidth();
|
|
|
|
int32_t h = gfxPrefs::LayersTileHeight();
|
|
|
|
|
|
|
|
if (gfxPrefs::LayersTilesAdjust()) {
|
2015-08-27 01:33:16 +03:00
|
|
|
gfx::IntSize screenSize = GetScreenSize();
|
|
|
|
if (screenSize.width > 0) {
|
2015-12-09 00:42:43 +03:00
|
|
|
// Choose a size so that there are between 2 and 4 tiles per screen width.
|
|
|
|
// FIXME: we should probably make sure this is within the max texture size,
|
|
|
|
// but I think everything should at least support 1024
|
2016-07-22 11:47:44 +03:00
|
|
|
w = h = clamped(int32_t(RoundUpPow2(screenSize.width)) / 4, 256, 1024);
|
2015-08-27 01:33:16 +03:00
|
|
|
}
|
|
|
|
|
2014-11-13 01:55:13 +03:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
android::sp<android::GraphicBuffer> alloc =
|
2015-08-27 01:33:16 +03:00
|
|
|
new android::GraphicBuffer(w, h, android::PIXEL_FORMAT_RGBA_8888,
|
|
|
|
android::GraphicBuffer::USAGE_SW_READ_OFTEN |
|
|
|
|
android::GraphicBuffer::USAGE_SW_WRITE_OFTEN |
|
|
|
|
android::GraphicBuffer::USAGE_HW_TEXTURE);
|
2014-11-13 01:55:13 +03:00
|
|
|
|
|
|
|
if (alloc.get()) {
|
|
|
|
w = alloc->getStride(); // We want the tiles to be gralloc stride aligned.
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-08-04 21:33:43 +03:00
|
|
|
// Don't allow changing the tile size after we've set it.
|
|
|
|
// Right now the code assumes that the tile size doesn't change.
|
|
|
|
MOZ_ASSERT(gfxVars::TileSize().width == -1 &&
|
|
|
|
gfxVars::TileSize().height == -1);
|
|
|
|
|
|
|
|
gfxVars::SetTileSize(IntSize(w, h));
|
2015-08-27 01:37:48 +03:00
|
|
|
}
|
|
|
|
|
2015-08-27 01:37:48 +03:00
|
|
|
void
|
|
|
|
gfxPlatform::PopulateScreenInfo()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIScreenManager> manager = do_GetService("@mozilla.org/gfx/screenmanager;1");
|
|
|
|
MOZ_ASSERT(manager, "failed to get nsIScreenManager");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScreen> screen;
|
|
|
|
manager->GetPrimaryScreen(getter_AddRefs(screen));
|
2015-08-27 01:33:16 +03:00
|
|
|
if (!screen) {
|
|
|
|
// This can happen in xpcshell, for instance
|
|
|
|
return;
|
|
|
|
}
|
2015-08-27 01:37:48 +03:00
|
|
|
|
|
|
|
screen->GetColorDepth(&mScreenDepth);
|
|
|
|
|
|
|
|
int left, top;
|
|
|
|
screen->GetRect(&left, &top, &mScreenSize.width, &mScreenSize.height);
|
|
|
|
}
|
|
|
|
|
2013-05-28 02:04:37 +04:00
|
|
|
bool
|
|
|
|
gfxPlatform::SupportsAzureContentForDrawTarget(DrawTarget* aTarget)
|
|
|
|
{
|
2016-06-07 04:17:48 +03:00
|
|
|
if (!aTarget || !aTarget->IsValid()) {
|
2013-05-28 02:04:37 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-02 20:11:52 +03:00
|
|
|
#ifdef USE_SKIA_GPU
|
|
|
|
// Skia content rendering doesn't support GPU acceleration, so we can't
|
|
|
|
// use the same backend if the current backend is accelerated.
|
|
|
|
if ((aTarget->GetType() == DrawTargetType::HARDWARE_RASTER)
|
|
|
|
&& (aTarget->GetBackendType() == BackendType::SKIA))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-06-20 00:35:33 +04:00
|
|
|
return SupportsAzureContentForType(aTarget->GetBackendType());
|
2013-05-28 02:04:37 +04:00
|
|
|
}
|
|
|
|
|
2016-09-30 20:54:22 +03:00
|
|
|
bool gfxPlatform::AllowOpenGLCanvas()
|
2016-02-24 21:02:00 +03:00
|
|
|
{
|
2016-09-30 20:54:22 +03:00
|
|
|
// For now, only allow Skia+OpenGL, unless it's blocked.
|
2016-02-22 16:23:00 +03:00
|
|
|
// Allow acceleration on Skia if the preference is set, unless it's blocked
|
2016-09-30 20:54:22 +03:00
|
|
|
// as long as we have the accelerated layers
|
|
|
|
if (gfxPrefs::CanvasAzureAccelerated() &&
|
|
|
|
mCompositorBackend == LayersBackend::LAYERS_OPENGL &&
|
|
|
|
(GetContentBackendFor(mCompositorBackend) == BackendType::SKIA))
|
|
|
|
{
|
2016-02-22 16:23:00 +03:00
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
|
|
|
|
int32_t status;
|
2016-04-14 00:12:47 +03:00
|
|
|
nsCString discardFailureId;
|
2016-02-22 16:23:00 +03:00
|
|
|
return !gfxInfo ||
|
|
|
|
(NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_CANVAS2D_ACCELERATION,
|
2016-04-14 00:12:47 +03:00
|
|
|
discardFailureId,
|
2016-02-22 16:23:00 +03:00
|
|
|
&status)) &&
|
|
|
|
status == nsIGfxInfo::FEATURE_STATUS_OK);
|
|
|
|
}
|
|
|
|
return false;
|
2014-09-11 00:15:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-21 03:23:52 +04:00
|
|
|
void
|
2014-03-06 01:49:37 +04:00
|
|
|
gfxPlatform::InitializeSkiaCacheLimits()
|
2013-10-22 23:15:24 +04:00
|
|
|
{
|
2016-09-30 20:54:22 +03:00
|
|
|
if (AllowOpenGLCanvas()) {
|
2015-02-25 11:20:00 +03:00
|
|
|
#ifdef USE_SKIA_GPU
|
2014-02-27 06:53:32 +04:00
|
|
|
bool usingDynamicCache = gfxPrefs::CanvasSkiaGLDynamicCache();
|
|
|
|
int cacheItemLimit = gfxPrefs::CanvasSkiaGLCacheItems();
|
2016-09-23 18:40:25 +03:00
|
|
|
uint64_t cacheSizeLimit = std::max(gfxPrefs::CanvasSkiaGLCacheSize(), (int32_t)0);
|
2013-10-22 23:15:24 +04:00
|
|
|
|
2014-02-21 03:23:52 +04:00
|
|
|
// Prefs are in megabytes, but we want the sizes in bytes
|
|
|
|
cacheSizeLimit *= 1024*1024;
|
2013-10-22 23:15:24 +04:00
|
|
|
|
2014-02-21 03:23:52 +04:00
|
|
|
if (usingDynamicCache) {
|
2014-09-12 03:52:42 +04:00
|
|
|
if (mTotalSystemMemory < 512*1024*1024) {
|
2014-07-29 19:58:40 +04:00
|
|
|
// We need a very minimal cache on anything smaller than 512mb.
|
|
|
|
// Note the large jump as we cross 512mb (from 2mb to 32mb).
|
2014-02-21 03:23:52 +04:00
|
|
|
cacheSizeLimit = 2*1024*1024;
|
2014-09-12 03:52:42 +04:00
|
|
|
} else if (mTotalSystemMemory > 0) {
|
|
|
|
cacheSizeLimit = mTotalSystemMemory / 16;
|
2014-02-21 03:23:52 +04:00
|
|
|
}
|
2013-10-22 23:15:24 +04:00
|
|
|
}
|
|
|
|
|
2016-09-23 18:40:25 +03:00
|
|
|
// Ensure cache size doesn't overflow on 32-bit platforms.
|
|
|
|
cacheSizeLimit = std::min(cacheSizeLimit, (uint64_t)SIZE_MAX);
|
|
|
|
|
2014-03-06 01:49:37 +04:00
|
|
|
#ifdef DEBUG
|
2016-09-23 18:40:25 +03:00
|
|
|
printf_stderr("Determined SkiaGL cache limits: Size %" PRIu64 ", Items: %i\n", cacheSizeLimit, cacheItemLimit);
|
2014-03-06 01:49:37 +04:00
|
|
|
#endif
|
2013-10-22 23:15:24 +04:00
|
|
|
|
2016-09-23 18:40:25 +03:00
|
|
|
mSkiaGlue->GetGrContext()->setResourceCacheLimits(cacheItemLimit, (size_t)cacheSizeLimit);
|
2014-04-15 23:07:42 +04:00
|
|
|
#endif
|
2014-02-15 01:55:58 +04:00
|
|
|
}
|
2014-03-06 01:49:37 +04:00
|
|
|
}
|
|
|
|
|
2015-07-29 23:35:55 +03:00
|
|
|
SkiaGLGlue*
|
2014-03-06 01:49:37 +04:00
|
|
|
gfxPlatform::GetSkiaGLGlue()
|
|
|
|
{
|
|
|
|
#ifdef USE_SKIA_GPU
|
2016-03-16 07:09:17 +03:00
|
|
|
// Check the accelerated Canvas is enabled for the first time,
|
|
|
|
// because the callers should check it before using.
|
2016-09-30 20:54:22 +03:00
|
|
|
if (!mSkiaGlue && !AllowOpenGLCanvas()) {
|
2015-11-26 13:00:00 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-03-06 01:49:37 +04:00
|
|
|
if (!mSkiaGlue) {
|
|
|
|
/* Dummy context. We always draw into a FBO.
|
|
|
|
*
|
|
|
|
* FIXME: This should be stored in TLS or something, since there needs to be one for each thread using it. As it
|
|
|
|
* stands, this only works on the main thread.
|
|
|
|
*/
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GLContext> glContext;
|
2016-06-06 23:52:42 +03:00
|
|
|
nsCString discardFailureId;
|
2015-07-29 23:35:55 +03:00
|
|
|
glContext = GLContextProvider::CreateHeadless(CreateContextFlags::REQUIRE_COMPAT_PROFILE |
|
2016-06-06 23:52:42 +03:00
|
|
|
CreateContextFlags::ALLOW_OFFLINE_RENDERER,
|
2016-06-11 05:01:00 +03:00
|
|
|
&discardFailureId);
|
2014-03-06 01:49:37 +04:00
|
|
|
if (!glContext) {
|
|
|
|
printf_stderr("Failed to create GLContext for SkiaGL!\n");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-07-29 23:35:55 +03:00
|
|
|
mSkiaGlue = new SkiaGLGlue(glContext);
|
2014-03-06 01:49:37 +04:00
|
|
|
MOZ_ASSERT(mSkiaGlue->GetGrContext(), "No GrContext");
|
|
|
|
InitializeSkiaCacheLimits();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return mSkiaGlue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-03-23 21:17:02 +03:00
|
|
|
gfxPlatform::PurgeSkiaFontCache()
|
|
|
|
{
|
|
|
|
#ifdef USE_SKIA
|
|
|
|
if (gfxPlatform::GetPlatform()->GetDefaultContentBackend() == BackendType::SKIA) {
|
|
|
|
SkGraphics::PurgeFontCache();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatform::PurgeSkiaGPUCache()
|
2014-03-06 01:49:37 +04:00
|
|
|
{
|
|
|
|
#ifdef USE_SKIA_GPU
|
|
|
|
if (!mSkiaGlue)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mSkiaGlue->GetGrContext()->freeGpuResources();
|
2014-09-03 05:49:06 +04:00
|
|
|
// GrContext::flush() doesn't call glFlush. Call it here.
|
|
|
|
mSkiaGlue->GetGLContext()->MakeCurrent();
|
|
|
|
mSkiaGlue->GetGLContext()->fFlush();
|
2014-02-15 01:55:58 +04:00
|
|
|
#endif
|
2014-02-15 03:48:05 +04:00
|
|
|
}
|
2014-02-15 01:55:58 +04:00
|
|
|
|
2014-09-12 03:52:42 +04:00
|
|
|
bool
|
|
|
|
gfxPlatform::HasEnoughTotalSystemMemoryForSkiaGL()
|
|
|
|
{
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
if (mTotalSystemMemory < 250*1024*1024) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<DrawTarget>
|
2012-07-25 04:45:58 +04:00
|
|
|
gfxPlatform::CreateDrawTargetForBackend(BackendType aBackend, const IntSize& aSize, SurfaceFormat aFormat)
|
2011-11-02 23:55:03 +04:00
|
|
|
{
|
2012-01-27 22:09:20 +04:00
|
|
|
// There is a bunch of knowledge in the gfxPlatform heirarchy about how to
|
|
|
|
// create the best offscreen surface for the current system and situation. We
|
|
|
|
// can easily take advantage of this for the Cairo backend, so that's what we
|
|
|
|
// do.
|
|
|
|
// mozilla::gfx::Factory can get away without having all this knowledge for
|
|
|
|
// now, but this might need to change in the future (using
|
|
|
|
// CreateOffscreenSurface() and CreateDrawTargetForSurface() for all
|
|
|
|
// backends).
|
2014-01-10 23:06:16 +04:00
|
|
|
if (aBackend == BackendType::CAIRO) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxASurface> surf = CreateOffscreenSurface(aSize, SurfaceFormatToImageFormat(aFormat));
|
2012-07-31 11:57:28 +04:00
|
|
|
if (!surf || surf->CairoStatus()) {
|
2013-07-31 19:44:31 +04:00
|
|
|
return nullptr;
|
2012-07-24 14:18:38 +04:00
|
|
|
}
|
2012-01-27 22:09:20 +04:00
|
|
|
|
2012-07-24 14:18:38 +04:00
|
|
|
return CreateDrawTargetForSurface(surf, aSize);
|
2012-01-27 22:09:20 +04:00
|
|
|
} else {
|
2012-07-25 04:45:58 +04:00
|
|
|
return Factory::CreateDrawTarget(aBackend, aSize, aFormat);
|
2012-01-27 22:09:20 +04:00
|
|
|
}
|
2011-06-24 21:41:18 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<DrawTarget>
|
2013-08-23 10:13:55 +04:00
|
|
|
gfxPlatform::CreateOffscreenCanvasDrawTarget(const IntSize& aSize, SurfaceFormat aFormat)
|
2012-07-25 04:45:58 +04:00
|
|
|
{
|
2014-01-10 23:06:16 +04:00
|
|
|
NS_ASSERTION(mPreferredCanvasBackend != BackendType::NONE, "No backend.");
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DrawTarget> target = CreateDrawTargetForBackend(mPreferredCanvasBackend, aSize, aFormat);
|
2012-07-25 04:45:58 +04:00
|
|
|
if (target ||
|
2014-01-10 23:06:16 +04:00
|
|
|
mFallbackCanvasBackend == BackendType::NONE) {
|
2014-06-12 23:24:05 +04:00
|
|
|
return target.forget();
|
2012-07-25 04:45:58 +04:00
|
|
|
}
|
|
|
|
|
2015-03-12 21:40:06 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// On Windows, the fallback backend (Cairo) should use its image backend.
|
|
|
|
return Factory::CreateDrawTarget(mFallbackCanvasBackend, aSize, aFormat);
|
|
|
|
#else
|
2012-07-25 04:45:58 +04:00
|
|
|
return CreateDrawTargetForBackend(mFallbackCanvasBackend, aSize, aFormat);
|
2015-03-12 21:40:06 +03:00
|
|
|
#endif
|
2012-07-25 04:45:58 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<DrawTarget>
|
2013-08-23 10:13:55 +04:00
|
|
|
gfxPlatform::CreateOffscreenContentDrawTarget(const IntSize& aSize, SurfaceFormat aFormat)
|
|
|
|
{
|
2014-01-10 23:06:16 +04:00
|
|
|
NS_ASSERTION(mPreferredCanvasBackend != BackendType::NONE, "No backend.");
|
2013-08-23 10:13:55 +04:00
|
|
|
return CreateDrawTargetForBackend(mContentBackend, aSize, aFormat);
|
|
|
|
}
|
2012-07-25 04:45:58 +04:00
|
|
|
|
2016-07-29 01:32:00 +03:00
|
|
|
already_AddRefed<DrawTarget>
|
|
|
|
gfxPlatform::CreateSimilarSoftwareDrawTarget(DrawTarget* aDT,
|
|
|
|
const IntSize& aSize,
|
|
|
|
SurfaceFormat aFormat)
|
|
|
|
{
|
|
|
|
RefPtr<DrawTarget> dt;
|
|
|
|
|
|
|
|
if (Factory::DoesBackendSupportDataDrawtarget(aDT->GetBackendType())) {
|
|
|
|
dt = aDT->CreateSimilarDrawTarget(aSize, aFormat);
|
|
|
|
} else {
|
|
|
|
dt = Factory::CreateDrawTarget(BackendType::SKIA, aSize, aFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dt.forget();
|
|
|
|
}
|
|
|
|
|
2016-08-12 00:54:08 +03:00
|
|
|
/* static */ already_AddRefed<DrawTarget>
|
2012-04-02 23:15:08 +04:00
|
|
|
gfxPlatform::CreateDrawTargetForData(unsigned char* aData, const IntSize& aSize, int32_t aStride, SurfaceFormat aFormat)
|
|
|
|
{
|
2016-08-12 00:54:08 +03:00
|
|
|
BackendType backendType = gfxVars::ContentBackend();
|
|
|
|
NS_ASSERTION(backendType != BackendType::NONE, "No backend.");
|
2015-07-31 22:11:48 +03:00
|
|
|
|
2016-08-12 00:54:08 +03:00
|
|
|
if (!Factory::DoesBackendSupportDataDrawtarget(backendType)) {
|
2015-01-08 05:34:07 +03:00
|
|
|
backendType = BackendType::CAIRO;
|
|
|
|
}
|
2015-01-08 00:58:25 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DrawTarget> dt = Factory::CreateDrawTargetForData(backendType,
|
2014-06-26 11:40:12 +04:00
|
|
|
aData, aSize,
|
|
|
|
aStride, aFormat);
|
2015-01-08 00:58:25 +03:00
|
|
|
|
2014-06-26 11:40:12 +04:00
|
|
|
return dt.forget();
|
2012-04-02 23:15:08 +04:00
|
|
|
}
|
|
|
|
|
2012-07-25 04:45:58 +04:00
|
|
|
/* static */ BackendType
|
|
|
|
gfxPlatform::BackendTypeForName(const nsCString& aName)
|
|
|
|
{
|
|
|
|
if (aName.EqualsLiteral("cairo"))
|
2014-01-10 23:06:16 +04:00
|
|
|
return BackendType::CAIRO;
|
2012-07-25 04:45:58 +04:00
|
|
|
if (aName.EqualsLiteral("skia"))
|
2014-01-10 23:06:16 +04:00
|
|
|
return BackendType::SKIA;
|
2012-07-25 04:45:58 +04:00
|
|
|
if (aName.EqualsLiteral("direct2d"))
|
2014-01-10 23:06:16 +04:00
|
|
|
return BackendType::DIRECT2D;
|
2014-09-15 01:51:27 +04:00
|
|
|
if (aName.EqualsLiteral("direct2d1.1"))
|
|
|
|
return BackendType::DIRECT2D1_1;
|
2014-01-10 23:06:16 +04:00
|
|
|
return BackendType::NONE;
|
2012-07-25 04:45:58 +04:00
|
|
|
}
|
|
|
|
|
2006-01-10 23:26:40 +03:00
|
|
|
nsresult
|
2010-02-24 20:57:57 +03:00
|
|
|
gfxPlatform::GetFontList(nsIAtom *aLangGroup,
|
2006-01-10 23:26:40 +03:00
|
|
|
const nsACString& aGenericFamily,
|
2009-01-18 23:14:14 +03:00
|
|
|
nsTArray<nsString>& aListOfFonts)
|
2006-01-10 23:26:40 +03:00
|
|
|
{
|
2016-03-18 15:43:38 +03:00
|
|
|
gfxPlatformFontList::PlatformFontList()->GetFontList(aLangGroup,
|
|
|
|
aGenericFamily,
|
|
|
|
aListOfFonts);
|
|
|
|
return NS_OK;
|
2006-01-10 23:26:40 +03:00
|
|
|
}
|
2006-06-15 08:47:23 +04:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxPlatform::UpdateFontList()
|
|
|
|
{
|
2016-03-18 15:43:38 +03:00
|
|
|
gfxPlatformFontList::PlatformFontList()->UpdateFontList();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxPlatform::GetStandardFamilyName(const nsAString& aFontName,
|
|
|
|
nsAString& aFamilyName)
|
|
|
|
{
|
|
|
|
gfxPlatformFontList::PlatformFontList()->GetStandardFamilyName(aFontName,
|
|
|
|
aFamilyName);
|
|
|
|
return NS_OK;
|
2006-06-15 08:47:23 +04:00
|
|
|
}
|
2006-09-26 08:20:41 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-10-01 07:01:53 +04:00
|
|
|
gfxPlatform::DownloadableFontsEnabled()
|
|
|
|
{
|
2010-05-27 09:05:30 +04:00
|
|
|
if (mAllowDownloadableFonts == UNINITIALIZED_VALUE) {
|
2010-10-07 11:59:19 +04:00
|
|
|
mAllowDownloadableFonts =
|
2011-09-29 10:19:26 +04:00
|
|
|
Preferences::GetBool(GFX_DOWNLOADABLE_FONTS_ENABLED, false);
|
2008-10-01 07:01:53 +04:00
|
|
|
}
|
|
|
|
|
2010-05-27 09:05:30 +04:00
|
|
|
return mAllowDownloadableFonts;
|
2008-10-01 07:01:53 +04:00
|
|
|
}
|
|
|
|
|
2012-03-09 06:05:40 +04:00
|
|
|
bool
|
|
|
|
gfxPlatform::UseCmapsDuringSystemFallback()
|
|
|
|
{
|
|
|
|
if (mFallbackUsesCmaps == UNINITIALIZED_VALUE) {
|
|
|
|
mFallbackUsesCmaps =
|
|
|
|
Preferences::GetBool(GFX_PREF_FALLBACK_USE_CMAPS, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mFallbackUsesCmaps;
|
|
|
|
}
|
|
|
|
|
2013-05-16 20:32:41 +04:00
|
|
|
bool
|
|
|
|
gfxPlatform::OpenTypeSVGEnabled()
|
|
|
|
{
|
|
|
|
if (mOpenTypeSVGEnabled == UNINITIALIZED_VALUE) {
|
|
|
|
mOpenTypeSVGEnabled =
|
|
|
|
Preferences::GetBool(GFX_PREF_OPENTYPE_SVG, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mOpenTypeSVGEnabled > 0;
|
|
|
|
}
|
|
|
|
|
2013-09-11 05:36:57 +04:00
|
|
|
uint32_t
|
|
|
|
gfxPlatform::WordCacheCharLimit()
|
|
|
|
{
|
|
|
|
if (mWordCacheCharLimit == UNINITIALIZED_VALUE) {
|
|
|
|
mWordCacheCharLimit =
|
|
|
|
Preferences::GetInt(GFX_PREF_WORD_CACHE_CHARLIMIT, 32);
|
|
|
|
if (mWordCacheCharLimit < 0) {
|
|
|
|
mWordCacheCharLimit = 32;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return uint32_t(mWordCacheCharLimit);
|
|
|
|
}
|
|
|
|
|
2013-09-11 05:36:57 +04:00
|
|
|
uint32_t
|
|
|
|
gfxPlatform::WordCacheMaxEntries()
|
|
|
|
{
|
|
|
|
if (mWordCacheMaxEntries == UNINITIALIZED_VALUE) {
|
|
|
|
mWordCacheMaxEntries =
|
|
|
|
Preferences::GetInt(GFX_PREF_WORD_CACHE_MAXENTRIES, 10000);
|
|
|
|
if (mWordCacheMaxEntries < 0) {
|
|
|
|
mWordCacheMaxEntries = 10000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return uint32_t(mWordCacheMaxEntries);
|
|
|
|
}
|
|
|
|
|
2011-12-10 02:32:29 +04:00
|
|
|
bool
|
|
|
|
gfxPlatform::UseGraphiteShaping()
|
|
|
|
{
|
|
|
|
if (mGraphiteShapingEnabled == UNINITIALIZED_VALUE) {
|
|
|
|
mGraphiteShapingEnabled =
|
|
|
|
Preferences::GetBool(GFX_PREF_GRAPHITE_SHAPING, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mGraphiteShapingEnabled;
|
|
|
|
}
|
|
|
|
|
2016-03-18 15:43:38 +03:00
|
|
|
gfxFontEntry*
|
|
|
|
gfxPlatform::LookupLocalFont(const nsAString& aFontName,
|
|
|
|
uint16_t aWeight,
|
|
|
|
int16_t aStretch,
|
|
|
|
uint8_t aStyle)
|
|
|
|
{
|
|
|
|
return gfxPlatformFontList::PlatformFontList()->LookupLocalFont(aFontName,
|
|
|
|
aWeight,
|
|
|
|
aStretch,
|
|
|
|
aStyle);
|
|
|
|
}
|
|
|
|
|
2009-08-30 17:55:24 +04:00
|
|
|
gfxFontEntry*
|
2014-09-08 11:23:19 +04:00
|
|
|
gfxPlatform::MakePlatformFont(const nsAString& aFontName,
|
|
|
|
uint16_t aWeight,
|
|
|
|
int16_t aStretch,
|
2015-10-19 05:16:43 +03:00
|
|
|
uint8_t aStyle,
|
2014-09-08 11:23:19 +04:00
|
|
|
const uint8_t* aFontData,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLength)
|
2009-08-30 17:55:24 +04:00
|
|
|
{
|
2016-03-18 15:43:38 +03:00
|
|
|
return gfxPlatformFontList::PlatformFontList()->MakePlatformFont(aFontName,
|
|
|
|
aWeight,
|
|
|
|
aStretch,
|
|
|
|
aStyle,
|
|
|
|
aFontData,
|
|
|
|
aLength);
|
2009-08-30 17:55:24 +04:00
|
|
|
}
|
2008-10-01 07:01:53 +04:00
|
|
|
|
2013-08-03 02:50:17 +04:00
|
|
|
mozilla::layers::DiagnosticTypes
|
|
|
|
gfxPlatform::GetLayerDiagnosticTypes()
|
2013-03-21 21:08:01 +04:00
|
|
|
{
|
2014-04-26 06:34:06 +04:00
|
|
|
mozilla::layers::DiagnosticTypes type = DiagnosticTypes::NO_DIAGNOSTIC;
|
2014-02-27 06:53:31 +04:00
|
|
|
if (gfxPrefs::DrawLayerBorders()) {
|
2014-04-26 06:34:06 +04:00
|
|
|
type |= mozilla::layers::DiagnosticTypes::LAYER_BORDERS;
|
2013-08-03 02:50:17 +04:00
|
|
|
}
|
2014-02-27 06:53:31 +04:00
|
|
|
if (gfxPrefs::DrawTileBorders()) {
|
2014-04-26 06:34:06 +04:00
|
|
|
type |= mozilla::layers::DiagnosticTypes::TILE_BORDERS;
|
2013-08-03 02:50:17 +04:00
|
|
|
}
|
2014-02-27 06:53:31 +04:00
|
|
|
if (gfxPrefs::DrawBigImageBorders()) {
|
2014-04-26 06:34:06 +04:00
|
|
|
type |= mozilla::layers::DiagnosticTypes::BIGIMAGE_BORDERS;
|
2013-08-03 02:50:17 +04:00
|
|
|
}
|
2014-03-25 20:54:39 +04:00
|
|
|
if (gfxPrefs::FlashLayerBorders()) {
|
2014-04-26 06:34:06 +04:00
|
|
|
type |= mozilla::layers::DiagnosticTypes::FLASH_BORDERS;
|
2014-03-25 20:54:39 +04:00
|
|
|
}
|
2013-08-03 02:50:17 +04:00
|
|
|
return type;
|
2013-03-21 21:08:01 +04:00
|
|
|
}
|
|
|
|
|
2012-07-25 04:45:58 +04:00
|
|
|
void
|
2013-11-05 23:54:12 +04:00
|
|
|
gfxPlatform::InitBackendPrefs(uint32_t aCanvasBitmask, BackendType aCanvasDefault,
|
|
|
|
uint32_t aContentBitmask, BackendType aContentDefault)
|
2012-07-25 04:45:58 +04:00
|
|
|
{
|
2012-11-07 06:27:09 +04:00
|
|
|
mPreferredCanvasBackend = GetCanvasBackendPref(aCanvasBitmask);
|
2014-01-10 23:06:16 +04:00
|
|
|
if (mPreferredCanvasBackend == BackendType::NONE) {
|
2013-11-05 23:54:12 +04:00
|
|
|
mPreferredCanvasBackend = aCanvasDefault;
|
2012-10-12 13:42:51 +04:00
|
|
|
}
|
2014-09-15 01:52:41 +04:00
|
|
|
|
|
|
|
if (mPreferredCanvasBackend == BackendType::DIRECT2D1_1) {
|
|
|
|
// Falling back to D2D 1.0 won't help us here. When D2D 1.1 DT creation
|
|
|
|
// fails it means the surface was too big or there's something wrong with
|
|
|
|
// the device. D2D 1.0 will encounter a similar situation.
|
|
|
|
mFallbackCanvasBackend =
|
|
|
|
GetCanvasBackendPref(aCanvasBitmask &
|
|
|
|
~(BackendTypeBit(mPreferredCanvasBackend) | BackendTypeBit(BackendType::DIRECT2D)));
|
|
|
|
} else {
|
|
|
|
mFallbackCanvasBackend =
|
|
|
|
GetCanvasBackendPref(aCanvasBitmask & ~BackendTypeBit(mPreferredCanvasBackend));
|
|
|
|
}
|
2013-08-26 08:13:24 +04:00
|
|
|
|
2013-05-28 02:04:37 +04:00
|
|
|
mContentBackendBitmask = aContentBitmask;
|
2013-08-26 08:13:24 +04:00
|
|
|
mContentBackend = GetContentBackendPref(mContentBackendBitmask);
|
2014-01-10 23:06:16 +04:00
|
|
|
if (mContentBackend == BackendType::NONE) {
|
2013-11-05 23:54:12 +04:00
|
|
|
mContentBackend = aContentDefault;
|
2014-01-12 08:02:18 +04:00
|
|
|
// mContentBackendBitmask is our canonical reference for supported
|
|
|
|
// backends so we need to add the default if we are using it and
|
|
|
|
// overriding the prefs.
|
|
|
|
mContentBackendBitmask |= BackendTypeBit(aContentDefault);
|
2013-11-05 23:54:12 +04:00
|
|
|
}
|
2016-08-04 21:33:44 +03:00
|
|
|
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
gfxVars::SetContentBackend(mContentBackend);
|
|
|
|
}
|
2012-09-17 04:20:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ BackendType
|
2012-11-07 06:27:09 +04:00
|
|
|
gfxPlatform::GetCanvasBackendPref(uint32_t aBackendBitmask)
|
2012-09-17 04:20:16 +04:00
|
|
|
{
|
2013-11-05 23:54:12 +04:00
|
|
|
return GetBackendPref("gfx.canvas.azure.backends", aBackendBitmask);
|
2012-09-17 07:23:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ BackendType
|
2013-08-26 08:13:24 +04:00
|
|
|
gfxPlatform::GetContentBackendPref(uint32_t &aBackendBitmask)
|
2012-09-17 07:23:00 +04:00
|
|
|
{
|
2013-11-05 23:54:12 +04:00
|
|
|
return GetBackendPref("gfx.content.azure.backends", aBackendBitmask);
|
2012-09-17 07:23:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ BackendType
|
2013-11-05 23:54:12 +04:00
|
|
|
gfxPlatform::GetBackendPref(const char* aBackendPrefName, uint32_t &aBackendBitmask)
|
2012-09-17 07:23:00 +04:00
|
|
|
{
|
2012-10-09 13:45:35 +04:00
|
|
|
nsTArray<nsCString> backendList;
|
|
|
|
nsCString prefString;
|
|
|
|
if (NS_SUCCEEDED(Preferences::GetCString(aBackendPrefName, &prefString))) {
|
|
|
|
ParseString(prefString, ',', backendList);
|
2012-07-25 04:45:58 +04:00
|
|
|
}
|
|
|
|
|
2013-08-26 08:13:24 +04:00
|
|
|
uint32_t allowedBackends = 0;
|
2014-01-10 23:06:16 +04:00
|
|
|
BackendType result = BackendType::NONE;
|
2012-10-09 13:45:35 +04:00
|
|
|
for (uint32_t i = 0; i < backendList.Length(); ++i) {
|
2013-08-26 08:13:24 +04:00
|
|
|
BackendType type = BackendTypeForName(backendList[i]);
|
2014-01-10 23:06:16 +04:00
|
|
|
if (BackendTypeBit(type) & aBackendBitmask) {
|
|
|
|
allowedBackends |= BackendTypeBit(type);
|
|
|
|
if (result == BackendType::NONE) {
|
2013-08-26 08:13:24 +04:00
|
|
|
result = type;
|
|
|
|
}
|
2012-07-25 04:45:58 +04:00
|
|
|
}
|
|
|
|
}
|
2013-08-26 08:13:24 +04:00
|
|
|
|
|
|
|
aBackendBitmask = allowedBackends;
|
|
|
|
return result;
|
2012-07-25 04:45:58 +04:00
|
|
|
}
|
|
|
|
|
2015-04-24 22:33:35 +03:00
|
|
|
bool
|
|
|
|
gfxPlatform::InSafeMode()
|
|
|
|
{
|
|
|
|
static bool sSafeModeInitialized = false;
|
|
|
|
static bool sInSafeMode = false;
|
|
|
|
|
|
|
|
if (!sSafeModeInitialized) {
|
|
|
|
sSafeModeInitialized = true;
|
|
|
|
nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
|
|
|
|
if (xr) {
|
|
|
|
xr->GetInSafeMode(&sInSafeMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sInSafeMode;
|
|
|
|
}
|
|
|
|
|
2012-08-26 05:27:28 +04:00
|
|
|
bool
|
|
|
|
gfxPlatform::OffMainThreadCompositingEnabled()
|
|
|
|
{
|
2014-06-06 17:51:24 +04:00
|
|
|
return UsesOffMainThreadCompositing();
|
2012-08-26 05:27:28 +04:00
|
|
|
}
|
|
|
|
|
2013-09-07 07:08:36 +04:00
|
|
|
eCMSMode
|
|
|
|
gfxPlatform::GetCMSMode()
|
|
|
|
{
|
2015-01-14 01:02:34 +03:00
|
|
|
if (!gCMSInitialized) {
|
2014-03-06 01:25:09 +04:00
|
|
|
int32_t mode = gfxPrefs::CMSMode();
|
|
|
|
if (mode >= 0 && mode < eCMSMode_AllCount) {
|
2013-09-07 07:08:36 +04:00
|
|
|
gCMSMode = static_cast<eCMSMode>(mode);
|
|
|
|
}
|
|
|
|
|
2014-03-06 01:25:09 +04:00
|
|
|
bool enableV4 = gfxPrefs::CMSEnableV4();
|
|
|
|
if (enableV4) {
|
2013-09-07 07:08:36 +04:00
|
|
|
qcms_enable_iccv4();
|
|
|
|
}
|
2015-01-14 01:02:34 +03:00
|
|
|
gCMSInitialized = true;
|
2013-09-07 07:08:36 +04:00
|
|
|
}
|
|
|
|
return gCMSMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
gfxPlatform::GetRenderingIntent()
|
|
|
|
{
|
2015-01-14 01:02:34 +03:00
|
|
|
// gfxPrefs.h is using 0 as the default for the rendering
|
|
|
|
// intent preference, based on that being the value for
|
|
|
|
// QCMS_INTENT_DEFAULT. Assert here to catch if that ever
|
|
|
|
// changes and we can then figure out what to do about it.
|
|
|
|
MOZ_ASSERT(QCMS_INTENT_DEFAULT == 0);
|
|
|
|
|
|
|
|
/* Try to query the pref system for a rendering intent. */
|
|
|
|
int32_t pIntent = gfxPrefs::CMSRenderingIntent();
|
|
|
|
if ((pIntent < QCMS_INTENT_MIN) || (pIntent > QCMS_INTENT_MAX)) {
|
|
|
|
/* If the pref is out of range, use embedded profile. */
|
|
|
|
pIntent = -1;
|
|
|
|
}
|
|
|
|
return pIntent;
|
2013-09-07 07:08:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-17 15:53:15 +04:00
|
|
|
gfxPlatform::TransformPixel(const Color& in, Color& out, qcms_transform *transform)
|
2013-09-07 07:08:36 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
if (transform) {
|
|
|
|
/* we want the bytes in RGB order */
|
|
|
|
#ifdef IS_LITTLE_ENDIAN
|
|
|
|
/* ABGR puts the bytes in |RGBA| order on little endian */
|
2014-10-17 15:53:15 +04:00
|
|
|
uint32_t packed = in.ToABGR();
|
2013-09-07 07:08:36 +04:00
|
|
|
qcms_transform_data(transform,
|
|
|
|
(uint8_t *)&packed, (uint8_t *)&packed,
|
|
|
|
1);
|
2014-10-17 15:53:15 +04:00
|
|
|
out = Color::FromABGR(packed);
|
2013-09-07 07:08:36 +04:00
|
|
|
#else
|
|
|
|
/* ARGB puts the bytes in |ARGB| order on big endian */
|
2015-09-25 04:16:50 +03:00
|
|
|
uint32_t packed = in.UnusualToARGB();
|
2013-09-07 07:08:36 +04:00
|
|
|
/* add one to move past the alpha byte */
|
|
|
|
qcms_transform_data(transform,
|
|
|
|
(uint8_t *)&packed + 1, (uint8_t *)&packed + 1,
|
|
|
|
1);
|
2015-09-25 04:16:50 +03:00
|
|
|
out = Color::UnusualFromARGB(packed);
|
2013-09-07 07:08:36 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (&out != &in)
|
|
|
|
out = in;
|
|
|
|
}
|
|
|
|
|
2013-11-07 14:20:08 +04:00
|
|
|
void
|
|
|
|
gfxPlatform::GetPlatformCMSOutputProfile(void *&mem, size_t &size)
|
2013-11-07 14:20:08 +04:00
|
|
|
{
|
2013-11-07 14:20:08 +04:00
|
|
|
mem = nullptr;
|
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatform::GetCMSOutputProfileData(void *&mem, size_t &size)
|
|
|
|
{
|
|
|
|
nsAdoptingCString fname = Preferences::GetCString("gfx.color_management.display_profile");
|
|
|
|
if (!fname.IsEmpty()) {
|
|
|
|
qcms_data_from_path(fname, &mem, &size);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gfxPlatform::GetPlatform()->GetPlatformCMSOutputProfile(mem, size);
|
|
|
|
}
|
2007-07-24 02:02:17 +04:00
|
|
|
}
|
|
|
|
|
2013-09-07 07:08:36 +04:00
|
|
|
void
|
|
|
|
gfxPlatform::CreateCMSOutputProfile()
|
|
|
|
{
|
|
|
|
if (!gCMSOutputProfile) {
|
|
|
|
/* Determine if we're using the internal override to force sRGB as
|
|
|
|
an output profile for reftests. See Bug 452125.
|
|
|
|
|
|
|
|
Note that we don't normally (outside of tests) set a
|
|
|
|
default value of this preference, which means nsIPrefBranch::GetBoolPref
|
|
|
|
will typically throw (and leave its out-param untouched).
|
|
|
|
*/
|
2014-01-09 22:17:29 +04:00
|
|
|
if (Preferences::GetBool(GFX_PREF_CMS_FORCE_SRGB, false)) {
|
2013-09-07 07:08:36 +04:00
|
|
|
gCMSOutputProfile = GetCMSsRGBProfile();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gCMSOutputProfile) {
|
2013-11-07 14:20:08 +04:00
|
|
|
void* mem = nullptr;
|
|
|
|
size_t size = 0;
|
2013-09-07 07:08:36 +04:00
|
|
|
|
2013-11-07 14:20:08 +04:00
|
|
|
GetCMSOutputProfileData(mem, size);
|
|
|
|
if ((mem != nullptr) && (size > 0)) {
|
|
|
|
gCMSOutputProfile = qcms_profile_from_memory(mem, size);
|
|
|
|
free(mem);
|
|
|
|
}
|
2014-01-13 19:25:52 +04:00
|
|
|
}
|
|
|
|
|
2013-09-07 07:08:36 +04:00
|
|
|
/* Determine if the profile looks bogus. If so, close the profile
|
|
|
|
* and use sRGB instead. See bug 460629, */
|
|
|
|
if (gCMSOutputProfile && qcms_profile_is_bogus(gCMSOutputProfile)) {
|
|
|
|
NS_ASSERTION(gCMSOutputProfile != GetCMSsRGBProfile(),
|
|
|
|
"Builtin sRGB profile tagged as bogus!!!");
|
|
|
|
qcms_profile_release(gCMSOutputProfile);
|
|
|
|
gCMSOutputProfile = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gCMSOutputProfile) {
|
|
|
|
gCMSOutputProfile = GetCMSsRGBProfile();
|
|
|
|
}
|
|
|
|
/* Precache the LUT16 Interpolations for the output profile. See
|
|
|
|
bug 444661 for details. */
|
|
|
|
qcms_profile_precache_output_transform(gCMSOutputProfile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qcms_profile *
|
|
|
|
gfxPlatform::GetCMSOutputProfile()
|
|
|
|
{
|
|
|
|
return gCMSOutputProfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
qcms_profile *
|
|
|
|
gfxPlatform::GetCMSsRGBProfile()
|
|
|
|
{
|
|
|
|
if (!gCMSsRGBProfile) {
|
|
|
|
|
|
|
|
/* Create the profile using qcms. */
|
|
|
|
gCMSsRGBProfile = qcms_profile_sRGB();
|
|
|
|
}
|
|
|
|
return gCMSsRGBProfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
qcms_transform *
|
|
|
|
gfxPlatform::GetCMSRGBTransform()
|
|
|
|
{
|
|
|
|
if (!gCMSRGBTransform) {
|
|
|
|
qcms_profile *inProfile, *outProfile;
|
|
|
|
outProfile = GetCMSOutputProfile();
|
|
|
|
inProfile = GetCMSsRGBProfile();
|
|
|
|
|
|
|
|
if (!inProfile || !outProfile)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
gCMSRGBTransform = qcms_transform_create(inProfile, QCMS_DATA_RGB_8,
|
|
|
|
outProfile, QCMS_DATA_RGB_8,
|
|
|
|
QCMS_INTENT_PERCEPTUAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gCMSRGBTransform;
|
|
|
|
}
|
|
|
|
|
|
|
|
qcms_transform *
|
|
|
|
gfxPlatform::GetCMSInverseRGBTransform()
|
|
|
|
{
|
|
|
|
if (!gCMSInverseRGBTransform) {
|
|
|
|
qcms_profile *inProfile, *outProfile;
|
|
|
|
inProfile = GetCMSOutputProfile();
|
|
|
|
outProfile = GetCMSsRGBProfile();
|
|
|
|
|
|
|
|
if (!inProfile || !outProfile)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
gCMSInverseRGBTransform = qcms_transform_create(inProfile, QCMS_DATA_RGB_8,
|
|
|
|
outProfile, QCMS_DATA_RGB_8,
|
|
|
|
QCMS_INTENT_PERCEPTUAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gCMSInverseRGBTransform;
|
|
|
|
}
|
|
|
|
|
|
|
|
qcms_transform *
|
|
|
|
gfxPlatform::GetCMSRGBATransform()
|
|
|
|
{
|
|
|
|
if (!gCMSRGBATransform) {
|
|
|
|
qcms_profile *inProfile, *outProfile;
|
|
|
|
outProfile = GetCMSOutputProfile();
|
|
|
|
inProfile = GetCMSsRGBProfile();
|
|
|
|
|
|
|
|
if (!inProfile || !outProfile)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
gCMSRGBATransform = qcms_transform_create(inProfile, QCMS_DATA_RGBA_8,
|
|
|
|
outProfile, QCMS_DATA_RGBA_8,
|
|
|
|
QCMS_INTENT_PERCEPTUAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gCMSRGBATransform;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Shuts down various transforms and profiles for CMS. */
|
|
|
|
static void ShutdownCMS()
|
|
|
|
{
|
|
|
|
|
|
|
|
if (gCMSRGBTransform) {
|
|
|
|
qcms_transform_release(gCMSRGBTransform);
|
|
|
|
gCMSRGBTransform = nullptr;
|
|
|
|
}
|
|
|
|
if (gCMSInverseRGBTransform) {
|
|
|
|
qcms_transform_release(gCMSInverseRGBTransform);
|
|
|
|
gCMSInverseRGBTransform = nullptr;
|
|
|
|
}
|
|
|
|
if (gCMSRGBATransform) {
|
|
|
|
qcms_transform_release(gCMSRGBATransform);
|
|
|
|
gCMSRGBATransform = nullptr;
|
|
|
|
}
|
|
|
|
if (gCMSOutputProfile) {
|
|
|
|
qcms_profile_release(gCMSOutputProfile);
|
|
|
|
|
|
|
|
// handle the aliased case
|
|
|
|
if (gCMSsRGBProfile == gCMSOutputProfile)
|
|
|
|
gCMSsRGBProfile = nullptr;
|
|
|
|
gCMSOutputProfile = nullptr;
|
|
|
|
}
|
|
|
|
if (gCMSsRGBProfile) {
|
|
|
|
qcms_profile_release(gCMSsRGBProfile);
|
|
|
|
gCMSsRGBProfile = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset the state variables
|
|
|
|
gCMSMode = eCMSMode_Off;
|
|
|
|
gCMSInitialized = false;
|
|
|
|
}
|
|
|
|
|
2009-10-07 19:26:58 +04:00
|
|
|
// default SetupClusterBoundaries, based on Unicode properties;
|
|
|
|
// platform subclasses may override if they wish
|
|
|
|
void
|
2014-01-04 19:02:17 +04:00
|
|
|
gfxPlatform::SetupClusterBoundaries(gfxTextRun *aTextRun, const char16_t *aString)
|
2009-10-07 19:26:58 +04:00
|
|
|
{
|
|
|
|
if (aTextRun->GetFlags() & gfxTextRunFactory::TEXT_IS_8BIT) {
|
|
|
|
// 8-bit text doesn't have clusters.
|
|
|
|
// XXX is this true in all languages???
|
|
|
|
// behdad: don't think so. Czech for example IIRC has a
|
|
|
|
// 'ch' grapheme.
|
2010-12-06 16:22:24 +03:00
|
|
|
// jfkthame: but that's not expected to behave as a grapheme cluster
|
|
|
|
// for selection/editing/etc.
|
2009-10-07 19:26:58 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
aTextRun->SetupClusterBoundaries(0, aString, aTextRun->GetLength());
|
2011-12-06 16:39:19 +04:00
|
|
|
}
|
2010-12-06 16:22:24 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2011-12-06 16:39:19 +04:00
|
|
|
gfxPlatform::GetBidiNumeralOption()
|
|
|
|
{
|
|
|
|
if (mBidiNumeralOption == UNINITIALIZED_VALUE) {
|
|
|
|
mBidiNumeralOption = Preferences::GetInt(BIDI_NUMERAL_PREF, 0);
|
2009-10-07 19:26:58 +04:00
|
|
|
}
|
2011-12-06 16:39:19 +04:00
|
|
|
return mBidiNumeralOption;
|
2009-10-07 19:26:58 +04:00
|
|
|
}
|
2010-05-27 09:05:30 +04:00
|
|
|
|
2015-11-20 07:35:15 +03:00
|
|
|
/* static */ void
|
|
|
|
gfxPlatform::FlushFontAndWordCaches()
|
2013-09-11 05:36:57 +04:00
|
|
|
{
|
|
|
|
gfxFontCache *fontCache = gfxFontCache::GetCache();
|
|
|
|
if (fontCache) {
|
|
|
|
fontCache->AgeAllGenerations();
|
|
|
|
fontCache->FlushShapedWordCaches();
|
|
|
|
}
|
2016-03-23 21:17:02 +03:00
|
|
|
|
|
|
|
gfxPlatform::PurgeSkiaFontCache();
|
2013-09-11 05:36:57 +04:00
|
|
|
}
|
|
|
|
|
2010-05-27 09:05:30 +04:00
|
|
|
void
|
2011-06-12 06:30:16 +04:00
|
|
|
gfxPlatform::FontsPrefsChanged(const char *aPref)
|
2010-05-27 09:05:30 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(aPref != nullptr, "null preference");
|
2010-05-27 09:05:30 +04:00
|
|
|
if (!strcmp(GFX_DOWNLOADABLE_FONTS_ENABLED, aPref)) {
|
|
|
|
mAllowDownloadableFonts = UNINITIALIZED_VALUE;
|
2012-03-09 06:05:40 +04:00
|
|
|
} else if (!strcmp(GFX_PREF_FALLBACK_USE_CMAPS, aPref)) {
|
|
|
|
mFallbackUsesCmaps = UNINITIALIZED_VALUE;
|
2013-09-11 05:36:57 +04:00
|
|
|
} else if (!strcmp(GFX_PREF_WORD_CACHE_CHARLIMIT, aPref)) {
|
|
|
|
mWordCacheCharLimit = UNINITIALIZED_VALUE;
|
2013-09-11 05:36:57 +04:00
|
|
|
FlushFontAndWordCaches();
|
|
|
|
} else if (!strcmp(GFX_PREF_WORD_CACHE_MAXENTRIES, aPref)) {
|
|
|
|
mWordCacheMaxEntries = UNINITIALIZED_VALUE;
|
|
|
|
FlushFontAndWordCaches();
|
2011-12-10 02:32:29 +04:00
|
|
|
} else if (!strcmp(GFX_PREF_GRAPHITE_SHAPING, aPref)) {
|
|
|
|
mGraphiteShapingEnabled = UNINITIALIZED_VALUE;
|
2013-09-11 05:36:57 +04:00
|
|
|
FlushFontAndWordCaches();
|
2011-12-06 16:39:19 +04:00
|
|
|
} else if (!strcmp(BIDI_NUMERAL_PREF, aPref)) {
|
|
|
|
mBidiNumeralOption = UNINITIALIZED_VALUE;
|
2012-09-06 08:57:54 +04:00
|
|
|
} else if (!strcmp(GFX_PREF_OPENTYPE_SVG, aPref)) {
|
2013-05-16 20:32:41 +04:00
|
|
|
mOpenTypeSVGEnabled = UNINITIALIZED_VALUE;
|
2012-09-06 08:57:54 +04:00
|
|
|
gfxFontCache::GetCache()->AgeAllGenerations();
|
2010-05-27 09:05:30 +04:00
|
|
|
}
|
|
|
|
}
|
2011-01-21 19:44:33 +03:00
|
|
|
|
|
|
|
|
2015-10-30 01:58:24 +03:00
|
|
|
mozilla::LogModule*
|
2011-01-21 19:44:33 +03:00
|
|
|
gfxPlatform::GetLog(eGfxLog aWhichLog)
|
|
|
|
{
|
2014-02-14 19:27:47 +04:00
|
|
|
// logs shared across gfx
|
2015-10-30 01:58:24 +03:00
|
|
|
static LazyLogModule sFontlistLog("fontlist");
|
|
|
|
static LazyLogModule sFontInitLog("fontinit");
|
|
|
|
static LazyLogModule sTextrunLog("textrun");
|
|
|
|
static LazyLogModule sTextrunuiLog("textrunui");
|
|
|
|
static LazyLogModule sCmapDataLog("cmapdata");
|
|
|
|
static LazyLogModule sTextPerfLog("textperf");
|
2014-02-14 19:27:47 +04:00
|
|
|
|
2011-01-21 19:44:33 +03:00
|
|
|
switch (aWhichLog) {
|
|
|
|
case eGfxLog_fontlist:
|
|
|
|
return sFontlistLog;
|
|
|
|
case eGfxLog_fontinit:
|
|
|
|
return sFontInitLog;
|
|
|
|
case eGfxLog_textrun:
|
|
|
|
return sTextrunLog;
|
|
|
|
case eGfxLog_textrunui:
|
|
|
|
return sTextrunuiLog;
|
2012-03-09 06:05:14 +04:00
|
|
|
case eGfxLog_cmapdata:
|
|
|
|
return sCmapDataLog;
|
2013-11-25 08:59:56 +04:00
|
|
|
case eGfxLog_textperf:
|
|
|
|
return sTextPerfLog;
|
2011-01-21 19:44:33 +03:00
|
|
|
}
|
|
|
|
|
2015-06-04 09:13:42 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Unexpected log type");
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-01-21 19:44:33 +03:00
|
|
|
}
|
2012-05-15 23:41:20 +04:00
|
|
|
|
2012-05-26 08:38:17 +04:00
|
|
|
mozilla::gfx::SurfaceFormat
|
2013-09-25 00:45:13 +04:00
|
|
|
gfxPlatform::Optimal2DFormatForContent(gfxContentType aContent)
|
2012-05-26 08:38:17 +04:00
|
|
|
{
|
|
|
|
switch (aContent) {
|
2014-01-23 22:26:40 +04:00
|
|
|
case gfxContentType::COLOR:
|
2012-06-20 08:03:24 +04:00
|
|
|
switch (GetOffscreenFormat()) {
|
2016-01-08 07:57:38 +03:00
|
|
|
case SurfaceFormat::A8R8G8B8_UINT32:
|
2014-01-10 23:06:16 +04:00
|
|
|
return mozilla::gfx::SurfaceFormat::B8G8R8A8;
|
2016-01-08 07:57:38 +03:00
|
|
|
case SurfaceFormat::X8R8G8B8_UINT32:
|
2014-01-10 23:06:16 +04:00
|
|
|
return mozilla::gfx::SurfaceFormat::B8G8R8X8;
|
2016-01-08 07:57:38 +03:00
|
|
|
case SurfaceFormat::R5G6B5_UINT16:
|
2015-10-23 09:01:31 +03:00
|
|
|
return mozilla::gfx::SurfaceFormat::R5G6B5_UINT16;
|
2012-06-20 08:03:24 +04:00
|
|
|
default:
|
2014-01-23 22:26:40 +04:00
|
|
|
NS_NOTREACHED("unknown gfxImageFormat for gfxContentType::COLOR");
|
2014-01-10 23:06:16 +04:00
|
|
|
return mozilla::gfx::SurfaceFormat::B8G8R8A8;
|
2012-06-20 08:03:24 +04:00
|
|
|
}
|
2014-01-23 22:26:40 +04:00
|
|
|
case gfxContentType::ALPHA:
|
2014-01-10 23:06:16 +04:00
|
|
|
return mozilla::gfx::SurfaceFormat::A8;
|
2014-01-23 22:26:40 +04:00
|
|
|
case gfxContentType::COLOR_ALPHA:
|
2014-01-10 23:06:16 +04:00
|
|
|
return mozilla::gfx::SurfaceFormat::B8G8R8A8;
|
2012-05-26 08:38:17 +04:00
|
|
|
default:
|
|
|
|
NS_NOTREACHED("unknown gfxContentType");
|
2014-01-10 23:06:16 +04:00
|
|
|
return mozilla::gfx::SurfaceFormat::B8G8R8A8;
|
2012-05-26 08:38:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxImageFormat
|
2013-09-25 00:45:13 +04:00
|
|
|
gfxPlatform::OptimalFormatForContent(gfxContentType aContent)
|
2012-05-26 08:38:17 +04:00
|
|
|
{
|
|
|
|
switch (aContent) {
|
2014-01-23 22:26:40 +04:00
|
|
|
case gfxContentType::COLOR:
|
2012-05-26 08:38:17 +04:00
|
|
|
return GetOffscreenFormat();
|
2014-01-23 22:26:40 +04:00
|
|
|
case gfxContentType::ALPHA:
|
2016-01-08 07:57:38 +03:00
|
|
|
return SurfaceFormat::A8;
|
2014-01-23 22:26:40 +04:00
|
|
|
case gfxContentType::COLOR_ALPHA:
|
2016-01-08 07:57:38 +03:00
|
|
|
return SurfaceFormat::A8R8G8B8_UINT32;
|
2012-05-26 08:38:17 +04:00
|
|
|
default:
|
|
|
|
NS_NOTREACHED("unknown gfxContentType");
|
2016-01-08 07:57:38 +03:00
|
|
|
return SurfaceFormat::A8R8G8B8_UINT32;
|
2012-05-26 08:38:17 +04:00
|
|
|
}
|
|
|
|
}
|
2012-11-22 06:40:57 +04:00
|
|
|
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
/**
|
|
|
|
* There are a number of layers acceleration (or layers in general) preferences
|
|
|
|
* that should be consistent for the lifetime of the application (bug 840967).
|
|
|
|
* As such, we will evaluate them all as soon as one of them is evaluated
|
|
|
|
* and remember the values. Changing these preferences during the run will
|
|
|
|
* not have any effect until we restart.
|
|
|
|
*/
|
2016-05-12 12:24:43 +03:00
|
|
|
static mozilla::Atomic<bool> sLayersSupportsHardwareVideoDecoding(false);
|
2015-05-27 05:05:18 +03:00
|
|
|
static bool sLayersHardwareVideoDecodingFailed = false;
|
2014-02-27 06:53:27 +04:00
|
|
|
static bool sBufferRotationCheckPref = true;
|
2013-08-04 11:46:17 +04:00
|
|
|
|
2016-05-12 12:24:43 +03:00
|
|
|
static mozilla::Atomic<bool> sLayersAccelerationPrefsInitialized(false);
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
|
2016-08-25 06:48:35 +03:00
|
|
|
void VideoDecodingFailedChangedCallback(const char* aPref, void*)
|
|
|
|
{
|
|
|
|
sLayersHardwareVideoDecodingFailed = Preferences::GetBool(aPref, false);
|
2016-09-28 01:34:48 +03:00
|
|
|
gfxPlatform::GetPlatform()->UpdateCanUseHardwareVideoDecoding();
|
2016-08-25 06:48:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-09-28 01:34:48 +03:00
|
|
|
gfxPlatform::UpdateCanUseHardwareVideoDecoding()
|
2016-08-25 06:48:35 +03:00
|
|
|
{
|
2016-09-28 01:34:48 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
gfxVars::SetCanUseHardwareVideoDecoding(CanUseHardwareVideoDecoding());
|
|
|
|
}
|
2016-08-25 06:48:35 +03:00
|
|
|
}
|
|
|
|
|
2013-08-04 11:46:17 +04:00
|
|
|
void
|
2016-04-29 07:52:54 +03:00
|
|
|
gfxPlatform::InitAcceleration()
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
{
|
2016-04-29 07:52:54 +03:00
|
|
|
if (sLayersAccelerationPrefsInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
2013-08-04 11:46:17 +04:00
|
|
|
|
2016-04-29 07:52:54 +03:00
|
|
|
InitCompositorAccelerationPrefs();
|
|
|
|
|
2016-04-29 07:52:54 +03:00
|
|
|
// If this is called for the first time on a non-main thread, we're screwed.
|
|
|
|
// At the moment there's no explicit guarantee that the main thread calls
|
|
|
|
// this before the compositor thread, but let's at least make the assumption
|
|
|
|
// explicit.
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "can only initialize prefs on the main thread");
|
2016-04-28 08:54:24 +03:00
|
|
|
|
2016-04-29 07:52:54 +03:00
|
|
|
gfxPrefs::GetSingleton();
|
2016-08-04 21:33:44 +03:00
|
|
|
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
gfxVars::SetBrowserTabsRemoteAutostart(BrowserTabsRemoteAutostart());
|
2016-08-24 21:02:00 +03:00
|
|
|
gfxVars::SetOffscreenFormat(GetOffscreenFormat());
|
2016-08-24 21:03:00 +03:00
|
|
|
gfxVars::SetRequiresAcceleratedGLContextForCompositorOGL(
|
|
|
|
RequiresAcceleratedGLContextForCompositorOGL());
|
2016-08-04 21:33:44 +03:00
|
|
|
}
|
2016-04-29 07:52:54 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
|
|
|
|
nsCString discardFailureId;
|
|
|
|
int32_t status;
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
|
2016-04-29 07:52:54 +03:00
|
|
|
if (Preferences::GetBool("media.hardware-video-decoding.enabled", false) &&
|
2015-04-01 06:06:56 +03:00
|
|
|
#ifdef XP_WIN
|
2016-04-29 07:52:54 +03:00
|
|
|
Preferences::GetBool("media.windows-media-foundation.use-dxva", true) &&
|
2015-04-01 06:06:56 +03:00
|
|
|
#endif
|
2016-04-29 07:52:54 +03:00
|
|
|
NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING,
|
2016-04-14 00:12:47 +03:00
|
|
|
discardFailureId, &status))) {
|
2016-04-29 07:52:54 +03:00
|
|
|
if (status == nsIGfxInfo::FEATURE_STATUS_OK || gfxPrefs::HardwareVideoDecodingForceEnabled()) {
|
|
|
|
sLayersSupportsHardwareVideoDecoding = true;
|
2016-04-28 08:54:25 +03:00
|
|
|
}
|
2016-04-29 07:52:54 +03:00
|
|
|
}
|
2016-04-28 08:54:25 +03:00
|
|
|
|
2016-08-25 06:48:35 +03:00
|
|
|
sLayersAccelerationPrefsInitialized = true;
|
2016-04-28 08:54:25 +03:00
|
|
|
|
2016-06-11 05:27:24 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
2016-08-25 06:48:35 +03:00
|
|
|
Preferences::RegisterCallbackAndCall(VideoDecodingFailedChangedCallback,
|
|
|
|
"media.hardware-video-decoding.failed",
|
|
|
|
nullptr,
|
|
|
|
Preferences::ExactMatch);
|
|
|
|
|
2016-08-16 21:00:01 +03:00
|
|
|
FeatureState& gpuProc = gfxConfig::GetFeature(Feature::GPU_PROCESS);
|
2016-06-11 05:27:24 +03:00
|
|
|
if (gfxPrefs::GPUProcessDevEnabled()) {
|
|
|
|
// We want to hide this from about:support, so only set a default if the
|
|
|
|
// pref is known to be true.
|
2016-08-16 21:00:01 +03:00
|
|
|
gpuProc.SetDefaultFromPref(
|
2016-06-11 05:27:24 +03:00
|
|
|
gfxPrefs::GetGPUProcessDevEnabledPrefName(),
|
|
|
|
true,
|
|
|
|
gfxPrefs::GetGPUProcessDevEnabledPrefDefault());
|
2016-08-16 21:00:01 +03:00
|
|
|
|
|
|
|
// We require E10S - otherwise, there is very little benefit to the GPU
|
|
|
|
// process, since the UI process must still use acceleration for
|
|
|
|
// performance.
|
|
|
|
if (!BrowserTabsRemoteAutostart()) {
|
|
|
|
gpuProc.Disable(
|
|
|
|
FeatureStatus::Unavailable,
|
|
|
|
"Multi-process mode is not enabled",
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_NO_E10S"));
|
|
|
|
}
|
2016-06-11 05:27:24 +03:00
|
|
|
}
|
|
|
|
|
2016-08-16 21:00:01 +03:00
|
|
|
if (gpuProc.IsEnabled()) {
|
2016-06-11 05:27:24 +03:00
|
|
|
GPUProcessManager* gpu = GPUProcessManager::Get();
|
2016-09-30 11:21:21 +03:00
|
|
|
gpu->LaunchGPUProcess();
|
2016-06-11 05:27:24 +03:00
|
|
|
}
|
|
|
|
}
|
2016-04-28 08:54:25 +03:00
|
|
|
}
|
|
|
|
|
2016-04-29 07:52:54 +03:00
|
|
|
void
|
|
|
|
gfxPlatform::InitCompositorAccelerationPrefs()
|
|
|
|
{
|
|
|
|
const char *acceleratedEnv = PR_GetEnv("MOZ_ACCELERATED");
|
|
|
|
|
2016-04-29 07:52:55 +03:00
|
|
|
FeatureState& feature = gfxConfig::GetFeature(Feature::HW_COMPOSITING);
|
|
|
|
|
2016-04-29 07:52:54 +03:00
|
|
|
// Base value - does the platform allow acceleration?
|
2016-04-29 07:52:55 +03:00
|
|
|
if (feature.SetDefault(AccelerateLayersByDefault(),
|
|
|
|
FeatureStatus::Blocked,
|
|
|
|
"Acceleration blocked by platform"))
|
2016-04-29 07:52:54 +03:00
|
|
|
{
|
|
|
|
if (gfxPrefs::LayersAccelerationDisabledDoNotUseDirectly()) {
|
2016-06-03 21:54:56 +03:00
|
|
|
feature.UserDisable("Disabled by pref",
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_COMP_PREF"));
|
2016-04-29 07:52:54 +03:00
|
|
|
} else if (acceleratedEnv && *acceleratedEnv == '0') {
|
2016-06-03 21:54:56 +03:00
|
|
|
feature.UserDisable("Disabled by envvar",
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_COMP_ENV"));
|
2016-04-29 07:52:54 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (acceleratedEnv && *acceleratedEnv == '1') {
|
2016-04-29 07:52:55 +03:00
|
|
|
feature.UserEnable("Enabled by envvar");
|
2016-04-29 07:52:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This has specific meaning elsewhere, so we always record it.
|
|
|
|
if (gfxPrefs::LayersAccelerationForceEnabledDoNotUseDirectly()) {
|
2016-04-29 07:52:55 +03:00
|
|
|
feature.UserForceEnable("Force-enabled by pref");
|
2016-04-29 07:52:54 +03:00
|
|
|
}
|
|
|
|
|
2016-04-29 07:52:55 +03:00
|
|
|
// Safe mode trumps everything.
|
|
|
|
if (InSafeMode()) {
|
2016-06-03 21:54:56 +03:00
|
|
|
feature.ForceDisable(FeatureStatus::Blocked, "Acceleration blocked by safe-mode",
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_COMP_SAFEMODE"));
|
2016-04-29 07:52:55 +03:00
|
|
|
}
|
2016-04-29 07:52:54 +03:00
|
|
|
}
|
|
|
|
|
2015-01-26 03:34:28 +03:00
|
|
|
bool
|
2015-04-01 06:06:56 +03:00
|
|
|
gfxPlatform::CanUseHardwareVideoDecoding()
|
2015-01-26 03:34:28 +03:00
|
|
|
{
|
|
|
|
// this function is called from the compositor thread, so it is not
|
|
|
|
// safe to init the prefs etc. from here.
|
|
|
|
MOZ_ASSERT(sLayersAccelerationPrefsInitialized);
|
2015-05-27 05:05:18 +03:00
|
|
|
return sLayersSupportsHardwareVideoDecoding && !sLayersHardwareVideoDecodingFailed;
|
2015-01-26 03:34:28 +03:00
|
|
|
}
|
|
|
|
|
2015-07-17 01:18:05 +03:00
|
|
|
bool
|
|
|
|
gfxPlatform::AccelerateLayersByDefault()
|
|
|
|
{
|
|
|
|
#if defined(MOZ_GL_PROVIDER) || defined(MOZ_WIDGET_UIKIT)
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
2015-04-10 23:17:27 +03:00
|
|
|
|
2013-08-04 11:46:17 +04:00
|
|
|
bool
|
|
|
|
gfxPlatform::BufferRotationEnabled()
|
|
|
|
{
|
|
|
|
MutexAutoLock autoLock(*gGfxPlatformPrefsLock);
|
|
|
|
|
2014-02-27 06:53:27 +04:00
|
|
|
return sBufferRotationCheckPref && gfxPrefs::BufferRotationEnabled();
|
2013-08-04 11:46:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatform::DisableBufferRotation()
|
|
|
|
{
|
|
|
|
MutexAutoLock autoLock(*gGfxPlatformPrefsLock);
|
|
|
|
|
2014-02-27 06:53:27 +04:00
|
|
|
sBufferRotationCheckPref = false;
|
2013-08-16 17:18:36 +04:00
|
|
|
}
|
2013-12-21 01:37:07 +04:00
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<ScaledFont>
|
2014-01-30 11:01:16 +04:00
|
|
|
gfxPlatform::GetScaledFontForFontWithCairoSkia(DrawTarget* aTarget, gfxFont* aFont)
|
|
|
|
{
|
|
|
|
NativeFont nativeFont;
|
2014-06-20 00:35:33 +04:00
|
|
|
if (aTarget->GetBackendType() == BackendType::CAIRO || aTarget->GetBackendType() == BackendType::SKIA) {
|
2014-01-30 11:01:16 +04:00
|
|
|
nativeFont.mType = NativeFontType::CAIRO_FONT_FACE;
|
|
|
|
nativeFont.mFont = aFont->GetCairoScaledFont();
|
|
|
|
return Factory::CreateScaledFontForNativeFont(nativeFont, aFont->GetAdjustedSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-06-06 17:51:24 +04:00
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
gfxPlatform::UsesOffMainThreadCompositing()
|
|
|
|
{
|
2016-08-23 03:25:52 +03:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_GPU) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-06 17:51:24 +04:00
|
|
|
static bool firstTime = true;
|
|
|
|
static bool result = false;
|
|
|
|
|
|
|
|
if (firstTime) {
|
2016-04-29 07:52:54 +03:00
|
|
|
MOZ_ASSERT(sLayersAccelerationPrefsInitialized);
|
2014-06-06 17:51:24 +04:00
|
|
|
result =
|
2016-08-04 21:33:44 +03:00
|
|
|
gfxVars::BrowserTabsRemoteAutostart() ||
|
2016-04-05 17:55:17 +03:00
|
|
|
!gfxPrefs::LayersOffMainThreadCompositionForceDisabled();
|
2014-07-23 00:46:02 +04:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
2014-06-06 17:51:24 +04:00
|
|
|
// Linux users who chose OpenGL are being grandfathered in to OMTC
|
2016-04-29 07:52:54 +03:00
|
|
|
result |= gfxPrefs::LayersAccelerationForceEnabledDoNotUseDirectly();
|
2014-07-23 00:46:02 +04:00
|
|
|
|
2014-06-06 17:51:24 +04:00
|
|
|
#endif
|
|
|
|
firstTime = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2015-01-09 02:12:47 +03:00
|
|
|
|
2015-09-15 18:13:57 +03:00
|
|
|
/***
|
|
|
|
* The preference "layout.frame_rate" has 3 meanings depending on the value:
|
|
|
|
*
|
|
|
|
* -1 = Auto (default), use hardware vsync or software vsync @ 60 hz if hw vsync fails.
|
|
|
|
* 0 = ASAP mode - used during talos testing.
|
|
|
|
* X = Software vsync at a rate of X times per second.
|
|
|
|
*/
|
2015-01-09 02:12:47 +03:00
|
|
|
already_AddRefed<mozilla::gfx::VsyncSource>
|
|
|
|
gfxPlatform::CreateHardwareVsyncSource()
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::gfx::VsyncSource> softwareVsync = new SoftwareVsyncSource();
|
2015-01-09 02:12:47 +03:00
|
|
|
return softwareVsync.forget();
|
|
|
|
}
|
2015-03-03 19:14:22 +03:00
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
gfxPlatform::IsInLayoutAsapMode()
|
|
|
|
{
|
|
|
|
// There are 2 modes of ASAP mode.
|
|
|
|
// 1 is that the refresh driver and compositor are in lock step
|
|
|
|
// the second is that the compositor goes ASAP and the refresh driver
|
|
|
|
// goes at whatever the configurated rate is. This only checks the version
|
|
|
|
// talos uses, which is the refresh driver and compositor are in lockstep.
|
2016-07-19 21:56:07 +03:00
|
|
|
return gfxPrefs::LayoutFrameRate() == 0;
|
2015-03-03 19:14:22 +03:00
|
|
|
}
|
|
|
|
|
2015-09-15 18:13:57 +03:00
|
|
|
/* static */ bool
|
|
|
|
gfxPlatform::ForceSoftwareVsync()
|
|
|
|
{
|
2016-07-19 21:56:07 +03:00
|
|
|
return gfxPrefs::LayoutFrameRate() > 0;
|
2015-09-15 18:13:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ int
|
|
|
|
gfxPlatform::GetSoftwareVsyncRate()
|
|
|
|
{
|
2016-07-19 21:56:07 +03:00
|
|
|
int preferenceRate = gfxPrefs::LayoutFrameRate();
|
2015-09-15 18:13:57 +03:00
|
|
|
if (preferenceRate <= 0) {
|
|
|
|
return gfxPlatform::GetDefaultFrameRate();
|
|
|
|
}
|
|
|
|
return preferenceRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ int
|
|
|
|
gfxPlatform::GetDefaultFrameRate()
|
|
|
|
{
|
|
|
|
return 60;
|
|
|
|
}
|
|
|
|
|
2015-03-25 01:04:44 +03:00
|
|
|
void
|
|
|
|
gfxPlatform::GetApzSupportInfo(mozilla::widget::InfoObject& aObj)
|
|
|
|
{
|
2015-06-04 23:51:10 +03:00
|
|
|
if (!gfxPlatform::AsyncPanZoomEnabled()) {
|
2015-03-26 04:37:33 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-25 01:04:44 +03:00
|
|
|
if (SupportsApzWheelInput()) {
|
|
|
|
aObj.DefineProperty("ApzWheelInput", 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SupportsApzTouchInput()) {
|
|
|
|
aObj.DefineProperty("ApzTouchInput", 1);
|
|
|
|
}
|
2015-09-28 21:44:36 +03:00
|
|
|
|
|
|
|
if (SupportsApzDragInput()) {
|
|
|
|
aObj.DefineProperty("ApzDragInput", 1);
|
|
|
|
}
|
2015-03-25 01:04:44 +03:00
|
|
|
}
|
|
|
|
|
2016-07-21 09:08:39 +03:00
|
|
|
void
|
|
|
|
gfxPlatform::GetTilesSupportInfo(mozilla::widget::InfoObject& aObj)
|
|
|
|
{
|
|
|
|
if (!gfxPrefs::LayersTilesEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-04 21:33:43 +03:00
|
|
|
IntSize tileSize = gfxVars::TileSize();
|
|
|
|
aObj.DefineProperty("TileHeight", tileSize.height);
|
|
|
|
aObj.DefineProperty("TileWidth", tileSize.width);
|
2016-07-21 09:08:39 +03:00
|
|
|
}
|
|
|
|
|
2015-06-04 23:51:10 +03:00
|
|
|
/*static*/ bool
|
|
|
|
gfxPlatform::AsyncPanZoomEnabled()
|
|
|
|
{
|
2015-06-24 01:03:44 +03:00
|
|
|
#if !defined(MOZ_B2G) && !defined(MOZ_WIDGET_ANDROID) && !defined(MOZ_WIDGET_UIKIT)
|
2015-06-04 23:51:10 +03:00
|
|
|
// For XUL applications (everything but B2G on mobile and desktop, and
|
|
|
|
// Firefox on Android) we only want to use APZ when E10S is enabled. If
|
|
|
|
// we ever get input events off the main thread we can consider relaxing
|
|
|
|
// this requirement.
|
|
|
|
if (!BrowserTabsRemoteAutostart()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
2016-08-06 00:38:51 +03:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2015-12-15 17:17:41 +03:00
|
|
|
return true;
|
|
|
|
#else
|
2015-06-04 23:51:10 +03:00
|
|
|
return gfxPrefs::AsyncPanZoomEnabledDoNotUseDirectly();
|
2015-12-15 17:17:41 +03:00
|
|
|
#endif
|
2015-06-04 23:51:10 +03:00
|
|
|
}
|
2015-07-13 18:53:10 +03:00
|
|
|
|
|
|
|
/*static*/ bool
|
|
|
|
gfxPlatform::PerfWarnings()
|
|
|
|
{
|
|
|
|
return gfxPrefs::PerfWarnings();
|
|
|
|
}
|
2015-07-17 01:18:05 +03:00
|
|
|
|
2015-10-08 22:21:59 +03:00
|
|
|
void
|
|
|
|
gfxPlatform::GetAcceleratedCompositorBackends(nsTArray<LayersBackend>& aBackends)
|
|
|
|
{
|
2016-06-20 19:29:47 +03:00
|
|
|
if (gfxConfig::IsEnabled(Feature::OPENGL_COMPOSITING)) {
|
2015-10-08 22:21:59 +03:00
|
|
|
aBackends.AppendElement(LayersBackend::LAYERS_OPENGL);
|
|
|
|
}
|
2016-06-20 19:29:47 +03:00
|
|
|
else {
|
2015-07-17 01:18:05 +03:00
|
|
|
static int tell_me_once = 0;
|
|
|
|
if (!tell_me_once) {
|
|
|
|
NS_WARNING("OpenGL-accelerated layers are not supported on this system");
|
|
|
|
tell_me_once = 1;
|
|
|
|
}
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
NS_RUNTIMEABORT("OpenGL-accelerated layers are a hard requirement on this platform. "
|
|
|
|
"Cannot continue without support for them");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatform::GetCompositorBackends(bool useAcceleration, nsTArray<mozilla::layers::LayersBackend>& aBackends)
|
|
|
|
{
|
|
|
|
if (useAcceleration) {
|
|
|
|
GetAcceleratedCompositorBackends(aBackends);
|
|
|
|
}
|
2015-12-23 18:22:55 +03:00
|
|
|
aBackends.AppendElement(LayersBackend::LAYERS_BASIC);
|
2015-07-17 01:18:05 +03:00
|
|
|
}
|
2015-07-20 00:50:35 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatform::NotifyCompositorCreated(LayersBackend aBackend)
|
|
|
|
{
|
|
|
|
if (mCompositorBackend == aBackend) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-06 09:39:28 +03:00
|
|
|
if (mCompositorBackend != LayersBackend::LAYERS_NONE) {
|
|
|
|
gfxCriticalNote << "Compositors might be mixed ("
|
|
|
|
<< int(mCompositorBackend) << "," << int(aBackend) << ")";
|
|
|
|
}
|
2015-07-20 00:50:35 +03:00
|
|
|
|
|
|
|
// Set the backend before we notify so it's available immediately.
|
|
|
|
mCompositorBackend = aBackend;
|
|
|
|
|
|
|
|
// Notify that we created a compositor, so telemetry can update.
|
2015-09-14 09:51:45 +03:00
|
|
|
NS_DispatchToMainThread(NS_NewRunnableFunction([] {
|
|
|
|
if (nsCOMPtr<nsIObserverService> obsvc = services::GetObserverService()) {
|
|
|
|
obsvc->NotifyObservers(nullptr, "compositor:created", nullptr);
|
|
|
|
}
|
|
|
|
}));
|
2015-07-20 00:50:35 +03:00
|
|
|
}
|
2015-08-02 23:59:33 +03:00
|
|
|
|
|
|
|
void
|
2016-08-21 06:59:11 +03:00
|
|
|
gfxPlatform::FetchAndImportContentDeviceData()
|
2015-08-02 23:59:33 +03:00
|
|
|
{
|
2016-08-21 06:59:11 +03:00
|
|
|
MOZ_ASSERT(XRE_IsContentProcess());
|
|
|
|
|
|
|
|
mozilla::dom::ContentChild* cc = mozilla::dom::ContentChild::GetSingleton();
|
|
|
|
|
|
|
|
mozilla::gfx::ContentDeviceData data;
|
|
|
|
cc->SendGetGraphicsDeviceInitData(&data);
|
|
|
|
|
|
|
|
ImportContentDeviceData(data);
|
2015-08-02 23:59:33 +03:00
|
|
|
}
|
|
|
|
|
2016-08-21 06:59:11 +03:00
|
|
|
void
|
|
|
|
gfxPlatform::ImportContentDeviceData(const mozilla::gfx::ContentDeviceData& aData)
|
2015-08-02 23:59:33 +03:00
|
|
|
{
|
2016-08-21 06:59:11 +03:00
|
|
|
MOZ_ASSERT(XRE_IsContentProcess());
|
2015-08-02 23:59:33 +03:00
|
|
|
|
2016-08-21 06:59:11 +03:00
|
|
|
const DevicePrefs& prefs = aData.prefs();
|
|
|
|
gfxConfig::Inherit(Feature::HW_COMPOSITING, prefs.hwCompositing());
|
|
|
|
gfxConfig::Inherit(Feature::OPENGL_COMPOSITING, prefs.oglCompositing());
|
|
|
|
}
|
2016-04-29 07:52:55 +03:00
|
|
|
|
2016-08-21 06:59:11 +03:00
|
|
|
void
|
|
|
|
gfxPlatform::BuildContentDeviceData(mozilla::gfx::ContentDeviceData* aOut)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
2016-08-21 06:59:11 +03:00
|
|
|
|
|
|
|
// Make sure our settings are synchronized from the GPU process.
|
|
|
|
GPUProcessManager::Get()->EnsureGPUReady();
|
|
|
|
|
2016-08-21 06:59:11 +03:00
|
|
|
aOut->prefs().hwCompositing() = gfxConfig::GetValue(Feature::HW_COMPOSITING);
|
|
|
|
aOut->prefs().oglCompositing() = gfxConfig::GetValue(Feature::OPENGL_COMPOSITING);
|
2015-08-02 23:59:33 +03:00
|
|
|
}
|
2015-09-28 21:44:36 +03:00
|
|
|
|
2016-08-21 06:59:11 +03:00
|
|
|
void
|
|
|
|
gfxPlatform::ImportGPUDeviceData(const mozilla::gfx::GPUDeviceData& aData)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
|
|
|
|
|
|
|
gfxConfig::ImportChange(Feature::OPENGL_COMPOSITING, aData.oglCompositing());
|
|
|
|
}
|
|
|
|
|
2015-09-28 21:44:36 +03:00
|
|
|
bool
|
|
|
|
gfxPlatform::SupportsApzDragInput() const
|
|
|
|
{
|
|
|
|
return gfxPrefs::APZDragEnabled();
|
|
|
|
}
|
2016-03-01 00:41:35 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatform::BumpDeviceCounter()
|
|
|
|
{
|
|
|
|
mDeviceCounter++;
|
|
|
|
}
|
2016-06-20 19:29:47 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatform::InitOpenGLConfig()
|
|
|
|
{
|
2016-07-08 22:18:47 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// Don't enable by default on Windows, since it could show up in about:support even
|
|
|
|
// though it'll never get used. Only attempt if user enables the pref
|
|
|
|
if (!Preferences::GetBool("layers.prefer-opengl")){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-06-20 19:29:47 +03:00
|
|
|
FeatureState& openGLFeature = gfxConfig::GetFeature(Feature::OPENGL_COMPOSITING);
|
|
|
|
|
|
|
|
// Check to see hw comp supported
|
|
|
|
if (!gfxConfig::IsEnabled(Feature::HW_COMPOSITING)) {
|
|
|
|
openGLFeature.DisableByDefault(FeatureStatus::Unavailable, "Hardware compositing is disabled",
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_OPENGL_NEED_HWCOMP"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
openGLFeature.SetDefaultFromPref(
|
|
|
|
gfxPrefs::GetLayersPreferOpenGLPrefName(),
|
2016-07-08 22:18:47 +03:00
|
|
|
true,
|
2016-06-20 19:29:47 +03:00
|
|
|
gfxPrefs::GetLayersPreferOpenGLPrefDefault());
|
|
|
|
#else
|
|
|
|
openGLFeature.EnableByDefault();
|
|
|
|
#endif
|
|
|
|
|
2016-09-05 01:47:19 +03:00
|
|
|
// When layers acceleration is force-enabled, enable it even for blacklisted
|
|
|
|
// devices.
|
|
|
|
if (gfxPrefs::LayersAccelerationForceEnabledDoNotUseDirectly()) {
|
|
|
|
openGLFeature.UserForceEnable("Force-enabled by pref");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-20 19:29:47 +03:00
|
|
|
nsCString message;
|
|
|
|
nsCString failureId;
|
|
|
|
if (!IsGfxInfoStatusOkay(nsIGfxInfo::FEATURE_OPENGL_LAYERS, &message, failureId)) {
|
|
|
|
openGLFeature.Disable(FeatureStatus::Blacklisted, message.get(), failureId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
gfxPlatform::IsGfxInfoStatusOkay(int32_t aFeature, nsCString* aOutMessage, nsCString& aFailureId)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
|
|
|
|
if (!gfxInfo) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-22 11:47:44 +03:00
|
|
|
int32_t status;
|
2016-06-20 19:29:47 +03:00
|
|
|
if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(aFeature, aFailureId, &status)) &&
|
|
|
|
status != nsIGfxInfo::FEATURE_STATUS_OK)
|
|
|
|
{
|
|
|
|
aOutMessage->AssignLiteral("#BLOCKLIST_");
|
|
|
|
aOutMessage->AppendASCII(aFailureId.get());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|