0

Move some base/apple/ files into base:🍎:

Bug: 1474628
Change-Id: I1ba27e9e5d692d4fbaad8830646fb70632d2cc57
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4799473
Reviewed-by: Mark Mentovai <mark@chromium.org>
Auto-Submit: Avi Drissman <avi@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Owners-Override: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1186166}
This commit is contained in:
Avi Drissman
2023-08-21 23:57:01 +00:00
committed by Chromium LUCI CQ
parent 3990580934
commit 42f9d8fe64
21 changed files with 67 additions and 63 deletions

@ -6,7 +6,7 @@
#include "base/apple/scoped_dispatch_object.h" #include "base/apple/scoped_dispatch_object.h"
namespace base { namespace base::apple {
struct DispatchSourceMach::Storage { struct DispatchSourceMach::Storage {
// The dispatch queue used to service the source_. // The dispatch queue used to service the source_.
@ -62,4 +62,4 @@ dispatch_queue_t DispatchSourceMach::Queue() const {
return storage_->queue.get(); return storage_->queue.get();
} }
} // namespace base } // namespace base::apple

@ -11,7 +11,7 @@
#include "base/base_export.h" #include "base/base_export.h"
namespace base { namespace base::apple {
// This class encapsulates a MACH_RECV dispatch source. When this object is // This class encapsulates a MACH_RECV dispatch source. When this object is
// destroyed, the source will be cancelled and it will wait for the source // destroyed, the source will be cancelled and it will wait for the source
@ -50,6 +50,6 @@ class BASE_EXPORT DispatchSourceMach {
std::unique_ptr<Storage> storage_; std::unique_ptr<Storage> storage_;
}; };
} // namespace base } // namespace base::apple
#endif // BASE_APPLE_DISPATCH_SOURCE_MACH_H_ #endif // BASE_APPLE_DISPATCH_SOURCE_MACH_H_

@ -13,7 +13,7 @@
#include "base/test/test_timeouts.h" #include "base/test/test_timeouts.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace base { namespace base::apple {
class DispatchSourceMachTest : public testing::Test { class DispatchSourceMachTest : public testing::Test {
public: public:
@ -122,4 +122,4 @@ TEST_F(DispatchSourceMachTest, NoMessagesAfterDestruction) {
dispatch_release(queue); dispatch_release(queue);
} }
} // namespace base } // namespace base::apple

@ -17,7 +17,7 @@
#error Do not use this file, or allow it to be included, in Objective-C code. #error Do not use this file, or allow it to be included, in Objective-C code.
#endif #endif
namespace base { namespace base::apple {
namespace internal { namespace internal {
@ -37,6 +37,6 @@ template <typename T>
using ScopedDispatchObject = using ScopedDispatchObject =
ScopedTypeRef<T, internal::ScopedDispatchObjectTraits<T>>; ScopedTypeRef<T, internal::ScopedDispatchObjectTraits<T>>;
} // namespace base } // namespace base::apple
#endif // BASE_APPLE_SCOPED_DISPATCH_OBJECT_H_ #endif // BASE_APPLE_SCOPED_DISPATCH_OBJECT_H_

@ -22,7 +22,7 @@
@class NSAutoreleasePool; @class NSAutoreleasePool;
namespace base { namespace base::apple {
// scoped_nsobject<> is patterned after std::unique_ptr<>, but maintains // scoped_nsobject<> is patterned after std::unique_ptr<>, but maintains
// ownership of an NSObject subclass object. Style deviations here are solely // ownership of an NSObject subclass object. Style deviations here are solely
@ -97,6 +97,6 @@ class scoped_nsobject<id> : public scoped_nsprotocol<id> {
using scoped_nsprotocol<id>::scoped_nsprotocol; using scoped_nsprotocol<id>::scoped_nsprotocol;
}; };
} // namespace base } // namespace base::apple
#endif // BASE_APPLE_SCOPED_NSOBJECT_H_ #endif // BASE_APPLE_SCOPED_NSOBJECT_H_

@ -14,17 +14,17 @@
namespace { namespace {
TEST(ScopedNSObjectTest, ScopedNSObject) { TEST(ScopedNSObjectTest, ScopedNSObject) {
base::scoped_nsobject<NSObject> p1([[NSObject alloc] init]); base::apple::scoped_nsobject<NSObject> p1([[NSObject alloc] init]);
ASSERT_TRUE(p1.get()); ASSERT_TRUE(p1.get());
ASSERT_EQ(1u, [p1 retainCount]); ASSERT_EQ(1u, [p1 retainCount]);
base::scoped_nsobject<NSObject> p2(p1); base::apple::scoped_nsobject<NSObject> p2(p1);
ASSERT_EQ(p1.get(), p2.get()); ASSERT_EQ(p1.get(), p2.get());
ASSERT_EQ(2u, [p1 retainCount]); ASSERT_EQ(2u, [p1 retainCount]);
p2.reset(); p2.reset();
ASSERT_EQ(nil, p2.get()); ASSERT_EQ(nil, p2.get());
ASSERT_EQ(1u, [p1 retainCount]); ASSERT_EQ(1u, [p1 retainCount]);
{ {
base::scoped_nsobject<NSObject> p3 = p1; base::apple::scoped_nsobject<NSObject> p3 = p1;
ASSERT_EQ(p1.get(), p3.get()); ASSERT_EQ(p1.get(), p3.get());
ASSERT_EQ(2u, [p1 retainCount]); ASSERT_EQ(2u, [p1 retainCount]);
@autoreleasepool { @autoreleasepool {
@ -34,19 +34,19 @@ TEST(ScopedNSObjectTest, ScopedNSObject) {
ASSERT_EQ(2u, [p1 retainCount]); ASSERT_EQ(2u, [p1 retainCount]);
} }
ASSERT_EQ(1u, [p1 retainCount]); ASSERT_EQ(1u, [p1 retainCount]);
base::scoped_nsobject<NSObject> p4([p1.get() retain]); base::apple::scoped_nsobject<NSObject> p4([p1.get() retain]);
ASSERT_EQ(2u, [p1 retainCount]); ASSERT_EQ(2u, [p1 retainCount]);
ASSERT_TRUE(p1 == p1.get()); ASSERT_TRUE(p1 == p1.get());
ASSERT_TRUE(p1 == p1); ASSERT_TRUE(p1 == p1);
ASSERT_FALSE(p1 != p1); ASSERT_FALSE(p1 != p1);
ASSERT_FALSE(p1 != p1.get()); ASSERT_FALSE(p1 != p1.get());
base::scoped_nsobject<NSObject> p5([[NSObject alloc] init]); base::apple::scoped_nsobject<NSObject> p5([[NSObject alloc] init]);
ASSERT_TRUE(p1 != p5); ASSERT_TRUE(p1 != p5);
ASSERT_TRUE(p1 != p5.get()); ASSERT_TRUE(p1 != p5.get());
ASSERT_FALSE(p1 == p5); ASSERT_FALSE(p1 == p5);
ASSERT_FALSE(p1 == p5.get()); ASSERT_FALSE(p1 == p5.get());
base::scoped_nsobject<NSObject> p6 = p1; base::apple::scoped_nsobject<NSObject> p6 = p1;
ASSERT_EQ(3u, [p6 retainCount]); ASSERT_EQ(3u, [p6 retainCount]);
@autoreleasepool { @autoreleasepool {
p6.autorelease(); p6.autorelease();
@ -55,8 +55,8 @@ TEST(ScopedNSObjectTest, ScopedNSObject) {
} }
ASSERT_EQ(2u, [p1 retainCount]); ASSERT_EQ(2u, [p1 retainCount]);
base::scoped_nsobject<NSObject> p7([NSObject new]); base::apple::scoped_nsobject<NSObject> p7([NSObject new]);
base::scoped_nsobject<NSObject> p8(std::move(p7)); base::apple::scoped_nsobject<NSObject> p8(std::move(p7));
ASSERT_TRUE(p8); ASSERT_TRUE(p8);
ASSERT_EQ(1u, [p8 retainCount]); ASSERT_EQ(1u, [p8 retainCount]);
ASSERT_FALSE(p7.get()); ASSERT_FALSE(p7.get());
@ -66,20 +66,21 @@ TEST(ScopedNSObjectTest, ScopedNSObject) {
// static_assert. // static_assert.
#if 0 #if 0
TEST(ScopedNSObjectTest, FailToCreateScopedNSObjectAutoreleasePool) { TEST(ScopedNSObjectTest, FailToCreateScopedNSObjectAutoreleasePool) {
base::scoped_nsobject<NSAutoreleasePool> pool; base::apple::scoped_nsobject<NSAutoreleasePool> pool;
} }
#endif #endif
TEST(ScopedNSObjectTest, ScopedNSObjectInContainer) { TEST(ScopedNSObjectTest, ScopedNSObjectInContainer) {
base::scoped_nsobject<id> p([[NSObject alloc] init]); base::apple::scoped_nsobject<id> p([[NSObject alloc] init]);
ASSERT_TRUE(p.get()); ASSERT_TRUE(p.get());
ASSERT_EQ(1u, [p retainCount]); ASSERT_EQ(1u, [p retainCount]);
{ {
std::vector<base::scoped_nsobject<id>> objects; std::vector<base::apple::scoped_nsobject<id>> objects;
objects.push_back(p); objects.push_back(p);
ASSERT_EQ(2u, [p retainCount]); ASSERT_EQ(2u, [p retainCount]);
ASSERT_EQ(p.get(), objects[0].get()); ASSERT_EQ(p.get(), objects[0].get());
objects.push_back(base::scoped_nsobject<id>([[NSObject alloc] init])); objects.push_back(
base::apple::scoped_nsobject<id>([[NSObject alloc] init]));
ASSERT_TRUE(objects[1].get()); ASSERT_TRUE(objects[1].get());
ASSERT_EQ(1u, [objects[1] retainCount]); ASSERT_EQ(1u, [objects[1] retainCount]);
} }
@ -87,11 +88,11 @@ TEST(ScopedNSObjectTest, ScopedNSObjectInContainer) {
} }
TEST(ScopedNSObjectTest, ScopedNSObjectFreeFunctions) { TEST(ScopedNSObjectTest, ScopedNSObjectFreeFunctions) {
base::scoped_nsobject<id> p1([[NSObject alloc] init]); base::apple::scoped_nsobject<id> p1([[NSObject alloc] init]);
id o1 = p1.get(); id o1 = p1.get();
ASSERT_TRUE(o1 == p1); ASSERT_TRUE(o1 == p1);
ASSERT_FALSE(o1 != p1); ASSERT_FALSE(o1 != p1);
base::scoped_nsobject<id> p2([[NSObject alloc] init]); base::apple::scoped_nsobject<id> p2([[NSObject alloc] init]);
ASSERT_TRUE(o1 != p2); ASSERT_TRUE(o1 != p2);
ASSERT_FALSE(o1 == p2); ASSERT_FALSE(o1 == p2);
id o2 = p2.get(); id o2 = p2.get();
@ -101,12 +102,12 @@ TEST(ScopedNSObjectTest, ScopedNSObjectFreeFunctions) {
} }
TEST(ScopedNSObjectTest, ResetWithAnotherScopedNSObject) { TEST(ScopedNSObjectTest, ResetWithAnotherScopedNSObject) {
base::scoped_nsobject<id> p1([[NSObject alloc] init]); base::apple::scoped_nsobject<id> p1([[NSObject alloc] init]);
id o1 = p1.get(); id o1 = p1.get();
id o2 = nil; id o2 = nil;
{ {
base::scoped_nsobject<id> p2([[NSObject alloc] init]); base::apple::scoped_nsobject<id> p2([[NSObject alloc] init]);
o2 = p2.get(); o2 = p2.get();
p1.reset(p2); p1.reset(p2);
EXPECT_EQ(2u, [p1 retainCount]); EXPECT_EQ(2u, [p1 retainCount]);

@ -76,7 +76,7 @@ class FilePathWatcherFSEvents : public FilePathWatcher::PlatformDelegate {
FilePathWatcher::Callback callback_; FilePathWatcher::Callback callback_;
// The dispatch queue on which the event stream is scheduled. // The dispatch queue on which the event stream is scheduled.
ScopedDispatchObject<dispatch_queue_t> queue_; apple::ScopedDispatchObject<dispatch_queue_t> queue_;
// Target path to watch (passed to callback). // Target path to watch (passed to callback).
// (Only accessed from the libdispatch queue.) // (Only accessed from the libdispatch queue.)

@ -116,9 +116,10 @@ void MachPortRendezvousServer::RegisterPortsForPid(
DCHECK_LT(ports.size(), kMaximumRendezvousPorts); DCHECK_LT(ports.size(), kMaximumRendezvousPorts);
DCHECK(!ports.empty()); DCHECK(!ports.empty());
ScopedDispatchObject<dispatch_source_t> exit_watcher(dispatch_source_create( apple::ScopedDispatchObject<dispatch_source_t> exit_watcher(
DISPATCH_SOURCE_TYPE_PROC, static_cast<uintptr_t>(pid), dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC,
DISPATCH_PROC_EXIT, dispatch_source_->Queue())); static_cast<uintptr_t>(pid), DISPATCH_PROC_EXIT,
dispatch_source_->Queue()));
dispatch_source_set_event_handler(exit_watcher, ^{ dispatch_source_set_event_handler(exit_watcher, ^{
OnClientExited(pid); OnClientExited(pid);
}); });
@ -130,7 +131,7 @@ void MachPortRendezvousServer::RegisterPortsForPid(
} }
MachPortRendezvousServer::ClientData::ClientData( MachPortRendezvousServer::ClientData::ClientData(
ScopedDispatchObject<dispatch_source_t> exit_watcher, apple::ScopedDispatchObject<dispatch_source_t> exit_watcher,
MachPortsForRendezvous ports) MachPortsForRendezvous ports)
: exit_watcher(exit_watcher), ports(ports) {} : exit_watcher(exit_watcher), ports(ports) {}
@ -147,7 +148,7 @@ MachPortRendezvousServer::MachPortRendezvousServer() {
BOOTSTRAP_CHECK(kr == KERN_SUCCESS, kr) BOOTSTRAP_CHECK(kr == KERN_SUCCESS, kr)
<< "bootstrap_check_in " << bootstrap_name; << "bootstrap_check_in " << bootstrap_name;
dispatch_source_ = std::make_unique<DispatchSourceMach>( dispatch_source_ = std::make_unique<apple::DispatchSourceMach>(
bootstrap_name.c_str(), server_port_.get(), ^{ bootstrap_name.c_str(), server_port_.get(), ^{
HandleRequest(); HandleRequest();
}); });

@ -109,14 +109,14 @@ class BASE_EXPORT MachPortRendezvousServer {
friend struct MachPortRendezvousFuzzer; friend struct MachPortRendezvousFuzzer;
struct ClientData { struct ClientData {
ClientData(ScopedDispatchObject<dispatch_source_t> exit_watcher, ClientData(apple::ScopedDispatchObject<dispatch_source_t> exit_watcher,
MachPortsForRendezvous ports); MachPortsForRendezvous ports);
ClientData(ClientData&&); ClientData(ClientData&&);
~ClientData(); ~ClientData();
// A DISPATCH_SOURCE_TYPE_PROC / DISPATCH_PROC_EXIT dispatch source. When // A DISPATCH_SOURCE_TYPE_PROC / DISPATCH_PROC_EXIT dispatch source. When
// the source is triggered, it calls OnClientExited(). // the source is triggered, it calls OnClientExited().
ScopedDispatchObject<dispatch_source_t> exit_watcher; apple::ScopedDispatchObject<dispatch_source_t> exit_watcher;
MachPortsForRendezvous ports; MachPortsForRendezvous ports;
}; };
@ -150,7 +150,7 @@ class BASE_EXPORT MachPortRendezvousServer {
apple::ScopedMachReceiveRight server_port_; apple::ScopedMachReceiveRight server_port_;
// Mach message dispatch source for |server_port_|. // Mach message dispatch source for |server_port_|.
std::unique_ptr<DispatchSourceMach> dispatch_source_; std::unique_ptr<apple::DispatchSourceMach> dispatch_source_;
Lock lock_; Lock lock_;
// Association of pid-to-ports. // Association of pid-to-ports.

@ -14,7 +14,7 @@ struct WaitableEventWatcher::Storage {
// A TYPE_MACH_RECV dispatch source on |receive_right_|. When a receive event // A TYPE_MACH_RECV dispatch source on |receive_right_|. When a receive event
// is delivered, the message queue will be peeked and the bound |callback_| // is delivered, the message queue will be peeked and the bound |callback_|
// may be run. This will be null if nothing is currently being watched. // may be run. This will be null if nothing is currently being watched.
ScopedDispatchObject<dispatch_source_t> dispatch_source; apple::ScopedDispatchObject<dispatch_source_t> dispatch_source;
}; };
WaitableEventWatcher::WaitableEventWatcher() WaitableEventWatcher::WaitableEventWatcher()

@ -42,7 +42,7 @@ void MachBootstrapAcceptor::Start() {
return; return;
} }
dispatch_source_ = std::make_unique<base::DispatchSourceMach>( dispatch_source_ = std::make_unique<base::apple::DispatchSourceMach>(
server_name_.c_str(), port(), ^{ server_name_.c_str(), port(), ^{
HandleRequest(); HandleRequest();
}); });

@ -64,7 +64,7 @@ class MachBootstrapAcceptor {
mojo::NamedPlatformChannel::ServerName server_name_; mojo::NamedPlatformChannel::ServerName server_name_;
raw_ptr<Delegate, AcrossTasksDanglingUntriaged> delegate_; raw_ptr<Delegate, AcrossTasksDanglingUntriaged> delegate_;
mojo::PlatformChannelServerEndpoint endpoint_; mojo::PlatformChannelServerEndpoint endpoint_;
std::unique_ptr<base::DispatchSourceMach> dispatch_source_; std::unique_ptr<base::apple::DispatchSourceMach> dispatch_source_;
}; };
} // namespace apps } // namespace apps

@ -12,7 +12,7 @@
@interface ZombieCxxDestructTest : NSObject @interface ZombieCxxDestructTest : NSObject
{ {
base::scoped_nsobject<id> _aRef; base::apple::scoped_nsobject<id> _aRef;
} }
- (instancetype)initWith:(id)anObject; - (instancetype)initWith:(id)anObject;
@end @end
@ -53,12 +53,12 @@ namespace {
// NOTE(shess): To test the negative, comment out the |g_objectDestruct()| // NOTE(shess): To test the negative, comment out the |g_objectDestruct()|
// call in |ZombieDealloc()|. // call in |ZombieDealloc()|.
TEST(ObjcZombieTest, CxxDestructors) { TEST(ObjcZombieTest, CxxDestructors) {
base::scoped_nsobject<id> anObject([[NSObject alloc] init]); base::apple::scoped_nsobject<id> anObject([[NSObject alloc] init]);
EXPECT_EQ(1u, [anObject retainCount]); EXPECT_EQ(1u, [anObject retainCount]);
ASSERT_TRUE(ObjcEvilDoers::ZombieEnable(YES, 100)); ASSERT_TRUE(ObjcEvilDoers::ZombieEnable(YES, 100));
base::scoped_nsobject<ZombieCxxDestructTest> soonInfected( base::apple::scoped_nsobject<ZombieCxxDestructTest> soonInfected(
[[ZombieCxxDestructTest alloc] initWith:anObject]); [[ZombieCxxDestructTest alloc] initWith:anObject]);
EXPECT_EQ(2u, [anObject retainCount]); EXPECT_EQ(2u, [anObject retainCount]);
@ -75,12 +75,12 @@ TEST(ObjcZombieTest, CxxDestructors) {
// Verify that the associated objects are released when the object is // Verify that the associated objects are released when the object is
// released. // released.
TEST(ObjcZombieTest, AssociatedObjectsReleased) { TEST(ObjcZombieTest, AssociatedObjectsReleased) {
base::scoped_nsobject<id> anObject([[NSObject alloc] init]); base::apple::scoped_nsobject<id> anObject([[NSObject alloc] init]);
EXPECT_EQ(1u, [anObject retainCount]); EXPECT_EQ(1u, [anObject retainCount]);
ASSERT_TRUE(ObjcEvilDoers::ZombieEnable(YES, 100)); ASSERT_TRUE(ObjcEvilDoers::ZombieEnable(YES, 100));
base::scoped_nsobject<ZombieAssociatedObjectTest> soonInfected( base::apple::scoped_nsobject<ZombieAssociatedObjectTest> soonInfected(
[[ZombieAssociatedObjectTest alloc] initWithAssociatedObject:anObject]); [[ZombieAssociatedObjectTest alloc] initWithAssociatedObject:anObject]);
EXPECT_EQ(2u, [anObject retainCount]); EXPECT_EQ(2u, [anObject retainCount]);

@ -51,7 +51,8 @@ class SystemMemoryPressureEvaluator
void OnMemoryPressureChanged(); void OnMemoryPressureChanged();
// The dispatch source that generates memory pressure change notifications. // The dispatch source that generates memory pressure change notifications.
base::ScopedDispatchObject<dispatch_source_t> memory_level_event_source_; base::apple::ScopedDispatchObject<dispatch_source_t>
memory_level_event_source_;
// Timer that will re-notify with the current vote at regular interval. // Timer that will re-notify with the current vote at regular interval.
base::RepeatingTimer renotify_current_vote_timer_; base::RepeatingTimer renotify_current_vote_timer_;

@ -52,7 +52,7 @@ class NamedMojoServerEndpointConnectorMac final
// Note: |server_endpoint_| must outlive |dispatch_source_|. // Note: |server_endpoint_| must outlive |dispatch_source_|.
mojo::PlatformChannelServerEndpoint server_endpoint_; mojo::PlatformChannelServerEndpoint server_endpoint_;
std::unique_ptr<base::DispatchSourceMach> dispatch_source_; std::unique_ptr<base::apple::DispatchSourceMach> dispatch_source_;
}; };
NamedMojoServerEndpointConnectorMac::NamedMojoServerEndpointConnectorMac( NamedMojoServerEndpointConnectorMac::NamedMojoServerEndpointConnectorMac(
@ -120,7 +120,7 @@ bool NamedMojoServerEndpointConnectorMac::TryStart() {
} }
server_endpoint_ = std::move(server_endpoint); server_endpoint_ = std::move(server_endpoint);
dispatch_source_ = std::make_unique<base::DispatchSourceMach>( dispatch_source_ = std::make_unique<base::apple::DispatchSourceMach>(
options_.server_name.c_str(), port(), ^{ options_.server_name.c_str(), port(), ^{
HandleRequest(); HandleRequest();
}); });

@ -58,7 +58,7 @@ ChildProcessTaskPortProvider::ChildProcessTaskPortProvider() {
const std::string dispatch_name = base::StringPrintf( const std::string dispatch_name = base::StringPrintf(
"%s.ChildProcessTaskPortProvider.%p", base::apple::BaseBundleID(), this); "%s.ChildProcessTaskPortProvider.%p", base::apple::BaseBundleID(), this);
notification_source_ = std::make_unique<base::DispatchSourceMach>( notification_source_ = std::make_unique<base::apple::DispatchSourceMach>(
dispatch_name.c_str(), notification_port_.get(), ^{ dispatch_name.c_str(), notification_port_.get(), ^{
OnTaskPortDied(); OnTaskPortDied();
}); });

@ -82,7 +82,7 @@ class CONTENT_EXPORT ChildProcessTaskPortProvider : public base::PortProvider {
base::apple::ScopedMachReceiveRight notification_port_; base::apple::ScopedMachReceiveRight notification_port_;
// Dispatch source for |notification_port_|. // Dispatch source for |notification_port_|.
std::unique_ptr<base::DispatchSourceMach> notification_source_; std::unique_ptr<base::apple::DispatchSourceMach> notification_source_;
}; };
} // namespace content } // namespace content

@ -186,9 +186,9 @@ not compile with ARC, but that are no longer needed with ARC code. Because there
are still parts of Chromium that cannot be compiled with ARC, these utilities are still parts of Chromium that cannot be compiled with ARC, these utilities
remain, however they should not (or sometimes cannot) be used from ARC: remain, however they should not (or sometimes cannot) be used from ARC:
- `base::scoped_nsobject<>`: This only exists to handle scoping of Objective-C - `scoped_nsobject<>`/`scoped_nsprotocol<>`: These only exists to handle scoping
objects in non-ARC code. It cannot be used in ARC code; use `__strong` of Objective-C objects in non-ARC code. They cannot be used in ARC code; use
instead. `__strong` instead.
- `ScopedNSAutoreleasePool`: Use `@autoreleasepool` instead, and remove any use - `ScopedNSAutoreleasePool`: Use `@autoreleasepool` instead, and remove any use
of `ScopedNSAutoreleasePool` that you encounter, if possible. of `ScopedNSAutoreleasePool` that you encounter, if possible.
`ScopedNSAutoreleasePool` was rewritten to be able to work in ARC code, but `ScopedNSAutoreleasePool` was rewritten to be able to work in ARC code, but

@ -221,7 +221,7 @@ class SharedEventAndSignalValue : public BackpressureMetalSharedEvent {
uint64_t signaled_value() const { return signaled_value_; } uint64_t signaled_value() const { return signaled_value_; }
private: private:
base::scoped_nsprotocol<id<MTLSharedEvent>> shared_event_; base::apple::scoped_nsprotocol<id<MTLSharedEvent>> shared_event_;
uint64_t signaled_value_; uint64_t signaled_value_;
}; };

@ -91,21 +91,21 @@ gfx::BufferFormat GetBufferFormatForPlane(viz::SharedImageFormat format,
#if BUILDFLAG(SKIA_USE_METAL) #if BUILDFLAG(SKIA_USE_METAL)
base::scoped_nsprotocol<id<MTLTexture>> CreateMetalTexture( base::apple::scoped_nsprotocol<id<MTLTexture>> CreateMetalTexture(
id<MTLDevice> mtl_device, id<MTLDevice> mtl_device,
IOSurfaceRef io_surface, IOSurfaceRef io_surface,
const gfx::Size& size, const gfx::Size& size,
viz::SharedImageFormat format, viz::SharedImageFormat format,
int plane_index) { int plane_index) {
TRACE_EVENT0("gpu", "IOSurfaceImageBackingFactory::CreateMetalTexture"); TRACE_EVENT0("gpu", "IOSurfaceImageBackingFactory::CreateMetalTexture");
base::scoped_nsprotocol<id<MTLTexture>> mtl_texture; base::apple::scoped_nsprotocol<id<MTLTexture>> mtl_texture;
MTLPixelFormat mtl_pixel_format = MTLPixelFormat mtl_pixel_format =
static_cast<MTLPixelFormat>(ToMTLPixelFormat(format, plane_index)); static_cast<MTLPixelFormat>(ToMTLPixelFormat(format, plane_index));
if (mtl_pixel_format == MTLPixelFormatInvalid) { if (mtl_pixel_format == MTLPixelFormatInvalid) {
return mtl_texture; return mtl_texture;
} }
base::scoped_nsobject<MTLTextureDescriptor> mtl_tex_desc( base::apple::scoped_nsobject<MTLTextureDescriptor> mtl_tex_desc(
[MTLTextureDescriptor new]); [MTLTextureDescriptor new]);
[mtl_tex_desc setTextureType:MTLTextureType2D]; [mtl_tex_desc setTextureType:MTLTextureType2D];
[mtl_tex_desc [mtl_tex_desc
@ -134,7 +134,7 @@ base::scoped_nsprotocol<id<MTLTexture>> CreateMetalTexture(
} }
std::vector<skgpu::graphite::BackendTexture> CreateGraphiteMetalTextures( std::vector<skgpu::graphite::BackendTexture> CreateGraphiteMetalTextures(
std::vector<base::scoped_nsprotocol<id<MTLTexture>>> mtl_textures, std::vector<base::apple::scoped_nsprotocol<id<MTLTexture>>> mtl_textures,
const viz::SharedImageFormat format, const viz::SharedImageFormat format,
const gfx::Size& size) { const gfx::Size& size) {
int num_planes = format.NumberOfPlanes(); int num_planes = format.NumberOfPlanes();
@ -399,7 +399,7 @@ class IOSurfaceImageBacking::SkiaGraphiteIOSurfaceRepresentation
SharedImageBacking* backing, SharedImageBacking* backing,
MemoryTypeTracker* tracker, MemoryTypeTracker* tracker,
skgpu::graphite::Recorder* recorder, skgpu::graphite::Recorder* recorder,
std::vector<base::scoped_nsprotocol<id<MTLTexture>>> mtl_textures) std::vector<base::apple::scoped_nsprotocol<id<MTLTexture>>> mtl_textures)
: SkiaGraphiteImageRepresentation(manager, backing, tracker), : SkiaGraphiteImageRepresentation(manager, backing, tracker),
recorder_(recorder), recorder_(recorder),
mtl_textures_(std::move(mtl_textures)) { mtl_textures_(std::move(mtl_textures)) {
@ -482,7 +482,7 @@ class IOSurfaceImageBacking::SkiaGraphiteIOSurfaceRepresentation
} }
const raw_ptr<skgpu::graphite::Recorder> recorder_; const raw_ptr<skgpu::graphite::Recorder> recorder_;
std::vector<base::scoped_nsprotocol<id<MTLTexture>>> mtl_textures_; std::vector<base::apple::scoped_nsprotocol<id<MTLTexture>>> mtl_textures_;
std::vector<sk_sp<SkSurface>> write_surfaces_; std::vector<sk_sp<SkSurface>> write_surfaces_;
}; };
#endif #endif
@ -1125,14 +1125,15 @@ IOSurfaceImageBacking::ProduceSkiaGraphite(
} else { } else {
CHECK_EQ(context_state->gr_context_type(), GrContextType::kGraphiteMetal); CHECK_EQ(context_state->gr_context_type(), GrContextType::kGraphiteMetal);
#if BUILDFLAG(SKIA_USE_METAL) #if BUILDFLAG(SKIA_USE_METAL)
std::vector<base::scoped_nsprotocol<id<MTLTexture>>> mtl_textures; std::vector<base::apple::scoped_nsprotocol<id<MTLTexture>>> mtl_textures;
mtl_textures.reserve(format().NumberOfPlanes()); mtl_textures.reserve(format().NumberOfPlanes());
for (int plane = 0; plane < format().NumberOfPlanes(); plane++) { for (int plane = 0; plane < format().NumberOfPlanes(); plane++) {
auto plane_size = format().GetPlaneSize(plane, size()); auto plane_size = format().GetPlaneSize(plane, size());
base::scoped_nsprotocol<id<MTLTexture>> mtl_texture = CreateMetalTexture( base::apple::scoped_nsprotocol<id<MTLTexture>> mtl_texture =
context_state->metal_context_provider()->GetMTLDevice(), CreateMetalTexture(
io_surface_.get(), plane_size, format(), plane); context_state->metal_context_provider()->GetMTLDevice(),
io_surface_.get(), plane_size, format(), plane);
if (!mtl_texture) { if (!mtl_texture) {
LOG(ERROR) << "Failed to create MTLTexture from IOSurface"; LOG(ERROR) << "Failed to create MTLTexture from IOSurface";
return nullptr; return nullptr;

@ -22,7 +22,7 @@
namespace gl { namespace gl {
struct GLDisplayEGL::ObjCStorage { struct GLDisplayEGL::ObjCStorage {
base::scoped_nsprotocol<id<MTLSharedEvent>> metal_shared_event; base::apple::scoped_nsprotocol<id<MTLSharedEvent>> metal_shared_event;
uint64_t metal_signaled_value = 0; uint64_t metal_signaled_value = 0;
}; };