Bug 1490537 - init and shutdown Skia in the GPU process. r=mattwoodrow

This commit is contained in:
Lee Salzman 2018-11-29 18:09:46 -05:00
parent 6fba94b2f0
commit a5f6c68080
4 changed files with 29 additions and 33 deletions

View File

@ -1865,7 +1865,7 @@ public:
private: private:
static FT_Library mFTLibrary; static FT_Library mFTLibrary;
static Mutex* mFTLock; static StaticMutex mFTLock;
public: public:
#endif #endif

View File

@ -46,7 +46,6 @@
#include <d3d10_1.h> #include <d3d10_1.h>
#include "HelpersD2D.h" #include "HelpersD2D.h"
#include "HelpersWinFonts.h" #include "HelpersWinFonts.h"
#include "mozilla/Mutex.h"
#endif #endif
#include "DrawTargetCapture.h" #include "DrawTargetCapture.h"
@ -67,8 +66,6 @@
#ifdef MOZ_ENABLE_FREETYPE #ifdef MOZ_ENABLE_FREETYPE
#include "ft2build.h" #include "ft2build.h"
#include FT_FREETYPE_H #include FT_FREETYPE_H
#include "mozilla/Mutex.h"
#endif #endif
#include "MainThreadUtils.h" #include "MainThreadUtils.h"
@ -219,7 +216,7 @@ int32_t LoggingPrefs::sGfxLogLevel = LOG_DEFAULT;
#ifdef MOZ_ENABLE_FREETYPE #ifdef MOZ_ENABLE_FREETYPE
FT_Library Factory::mFTLibrary = nullptr; FT_Library Factory::mFTLibrary = nullptr;
Mutex* Factory::mFTLock = nullptr; StaticMutex Factory::mFTLock;
#endif #endif
#ifdef WIN32 #ifdef WIN32
@ -243,10 +240,6 @@ Factory::Init(const Config& aConfig)
{ {
MOZ_ASSERT(!sConfig); MOZ_ASSERT(!sConfig);
sConfig = new Config(aConfig); sConfig = new Config(aConfig);
#ifdef MOZ_ENABLE_FREETYPE
mFTLock = new Mutex("Factory::mFTLock");
#endif
} }
void void
@ -260,10 +253,6 @@ Factory::ShutDown()
#ifdef MOZ_ENABLE_FREETYPE #ifdef MOZ_ENABLE_FREETYPE
mFTLibrary = nullptr; mFTLibrary = nullptr;
if (mFTLock) {
delete mFTLock;
mFTLock = nullptr;
}
#endif #endif
} }
@ -764,22 +753,19 @@ Factory::ReleaseFTLibrary(FT_Library aFTLibrary)
void void
Factory::LockFTLibrary(FT_Library aFTLibrary) Factory::LockFTLibrary(FT_Library aFTLibrary)
{ {
MOZ_ASSERT(mFTLock); mFTLock.Lock();
mFTLock->Lock();
} }
void void
Factory::UnlockFTLibrary(FT_Library aFTLibrary) Factory::UnlockFTLibrary(FT_Library aFTLibrary)
{ {
MOZ_ASSERT(mFTLock); mFTLock.Unlock();
mFTLock->Unlock();
} }
FT_Face FT_Face
Factory::NewFTFace(FT_Library aFTLibrary, const char* aFileName, int aFaceIndex) Factory::NewFTFace(FT_Library aFTLibrary, const char* aFileName, int aFaceIndex)
{ {
MOZ_ASSERT(mFTLock); StaticMutexAutoLock lock(mFTLock);
MutexAutoLock lock(*mFTLock);
if (!aFTLibrary) { if (!aFTLibrary) {
aFTLibrary = mFTLibrary; aFTLibrary = mFTLibrary;
} }
@ -793,8 +779,7 @@ Factory::NewFTFace(FT_Library aFTLibrary, const char* aFileName, int aFaceIndex)
FT_Face FT_Face
Factory::NewFTFaceFromData(FT_Library aFTLibrary, const uint8_t* aData, size_t aDataSize, int aFaceIndex) Factory::NewFTFaceFromData(FT_Library aFTLibrary, const uint8_t* aData, size_t aDataSize, int aFaceIndex)
{ {
MOZ_ASSERT(mFTLock); StaticMutexAutoLock lock(mFTLock);
MutexAutoLock lock(*mFTLock);
if (!aFTLibrary) { if (!aFTLibrary) {
aFTLibrary = mFTLibrary; aFTLibrary = mFTLibrary;
} }
@ -808,23 +793,14 @@ Factory::NewFTFaceFromData(FT_Library aFTLibrary, const uint8_t* aData, size_t a
void void
Factory::ReleaseFTFace(FT_Face aFace) Factory::ReleaseFTFace(FT_Face aFace)
{ {
// May be called during shutdown when the lock is already destroyed. StaticMutexAutoLock lock(mFTLock);
// However, there are no other threads using the face by this point,
// so it is safe to skip locking if the lock is not around.
if (mFTLock) {
mFTLock->Lock();
}
FT_Done_Face(aFace); FT_Done_Face(aFace);
if (mFTLock) {
mFTLock->Unlock();
}
} }
FT_Error FT_Error
Factory::LoadFTGlyph(FT_Face aFace, uint32_t aGlyphIndex, int32_t aFlags) Factory::LoadFTGlyph(FT_Face aFace, uint32_t aGlyphIndex, int32_t aFlags)
{ {
MOZ_ASSERT(mFTLock); StaticMutexAutoLock lock(mFTLock);
MutexAutoLock lock(*mFTLock);
return FT_Load_Glyph(aFace, aGlyphIndex, aFlags); return FT_Load_Glyph(aFace, aGlyphIndex, aFlags);
} }
#endif #endif
@ -1028,7 +1004,7 @@ Factory::CreateScaledFontForDWriteFont(IDWriteFontFace* aFontFace,
aStyle); aStyle);
} }
#endif // XP_WIN #endif // WIN32
#ifdef USE_SKIA_GPU #ifdef USE_SKIA_GPU
already_AddRefed<DrawTarget> already_AddRefed<DrawTarget>

View File

@ -38,6 +38,7 @@
#include "mozilla/webrender/RenderThread.h" #include "mozilla/webrender/RenderThread.h"
#include "mozilla/webrender/WebRenderAPI.h" #include "mozilla/webrender/WebRenderAPI.h"
#include "mozilla/HangDetails.h" #include "mozilla/HangDetails.h"
#include "nscore.h"
#include "nsDebugImpl.h" #include "nsDebugImpl.h"
#include "nsIGfxInfo.h" #include "nsIGfxInfo.h"
#include "nsThreadManager.h" #include "nsThreadManager.h"
@ -47,6 +48,8 @@
#include "VRManager.h" #include "VRManager.h"
#include "VRManagerParent.h" #include "VRManagerParent.h"
#include "VsyncBridgeParent.h" #include "VsyncBridgeParent.h"
#include "cairo.h"
#include "skia/include/core/SkGraphics.h"
#if defined(XP_WIN) #if defined(XP_WIN)
# include "mozilla/gfx/DeviceManagerDx.h" # include "mozilla/gfx/DeviceManagerDx.h"
# include <process.h> # include <process.h>
@ -54,6 +57,7 @@
#endif #endif
#ifdef MOZ_WIDGET_GTK #ifdef MOZ_WIDGET_GTK
# include <gtk/gtk.h> # include <gtk/gtk.h>
# include "skia/include/ports/SkTypeface_cairo.h"
#endif #endif
#ifdef MOZ_GECKO_PROFILER #ifdef MOZ_GECKO_PROFILER
#include "ChildProfilerController.h" #include "ChildProfilerController.h"
@ -220,6 +224,10 @@ GPUParent::RecvInit(nsTArray<GfxPrefSetting>&& prefs,
LayerTreeOwnerTracker::Get()->Map(map.layersId(), map.ownerId()); LayerTreeOwnerTracker::Get()->Map(map.layersId(), map.ownerId());
} }
// We bypass gfxPlatform::Init, so we must initialize any relevant libraries
// here that would normally be initialized there.
SkGraphics::Init();
#if defined(XP_WIN) #if defined(XP_WIN)
if (gfxConfig::IsEnabled(Feature::D3D11_COMPOSITING)) { if (gfxConfig::IsEnabled(Feature::D3D11_COMPOSITING)) {
DeviceManagerDx::Get()->CreateCompositorDevices(); DeviceManagerDx::Get()->CreateCompositorDevices();
@ -260,6 +268,8 @@ GPUParent::RecvInit(nsTArray<GfxPrefSetting>&& prefs,
FT_Library library = Factory::NewFTLibrary(); FT_Library library = Factory::NewFTLibrary();
MOZ_ASSERT(library); MOZ_ASSERT(library);
Factory::SetFTLibrary(library); Factory::SetFTLibrary(library);
SkInitCairoFT(true);
} }
#endif #endif
@ -552,6 +562,14 @@ GPUParent::ActorDestroy(ActorDestroyReason aWhy)
#endif #endif
Factory::ShutDown(); Factory::ShutDown();
// We bypass gfxPlatform shutdown, so we must shutdown any libraries here
// that would normally be handled by it.
#ifdef NS_FREE_PERMANENT_DATA
SkGraphics::PurgeFontCache();
cairo_debug_reset_static_data();
#endif
#if defined(XP_WIN) #if defined(XP_WIN)
DeviceManagerDx::Shutdown(); DeviceManagerDx::Shutdown();
#endif #endif

View File

@ -86,3 +86,5 @@ FINAL_LIBRARY = 'xul'
CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS'] CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS']
CXXFLAGS += CONFIG['TK_CFLAGS'] CXXFLAGS += CONFIG['TK_CFLAGS']
LOCAL_INCLUDES += CONFIG['SKIA_INCLUDES']