Review request: initial check-in for Cocoa-based AWT and lightweight peers

Artem Ananiev artem.ananiev at oracle.com
Thu Mar 31 07:43:57 PDT 2011


Hi, team,

as all you know, one of the major areas for contribution to MacOSX 
OpenJDK port is UI libraries: AWT, Java2D, Swing. Currently, macosx-port 
repository only contains X11-based implementation copied from BSD port, 
and it's time to start a new, Cocoa-based one.

Here is the webrev:

http://cr.openjdk.java.net/~art/macosx-port/lwawt-initial-checkin/

It's huge, and I don't expect a comprehensive review right now. The 
easier way is to apply the patch and to try running some applications. 
To enable the new toolkit, you need to set AWT_TOOLKIT environment 
variable. Here is an example to run Notepad demo shipped with JDK:

AWT_TOOLKIT=CToolkit <BUILD>/java -jar demos/jfc/Notepad/Notepad.jar

By default, without AWT_TOOLKIT specified, X11 toolkit (which is 
sun.awt.X11.XToolkit) is used. Headless support is to come a bit later.

The implementation is far from complete and robust. Many AWT components 
are missed: ScrollPane, TextArea and others. Many non-component classes 
like java.awt.Desktop or printing support are missed as well. There are 
some rendering artifacts on resize. All these are known limitations, and 
I'm going to file separate bugs for all the issues I notice and you report.

Here is some high-level technical background:

1. The webrev can be logically split into several parts: Makefile 
changes, fonts stuff, lightweight peers, MacOSX specific platform peers, 
OpenGL pipeline.

2. As on Linux/Solaris platforms, AWT/2D is build into two different 
libraries: <JRE>/lib/libawt.dylib and <JRE>/lib/lwawt/liblwawt.dylib 
Whether to load xawt/libmawt or lwawt/liblwawt is decided in 
awt_LoadLibrary.c, that is, at the time when AWT is loaded with a call 
to System.loadLibrary("awt"), typically, from Toolkit.java

3. Lightweight peers. This is the layer in sun.lwawt package to 
implement AWT regular components using Swing. I know it sounds really 
weird, but this is what I said :) The only heavyweight component is 
java.awt.Window and its counterpart sun.lwawt.LWWindowPeer. The peer 
forwards most of the calls to PlatformWindow, which is an interface, 
currently only implemented on MacOSX (but I don't see any obstacles to 
implement it on other platforms, if we find it useful later).

4. The classes in sun.lwawt.macosx are platform-specific counterparts of 
lightweight peer. One of them, CPlatformWindow, is the implementation of 
PlatformWindow interface, others are for menus, cursors, robot and other 
stuff.

5. At the native level, CPlatformWindow delegates the work to an 
instance of AWTWindow, which is a subclass of NSWindow. This class 
receives all the input and other events, dispatches them to 
CPlatformWindow, which forwards them to LWWindowPeer and then to a 
proper AWT component.

Thanks,

Artem


More information about the macosx-port-dev mailing list