<AWT Dev> [OpenJDK 2D-Dev] [8] Review request for 8011059 [macosx] Make JDK demos look perfect on retina displays

Jim Graham james.graham at oracle.com
Tue Nov 19 19:01:17 PST 2013

I did some more reading about the various ways in which the ImageObserver is used and noticed the following points, some of which may be to our advantage.

Many of the drawImage() calls mention that they will notify the observer as the image is "scaled or converted for the output device".  I believe in the world before 2D, we would often have to load or convert the image asynchronously for various changes in the output.  When we created the 2D interface and added some on-the-fly image scaling code, we mentioned that scaling was no longer asynchronous, but technically the API is still designed for asynchronous operations when the rendering parameters change.

However, the drawImage() call that takes 8 parameters dxy12, sxy12 - specifically includes the words:

      * This method always uses the unscaled version of the image
      * to render the scaled rectangle and performs the required
      * scaling on the fly. It does not use a cached, scaled version
      * of the image for this operation. Scaling of the image from source
      * to destination is performed such that the first coordinate
      * of the source rectangle is mapped to the first coordinate of
      * the destination rectangle, and the second source coordinate is
      * mapped to the second destination coordinate. The subimage is
      * scaled and flipped as needed to preserve those mappings.
     public abstract boolean drawImage(Image img,
                                       int dx1, int dy1, int dx2, int dy2,
                                       int sx1, int sy1, int sx2, int sy2,
                                       ImageObserver observer);

which basically, at the time it was created in 1.1, was an opt "out" of the asynchronous operations that might happen when you scaled an image with drawImage(xywh).  As worded, this would suggest that this method does not use the @2x version and always uses the default resolution version, but those words were not put there for this particular intent, they were put there to indicate that we weren't going to do an off-line scaling of the pixels which sometimes happened in 1.0.x and possibly 1.1 (for the other calls that predated 1.1 until Java2D).

I also found the Component.prepareImage() and Component.checkImage() methods which also take an ImageObserver.  Those methods imply that they will possibly start the process and return information on a particular version of an image appropriate for the current output device.  There is even a prepareImage(w,h) method that gets an image ready to render at the indicated size.  Given that these methods are on component, it probably makes sense to have that code look up which representation would be used for those indicated dimensions on the indicated output device that the Component is displayed on.


More information about the awt-dev mailing list