[Impeller] Create an autorelease pool for Impeller tests running on macOS. (flutter/engine#42265)
See https://github.com/flutter/flutter/issues/127358
This commit is contained in:
@@ -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
|
||||
@@ -3572,6 +3574,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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
@@ -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_
|
||||
@@ -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<GoldenPlaygroundTestImpl> pimpl_;
|
||||
|
||||
#if FML_OS_MACOSX
|
||||
fml::ScopedNSAutoreleasePool autorelease_pool_;
|
||||
#endif
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(GoldenPlaygroundTest);
|
||||
};
|
||||
|
||||
|
||||
@@ -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 {
|
||||
@@ -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) {
|
||||
@@ -262,7 +244,7 @@ bool Playground::OpenPlaygroundHere(
|
||||
|
||||
while (true) {
|
||||
#if FML_OS_MACOSX
|
||||
AutoReleasePool pool;
|
||||
fml::ScopedNSAutoreleasePool pool;
|
||||
#endif
|
||||
::glfwPollEvents();
|
||||
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user