зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1915433 - Simplify CMS and gfxPlatform initialization. r=gfx-reviewers,bradwerth
Differential Revision: https://phabricator.services.mozilla.com/D220484
This commit is contained in:
Родитель
9a3dda8889
Коммит
517850c2bb
|
@ -171,23 +171,13 @@ using namespace mozilla::layers;
|
|||
using namespace mozilla::gl;
|
||||
using namespace mozilla::gfx;
|
||||
|
||||
gfxPlatform* gPlatform = nullptr;
|
||||
static bool gEverInitialized = false;
|
||||
gfxPlatform* gfxPlatform::gPlatform = nullptr;
|
||||
|
||||
const ContentDeviceData* gContentDeviceInitData = nullptr;
|
||||
Maybe<nsTArray<uint8_t>> gCMSOutputProfileData;
|
||||
|
||||
Atomic<bool, MemoryOrdering::ReleaseAcquire> gfxPlatform::gCMSInitialized;
|
||||
Atomic<bool, ReleaseAcquire> gfxPlatform::gCMSInitialized;
|
||||
CMSMode gfxPlatform::gCMSMode = CMSMode::Off;
|
||||
|
||||
// These two may point to the same profile
|
||||
qcms_profile* gfxPlatform::gCMSOutputProfile = nullptr;
|
||||
qcms_profile* gfxPlatform::gCMSsRGBProfile = nullptr;
|
||||
|
||||
qcms_transform* gfxPlatform::gCMSRGBTransform = nullptr;
|
||||
qcms_transform* gfxPlatform::gCMSInverseRGBTransform = nullptr;
|
||||
qcms_transform* gfxPlatform::gCMSRGBATransform = nullptr;
|
||||
qcms_transform* gfxPlatform::gCMSBGRATransform = nullptr;
|
||||
const ContentDeviceData* gContentDeviceInitData = nullptr;
|
||||
|
||||
/// This override of the LogForwarder, initially used for the critical graphics
|
||||
/// errors, is sending the log to the crash annotations as well, but only
|
||||
|
@ -454,16 +444,6 @@ gfxPlatform::gfxPlatform()
|
|||
VRManager::ManagerInit();
|
||||
}
|
||||
|
||||
gfxPlatform* gfxPlatform::GetPlatform() {
|
||||
if (!gPlatform) {
|
||||
MOZ_RELEASE_ASSERT(!XRE_IsContentProcess(),
|
||||
"Content Process should have called InitChild() before "
|
||||
"first GetPlatform()");
|
||||
Init();
|
||||
}
|
||||
return gPlatform;
|
||||
}
|
||||
|
||||
bool gfxPlatform::Initialized() { return !!gPlatform; }
|
||||
|
||||
/* static */
|
||||
|
@ -812,9 +792,11 @@ void gfxPlatform::Init() {
|
|||
MOZ_RELEASE_ASSERT(!XRE_IsGPUProcess(), "GFX: Not allowed in GPU process.");
|
||||
MOZ_RELEASE_ASSERT(!XRE_IsRDDProcess(), "GFX: Not allowed in RDD process.");
|
||||
MOZ_RELEASE_ASSERT(NS_IsMainThread(), "GFX: Not in main thread.");
|
||||
|
||||
if (gEverInitialized) {
|
||||
MOZ_CRASH("Already started???");
|
||||
MOZ_RELEASE_ASSERT(!gEverInitialized);
|
||||
if (XRE_IsContentProcess()) {
|
||||
MOZ_RELEASE_ASSERT(gContentDeviceInitData,
|
||||
"Content Process should cal InitChild() before "
|
||||
"first GetPlatform()");
|
||||
}
|
||||
gEverInitialized = true;
|
||||
|
||||
|
@ -975,7 +957,7 @@ void gfxPlatform::Init() {
|
|||
|
||||
// Create the sRGB to output display profile transforms. They can be accessed
|
||||
// off the main thread so we want to avoid a race condition.
|
||||
InitializeCMS();
|
||||
gPlatform->InitializeCMS();
|
||||
|
||||
SkGraphics::Init();
|
||||
#ifdef MOZ_ENABLE_FREETYPE
|
||||
|
@ -1187,6 +1169,16 @@ int32_t gfxPlatform::MaxAllocSize() {
|
|||
StaticPrefs::gfx_max_alloc_size_AtStartup_DoNotUseDirectly());
|
||||
}
|
||||
|
||||
void gfxPlatform::MaybeInitializeCMS() {
|
||||
if (XRE_IsGPUProcess()) {
|
||||
// Colors in the GPU process should already be managed, so we don't need to
|
||||
// perform color management there.
|
||||
gCMSInitialized = true;
|
||||
return;
|
||||
}
|
||||
Unused << GetPlatform();
|
||||
}
|
||||
|
||||
/* static */
|
||||
void gfxPlatform::InitMoz2DLogging() {
|
||||
auto fwd = new CrashStatsLogForwarder(
|
||||
|
@ -1262,7 +1254,7 @@ void gfxPlatform::Shutdown() {
|
|||
gfxFontMissingGlyphs::Shutdown();
|
||||
|
||||
// Free the various non-null transforms and loaded profiles
|
||||
ShutdownCMS();
|
||||
gPlatform->ShutdownCMS();
|
||||
|
||||
Preferences::UnregisterPrefixCallbacks(FontPrefChanged, kObservedPrefs);
|
||||
|
||||
|
@ -2034,10 +2026,7 @@ bool gfxPlatform::OffMainThreadCompositingEnabled() {
|
|||
return UsesOffMainThreadCompositing();
|
||||
}
|
||||
|
||||
void gfxPlatform::SetCMSModeOverride(CMSMode aMode) {
|
||||
MOZ_ASSERT(gCMSInitialized);
|
||||
gCMSMode = aMode;
|
||||
}
|
||||
void gfxPlatform::SetCMSModeOverride(CMSMode aMode) { gCMSMode = aMode; }
|
||||
|
||||
int gfxPlatform::GetRenderingIntent() {
|
||||
// StaticPrefList.yaml is using 0 as the default for the rendering
|
||||
|
@ -2099,12 +2088,8 @@ nsTArray<uint8_t> gfxPlatform::GetPrefCMSOutputProfileData() {
|
|||
return result;
|
||||
}
|
||||
|
||||
const mozilla::gfx::ContentDeviceData* gfxPlatform::GetInitContentDeviceData() {
|
||||
return gContentDeviceInitData;
|
||||
}
|
||||
|
||||
Maybe<nsTArray<uint8_t>>& gfxPlatform::GetCMSOutputProfileData() {
|
||||
return gCMSOutputProfileData;
|
||||
return mCMSOutputProfileData;
|
||||
}
|
||||
|
||||
CMSMode GfxColorManagementMode() {
|
||||
|
@ -2116,26 +2101,10 @@ CMSMode GfxColorManagementMode() {
|
|||
}
|
||||
|
||||
void gfxPlatform::InitializeCMS() {
|
||||
if (gCMSInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (XRE_IsGPUProcess()) {
|
||||
// Colors in the GPU process should already be managed, so we don't need to
|
||||
// perform color management there.
|
||||
gCMSInitialized = true;
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread(),
|
||||
"CMS should be initialized on the main thread");
|
||||
if (MOZ_UNLIKELY(!NS_IsMainThread())) {
|
||||
return;
|
||||
}
|
||||
|
||||
gCMSInitialized = true;
|
||||
gCMSMode = GfxColorManagementMode();
|
||||
|
||||
gCMSsRGBProfile = qcms_profile_sRGB();
|
||||
mCMSsRGBProfile = qcms_profile_sRGB();
|
||||
|
||||
/* Determine if we're using the internal override to force sRGB as
|
||||
an output profile for reftests. See Bug 452125.
|
||||
|
@ -2146,53 +2115,52 @@ void gfxPlatform::InitializeCMS() {
|
|||
*/
|
||||
if (StaticPrefs::gfx_color_management_force_srgb() ||
|
||||
StaticPrefs::gfx_color_management_native_srgb()) {
|
||||
gCMSOutputProfile = gCMSsRGBProfile;
|
||||
mCMSOutputProfile = mCMSsRGBProfile;
|
||||
}
|
||||
|
||||
if (!gCMSOutputProfile) {
|
||||
nsTArray<uint8_t> outputProfileData =
|
||||
gfxPlatform::GetPlatform()->GetPlatformCMSOutputProfileData();
|
||||
if (!mCMSOutputProfile) {
|
||||
nsTArray<uint8_t> outputProfileData = GetPlatformCMSOutputProfileData();
|
||||
if (!outputProfileData.IsEmpty()) {
|
||||
gCMSOutputProfile = qcms_profile_from_memory_curves_only(
|
||||
mCMSOutputProfile = qcms_profile_from_memory_curves_only(
|
||||
outputProfileData.Elements(), outputProfileData.Length());
|
||||
}
|
||||
}
|
||||
|
||||
/* 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 != gCMSsRGBProfile,
|
||||
if (mCMSOutputProfile && qcms_profile_is_bogus(mCMSOutputProfile)) {
|
||||
NS_ASSERTION(mCMSOutputProfile != mCMSsRGBProfile,
|
||||
"Builtin sRGB profile tagged as bogus!!!");
|
||||
qcms_profile_release(gCMSOutputProfile);
|
||||
gCMSOutputProfile = nullptr;
|
||||
qcms_profile_release(mCMSOutputProfile);
|
||||
mCMSOutputProfile = nullptr;
|
||||
}
|
||||
|
||||
if (!gCMSOutputProfile) {
|
||||
gCMSOutputProfile = gCMSsRGBProfile;
|
||||
if (!mCMSOutputProfile) {
|
||||
mCMSOutputProfile = mCMSsRGBProfile;
|
||||
}
|
||||
|
||||
/* Precache the LUT16 Interpolations for the output profile. See
|
||||
bug 444661 for details. */
|
||||
qcms_profile_precache_output_transform(gCMSOutputProfile);
|
||||
qcms_profile_precache_output_transform(mCMSOutputProfile);
|
||||
|
||||
// Create the RGB transform.
|
||||
gCMSRGBTransform =
|
||||
qcms_transform_create(gCMSsRGBProfile, QCMS_DATA_RGB_8, gCMSOutputProfile,
|
||||
mCMSRGBTransform =
|
||||
qcms_transform_create(mCMSsRGBProfile, QCMS_DATA_RGB_8, mCMSOutputProfile,
|
||||
QCMS_DATA_RGB_8, QCMS_INTENT_PERCEPTUAL);
|
||||
|
||||
// And the inverse.
|
||||
gCMSInverseRGBTransform =
|
||||
qcms_transform_create(gCMSOutputProfile, QCMS_DATA_RGB_8, gCMSsRGBProfile,
|
||||
mCMSInverseRGBTransform =
|
||||
qcms_transform_create(mCMSOutputProfile, QCMS_DATA_RGB_8, mCMSsRGBProfile,
|
||||
QCMS_DATA_RGB_8, QCMS_INTENT_PERCEPTUAL);
|
||||
|
||||
// The RGBA transform.
|
||||
gCMSRGBATransform = qcms_transform_create(gCMSsRGBProfile, QCMS_DATA_RGBA_8,
|
||||
gCMSOutputProfile, QCMS_DATA_RGBA_8,
|
||||
mCMSRGBATransform = qcms_transform_create(mCMSsRGBProfile, QCMS_DATA_RGBA_8,
|
||||
mCMSOutputProfile, QCMS_DATA_RGBA_8,
|
||||
QCMS_INTENT_PERCEPTUAL);
|
||||
|
||||
// And the BGRA one.
|
||||
gCMSBGRATransform = qcms_transform_create(gCMSsRGBProfile, QCMS_DATA_BGRA_8,
|
||||
gCMSOutputProfile, QCMS_DATA_BGRA_8,
|
||||
mCMSBGRATransform = qcms_transform_create(mCMSsRGBProfile, QCMS_DATA_BGRA_8,
|
||||
mCMSOutputProfile, QCMS_DATA_BGRA_8,
|
||||
QCMS_INTENT_PERCEPTUAL);
|
||||
|
||||
// FIXME: We only enable iccv4 after we create the platform profile, to
|
||||
|
@ -2202,8 +2170,6 @@ void gfxPlatform::InitializeCMS() {
|
|||
if (StaticPrefs::gfx_color_management_enablev4()) {
|
||||
qcms_enable_iccv4();
|
||||
}
|
||||
|
||||
gCMSInitialized = true;
|
||||
}
|
||||
|
||||
qcms_transform* gfxPlatform::GetCMSOSRGBATransform() {
|
||||
|
@ -2232,39 +2198,38 @@ qcms_data_type gfxPlatform::GetCMSOSRGBAType() {
|
|||
|
||||
/* Shuts down various transforms and profiles for CMS. */
|
||||
void gfxPlatform::ShutdownCMS() {
|
||||
if (gCMSRGBTransform) {
|
||||
qcms_transform_release(gCMSRGBTransform);
|
||||
gCMSRGBTransform = nullptr;
|
||||
if (mCMSRGBTransform) {
|
||||
qcms_transform_release(mCMSRGBTransform);
|
||||
mCMSRGBTransform = nullptr;
|
||||
}
|
||||
if (gCMSInverseRGBTransform) {
|
||||
qcms_transform_release(gCMSInverseRGBTransform);
|
||||
gCMSInverseRGBTransform = nullptr;
|
||||
if (mCMSInverseRGBTransform) {
|
||||
qcms_transform_release(mCMSInverseRGBTransform);
|
||||
mCMSInverseRGBTransform = nullptr;
|
||||
}
|
||||
if (gCMSRGBATransform) {
|
||||
qcms_transform_release(gCMSRGBATransform);
|
||||
gCMSRGBATransform = nullptr;
|
||||
if (mCMSRGBATransform) {
|
||||
qcms_transform_release(mCMSRGBATransform);
|
||||
mCMSRGBATransform = nullptr;
|
||||
}
|
||||
if (gCMSBGRATransform) {
|
||||
qcms_transform_release(gCMSBGRATransform);
|
||||
gCMSBGRATransform = nullptr;
|
||||
if (mCMSBGRATransform) {
|
||||
qcms_transform_release(mCMSBGRATransform);
|
||||
mCMSBGRATransform = nullptr;
|
||||
}
|
||||
if (gCMSOutputProfile) {
|
||||
qcms_profile_release(gCMSOutputProfile);
|
||||
|
||||
if (mCMSOutputProfile) {
|
||||
// handle the aliased case
|
||||
if (gCMSsRGBProfile == gCMSOutputProfile) {
|
||||
gCMSsRGBProfile = nullptr;
|
||||
if (mCMSsRGBProfile == mCMSOutputProfile) {
|
||||
mCMSsRGBProfile = nullptr;
|
||||
}
|
||||
gCMSOutputProfile = nullptr;
|
||||
|
||||
qcms_profile_release(mCMSOutputProfile);
|
||||
mCMSOutputProfile = nullptr;
|
||||
}
|
||||
if (gCMSsRGBProfile) {
|
||||
qcms_profile_release(gCMSsRGBProfile);
|
||||
gCMSsRGBProfile = nullptr;
|
||||
if (mCMSsRGBProfile) {
|
||||
qcms_profile_release(mCMSsRGBProfile);
|
||||
mCMSsRGBProfile = nullptr;
|
||||
}
|
||||
|
||||
// Reset the state variables
|
||||
gCMSMode = CMSMode::Off;
|
||||
gCMSInitialized = false;
|
||||
}
|
||||
|
||||
uint32_t gfxPlatform::GetBidiNumeralOption() {
|
||||
|
@ -4016,8 +3981,7 @@ void gfxPlatform::ImportContentDeviceData(
|
|||
// We don't inherit Feature::OPENGL_COMPOSITING here, because platforms
|
||||
// will handle that (without imported data from the parent) in
|
||||
// InitOpenGLConfig.
|
||||
|
||||
gCMSOutputProfileData = Some(aData.cmsOutputProfileData().Clone());
|
||||
mCMSOutputProfileData = Some(aData.cmsOutputProfileData().Clone());
|
||||
}
|
||||
|
||||
void gfxPlatform::BuildContentDeviceData(
|
||||
|
@ -4062,8 +4026,9 @@ bool gfxPlatform::SupportsApzZooming() const {
|
|||
|
||||
void gfxPlatform::InitOpenGLConfig() {
|
||||
#ifdef XP_WIN
|
||||
// Don't enable by default on Windows, since it could show up in about:support
|
||||
// even though it'll never get used. Only attempt if user enables the pref
|
||||
// Don't enable by default on Windows, since it could show up in
|
||||
// about:support even though it'll never get used. Only attempt if user
|
||||
// enables the pref
|
||||
if (!Preferences::GetBool("layers.prefer-opengl")) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -177,7 +177,12 @@ class gfxPlatform : public mozilla::layers::MemoryPressureListener {
|
|||
* This is a singleton; it contains mostly convenience
|
||||
* functions to obtain platform-specific objects.
|
||||
*/
|
||||
static gfxPlatform* GetPlatform();
|
||||
static gfxPlatform* GetPlatform() {
|
||||
if (MOZ_UNLIKELY(!gPlatform)) {
|
||||
Init();
|
||||
}
|
||||
return gPlatform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not graphics has been initialized yet. This is
|
||||
|
@ -493,6 +498,13 @@ class gfxPlatform : public mozilla::layers::MemoryPressureListener {
|
|||
|
||||
void UpdateCanUseHardwareVideoDecoding();
|
||||
|
||||
inline static void EnsureCMSInitialized() {
|
||||
if (MOZ_UNLIKELY(!gCMSInitialized)) {
|
||||
MaybeInitializeCMS();
|
||||
MOZ_ASSERT(gCMSInitialized);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Are we going to try color management?
|
||||
*/
|
||||
|
@ -528,48 +540,42 @@ class gfxPlatform : public mozilla::layers::MemoryPressureListener {
|
|||
* Return the output device ICC profile.
|
||||
*/
|
||||
static qcms_profile* GetCMSOutputProfile() {
|
||||
EnsureCMSInitialized();
|
||||
return gCMSOutputProfile;
|
||||
return GetPlatform()->mCMSOutputProfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the sRGB ICC profile.
|
||||
*/
|
||||
static qcms_profile* GetCMSsRGBProfile() {
|
||||
EnsureCMSInitialized();
|
||||
return gCMSsRGBProfile;
|
||||
return GetPlatform()->mCMSsRGBProfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return sRGB -> output device transform.
|
||||
*/
|
||||
static qcms_transform* GetCMSRGBTransform() {
|
||||
EnsureCMSInitialized();
|
||||
return gCMSRGBTransform;
|
||||
return GetPlatform()->mCMSRGBTransform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return output -> sRGB device transform.
|
||||
*/
|
||||
static qcms_transform* GetCMSInverseRGBTransform() {
|
||||
MOZ_ASSERT(gCMSInitialized);
|
||||
return gCMSInverseRGBTransform;
|
||||
return GetPlatform()->mCMSInverseRGBTransform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return sRGBA -> output device transform.
|
||||
*/
|
||||
static qcms_transform* GetCMSRGBATransform() {
|
||||
MOZ_ASSERT(gCMSInitialized);
|
||||
return gCMSRGBATransform;
|
||||
return GetPlatform()->mCMSRGBATransform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return sBGRA -> output device transform.
|
||||
*/
|
||||
static qcms_transform* GetCMSBGRATransform() {
|
||||
MOZ_ASSERT(gCMSInitialized);
|
||||
return gCMSBGRATransform;
|
||||
return GetPlatform()->mCMSBGRATransform;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -854,16 +860,6 @@ class gfxPlatform : public mozilla::layers::MemoryPressureListener {
|
|||
static nsTArray<uint8_t> GetPrefCMSOutputProfileData();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* If inside a child process and currently being initialized by the
|
||||
* SetXPCOMProcessAttributes message, this can be used by subclasses to
|
||||
* retrieve the ContentDeviceData passed by the message
|
||||
*
|
||||
* If not currently being initialized, will return nullptr. In this case,
|
||||
* child should send a sync message to ask parent for color profile
|
||||
*/
|
||||
const mozilla::gfx::ContentDeviceData* GetInitContentDeviceData();
|
||||
|
||||
/**
|
||||
* If inside a child process and have ever received a
|
||||
* SetXPCOMProcessAttributes message, this contains the cmsOutputProfileData
|
||||
|
@ -935,27 +931,10 @@ class gfxPlatform : public mozilla::layers::MemoryPressureListener {
|
|||
|
||||
static void InitOpenGLConfig();
|
||||
|
||||
static mozilla::Atomic<bool, mozilla::MemoryOrdering::ReleaseAcquire>
|
||||
gCMSInitialized;
|
||||
static CMSMode gCMSMode;
|
||||
static gfxPlatform* gPlatform;
|
||||
|
||||
// These two may point to the same profile
|
||||
static qcms_profile* gCMSOutputProfile;
|
||||
static qcms_profile* gCMSsRGBProfile;
|
||||
|
||||
static qcms_transform* gCMSRGBTransform;
|
||||
static qcms_transform* gCMSInverseRGBTransform;
|
||||
static qcms_transform* gCMSRGBATransform;
|
||||
static qcms_transform* gCMSBGRATransform;
|
||||
|
||||
inline static void EnsureCMSInitialized() {
|
||||
if (MOZ_UNLIKELY(!gCMSInitialized)) {
|
||||
InitializeCMS();
|
||||
}
|
||||
}
|
||||
|
||||
static void InitializeCMS();
|
||||
static void ShutdownCMS();
|
||||
void InitializeCMS();
|
||||
void ShutdownCMS();
|
||||
|
||||
/**
|
||||
* This uses nsIScreenManager to determine the primary screen color depth
|
||||
|
@ -974,6 +953,23 @@ class gfxPlatform : public mozilla::layers::MemoryPressureListener {
|
|||
static bool IsDXP010Blocked();
|
||||
static bool IsDXP016Blocked();
|
||||
|
||||
static void MaybeInitializeCMS();
|
||||
|
||||
// We need these to be static because we might call them in the GPU process,
|
||||
// even if we don't do color management there.
|
||||
static mozilla::Atomic<bool, mozilla::ReleaseAcquire> gCMSInitialized;
|
||||
static CMSMode gCMSMode;
|
||||
|
||||
// These two may point to the same profile
|
||||
qcms_profile* mCMSOutputProfile = nullptr;
|
||||
qcms_profile* mCMSsRGBProfile = nullptr;
|
||||
|
||||
qcms_transform* mCMSRGBTransform = nullptr;
|
||||
qcms_transform* mCMSInverseRGBTransform = nullptr;
|
||||
qcms_transform* mCMSRGBATransform = nullptr;
|
||||
qcms_transform* mCMSBGRATransform = nullptr;
|
||||
mozilla::Maybe<nsTArray<uint8_t>> mCMSOutputProfileData;
|
||||
|
||||
RefPtr<gfxASurface> mScreenReferenceSurface;
|
||||
RefPtr<mozilla::layers::MemoryPressureObserver> mMemoryPressureObserver;
|
||||
|
||||
|
|
|
@ -373,9 +373,6 @@ void gfxWindowsPlatform::InitAcceleration() {
|
|||
|
||||
DeviceManagerDx::Init();
|
||||
|
||||
// Content processes should have received content device data from parent.
|
||||
MOZ_ASSERT_IF(XRE_IsContentProcess(), GetInitContentDeviceData());
|
||||
|
||||
InitializeConfig();
|
||||
InitGPUProcessSupport();
|
||||
// Ensure devices initialization. SharedSurfaceANGLE and
|
||||
|
|
Загрузка…
Ссылка в новой задаче