mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-24 02:35:41 +00:00
Bug 1448703 - clear blob image resources from clear_namespace hook. r=jrmuizel
This commit is contained in:
parent
d5091638e8
commit
47222b48e5
@ -44,11 +44,24 @@ using namespace gfx;
|
||||
namespace wr {
|
||||
|
||||
struct FontTemplate {
|
||||
const uint8_t *mData;
|
||||
const uint8_t* mData;
|
||||
size_t mSize;
|
||||
uint32_t mIndex;
|
||||
const VecU8 *mVec;
|
||||
const VecU8* mVec;
|
||||
RefPtr<UnscaledFont> mUnscaledFont;
|
||||
|
||||
FontTemplate()
|
||||
: mData(nullptr)
|
||||
, mSize(0)
|
||||
, mIndex(0)
|
||||
, mVec(nullptr)
|
||||
{}
|
||||
|
||||
~FontTemplate() {
|
||||
if (mVec) {
|
||||
wr_dec_ref_arc(mVec);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
StaticMutex sFontDataTableLock;
|
||||
@ -75,6 +88,10 @@ static struct FontDeleteLog {
|
||||
AddEntry(AsUint64(WrFontKey { aNamespace, 0 }));
|
||||
}
|
||||
|
||||
void AddAll() {
|
||||
AddEntry(0);
|
||||
}
|
||||
|
||||
// Find a matching entry in the log, searching backwards starting at the newest
|
||||
// entry and finishing with the oldest entry. Returns a brief description of why
|
||||
// the font was deleted, if known.
|
||||
@ -88,21 +105,28 @@ static struct FontDeleteLog {
|
||||
return "deleted font";
|
||||
} else if (mEntries[offset] == namespaceEntry) {
|
||||
return "cleared namespace";
|
||||
} else if (!mEntries[offset]) {
|
||||
return "cleared all";
|
||||
}
|
||||
} while (offset != mNextEntry);
|
||||
return "unknown font";
|
||||
}
|
||||
} sFontDeleteLog;
|
||||
|
||||
void
|
||||
ClearAllBlobImageResources() {
|
||||
StaticMutexAutoLock lock(sFontDataTableLock);
|
||||
sFontDeleteLog.AddAll();
|
||||
sFontDataTable.clear();
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
void
|
||||
ClearBlobImageResources(WrIdNamespace aNamespace) {
|
||||
StaticMutexAutoLock lock(sFontDataTableLock);
|
||||
sFontDeleteLog.Add(aNamespace);
|
||||
for (auto i = sFontDataTable.begin(); i != sFontDataTable.end();) {
|
||||
if (i->first.mNamespace == aNamespace) {
|
||||
if (i->second.mVec) {
|
||||
wr_dec_ref_arc(i->second.mVec);
|
||||
}
|
||||
i = sFontDataTable.erase(i);
|
||||
} else {
|
||||
i++;
|
||||
@ -110,18 +134,16 @@ ClearBlobImageResources(WrIdNamespace aNamespace) {
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
void
|
||||
AddFontData(WrFontKey aKey, const uint8_t *aData, size_t aSize, uint32_t aIndex, const ArcVecU8 *aVec) {
|
||||
StaticMutexAutoLock lock(sFontDataTableLock);
|
||||
auto i = sFontDataTable.find(aKey);
|
||||
if (i == sFontDataTable.end()) {
|
||||
FontTemplate font;
|
||||
FontTemplate& font = sFontDataTable[aKey];
|
||||
font.mData = aData;
|
||||
font.mSize = aSize;
|
||||
font.mIndex = aIndex;
|
||||
font.mVec = wr_add_ref_arc(aVec);
|
||||
sFontDataTable[aKey] = font;
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,11 +152,7 @@ AddNativeFontHandle(WrFontKey aKey, void* aHandle, uint32_t aIndex) {
|
||||
StaticMutexAutoLock lock(sFontDataTableLock);
|
||||
auto i = sFontDataTable.find(aKey);
|
||||
if (i == sFontDataTable.end()) {
|
||||
FontTemplate font;
|
||||
font.mData = nullptr;
|
||||
font.mSize = 0;
|
||||
font.mIndex = 0;
|
||||
font.mVec = nullptr;
|
||||
FontTemplate& font = sFontDataTable[aKey];
|
||||
#ifdef XP_MACOSX
|
||||
font.mUnscaledFont = new UnscaledFontMac(reinterpret_cast<CGFontRef>(aHandle), true);
|
||||
#elif defined(XP_WIN)
|
||||
@ -144,7 +162,6 @@ AddNativeFontHandle(WrFontKey aKey, void* aHandle, uint32_t aIndex) {
|
||||
#else
|
||||
font.mUnscaledFont = new UnscaledFontFontconfig(reinterpret_cast<const char*>(aHandle), aIndex);
|
||||
#endif
|
||||
sFontDataTable[aKey] = font;
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,9 +171,6 @@ DeleteFontData(WrFontKey aKey) {
|
||||
sFontDeleteLog.Add(aKey);
|
||||
auto i = sFontDataTable.find(aKey);
|
||||
if (i != sFontDataTable.end()) {
|
||||
if (i->second.mVec) {
|
||||
wr_dec_ref_arc(i->second.mVec);
|
||||
}
|
||||
sFontDataTable.erase(i);
|
||||
}
|
||||
}
|
||||
@ -171,7 +185,7 @@ GetUnscaledFont(Translator *aTranslator, wr::FontKey key) {
|
||||
<< " because " << sFontDeleteLog.Find(key);
|
||||
return nullptr;
|
||||
}
|
||||
auto &data = i->second;
|
||||
FontTemplate &data = i->second;
|
||||
if (data.mUnscaledFont) {
|
||||
return data.mUnscaledFont;
|
||||
}
|
||||
|
@ -97,6 +97,8 @@ RenderThread::ShutDown()
|
||||
#endif
|
||||
}
|
||||
|
||||
extern void ClearAllBlobImageResources();
|
||||
|
||||
void
|
||||
RenderThread::ShutDownTask(layers::SynchronousTask* aTask)
|
||||
{
|
||||
@ -106,6 +108,8 @@ RenderThread::ShutDownTask(layers::SynchronousTask* aTask)
|
||||
// Releasing on the render thread will allow us to avoid dispatching to remove
|
||||
// remaining textures from the texture map.
|
||||
layers::SharedSurfacesParent::Shutdown();
|
||||
|
||||
ClearAllBlobImageResources();
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -357,8 +357,6 @@ WebRenderAPI::GetNamespace() {
|
||||
return wr_api_get_namespace(mDocHandle);
|
||||
}
|
||||
|
||||
extern void ClearBlobImageResources(WrIdNamespace aNamespace);
|
||||
|
||||
WebRenderAPI::~WebRenderAPI()
|
||||
{
|
||||
if (!mRootDocumentApi) {
|
||||
@ -376,21 +374,6 @@ WebRenderAPI::~WebRenderAPI()
|
||||
wr_api_shut_down(mDocHandle);
|
||||
}
|
||||
|
||||
// wr_api_get_namespace cannot be marked destructor-safe because it has a
|
||||
// return value, and we can't call it if MOZ_BUILD_WEBRENDER is not defined
|
||||
// because it's not destructor-safe. So let's just ifdef around it. This is
|
||||
// basically a hack to get around compile-time warnings, this code never runs
|
||||
// unless MOZ_BUILD_WEBRENDER is defined anyway.
|
||||
#ifdef MOZ_BUILD_WEBRENDER
|
||||
wr::WrIdNamespace ns = GetNamespace();
|
||||
#else
|
||||
wr::WrIdNamespace ns{0};
|
||||
#endif
|
||||
|
||||
// Clean up any resources the blob image renderer is holding onto that
|
||||
// can no longer be used once this WR API instance goes away.
|
||||
ClearBlobImageResources(ns);
|
||||
|
||||
wr_api_delete(mDocHandle);
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ type WrEpoch = Epoch;
|
||||
/// cbindgen:derive-lt=true
|
||||
/// cbindgen:derive-lte=true
|
||||
/// cbindgen:derive-neq=true
|
||||
type WrIdNamespace = IdNamespace;
|
||||
pub type WrIdNamespace = IdNamespace;
|
||||
|
||||
/// cbindgen:field-names=[mNamespace, mHandle]
|
||||
type WrPipelineId = PipelineId;
|
||||
|
@ -494,17 +494,19 @@ impl BlobImageRenderer for Moz2dImageRenderer {
|
||||
fn delete_font_instance(&mut self, _key: FontInstanceKey) {
|
||||
}
|
||||
|
||||
fn clear_namespace(&mut self, _namespace: IdNamespace) {
|
||||
fn clear_namespace(&mut self, namespace: IdNamespace) {
|
||||
unsafe { ClearBlobImageResources(namespace); }
|
||||
}
|
||||
}
|
||||
|
||||
use bindings::WrFontKey;
|
||||
use bindings::{WrFontKey, WrIdNamespace};
|
||||
|
||||
#[allow(improper_ctypes)] // this is needed so that rustc doesn't complain about passing the &Arc<Vec> to an extern function
|
||||
extern "C" {
|
||||
fn AddFontData(key: WrFontKey, data: *const u8, size: usize, index: u32, vec: &ArcVecU8);
|
||||
fn AddNativeFontHandle(key: WrFontKey, handle: *mut c_void, index: u32);
|
||||
fn DeleteFontData(key: WrFontKey);
|
||||
fn ClearBlobImageResources(namespace: WrIdNamespace);
|
||||
}
|
||||
|
||||
impl Moz2dImageRenderer {
|
||||
|
Loading…
Reference in New Issue
Block a user