Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions fml/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 26 additions & 0 deletions fml/platform/darwin/scoped_nsautorelease_pool.cc
Original file line number Diff line number Diff line change
@@ -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 <objc/message.h>
#include <objc/runtime.h>

namespace {
typedef id (*msg_send)(void*, SEL);
} // anonymous namespace

namespace fml {

ScopedNSAutoreleasePool::ScopedNSAutoreleasePool() {
autorelease_pool_ = reinterpret_cast<msg_send>(objc_msgSend)(
objc_getClass("NSAutoreleasePool"), sel_getUid("new"));
}

ScopedNSAutoreleasePool::~ScopedNSAutoreleasePool() {
reinterpret_cast<msg_send>(objc_msgSend)(autorelease_pool_,
sel_getUid("drain"));
}

} // namespace fml
26 changes: 26 additions & 0 deletions fml/platform/darwin/scoped_nsautorelease_pool.h
Original file line number Diff line number Diff line change
@@ -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_;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add FML_DISALLOW_COPY_AND_ASSIGN

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


FML_DISALLOW_COPY_AND_ASSIGN(ScopedNSAutoreleasePool);
};

} // namespace fml

#endif // FLUTTER_FML_PLATFORM_DARWIN_SCOPED_NSAUTORELEASEPOOL_H_
9 changes: 9 additions & 0 deletions impeller/golden_tests/golden_playground_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<GoldenPlaygroundTestImpl> pimpl_;

#if FML_OS_MACOSX
fml::ScopedNSAutoreleasePool autorelease_pool_;
#endif

FML_DISALLOW_COPY_AND_ASSIGN(GoldenPlaygroundTest);
};

Expand Down
22 changes: 2 additions & 20 deletions impeller/playground/playground.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
#include "third_party/imgui/imgui.h"

#if FML_OS_MACOSX
#include <objc/message.h>
#include <objc/runtime.h>
#include "fml/platform/darwin/scoped_nsautorelease_pool.h"
#endif

namespace impeller {
Expand Down Expand Up @@ -183,23 +182,6 @@ void Playground::SetCursorPosition(Point pos) {
cursor_position_ = pos;
}

#if FML_OS_MACOSX
class AutoReleasePool {
public:
AutoReleasePool() {
pool_ = reinterpret_cast<msg_send>(objc_msgSend)(
objc_getClass("NSAutoreleasePool"), sel_getUid("new"));
}
~AutoReleasePool() {
reinterpret_cast<msg_send>(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) {
Expand Down Expand Up @@ -262,7 +244,7 @@ bool Playground::OpenPlaygroundHere(

while (true) {
#if FML_OS_MACOSX
AutoReleasePool pool;
fml::ScopedNSAutoreleasePool pool;
#endif
::glfwPollEvents();

Expand Down
8 changes: 8 additions & 0 deletions impeller/playground/playground_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
};

Expand Down