Skip to content

Commit

Permalink
Bug 1855742 - Part 3. Implement ImageBridgeChild::GetTileLockAllocato…
Browse files Browse the repository at this point in the history
…r. r=gfx-reviewers,lsalzman

This patch adds support for allocationg shmem sections for
ImageBridgeChild. The recording infrastructure depends on it.

Differential Revision: https://phabricator.services.mozilla.com/D189528
  • Loading branch information
aosmond committed Dec 19, 2023
1 parent d8fe0cd commit 370628c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions gfx/layers/ipc/ISurfaceAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ bool FixedSizeSmallShmemSectionAllocator::AllocShmemSection(
uint32_t aSize, ShmemSection* aShmemSection) {
// For now we only support sizes of 4. If we want to support different sizes
// some more complicated bookkeeping should be added.
NS_ASSERT_OWNINGTHREAD(FixedSizeSmallShmemSectionAllocator);
MOZ_ASSERT(aSize == sSupportedBlockSize);
MOZ_ASSERT(aShmemSection);

Expand Down Expand Up @@ -178,6 +179,8 @@ void FixedSizeSmallShmemSectionAllocator::FreeShmemSection(

void FixedSizeSmallShmemSectionAllocator::DeallocShmemSection(
mozilla::layers::ShmemSection& aShmemSection) {
NS_ASSERT_OWNINGTHREAD(FixedSizeSmallShmemSectionAllocator);

if (!IPCOpen()) {
gfxCriticalNote << "Attempt to dealloc a ShmemSections after shutdown.";
return;
Expand All @@ -188,6 +191,8 @@ void FixedSizeSmallShmemSectionAllocator::DeallocShmemSection(
}

void FixedSizeSmallShmemSectionAllocator::ShrinkShmemSectionHeap() {
NS_ASSERT_OWNINGTHREAD(FixedSizeSmallShmemSectionAllocator);

if (!IPCOpen()) {
mUsedShmems.clear();
return;
Expand Down
2 changes: 2 additions & 0 deletions gfx/layers/ipc/ISurfaceAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ class GfxMemoryImageReporter final : public nsIMemoryReporter {
/// copy-on-write locks for now).
class FixedSizeSmallShmemSectionAllocator final : public ShmemSectionAllocator {
public:
NS_DECL_OWNINGTHREAD

enum AllocationStatus { STATUS_ALLOCATED, STATUS_FREED };

struct ShmemSectionHeapHeader {
Expand Down
9 changes: 9 additions & 0 deletions gfx/layers/ipc/ImageBridgeChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ void ImageBridgeChild::ShutdownStep2(SynchronousTask* aTask) {

MOZ_ASSERT(InImageBridgeChildThread(),
"Should be in ImageBridgeChild thread.");

mSectionAllocator = nullptr;

if (!mDestroyed) {
Close();
}
Expand Down Expand Up @@ -483,12 +486,14 @@ void ImageBridgeChild::Bind(Endpoint<PImageBridgeChild>&& aEndpoint) {
return;
}

mSectionAllocator = MakeUnique<FixedSizeSmallShmemSectionAllocator>(this);
mCanSend = true;
}

void ImageBridgeChild::BindSameProcess(RefPtr<ImageBridgeParent> aParent) {
Open(aParent, aParent->GetThread(), mozilla::ipc::ChildSide);

mSectionAllocator = MakeUnique<FixedSizeSmallShmemSectionAllocator>(this);
mCanSend = true;
}

Expand Down Expand Up @@ -601,6 +606,10 @@ bool InImageBridgeChildThread() {
sImageBridgeChildThread->IsOnCurrentThread();
}

FixedSizeSmallShmemSectionAllocator* ImageBridgeChild::GetTileLockAllocator() {
return mSectionAllocator.get();
}

nsISerialEventTarget* ImageBridgeChild::GetThread() const {
return sImageBridgeChildThread;
}
Expand Down
6 changes: 5 additions & 1 deletion gfx/layers/ipc/ImageBridgeChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "mozilla/layers/PImageBridgeChild.h"
#include "mozilla/layers/TextureForwarder.h"
#include "mozilla/Mutex.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/webrender/WebRenderTypes.h"
#include "nsRegion.h" // for nsIntRegion
#include "mozilla/gfx/Rect.h"
Expand Down Expand Up @@ -154,6 +155,8 @@ class ImageBridgeChild final : public PImageBridgeChild,
void BeginTransaction();
void EndTransaction();

FixedSizeSmallShmemSectionAllocator* GetTileLockAllocator() override;

/**
* Returns the ImageBridgeChild's thread.
*
Expand Down Expand Up @@ -342,8 +345,9 @@ class ImageBridgeChild final : public PImageBridgeChild,
uint32_t mNamespace;

CompositableTransaction* mTxn;
UniquePtr<FixedSizeSmallShmemSectionAllocator> mSectionAllocator;

bool mCanSend;
mozilla::Atomic<bool> mCanSend;
mozilla::Atomic<bool> mDestroyed;

/**
Expand Down

0 comments on commit 370628c

Please sign in to comment.