For a summary of Java 2D properties, see Java 2D Properties.
By choosing a different pipeline, or manipulating the properties of a pipeline, you might be able to determine the cause of the problem, and often find a workaround.
In general, you can troubleshoot Java 2D pipeline issues by determining the default pipeline used in your configuration. Then, either change the pipeline to another one, or modify the properties of the default pipeline.
If the problem disappears, then you found a workaround. If the problem persists, then try changing another property or pipeline.
Java 2D uses a set of pipelines, which can be roughly defined as different ways of rendering the primitives. These pipelines are as follows:
Oracle Solaris and Linux: X11 Pipelineis the default for the Oracle Solaris and Linux operating systems.
Windows OS - DirectDraw/GDI Pipeline is the default on Windows
Windows OS - Direct3D Pipeline in Full-Screen Mode is an alternative on Windows.
OpenGL Pipeline in Oracle Solaris, Linux, and Windowsis an alternative on the Oracle Solaris and Linux operating systems, as well as Windows.
On UNIX platforms, the default pipeline is the X11 pipeline. This pipeline uses the X protocol for rendering to the screen or to certain types of offscreen images, such as VolatileImages
, or "compatible" images (images that are created with the GraphicsConfiguration.createCompatibleImage() method).
These types of images can be put into X11 pixmaps for improved performance, especially in the case of the Remote X server.
In addition, in certain cases, Java 2D uses X server extensions, for example, the MIT X shared memory extension, or Direct Graphics Access extension, Double-buffer extension for double-buffering when using the BufferStrategy
API.
An additional pipeline, the OpenGL pipeline, might offer greater performance in some configurations.
The following are X11 pipeline properties to troubleshoot.
Java 2D by default uses X11 pixmaps for storing or caching certain types of offscreen images.
Only the following types of images can be stored in pixmaps:
Opaque images, in which case ColorModel.getTransparency() returns Transparency.OPAQUE
1-bit transparent images (also known as sprites, Transparency.BITMASK
)
The advantage of using pixmaps for storing images is that they can be put into the framebuffer's video memory at the driver's discretion, which improves the speed at which these pixmaps can be copied to the screen or another pixmap.
The use of pixmaps typically results in better performance. However, in certain cases, the opposite is true. These cases typically involve the use of operations that cannot be performed using the X protocol, such as antialiasing, alpha compositing, and transforms that are more complex than simple translation transforms.
For these operations, the X11 pipeline must do the rendering using the built-in software renderer. In most cases, this includes reading the contents of the pixmap to system memory (over the network in the case of remote X server), performing the rendering, and then sending the pixels back to the pixmap. These operations could result in extremely poor performance, especially if the X server is remote.
The following are two cases to disable the use of X11 pipeline:
Disable X11 pipeline pixmaps:
To disable the use of pixmaps by Java2D, pass the following property to the Java VM: -Dsun.java2d.pmoffscreen=false
.
Disable X11 pipeline shared memory pixmaps:
Note:
The shared memory pixmaps can only be used in the case of a local X server.The advantage of using shared memory pixmaps is that the pipeline can get direct access to the pixels in the pipeline bypassing the X11 protocol, which results in better performance.
By default, an image is stored in a normal X server pixmap, but it can be later moved to a shared memory pixmap if the pipeline detects excessive reading from such an image. The image can be moved back to a server pixmap if it is copied from often enough.
The pipeline allows two ways of controlling the use of shared memory pixmaps: either disabling them or forcing all images to be stored in shared memory pixmaps.
To disable shared memory pixmaps, set the J2D_PIXMAPS
environment variable to server
. This is the default in remote X server case.
To force all pixmaps to be created in shared memory, set J2D_PIXMAPS
to shared
.
The Java 2D X11 pipeline uses the MIT Shared Memory Extension (MIT SHM), which allows a faster exchange of data between the client and the X server. This can significantly improve the performance of Java applications.
The following are two ways to improve the performance of the Java application.
On SPARC hardware, if the framebuffer supports Sun's Direct Graphics Access (DGA) X server extension, and Java 2D has a corresponding module for accessing the framebuffer, then DGA will be used for rendering to the screen.
All offscreen images will reside in Java heap memory, and Java 2D's software-only rendering pipeline is used for rendering to them. This is different from a typical UNIX configuration, where X11 pixmaps are used for offscreen images.
The following are use cases that describe how to detect DGA extension support and disable or enable DGA:
On certain video boards on the SPARC platform, more than one visual can be available from the X server.
By default, Java 2D tries to select the best visual, where "best" is typically a higher-bit depth visual. For example, on some Oracle Solaris operating system releases, the default X11 visual is 8-bit PseudoColor, although 24-bit visual is also available. In these cases, Java 2D selects a 24-bit TrueColor visual as the default for Java windows.
While it is possible to create a Java top-level window with a GraphicsConfiguration
object corresponding to a different visual, in some cases, it is necessary to make Java use a different default visual instead. This can be done by setting the FORCEDEFVIS
environment variable. It can be set to true
to force the use of the default X server visual (even if it is not the best one), or it can be set to a hexadecimal number corresponding to the visual ID as reported by tools like xdpyinfo
.
To determine your X server default visual, execute the xdpyinfo
command and look at the default visual id
field.
The default pipeline on the Windows platform is a mixture of the DirectDraw pipeline and the GDI pipeline, where some operations are performed with the DirectDraw pipeline and others with the GDI pipeline. DirectDraw and GDI APIs are used for rendering to accelerated offscreen and onscreen surfaces.
Starting with the Java SE 6 release, when the application enters full-screen mode, the new Direct3D pipeline can be used, if the drivers satisfy the requirements. The possible issues with the Direct3D pipeline include rendering artifacts, crashes, and performance related problems.
An additional pipeline, the OpenGL pipeline, might offer greater performance in some configurations.
The following are three cases to troubleshoot issues with the Direct3D pipeline such as rendering artifacts, crashes, and performance related problems:
Starting with the Java SE 6 release, the Direct3D pipeline uses the Direct3D API for rendering. This pipeline is enabled in full-screen mode by default, if the drivers support the required features and the level of rendering quality.
It is possible to enable the Direct3D pipeline or to force its use, as described in the following sections:
Consider enabling the Direct3D pipeline for your application if it heavily uses rendering operations such as alpha compositing, antialiasing, and transforms.
However, use caution when deciding to enable this pipeline in your application. For example, some built-in video chipsets (which are used in most notebooks) do not perform well using Direct3D, even if they satisfy the quality requirements for Java 2D pipelines.
The following are three cases to troubleshoot problems with Direct3D API.
The OpenGL pipeline is available on Oracle Solaris, Linux, and Windows.
This alternate pipeline uses the hardware-accelerated, cross-platform OpenGL API when rendering to VolatileImages
, to backbuffers created with BufferStrategy
API, and to the screen.
This pipeline can offer great performance advantages over the default (X11 or GDI/DirectDraw) pipelines for certain applications. Consider enabling the pipeline for your application if it heavily uses of rendering operations like alpha compositing, antialiasing, and transforms.
The following are use cases for troubleshooting problems in OpenGL pipeline
The OpenGL pipeline is disabled by default.
To attempt to enable the OpenGL pipeline, provide the following option to the JVM:
-Dsun.java2d.opengl=true
To receive verbose console output about whether the OpenGL pipeline is initialized successfully for a particular screen, set the option to True (note the uppercase T).
The OpenGL pipeline will not be enabled if the hardware or drivers do not meet the minimum requirements.
If one of the following requirements is not met, Java 2D will fall back and use the default pipeline (X11 on Oracle Solaris/Linux or GDI/DirectDraw on Windows), which means your application will continue to work correctly, but without the OpenGL acceleration.
The minimum requirements for the Oracle Solaris and Linux operating systems are the following:
Hardware accelerated OpenGL/GLX libraries installed and configured properly
OpenGL version 1.2 or higher
GLX version 1.3 or higher
At least one TrueColor visual with an available depth buffer
The minimum requirements for Windows OS are the following:
Hardware accelerated drivers supporting the extensions WGL_ARB_pbuffer
, WGL_ARB_render_texture
, and WGL_ARB_pixel_format
OpenGL version 1.2 or higher
At least one pixel format with an available depth buffer
You can get detailed information about the startup procedures of the OpenGL-based Java 2D pipeline by using the J2D_TRACE_LEVEL
environment variable.
As previously mentioned, the OpenGL pipeline might not be enabled on certain machines for various reasons. For example, the drivers might not be properly installed and might report an insufficient version number. Alternatively, your machine might have an older graphics card that does not support the appropriate OpenGL version or extensions.
In the Java SE 6 and later releases, you can get detailed information about the startup procedures of the OpenGL-based Java 2D pipeline by using the J2D_TRACE_LEVEL
environment variable, as shown in the following examples.
Set the J2D_TRACE_LEVEL
environment variable on Windows.
# set J2D_TRACE_LEVEL=4 # java -Dsun.java2d.opengl=True YourApp
Set the J2D_TRACE_LEVEL
environment variable on Solaris and Linux.
# export J2D_TRACE_LEVEL=4 # java -Dsun.java2d.opengl=True YourApp
The output will be different depending on your platform and the installed graphics hardware, but it can give you some insight into the reasons why the OpenGL pipeline is not being successfully enabled for your configuration.
Note:
This output is especially useful when filing bug reports intended for the Java 2D team at Sun.
Diagnose if rendering or performance issues are being caused by Java 2D or by the OpenGL drivers.
Because the OpenGL pipeline relies so heavily on the underlying graphics hardware and drivers, it might sometimes be difficult to determine whether rendering or performance issues are being caused by Java 2D or by the OpenGL drivers.
One feature new to the OpenGL pipeline in the Java SE 6 release is the use of the GL_EXT_framebuffer_object
extension, which provides better performance for rendering and reduced VRAM consumption when using VolatileImages
. This "FBO" codepath is enabled by default when the OpenGL pipeline is enabled, but only if your graphics hardware and driver support this OpenGL extension. This extension is generally available on Nvidia GeForce/Quadro FX series and later, and on ATI Radeon 9500 and later. If you suspect that the "FBO" codepath is causing problems in your application, then you can disable it by setting the following system property:
-Dsun.java2d.opengl.fbobject=false
Setting this property will cause Java 2D to fall back on the older pbuffer-based
codepath.
If you find that a certain Java 2D operation causes different visual results with the OpenGL pipeline enabled than without, then it probably indicates a graphics driver bug. Similarly, if the performance of Java 2D rendering is significantly worse with the OpenGL pipeline enabled than without, then it is most likely caused by a driver or hardware problem.
In either case, file a detailed bug report through the normal bug reporting channels. See Submit a Bug Report. When filing bug reports, be as detailed as possible, and include the following information:
J2D_TRACE_LEVEL=4
is specified on the command line (as described in the previous section)glxinfo
command if you are on Oracle Solaris or LinuxList of graphics card manufacturers with their corresponding websites, supported platforms, and some examples of cards.
Because the OpenGL pipeline relies heavily on the OpenGL API and the underlying graphics hardware and drivers, it is very important to ensure that you have the latest graphics drivers installed on your machine. Drivers can be downloaded from your graphics card manufacturer's web site, as shown in the following table.
Manufacturer | Platforms | Cards Known to Work |
---|---|---|
Linux, Windows |
Radeon 8500 and later, FireGL series |
|
Oracle Solaris on x64, Linux, Windows |
GeForce 2 series and later, Quadro FX series and later |
|
Oracle Solaris on SPARC |
Expert3D series, XVR-500, XVR-600, XVR-1200, XVR-2500 |
|
Oracle Solaris on x86, Linux |
Various (check with Xi Graphics) |