X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fplat%2FDarwin.java;h=a3e4141e34b19c6e2942b4f1f063f8f524db15ac;hb=745fb6aad79e10eb8c402b8fa6a591769c0fcdfb;hp=983c42f6ec5f3228482d54555ffb02314c3f9aaf;hpb=097a2d2e60f82064d5033ec1ee8e28c2545926ab;p=org.ibex.core.git diff --git a/src/org/xwt/plat/Darwin.java b/src/org/xwt/plat/Darwin.java index 983c42f..a3e4141 100644 --- a/src/org/xwt/plat/Darwin.java +++ b/src/org/xwt/plat/Darwin.java @@ -13,11 +13,6 @@ public class Darwin extends POSIX { private CarbonOpenGL openGL; boolean jaguar; // true if we are on OS X >= 10.2 - // TEMPORARY HACKS (remove these when we ditch platform fonts) - protected int _stringWidth(String font, String text) { return (int)Math.round(6.5 * text.length()); } - protected int _getMaxAscent(String font) { return 10; } - protected int _getMaxDescent(String font) { return 2; } - // General Methods protected String _getAltKeyName() { return "Option"; } protected boolean _needsAutoClick() { return false; } @@ -32,9 +27,8 @@ public class Darwin extends POSIX { private native static int cgScreenWidth(); private native static int cgScreenHeight(); protected native void _newBrowserWindow(String url); - protected native Proxy natDetectProxy(); + protected native HTTP.Proxy natDetectProxy(); private native void natInit(); - protected native void _exit(); private native String natGetClipBoard(); private native void natSetClipBoard(String text); @@ -53,7 +47,6 @@ public class Darwin extends POSIX { public Semaphore sem = new Semaphore(); public String fileName; public String saveName; - public RawData rawUPP; } private native void natFileDialog(FileDialogHelper helper, String suggestedFileName, boolean write); protected String _fileDialog(final String fn, final boolean w) { @@ -67,9 +60,6 @@ public class Darwin extends POSIX { } - // Called by main thread after initialization, this is the event handler - protected native void _running(); - static void abort(String err) { throw new Error(err); } @@ -81,12 +71,15 @@ public class Darwin extends POSIX { } } - protected synchronized Proxy _detectProxy() { + protected synchronized HTTP.Proxy _detectProxy() { return natDetectProxy(); } private static native final boolean isJaguar(); + // Called by main thread after initialization, this is the event handler + protected native void runApplicationEventLoop(); + public void init() { super.init(); jaguar = isJaguar(); @@ -95,12 +88,14 @@ public class Darwin extends POSIX { openGL.init(); } catch(OpenGL.NotSupportedException e) { Log.log(this,"WARNING: OpenGL support not available: " + e); - // FIXME: We need to fallback to Quartz2D + // FEATURE: fall back to quartz 2d throw new Error("No OpenGL support"); } natInit(); } + public void _running() { runApplicationEventLoop(); } + private final class CarbonOpenGL extends OpenGL { public RawData rawPixelFormat; public RawData rawSharedContext; @@ -131,10 +126,13 @@ public class Darwin extends POSIX { protected native void activateSharedContext(); } - static abstract class CarbonSurface extends Surface { + static abstract class CarbonSurface extends Surface.DoubleBufferedSurface { RawData rawWindowRef; - RawData rawEventHandlerUPP; int modifiers; + int winWidth; + int winHeight; + + boolean pendingResize; private native void natSetInvisible(boolean i); public void setInvisible(final boolean i) { CarbonMessage.add(new CarbonMessage() { public void perform() { natSetInvisible(i); } }); } @@ -148,15 +146,15 @@ public class Darwin extends POSIX { public void setTitleBarText(final String s) { CarbonMessage.add(new CarbonMessage() { public void perform() { natSetTitleBarText(s); } }); } private native void natSetSize(int w, int h); public void setSize(final int w, final int h) { CarbonMessage.add(new CarbonMessage() { public void perform() { natSetSize(w,h); } }); } - private native void natSetLocation(int x, int y); - public void setLocation(final int x, final int y) { CarbonMessage.add(new CarbonMessage() { public void perform() { natSetLocation(x,y); } }); } + private native void natSetLocation(); + public void setLocation() { CarbonMessage.add(new CarbonMessage() { public void perform() { natSetLocation(); } }); } private native void natToFront(); public void toFront() { CarbonMessage.add(new CarbonMessage() { public void perform() { natToFront(); } }); } private native void natToBack(); public void toBack() { CarbonMessage.add(new CarbonMessage() { public void perform() { natToBack(); } }); } private native void natSetLimits(int minWidth, int minHeight, int maxWidth, int maxHeight); public void setLimits(final int mnw, final int mnh, final int mxw, final int mxh) { - if(Carbon.singleton.jaguar) + if(Darwin.singleton.jaguar) CarbonMessage.add(new CarbonMessage() { public void perform() { natSetLimits(mnw,mnh,mxw,mxh); } }); } private native void natSyncCursor(int n); @@ -173,11 +171,9 @@ public class Darwin extends POSIX { final int n_ = n; CarbonMessage.add(new CarbonMessage() { public void perform() { natSyncCursor(n_); } }); } - - public void _sizeChange(int w, int h) { SizeChange(w,h); } - + /* Drawing stuff */ - public abstract void blit(DoubleBuffer s, int sx, int sy, int dx, int dy, int dx2, int dy2); + public abstract void blit(PixelBuffer s, int sx, int sy, int dx, int dy, int dx2, int dy2); public final void _dispose() { CarbonMessage.add(new CarbonMessage() { public void perform() { natDispose(); } }); } public native void natDispose(); @@ -191,10 +187,13 @@ public class Darwin extends POSIX { sem.block(); } - public void reshape(int w, int h) { } + public void needsReshape() { } + protected static native void blitLock(); + protected static native void blitUnlock(); + protected static native void blitWait(); } - static class GLCarbonDoubleBuffer extends OpenGL.GLDoubleBuffer { + static class GLCarbonPixelBuffer extends OpenGL.GLPixelBuffer { RawData rawCTX; RawData rawWindowRef; int textureName; @@ -209,12 +208,12 @@ public class Darwin extends POSIX { if(!gl.rectangularTextures) n = OpenGL.roundToPowerOf2(n); return Math.min(n,gl.maxAglSurfaceTexSize); } - public GLCarbonDoubleBuffer(int w, int h, final CarbonOpenGL gl) { + public GLCarbonPixelBuffer(int w, int h, final CarbonOpenGL gl) { super(fixupDimension(gl,w),fixupDimension(gl,h)); this.gl = gl; rectTexture = gl.hasRectangularTextures(); final Semaphore sem = new Semaphore(); - CarbonMessage.add(new CarbonMessage() { public void perform() { GLCarbonDoubleBuffer.this.natInit(); sem.release(); } }); + CarbonMessage.add(new CarbonMessage() { public void perform() { GLCarbonPixelBuffer.this.natInit(); sem.release(); } }); sem.block(); } public native void activateContext(); @@ -227,9 +226,11 @@ public class Darwin extends POSIX { static class GLCarbonSurface extends CarbonSurface { RawData rawCTX; CarbonOpenGL gl; - boolean sizeChange; - + boolean needsReshape; + private final native void natInit(); + private final native void flush(); + private final native void clear(); public GLCarbonSurface(Box root, boolean framed, CarbonOpenGL gl) { super(root,framed); @@ -242,39 +243,52 @@ public class Darwin extends POSIX { mxh = Math.min(mxh,gl.maxSurfaceHeight); super.setLimits(mnw,mnh,mxw,mxh); } - public void _sizeChange(int w, int h) { - sizeChange = true; - super._sizeChange(w,h); - } public void setSize(int w, int h) { - sizeChange = true; w = Math.min(w,gl.maxSurfaceWidth); h = Math.min(h,gl.maxSurfaceWidth); super.setSize(w,h); } - private native void natBlit(GLCarbonDoubleBuffer db, int sx, int sy, int dx, int dy, int dx2, int dy2); - public synchronized void blit(DoubleBuffer db, int sx, int sy, int dx, int dy, int dx2, int dy2) { - natBlit((GLCarbonDoubleBuffer)db,sx,sy,dx,dy,dx2,dy2); + private native void natBlit(GLCarbonPixelBuffer db, int sx, int sy, int dx, int dy, int dx2, int dy2); + public void blit(PixelBuffer db, int sx, int sy, int dx, int dy, int dx2, int dy2) { + natBlit((GLCarbonPixelBuffer)db,sx,sy,dx,dy,dx2,dy2); } - private native void natReshape(int w, int h); - public synchronized void reshape(int w, int h) { natReshape(w,h); } + // The blit_lock ensures the window size does not change through the entire blit operation. + public void render_() { + blitLock(); + while(pendingResize) blitWait(); + if(needsReshape) { + needsReshape = false; + + reshape(winWidth,winHeight); + clear(); + Dirty(0,0,getWidth(),getHeight()); + } + super.render_(); + flush(); + blitUnlock(); + } + + private native void reshape(int w, int h); + // blit_lock is assumed to be held + public void needsReshape() { needsReshape = true; } + public native void natDispose(); } - /*private class QZCarbonDoubleBuffer extends DoubleBuffer { + /*private class QZCarbonPixelBuffer extends PixelBuffer { - public QZCarbonDoubleBuffer(int width, int height) { + public QZCarbonPixelBuffer(int width, int height) { } } private class QZCarbonSurface extends CarbonSurface { public QZCarbonSurface(Box root, boolean framed) { super(b,root); } - public native void blit(DoubleBuffer s, int sx, int sy, int dx, int dy, int dx2, int dy2); + public native void blit(PixelBuffer s, int sx, int sy, int dx, int dy, int dx2, int dy2); } private class QZCarbonPicture extends Picture { @@ -290,11 +304,11 @@ public class Darwin extends POSIX { } }*/ - protected DoubleBuffer _createDoubleBuffer(int w, int h, Surface owner) { + protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { if(openGL != null) - return new GLCarbonDoubleBuffer(w,h,openGL); + return new GLCarbonPixelBuffer(w,h,openGL); else - return /*new QZCarbonDoubleBuffer(w,h)*/ null; + return /*new QZCarbonPixelBuffer(w,h)*/ null; } protected Surface _createSurface(Box b, boolean framed) { if(openGL != null) @@ -308,6 +322,12 @@ public class Darwin extends POSIX { else return /*new QZCarbonPicture(data,w,h);*/ null; } + protected Picture _createAlphaOnlyPicture(byte[] data, int w, int h) { + if(openGL != null) + return openGL.createAlphaOnlyPicture(data,w,h); + else + return super.createAlphaOnlyPicture(data,w,h); + } /* A message that is sent through the carbon event queue */ private static abstract class CarbonMessage {