X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fplat%2FDarwin.java;h=a4f533e409f92429439add71f01ff0e1b1e4bf28;hb=14be229c827cd4034184ea29d6653f6cbd969507;hp=d6aa8d86f59903279bcd26e26b5f090acc9023f7;hpb=f8e2aa0c7c2b5bd2bca1808fb15dfc8e75d96d56;p=org.ibex.core.git diff --git a/src/org/xwt/plat/Darwin.java b/src/org/xwt/plat/Darwin.java index d6aa8d8..a4f533e 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; } @@ -34,7 +29,6 @@ public class Darwin extends POSIX { protected native void _newBrowserWindow(String url); 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); } @@ -87,36 +77,43 @@ public class Darwin extends POSIX { private static native final boolean isJaguar(); - public void init() { - super.init(); + public void postInit() { jaguar = isJaguar(); try { openGL = new CarbonOpenGL(); openGL.init(); } catch(OpenGL.NotSupportedException e) { - Log.log(this,"WARNING: OpenGL support not available: " + e); - // FIXME: We need to fallback to Quartz2D + Log.info(this,"WARNING: OpenGL support not available: " + e); + // FEATURE: fall back to quartz 2d throw new Error("No OpenGL support"); } natInit(); } + protected native void runApplicationEventLoop(); + private class DarwinScheduler extends org.xwt.Scheduler { + public void run() { + new Thread() { public void run() { defaultRun(); } }.start(); + runApplicationEventLoop(); + } + } + private final class CarbonOpenGL extends OpenGL { public RawData rawPixelFormat; - public RawData rawSharedContext; + public RawData rawSharedInterpreter; public int maxAglSurfaceTexSize; public int maxSurfaceWidth; public int maxSurfaceHeight; private native boolean initPixelFormat(); - private native void initSharedContext(); + private native void initSharedInterpreter(); public CarbonOpenGL() throws NotSupportedException { if(!jaguar) throw new NotSupportedException("OpenGL requires Mac OS X 10.2 or greater"); if(!initPixelFormat()) throw new NotSupportedException("Couldn't get an acceptable pixel format"); - initSharedContext(); + initSharedInterpreter(); } public void init() throws NotSupportedException { @@ -124,17 +121,20 @@ public class Darwin extends POSIX { maxAglSurfaceTexSize = rectangularTextures ? maxRectTexSize : maxTexSize; if(renderer.startsWith("ATI Radeon 7500")) { maxAglSurfaceTexSize = Math.min(rectangularTextures ? 1600 : 1024,maxAglSurfaceTexSize); - Log.log(this,"Working around Radeon 7500 bug: maxAglSurfaceTexSize: " + maxAglSurfaceTexSize); + Log.info(this,"Working around Radeon 7500 bug: maxAglSurfaceTexSize: " + maxAglSurfaceTexSize); } maxSurfaceWidth = maxSurfaceHeight = maxAglSurfaceTexSize; } - protected native void activateSharedContext(); + protected native void activateSharedInterpreter(); } - 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); } }); } @@ -147,9 +147,9 @@ public class Darwin extends POSIX { private native void natSetTitleBarText(String s); 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); } }); } + public void _setSize(final int w, final int h) { CarbonMessage.add(new CarbonMessage() { public void perform() { natSetSize(w,h); } }); } + 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(); @@ -173,9 +173,7 @@ 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(PixelBuffer s, int sx, int sy, int dx, int dy, int dx2, int dy2); @@ -191,7 +189,10 @@ 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 GLCarbonPixelBuffer extends OpenGL.GLPixelBuffer { @@ -217,7 +218,7 @@ public class Darwin extends POSIX { CarbonMessage.add(new CarbonMessage() { public void perform() { GLCarbonPixelBuffer.this.natInit(); sem.release(); } }); sem.block(); } - public native void activateContext(); + public native void activateInterpreter(); protected void finalize() { CarbonMessage.add(new CarbonMessage() { public void perform() { natCleanup(rawWindowRef,rawCTX); } }); gl.deleteTexture(textureName); @@ -227,9 +228,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,26 +245,40 @@ 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; + public void _setSize(int w, int h) { w = Math.min(w,gl.maxSurfaceWidth); h = Math.min(h,gl.maxSurfaceWidth); - super.setSize(w,h); + super._setSize(w,h); } private native void natBlit(GLCarbonPixelBuffer db, int sx, int sy, int dx, int dy, int dx2, int dy2); - public synchronized void blit(PixelBuffer 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,winWidth,winHeight); + //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(); } @@ -302,12 +319,18 @@ public class Darwin extends POSIX { else return /*new QZCarbonSufrace(b,framed)*/ null; } - protected Picture _createPicture(int[] data, int w, int h) { + protected Picture _createPicture() { if(openGL != null) - return openGL.createPicture(data,w,h); + return openGL._createPicture(true); else return /*new QZCarbonPicture(data,w,h);*/ null; } + protected org.xwt.Font.Glyph _createGlyph(org.xwt.Font f, char c) { + if(openGL != null) + return openGL._createGlyph(f, c); + else + return super.createGlyph(f, c); + } /* A message that is sent through the carbon event queue */ private static abstract class CarbonMessage {