Bug 1418869 - Do not try to share the fallback images. r=aosmond
The flag of force update is only for fallback items. Fallback items can't share the images with other items.
So I replace 'aForceUpdate' with 'aFallback' and remove some unnecessary checks.
MozReview-Commit-ID: Dcu95FZXlUz
--- a/gfx/layers/ipc/SharedSurfacesChild.cpp
+++ b/gfx/layers/ipc/SharedSurfacesChild.cpp
@@ -87,17 +87,16 @@ public:
void MarkShared()
{
MOZ_ASSERT(!mShared);
mShared = true;
}
wr::ImageKey UpdateKey(WebRenderLayerManager* aManager,
wr::IpcResourceUpdateQueue& aResources,
- bool aForceUpdate,
uint32_t aGenerationId)
{
MOZ_ASSERT(aManager);
MOZ_ASSERT(!aManager->IsDestroyed());
// We iterate through all of the items to ensure we clean up the old
// WebRenderLayerManager references. Most of the time there will be few
// entries and this should not be particularly expensive compared to the
@@ -109,17 +108,17 @@ public:
auto i = mKeys.Length();
while (i > 0) {
--i;
ImageKeyData& entry = mKeys[i];
if (entry.mManager->IsDestroyed()) {
mKeys.RemoveElementAt(i);
} else if (entry.mManager == aManager) {
found = true;
- if (aForceUpdate || entry.mGenerationId != aGenerationId) {
+ if (entry.mGenerationId != aGenerationId) {
aManager->AddImageKeyForDiscard(entry.mImageKey);
entry.mGenerationId = aGenerationId;
entry.mImageKey = aManager->WrBridge()->GetNextImageKey();
aResources.AddExternalImage(mId, entry.mImageKey);
}
key = entry.mImageKey;
}
}
@@ -146,17 +145,16 @@ SharedSurfacesChild::DestroySharedUserDa
auto data = static_cast<SharedUserData*>(aClosure);
delete data;
}
/* static */ nsresult
SharedSurfacesChild::Share(SourceSurfaceSharedData* aSurface,
WebRenderLayerManager* aManager,
wr::IpcResourceUpdateQueue& aResources,
- bool aForceUpdate,
uint32_t aGenerationId,
wr::ImageKey& aKey)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aSurface);
MOZ_ASSERT(aManager);
CompositorManagerChild* manager = CompositorManagerChild::GetInstance();
@@ -171,17 +169,17 @@ SharedSurfacesChild::Share(SourceSurface
data = new SharedUserData(manager->GetNextExternalImageId());
aSurface->AddUserData(&sSharedKey, data, DestroySharedUserData);
} else if (!manager->OwnsExternalImageId(data->Id())) {
// If the id isn't owned by us, that means the bridge was reinitialized, due
// to the GPU process crashing. All previous mappings have been released.
data->SetId(manager->GetNextExternalImageId());
} else if (data->IsShared()) {
// It has already been shared with the GPU process, reuse the id.
- aKey = data->UpdateKey(aManager, aResources, aForceUpdate, aGenerationId);
+ aKey = data->UpdateKey(aManager, aResources, aGenerationId);
return NS_OK;
}
// Ensure that the handle doesn't get released until after we have finished
// sending the buffer to the GPU process and/or reallocating it.
// FinishedSharing is not a sufficient condition because another thread may
// decide we are done while we are in the processing of sharing our newly
// reallocated handle. Once it goes out of scope, it may release the handle.
@@ -189,17 +187,17 @@ SharedSurfacesChild::Share(SourceSurface
// If we live in the same process, then it is a simple matter of directly
// asking the parent instance to store a pointer to the same data, no need
// to map the data into our memory space twice.
auto pid = manager->OtherPid();
if (pid == base::GetCurrentProcId()) {
SharedSurfacesParent::AddSameProcess(data->Id(), aSurface);
data->MarkShared();
- aKey = data->UpdateKey(aManager, aResources, aForceUpdate, aGenerationId);
+ aKey = data->UpdateKey(aManager, aResources, aGenerationId);
return NS_OK;
}
// Attempt to share a handle with the GPU process. The handle may or may not
// be available -- it will only be available if it is either not yet finalized
// and/or if it has been finalized but never used for drawing in process.
ipc::SharedMemoryBasic::Handle handle = ipc::SharedMemoryBasic::NULLHandle();
nsresult rv = aSurface->ShareToProcess(pid, handle);
@@ -224,25 +222,24 @@ SharedSurfacesChild::Share(SourceSurface
MOZ_RELEASE_ASSERT(format == SurfaceFormat::B8G8R8X8 ||
format == SurfaceFormat::B8G8R8A8, "bad format");
data->MarkShared();
manager->SendAddSharedSurface(data->Id(),
SurfaceDescriptorShared(aSurface->GetSize(),
aSurface->Stride(),
format, handle));
- aKey = data->UpdateKey(aManager, aResources, aForceUpdate, aGenerationId);
+ aKey = data->UpdateKey(aManager, aResources, aGenerationId);
return NS_OK;
}
/* static */ nsresult
SharedSurfacesChild::Share(ImageContainer* aContainer,
WebRenderLayerManager* aManager,
wr::IpcResourceUpdateQueue& aResources,
- bool aForceUpdate,
wr::ImageKey& aKey)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aContainer);
MOZ_ASSERT(aManager);
if (aContainer->IsAsync()) {
return NS_ERROR_NOT_IMPLEMENTED;
@@ -261,17 +258,17 @@ SharedSurfacesChild::Share(ImageContaine
}
if (surface->GetType() != SurfaceType::DATA_SHARED) {
return NS_ERROR_NOT_IMPLEMENTED;
}
auto sharedSurface = static_cast<SourceSurfaceSharedData*>(surface.get());
return Share(sharedSurface, aManager, aResources,
- aForceUpdate, generation, aKey);
+ generation, aKey);
}
/* static */ void
SharedSurfacesChild::Unshare(const wr::ExternalImageId& aId,
nsTArray<ImageKeyData>& aKeys)
{
MOZ_ASSERT(NS_IsMainThread());
--- a/gfx/layers/ipc/SharedSurfacesChild.h
+++ b/gfx/layers/ipc/SharedSurfacesChild.h
@@ -28,24 +28,22 @@ class CompositorManagerChild;
class WebRenderLayerManager;
class SharedSurfacesChild final
{
public:
static nsresult Share(gfx::SourceSurfaceSharedData* aSurface,
WebRenderLayerManager* aManager,
wr::IpcResourceUpdateQueue& aResources,
- bool aForceUpdate,
uint32_t aGenerationId,
wr::ImageKey& aKey);
static nsresult Share(ImageContainer* aContainer,
WebRenderLayerManager* aManager,
wr::IpcResourceUpdateQueue& aResources,
- bool aForceUpdate,
wr::ImageKey& aKey);
private:
SharedSurfacesChild() = delete;
~SharedSurfacesChild() = delete;
class ImageKeyData;
class SharedUserData;
--- a/gfx/layers/wr/WebRenderUserData.cpp
+++ b/gfx/layers/wr/WebRenderUserData.cpp
@@ -88,40 +88,41 @@ WebRenderImageData::ClearCachedResources
WrBridge()->RemovePipelineIdForCompositable(mPipelineId.ref());
mPipelineId.reset();
}
}
Maybe<wr::ImageKey>
WebRenderImageData::UpdateImageKey(ImageContainer* aContainer,
wr::IpcResourceUpdateQueue& aResources,
- bool aForceUpdate)
+ bool aFallback)
{
MOZ_ASSERT(aContainer);
if (mContainer != aContainer) {
mContainer = aContainer;
}
wr::WrImageKey key;
- nsresult rv = SharedSurfacesChild::Share(aContainer, mWRManager, aResources,
- aForceUpdate, key);
- if (NS_SUCCEEDED(rv)) {
- // Ensure that any previously owned keys are released before replacing. We
- // don't own this key, the surface itself owns it, so that it can be shared
- // across multiple elements.
- ClearImageKey();
- mKey = Some(key);
- return mKey;
- }
+ if (!aFallback) {
+ nsresult rv = SharedSurfacesChild::Share(aContainer, mWRManager, aResources, key);
+ if (NS_SUCCEEDED(rv)) {
+ // Ensure that any previously owned keys are released before replacing. We
+ // don't own this key, the surface itself owns it, so that it can be shared
+ // across multiple elements.
+ ClearImageKey();
+ mKey = Some(key);
+ return mKey;
+ }
- if (rv != NS_ERROR_NOT_IMPLEMENTED) {
- // We should be using the shared surface but somehow sharing it failed.
- ClearImageKey();
- return Nothing();
+ if (rv != NS_ERROR_NOT_IMPLEMENTED) {
+ // We should be using the shared surface but somehow sharing it failed.
+ ClearImageKey();
+ return Nothing();
+ }
}
CreateImageClientIfNeeded();
CreateExternalImageIfNeeded();
if (!mImageClient || !mExternalImageId) {
return Nothing();
}
@@ -134,17 +135,17 @@ WebRenderImageData::UpdateImageKey(Image
bool ret = imageClient->UpdateImage(aContainer, /* unused */0);
if (!ret || imageClient->IsEmpty()) {
// Delete old key
ClearImageKey();
return Nothing();
}
// Reuse old key if generation is not updated.
- if (!aForceUpdate && oldCounter == imageClient->GetLastUpdateGenerationCounter() && mKey) {
+ if (!aFallback && oldCounter == imageClient->GetLastUpdateGenerationCounter() && mKey) {
return mKey;
}
// Delete old key, we are generating a new key.
// TODO(nical): noooo... we need to reuse image keys.
if (mKey) {
mWRManager->AddImageKeyForDiscard(mKey.value());
}
--- a/gfx/layers/wr/WebRenderUserData.h
+++ b/gfx/layers/wr/WebRenderUserData.h
@@ -80,17 +80,17 @@ public:
virtual UserDataType GetType() override { return UserDataType::eImage; }
static UserDataType Type() { return UserDataType::eImage; }
Maybe<wr::ImageKey> GetKey() { return mKey; }
void SetKey(const wr::ImageKey& aKey) { mKey = Some(aKey); }
already_AddRefed<ImageClient> GetImageClient();
Maybe<wr::ImageKey> UpdateImageKey(ImageContainer* aContainer,
wr::IpcResourceUpdateQueue& aResources,
- bool aForceUpdate = false);
+ bool aFallback = false);
void CreateAsyncImageWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
ImageContainer* aContainer,
const StackingContextHelper& aSc,
const LayoutDeviceRect& aBounds,
const LayoutDeviceRect& aSCBounds,
const gfx::Matrix4x4& aSCTransform,
const gfx::MaybeIntSize& aScaleToSize,