Skip to content

JNode Graphics2D

Levente Santha edited this page May 11, 2026 · 1 revision

JNode Graphics2D

Graphics2D implementation with hardware acceleration support in JNode's AWT peer layer.

Overview

JNode provides two Graphics2D implementations for AWT component rendering:

  • Current: JNodeSurfaceGraphics2D — extends SurfaceGraphics2D, delegates drawing operations to a Surface abstraction
  • Deprecated: JNodeGraphics2D — extends AbstractSurfaceGraphics2D (which extends GNU Classpath's AbstractGraphics2D), uses an internal BufferedImage for software rendering

Both implementations bridge the standard Java 2D API to JNode's video driver layer via the Surface interface.

Class Hierarchy

java.awt.Graphics2D
├── SurfaceGraphics2D (abstract, gui/src/awt/org/jnode/awt/util/)
│   └── JNodeSurfaceGraphics2D (gui/src/awt/org/jnode/awt/)
└── gnu.java.awt.java2d.AbstractGraphics2D (GNU Classpath)
    └── AbstractSurfaceGraphics2D (abstract, deprecated, gui/src/awt/org/jnode/awt/util/)
        └── JNodeGraphics2D (deprecated, gui/src/awt/org/jnode/awt/)

Rendering Pipeline

JNodeSurfaceGraphics2D (Current)

JNodeSurfaceGraphics2D wraps an AbstractSurface (from the video driver layer) and delegates all rendering through it:

  1. getDestinationRaster() lazily creates a BufferedImage (TYPE_INT_ARGB) sized to the component
  2. Drawing operations (fill, draw, drawString) delegate to surface.draw(...), surface.fill(...), or FontManager
  3. updateRaster() blits the BufferedImage back to the surface via drawImage(image, 0, 0, null)

This is a double-buffering approach: rendering writes to an offscreen BufferedImage, and updateRaster flushes it to the physical surface.

JNodeGraphics2D (Deprecated)

JNodeGraphics2D uses the older AbstractSurfaceGraphics2D base:

  1. getDestinationRaster() lazily creates a BufferedImage (TYPE_INT_ARGB)
  2. Drawing operations (rawDrawLine, rawFillRect, rawDrawString) directly call surface methods
  3. updateRaster() calls rawUpdateRaster() to flush the raster to the surface

AbstractSurfaceGraphics2D also manages rendering modes (PAINT_MODE vs XOR_MODE) via Surface.PAINT_MODE/Surface.XOR_MODE.

Surface Integration

The Surface interface (org.jnode.driver.video.Surface) is the core abstraction for paintable 2D regions:

  • FrameBuffer-backed: Physical video memory or memory-mapped framebuffer
  • BufferedImage-backed: In-memory image buffer used as rendering target

Key surface operations used by Graphics2D:

  • surface.drawCompatibleRaster(...) — blit a raster to the surface
  • surface.fillRect(...) / surface.drawLine(...) — primitive drawing
  • surface.copyArea(...) — fast copy for copyArea
  • surface.draw(...) — shape rendering via BasicSurfaceGraphics
  • surface.getColorModel() — get the ColorModel for raster compatibility

Font Rendering

Both Graphics2D implementations route text rendering through JNodeToolkit.getFontManager():

tk.getFontManager().drawText(surface, getClip(), getTransform(), text, font, x, y, getColor());

The FontManager (org.jnode.awt.font.FontManager) dispatches to TrueType (TTFFontData) or BDF (BDFFontContainer) renderers. See Font-Rendering for details.

Rendering Modes

AbstractSurfaceGraphics2D maintains a mode field:

  • Surface.PAINT_MODE — normal opaque paint (set via setPaintMode())
  • Surface.XOR_MODE — XOR composite mode for fast drawing (set via setXORMode(Color))

Only JNodeSurfaceGraphics2D supports full Graphics2D state (AffineTransform, Composite, Stroke, Paint, RenderingHints).

Color Model and Bit-Depth

JNodeToolkit.getColorModel() provides the ColorModel for the current display configuration. Graphics2D classes use this to:

  • Validate raster compatibility (isCompatibleRaster)
  • Convert between pixel formats when blitting images

The video driver layer supports multiple bit-depths (8bpp indexed, 16bpp, 24bpp, 32bpp), and the color model adapts accordingly.

Key Helper Classes

Class Role
BasicSurfaceGraphics Simple Graphics implementation delegating to Surface, handles origin translation, clipping, color, font
SurfaceGraphics2D Full Graphics2D state (transform, composite, stroke, paint, hints) delegating simple operations to BasicSurfaceGraphics
AbstractSurface Base for surface implementations in org.jnode.driver.video.util
BufferedImageSurface In-memory surface wrapping BufferedImage
GraphicsFactory Factory for creating appropriate Graphics2D instances per component type

Gotchas

  • Deprecated path: JNodeGraphics2D / AbstractSurfaceGraphics2D are marked @deprecated and may be removed
  • Missing implementations: JNodeSurfaceGraphics2D has stub implementations for clip(Shape), drawRenderedImage, drawRenderableImage, drawImage(AffineTransform), drawImage(BufferedImageOp), hit(), shear() — all emit debug messages via Unsafe.debug
  • getDeviceConfiguration() returns null in JNodeSurfaceGraphics2D
  • Double buffering overhead: The current implementation renders to a BufferedImage then blits to the surface, adding a copy per update cycle
  • Clip transformation: BasicSurfaceGraphics handles origin translation; JNodeSurfaceGraphics2D applies an AffineTransform from the graphics origin for shape operations

Related Classes

  • gui/src/awt/org/jnode/awt/JNodeGenericPeer — the AWT peer base; creates Graphics2D instances via GraphicsFactory
  • gui/src/awt/org/jnode/awt/JNodeToolkit — provides getGraphics() returning the AbstractSurface, color model, and font metrics
  • gui/src/awt/org/jnode/awt/util/BasicSurfaceGraphics — simple Graphics implementation underlying both Graphics2D classes
  • gui/src/awt/org/jnode/awt/util/AbstractSurfaceGraphics2D — deprecated base with direct surface rendering
  • gui/src/driver/org/jnode/driver/video/ — video driver layer with Surface interface and implementations

Clone this wiki locally