mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-16 14:42:44 +00:00
Use @autoreleasepool to avoid accumulating objects
This commit is contained in:
parent
0b37d23c37
commit
5ba071e760
@ -1,5 +1,5 @@
|
|||||||
// SHE library
|
// SHE library
|
||||||
// Copyright (C) 2015-2016 David Capello
|
// Copyright (C) 2015-2017 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
// Read LICENSE.txt for more information.
|
// Read LICENSE.txt for more information.
|
||||||
@ -19,40 +19,42 @@ void OSXEventQueue::getEvent(Event& ev, bool canWait)
|
|||||||
{
|
{
|
||||||
ev.setType(Event::None);
|
ev.setType(Event::None);
|
||||||
|
|
||||||
retry:;
|
@autoreleasepool {
|
||||||
NSApplication* app = [NSApplication sharedApplication];
|
retry:;
|
||||||
if (!app)
|
NSApplication* app = [NSApplication sharedApplication];
|
||||||
return;
|
if (!app)
|
||||||
|
return;
|
||||||
|
|
||||||
// Pump the whole queue of Cocoa events
|
// Pump the whole queue of Cocoa events
|
||||||
NSEvent* event;
|
NSEvent* event;
|
||||||
do {
|
do {
|
||||||
event = [app nextEventMatchingMask:NSAnyEventMask
|
event = [app nextEventMatchingMask:NSAnyEventMask
|
||||||
untilDate:[NSDate distantPast]
|
untilDate:[NSDate distantPast]
|
||||||
inMode:NSDefaultRunLoopMode
|
inMode:NSDefaultRunLoopMode
|
||||||
dequeue:YES];
|
dequeue:YES];
|
||||||
if (event) {
|
if (event) {
|
||||||
// Intercept <Control+Tab>, <Cmd+[>, and other keyboard
|
// Intercept <Control+Tab>, <Cmd+[>, and other keyboard
|
||||||
// combinations, and send them directly to the main
|
// combinations, and send them directly to the main
|
||||||
// NSView. Without this, the NSApplication intercepts the key
|
// NSView. Without this, the NSApplication intercepts the key
|
||||||
// combination and use it to go to the next key view.
|
// combination and use it to go to the next key view.
|
||||||
if (event.type == NSKeyDown) {
|
if (event.type == NSKeyDown) {
|
||||||
[app.mainWindow.contentView keyDown:event];
|
[app.mainWindow.contentView keyDown:event];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[app sendEvent:event];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
} while (event);
|
||||||
[app sendEvent:event];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (event);
|
|
||||||
|
|
||||||
if (!m_events.try_pop(ev)) {
|
if (!m_events.try_pop(ev)) {
|
||||||
if (canWait) {
|
if (canWait) {
|
||||||
// Wait until there is a Cocoa event in queue
|
// Wait until there is a Cocoa event in queue
|
||||||
[NSApp nextEventMatchingMask:NSAnyEventMask
|
[NSApp nextEventMatchingMask:NSAnyEventMask
|
||||||
untilDate:[NSDate distantFuture]
|
untilDate:[NSDate distantFuture]
|
||||||
inMode:NSDefaultRunLoopMode
|
inMode:NSDefaultRunLoopMode
|
||||||
dequeue:NO];
|
dequeue:NO];
|
||||||
goto retry;
|
goto retry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// SHE library
|
// SHE library
|
||||||
// Copyright (C) 2012-2016 David Capello
|
// Copyright (C) 2012-2017 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
// Read LICENSE.txt for more information.
|
// Read LICENSE.txt for more information.
|
||||||
@ -113,14 +113,16 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateWindow(const gfx::Rect& bounds) {
|
void updateWindow(const gfx::Rect& bounds) {
|
||||||
int scale = this->scale();
|
@autoreleasepool {
|
||||||
NSView* view = m_window.contentView;
|
int scale = this->scale();
|
||||||
[view setNeedsDisplayInRect:
|
NSView* view = m_window.contentView;
|
||||||
NSMakeRect(bounds.x*scale,
|
[view setNeedsDisplayInRect:
|
||||||
view.frame.size.height - (bounds.y+bounds.h)*scale,
|
NSMakeRect(bounds.x*scale,
|
||||||
bounds.w*scale,
|
view.frame.size.height - (bounds.y+bounds.h)*scale,
|
||||||
bounds.h*scale)];
|
bounds.w*scale,
|
||||||
[view displayIfNeeded];
|
bounds.h*scale)];
|
||||||
|
[view displayIfNeeded];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTranslateDeadKeys(bool state) {
|
void setTranslateDeadKeys(bool state) {
|
||||||
@ -304,7 +306,7 @@ private:
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
bitmap.lockPixels();
|
bitmap.lockPixels();
|
||||||
{
|
@autoreleasepool {
|
||||||
NSGraphicsContext* gc = [NSGraphicsContext currentContext];
|
NSGraphicsContext* gc = [NSGraphicsContext currentContext];
|
||||||
CGContextRef cg = (CGContextRef)[gc graphicsPort];
|
CGContextRef cg = (CGContextRef)[gc graphicsPort];
|
||||||
CGColorSpaceRef colorSpace = CGDisplayCopyColorSpace(CGMainDisplayID());
|
CGColorSpaceRef colorSpace = CGDisplayCopyColorSpace(CGMainDisplayID());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user