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
|
|
|
|
2014-05-06 05:56:40 +04:00
|
|
|
#include "mozilla/layers/AsyncTransactionTracker.h" // for AsyncTransactionTracker
|
2012-08-26 05:27:28 +04:00
|
|
|
#include "mozilla/layers/CompositorChild.h"
|
2012-07-13 19:25:29 +04:00
|
|
|
#include "mozilla/layers/CompositorParent.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
|
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"
|
2014-11-18 01:16:55 +03:00
|
|
|
#include "prprf.h"
|
2011-01-21 19:44:33 +03:00
|
|
|
|
2005-11-29 23:29:45 +03:00
|
|
|
#include "gfxPlatform.h"
|
2014-02-13 21:38:40 +04:00
|
|
|
#include "gfxPrefs.h"
|
2014-09-16 13:58:12 +04:00
|
|
|
#include "gfxTextRun.h"
|
2014-07-09 23:24:49 +04:00
|
|
|
#include "gfxVR.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"
|
2008-04-19 17:19:04 +04:00
|
|
|
#elif defined(MOZ_WIDGET_QT)
|
|
|
|
#include "gfxQtPlatform.h"
|
2010-05-11 21:27:36 +04:00
|
|
|
#elif defined(ANDROID)
|
|
|
|
#include "gfxAndroidPlatform.h"
|
2005-11-29 23:29:45 +03:00
|
|
|
#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"
|
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"
|
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
|
|
|
|
|
2013-10-22 23:15:24 +04:00
|
|
|
#include "mozilla/Hal.h"
|
2014-04-15 23:07:42 +04:00
|
|
|
#ifdef USE_SKIA
|
2013-06-29 06:48:35 +04:00
|
|
|
#include "skia/SkGraphics.h"
|
2014-10-15 07:55:37 +04:00
|
|
|
# ifdef USE_SKIA_GPU
|
|
|
|
# include "SkiaGLGlue.h"
|
|
|
|
# endif
|
|
|
|
#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"
|
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
|
|
|
|
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"
|
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;
|
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
|
|
|
|
2015-04-16 18:55:36 +03:00
|
|
|
void InitLayersAccelerationPrefs();
|
|
|
|
|
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;
|
2014-11-18 01:16:55 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual std::vector<std::pair<int32_t,std::string> > StringsVectorCopy() override;
|
2015-01-14 05:19:25 +03:00
|
|
|
|
2014-11-18 01:16:55 +03:00
|
|
|
void SetCircularBufferSize(uint32_t aCapacity);
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Helpers for the Log()
|
|
|
|
bool UpdateStringsVector(const std::string& aString);
|
|
|
|
void UpdateCrashReport();
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<std::pair<int32_t,std::string> > mBuffer;
|
|
|
|
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-01-14 05:19:25 +03:00
|
|
|
std::vector<std::pair<int32_t,std::string> >
|
|
|
|
CrashStatsLogForwarder::StringsVectorCopy()
|
|
|
|
{
|
|
|
|
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());
|
|
|
|
|
|
|
|
// Checking for index >= mBuffer.size(), rather than index == mBuffer.size()
|
|
|
|
// just out of paranoia, but we know index <= mBuffer.size().
|
|
|
|
std::pair<int32_t,std::string> newEntry(mIndex,aString);
|
|
|
|
if (index >= static_cast<int32_t>(mBuffer.size())) {
|
|
|
|
mBuffer.push_back(newEntry);
|
|
|
|
} else {
|
|
|
|
mBuffer[index] = newEntry;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CrashStatsLogForwarder::UpdateCrashReport()
|
|
|
|
{
|
|
|
|
std::stringstream message;
|
|
|
|
for(std::vector<std::pair<int32_t, std::string> >::iterator it = mBuffer.begin(); it != mBuffer.end(); ++it) {
|
|
|
|
message << "|[" << (*it).first << "]" << (*it).second;
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2014-09-18 01:23:08 +04:00
|
|
|
|
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,
|
|
|
|
MOZ_UTF16(GFX_PREF_CMS_FORCE_SRGB)) == 0,
|
|
|
|
"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
|
|
|
|
|
|
|
gfxPlatform::GetPlatform()->PurgeSkiaCache();
|
2013-11-01 17:52:06 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-10 17:49:26 +03:00
|
|
|
// xxx - this can probably be eliminated by reworking pref font handling code
|
2008-01-31 03:23:36 +03:00
|
|
|
static const char *gPrefLangNames[] = {
|
2015-07-10 17:49:26 +03:00
|
|
|
#define FONT_PREF_LANG(enum_id_, str_, atom_id_) str_
|
|
|
|
#include "gfxFontPrefLangList.h"
|
|
|
|
#undef FONT_PREF_LANG
|
2008-01-31 03:23:36 +03:00
|
|
|
};
|
|
|
|
|
2015-05-14 04:23:46 +03:00
|
|
|
static nsIAtom* PrefLangToLangGroups(uint32_t aIndex)
|
|
|
|
{
|
2015-07-10 17:49:26 +03:00
|
|
|
// static array here avoids static constructor
|
2015-05-14 04:23:46 +03:00
|
|
|
static nsIAtom* gPrefLangToLangGroups[] = {
|
2015-07-10 17:49:26 +03:00
|
|
|
#define FONT_PREF_LANG(enum_id_, str_, atom_id_) nsGkAtoms::atom_id_
|
|
|
|
#include "gfxFontPrefLangList.h"
|
|
|
|
#undef FONT_PREF_LANG
|
2015-05-14 04:23:46 +03:00
|
|
|
};
|
2015-07-10 17:49:26 +03:00
|
|
|
|
2015-05-14 04:23:46 +03:00
|
|
|
return aIndex < ArrayLength(gPrefLangToLangGroups)
|
|
|
|
? gPrefLangToLangGroups[aIndex]
|
|
|
|
: nsGkAtoms::Unicode;
|
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2010-05-27 09:05:30 +04:00
|
|
|
gfxPlatform::gfxPlatform()
|
2014-11-13 01:54:29 +03:00
|
|
|
: mTileWidth(-1)
|
|
|
|
, mTileHeight(-1)
|
2015-01-07 08:39:46 +03:00
|
|
|
, mAzureCanvasBackendCollector(this, &gfxPlatform::GetAzureBackendInfo)
|
2015-03-25 01:04:44 +03:00
|
|
|
, mApzSupportCollector(this, &gfxPlatform::GetApzSupportInfo)
|
2015-07-20 00:50:35 +03:00
|
|
|
, mCompositorBackend(layers::LayersBackend::LAYERS_NONE)
|
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;
|
|
|
|
|
2014-01-10 23:06:16 +04:00
|
|
|
uint32_t canvasMask = BackendTypeBit(BackendType::CAIRO) | BackendTypeBit(BackendType::SKIA);
|
|
|
|
uint32_t contentMask = BackendTypeBit(BackendType::CAIRO);
|
|
|
|
InitBackendPrefs(canvasMask, BackendType::CAIRO,
|
|
|
|
contentMask, BackendType::CAIRO);
|
2014-09-12 03:52:42 +04:00
|
|
|
mTotalSystemMemory = mozilla::hal::GetTotalSystemMemory();
|
2014-07-09 23:24:49 +04:00
|
|
|
|
2015-04-01 23:02:20 +03:00
|
|
|
// give HMDs a chance to be initialized very early on
|
|
|
|
VRHMDManager::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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-21 23:36:53 +04:00
|
|
|
void
|
2007-03-30 01:48:46 +04:00
|
|
|
gfxPlatform::Init()
|
|
|
|
{
|
2015-03-05 19:43:53 +03:00
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
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-11-18 01:16:55 +03:00
|
|
|
CrashStatsLogForwarder* logForwarder = new CrashStatsLogForwarder("GraphicsCriticalError");
|
|
|
|
mozilla::gfx::Factory::SetLogForwarder(logForwarder);
|
2014-09-18 01:23:08 +04:00
|
|
|
|
2014-03-04 21:26:33 +04:00
|
|
|
// Initialize the preferences by creating the singleton.
|
|
|
|
gfxPrefs::GetSingleton();
|
2014-02-13 21:38:40 +04:00
|
|
|
|
2014-11-18 01:16:55 +03:00
|
|
|
logForwarder->SetCircularBufferSize(gfxPrefs::GfxLoggingCrashLength());
|
|
|
|
|
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;
|
2008-04-19 17:19:04 +04:00
|
|
|
#elif defined(MOZ_WIDGET_QT)
|
|
|
|
gPlatform = new gfxQtPlatform;
|
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
|
2007-03-30 01:48:46 +04:00
|
|
|
|
2014-10-15 05:24:53 +04:00
|
|
|
#ifdef MOZ_GL_DEBUG
|
2015-07-30 00:16:17 +03:00
|
|
|
mozilla::gl::GLContext::StaticInit();
|
2012-05-13 03:23:56 +04:00
|
|
|
#endif
|
|
|
|
|
2015-04-16 18:55:36 +03:00
|
|
|
InitLayersAccelerationPrefs();
|
2014-06-06 17:51:24 +04:00
|
|
|
InitLayersIPC();
|
2013-06-21 01:32:04 +04:00
|
|
|
|
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();
|
|
|
|
#elif defined(MOZ_WIDGET_QT)
|
|
|
|
usePlatformFontList = false;
|
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),
|
2015-07-07 04:21:47 +03:00
|
|
|
gfxImageFormat::ARGB32);
|
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);
|
|
|
|
if (!gPlatform->mScreenReferenceDrawTarget) {
|
|
|
|
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-30 00:16:17 +03:00
|
|
|
mozilla::gl::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-30 00:16:17 +03:00
|
|
|
mozilla::gl::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
|
|
|
|
2014-12-18 19:30:06 +03:00
|
|
|
if (XRE_IsParentProcess() && gfxPrefs::HardwareVsyncEnabled()) {
|
|
|
|
gPlatform->mVsyncSource = gPlatform->CreateHardwareVsyncSource();
|
2014-11-21 21:52:17 +03:00
|
|
|
}
|
2005-11-29 23:29:45 +03:00
|
|
|
}
|
|
|
|
|
2014-06-06 17:51:24 +04:00
|
|
|
static bool sLayersIPCIsUp = false;
|
|
|
|
|
2007-03-20 02:16:15 +03:00
|
|
|
void
|
|
|
|
gfxPlatform::Shutdown()
|
|
|
|
{
|
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
|
|
|
|
2011-06-12 06:30:16 +04:00
|
|
|
// In some cases, gPlatform may not be created but Shutdown() called,
|
|
|
|
// e.g., during xpcshell tests.
|
|
|
|
if (gPlatform) {
|
2013-09-07 07:08:36 +04:00
|
|
|
/* Unregister our CMS Override callback. */
|
|
|
|
NS_ASSERTION(gPlatform->mSRGBOverrideObserver, "mSRGBOverrideObserver has alreay gone");
|
2014-01-09 22:17:29 +04:00
|
|
|
Preferences::RemoveObserver(gPlatform->mSRGBOverrideObserver, GFX_PREF_CMS_FORCE_SRGB);
|
2013-09-07 07:08:36 +04:00
|
|
|
gPlatform->mSRGBOverrideObserver = nullptr;
|
|
|
|
|
2011-06-12 06:30:16 +04:00
|
|
|
NS_ASSERTION(gPlatform->mFontPrefsObserver, "mFontPrefsObserver has alreay gone");
|
|
|
|
Preferences::RemoveObservers(gPlatform->mFontPrefsObserver, kObservedPrefs);
|
2012-07-30 18:20:58 +04:00
|
|
|
gPlatform->mFontPrefsObserver = nullptr;
|
2013-11-01 17:52:06 +04: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;
|
2014-03-26 22:21:16 +04:00
|
|
|
gPlatform->mSkiaGlue = nullptr;
|
2014-12-18 19:30:06 +03:00
|
|
|
gPlatform->mVsyncSource = nullptr;
|
2011-06-12 06:30:16 +04:00
|
|
|
}
|
2009-09-10 05:22:03 +04:00
|
|
|
|
2012-07-20 23:20:51 +04:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
// Shut down the texture pool
|
2015-07-30 00:16:17 +03:00
|
|
|
mozilla::gl::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-30 00:16:17 +03:00
|
|
|
mozilla::gl::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-30 00:16:17 +03:00
|
|
|
mozilla::gl::GLContextProviderEGL::Shutdown();
|
2012-02-07 07:09:28 +04:00
|
|
|
#endif
|
2010-07-20 08:05:42 +04:00
|
|
|
|
2014-11-18 01:16:55 +03:00
|
|
|
// This is a bit iffy - we're assuming that we were the ones that set the
|
|
|
|
// log forwarder in the Factory, so that it's our responsibility to
|
|
|
|
// delete it.
|
2014-09-18 01:23:08 +04:00
|
|
|
delete mozilla::gfx::Factory::GetLogForwarder();
|
|
|
|
mozilla::gfx::Factory::SetLogForwarder(nullptr);
|
|
|
|
|
2013-08-04 11:46:17 +04:00
|
|
|
delete gGfxPlatformPrefsLock;
|
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
|
|
|
|
AsyncTransactionTrackersHolder::Initialize();
|
|
|
|
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsParentProcess())
|
2014-06-06 17:51:24 +04:00
|
|
|
{
|
2014-06-17 06:00:15 +04:00
|
|
|
mozilla::layers::CompositorParent::StartUp();
|
2015-07-08 10:28:48 +03:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2014-06-06 17:51:24 +04:00
|
|
|
SharedBufferManagerChild::StartUp();
|
|
|
|
#endif
|
2015-07-08 10:28:48 +03:00
|
|
|
mozilla::layers::ImageBridgeChild::StartUp();
|
2014-06-06 17:51:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
gfxPlatform::ShutdownLayersIPC()
|
|
|
|
{
|
|
|
|
if (!sLayersIPCIsUp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sLayersIPCIsUp = false;
|
|
|
|
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsParentProcess())
|
2015-01-14 22:23:06 +03:00
|
|
|
{
|
2014-06-06 17:51:24 +04:00
|
|
|
// This must happen after the shutdown of media and widgets, which
|
|
|
|
// are triggered by the NS_XPCOM_SHUTDOWN_OBSERVER_ID notification.
|
|
|
|
layers::ImageBridgeChild::ShutDown();
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
layers::SharedBufferManagerChild::ShutDown();
|
|
|
|
#endif
|
|
|
|
|
2014-06-17 06:00:15 +04:00
|
|
|
layers::CompositorParent::ShutDown();
|
2014-06-06 17:51:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-20 02:16:15 +03:00
|
|
|
gfxPlatform::~gfxPlatform()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mScreenReferenceSurface = nullptr;
|
2013-10-24 19:50:26 +04:00
|
|
|
mScreenReferenceDrawTarget = nullptr;
|
2012-05-12 01:21:41 +04:00
|
|
|
|
2014-07-09 23:24:49 +04:00
|
|
|
// Clean up any VR stuff
|
2015-04-01 23:02:20 +03:00
|
|
|
VRHMDManager::ManagerDestroy();
|
2014-07-09 23:24:49 +04:00
|
|
|
|
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-01-08 03:13:03 +03:00
|
|
|
#if defined(DEBUG) || defined(NS_BUILD_REFCNT_LOGGING) || defined(MOZ_VALGRIND)
|
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
|
|
|
|
SkGraphics::Term();
|
|
|
|
#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
|
|
|
}
|
|
|
|
|
2011-06-24 21:41:18 +04:00
|
|
|
cairo_user_data_key_t kDrawTarget;
|
|
|
|
|
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();
|
2014-04-14 22:51:00 +04: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;
|
|
|
|
}
|
2013-07-31 19:44:31 +04:00
|
|
|
aSurface->SetData(&kDrawTarget, drawTarget, nullptr);
|
2014-06-12 23:24:05 +04:00
|
|
|
return drawTarget.forget();
|
2011-06-24 21:41:18 +04:00
|
|
|
}
|
|
|
|
|
2013-07-10 05:02:41 +04:00
|
|
|
// This is a temporary function used by ContentClient to build a DrawTarget
|
|
|
|
// around the gfxASurface. This should eventually be replaced by plumbing
|
|
|
|
// the DrawTarget through directly
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<DrawTarget>
|
2013-07-10 05:02:41 +04:00
|
|
|
gfxPlatform::CreateDrawTargetForUpdateSurface(gfxASurface *aSurface, const IntSize& aSize)
|
|
|
|
{
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// this is a bit of a hack that assumes that the buffer associated with the CGContext
|
|
|
|
// will live around long enough that nothing bad will happen.
|
2014-01-23 22:26:40 +04:00
|
|
|
if (aSurface->GetType() == gfxSurfaceType::Quartz) {
|
2013-07-10 05:02:41 +04:00
|
|
|
return Factory::CreateDrawTargetForCairoCGContext(static_cast<gfxQuartzSurface*>(aSurface)->GetCGContext(), aSize);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
MOZ_CRASH();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2012-10-08 06:44:36 +04:00
|
|
|
RefPtr<SourceSurface> mSrcSurface;
|
|
|
|
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
|
|
|
|
{
|
|
|
|
nsRefPtr<gfxASurface> mSurface;
|
|
|
|
};
|
|
|
|
|
|
|
|
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>
|
2011-06-24 21:41:18 +04:00
|
|
|
gfxPlatform::GetSourceSurfaceForSurface(DrawTarget *aTarget, gfxASurface *aSurface)
|
|
|
|
{
|
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();
|
|
|
|
if (!aTarget) {
|
2013-12-12 01:05:26 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-05-01 16:14:16 +03:00
|
|
|
RefPtr<SourceSurface> srcSurface(surf->mSrcSurface);
|
|
|
|
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).
|
|
|
|
NativeSurface surf;
|
|
|
|
surf.mFormat = format;
|
|
|
|
surf.mType = NativeSurfaceType::CAIRO_SURFACE;
|
|
|
|
surf.mSurface = aSurface->CairoSurface();
|
2015-04-07 17:08:57 +03:00
|
|
|
surf.mSize = aSurface->GetSize();
|
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.
|
|
|
|
return aTarget->CreateSourceSurfaceFromNativeSurface(surf);
|
|
|
|
}
|
|
|
|
|
2011-06-24 21:41:18 +04:00
|
|
|
RefPtr<SourceSurface> srcBuffer;
|
|
|
|
|
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:
|
|
|
|
RefPtr<DataSourceSurface> surf = GetWrappedDataSourceSurface(aSurface);
|
|
|
|
if (surf) {
|
|
|
|
srcBuffer = aTarget->OptimizeSourceSurface(surf);
|
|
|
|
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.
|
2012-09-03 03:07:05 +04:00
|
|
|
NativeSurface surf;
|
|
|
|
surf.mFormat = format;
|
2014-01-10 23:06:16 +04:00
|
|
|
surf.mType = NativeSurfaceType::CAIRO_SURFACE;
|
2012-09-03 03:07:05 +04:00
|
|
|
surf.mSurface = aSurface->CairoSurface();
|
2015-04-07 17:08:57 +03:00
|
|
|
surf.mSize = aSurface->GetSize();
|
2014-06-17 13:08:23 +04:00
|
|
|
RefPtr<DrawTarget> drawTarget =
|
|
|
|
Factory::CreateDrawTarget(BackendType::CAIRO, IntSize(1, 1), format);
|
2015-03-09 22:48:20 +03:00
|
|
|
if (!drawTarget) {
|
|
|
|
gfxWarning() << "gfxPlatform::GetSourceSurfaceForSurface failed in CreateDrawTarget";
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-06-17 13:08:23 +04:00
|
|
|
srcBuffer = drawTarget->CreateSourceSurfaceFromNativeSurface(surf);
|
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)
|
|
|
|
{
|
|
|
|
nsRefPtr<gfxImageSurface> image = aSurface->GetAsImageSurface();
|
|
|
|
if (!image) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
RefPtr<DataSourceSurface> result =
|
|
|
|
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:54:29 +03:00
|
|
|
int
|
|
|
|
gfxPlatform::GetTileWidth()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mTileWidth != -1);
|
|
|
|
return mTileWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
gfxPlatform::GetTileHeight()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mTileHeight != -1);
|
|
|
|
return mTileHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatform::SetTileSize(int aWidth, int aHeight)
|
|
|
|
{
|
|
|
|
// 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((mTileWidth == -1 && mTileHeight == -1) ||
|
|
|
|
(mTileWidth == aWidth && mTileHeight == aHeight));
|
|
|
|
|
|
|
|
mTileWidth = aWidth;
|
|
|
|
mTileHeight = aHeight;
|
|
|
|
}
|
|
|
|
|
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()) {
|
2014-11-13 01:55:13 +03:00
|
|
|
NS_RUNTIMEABORT("wrong process.");
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t w = gfxPrefs::LayersTileWidth();
|
|
|
|
int32_t h = gfxPrefs::LayersTileHeight();
|
|
|
|
|
|
|
|
// TODO We may want to take the screen size into consideration here.
|
|
|
|
if (gfxPrefs::LayersTilesAdjust()) {
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
int32_t format = android::PIXEL_FORMAT_RGBA_8888;
|
|
|
|
android::sp<android::GraphicBuffer> alloc =
|
|
|
|
new android::GraphicBuffer(gfxPrefs::LayersTileWidth(), gfxPrefs::LayersTileHeight(),
|
|
|
|
format,
|
|
|
|
android::GraphicBuffer::USAGE_SW_READ_OFTEN |
|
|
|
|
android::GraphicBuffer::USAGE_SW_WRITE_OFTEN |
|
|
|
|
android::GraphicBuffer::USAGE_HW_TEXTURE);
|
|
|
|
|
|
|
|
if (alloc.get()) {
|
|
|
|
w = alloc->getStride(); // We want the tiles to be gralloc stride aligned.
|
|
|
|
// No need to adjust the height here.
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
SetTileSize(w, h);
|
|
|
|
}
|
|
|
|
|
2013-05-28 02:04:37 +04:00
|
|
|
bool
|
|
|
|
gfxPlatform::SupportsAzureContentForDrawTarget(DrawTarget* aTarget)
|
|
|
|
{
|
|
|
|
if (!aTarget) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-06-20 00:35:33 +04:00
|
|
|
return SupportsAzureContentForType(aTarget->GetBackendType());
|
2013-05-28 02:04:37 +04:00
|
|
|
}
|
|
|
|
|
2012-12-01 03:58:00 +04:00
|
|
|
bool
|
|
|
|
gfxPlatform::UseAcceleratedSkiaCanvas()
|
|
|
|
{
|
2014-02-27 06:53:32 +04:00
|
|
|
return gfxPrefs::CanvasAzureAccelerated() &&
|
2014-01-10 23:06:16 +04:00
|
|
|
mPreferredCanvasBackend == BackendType::SKIA;
|
2012-12-01 03:58:00 +04:00
|
|
|
}
|
|
|
|
|
2014-09-11 00:15:43 +04:00
|
|
|
bool gfxPlatform::HaveChoiceOfHWAndSWCanvas()
|
|
|
|
{
|
|
|
|
return mPreferredCanvasBackend == BackendType::SKIA;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-02-21 03:23:52 +04:00
|
|
|
if (UseAcceleratedSkiaCanvas()) {
|
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();
|
|
|
|
int cacheSizeLimit = gfxPrefs::CanvasSkiaGLCacheSize();
|
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
|
|
|
}
|
|
|
|
|
2014-03-06 01:49:37 +04:00
|
|
|
#ifdef DEBUG
|
2014-02-21 03:23:52 +04:00
|
|
|
printf_stderr("Determined SkiaGL cache limits: Size %i, Items: %i\n", cacheSizeLimit, cacheItemLimit);
|
2014-03-06 01:49:37 +04:00
|
|
|
#endif
|
2013-10-22 23:15:24 +04:00
|
|
|
|
2014-08-20 23:09:47 +04:00
|
|
|
mSkiaGlue->GetGrContext()->setResourceCacheLimits(cacheItemLimit, 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-30 00:16:17 +03:00
|
|
|
mozilla::gl::SkiaGLGlue*
|
2014-03-06 01:49:37 +04:00
|
|
|
gfxPlatform::GetSkiaGLGlue()
|
|
|
|
{
|
|
|
|
#ifdef USE_SKIA_GPU
|
|
|
|
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-07-30 00:16:17 +03:00
|
|
|
bool requireCompatProfile = true;
|
|
|
|
nsRefPtr<mozilla::gl::GLContext> glContext;
|
|
|
|
glContext = mozilla::gl::GLContextProvider::CreateHeadless(requireCompatProfile);
|
2014-03-06 01:49:37 +04:00
|
|
|
if (!glContext) {
|
|
|
|
printf_stderr("Failed to create GLContext for SkiaGL!\n");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-07-30 00:16:17 +03:00
|
|
|
mSkiaGlue = new mozilla::gl::SkiaGLGlue(glContext);
|
2014-03-06 01:49:37 +04:00
|
|
|
MOZ_ASSERT(mSkiaGlue->GetGrContext(), "No GrContext");
|
|
|
|
InitializeSkiaCacheLimits();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return mSkiaGlue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatform::PurgeSkiaCache()
|
|
|
|
{
|
|
|
|
#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-07-07 04:21:47 +03:00
|
|
|
nsRefPtr<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.");
|
2012-07-31 10:30:10 +04: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
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<DrawTarget>
|
2012-04-02 23:15:08 +04:00
|
|
|
gfxPlatform::CreateDrawTargetForData(unsigned char* aData, const IntSize& aSize, int32_t aStride, SurfaceFormat aFormat)
|
|
|
|
{
|
2014-01-22 02:15:48 +04:00
|
|
|
NS_ASSERTION(mContentBackend != BackendType::NONE, "No backend.");
|
2014-06-26 11:40:12 +04:00
|
|
|
|
2015-01-08 05:34:07 +03:00
|
|
|
BackendType backendType = mContentBackend;
|
|
|
|
|
|
|
|
if (!Factory::DoesBackendSupportDataDrawtarget(mContentBackend)) {
|
|
|
|
backendType = BackendType::CAIRO;
|
|
|
|
}
|
2015-01-08 00:58:25 +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;
|
2012-07-25 04:45:58 +04:00
|
|
|
if (aName.EqualsLiteral("cg"))
|
2014-01-10 23:06:16 +04:00
|
|
|
return BackendType::COREGRAPHICS;
|
|
|
|
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
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2006-06-15 08:47:23 +04:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxPlatform::UpdateFontList()
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
bool aItalic,
|
|
|
|
const uint8_t* aFontData,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLength)
|
2009-08-30 17:55:24 +04:00
|
|
|
{
|
|
|
|
// Default implementation does not handle activating downloaded fonts;
|
|
|
|
// just free the data and return.
|
|
|
|
// Platforms that support @font-face must override this,
|
|
|
|
// using the data to instantiate the font, and taking responsibility
|
|
|
|
// for freeing it when no longer required.
|
|
|
|
if (aFontData) {
|
2015-04-01 08:29:55 +03:00
|
|
|
free((void*)aFontData);
|
2009-08-30 17:55:24 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-08-30 17:55:24 +04:00
|
|
|
}
|
2008-10-01 07:01:53 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
bool gfxPlatform::ForEachPrefFont(eFontPrefLang aLangArray[], uint32_t aLangArrayLen, PrefFontCallback aCallback,
|
2008-01-31 03:23:36 +03:00
|
|
|
void *aClosure)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_TRUE(Preferences::GetRootBranch(), false);
|
2008-01-31 03:23:36 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i;
|
2008-01-31 03:23:36 +03:00
|
|
|
for (i = 0; i < aLangArrayLen; i++) {
|
|
|
|
eFontPrefLang prefLang = aLangArray[i];
|
|
|
|
const char *langGroup = GetPrefLangName(prefLang);
|
2012-11-07 03:23:13 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString prefName;
|
2012-11-07 03:23:13 +04:00
|
|
|
|
2008-01-31 03:23:36 +03:00
|
|
|
prefName.AssignLiteral("font.default.");
|
|
|
|
prefName.Append(langGroup);
|
2011-06-12 06:30:16 +04:00
|
|
|
nsAdoptingCString genericDotLang = Preferences::GetCString(prefName.get());
|
2012-11-07 03:23:13 +04:00
|
|
|
|
2014-05-22 07:48:51 +04:00
|
|
|
genericDotLang.Append('.');
|
2008-01-31 03:23:36 +03:00
|
|
|
genericDotLang.Append(langGroup);
|
2012-11-07 03:23:13 +04:00
|
|
|
|
|
|
|
// fetch font.name.xxx value
|
2008-01-31 03:23:36 +03:00
|
|
|
prefName.AssignLiteral("font.name.");
|
|
|
|
prefName.Append(genericDotLang);
|
2011-06-12 06:30:16 +04:00
|
|
|
nsAdoptingCString nameValue = Preferences::GetCString(prefName.get());
|
|
|
|
if (nameValue) {
|
2009-04-04 13:43:42 +04:00
|
|
|
if (!aCallback(prefLang, NS_ConvertUTF8toUTF16(nameValue), aClosure))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-01-31 03:23:36 +03:00
|
|
|
}
|
2012-11-07 03:23:13 +04:00
|
|
|
|
|
|
|
// fetch font.name-list.xxx value
|
2008-01-31 03:23:36 +03:00
|
|
|
prefName.AssignLiteral("font.name-list.");
|
|
|
|
prefName.Append(genericDotLang);
|
2011-06-12 06:30:16 +04:00
|
|
|
nsAdoptingCString nameListValue = Preferences::GetCString(prefName.get());
|
|
|
|
if (nameListValue && !nameListValue.Equals(nameValue)) {
|
2009-10-07 18:13:40 +04:00
|
|
|
const char kComma = ',';
|
|
|
|
const char *p, *p_end;
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString list(nameListValue);
|
2009-10-07 18:13:40 +04:00
|
|
|
list.BeginReading(p);
|
|
|
|
list.EndReading(p_end);
|
|
|
|
while (p < p_end) {
|
|
|
|
while (nsCRT::IsAsciiSpace(*p)) {
|
|
|
|
if (++p == p_end)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (p == p_end)
|
|
|
|
break;
|
|
|
|
const char *start = p;
|
|
|
|
while (++p != p_end && *p != kComma)
|
|
|
|
/* nothing */ ;
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString fontName(Substring(start, p));
|
2011-10-17 18:59:28 +04:00
|
|
|
fontName.CompressWhitespace(false, true);
|
2009-10-07 18:13:40 +04:00
|
|
|
if (!aCallback(prefLang, NS_ConvertUTF8toUTF16(fontName), aClosure))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-10-07 18:13:40 +04:00
|
|
|
p++;
|
|
|
|
}
|
2008-01-31 03:23:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-01-31 03:23:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
eFontPrefLang
|
|
|
|
gfxPlatform::GetFontPrefLangFor(const char* aLang)
|
|
|
|
{
|
2014-06-05 14:15:26 +04:00
|
|
|
if (!aLang || !aLang[0]) {
|
2008-01-31 03:23:36 +03:00
|
|
|
return eFontPrefLang_Others;
|
2014-06-05 14:15:26 +04:00
|
|
|
}
|
|
|
|
for (uint32_t i = 0; i < ArrayLength(gPrefLangNames); ++i) {
|
|
|
|
if (!PL_strcasecmp(gPrefLangNames[i], aLang)) {
|
2008-01-31 03:23:36 +03:00
|
|
|
return eFontPrefLang(i);
|
2014-06-05 14:15:26 +04:00
|
|
|
}
|
2008-01-31 03:23:36 +03:00
|
|
|
}
|
|
|
|
return eFontPrefLang_Others;
|
|
|
|
}
|
|
|
|
|
2010-02-24 20:57:57 +03:00
|
|
|
eFontPrefLang
|
|
|
|
gfxPlatform::GetFontPrefLangFor(nsIAtom *aLang)
|
|
|
|
{
|
|
|
|
if (!aLang)
|
|
|
|
return eFontPrefLang_Others;
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString lang;
|
2010-02-24 20:57:57 +03:00
|
|
|
aLang->ToUTF8String(lang);
|
|
|
|
return GetFontPrefLangFor(lang.get());
|
|
|
|
}
|
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
nsIAtom*
|
|
|
|
gfxPlatform::GetLangGroupForPrefLang(eFontPrefLang aLang)
|
|
|
|
{
|
|
|
|
// the special CJK set pref lang should be resolved into separate
|
|
|
|
// calls to individual CJK pref langs before getting here
|
|
|
|
NS_ASSERTION(aLang != eFontPrefLang_CJKSet, "unresolved CJK set pref lang");
|
|
|
|
|
2015-05-14 04:23:46 +03:00
|
|
|
return PrefLangToLangGroups(uint32_t(aLang));
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
2008-01-31 03:23:36 +03:00
|
|
|
const char*
|
|
|
|
gfxPlatform::GetPrefLangName(eFontPrefLang aLang)
|
|
|
|
{
|
2014-06-05 14:15:26 +04:00
|
|
|
if (uint32_t(aLang) < ArrayLength(gPrefLangNames)) {
|
2012-08-22 19:56:38 +04:00
|
|
|
return gPrefLangNames[uint32_t(aLang)];
|
2014-06-05 14:15:26 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-01-31 03:23:36 +03:00
|
|
|
}
|
|
|
|
|
2009-10-07 19:26:58 +04:00
|
|
|
eFontPrefLang
|
2012-08-22 19:56:38 +04:00
|
|
|
gfxPlatform::GetFontPrefLangFor(uint8_t aUnicodeRange)
|
2009-10-07 19:26:58 +04:00
|
|
|
{
|
|
|
|
switch (aUnicodeRange) {
|
|
|
|
case kRangeSetLatin: return eFontPrefLang_Western;
|
|
|
|
case kRangeCyrillic: return eFontPrefLang_Cyrillic;
|
|
|
|
case kRangeGreek: return eFontPrefLang_Greek;
|
|
|
|
case kRangeHebrew: return eFontPrefLang_Hebrew;
|
|
|
|
case kRangeArabic: return eFontPrefLang_Arabic;
|
|
|
|
case kRangeThai: return eFontPrefLang_Thai;
|
|
|
|
case kRangeKorean: return eFontPrefLang_Korean;
|
|
|
|
case kRangeJapanese: return eFontPrefLang_Japanese;
|
|
|
|
case kRangeSChinese: return eFontPrefLang_ChineseCN;
|
|
|
|
case kRangeTChinese: return eFontPrefLang_ChineseTW;
|
|
|
|
case kRangeDevanagari: return eFontPrefLang_Devanagari;
|
|
|
|
case kRangeTamil: return eFontPrefLang_Tamil;
|
|
|
|
case kRangeArmenian: return eFontPrefLang_Armenian;
|
|
|
|
case kRangeBengali: return eFontPrefLang_Bengali;
|
|
|
|
case kRangeCanadian: return eFontPrefLang_Canadian;
|
|
|
|
case kRangeEthiopic: return eFontPrefLang_Ethiopic;
|
|
|
|
case kRangeGeorgian: return eFontPrefLang_Georgian;
|
|
|
|
case kRangeGujarati: return eFontPrefLang_Gujarati;
|
|
|
|
case kRangeGurmukhi: return eFontPrefLang_Gurmukhi;
|
|
|
|
case kRangeKhmer: return eFontPrefLang_Khmer;
|
|
|
|
case kRangeMalayalam: return eFontPrefLang_Malayalam;
|
2011-03-31 12:47:02 +04:00
|
|
|
case kRangeOriya: return eFontPrefLang_Oriya;
|
|
|
|
case kRangeTelugu: return eFontPrefLang_Telugu;
|
|
|
|
case kRangeKannada: return eFontPrefLang_Kannada;
|
|
|
|
case kRangeSinhala: return eFontPrefLang_Sinhala;
|
|
|
|
case kRangeTibetan: return eFontPrefLang_Tibetan;
|
2009-10-07 19:26:58 +04:00
|
|
|
case kRangeSetCJK: return eFontPrefLang_CJKSet;
|
|
|
|
default: return eFontPrefLang_Others;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-07 03:23:13 +04:00
|
|
|
bool
|
2008-01-31 03:23:36 +03:00
|
|
|
gfxPlatform::IsLangCJK(eFontPrefLang aLang)
|
|
|
|
{
|
2010-03-08 12:14:56 +03:00
|
|
|
switch (aLang) {
|
|
|
|
case eFontPrefLang_Japanese:
|
|
|
|
case eFontPrefLang_ChineseTW:
|
|
|
|
case eFontPrefLang_ChineseCN:
|
|
|
|
case eFontPrefLang_ChineseHK:
|
|
|
|
case eFontPrefLang_Korean:
|
|
|
|
case eFontPrefLang_CJKSet:
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-03-08 12:14:56 +03:00
|
|
|
default:
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-03-08 12:14:56 +03:00
|
|
|
}
|
2008-01-31 03:23:36 +03: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-11-07 03:23:13 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
gfxPlatform::GetLangPrefs(eFontPrefLang aPrefLangs[], uint32_t &aLen, eFontPrefLang aCharLang, eFontPrefLang aPageLang)
|
2009-10-07 19:26:58 +04:00
|
|
|
{
|
|
|
|
if (IsLangCJK(aCharLang)) {
|
|
|
|
AppendCJKPrefLangs(aPrefLangs, aLen, aCharLang, aPageLang);
|
|
|
|
} else {
|
|
|
|
AppendPrefLang(aPrefLangs, aLen, aCharLang);
|
|
|
|
}
|
|
|
|
|
|
|
|
AppendPrefLang(aPrefLangs, aLen, eFontPrefLang_Others);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
gfxPlatform::AppendCJKPrefLangs(eFontPrefLang aPrefLangs[], uint32_t &aLen, eFontPrefLang aCharLang, eFontPrefLang aPageLang)
|
2009-10-07 19:26:58 +04:00
|
|
|
{
|
|
|
|
// prefer the lang specified by the page *if* CJK
|
|
|
|
if (IsLangCJK(aPageLang)) {
|
|
|
|
AppendPrefLang(aPrefLangs, aLen, aPageLang);
|
|
|
|
}
|
2012-11-07 03:23:13 +04:00
|
|
|
|
2009-10-07 19:26:58 +04:00
|
|
|
// if not set up, set up the default CJK order, based on accept lang settings and locale
|
|
|
|
if (mCJKPrefLangs.Length() == 0) {
|
2012-11-07 03:23:13 +04:00
|
|
|
|
2009-10-07 19:26:58 +04:00
|
|
|
// temp array
|
|
|
|
eFontPrefLang tempPrefLangs[kMaxLenPrefLangList];
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t tempLen = 0;
|
2012-11-07 03:23:13 +04:00
|
|
|
|
2009-10-07 19:26:58 +04:00
|
|
|
// Add the CJK pref fonts from accept languages, the order should be same order
|
2011-06-12 06:30:16 +04:00
|
|
|
nsAdoptingCString list = Preferences::GetLocalizedCString("intl.accept_languages");
|
2010-03-15 21:29:55 +03:00
|
|
|
if (!list.IsEmpty()) {
|
2009-10-07 19:26:58 +04:00
|
|
|
const char kComma = ',';
|
|
|
|
const char *p, *p_end;
|
|
|
|
list.BeginReading(p);
|
|
|
|
list.EndReading(p_end);
|
|
|
|
while (p < p_end) {
|
|
|
|
while (nsCRT::IsAsciiSpace(*p)) {
|
|
|
|
if (++p == p_end)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (p == p_end)
|
|
|
|
break;
|
|
|
|
const char *start = p;
|
|
|
|
while (++p != p_end && *p != kComma)
|
|
|
|
/* nothing */ ;
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString lang(Substring(start, p));
|
2011-10-17 18:59:28 +04:00
|
|
|
lang.CompressWhitespace(false, true);
|
2009-10-07 19:26:58 +04:00
|
|
|
eFontPrefLang fpl = gfxPlatform::GetFontPrefLangFor(lang.get());
|
|
|
|
switch (fpl) {
|
|
|
|
case eFontPrefLang_Japanese:
|
|
|
|
case eFontPrefLang_Korean:
|
|
|
|
case eFontPrefLang_ChineseCN:
|
|
|
|
case eFontPrefLang_ChineseHK:
|
|
|
|
case eFontPrefLang_ChineseTW:
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, fpl);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
do { // to allow 'break' to abort this block if a call fails
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsILocaleService> ls =
|
|
|
|
do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocale> appLocale;
|
|
|
|
rv = ls->GetApplicationLocale(getter_AddRefs(appLocale));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsString localeStr;
|
|
|
|
rv = appLocale->
|
|
|
|
GetCategory(NS_LITERAL_STRING(NSILOCALE_MESSAGE), localeStr);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
|
|
|
|
const nsAString& lang = Substring(localeStr, 0, 2);
|
|
|
|
if (lang.EqualsLiteral("ja")) {
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Japanese);
|
|
|
|
} else if (lang.EqualsLiteral("zh")) {
|
|
|
|
const nsAString& region = Substring(localeStr, 3, 2);
|
|
|
|
if (region.EqualsLiteral("CN")) {
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseCN);
|
|
|
|
} else if (region.EqualsLiteral("TW")) {
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseTW);
|
|
|
|
} else if (region.EqualsLiteral("HK")) {
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseHK);
|
|
|
|
}
|
|
|
|
} else if (lang.EqualsLiteral("ko")) {
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Korean);
|
|
|
|
}
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
// last resort... (the order is same as old gfx.)
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Japanese);
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_Korean);
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseCN);
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseHK);
|
|
|
|
AppendPrefLang(tempPrefLangs, tempLen, eFontPrefLang_ChineseTW);
|
2012-11-07 03:23:13 +04:00
|
|
|
|
2009-10-07 19:26:58 +04:00
|
|
|
// copy into the cached array
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t j;
|
2009-10-07 19:26:58 +04:00
|
|
|
for (j = 0; j < tempLen; j++) {
|
|
|
|
mCJKPrefLangs.AppendElement(tempPrefLangs[j]);
|
|
|
|
}
|
|
|
|
}
|
2012-11-07 03:23:13 +04:00
|
|
|
|
2009-10-07 19:26:58 +04:00
|
|
|
// append in cached CJK langs
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i, numCJKlangs = mCJKPrefLangs.Length();
|
2012-11-07 03:23:13 +04:00
|
|
|
|
2009-10-07 19:26:58 +04:00
|
|
|
for (i = 0; i < numCJKlangs; i++) {
|
|
|
|
AppendPrefLang(aPrefLangs, aLen, (eFontPrefLang) (mCJKPrefLangs[i]));
|
|
|
|
}
|
2012-11-07 03:23:13 +04:00
|
|
|
|
2009-10-07 19:26:58 +04:00
|
|
|
}
|
|
|
|
|
2012-11-07 03:23:13 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
gfxPlatform::AppendPrefLang(eFontPrefLang aPrefLangs[], uint32_t& aLen, eFontPrefLang aAddLang)
|
2008-01-31 03:23:36 +03:00
|
|
|
{
|
|
|
|
if (aLen >= kMaxLenPrefLangList) return;
|
2012-11-07 03:23:13 +04:00
|
|
|
|
2008-01-31 03:23:36 +03:00
|
|
|
// make sure
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i = 0;
|
2008-01-31 03:23:36 +03:00
|
|
|
while (i < aLen && aPrefLangs[i] != aAddLang) {
|
|
|
|
i++;
|
|
|
|
}
|
2012-11-07 03:23:13 +04:00
|
|
|
|
2008-01-31 03:23:36 +03:00
|
|
|
if (i == aLen) {
|
|
|
|
aPrefLangs[aLen] = aAddLang;
|
|
|
|
aLen++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
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 */
|
2014-10-17 15:53:15 +04:00
|
|
|
uint32_t packed = in.ToARGB();
|
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);
|
2014-10-17 15:53:15 +04:00
|
|
|
out = Color::FromARGB(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
|
|
|
|
2013-09-11 05:36:57 +04:00
|
|
|
static void
|
|
|
|
FlushFontAndWordCaches()
|
|
|
|
{
|
|
|
|
gfxFontCache *fontCache = gfxFontCache::GetCache();
|
|
|
|
if (fontCache) {
|
|
|
|
fontCache->AgeAllGenerations();
|
|
|
|
fontCache->FlushShapedWordCaches();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
PRLogModuleInfo*
|
|
|
|
gfxPlatform::GetLog(eGfxLog aWhichLog)
|
|
|
|
{
|
2014-02-14 19:27:47 +04:00
|
|
|
// logs shared across gfx
|
|
|
|
static PRLogModuleInfo *sFontlistLog = nullptr;
|
|
|
|
static PRLogModuleInfo *sFontInitLog = nullptr;
|
|
|
|
static PRLogModuleInfo *sTextrunLog = nullptr;
|
|
|
|
static PRLogModuleInfo *sTextrunuiLog = nullptr;
|
|
|
|
static PRLogModuleInfo *sCmapDataLog = nullptr;
|
|
|
|
static PRLogModuleInfo *sTextPerfLog = nullptr;
|
|
|
|
|
|
|
|
// Assume that if one is initialized, all are initialized
|
|
|
|
if (!sFontlistLog) {
|
|
|
|
sFontlistLog = PR_NewLogModule("fontlist");
|
|
|
|
sFontInitLog = PR_NewLogModule("fontinit");
|
|
|
|
sTextrunLog = PR_NewLogModule("textrun");
|
|
|
|
sTextrunuiLog = PR_NewLogModule("textrunui");
|
|
|
|
sCmapDataLog = PR_NewLogModule("cmapdata");
|
|
|
|
sTextPerfLog = PR_NewLogModule("textperf");
|
|
|
|
}
|
|
|
|
|
2011-01-21 19:44:33 +03:00
|
|
|
switch (aWhichLog) {
|
|
|
|
case eGfxLog_fontlist:
|
|
|
|
return sFontlistLog;
|
|
|
|
break;
|
|
|
|
case eGfxLog_fontinit:
|
|
|
|
return sFontInitLog;
|
|
|
|
break;
|
|
|
|
case eGfxLog_textrun:
|
|
|
|
return sTextrunLog;
|
|
|
|
break;
|
|
|
|
case eGfxLog_textrunui:
|
|
|
|
return sTextrunuiLog;
|
|
|
|
break;
|
2012-03-09 06:05:14 +04:00
|
|
|
case eGfxLog_cmapdata:
|
|
|
|
return sCmapDataLog;
|
|
|
|
break;
|
2013-11-25 08:59:56 +04:00
|
|
|
case eGfxLog_textperf:
|
|
|
|
return sTextPerfLog;
|
|
|
|
break;
|
2011-01-21 19:44:33 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
int
|
|
|
|
gfxPlatform::GetScreenDepth() const
|
|
|
|
{
|
2012-07-06 17:19:27 +04:00
|
|
|
NS_WARNING("GetScreenDepth not implemented on this platform -- returning 0!");
|
2012-05-15 23:41:20 +04:00
|
|
|
return 0;
|
|
|
|
}
|
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()) {
|
2014-01-23 22:26:40 +04:00
|
|
|
case gfxImageFormat::ARGB32:
|
2014-01-10 23:06:16 +04:00
|
|
|
return mozilla::gfx::SurfaceFormat::B8G8R8A8;
|
2014-01-23 22:26:40 +04:00
|
|
|
case gfxImageFormat::RGB24:
|
2014-01-10 23:06:16 +04:00
|
|
|
return mozilla::gfx::SurfaceFormat::B8G8R8X8;
|
2014-01-23 22:26:40 +04:00
|
|
|
case gfxImageFormat::RGB16_565:
|
2014-01-10 23:06:16 +04:00
|
|
|
return mozilla::gfx::SurfaceFormat::R5G6B5;
|
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:
|
2014-01-23 22:26:40 +04:00
|
|
|
return gfxImageFormat::A8;
|
2014-01-23 22:26:40 +04:00
|
|
|
case gfxContentType::COLOR_ALPHA:
|
2014-01-23 22:26:40 +04:00
|
|
|
return gfxImageFormat::ARGB32;
|
2012-05-26 08:38:17 +04:00
|
|
|
default:
|
|
|
|
NS_NOTREACHED("unknown gfxContentType");
|
2014-01-23 22:26:40 +04:00
|
|
|
return gfxImageFormat::ARGB32;
|
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.
|
|
|
|
*/
|
2013-11-15 20:28:40 +04:00
|
|
|
static bool sLayersSupportsD3D9 = false;
|
2014-05-16 20:16:21 +04:00
|
|
|
static bool sLayersSupportsD3D11 = false;
|
2015-06-06 00:17:30 +03:00
|
|
|
bool gANGLESupportsD3D11 = false;
|
2015-04-01 06:06:56 +03:00
|
|
|
static 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;
|
2014-02-21 05:26:41 +04:00
|
|
|
static bool sPrefBrowserTabsRemoteAutostart = false;
|
2013-08-04 11:46:17 +04:00
|
|
|
|
|
|
|
static 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
|
|
|
|
2013-08-04 11:46:17 +04:00
|
|
|
void
|
|
|
|
InitLayersAccelerationPrefs()
|
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
|
|
|
{
|
|
|
|
if (!sLayersAccelerationPrefsInitialized)
|
|
|
|
{
|
2013-11-27 11:33:39 +04: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");
|
|
|
|
|
2014-06-06 17:51:24 +04:00
|
|
|
gfxPrefs::GetSingleton();
|
2014-09-10 22:53:55 +04:00
|
|
|
sPrefBrowserTabsRemoteAutostart = BrowserTabsRemoteAutostart();
|
2013-08-04 11:46:17 +04:00
|
|
|
|
2015-07-08 23:51:09 +03:00
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
|
2015-04-01 06:06:56 +03:00
|
|
|
int32_t status;
|
2013-11-15 20:28:40 +04:00
|
|
|
#ifdef XP_WIN
|
2014-02-27 06:53:27 +04:00
|
|
|
if (gfxPrefs::LayersAccelerationForceEnabled()) {
|
2013-11-15 20:28:40 +04:00
|
|
|
sLayersSupportsD3D9 = true;
|
2014-05-16 20:16:21 +04:00
|
|
|
sLayersSupportsD3D11 = true;
|
2015-04-01 06:06:56 +03:00
|
|
|
} else if (gfxInfo) {
|
|
|
|
if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS, &status))) {
|
|
|
|
if (status == nsIGfxInfo::FEATURE_STATUS_OK) {
|
|
|
|
sLayersSupportsD3D9 = true;
|
2014-05-16 20:16:21 +04:00
|
|
|
}
|
2015-04-01 06:06:56 +03:00
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_DIRECT3D_11_LAYERS, &status))) {
|
|
|
|
if (status == nsIGfxInfo::FEATURE_STATUS_OK) {
|
2014-12-06 03:02:19 +03:00
|
|
|
sLayersSupportsD3D11 = true;
|
|
|
|
}
|
2015-04-01 06:06:56 +03:00
|
|
|
}
|
|
|
|
if (!gfxPrefs::LayersD3D11DisableWARP()) {
|
|
|
|
// Always support D3D11 when WARP is allowed.
|
|
|
|
sLayersSupportsD3D11 = true;
|
2013-08-04 11:46:17 +04:00
|
|
|
}
|
2015-04-10 23:17:27 +03:00
|
|
|
if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_DIRECT3D_11_ANGLE, &status))) {
|
|
|
|
if (status == nsIGfxInfo::FEATURE_STATUS_OK) {
|
2015-06-06 00:17:30 +03:00
|
|
|
gANGLESupportsD3D11 = true;
|
2015-04-10 23:17:27 +03:00
|
|
|
}
|
|
|
|
}
|
2013-08-04 11:46:17 +04:00
|
|
|
}
|
2013-11-15 20:28:40 +04:00
|
|
|
#endif
|
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
|
|
|
|
2015-04-01 06:06:56 +03:00
|
|
|
if (Preferences::GetBool("media.hardware-video-decoding.enabled", false) &&
|
|
|
|
#ifdef XP_WIN
|
|
|
|
Preferences::GetBool("media.windows-media-foundation.use-dxva", true) &&
|
|
|
|
#endif
|
|
|
|
NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_HARDWARE_VIDEO_DECODING,
|
|
|
|
&status))) {
|
|
|
|
if (status == nsIGfxInfo::FEATURE_STATUS_OK) {
|
|
|
|
sLayersSupportsHardwareVideoDecoding = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-27 05:05:18 +03:00
|
|
|
Preferences::AddBoolVarCache(&sLayersHardwareVideoDecodingFailed,
|
|
|
|
"media.hardware-video-decoding.failed",
|
|
|
|
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
|
|
|
sLayersAccelerationPrefsInitialized = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-04 11:46:17 +04:00
|
|
|
bool
|
|
|
|
gfxPlatform::CanUseDirect3D9()
|
|
|
|
{
|
|
|
|
// this function is called from the compositor thread, so it is not
|
|
|
|
// safe to init the prefs etc. from here.
|
|
|
|
MOZ_ASSERT(sLayersAccelerationPrefsInitialized);
|
|
|
|
return sLayersSupportsD3D9;
|
|
|
|
}
|
|
|
|
|
2014-05-16 20:16:21 +04:00
|
|
|
bool
|
|
|
|
gfxPlatform::CanUseDirect3D11()
|
|
|
|
{
|
|
|
|
// this function is called from the compositor thread, so it is not
|
|
|
|
// safe to init the prefs etc. from here.
|
|
|
|
MOZ_ASSERT(sLayersAccelerationPrefsInitialized);
|
|
|
|
return sLayersSupportsD3D11;
|
|
|
|
}
|
|
|
|
|
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-04-10 23:17:27 +03:00
|
|
|
bool
|
|
|
|
gfxPlatform::CanUseDirect3D11ANGLE()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(sLayersAccelerationPrefsInitialized);
|
2015-06-06 00:17:30 +03:00
|
|
|
return gANGLESupportsD3D11;
|
2015-04-10 23:17:27 +03:00
|
|
|
}
|
|
|
|
|
2015-07-17 01:18:05 +03:00
|
|
|
bool
|
|
|
|
gfxPlatform::ShouldUseLayersAcceleration()
|
|
|
|
{
|
|
|
|
const char *acceleratedEnv = PR_GetEnv("MOZ_ACCELERATED");
|
|
|
|
if (gfxPrefs::LayersAccelerationDisabled() ||
|
|
|
|
InSafeMode() ||
|
|
|
|
(acceleratedEnv && *acceleratedEnv == '0'))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (gfxPrefs::LayersAccelerationForceEnabled()) {
|
|
|
|
return true;
|
|
|
|
}
|
Refactor graphics device initialization on Windows. (bug 1183910 part 1, r=mattwoodrow,bas)
This patch addresses a number of inconsistencies in the device initialization process, as well as simplifying it for future use. All device decisions are now explicitly made up-front during startup, rather than implicitly or on-demand. In addition a number of restrictions have been placed on when we can construct devices.
Full change list:
(1) We no longer attempt to use D3D11 if acceleration is disabled or D3D9 is preferred. This is a departure from our previous behavior, where we would construct these devices but then not use them as a compositor backend.
(2) D3D11 startup no longer creates a content device (this is reserved for D2D initialization).
(3) D2D is only attempted if we managed to create a D3D11 compositor device. This is a departure from previous behavior where if D3D11 was not used for compositing, we could still create its machinery to use D2D as a content backend.
(4) D2D 1.1 initialization is now directly responsible for creating a D3D11 content device.
(5) D2D 1.0 and 1.1 logic have been disentangled for clarity.
(6) UpdateRenderMode() has been split up, so we can update backend prefs out of band with device resets.
(7) mUseGDIFonts and mUseDirectWrite have been removed as their state was confusing. Instead, D2D now depends on DWrite initialization succeeding. If later we fail to get a DWrite font list, we revert our decision to use Direct2D.
(8) Device resets now clear a little more state, including the devices set in Moz2D Factory.
(9) We no longer create a DWrite text analyzer as it was unused.
2015-07-29 02:52:54 +03:00
|
|
|
if (AccelerateLayersByDefault()) {
|
2015-07-17 01:18:05 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (acceleratedEnv && *acceleratedEnv != '0') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
InitLayersAccelerationPrefs();
|
|
|
|
static bool firstTime = true;
|
|
|
|
static bool result = false;
|
|
|
|
|
|
|
|
if (firstTime) {
|
|
|
|
result =
|
|
|
|
sPrefBrowserTabsRemoteAutostart ||
|
|
|
|
gfxPrefs::LayersOffMainThreadCompositionEnabled() ||
|
|
|
|
gfxPrefs::LayersOffMainThreadCompositionForceEnabled() ||
|
|
|
|
gfxPrefs::LayersOffMainThreadCompositionTestingEnabled();
|
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
|
2014-07-23 00:46:02 +04:00
|
|
|
result |= gfxPrefs::LayersAccelerationForceEnabled();
|
|
|
|
|
2014-06-06 17:51:24 +04:00
|
|
|
#endif
|
|
|
|
firstTime = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2015-01-09 02:12:47 +03:00
|
|
|
|
|
|
|
already_AddRefed<mozilla::gfx::VsyncSource>
|
|
|
|
gfxPlatform::CreateHardwareVsyncSource()
|
|
|
|
{
|
2015-05-05 23:57:47 +03:00
|
|
|
NS_WARNING("Hardware Vsync support not yet implemented. Falling back to software timers");
|
2015-01-09 02:12:47 +03:00
|
|
|
nsRefPtr<mozilla::gfx::VsyncSource> softwareVsync = new SoftwareVsyncSource();
|
|
|
|
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.
|
|
|
|
return Preferences::GetInt("layout.frame_rate", -1) == 0;
|
|
|
|
}
|
|
|
|
|
2015-03-26 04:37:33 +03:00
|
|
|
static nsString
|
|
|
|
DetectBadApzWheelInputPrefs()
|
|
|
|
{
|
|
|
|
static const char *sBadMultiplierPrefs[] = {
|
|
|
|
"mousewheel.default.delta_multiplier_x",
|
|
|
|
"mousewheel.with_alt.delta_multiplier_x",
|
|
|
|
"mousewheel.with_control.delta_multiplier_x",
|
|
|
|
"mousewheel.with_meta.delta_multiplier_x",
|
|
|
|
"mousewheel.with_shift.delta_multiplier_x",
|
|
|
|
"mousewheel.with_win.delta_multiplier_x",
|
|
|
|
"mousewheel.with_alt.delta_multiplier_y",
|
|
|
|
"mousewheel.with_control.delta_multiplier_y",
|
|
|
|
"mousewheel.with_meta.delta_multiplier_y",
|
|
|
|
"mousewheel.with_shift.delta_multiplier_y",
|
|
|
|
"mousewheel.with_win.delta_multiplier_y",
|
|
|
|
};
|
|
|
|
|
|
|
|
nsString badPref;
|
|
|
|
for (size_t i = 0; i < MOZ_ARRAY_LENGTH(sBadMultiplierPrefs); i++) {
|
|
|
|
if (Preferences::GetInt(sBadMultiplierPrefs[i], 100) != 100) {
|
|
|
|
badPref.AssignASCII(sBadMultiplierPrefs[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return badPref;
|
|
|
|
}
|
|
|
|
|
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()) {
|
2015-03-26 04:37:33 +03:00
|
|
|
nsString badPref = DetectBadApzWheelInputPrefs();
|
2015-03-25 01:04:44 +03:00
|
|
|
|
|
|
|
aObj.DefineProperty("ApzWheelInput", 1);
|
|
|
|
if (badPref.Length()) {
|
|
|
|
aObj.DefineProperty("ApzWheelInputWarning", badPref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SupportsApzTouchInput()) {
|
|
|
|
aObj.DefineProperty("ApzTouchInput", 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
return gfxPrefs::AsyncPanZoomEnabledDoNotUseDirectly();
|
|
|
|
}
|
2015-07-13 18:53:10 +03:00
|
|
|
|
|
|
|
/*virtual*/ bool
|
|
|
|
gfxPlatform::UseProgressivePaint()
|
|
|
|
{
|
|
|
|
return gfxPrefs::ProgressivePaintDoNotUseDirectly();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ bool
|
|
|
|
gfxPlatform::PerfWarnings()
|
|
|
|
{
|
|
|
|
return gfxPrefs::PerfWarnings();
|
|
|
|
}
|
2015-07-17 01:18:05 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatform::GetAcceleratedCompositorBackends(nsTArray<LayersBackend>& aBackends)
|
|
|
|
{
|
|
|
|
// Being whitelisted is not enough to accelerate, but not being whitelisted is
|
|
|
|
// enough not to:
|
|
|
|
bool whitelisted = false;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
|
|
|
|
if (gfxInfo) {
|
|
|
|
// bug 655578: on X11 at least, we must always call GetData (even if we don't need that information)
|
|
|
|
// as that's what causes GfxInfo initialization which kills the zombie 'glxtest' process.
|
|
|
|
// initially we relied on the fact that GetFeatureStatus calls GetData for us, but bug 681026 showed
|
|
|
|
// that assumption to be unsafe.
|
|
|
|
gfxInfo->GetData();
|
|
|
|
|
|
|
|
int32_t status;
|
|
|
|
if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_OPENGL_LAYERS, &status))) {
|
|
|
|
if (status == nsIGfxInfo::FEATURE_STATUS_OK) {
|
|
|
|
aBackends.AppendElement(LayersBackend::LAYERS_OPENGL);
|
|
|
|
whitelisted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!whitelisted) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
if (SupportsBasicCompositor()) {
|
|
|
|
aBackends.AppendElement(LayersBackend::LAYERS_BASIC);
|
|
|
|
}
|
|
|
|
}
|
2015-07-20 00:50:35 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatform::NotifyCompositorCreated(LayersBackend aBackend)
|
|
|
|
{
|
|
|
|
if (mCompositorBackend == aBackend) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mCompositorBackend == LayersBackend::LAYERS_NONE, "Compositor backend changed.");
|
|
|
|
|
|
|
|
// Set the backend before we notify so it's available immediately.
|
|
|
|
mCompositorBackend = aBackend;
|
|
|
|
|
|
|
|
// Notify that we created a compositor, so telemetry can update.
|
|
|
|
if (nsCOMPtr<nsIObserverService> obsvc = services::GetObserverService()) {
|
|
|
|
obsvc->NotifyObservers(nullptr, "compositor:created", nullptr);
|
|
|
|
}
|
|
|
|
}
|