diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index cb3241c442528..b4b2d08f5479b 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -928,6 +928,8 @@ ORIGIN: ../../../flutter/fml/platform/darwin/platform_version.h + ../../../flutt ORIGIN: ../../../flutter/fml/platform/darwin/platform_version.mm + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/platform/darwin/scoped_block.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/platform/darwin/scoped_block.mm + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/fml/platform/darwin/scoped_nsautorelease_pool.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/fml/platform/darwin/scoped_nsautorelease_pool.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/platform/darwin/scoped_nsobject.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/platform/darwin/scoped_nsobject.mm + ../../../flutter/LICENSE ORIGIN: ../../../flutter/fml/platform/darwin/string_range_sanitization.h + ../../../flutter/LICENSE @@ -3569,6 +3571,8 @@ FILE: ../../../flutter/fml/platform/darwin/platform_version.h FILE: ../../../flutter/fml/platform/darwin/platform_version.mm FILE: ../../../flutter/fml/platform/darwin/scoped_block.h FILE: ../../../flutter/fml/platform/darwin/scoped_block.mm +FILE: ../../../flutter/fml/platform/darwin/scoped_nsautorelease_pool.cc +FILE: ../../../flutter/fml/platform/darwin/scoped_nsautorelease_pool.h FILE: ../../../flutter/fml/platform/darwin/scoped_nsobject.h FILE: ../../../flutter/fml/platform/darwin/scoped_nsobject.mm FILE: ../../../flutter/fml/platform/darwin/string_range_sanitization.h diff --git a/fml/BUILD.gn b/fml/BUILD.gn index 9f7310b5b0650..6e32f99a6a07a 100644 --- a/fml/BUILD.gn +++ b/fml/BUILD.gn @@ -150,6 +150,8 @@ source_set("fml") { "platform/darwin/platform_version.mm", "platform/darwin/scoped_block.h", "platform/darwin/scoped_block.mm", + "platform/darwin/scoped_nsautorelease_pool.cc", + "platform/darwin/scoped_nsautorelease_pool.h", "platform/darwin/scoped_nsobject.h", "platform/darwin/scoped_nsobject.mm", "platform/darwin/string_range_sanitization.h", diff --git a/fml/platform/darwin/scoped_nsautorelease_pool.cc b/fml/platform/darwin/scoped_nsautorelease_pool.cc new file mode 100644 index 0000000000000..e7191d6ff7d63 --- /dev/null +++ b/fml/platform/darwin/scoped_nsautorelease_pool.cc @@ -0,0 +1,26 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/fml/platform/darwin/scoped_nsautorelease_pool.h" + +#include +#include + +namespace { +typedef id (*msg_send)(void*, SEL); +} // anonymous namespace + +namespace fml { + +ScopedNSAutoreleasePool::ScopedNSAutoreleasePool() { + autorelease_pool_ = reinterpret_cast(objc_msgSend)( + objc_getClass("NSAutoreleasePool"), sel_getUid("new")); +} + +ScopedNSAutoreleasePool::~ScopedNSAutoreleasePool() { + reinterpret_cast(objc_msgSend)(autorelease_pool_, + sel_getUid("drain")); +} + +} // namespace fml diff --git a/fml/platform/darwin/scoped_nsautorelease_pool.h b/fml/platform/darwin/scoped_nsautorelease_pool.h new file mode 100644 index 0000000000000..50ad5621d1e2e --- /dev/null +++ b/fml/platform/darwin/scoped_nsautorelease_pool.h @@ -0,0 +1,26 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_FML_PLATFORM_DARWIN_SCOPED_NSAUTORELEASEPOOL_H_ +#define FLUTTER_FML_PLATFORM_DARWIN_SCOPED_NSAUTORELEASEPOOL_H_ + +#include "flutter/fml/macros.h" + +namespace fml { + +// Pushes an autorelease pool when constructed and pops it when destructed. +class ScopedNSAutoreleasePool { + public: + ScopedNSAutoreleasePool(); + ~ScopedNSAutoreleasePool(); + + private: + void* autorelease_pool_; + + FML_DISALLOW_COPY_AND_ASSIGN(ScopedNSAutoreleasePool); +}; + +} // namespace fml + +#endif // FLUTTER_FML_PLATFORM_DARWIN_SCOPED_NSAUTORELEASEPOOL_H_ diff --git a/impeller/golden_tests/golden_playground_test.h b/impeller/golden_tests/golden_playground_test.h index e220d5c4b618d..05fc5d09fe217 100644 --- a/impeller/golden_tests/golden_playground_test.h +++ b/impeller/golden_tests/golden_playground_test.h @@ -12,6 +12,10 @@ #include "flutter/impeller/renderer/render_target.h" #include "flutter/testing/testing.h" +#if FML_OS_MACOSX +#include "flutter/fml/platform/darwin/scoped_nsautorelease_pool.h" +#endif + namespace impeller { class GoldenPlaygroundTest @@ -51,6 +55,11 @@ class GoldenPlaygroundTest struct GoldenPlaygroundTestImpl; // This is only a shared_ptr so it can work with a forward declared type. std::shared_ptr pimpl_; + +#if FML_OS_MACOSX + fml::ScopedNSAutoreleasePool autorelease_pool_; +#endif + FML_DISALLOW_COPY_AND_ASSIGN(GoldenPlaygroundTest); }; diff --git a/impeller/playground/playground.cc b/impeller/playground/playground.cc index 4f61c5c5020ef..769dc62c2410e 100644 --- a/impeller/playground/playground.cc +++ b/impeller/playground/playground.cc @@ -31,8 +31,7 @@ #include "third_party/imgui/imgui.h" #if FML_OS_MACOSX -#include -#include +#include "fml/platform/darwin/scoped_nsautorelease_pool.h" #endif namespace impeller { @@ -183,23 +182,6 @@ void Playground::SetCursorPosition(Point pos) { cursor_position_ = pos; } -#if FML_OS_MACOSX -class AutoReleasePool { - public: - AutoReleasePool() { - pool_ = reinterpret_cast(objc_msgSend)( - objc_getClass("NSAutoreleasePool"), sel_getUid("new")); - } - ~AutoReleasePool() { - reinterpret_cast(objc_msgSend)(pool_, sel_getUid("drain")); - } - - private: - typedef id (*msg_send)(void*, SEL); - id pool_; -}; -#endif - bool Playground::OpenPlaygroundHere( const Renderer::RenderCallback& render_callback) { if (!switches_.enable_playground) { @@ -262,7 +244,7 @@ bool Playground::OpenPlaygroundHere( while (true) { #if FML_OS_MACOSX - AutoReleasePool pool; + fml::ScopedNSAutoreleasePool pool; #endif ::glfwPollEvents(); diff --git a/impeller/playground/playground_test.h b/impeller/playground/playground_test.h index f1c732f0a08db..2a4b4aa5dc933 100644 --- a/impeller/playground/playground_test.h +++ b/impeller/playground/playground_test.h @@ -13,6 +13,10 @@ #include "impeller/playground/playground.h" #include "impeller/playground/switches.h" +#if FML_OS_MACOSX +#include "flutter/fml/platform/darwin/scoped_nsautorelease_pool.h" +#endif + namespace impeller { class PlaygroundTest : public Playground, @@ -42,6 +46,10 @@ class PlaygroundTest : public Playground, // |Playground| bool ShouldKeepRendering() const; +#if FML_OS_MACOSX + fml::ScopedNSAutoreleasePool autorelease_pool_; +#endif + FML_DISALLOW_COPY_AND_ASSIGN(PlaygroundTest); };