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:
static FT_Library mFTLibrary;
static Mutex* mFTLock;
static StaticMutex mFTLock;
public:
#endif

View File

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

View File

@ -38,6 +38,7 @@
#include "mozilla/webrender/RenderThread.h"
#include "mozilla/webrender/WebRenderAPI.h"
#include "mozilla/HangDetails.h"
#include "nscore.h"
#include "nsDebugImpl.h"
#include "nsIGfxInfo.h"
#include "nsThreadManager.h"
@ -47,6 +48,8 @@
#include "VRManager.h"
#include "VRManagerParent.h"
#include "VsyncBridgeParent.h"
#include "cairo.h"
#include "skia/include/core/SkGraphics.h"
#if defined(XP_WIN)
# include "mozilla/gfx/DeviceManagerDx.h"
# include <process.h>
@ -54,6 +57,7 @@
#endif
#ifdef MOZ_WIDGET_GTK
# include <gtk/gtk.h>
# include "skia/include/ports/SkTypeface_cairo.h"
#endif
#ifdef MOZ_GECKO_PROFILER
#include "ChildProfilerController.h"
@ -220,6 +224,10 @@ GPUParent::RecvInit(nsTArray<GfxPrefSetting>&& prefs,
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 (gfxConfig::IsEnabled(Feature::D3D11_COMPOSITING)) {
DeviceManagerDx::Get()->CreateCompositorDevices();
@ -260,6 +268,8 @@ GPUParent::RecvInit(nsTArray<GfxPrefSetting>&& prefs,
FT_Library library = Factory::NewFTLibrary();
MOZ_ASSERT(library);
Factory::SetFTLibrary(library);
SkInitCairoFT(true);
}
#endif
@ -552,6 +562,14 @@ GPUParent::ActorDestroy(ActorDestroyReason aWhy)
#endif
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)
DeviceManagerDx::Shutdown();
#endif

View File

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