Bug 1688833 - Migrate LookupForAdd to WithEntryHandle in gfx. r=jgilbert

Differential Revision: https://phabricator.services.mozilla.com/D104216
This commit is contained in:
Simon Giesecke 2021-02-09 18:19:40 +00:00
parent 010633d2d1
commit 8df74b1582
3 changed files with 31 additions and 29 deletions

View File

@ -868,8 +868,10 @@ EGLSurface GLContextEGL::CreateWaylandBufferSurface(
if (surface) {
#ifdef MOZ_GTK_WAYLAND
WaylandGLSurface* waylandData = new WaylandGLSurface(wlsurface, eglwindow);
auto entry = sWaylandGLSurface.LookupForAdd(surface);
entry.OrInsert([&waylandData]() { return waylandData; });
// XXX This looks as if this should unconditionally insert. Otherwise,
// waylandData would be leaked.
sWaylandGLSurface.WithEntryHandle(
surface, [&](auto&& entry) { entry.OrInsert(waylandData); });
#endif
}

View File

@ -835,29 +835,28 @@ TextureClient* SourceSurfaceImage::GetTextureClient(
return nullptr;
}
auto entry = mTextureClients.LookupForAdd(aKnowsCompositor->GetSerial());
if (entry) {
return entry.Data();
}
return mTextureClients.WithEntryHandle(
aKnowsCompositor->GetSerial(), [&](auto&& entry) -> TextureClient* {
if (entry) {
return entry.Data().get();
}
RefPtr<TextureClient> textureClient;
RefPtr<SourceSurface> surface = GetAsSourceSurface();
MOZ_ASSERT(surface);
if (surface) {
// gfx::BackendType::NONE means default to content backend
textureClient = TextureClient::CreateFromSurface(
aKnowsCompositor, surface, BackendSelector::Content, mTextureFlags,
ALLOC_DEFAULT);
}
if (textureClient) {
textureClient->SyncWithObject(aKnowsCompositor->GetSyncObject());
entry.OrInsert([&textureClient]() { return textureClient; });
return textureClient;
}
RefPtr<TextureClient> textureClient;
RefPtr<SourceSurface> surface = GetAsSourceSurface();
MOZ_ASSERT(surface);
if (surface) {
// gfx::BackendType::NONE means default to content backend
textureClient = TextureClient::CreateFromSurface(
aKnowsCompositor, surface, BackendSelector::Content,
mTextureFlags, ALLOC_DEFAULT);
}
if (textureClient) {
textureClient->SyncWithObject(aKnowsCompositor->GetSyncObject());
return entry.Insert(std::move(textureClient)).get();
}
// Remove the speculatively added entry.
entry.OrRemove();
return nullptr;
return nullptr;
});
}
ImageContainer::ProducerID ImageContainer::AllocateProducerID() {

View File

@ -951,12 +951,13 @@ bool LayerTransactionParent::BindLayerToHandle(RefPtr<Layer> aLayer,
if (!aHandle || !aLayer) {
return false;
}
auto entry = mLayerMap.LookupForAdd(aHandle.Value());
if (entry) {
return false;
}
entry.OrInsert([&aLayer]() { return aLayer; });
return true;
return mLayerMap.WithEntryHandle(aHandle.Value(), [&](auto&& entry) {
if (entry) {
return false;
}
entry.Insert(std::move(aLayer));
return true;
});
}
Layer* LayerTransactionParent::AsLayer(const LayerHandle& aHandle) {