[Impeller] Use NSAutoReleasePool for Metal playgrounds. (flutter/engine#40748)
[Impeller] Use NSAutoReleasePool for Metal playgrounds.
This commit is contained in:
@@ -30,6 +30,11 @@
|
||||
#include "third_party/imgui/backends/imgui_impl_glfw.h"
|
||||
#include "third_party/imgui/imgui.h"
|
||||
|
||||
#if FML_OS_MACOSX
|
||||
#include <objc/message.h>
|
||||
#include <objc/runtime.h>
|
||||
#endif
|
||||
|
||||
namespace impeller {
|
||||
|
||||
std::string PlaygroundBackendToString(PlaygroundBackend backend) {
|
||||
@@ -178,6 +183,23 @@ 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 (!is_enabled()) {
|
||||
@@ -239,6 +261,9 @@ bool Playground::OpenPlaygroundHere(
|
||||
::glfwShowWindow(window);
|
||||
|
||||
while (true) {
|
||||
#if FML_OS_MACOSX
|
||||
AutoReleasePool pool;
|
||||
#endif
|
||||
::glfwPollEvents();
|
||||
|
||||
if (::glfwWindowShouldClose(window)) {
|
||||
|
||||
Reference in New Issue
Block a user