commit f78cdbaff8a375d2b614c9434f2a59eeeabbb6ce
parent d187ae71630af53a63e2469b182d9307a9d54857
Author: Markus Stange <mstange.moz@gmail.com>
Date: Tue, 7 Oct 2025 15:49:45 +0000
Bug 1992515 - Use IOSurfacePort in CommandChangedSurface. r=bradwerth
Differential Revision: https://phabricator.services.mozilla.com/D267489
Diffstat:
8 files changed, 19 insertions(+), 31 deletions(-)
diff --git a/gfx/layers/NativeLayerCommandQueue.cpp b/gfx/layers/NativeLayerCommandQueue.cpp
@@ -12,16 +12,15 @@ NativeLayerCommandQueue::NativeLayerCommandQueue()
: mQueue("NativeLayerCommandQueue") {}
void NativeLayerCommandQueue::AppendCommand(
- const mozilla::layers::NativeLayerCommand& aCommand) {
+ mozilla::layers::NativeLayerCommand&& aCommand) {
auto q = mQueue.Lock();
- q->AppendElement(aCommand);
+ q->AppendElement(std::move(aCommand));
}
void NativeLayerCommandQueue::FlushToArray(
nsTArray<mozilla::layers::NativeLayerCommand>& aQueue) {
auto q = mQueue.Lock();
- aQueue.AppendElements(*q);
- q->Clear();
+ aQueue.AppendElements(std::move(*q));
}
} // namespace layers
diff --git a/gfx/layers/NativeLayerCommandQueue.h b/gfx/layers/NativeLayerCommandQueue.h
@@ -18,7 +18,7 @@ class NativeLayerCommandQueue {
NativeLayerCommandQueue();
- void AppendCommand(const mozilla::layers::NativeLayerCommand& aCommand);
+ void AppendCommand(mozilla::layers::NativeLayerCommand&& aCommand);
void FlushToArray(nsTArray<mozilla::layers::NativeLayerCommand>& aQueue);
protected:
diff --git a/gfx/layers/NativeLayerRemoteMac.mm b/gfx/layers/NativeLayerRemoteMac.mm
@@ -247,18 +247,15 @@ void NativeLayerRemoteMac::FlushDirtyLayerInfoToCommandQueue() {
auto ID = reinterpret_cast<uint64_t>(this);
if (mDirtyChangedSurface) {
- uint32_t surfaceID = 0;
+ IOSurfacePort surfacePort;
auto surfaceWithInvalidRegion = FrontSurface();
if (surfaceWithInvalidRegion) {
- // Get the unique ID for this IOSurfaceRef, which only works
- // because kIOSurfaceIsGlobal was set to true when this
- // IOSurface was created.
- IOSurfaceRef surfaceRef = surfaceWithInvalidRegion->mSurface.get();
- surfaceID = IOSurfaceGetID(surfaceRef);
+ surfacePort =
+ IOSurfacePort::FromSurface(surfaceWithInvalidRegion->mSurface);
}
mCommandQueue->AppendCommand(mozilla::layers::CommandChangedSurface(
- ID, surfaceID, IsDRM(), IsHDR(), GetSize()));
+ ID, std::move(surfacePort), IsDRM(), IsHDR(), GetSize()));
mDirtyChangedSurface = false;
}
diff --git a/gfx/layers/NativeLayerRootRemoteMacChild.mm b/gfx/layers/NativeLayerRootRemoteMacChild.mm
@@ -132,7 +132,7 @@ bool NativeLayerRootRemoteMacChild::CommitToScreen() {
if (!commands.IsEmpty()) {
// Send all the queued commands, including the ones we just added.
MOZ_ASSERT(mRemoteChild);
- mRemoteChild->SendCommitNativeLayerCommands(commands);
+ mRemoteChild->SendCommitNativeLayerCommands(std::move(commands));
}
return true;
}
diff --git a/gfx/layers/NativeLayerRootRemoteMacParent.h b/gfx/layers/NativeLayerRootRemoteMacParent.h
@@ -43,8 +43,8 @@ class NativeLayerRootRemoteMacParent final : public NativeLayerRemoteParent {
Maybe<RoundedRect> aRoundedClipRect,
Matrix4x4 aTransform, int8_t aSamplingFilter,
bool aSurfaceIsFlipped);
- void HandleChangedSurface(uint64_t aID, uint32_t aSurfaceID, bool aIsDRM,
- bool aIsHDR, IntSize aSize);
+ void HandleChangedSurface(uint64_t aID, IOSurfacePort aSurfacePort,
+ bool aIsDRM, bool aIsHDR, IntSize aSize);
RefPtr<NativeLayerRootCA> mRealNativeLayerRoot;
UniquePtr<NativeLayerRootSnapshotter> mSnapshotter;
diff --git a/gfx/layers/NativeLayerRootRemoteMacParent.mm b/gfx/layers/NativeLayerRootRemoteMacParent.mm
@@ -67,7 +67,8 @@ NativeLayerRootRemoteMacParent::RecvCommitNativeLayerCommands(
case NativeLayerCommand::TCommandChangedSurface: {
auto& changedSurface = command.get_CommandChangedSurface();
- HandleChangedSurface(changedSurface.ID(), changedSurface.SurfaceID(),
+ HandleChangedSurface(changedSurface.ID(),
+ std::move(changedSurface.Surface()),
changedSurface.IsDRM(), changedSurface.IsHDR(),
changedSurface.Size());
break;
@@ -182,11 +183,9 @@ void NativeLayerRootRemoteMacParent::HandleLayerInfo(
layer->SetSurfaceIsFlipped(aSurfaceIsFlipped);
}
-void NativeLayerRootRemoteMacParent::HandleChangedSurface(uint64_t aID,
- uint32_t aSurfaceID,
- bool aIsDRM,
- bool aIsHDR,
- IntSize aSize) {
+void NativeLayerRootRemoteMacParent::HandleChangedSurface(
+ uint64_t aID, IOSurfacePort aSurfacePort, bool aIsDRM, bool aIsHDR,
+ IntSize aSize) {
auto entry = mKnownLayers.MaybeGet(aID);
if (!entry) {
gfxWarning() << "Got a ChangedSurface for an unknown layer.";
@@ -196,14 +195,7 @@ void NativeLayerRootRemoteMacParent::HandleChangedSurface(uint64_t aID,
RefPtr<NativeLayerCA> layer = (*entry)->AsNativeLayerCA();
MOZ_ASSERT(layer, "All of our known layers should be NativeLayerCA.");
- // Set the surface of this layer.
- auto surfaceRef = IOSurfaceLookup(aSurfaceID);
- if (surfaceRef) {
- // The call to IOSurfaceLookup leaves us with a retain count of 1.
- // The CFTypeRefPtr will take care of it when it falls out of scope,
- // since we declare it with create rule semantics.
- CFTypeRefPtr<IOSurfaceRef> surface =
- CFTypeRefPtr<IOSurfaceRef>::WrapUnderCreateRule(surfaceRef);
+ if (auto surface = aSurfacePort.GetSurface()) {
layer->SetSurfaceToPresent(surface, aSize, aIsDRM, aIsHDR);
}
}
diff --git a/gfx/layers/SurfacePoolCA.mm b/gfx/layers/SurfacePoolCA.mm
@@ -184,7 +184,6 @@ CFTypeRefPtr<IOSurfaceRef> SurfacePoolCA::LockedPool::ObtainSurfaceFromPool(
(__bridge NSString*)
kIOSurfacePixelFormat : @(kCVPixelFormatType_32BGRA),
(__bridge NSString*)kIOSurfaceBytesPerElement : @(4),
- (__bridge NSString*)kIOSurfaceIsGlobal : @(YES),
}));
if (surface) {
if (StaticPrefs::gfx_color_management_native_srgb()) {
diff --git a/gfx/layers/ipc/PNativeLayerRemote.ipdl b/gfx/layers/ipc/PNativeLayerRemote.ipdl
@@ -11,6 +11,7 @@ using mozilla::gfx::IntRect from "mozilla/gfx/Point.h";
using mozilla::gfx::RoundedRect from "mozilla/gfx/Point.h";
using mozilla::gfx::IntSize from "mozilla/gfx/Point.h";
using mozilla::gfx::Matrix4x4 from "mozilla/gfx/Matrix.h";
+[MoveOnly] using mozilla::layers::IOSurfacePort from "mozilla/layers/IOSurfacePort.h";
namespace mozilla {
namespace layers {
@@ -62,7 +63,7 @@ struct CommandLayerInfo {
struct CommandChangedSurface {
uint64_t ID;
- uint32_t SurfaceID;
+ IOSurfacePort Surface;
bool IsDRM;
bool IsHDR;
IntSize Size;