devdraw/OSX: flush to screen in background, fix resize bug
This commit is contained in:
parent
607880ce78
commit
d69cf634a8
1 changed files with 35 additions and 2 deletions
|
|
@ -50,6 +50,8 @@ struct {
|
||||||
CGImageRef image;
|
CGImageRef image;
|
||||||
CGContextRef windowctx;
|
CGContextRef windowctx;
|
||||||
PasteboardRef snarf;
|
PasteboardRef snarf;
|
||||||
|
int needflush;
|
||||||
|
QLock flushlock;
|
||||||
} osx;
|
} osx;
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
|
@ -319,6 +321,8 @@ mouseevent(EventRef event)
|
||||||
|
|
||||||
// OS X swaps button 2 and 3
|
// OS X swaps button 2 and 3
|
||||||
but = (but & ~6) | ((but & 4)>>1) | ((but&2)<<1);
|
but = (but & ~6) | ((but & 4)>>1) | ((but&2)<<1);
|
||||||
|
|
||||||
|
but = mouseswap(but);
|
||||||
|
|
||||||
// Apply keyboard modifiers and pretend it was a real mouse button.
|
// Apply keyboard modifiers and pretend it was a real mouse button.
|
||||||
// (Modifiers typed while holding the button go into kbuttons,
|
// (Modifiers typed while holding the button go into kbuttons,
|
||||||
|
|
@ -507,6 +511,29 @@ eresized(int new)
|
||||||
osx.image = image;
|
osx.image = image;
|
||||||
osx.screenimage = m;
|
osx.screenimage = m;
|
||||||
osx.screenr = r;
|
osx.screenr = r;
|
||||||
|
|
||||||
|
// I'm not 100% sure why this is necessary
|
||||||
|
// but otherwise some resizes (esp. vertical ones)
|
||||||
|
// stop updating the screen.
|
||||||
|
qlock(&osx.flushlock);
|
||||||
|
QDEndCGContext(GetWindowPort(osx.window), &osx.windowctx);
|
||||||
|
osx.windowctx = nil;
|
||||||
|
qunlock(&osx.flushlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
flushproc(void *v)
|
||||||
|
{
|
||||||
|
for(;;){
|
||||||
|
if(osx.needflush && osx.windowctx && canqlock(&osx.flushlock)){
|
||||||
|
if(osx.windowctx){
|
||||||
|
CGContextFlush(osx.windowctx);
|
||||||
|
osx.needflush = 0;
|
||||||
|
}
|
||||||
|
qunlock(&osx.flushlock);
|
||||||
|
}
|
||||||
|
usleep(33333);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -515,8 +542,11 @@ _flushmemscreen(Rectangle r)
|
||||||
CGRect cgr;
|
CGRect cgr;
|
||||||
CGImageRef subimg;
|
CGImageRef subimg;
|
||||||
|
|
||||||
if(osx.windowctx == nil)
|
qlock(&osx.flushlock);
|
||||||
|
if(osx.windowctx == nil){
|
||||||
QDBeginCGContext(GetWindowPort(osx.window), &osx.windowctx);
|
QDBeginCGContext(GetWindowPort(osx.window), &osx.windowctx);
|
||||||
|
proccreate(flushproc, nil, 256*1024);
|
||||||
|
}
|
||||||
|
|
||||||
cgr.origin.x = r.min.x;
|
cgr.origin.x = r.min.x;
|
||||||
cgr.origin.y = r.min.y;
|
cgr.origin.y = r.min.y;
|
||||||
|
|
@ -525,7 +555,8 @@ _flushmemscreen(Rectangle r)
|
||||||
subimg = CGImageCreateWithImageInRect(osx.image, cgr);
|
subimg = CGImageCreateWithImageInRect(osx.image, cgr);
|
||||||
cgr.origin.y = Dy(osx.screenr) - r.max.y; // XXX how does this make any sense?
|
cgr.origin.y = Dy(osx.screenr) - r.max.y; // XXX how does this make any sense?
|
||||||
CGContextDrawImage(osx.windowctx, cgr, subimg);
|
CGContextDrawImage(osx.windowctx, cgr, subimg);
|
||||||
CGContextFlush(osx.windowctx);
|
osx.needflush = 1;
|
||||||
|
qunlock(&osx.flushlock);
|
||||||
CGImageRelease(subimg);
|
CGImageRelease(subimg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -536,6 +567,7 @@ fullscreen(void)
|
||||||
static WindowRef oldwindow;
|
static WindowRef oldwindow;
|
||||||
GDHandle device;
|
GDHandle device;
|
||||||
|
|
||||||
|
qlock(&osx.flushlock);
|
||||||
if(osx.isfullscreen){
|
if(osx.isfullscreen){
|
||||||
if(osx.windowctx){
|
if(osx.windowctx){
|
||||||
QDEndCGContext(GetWindowPort(osx.window), &osx.windowctx);
|
QDEndCGContext(GetWindowPort(osx.window), &osx.windowctx);
|
||||||
|
|
@ -557,6 +589,7 @@ fullscreen(void)
|
||||||
osx.isfullscreen = 1;
|
osx.isfullscreen = 1;
|
||||||
osx.fullscreentime = msec();
|
osx.fullscreentime = msec();
|
||||||
}
|
}
|
||||||
|
qunlock(&osx.flushlock);
|
||||||
eresized(1);
|
eresized(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue