devdraw: rewrite the Cocoa screen using Metal

Add a new macOS cocoa screen, cocoa-screen-metal.m.
Rewrite the macOS cocoa drawing code to use the builtin runloop,
and use Metal to push pixels with CAMetalLayer.

Remove all of the deprecated code, and simplify some of the logic.
Modify mkwsysrules.sh such that the new code is used only when
the system version is equal or higher than 10.14.

Allow touch events to simulate mouse clicks:
three finger tap for the middle mouse button;
four finger tap for the 2-1 chord.

Support Tresize.

Scale 16x16 Cursor up to 32x32 with an EPX algorithm.

Support macOS input sources including the basic dead keys and the
advanced CJK input methods.

Increase the communication buffers in cocoa-srv.c to allow more
input, especially for long sentences prepared by the macOS input
souces.
This commit is contained in:
Xiao-Yong Jin 2018-10-21 20:59:21 -05:00 committed by Russ Cox
parent de43b1629d
commit 9af9ceca26
8 changed files with 1307 additions and 21 deletions

View file

@ -1,11 +1,13 @@
Cursor bigarrow = {
{0, 0},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFC,
0xFF, 0xF0, 0xFF, 0xF0, 0xFF, 0xF8, 0xFF, 0xFC,
0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFC,
0xF3, 0xF8, 0xF1, 0xF0, 0xE0, 0xE0, 0xC0, 0x40},
{ -1, -1 },
{ 0xFF, 0xFF, 0x80, 0x01, 0x80, 0x02, 0x80, 0x0C,
0x80, 0x10, 0x80, 0x10, 0x80, 0x08, 0x80, 0x04,
0x80, 0x02, 0x80, 0x01, 0x80, 0x02, 0x8C, 0x04,
0x92, 0x08, 0x91, 0x10, 0xA0, 0xA0, 0xC0, 0x40,
},
{ 0x00, 0x00, 0x7F, 0xFE, 0x7F, 0xFC, 0x7F, 0xF0,
0x7F, 0xE0, 0x7F, 0xE0, 0x7F, 0xF0, 0x7F, 0xF8,
0x7F, 0xFC, 0x7F, 0xFE, 0x7F, 0xFC, 0x73, 0xF8,
0x61, 0xF0, 0x60, 0xE0, 0x40, 0x40, 0x00, 0x00},
0x61, 0xF0, 0x60, 0xE0, 0x40, 0x40, 0x00, 0x00,
},
};

File diff suppressed because it is too large Load diff

View file

@ -16,5 +16,9 @@ void servep9p(void);
void zlock(void);
void zunlock(void);
void resizeimg(void);
Rectangle mouserect;
int mouseresized;
void resizewindow(Rectangle);

View file

@ -21,7 +21,7 @@ typedef struct Tagbuf Tagbuf;
struct Kbdbuf
{
Rune r[32];
Rune r[256];
int ri;
int wi;
int stall;
@ -29,7 +29,7 @@ struct Kbdbuf
struct Mousebuf
{
Mouse m[32];
Mouse m[256];
Mouse last;
int ri;
int wi;
@ -38,7 +38,7 @@ struct Mousebuf
struct Tagbuf
{
int t[32];
int t[256];
int ri;
int wi;
};
@ -97,7 +97,7 @@ servep9p(void)
/* pick off messages one by one */
if(convM2W(mbuf, nn+4, &m) <= 0)
sysfatal("cannot convert message");
if(trace) fprint(2, "<- %W\n", &m);
if(trace) fprint(2, "%ud [%d] <- %W\n", nsec()/1000000, threadid(), &m);
runmsg(&m);
}
}
@ -191,6 +191,7 @@ runmsg(Wsysmsg *m)
break;
case Trddraw:
zlock();
n = m->count;
if(n > sizeof buf)
n = sizeof buf;
@ -202,13 +203,16 @@ runmsg(Wsysmsg *m)
m->data = buf;
replymsg(m);
}
zunlock();
break;
case Twrdraw:
zlock();
if(_drawmsgwrite(m->data, m->count) < 0)
replyerror(m);
else
replymsg(m);
zunlock();
break;
case Ttop:
@ -217,7 +221,9 @@ runmsg(Wsysmsg *m)
break;
case Tresize:
// _xresizewindow(m->rect);
#if OSX_VERSION >= 101400
resizewindow(m->rect);
#endif
replymsg(m);
break;
}
@ -238,7 +244,7 @@ replymsg(Wsysmsg *m)
if(m->type%2 == 0)
m->type++;
if(trace) fprint(2, "-> %W\n", m);
if(trace) fprint(2, "%ud [%d] -> %W\n", nsec()/1000000, threadid(), m);
/* copy to output buffer */
n = sizeW2M(m);
@ -293,11 +299,11 @@ matchmouse(void)
mousetags.ri = 0;
m.mouse = mouse.m[mouse.ri];
m.resized = mouseresized;
mouseresized = 0;
/*
if(m.resized)
fprint(2, "sending resize\n");
*/
mouseresized = 0;
mouse.ri++;
if(mouse.ri == nelem(mouse.m))
mouse.ri = 0;
@ -367,8 +373,6 @@ abortcompose(void)
keystroke(Kalt);
}
void resizeimg(void);
void
keystroke(int c)
{

View file

@ -25,4 +25,11 @@ qunlock(QLock *q)
{
pthread_mutex_unlock(&q->m);
}
int
threadid(void)
{
return pthread_mach_thread_np(pthread_self());
}
#endif

View file

@ -30,4 +30,5 @@
void qlock(QLock*);
void qunlock(QLock*);
int threadid(void);
#endif

View file

@ -35,6 +35,9 @@ latin1.h: $PLAN9/lib/keyboard $O.mklatinkbd
$O.macargv: $MACARGV
$LD -o $target $prereq
cocoa-screen-metal-objc.$O: cocoa-screen-metal.m
$CC $CFLAGS $OBJCFLAGS -o $target cocoa-screen-metal.m
%-objc.$O: %.m
$CC $CFLAGS -o $target $stem.m

View file

@ -60,7 +60,12 @@ elif [ $WSYSTYPE = osx ]; then
echo 'WSYSOFILES=$WSYSOFILES osx-screen-carbon-objc.o osx-draw.o osx-srv.o'
echo 'MACARGV=macargv.o'
elif [ $WSYSTYPE = osx-cocoa ]; then
if sw_vers|awk '/ProductVersion/{split($2,a,".");exit(a[2]<14)}' >/dev/null; then # 0 is true in sh.
echo 'OBJCFLAGS=$OBJCFLAGS -fobjc-arc'
echo 'WSYSOFILES=$WSYSOFILES osx-draw.o cocoa-screen-metal-objc.o cocoa-srv.o cocoa-thread.o'
else
echo 'WSYSOFILES=$WSYSOFILES osx-draw.o cocoa-screen-objc.o cocoa-srv.o cocoa-thread.o'
fi
echo 'MACARGV=macargv-objc.o'
elif [ $WSYSTYPE = nowsys ]; then
echo 'WSYSOFILES=nowsys.o'