diff --git a/mx.trufflesqueak/native-image.properties b/mx.trufflesqueak/native-image.properties index 68b4927a8..96d197225 100644 --- a/mx.trufflesqueak/native-image.properties +++ b/mx.trufflesqueak/native-image.properties @@ -5,11 +5,9 @@ ImageName = trufflesqueak Requires = language:nfi -JavaArgs = -Dpolyglot.engine.PreinitializeContexts=squeak +JavaArgs = -Dpolyglot.engine.PreinitializeContexts=squeak -Djava.awt.headless=false Args = -H:MaxRuntimeCompileMethods=5000 \ --enable-url-protocols=https \ - -H:+AssertInitializationSpecifiedForAllClasses \ --initialize-at-build-time=de.hpi.swa.trufflesqueak,org.bouncycastle \ - --initialize-at-build-time=java.awt,sun.awt.image,com.sun.jndi,sun.java2d.cmm \ - --initialize-at-run-time=sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher + --initialize-at-run-time=com.sun.imageio.plugins,com.sun.java.swing,java.applet,java.awt,javax.accessibility,javax.imageio,javax.swing,sun.awt,sun.datatransfer,sun.font,sun.java2d,sun.swing,com.sun.beans.util diff --git a/src/de.hpi.swa.trufflesqueak/src/META-INF/native-image/jni-config.json b/src/de.hpi.swa.trufflesqueak/src/META-INF/native-image/jni-config.json new file mode 100644 index 000000000..b9943f980 --- /dev/null +++ b/src/de.hpi.swa.trufflesqueak/src/META-INF/native-image/jni-config.json @@ -0,0 +1,506 @@ +[ +{ + "name":"[B" +}, +{ + "name":"[Lsun.java2d.loops.GraphicsPrimitive;" +}, +{ + "name":"[[B" +}, +{ + "name":"java.awt.AWTEvent", + "fields":[ + {"name":"bdata"}, + {"name":"consumed"}, + {"name":"id"} + ] +}, +{ + "name":"java.awt.AlphaComposite", + "fields":[ + {"name":"extraAlpha"}, + {"name":"rule"} + ] +}, +{ + "name":"java.awt.Color", + "fields":[{"name":"value"}], + "methods":[{"name":"getRGB","parameterTypes":[] }] +}, +{ + "name":"java.awt.Component", + "fields":[ + {"name":"appContext"}, + {"name":"background"}, + {"name":"foreground"}, + {"name":"graphicsConfig"}, + {"name":"height"}, + {"name":"isPacked"}, + {"name":"name"}, + {"name":"peer"}, + {"name":"width"}, + {"name":"x"}, + {"name":"y"} + ], + "methods":[ + {"name":"getLocationOnScreen_NoTreeLock","parameterTypes":[] }, + {"name":"getParent_NoClientCode","parameterTypes":[] } + ] +}, +{ + "name":"java.awt.Font", + "fields":[ + {"name":"pData"}, + {"name":"size"}, + {"name":"style"} + ], + "methods":[ + {"name":"getFamily_NoClientCode","parameterTypes":[] }, + {"name":"getFontPeer","parameterTypes":[] } + ] +}, +{ + "name":"java.awt.GraphicsEnvironment", + "methods":[{"name":"isHeadless","parameterTypes":[] }] +}, +{ + "name":"java.awt.Insets", + "fields":[ + {"name":"bottom"}, + {"name":"left"}, + {"name":"right"}, + {"name":"top"} + ] +}, +{ + "name":"java.awt.Rectangle", + "methods":[{"name":"","parameterTypes":["int","int","int","int"] }] +}, +{ + "name":"java.awt.event.InputEvent", + "fields":[{"name":"modifiers"}] +}, +{ + "name":"java.awt.event.KeyEvent", + "fields":[ + {"name":"isProxyActive"}, + {"name":"keyChar"}, + {"name":"keyCode"} + ] +}, +{ + "name":"java.awt.geom.AffineTransform", + "fields":[ + {"name":"m00"}, + {"name":"m01"}, + {"name":"m02"}, + {"name":"m10"}, + {"name":"m11"}, + {"name":"m12"} + ] +}, +{ + "name":"java.awt.geom.Path2D", + "fields":[ + {"name":"numTypes"}, + {"name":"pointTypes"}, + {"name":"windingRule"} + ] +}, +{ + "name":"java.awt.geom.Path2D$Float", + "fields":[{"name":"floatCoords"}] +}, +{ + "name":"java.awt.image.BufferedImage", + "fields":[ + {"name":"colorModel"}, + {"name":"imageType"}, + {"name":"raster"} + ], + "methods":[ + {"name":"getRGB","parameterTypes":["int","int","int","int","int[]","int","int"] }, + {"name":"setRGB","parameterTypes":["int","int","int","int","int[]","int","int"] } + ] +}, +{ + "name":"java.awt.image.ColorModel", + "fields":[ + {"name":"colorSpace"}, + {"name":"colorSpaceType"}, + {"name":"isAlphaPremultiplied"}, + {"name":"is_sRGB"}, + {"name":"nBits"}, + {"name":"numComponents"}, + {"name":"pData"}, + {"name":"supportsAlpha"}, + {"name":"transparency"} + ], + "methods":[{"name":"getRGBdefault","parameterTypes":[] }] +}, +{ + "name":"java.awt.image.DirectColorModel", + "methods":[{"name":"","parameterTypes":["int","int","int","int","int"] }] +}, +{ + "name":"java.awt.image.IndexColorModel", + "fields":[ + {"name":"allgrayopaque"}, + {"name":"colorData"}, + {"name":"map_size"}, + {"name":"rgb"}, + {"name":"transparent_index"} + ] +}, +{ + "name":"java.awt.image.Raster", + "fields":[ + {"name":"dataBuffer"}, + {"name":"height"}, + {"name":"minX"}, + {"name":"minY"}, + {"name":"numBands"}, + {"name":"numDataElements"}, + {"name":"sampleModel"}, + {"name":"sampleModelTranslateX"}, + {"name":"sampleModelTranslateY"}, + {"name":"width"} + ] +}, +{ + "name":"java.awt.image.SampleModel", + "fields":[ + {"name":"height"}, + {"name":"width"} + ], + "methods":[ + {"name":"getPixels","parameterTypes":["int","int","int","int","int[]","java.awt.image.DataBuffer"] }, + {"name":"setPixels","parameterTypes":["int","int","int","int","int[]","java.awt.image.DataBuffer"] } + ] +}, +{ + "name":"java.awt.image.SinglePixelPackedSampleModel", + "fields":[ + {"name":"bitMasks"}, + {"name":"bitOffsets"}, + {"name":"bitSizes"}, + {"name":"maxBitSize"} + ] +}, +{ + "name":"java.lang.Boolean", + "methods":[{"name":"getBoolean","parameterTypes":["java.lang.String"] }] +}, +{ + "name":"java.lang.System", + "methods":[ + {"name":"load","parameterTypes":["java.lang.String"] }, + {"name":"setProperty","parameterTypes":["java.lang.String","java.lang.String"] } + ] +}, +{ + "name":"java.lang.Thread", + "methods":[{"name":"yield","parameterTypes":[] }] +}, +{ + "name":"org.graalvm.launcher.AbstractLanguageLauncher", + "methods":[{"name":"runLauncher","parameterTypes":["byte[][]","int","long","boolean"] }] +}, +{ + "name":"org.graalvm.launcher.AbstractLanguageLauncher$RelaunchException", + "fields":[{"name":"vmArgs"}] +}, +{ + "name":"sun.awt.SunHints", + "fields":[{"name":"INTVAL_STROKE_PURE"}] +}, +{ + "name":"sun.awt.SunToolkit", + "methods":[ + {"name":"awtLock","parameterTypes":[] }, + {"name":"awtLockNotify","parameterTypes":[] }, + {"name":"awtLockNotifyAll","parameterTypes":[] }, + {"name":"awtLockWait","parameterTypes":["long"] }, + {"name":"awtUnlock","parameterTypes":[] } + ] +}, +{ + "name":"sun.awt.X11.XBaseWindow", + "fields":[{"name":"window"}], + "methods":[{"name":"getWindow","parameterTypes":[] }] +}, +{ + "name":"sun.awt.X11.XContentWindow" +}, +{ + "name":"sun.awt.X11.XErrorHandlerUtil", + "methods":[ + {"name":"globalErrorHandler","parameterTypes":["long","long"] }, + {"name":"init","parameterTypes":["long"] } + ] +}, +{ + "name":"sun.awt.X11.XFramePeer" +}, +{ + "name":"sun.awt.X11.XRootWindow", + "methods":[{"name":"getXRootWindow","parameterTypes":[] }] +}, +{ + "name":"sun.awt.X11.XToolkit", + "fields":[ + {"name":"modLockIsShiftLock"}, + {"name":"numLockMask"} + ] +}, +{ + "name":"sun.awt.X11.XWindow", + "fields":[ + {"name":"drawState"}, + {"name":"graphicsConfig"}, + {"name":"target"} + ] +}, +{ + "name":"sun.awt.X11GraphicsConfig", + "fields":[ + {"name":"aData"}, + {"name":"bitsPerPixel"}, + {"name":"screen"} + ] +}, +{ + "name":"sun.awt.X11GraphicsDevice", + "fields":[{"name":"screen"}], + "methods":[{"name":"addDoubleBufferVisual","parameterTypes":["int"] }] +}, +{ + "name":"sun.awt.X11InputMethodBase", + "fields":[{"name":"pData"}] +}, +{ + "name":"sun.awt.image.BufImgSurfaceData$ICMColorData", + "fields":[{"name":"pData"}], + "methods":[{"name":"","parameterTypes":["long"] }] +}, +{ + "name":"sun.awt.image.IntegerComponentRaster", + "fields":[ + {"name":"data"}, + {"name":"dataOffsets"}, + {"name":"pixelStride"}, + {"name":"scanlineStride"}, + {"name":"type"} + ] +}, +{ + "name":"sun.java2d.Disposer", + "methods":[{"name":"addRecord","parameterTypes":["java.lang.Object","long","long"] }] +}, +{ + "name":"sun.java2d.InvalidPipeException" +}, +{ + "name":"sun.java2d.NullSurfaceData" +}, +{ + "name":"sun.java2d.SunGraphics2D", + "fields":[ + {"name":"clipRegion"}, + {"name":"composite"}, + {"name":"eargb"}, + {"name":"lcdTextContrast"}, + {"name":"pixel"}, + {"name":"strokeHint"} + ] +}, +{ + "name":"sun.java2d.SurfaceData", + "fields":[ + {"name":"pData"}, + {"name":"valid"} + ] +}, +{ + "name":"sun.java2d.loops.Blit", + "methods":[{"name":"","parameterTypes":["long","sun.java2d.loops.SurfaceType","sun.java2d.loops.CompositeType","sun.java2d.loops.SurfaceType"] }] +}, +{ + "name":"sun.java2d.loops.BlitBg", + "methods":[{"name":"","parameterTypes":["long","sun.java2d.loops.SurfaceType","sun.java2d.loops.CompositeType","sun.java2d.loops.SurfaceType"] }] +}, +{ + "name":"sun.java2d.loops.CompositeType", + "fields":[ + {"name":"AnyAlpha"}, + {"name":"Src"}, + {"name":"SrcNoEa"}, + {"name":"SrcOver"}, + {"name":"SrcOverNoEa"}, + {"name":"Xor"} + ] +}, +{ + "name":"sun.java2d.loops.DrawGlyphList", + "methods":[{"name":"","parameterTypes":["long","sun.java2d.loops.SurfaceType","sun.java2d.loops.CompositeType","sun.java2d.loops.SurfaceType"] }] +}, +{ + "name":"sun.java2d.loops.DrawGlyphListAA", + "methods":[{"name":"","parameterTypes":["long","sun.java2d.loops.SurfaceType","sun.java2d.loops.CompositeType","sun.java2d.loops.SurfaceType"] }] +}, +{ + "name":"sun.java2d.loops.DrawGlyphListLCD", + "methods":[{"name":"","parameterTypes":["long","sun.java2d.loops.SurfaceType","sun.java2d.loops.CompositeType","sun.java2d.loops.SurfaceType"] }] +}, +{ + "name":"sun.java2d.loops.DrawLine", + "methods":[{"name":"","parameterTypes":["long","sun.java2d.loops.SurfaceType","sun.java2d.loops.CompositeType","sun.java2d.loops.SurfaceType"] }] +}, +{ + "name":"sun.java2d.loops.DrawParallelogram", + "methods":[{"name":"","parameterTypes":["long","sun.java2d.loops.SurfaceType","sun.java2d.loops.CompositeType","sun.java2d.loops.SurfaceType"] }] +}, +{ + "name":"sun.java2d.loops.DrawPath", + "methods":[{"name":"","parameterTypes":["long","sun.java2d.loops.SurfaceType","sun.java2d.loops.CompositeType","sun.java2d.loops.SurfaceType"] }] +}, +{ + "name":"sun.java2d.loops.DrawPolygons", + "methods":[{"name":"","parameterTypes":["long","sun.java2d.loops.SurfaceType","sun.java2d.loops.CompositeType","sun.java2d.loops.SurfaceType"] }] +}, +{ + "name":"sun.java2d.loops.DrawRect", + "methods":[{"name":"","parameterTypes":["long","sun.java2d.loops.SurfaceType","sun.java2d.loops.CompositeType","sun.java2d.loops.SurfaceType"] }] +}, +{ + "name":"sun.java2d.loops.FillParallelogram", + "methods":[{"name":"","parameterTypes":["long","sun.java2d.loops.SurfaceType","sun.java2d.loops.CompositeType","sun.java2d.loops.SurfaceType"] }] +}, +{ + "name":"sun.java2d.loops.FillPath", + "methods":[{"name":"","parameterTypes":["long","sun.java2d.loops.SurfaceType","sun.java2d.loops.CompositeType","sun.java2d.loops.SurfaceType"] }] +}, +{ + "name":"sun.java2d.loops.FillRect", + "methods":[{"name":"","parameterTypes":["long","sun.java2d.loops.SurfaceType","sun.java2d.loops.CompositeType","sun.java2d.loops.SurfaceType"] }] +}, +{ + "name":"sun.java2d.loops.FillSpans", + "methods":[{"name":"","parameterTypes":["long","sun.java2d.loops.SurfaceType","sun.java2d.loops.CompositeType","sun.java2d.loops.SurfaceType"] }] +}, +{ + "name":"sun.java2d.loops.GraphicsPrimitive", + "fields":[{"name":"pNativePrim"}] +}, +{ + "name":"sun.java2d.loops.GraphicsPrimitiveMgr", + "methods":[{"name":"register","parameterTypes":["sun.java2d.loops.GraphicsPrimitive[]"] }] +}, +{ + "name":"sun.java2d.loops.MaskBlit", + "methods":[{"name":"","parameterTypes":["long","sun.java2d.loops.SurfaceType","sun.java2d.loops.CompositeType","sun.java2d.loops.SurfaceType"] }] +}, +{ + "name":"sun.java2d.loops.MaskFill", + "methods":[{"name":"","parameterTypes":["long","sun.java2d.loops.SurfaceType","sun.java2d.loops.CompositeType","sun.java2d.loops.SurfaceType"] }] +}, +{ + "name":"sun.java2d.loops.ScaledBlit", + "methods":[{"name":"","parameterTypes":["long","sun.java2d.loops.SurfaceType","sun.java2d.loops.CompositeType","sun.java2d.loops.SurfaceType"] }] +}, +{ + "name":"sun.java2d.loops.SurfaceType", + "fields":[ + {"name":"Any3Byte"}, + {"name":"Any4Byte"}, + {"name":"AnyByte"}, + {"name":"AnyColor"}, + {"name":"AnyInt"}, + {"name":"AnyShort"}, + {"name":"ByteBinary1Bit"}, + {"name":"ByteBinary2Bit"}, + {"name":"ByteBinary4Bit"}, + {"name":"ByteGray"}, + {"name":"ByteIndexed"}, + {"name":"ByteIndexedBm"}, + {"name":"FourByteAbgr"}, + {"name":"FourByteAbgrPre"}, + {"name":"Index12Gray"}, + {"name":"Index8Gray"}, + {"name":"IntArgb"}, + {"name":"IntArgbBm"}, + {"name":"IntArgbPre"}, + {"name":"IntBgr"}, + {"name":"IntRgb"}, + {"name":"IntRgbx"}, + {"name":"OpaqueColor"}, + {"name":"ThreeByteBgr"}, + {"name":"Ushort4444Argb"}, + {"name":"Ushort555Rgb"}, + {"name":"Ushort555Rgbx"}, + {"name":"Ushort565Rgb"}, + {"name":"UshortGray"}, + {"name":"UshortIndexed"} + ] +}, +{ + "name":"sun.java2d.loops.TransformHelper", + "methods":[{"name":"","parameterTypes":["long","sun.java2d.loops.SurfaceType","sun.java2d.loops.CompositeType","sun.java2d.loops.SurfaceType"] }] +}, +{ + "name":"sun.java2d.loops.XORComposite", + "fields":[ + {"name":"alphaMask"}, + {"name":"xorColor"}, + {"name":"xorPixel"} + ] +}, +{ + "name":"sun.java2d.pipe.Region", + "fields":[ + {"name":"bands"}, + {"name":"endIndex"}, + {"name":"hix"}, + {"name":"hiy"}, + {"name":"lox"}, + {"name":"loy"} + ] +}, +{ + "name":"sun.java2d.pipe.RegionIterator", + "fields":[ + {"name":"curIndex"}, + {"name":"numXbands"}, + {"name":"region"} + ] +}, +{ + "name":"sun.java2d.xr.XRBackendNative", + "fields":[ + {"name":"FMTPTR_A8"}, + {"name":"FMTPTR_ARGB32"}, + {"name":"MASK_XIMG"} + ] +}, +{ + "name":"sun.java2d.xr.XRSurfaceData", + "fields":[ + {"name":"picture"}, + {"name":"xid"} + ] +}, +{ + "name":"sun.management.VMManagementImpl", + "fields":[ + {"name":"compTimeMonitoringSupport"}, + {"name":"currentThreadCpuTimeSupport"}, + {"name":"objectMonitorUsageSupport"}, + {"name":"otherThreadCpuTimeSupport"}, + {"name":"remoteDiagnosticCommandsSupport"}, + {"name":"synchronizerUsageSupport"}, + {"name":"threadAllocatedMemorySupport"}, + {"name":"threadContentionMonitoringSupport"} + ] +} +] diff --git a/src/de.hpi.swa.trufflesqueak/src/META-INF/native-image/predefined-classes-config.json b/src/de.hpi.swa.trufflesqueak/src/META-INF/native-image/predefined-classes-config.json new file mode 100644 index 000000000..0e79b2c5d --- /dev/null +++ b/src/de.hpi.swa.trufflesqueak/src/META-INF/native-image/predefined-classes-config.json @@ -0,0 +1,8 @@ +[ + { + "type":"agent-extracted", + "classes":[ + ] + } +] + diff --git a/src/de.hpi.swa.trufflesqueak/src/META-INF/native-image/proxy-config.json b/src/de.hpi.swa.trufflesqueak/src/META-INF/native-image/proxy-config.json new file mode 100644 index 000000000..0d4f101c7 --- /dev/null +++ b/src/de.hpi.swa.trufflesqueak/src/META-INF/native-image/proxy-config.json @@ -0,0 +1,2 @@ +[ +] diff --git a/src/de.hpi.swa.trufflesqueak/src/META-INF/native-image/reflect-config.json b/src/de.hpi.swa.trufflesqueak/src/META-INF/native-image/reflect-config.json new file mode 100644 index 000000000..e5e0f24c9 --- /dev/null +++ b/src/de.hpi.swa.trufflesqueak/src/META-INF/native-image/reflect-config.json @@ -0,0 +1,177 @@ +[ +{ + "name":"[B" +}, +{ + "name":"[C" +}, +{ + "name":"de.hpi.swa.trufflesqueak.launcher.TruffleSqueakLauncher", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.model.AbstractPointersObject", + "fields":[ + {"name":"object0"}, + {"name":"object1"}, + {"name":"object2"}, + {"name":"primitive0"}, + {"name":"primitive1"}, + {"name":"primitive2"}, + {"name":"primitiveUsedMap"} + ] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.plugins.NullPlugin$PrimHighResClockNode", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.plugins.NullPlugin$PrimMultipleBytecodeSetsActive0Node", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.plugins.NullPlugin$PrimScreenScaleFactorNode", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.plugins.NullPlugin$PrimUtcWithOffset1Node", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.plugins.SecurityPlugin$PrimCanWriteImageNode", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.plugins.SecurityPlugin$PrimGetUntrustedUserDirectoryNode", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.primitives.impl.ControlPrimitives$PrimBytesLeftNode", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.primitives.impl.ControlPrimitives$PrimIncrementalGCNode", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.primitives.impl.ControlPrimitives$PrimQuickReturnFalseNode", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.primitives.impl.ControlPrimitives$PrimQuickReturnMinusOneNode", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.primitives.impl.ControlPrimitives$PrimQuickReturnNilNode", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.primitives.impl.ControlPrimitives$PrimQuickReturnOneNode", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.primitives.impl.ControlPrimitives$PrimQuickReturnTrueNode", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.primitives.impl.ControlPrimitives$PrimQuickReturnTwoNode", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.primitives.impl.ControlPrimitives$PrimQuickReturnZeroNode", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.primitives.impl.IOPrimitives$PrimScreenSizeNode", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.primitives.impl.MiscellaneousPrimitives$PrimLocalMicrosecondsClockNode", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.primitives.impl.MiscellaneousPrimitives$PrimMaxIdentityHashNode", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.primitives.impl.MiscellaneousPrimitives$PrimSecondClockNode", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.primitives.impl.MiscellaneousPrimitives$PrimUTCClockNode", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.primitives.impl.MiscellaneousPrimitives$PrimVMPathNode", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.primitives.impl.StoragePrimitives$PrimSomeObjectNode", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"de.hpi.swa.trufflesqueak.nodes.primitives.impl.StoragePrimitives$PrimSpecialObjectsArrayNode", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"java.awt.Image" +}, +{ + "name":"java.awt.SequencedEvent" +}, +{ + "name":"java.io.InputStream" +}, +{ + "name":"java.io.Reader" +}, +{ + "name":"java.lang.String" +}, +{ + "name":"java.nio.ByteBuffer" +}, +{ + "name":"java.nio.CharBuffer" +}, +{ + "name":"java.security.MessageDigestSpi" +}, +{ + "name":"java.security.SecureRandomParameters" +}, +{ + "name":"java.util.List" +}, +{ + "name":"org.graalvm.polyglot.Engine", + "methods":[{"name":"getImpl","parameterTypes":[] }] +}, +{ + "name":"org.graalvm.polyglot.management.Management" +}, +{ + "name":"sun.awt.X11.XToolkit", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"sun.awt.X11GraphicsEnvironment", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"sun.java2d.marlin.DMarlinRenderingEngine", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"sun.misc.Unsafe", + "fields":[{"name":"theUnsafe"}] +}, +{ + "name":"sun.security.provider.NativePRNG", + "methods":[{"name":"","parameterTypes":[] }] +}, +{ + "name":"sun.security.provider.SHA", + "methods":[{"name":"","parameterTypes":[] }] +} +] diff --git a/src/de.hpi.swa.trufflesqueak/src/META-INF/native-image/resource-config.json b/src/de.hpi.swa.trufflesqueak/src/META-INF/native-image/resource-config.json new file mode 100644 index 000000000..507192cbc --- /dev/null +++ b/src/de.hpi.swa.trufflesqueak/src/META-INF/native-image/resource-config.json @@ -0,0 +1,21 @@ +{ + "resources":{ + "includes":[ + { + "pattern":"\\QMETA-INF/services/com.oracle.truffle.api.TruffleLanguage$Provider\\E" + }, + { + "pattern":"\\QMETA-INF/services/com.oracle.truffle.api.instrumentation.TruffleInstrument$Provider\\E" + }, + { + "pattern":"\\QMETA-INF/services/java.nio.file.spi.FileSystemProvider\\E" + }, + { + "pattern":"\\Qcom/oracle/truffle/nfi/backend/libffi/LibFFILanguage.class\\E" + } + ]}, + "bundles":[{ + "name":"sun.awt.resources.awt", + "classNames":["sun.awt.resources.awt"] + }] +} diff --git a/src/de.hpi.swa.trufflesqueak/src/META-INF/native-image/serialization-config.json b/src/de.hpi.swa.trufflesqueak/src/META-INF/native-image/serialization-config.json new file mode 100644 index 000000000..bf554e062 --- /dev/null +++ b/src/de.hpi.swa.trufflesqueak/src/META-INF/native-image/serialization-config.json @@ -0,0 +1,6 @@ +{ + "types":[ + ], + "lambdaCapturingTypes":[ + ] +} diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/aot/SDL.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/aot/SDL.java deleted file mode 100644 index 693c7159a..000000000 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/aot/SDL.java +++ /dev/null @@ -1,624 +0,0 @@ -/* - * Copyright (c) 2017-2022 Software Architecture Group, Hasso Plattner Institute - * Copyright (c) 2021-2022 Oracle and/or its affiliates - * - * Licensed under the MIT License. - */ -package de.hpi.swa.trufflesqueak.aot; - -import org.graalvm.nativeimage.Platform; -import org.graalvm.nativeimage.Platforms; -import org.graalvm.nativeimage.c.CContext; -import org.graalvm.nativeimage.c.constant.CConstant; -import org.graalvm.nativeimage.c.constant.CEnum; -import org.graalvm.nativeimage.c.constant.CEnumConstant; -import org.graalvm.nativeimage.c.constant.CEnumValue; -import org.graalvm.nativeimage.c.function.CFunction; -import org.graalvm.nativeimage.c.struct.AllowNarrowingCast; -import org.graalvm.nativeimage.c.struct.CField; -import org.graalvm.nativeimage.c.struct.CFieldAddress; -import org.graalvm.nativeimage.c.struct.CStruct; -import org.graalvm.nativeimage.c.type.CCharPointer; -import org.graalvm.nativeimage.c.type.CIntPointer; -import org.graalvm.nativeimage.c.type.CTypeConversion; -import org.graalvm.nativeimage.c.type.CTypeConversion.CCharPointerHolder; -import org.graalvm.nativeimage.c.type.VoidPointer; -import org.graalvm.nativeimage.c.type.WordPointer; -import org.graalvm.word.PointerBase; - -import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; - -/** - * - * SDL2 bindings for SubstrateVM (tested with SDL 2.0.2). - * - */ -@CContext(SDLCContext.class) -@Platforms({Platform.LINUX.class, Platform.DARWIN.class}) -public final class SDL { - /* - * SDL.h - */ - - @CConstant("SDL_INIT_VIDEO") - public static native int initVideo(); - - @CFunction("SDL_Init") - public static native int init(int flags); - - @CFunction("SDL_Quit") - public static native void quit(); - - /* - * SDL_clipboard.h - */ - - @CFunction("SDL_GetClipboardText") - public static native CCharPointer getClipboardText(); - - @CFunction("SDL_SetClipboardText") - public static native int setClipboardText(CCharPointer text); - - /* - * SDL_error.h - */ - - @CFunction("SDL_GetError") - public static native CCharPointer getError(); - - @TruffleBoundary - public static String getErrorString() { - return CTypeConversion.toJavaString(SDL.getError()); - } - - /* - * SDL_events.h - */ - - @CEnum - public enum EventType { - //@formatter:off - @CEnumConstant("SDL_FIRSTEVENT") FIRSTEVENT, - @CEnumConstant("SDL_QUIT") QUIT, - @CEnumConstant("SDL_APP_TERMINATING") APP_TERMINATING, - @CEnumConstant("SDL_APP_LOWMEMORY") APP_LOWMEMORY, - @CEnumConstant("SDL_APP_WILLENTERBACKGROUND") APP_WILLENTERBACKGROUND, - @CEnumConstant("SDL_APP_DIDENTERBACKGROUND") APP_DIDENTERBACKGROUND, - @CEnumConstant("SDL_APP_WILLENTERFOREGROUND") APP_WILLENTERFOREGROUND, - @CEnumConstant("SDL_APP_DIDENTERFOREGROUND") APP_DIDENTERFOREGROUND, - @CEnumConstant("SDL_WINDOWEVENT") WINDOWEVENT, - @CEnumConstant("SDL_SYSWMEVENT") SYSWMEVENT, - @CEnumConstant("SDL_KEYDOWN") KEYDOWN, - @CEnumConstant("SDL_KEYUP") KEYUP, - @CEnumConstant("SDL_TEXTEDITING") TEXTEDITING, - @CEnumConstant("SDL_TEXTINPUT") TEXTINPUT, - @CEnumConstant("SDL_MOUSEMOTION") MOUSEMOTION, - @CEnumConstant("SDL_MOUSEBUTTONDOWN") MOUSEBUTTONDOWN, - @CEnumConstant("SDL_MOUSEBUTTONUP") MOUSEBUTTONUP, - @CEnumConstant("SDL_MOUSEWHEEL") MOUSEWHEEL, - @CEnumConstant("SDL_JOYAXISMOTION") JOYAXISMOTION, - @CEnumConstant("SDL_JOYBALLMOTION") JOYBALLMOTION, - @CEnumConstant("SDL_JOYHATMOTION") JOYHATMOTION, - @CEnumConstant("SDL_JOYBUTTONDOWN") JOYBUTTONDOWN, - @CEnumConstant("SDL_JOYBUTTONUP") JOYBUTTONUP, - @CEnumConstant("SDL_JOYDEVICEADDED") JOYDEVICEADDED, - @CEnumConstant("SDL_JOYDEVICEREMOVED") JOYDEVICEREMOVED, - @CEnumConstant("SDL_CONTROLLERAXISMOTION") CONTROLLERAXISMOTION, - @CEnumConstant("SDL_CONTROLLERBUTTONDOWN") CONTROLLERBUTTONDOWN, - @CEnumConstant("SDL_CONTROLLERBUTTONUP") CONTROLLERBUTTONUP, - @CEnumConstant("SDL_CONTROLLERDEVICEADDED") CONTROLLERDEVICEADDED, - @CEnumConstant("SDL_CONTROLLERDEVICEREMOVED") CONTROLLERDEVICEREMOVED, - @CEnumConstant("SDL_CONTROLLERDEVICEREMAPPED") CONTROLLERDEVICEREMAPPED, - @CEnumConstant("SDL_FINGERDOWN") FINGERDOWN, - @CEnumConstant("SDL_FINGERUP") FINGERUP, - @CEnumConstant("SDL_FINGERMOTION") FINGERMOTION, - @CEnumConstant("SDL_DOLLARGESTURE") DOLLARGESTURE, - @CEnumConstant("SDL_DOLLARRECORD") DOLLARRECORD, - @CEnumConstant("SDL_MULTIGESTURE") MULTIGESTURE, - @CEnumConstant("SDL_CLIPBOARDUPDATE") CLIPBOARDUPDATE, - @CEnumConstant("SDL_DROPFILE") DROPFILE, - @CEnumConstant("SDL_RENDER_TARGETS_RESET") RENDER_TARGETS_RESET, - @CEnumConstant("SDL_USEREVENT") USEREVENT, - @CEnumConstant("SDL_LASTEVENT") LASTEVENT; - //@formatter:on - - @CEnumValue - public native int getCValue(); - } - - @CConstant("SDL_IGNORE") - public static native int ignore(); - - @CStruct(value = "union SDL_Event") - public interface Event extends PointerBase { - @CField - int type(); - - @CField - @AllowNarrowingCast - CCharPointer padding(); - } - - @CStruct(value = "SDL_MouseMotionEvent", addStructKeyword = true, isIncomplete = true) - public interface MouseMotionEvent extends PointerBase { - @CField - int x(); - - @CField - int y(); - } - - @CStruct(value = "SDL_MouseWheelEvent", addStructKeyword = true, isIncomplete = true) - public interface MouseWheelEvent extends PointerBase { - @CField - int x(); - - @CField - int y(); - } - - @CStruct(value = "SDL_MouseButtonEvent", addStructKeyword = true, isIncomplete = true) - public interface MouseButtonEvent extends PointerBase { - @CField - int type(); - - @CField - byte button(); - } - - @CStruct(value = "SDL_KeyboardEvent", addStructKeyword = true, isIncomplete = true) - public interface KeyboardEvent extends PointerBase { - @CFieldAddress - Keysym keysym(); - } - - @CStruct(value = "SDL_Keysym", addStructKeyword = true, isIncomplete = true) - public interface Keysym extends PointerBase { - @CField - int sym(); - } - - @CStruct(value = "SDL_TextInputEvent", addStructKeyword = true, isIncomplete = true) - public interface TextInputEvent extends PointerBase { - @CFieldAddress - CCharPointer text(); - } - - @CStruct(value = "SDL_WindowEvent", addStructKeyword = true, isIncomplete = true) - public interface WindowEvent extends PointerBase { - @CField - byte event(); - - @CField - int data1(); - - @CField - int data2(); - } - - @CFunction("SDL_EventState") - public static native int eventState(int type, int state); - - @CFunction("SDL_PollEvent") - public static native int pollEvent(Event event); - - /* - * SDL_hints.h - */ - - // Checkstyle: stop - public static final String HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK = "SDL_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK"; - public static final String HINT_RENDER_SCALE_QUALITY = "SDL_RENDER_SCALE_QUALITY"; - public static final String HINT_RENDER_VSYNC = "SDL_RENDER_VSYNC"; - public static final String HINT_VIDEO_X11_NET_WM_PING = "SDL_VIDEO_X11_NET_WM_PING"; - // Checkstyle: resume - - @CFunction("SDL_SetHint") - public static native int setHint(CCharPointer key, CCharPointer value); - - public static int setHint(final String key, final String value) { - try (CCharPointerHolder keyPointerHolder = CTypeConversion.toCString(key)) { - try (CCharPointerHolder valuePointerHolder = CTypeConversion.toCString(value)) { - return SDL.setHint(keyPointerHolder.get(), valuePointerHolder.get()); - } - } - } - - /* - * SDL_keycode.h - */ - - @CConstant("SDLK_DOWN") - public static native int kDown(); - - @CConstant("SDLK_LEFT") - public static native int kLeft(); - - @CConstant("SDLK_RIGHT") - public static native int kRight(); - - @CConstant("SDLK_UP") - public static native int kUp(); - - @CConstant("SDLK_HOME") - public static native int kHome(); - - @CConstant("SDLK_END") - public static native int kEnd(); - - @CConstant("SDLK_INSERT") - public static native int kInsert(); - - @CConstant("SDLK_PAGEUP") - public static native int kPageup(); - - @CConstant("SDLK_PAGEDOWN") - public static native int kPagedown(); - - @CConstant("SDLK_LSHIFT") - public static native int kLShift(); - - @CConstant("SDLK_RSHIFT") - public static native int kRShift(); - - @CConstant("SDLK_LCTRL") - public static native int kLCtrl(); - - @CConstant("SDLK_RCTRL") - public static native int kRCtrl(); - - @CConstant("SDLK_LALT") - public static native int kLAlt(); - - @CConstant("SDLK_RALT") - public static native int kRAlt(); - - @CConstant("SDLK_LGUI") - public static native int kLGui(); - - @CConstant("SDLK_RGUI") - public static native int kRGui(); - - @CConstant("SDLK_DELETE") - public static native int kDelete(); - - @CConstant("SDLK_BACKSPACE") - public static native int kBackspace(); - - @CConstant("SDLK_PAUSE") - public static native int kPause(); - - @CConstant("SDLK_CAPSLOCK") - public static native int kCapslock(); - - @CConstant("SDLK_NUMLOCKCLEAR") - public static native int kNumlockclear(); - - @CConstant("SDLK_SCROLLLOCK") - public static native int kScrolllock(); - - @CConstant("SDLK_PRINTSCREEN") - public static native int kPrintscreen(); - - @CConstant("KMOD_NONE") - public static native int kmodNone(); - - @CConstant("KMOD_LSHIFT") - public static native int kmodLShift(); - - @CConstant("KMOD_RSHIFT") - public static native int kmodRShift(); - - @CConstant("KMOD_LCTRL") - public static native int kmodLCtrl(); - - @CConstant("KMOD_RCTRL") - public static native int kmodRCtrl(); - - @CConstant("KMOD_LALT") - public static native int kmodLAlt(); - - @CConstant("KMOD_RALT") - public static native int kmodRAlt(); - - @CConstant("KMOD_LGUI") - public static native int kmodLGui(); - - @CConstant("KMOD_RGUI") - public static native int kmodRGui(); - - @CConstant("KMOD_CAPS") - public static native int kmodCaps(); - - @CConstant("KMOD_CTRL") - public static native int kmodCtrl(); - - @CConstant("KMOD_SHIFT") - public static native int kmodShift(); - - @CConstant("KMOD_ALT") - public static native int kmodAlt(); - - @CConstant("KMOD_GUI") - public static native int kmodGui(); - - /* - * SDL_keyboard.h - */ - - @CFunction("SDL_GetModState") - public static native int getModState(); - - /* - * SDL_mouse.h - */ - - @CConstant("SDL_BUTTON_LEFT") - public static native int buttonLeft(); - - @CConstant("SDL_BUTTON_MIDDLE") - public static native int buttonMiddle(); - - @CConstant("SDL_BUTTON_RIGHT") - public static native int buttonRight(); - - @CConstant("SDL_BUTTON_X1") - public static native int buttonX1(); - - @CConstant("SDL_BUTTON_X2") - public static native int buttonX2(); - - @CConstant("SDL_BUTTON_LMASK") - public static native int buttonLMask(); - - @CConstant("SDL_BUTTON_MMASK") - public static native int buttonMMask(); - - @CConstant("SDL_BUTTON_RMASK") - public static native int buttonRMask(); - - @CConstant("SDL_BUTTON_X1MASK") - public static native int buttonX1Mask(); - - @CConstant("SDL_BUTTON_X2MASK") - public static native int buttonX2Mask(); - - @CStruct(value = "SDL_CURSOR", addStructKeyword = true, isIncomplete = true) - public interface Cursor extends PointerBase { - /* Opaque. */ - } - - @CFunction("SDL_CreateCursor") - public static native Cursor createCursor(CCharPointer data, CCharPointer mask, int w, int h, int hotX, int hotY); - - @CFunction("SDL_SetCursor") - public static native void setCursor(Cursor cursor); - - @CFunction("SDL_FreeCursor") - public static native void freeCursor(Cursor cursor); - - /* - * SDL_pixels.h - */ - - @CEnum - public enum Pixelformat { - //@formatter:off - @CEnumConstant("SDL_PIXELFORMAT_UNKNOWN") UNKNOWN, - @CEnumConstant("SDL_PIXELFORMAT_INDEX1LSB") INDEX1LSB, - @CEnumConstant("SDL_PIXELFORMAT_INDEX1MSB") INDEX1MSB, - @CEnumConstant("SDL_PIXELFORMAT_INDEX4LSB") INDEX4LSB, - @CEnumConstant("SDL_PIXELFORMAT_INDEX4MSB") INDEX4MSB, - @CEnumConstant("SDL_PIXELFORMAT_INDEX8") INDEX8, - @CEnumConstant("SDL_PIXELFORMAT_RGB332") RGB332, - @CEnumConstant("SDL_PIXELFORMAT_RGB444") RGB444, - @CEnumConstant("SDL_PIXELFORMAT_RGB555") RGB555, - @CEnumConstant("SDL_PIXELFORMAT_BGR555") BGR555, - @CEnumConstant("SDL_PIXELFORMAT_ARGB4444") ARGB4444, - @CEnumConstant("SDL_PIXELFORMAT_RGBA4444") RGBA4444, - @CEnumConstant("SDL_PIXELFORMAT_ABGR4444") ABGR4444, - @CEnumConstant("SDL_PIXELFORMAT_BGRA4444") BGRA4444, - @CEnumConstant("SDL_PIXELFORMAT_ARGB1555") ARGB1555, - @CEnumConstant("SDL_PIXELFORMAT_RGBA5551") RGBA5551, - @CEnumConstant("SDL_PIXELFORMAT_ABGR1555") ABGR1555, - @CEnumConstant("SDL_PIXELFORMAT_BGRA5551") BGRA5551, - @CEnumConstant("SDL_PIXELFORMAT_RGB565") RGB565, - @CEnumConstant("SDL_PIXELFORMAT_BGR565") BGR565, - @CEnumConstant("SDL_PIXELFORMAT_RGB24") RGB24, - @CEnumConstant("SDL_PIXELFORMAT_BGR24") BGR24, - @CEnumConstant("SDL_PIXELFORMAT_RGB888") RGB888, - @CEnumConstant("SDL_PIXELFORMAT_RGBX8888") RGBX8888, - @CEnumConstant("SDL_PIXELFORMAT_BGR888") BGR888, - @CEnumConstant("SDL_PIXELFORMAT_BGRX8888") BGRX8888, - @CEnumConstant("SDL_PIXELFORMAT_ARGB8888") ARGB8888, - @CEnumConstant("SDL_PIXELFORMAT_RGBA8888") RGBA8888, - @CEnumConstant("SDL_PIXELFORMAT_ABGR8888") ABGR8888, - @CEnumConstant("SDL_PIXELFORMAT_BGRA8888") BGRA8888, - @CEnumConstant("SDL_PIXELFORMAT_ARGB2101010") ARGB2101010, - @CEnumConstant("SDL_PIXELFORMAT_YV12") YV12, - @CEnumConstant("SDL_PIXELFORMAT_IYUV") IYUV, - @CEnumConstant("SDL_PIXELFORMAT_YUY2") YUY2, - @CEnumConstant("SDL_PIXELFORMAT_UYVY") UYVY, - @CEnumConstant("SDL_PIXELFORMAT_YVYU") YVYU; - //@formatter:on - - @CEnumValue - public native int getCValue(); - } - - /* - * SDL_rect.h - */ - - @CStruct(value = "SDL_Rect", addStructKeyword = true) - public interface Rect extends PointerBase { - @CField - int getx(); - - @CField - void setx(int value); - - @CField - int gety(); - - @CField - void sety(int value); - - @CField - int getw(); - - @CField - void setw(int value); - - @CField - int geth(); - - @CField - void seth(int value); - } - - @CFunction("SDL_UnionRect") - public static native void unionRect(Rect a, Rect b, Rect result); - - /* - * SDL_renderer.h - */ - - @CConstant("SDL_RENDERER_SOFTWARE") - public static native int rendererSoftware(); - - @CConstant("SDL_RENDERER_ACCELERATED") - public static native int rendererAccelerated(); - - @CConstant("SDL_RENDERER_PRESENTVSYNC") - public static native int rendererPresentvsync(); - - @CConstant("SDL_RENDERER_TARGETTEXTURE") - public static native int rendererTargettexture(); - - @CConstant("SDL_TEXTUREACCESS_STATIC") - public static native int textureaccessStatic(); - - @CConstant("SDL_TEXTUREACCESS_STREAMING") - public static native int textureaccessStreaming(); - - @CConstant("SDL_TEXTUREACCESS_TARGET") - public static native int textureaccessTarget(); - - @CStruct(value = "SDL_RENDERER", addStructKeyword = true, isIncomplete = true) - public interface Renderer extends PointerBase { - /* Opaque. */ - } - - @CStruct(value = "SDL_TEXTURE", addStructKeyword = true, isIncomplete = true) - public interface Texture extends PointerBase { - /* Opaque. */ - } - - @CFunction("SDL_CreateRenderer") - public static native Renderer createRenderer(Window window, int index, int flags); - - @CFunction("SDL_CreateTexture") - public static native Texture createTexture(Renderer renderer, int format, int access, int w, int h); - - @CFunction("SDL_DestroyTexture") - public static native void destroyTexture(Texture texture); - - @CFunction("SDL_LockTexture") - public static native int lockTexture(Texture texture, Rect rect, WordPointer pixels, CIntPointer pitch); - - @CFunction("SDL_RenderClear") - public static native int renderClear(Renderer renderer); - - @CFunction("SDL_RenderCopy") - public static native int renderCopy(PointerBase renderer, PointerBase texture, PointerBase srcrect, PointerBase dstrect); - - @CFunction("SDL_RenderPresent") - public static native void renderPresent(Renderer renderer); - - @CFunction("SDL_SetRenderDrawColor") - public static native int setRenderDrawColor(Renderer renderer, int r, int g, int b, int a); - - @CFunction("SDL_UnlockTexture") - public static native void unlockTexture(Texture texture); - - @CFunction("SDL_UpdateTexture") - public static native int updateTexture(Texture texture, Rect rect, VoidPointer pixels, int pitch); - - /* - * SDL_video.h - */ - - @CEnum - public enum WindowFlags { - //@formatter:off - @CEnumConstant("SDL_WINDOW_FULLSCREEN") FULLSCREEN, - @CEnumConstant("SDL_WINDOW_OPENGL") OPENGL, - @CEnumConstant("SDL_WINDOW_SHOWN") SHOWN, - @CEnumConstant("SDL_WINDOW_HIDDEN") HIDDEN, - @CEnumConstant("SDL_WINDOW_BORDERLESS") BORDERLESS, - @CEnumConstant("SDL_WINDOW_RESIZABLE") RESIZABLE, - @CEnumConstant("SDL_WINDOW_MINIMIZED") MINIMIZED, - @CEnumConstant("SDL_WINDOW_MAXIMIZED") MAXIMIZED, - @CEnumConstant("SDL_WINDOW_INPUT_GRABBED") INPUT_GRABBED, - @CEnumConstant("SDL_WINDOW_INPUT_FOCUS") INPUT_FOCUS, - @CEnumConstant("SDL_WINDOW_MOUSE_FOCUS") MOUSE_FOCUS, - @CEnumConstant("SDL_WINDOW_FULLSCREEN_DESKTOP") FULLSCREEN_DESKTOP, - @CEnumConstant("SDL_WINDOW_FOREIGN") FOREIGN, - @CEnumConstant("SDL_WINDOW_ALLOW_HIGHDPI") ALLOW_HIGHDPI; - //@formatter:on - - @CEnumValue - public native int getCValue(); - } - - @CEnum - public enum WindowEventID { - //@formatter:off - @CEnumConstant("SDL_WINDOWEVENT_NONE") NONE, - @CEnumConstant("SDL_WINDOWEVENT_SHOWN") SHOWN, - @CEnumConstant("SDL_WINDOWEVENT_HIDDEN") HIDDEN, - @CEnumConstant("SDL_WINDOWEVENT_EXPOSED") EXPOSED, - @CEnumConstant("SDL_WINDOWEVENT_MOVED") MOVED, - @CEnumConstant("SDL_WINDOWEVENT_RESIZED") RESIZED, - @CEnumConstant("SDL_WINDOWEVENT_SIZE_CHANGED") SIZE_CHANGED, - @CEnumConstant("SDL_WINDOWEVENT_MINIMIZED") MINIMIZED, - @CEnumConstant("SDL_WINDOWEVENT_MAXIMIZED") MAXIMIZED, - @CEnumConstant("SDL_WINDOWEVENT_RESTORED") RESTORED, - @CEnumConstant("SDL_WINDOWEVENT_ENTER") ENTER, - @CEnumConstant("SDL_WINDOWEVENT_LEAVE") LEAVE, - @CEnumConstant("SDL_WINDOWEVENT_FOCUS_GAINED") FOCUS_GAINED, - @CEnumConstant("SDL_WINDOWEVENT_FOCUS_LOST") FOCUS_LOST, - @CEnumConstant("SDL_WINDOWEVENT_CLOSE") CLOSE; - //@formatter:on - - @CEnumValue - public native int getCValue(); - } - - @CStruct(value = "SDL_WINDOW", addStructKeyword = true, isIncomplete = true) - public interface Window extends PointerBase { - /* Opaque. */ - } - - @CConstant("SDL_WINDOWPOS_UNDEFINED") - public static native int windowposUndefined(); - - @CFunction("SDL_CreateWindow") - public static native Window createWindow(CCharPointer data, int x, int y, int w, int h, int windowResizable); - - @CFunction("SDL_DestroyWindow") - public static native void destroyWindow(Window window); - - @CFunction("SDL_GetWindowSize") - public static native void getWindowSize(Window window, CIntPointer w, CIntPointer h); - - @CFunction("SDL_GL_SetSwapInterval") - public static native int glSetSwapInterval(int interval); - - @CFunction("SDL_SetWindowFullscreen") - public static native int setWindowFullscreen(Window window, int flags); - - @CFunction("SDL_SetWindowTitle") - public static native void setWindowTitle(Window window, CCharPointer title); -} diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/aot/SDLCContext.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/aot/SDLCContext.java deleted file mode 100644 index f80923524..000000000 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/aot/SDLCContext.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2017-2022 Software Architecture Group, Hasso Plattner Institute - * Copyright (c) 2021-2022 Oracle and/or its affiliates - * - * Licensed under the MIT License. - */ -package de.hpi.swa.trufflesqueak.aot; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import org.graalvm.nativeimage.Platform; -import org.graalvm.nativeimage.c.CContext; - -import de.hpi.swa.trufflesqueak.util.MiscUtils; - -public final class SDLCContext implements CContext.Directives { - @Override - public boolean isInConfiguration() { - /* SDL2 backend only supported on Linux and Darwin */ - return Platform.includedIn(Platform.LINUX.class) || Platform.includedIn(Platform.DARWIN.class); - } - - @Override - public List getHeaderFiles() { - return Collections.singletonList(""); - } - - @Override - public List getLibraries() { - return Collections.singletonList("SDL2"); - } - - @Override - public List getOptions() { - if (isInConfiguration()) { - return Arrays.asList(SDL2Config.CFLAGS.split(" ")); - } else { - throw new UnsupportedOperationException("Unsupported OS"); - } - } - - private static class SDL2Config { - private static final String CFLAGS; - - static { - final List lines = MiscUtils.exec("sdl2-config --cflags", 5); - if (lines != null && lines.size() == 1) { - CFLAGS = lines.get(0); - } else { - throw new UnsupportedOperationException("`sdl2-config --cflags` failed. Please make sure SDL2 is installed on your system."); - } - } - } -} diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/aot/SqueakSDL2Display.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/aot/SqueakSDL2Display.java deleted file mode 100644 index 33b4f355c..000000000 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/aot/SqueakSDL2Display.java +++ /dev/null @@ -1,595 +0,0 @@ -/* - * Copyright (c) 2017-2022 Software Architecture Group, Hasso Plattner Institute - * Copyright (c) 2021-2022 Oracle and/or its affiliates - * - * Licensed under the MIT License. - */ -package de.hpi.swa.trufflesqueak.aot; - -import java.util.ArrayDeque; -import java.util.Arrays; - -import org.graalvm.nativeimage.PinnedObject; -import org.graalvm.nativeimage.Platform; -import org.graalvm.nativeimage.Platforms; -import org.graalvm.nativeimage.UnmanagedMemory; -import org.graalvm.nativeimage.c.struct.SizeOf; -import org.graalvm.nativeimage.c.type.CIntPointer; -import org.graalvm.nativeimage.c.type.CTypeConversion; -import org.graalvm.nativeimage.c.type.CTypeConversion.CCharPointerHolder; -import org.graalvm.nativeimage.c.type.VoidPointer; -import org.graalvm.nativeimage.c.type.WordPointer; -import org.graalvm.word.WordFactory; - -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; -import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; - -import de.hpi.swa.trufflesqueak.aot.SDL.Cursor; -import de.hpi.swa.trufflesqueak.aot.SDL.Event; -import de.hpi.swa.trufflesqueak.aot.SDL.KeyboardEvent; -import de.hpi.swa.trufflesqueak.aot.SDL.MouseButtonEvent; -import de.hpi.swa.trufflesqueak.aot.SDL.MouseMotionEvent; -import de.hpi.swa.trufflesqueak.aot.SDL.MouseWheelEvent; -import de.hpi.swa.trufflesqueak.aot.SDL.Rect; -import de.hpi.swa.trufflesqueak.aot.SDL.Renderer; -import de.hpi.swa.trufflesqueak.aot.SDL.TextInputEvent; -import de.hpi.swa.trufflesqueak.aot.SDL.Texture; -import de.hpi.swa.trufflesqueak.aot.SDL.Window; -import de.hpi.swa.trufflesqueak.aot.SDL.WindowEvent; -import de.hpi.swa.trufflesqueak.exceptions.SqueakExceptions.SqueakException; -import de.hpi.swa.trufflesqueak.exceptions.SqueakExceptions.SqueakQuit; -import de.hpi.swa.trufflesqueak.image.SqueakImageContext; -import de.hpi.swa.trufflesqueak.io.SqueakDisplayInterface; -import de.hpi.swa.trufflesqueak.io.SqueakIOConstants.EVENT_TYPE; -import de.hpi.swa.trufflesqueak.io.SqueakIOConstants.KEY; -import de.hpi.swa.trufflesqueak.io.SqueakIOConstants.KEYBOARD_EVENT; -import de.hpi.swa.trufflesqueak.io.SqueakIOConstants.MOUSE; -import de.hpi.swa.trufflesqueak.model.NativeObject; -import de.hpi.swa.trufflesqueak.model.PointersObject; -import de.hpi.swa.trufflesqueak.model.layout.ObjectLayouts.FORM; -import de.hpi.swa.trufflesqueak.nodes.accessing.AbstractPointersObjectNodes.AbstractPointersObjectReadNode; -import de.hpi.swa.trufflesqueak.util.OS; - -@Platforms({Platform.LINUX.class, Platform.DARWIN.class}) -public final class SqueakSDL2Display implements SqueakDisplayInterface { - private static final String DEFAULT_WINDOW_TITLE = "TruffleSqueak + SubstrateVM + SDL2"; - - private final SqueakImageContext image; - private final Rect flipRect = UnmanagedMemory.malloc(SizeOf.unsigned(SDL.Rect.class)); - private final Rect renderRect = UnmanagedMemory.malloc(SizeOf.unsigned(SDL.Rect.class)); - private final Rect nullRect = WordFactory.nullPointer(); - private final WordPointer pixelVoidPP = UnmanagedMemory.malloc(SizeOf.unsigned(WordPointer.class)); - private final CIntPointer pitchIntP = UnmanagedMemory.malloc(SizeOf.unsigned(CIntPointer.class)); - private final ArrayDeque deferredEvents = new ArrayDeque<>(); - private final Event event = UnmanagedMemory.malloc(SizeOf.unsigned(Event.class)); - - private Window window = WordFactory.nullPointer(); - private Renderer renderer = WordFactory.nullPointer(); - private Texture texture = WordFactory.nullPointer(); - private Cursor cursor = WordFactory.nullPointer(); - private NativeObject bitmap; - @CompilationFinal private int inputSemaphoreIndex; - private boolean deferUpdates; - private boolean textureDirty; - private int width; - private int height; - private final int bpp = 4; // TODO: for 32bit only! - - private int lastMouseXPos; - private int lastMouseYPos; - private int button; - private int key; - private boolean isKeyDown; - - public SqueakSDL2Display(final SqueakImageContext image) { - this.image = image; - sdlAssert(SDL.init(SDL.initVideo()) == 0); - - // Do not wait for vsync. - SDL.setHint(SDL.HINT_RENDER_VSYNC, "0"); - // Nearest pixel sampling. - SDL.setHint(SDL.HINT_RENDER_SCALE_QUALITY, "0"); - // Disable WM_PING, so the WM does not think it is hung. - SDL.setHint(SDL.HINT_VIDEO_X11_NET_WM_PING, "0"); - // Ctrl-Click on macOS is right click. - SDL.setHint(SDL.HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, "1"); - - // Disable unneeded events to avoid issues (e.g. double clicks). - SDL.eventState(SDL.EventType.TEXTEDITING.getCValue(), SDL.ignore()); - SDL.eventState(SDL.EventType.FINGERDOWN.getCValue(), SDL.ignore()); - SDL.eventState(SDL.EventType.FINGERUP.getCValue(), SDL.ignore()); - SDL.eventState(SDL.EventType.FINGERMOTION.getCValue(), SDL.ignore()); - - // Try to allow late tearing (pushes frames faster). - if (SDL.glSetSwapInterval(-1) < 0) { - SDL.glSetSwapInterval(0); // At least try to disable vsync. - } - } - - @Override - public void showDisplayBitsLeftTopRightBottom(final PointersObject destForm, final int left, final int top, final int right, final int bottom) { - if (left < right && top < bottom && !deferUpdates && destForm.isDisplay(image)) { - paintImmediately(left, right, top, bottom); - } - } - - @Override - public void showDisplayRect(final int left, final int right, final int top, final int bottom) { - assert left < right && top < bottom; - paintImmediately(left, right, top, bottom); - } - - @TruffleBoundary - private void paintImmediately(final int left, final int right, final int top, final int bottom) { - copyPixels(left + top * width, right + bottom * width); - recordDamage(left, top, right - left, bottom - top); - textureDirty = true; - render(true); - } - - @Override - @TruffleBoundary - public void setFullscreen(final boolean enable) { - if (enable) { - SDL.setWindowFullscreen(window, SDL.WindowFlags.FULLSCREEN_DESKTOP.getCValue()); - } else { - SDL.setWindowFullscreen(window, 0); - } - } - - @Override - @TruffleBoundary - public void close() { - if (window.isNonNull()) { - SDL.destroyWindow(window); - } - SDL.quit(); - } - - @Override - @TruffleBoundary - public void open(final PointersObject sqDisplay) { - final AbstractPointersObjectReadNode readNode = AbstractPointersObjectReadNode.getUncached(); - bitmap = readNode.executeNative(sqDisplay, FORM.BITS); - if (!bitmap.isIntType()) { - throw SqueakException.create("Display bitmap expected to be a words object"); - } - - final int depth = readNode.executeInt(sqDisplay, FORM.DEPTH); - if (depth != 32) { - throw SqueakException.create("Expected 32bit display"); - } - if (window.isNull()) { - width = readNode.executeInt(sqDisplay, FORM.WIDTH); - height = readNode.executeInt(sqDisplay, FORM.HEIGHT); - try (CCharPointerHolder title = CTypeConversion.toCString(DEFAULT_WINDOW_TITLE)) { - window = SDL.createWindow( - title.get(), - SDL.windowposUndefined(), - SDL.windowposUndefined(), - width, - height, - SDL.WindowFlags.RESIZABLE.getCValue()); - sdlAssert(window.isNonNull()); - } - renderer = SDL.createRenderer(window, -1, SDL.rendererSoftware()); - sdlAssert(renderer.isNonNull()); - texture = SDL.createTexture(renderer, SDL.Pixelformat.ARGB8888.getCValue(), SDL.textureaccessStreaming(), width, height); - sdlAssert(texture.isNonNull()); - fullDamage(); - getNextEvent(); // Poll and drop fix events for faster window initialization. - } else { - resizeTo(readNode.executeInt(sqDisplay, FORM.WIDTH), readNode.executeInt(sqDisplay, FORM.HEIGHT)); - } - } - - @Override - @TruffleBoundary - public boolean isVisible() { - return window.isNonNull(); - } - - @Override - @TruffleBoundary - public void setCursor(final int[] cursorWords, final int[] mask, final int width, final int height, final int depth, final int offsetX, final int offsetY) { - if (window.isNull()) { - return; - } - if (cursor.isNonNull()) { - SDL.freeCursor(cursor); - } - final int nCursorBytes = cursorWords.length * 2; - final byte[] cursorBytes = cursorWordsToBytes(nCursorBytes, cursorWords); - final byte[] maskBytes = cursorWordsToBytes(nCursorBytes, mask); - try (PinnedObject pinnedCursorBytes = PinnedObject.create(cursorBytes)) { - try (PinnedObject pinnedMaskBytes = PinnedObject.create(maskBytes)) { - cursor = SDL.createCursor(pinnedCursorBytes.addressOfArrayElement(0), pinnedMaskBytes.addressOfArrayElement(0), 16, 16, offsetX, offsetY); - } - } - if (!sdlError(cursor.isNonNull())) { - return; - } - SDL.setCursor(cursor); - } - - @Override - public long[] getNextEvent() { - return deferredEvents.pollFirst(); - } - - @Override - @TruffleBoundary - public void pollEvents() { - while (SDL.pollEvent(event) != 0) { - final long time = getEventTime(); - final int eventType = event.type(); - if (eventType == SDL.EventType.MOUSEBUTTONDOWN.getCValue() || eventType == SDL.EventType.MOUSEBUTTONUP.getCValue()) { - handleMouseButton(); - queueEvent(getNextMouseEvent(time)); - } else if (eventType == SDL.EventType.MOUSEMOTION.getCValue()) { - handleMouseMove(); - queueEvent(getNextMouseEvent(time)); - } else if (eventType == SDL.EventType.MOUSEWHEEL.getCValue()) { - queueEvent(getNextMouseWheelEvent(time)); - } else if (eventType == SDL.EventType.KEYDOWN.getCValue()) { - isKeyDown = true; - handleKeyboardEvent(); - long[] later = null; - // No TEXTINPUT event for this key will follow, but Squeak needs a KeyStroke anyway. - if (!isModifierKey(key) && (OS.isLinux() && isControlKey(key) || - !OS.isLinux() && (isControlKey(key) || (SDL.getModState() & ~SDL.kmodShift()) != 0))) { - later = getNextKeyEvent(KEYBOARD_EVENT.CHAR, time); - } - fixKeyCodeCase(); - queueEvent(getNextKeyEvent(KEYBOARD_EVENT.DOWN, time)); - if (later != null) { - queueEvent(later); - } - } else if (eventType == SDL.EventType.TEXTINPUT.getCValue()) { - handleTextInputEvent(); - queueEvent(getNextKeyEvent(KEYBOARD_EVENT.CHAR, time)); - } else if (eventType == SDL.EventType.KEYUP.getCValue()) { - isKeyDown = false; - handleKeyboardEvent(); - fixKeyCodeCase(); - queueEvent(getNextKeyEvent(KEYBOARD_EVENT.UP, time)); - } else if (eventType == SDL.EventType.WINDOWEVENT.getCValue()) { - handleWindowEvent(); - } else if (eventType == SDL.EventType.RENDER_TARGETS_RESET.getCValue()) { - /* || eventType == SDL.EventType.RENDER_DEVICE_RESET.getCValue() */ - fullDamage(); - render(true); - } else if (eventType == SDL.EventType.QUIT.getCValue()) { - throw new SqueakQuit(null, 0); - } - } - } - - @Override - public void setDeferUpdates(final boolean flag) { - deferUpdates = flag; - } - - @Override - public boolean getDeferUpdates() { - return deferUpdates; - } - - @Override - @TruffleBoundary - public void resizeTo(final int newWidth, final int newHeight) { - if (width == newWidth && height == newHeight) { - return; - } - width = newWidth; - height = newHeight; - if (texture.isNonNull()) { - SDL.destroyTexture(texture); - } - texture = SDL.createTexture(renderer, SDL.Pixelformat.ARGB8888.getCValue(), SDL.textureaccessStreaming(), width, height); - sdlAssert(texture.isNonNull()); - lock(); - fullDamage(); - } - - @Override - public int getWindowWidth() { - return width; - } - - @Override - public int getWindowHeight() { - return height; - } - - @Override - @TruffleBoundary - public void setWindowTitle(final String title) { - try (CCharPointerHolder titleC = CTypeConversion.toCString(title)) { - SDL.setWindowTitle(window, titleC.get()); - } - } - - @Override - public void setInputSemaphoreIndex(final int interruptSemaphoreIndex) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - inputSemaphoreIndex = interruptSemaphoreIndex; - } - - @Override - @TruffleBoundary - public String getClipboardData() { - return CTypeConversion.toJavaString(SDL.getClipboardText()); - } - - @Override - @TruffleBoundary - public void setClipboardData(final String text) { - try (CCharPointerHolder textPointer = CTypeConversion.toCString(text)) { - SDL.setClipboardText(textPointer.get()); - } - } - - @Override - public void beep() { - image.printToStdOut((char) 7); - } - - private static void sdlAssert(final boolean successful) { - if (!successful) { - throw SqueakException.create(SDL.getErrorString()); - } - } - - private boolean sdlError(final boolean successful) { - if (!successful) { - image.printToStdErr(SDL.getErrorString()); - } - return successful; - } - - private void copyPixels(final int start, final int stop) { - final int offset = start * bpp; - assert offset >= 0; - final int remainingSize = width * height * bpp - offset; - if (remainingSize <= 0 || start >= stop) { - image.printToStdOut("remainingSize <= 0", remainingSize, "start >= stop", start, stop); - return; - } - final int[] pixels = bitmap.getIntStorage(); - try (PinnedObject pinnedPixels = PinnedObject.create(pixels)) { - final VoidPointer surfaceBufferPointer = pinnedPixels.addressOfArrayElement(0); - SDL.updateTexture(texture, nullRect, surfaceBufferPointer, width * bpp); - } - } - - private void render(final boolean forced) { - if (!forced && (deferUpdates || !textureDirty)) { - return; - } - textureDirty = false; - unlock(); - if (!sdlError(SDL.renderCopy(renderer, texture, renderRect, renderRect) == 0)) { - return; - } - SDL.renderPresent(renderer); - resetDamage(); - lock(); - } - - private void unlock() { - SDL.unlockTexture(texture); - } - - private void lock() { - sdlError(SDL.lockTexture(texture, nullRect, pixelVoidPP, pitchIntP) == 0); - } - - private void recordDamage(final int x, final int y, final int w, final int h) { - flipRect.setx(x); - flipRect.sety(y); - flipRect.setw(Math.min(w + 1, width - x)); - flipRect.seth(Math.min(h + 1, height - y)); - SDL.unionRect(flipRect, renderRect, renderRect); - } - - private void resetDamage() { - renderRect.setx(0); - renderRect.sety(0); - renderRect.setw(0); - renderRect.seth(0); - } - - private void fullDamage() { - renderRect.setx(0); - renderRect.sety(0); - renderRect.setw(width); - renderRect.seth(height); - } - - private static byte[] cursorWordsToBytes(final int nBytes, final int[] words) { - final byte[] bytes = new byte[nBytes]; - if (words != null) { - for (int i = 0; i < words.length; i++) { - final int word = words[i]; - bytes[i * 2] = (byte) (word >> 24); - bytes[i * 2 + 1] = (byte) (word >> 16); - } - } else { - Arrays.fill(bytes, (byte) 0); - } - return bytes; - } - - private static boolean isControlKey(final int key) { - return key < 32 || key == KEY.DELETE || key == KEY.NUMLOCK || key == KEY.SCROLLLOCK; - } - - private static boolean isModifierKey(final int key) { - return key == KEY.COMMAND || key == KEY.CTRL || key == KEY.SHIFT; - } - - private void handleWindowEvent() { - final WindowEvent windowEvent = (WindowEvent) event; - final byte eventID = windowEvent.event(); - if (eventID == SDL.WindowEventID.RESIZED.ordinal() || eventID == SDL.WindowEventID.SIZE_CHANGED.ordinal() || eventID == SDL.WindowEventID.EXPOSED.ordinal()) { - final int newWidth = windowEvent.data1(); - final int newHeight = windowEvent.data2(); - if (newWidth != width || newHeight != height) { - // TODO: resizeTo(newWidth, newHeight); - } - fullDamage(); - render(true); - } - } - - @TruffleBoundary - private void handleTextInputEvent() { - final TextInputEvent textInputEvent = (TextInputEvent) event; - key = CTypeConversion.toJavaString(textInputEvent.text()).charAt(0); - } - - private long[] getNextKeyEvent(final long event_type, final long time) { - return new long[]{EVENT_TYPE.KEYBOARD, time, key, event_type, getModifierMask(0), key, 0, 0}; - } - - private void fixKeyCodeCase() { - if (key <= 255) { - key = Character.toUpperCase(key); - } - } - - private void handleKeyboardEvent() { - final KeyboardEvent keyboardEvent = (KeyboardEvent) event; - final int sym = keyboardEvent.keysym().sym(); - key = 0; - if (sym == SDL.kDown()) { - key = KEY.DOWN; - } else if (sym == SDL.kLeft()) { - key = KEY.LEFT; - } else if (sym == SDL.kRight()) { - key = KEY.RIGHT; - } else if (sym == SDL.kUp()) { - key = KEY.UP; - } else if (sym == SDL.kHome()) { - key = KEY.HOME; - } else if (sym == SDL.kEnd()) { - key = KEY.END; - } else if (sym == SDL.kInsert()) { - key = KEY.INSERT; - } else if (sym == SDL.kPageup()) { - key = KEY.PAGEUP; - } else if (sym == SDL.kPagedown()) { - key = KEY.PAGEDOWN; - } else if (sym == SDL.kLShift() || sym == SDL.kRShift()) { - key = KEY.SHIFT; - } else if (sym == SDL.kLCtrl() || sym == SDL.kRCtrl()) { - key = KEY.CTRL; - } else if (sym == SDL.kLAlt() || sym == SDL.kRAlt()) { - key = KEY.COMMAND; - } else if (OS.isMacOS() && (sym == SDL.kLGui() || sym == SDL.kRGui())) { - key = KEY.COMMAND; - } else if (sym == SDL.kDelete()) { - key = KEY.DELETE; - } else if (sym == SDL.kBackspace()) { - key = KEY.BACKSPACE; - } else if (sym == SDL.kPause()) { - key = KEY.BREAK; - } else if (sym == SDL.kCapslock()) { - key = KEY.CAPSLOCK; - } else if (sym == SDL.kNumlockclear()) { - key = KEY.NUMLOCK; - } else if (sym == SDL.kScrolllock()) { - key = KEY.SCROLLLOCK; - } else if (sym == SDL.kPrintscreen()) { - key = KEY.PRINT; - } else { - key = sym; - } - } - - private long[] getNextMouseWheelEvent(final long time) { - final MouseWheelEvent mouseWheelEvent = (MouseWheelEvent) event; - final long mods = getModifierMask(3); - final long btn = getMouseEventButtons(mods); - return new long[]{EVENT_TYPE.MOUSE_WHEEL, time, mouseWheelEvent.x() * 120, mouseWheelEvent.y() * 120, btn, mods, 0L, 0L}; - } - - private void handleMouseMove() { - final MouseMotionEvent mouseMotionEvent = (MouseMotionEvent) event; - lastMouseXPos = mouseMotionEvent.x(); - lastMouseYPos = mouseMotionEvent.y(); - } - - private long[] getNextMouseEvent(final long time) { - final long mods = getModifierMask(3); - final long btn = getMouseEventButtons(mods); - return new long[]{EVENT_TYPE.MOUSE, time, lastMouseXPos, lastMouseYPos, btn, mods, 0L, 0L}; - } - - private long getMouseEventButtons(final long mods) { - long btn = button; - if (btn == MOUSE.RED) { - if ((mods & KEY.CTRL_BIT) != 0) { - btn = MOUSE.BLUE; - } else if ((mods & (KEY.COMMAND_BIT | KEY.OPTION_BIT)) != 0) { - btn = MOUSE.YELLOW; - } - } - return btn; - } - - private static long getModifierMask(final int shift) { - final int mod = SDL.getModState(); - int modifier = 0; - if ((mod & SDL.kmodCtrl()) != 0) { - modifier |= KEY.CTRL_BIT; - } - if ((mod & SDL.kmodShift()) != 0) { - modifier |= KEY.SHIFT_BIT; - } - if ((mod & SDL.kmodCaps()) != 0) { - modifier |= KEY.SHIFT_BIT; - } - if ((mod & SDL.kmodAlt()) != 0) { - if (OS.isMacOS()) { - modifier |= KEY.COMMAND_BIT; - } else { - modifier |= KEY.OPTION_BIT; - } - } - if ((mod & SDL.kmodAlt()) != 0) { - modifier |= KEY.COMMAND_BIT; - } - return modifier << shift; - } - - private void handleMouseButton() { - final MouseButtonEvent mouseButtonEvent = (MouseButtonEvent) event; - int btn = mouseButtonEvent.button(); - if (btn == SDL.buttonRight()) { - btn = MOUSE.BLUE; - } else if (btn == SDL.buttonMiddle()) { - btn = MOUSE.YELLOW; - } else if (btn == SDL.buttonLeft()) { - btn = isKeyDown && key == KEY.COMMAND ? MOUSE.YELLOW : MOUSE.RED; - } - if (event.type() == SDL.EventType.MOUSEBUTTONDOWN.getCValue()) { - button |= btn; - } else { - button &= ~btn; - } - } - - private long getEventTime() { - return System.currentTimeMillis() - image.startUpMillis; - } - - private void queueEvent(final long[] eventData) { - deferredEvents.add(eventData); - if (image.options.signalInputSemaphore && inputSemaphoreIndex > 0) { - image.interrupt.signalSemaphoreWithIndex(inputSemaphoreIndex); - } - } -} diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageContext.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageContext.java index eea530292..a5e224817 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageContext.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageContext.java @@ -12,8 +12,6 @@ import java.nio.file.Paths; import java.util.HashMap; -import org.graalvm.nativeimage.Platform; - import com.oracle.truffle.api.CompilerAsserts; import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; @@ -21,7 +19,6 @@ import com.oracle.truffle.api.TruffleFile; import com.oracle.truffle.api.TruffleLanguage.ContextReference; import com.oracle.truffle.api.TruffleLanguage.ParsingRequest; -import com.oracle.truffle.api.TruffleOptions; import com.oracle.truffle.api.instrumentation.AllocationReporter; import com.oracle.truffle.api.interop.InteropLibrary; import com.oracle.truffle.api.library.Message; @@ -33,12 +30,10 @@ import de.hpi.swa.trufflesqueak.SqueakImage; import de.hpi.swa.trufflesqueak.SqueakLanguage; import de.hpi.swa.trufflesqueak.SqueakOptions.SqueakContextOptions; -import de.hpi.swa.trufflesqueak.aot.SqueakSDL2Display; import de.hpi.swa.trufflesqueak.exceptions.ProcessSwitch; import de.hpi.swa.trufflesqueak.exceptions.SqueakExceptions.SqueakException; import de.hpi.swa.trufflesqueak.interop.LookupMethodByStringNode; import de.hpi.swa.trufflesqueak.io.SqueakDisplay; -import de.hpi.swa.trufflesqueak.io.SqueakDisplayInterface; import de.hpi.swa.trufflesqueak.model.AbstractSqueakObject; import de.hpi.swa.trufflesqueak.model.AbstractSqueakObjectWithClassAndHash; import de.hpi.swa.trufflesqueak.model.ArrayObject; @@ -140,7 +135,7 @@ public final class SqueakImageContext { private boolean currentMarkingFlag; private ArrayObject hiddenRoots; private int globalClassCounter = -1; - @CompilationFinal private SqueakDisplayInterface display; + @CompilationFinal private SqueakDisplay display; public final CheckForInterruptsState interrupt; public final long startUpMillis = System.currentTimeMillis(); public final ReferenceQueue weakPointersQueue = new ReferenceQueue<>(); @@ -567,7 +562,7 @@ public boolean hasDisplay() { return display != null; } - public SqueakDisplayInterface getDisplay() { + public SqueakDisplay getDisplay() { return display; } @@ -620,14 +615,7 @@ public boolean isHeadless() { public void attachDisplayIfNecessary() { if (!isHeadless) { CompilerDirectives.transferToInterpreterAndInvalidate(); - if (TruffleOptions.AOT) { - /* SDL2 backend only supported on Linux and Darwin */ - if (Platform.includedIn(Platform.LINUX.class) || Platform.includedIn(Platform.DARWIN.class)) { - display = new SqueakSDL2Display(this); - } - } else { - display = new SqueakDisplay(this); - } + display = new SqueakDisplay(this); } } diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/io/SqueakDisplay.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/io/SqueakDisplay.java index 02cf7af9f..7b24ff79e 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/io/SqueakDisplay.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/io/SqueakDisplay.java @@ -30,7 +30,6 @@ import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; -import java.net.URL; import java.util.ArrayDeque; import java.util.List; @@ -54,11 +53,8 @@ import de.hpi.swa.trufflesqueak.shared.SqueakLanguageConfig; import de.hpi.swa.trufflesqueak.util.MiscUtils; -public final class SqueakDisplay implements SqueakDisplayInterface { +public final class SqueakDisplay { private static final String DEFAULT_WINDOW_TITLE = "TruffleSqueak"; - private static final Dimension MINIMUM_WINDOW_SIZE = new Dimension(200, 150); - private static final Toolkit TOOLKIT = Toolkit.getDefaultToolkit(); - private static final URL ICON_URL = SqueakDisplay.class.getResource("trufflesqueak-icon.png"); @CompilationFinal(dimensions = 1) private static final int[] CURSOR_COLORS = new int[]{0x00000000, 0xFF0000FF, 0xFFFFFFFF, 0xFF000000}; public final SqueakImageContext image; @@ -78,25 +74,21 @@ public final class SqueakDisplay implements SqueakDisplayInterface { private Point rememberedWindowLocation; private boolean deferUpdates; - static { - tryToSetTaskbarIcon(); - } - public SqueakDisplay(final SqueakImageContext image) { this.image = image; frame.add(canvas); mouse = new SqueakMouse(this); keyboard = new SqueakKeyboard(this); frame.setFocusTraversalKeysEnabled(false); // Ensure `Tab` key is captured. - frame.setMinimumSize(MINIMUM_WINDOW_SIZE); + frame.setMinimumSize(new Dimension(200, 150)); frame.setResizable(true); installEventListeners(); + tryToSetTaskbarIcon(); } - @TruffleBoundary private static void tryToSetTaskbarIcon() { try { - Taskbar.getTaskbar().setIconImage(TOOLKIT.getImage(ICON_URL)); + Taskbar.getTaskbar().setIconImage(Toolkit.getDefaultToolkit().getImage(SqueakDisplay.class.getResource("trufflesqueak-icon.png"))); } catch (final UnsupportedOperationException e) { // Ignore } @@ -188,7 +180,6 @@ private void setSqueakDisplay(final PointersObject squeakDisplay) { } } - @Override @TruffleBoundary public void showDisplayBitsLeftTopRightBottom(final PointersObject destForm, final int left, final int top, final int right, final int bottom) { if (left < right && top < bottom && !deferUpdates && destForm.isDisplay(image)) { @@ -196,40 +187,34 @@ public void showDisplayBitsLeftTopRightBottom(final PointersObject destForm, fin } } - @Override @TruffleBoundary public void showDisplayRect(final int left, final int right, final int top, final int bottom) { assert left < right && top < bottom; canvas.paintImmediately(left, top, right, bottom); } - @Override @TruffleBoundary public void close() { frame.setVisible(false); frame.dispose(); } - @Override @TruffleBoundary public void resizeTo(final int width, final int height) { canvas.setPreferredSize(new Dimension(width, height)); frame.pack(); } - @Override @TruffleBoundary public int getWindowWidth() { return canvas.getWidth(); } - @Override @TruffleBoundary public int getWindowHeight() { return canvas.getHeight(); } - @Override @TruffleBoundary public void setFullscreen(final boolean enable) { if (enable) { @@ -258,7 +243,6 @@ public void setFullscreen(final boolean enable) { frame.setVisible(true); } - @Override @TruffleBoundary public void open(final PointersObject sqDisplay) { canvas.setSqueakDisplay(sqDisplay); @@ -280,16 +264,14 @@ public void open(final PointersObject sqDisplay) { } } - @Override @TruffleBoundary public boolean isVisible() { return frame.isVisible(); } - @Override @TruffleBoundary public void setCursor(final int[] cursorWords, final int[] mask, final int width, final int height, final int depth, final int offsetX, final int offsetY) { - final Dimension bestCursorSize = TOOLKIT.getBestCursorSize(width, height); + final Dimension bestCursorSize = Toolkit.getDefaultToolkit().getBestCursorSize(width, height); final Cursor cursor; if (bestCursorSize.width == 0 || bestCursorSize.height == 0) { cursor = Cursor.getDefaultCursor(); @@ -325,7 +307,7 @@ public void setCursor(final int[] cursorWords, final int[] mask, final int width } // Ensure hotspot is within cursor bounds. final Point hotSpot = new Point(Math.min(Math.max(offsetX, 1), width - 1), Math.min(Math.max(offsetY, 1), height - 1)); - cursor = TOOLKIT.createCustomCursor(bufferedImage, hotSpot, "TruffleSqueak Cursor"); + cursor = Toolkit.getDefaultToolkit().createCustomCursor(bufferedImage, hotSpot, "TruffleSqueak Cursor"); } frame.setCursor(cursor); } @@ -346,7 +328,6 @@ private static int[] mergeCursorWithMask(final int[] cursorWords, final int[] ma return cursorMergedWords; } - @Override public long[] getNextEvent() { return deferredEvents.pollFirst(); } @@ -384,31 +365,26 @@ private long getEventTime() { return System.currentTimeMillis() - image.startUpMillis; } - @Override public void setDeferUpdates(final boolean flag) { deferUpdates = flag; } - @Override public boolean getDeferUpdates() { return deferUpdates; } - @Override @TruffleBoundary public void setWindowTitle(final String title) { frame.setTitle(title); } - @Override public void setInputSemaphoreIndex(final int interruptSemaphoreIndex) { CompilerDirectives.transferToInterpreterAndInvalidate(); inputSemaphoreIndex = interruptSemaphoreIndex; } - @Override @TruffleBoundary - public String getClipboardData() { + public static String getClipboardData() { try { return (String) Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor); } catch (UnsupportedFlavorException | IOException e) { @@ -416,24 +392,17 @@ public String getClipboardData() { } } - @Override @TruffleBoundary - public void setClipboardData(final String text) { + public static void setClipboardData(final String text) { final StringSelection selection = new StringSelection(text); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection); } - @Override @TruffleBoundary - public void beep() { + public static void beep() { Toolkit.getDefaultToolkit().beep(); } - @Override - public void pollEvents() { - throw SqueakException.create("No need to poll for events manually when using AWT."); - } - private final class SqueakDropTargetAdapter extends DropTargetAdapter { @Override diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/io/SqueakDisplayInterface.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/io/SqueakDisplayInterface.java deleted file mode 100644 index 92da494f9..000000000 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/io/SqueakDisplayInterface.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2017-2022 Software Architecture Group, Hasso Plattner Institute - * Copyright (c) 2021-2022 Oracle and/or its affiliates - * - * Licensed under the MIT License. - */ -package de.hpi.swa.trufflesqueak.io; - -import de.hpi.swa.trufflesqueak.model.PointersObject; - -public interface SqueakDisplayInterface { - - void showDisplayBitsLeftTopRightBottom(PointersObject destForm, int left, int top, int right, int bottom); - - void showDisplayRect(int left, int right, int top, int bottom); - - void close(); - - void resizeTo(int width, int height); - - int getWindowWidth(); - - int getWindowHeight(); - - void setFullscreen(boolean enable); - - void open(PointersObject sqDisplay); - - boolean isVisible(); - - void setCursor(int[] cursorWords, int[] mask, int width, int height, int depth, int offsetX, int offsetY); - - long[] getNextEvent(); - - void setDeferUpdates(boolean flag); - - boolean getDeferUpdates(); - - void setWindowTitle(String title); - - void setInputSemaphoreIndex(int interruptSemaphoreIndex); - - String getClipboardData(); - - void setClipboardData(String text); - - void beep(); - - void pollEvents(); -} diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/IOPrimitives.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/IOPrimitives.java index a7da26467..449758384 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/IOPrimitives.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/IOPrimitives.java @@ -11,7 +11,6 @@ import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; -import com.oracle.truffle.api.TruffleOptions; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Cached.Shared; import com.oracle.truffle.api.dsl.Fallback; @@ -28,7 +27,7 @@ import de.hpi.swa.trufflesqueak.exceptions.PrimitiveExceptions.PrimitiveFailed; import de.hpi.swa.trufflesqueak.image.SqueakImageContext; import de.hpi.swa.trufflesqueak.image.SqueakImageWriter; -import de.hpi.swa.trufflesqueak.io.SqueakDisplayInterface; +import de.hpi.swa.trufflesqueak.io.SqueakDisplay; import de.hpi.swa.trufflesqueak.io.SqueakIOConstants; import de.hpi.swa.trufflesqueak.model.ArrayObject; import de.hpi.swa.trufflesqueak.model.BooleanObject; @@ -109,14 +108,10 @@ protected final Object doSet(final Object receiver, final long semaIndex) { protected abstract static class PrimGetNextEventNode extends AbstractPrimitiveNode implements BinaryPrimitiveFallback { @Specialization - protected final PointersObject doGetNext(final PointersObject eventSensor, final ArrayObject targetArray, - @Cached("createIdentityProfile()") final ValueProfile displayProfile) { + protected final PointersObject doGetNext(final PointersObject eventSensor, final ArrayObject targetArray) { final SqueakImageContext image = getContext(); if (image.hasDisplay()) { - final SqueakDisplayInterface display = displayProfile.profile(image.getDisplay()); - if (TruffleOptions.AOT) { - display.pollEvents(); - } + final SqueakDisplay display = image.getDisplay(); final long[] event = display.getNextEvent(); targetArray.setStorage(event != null ? event : SqueakIOConstants.NONE_EVENT); } else { @@ -867,7 +862,7 @@ protected abstract static class PrimBeepNode extends AbstractPrimitiveNode { protected final Object doBeep(final Object receiver) { final SqueakImageContext image = getContext(); if (image.hasDisplay()) { - image.getDisplay().beep(); + SqueakDisplay.beep(); } else { image.printToStdOut((char) 7); } diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/MiscellaneousPrimitives.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/MiscellaneousPrimitives.java index 1053811cb..07b9454ad 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/MiscellaneousPrimitives.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/MiscellaneousPrimitives.java @@ -26,6 +26,7 @@ import de.hpi.swa.trufflesqueak.exceptions.PrimitiveExceptions.PrimitiveFailed; import de.hpi.swa.trufflesqueak.image.SqueakImageContext; +import de.hpi.swa.trufflesqueak.io.SqueakDisplay; import de.hpi.swa.trufflesqueak.model.AbstractPointersObject; import de.hpi.swa.trufflesqueak.model.AbstractSqueakObject; import de.hpi.swa.trufflesqueak.model.AbstractSqueakObjectWithClassAndHash; @@ -479,7 +480,7 @@ protected abstract static class PrimClipboardText1Node extends AbstractPrimitive protected final NativeObject getClipboardText(@SuppressWarnings("unused") final Object receiver) { final SqueakImageContext image = getContext(); if (image.hasDisplay()) { - return image.asByteString(image.getDisplay().getClipboardData()); + return image.asByteString(SqueakDisplay.getClipboardData()); } else { return image.clipboardTextHeadless; } @@ -493,7 +494,7 @@ protected abstract static class PrimClipboardText2Node extends AbstractPrimitive protected final NativeObject setClipboardText(@SuppressWarnings("unused") final Object receiver, final NativeObject value) { final SqueakImageContext image = getContext(); if (image.hasDisplay()) { - image.getDisplay().setClipboardData(value.asStringUnsafe()); + SqueakDisplay.setClipboardData(value.asStringUnsafe()); } else { image.clipboardTextHeadless = value; }