[OpenJDK 2D-Dev] PATCH: Color.createContext fixlet
Jim.A.Graham at Sun.COM
Wed Apr 16 12:22:36 PDT 2008
I'm curious if you need this behavior or not. We are planning to delete
the doc comment in JDK7 because the context objects are so cheap to
create that it wasn't really necessary. The comment was added early in
the development of the 2D API and was documenting what was in the code
without much regard for whether the restrictions were reasonable. In
retrospect we should have had the docs simply say that it ignores the
various documented attributes in choosing a context, but not include any
promise that the same context will be returned as it is irrelevant from
an API perspective for any real world purposes. Also, very early in the
2D development we ended up calling createContext() on the Color object
in a lot of common cases from the rendering code and so its performance
really mattered - that is no longer the case.
The version you see in the OpenJDK 6 source base was inherited from an
early version of the OpenJDK 7 source base where we had made the
implementation change to fix a bug, but hadn't yet gotten the API
reviews to modify the spec to remove the promise. Our plan for 7 is
still to remove the restriction.
With respect to OpenJDK 6, it might be the path of least resistance to
remain true to the original JDK 6 spec, but it would be nice not to lose
the bug fix that caused the change in behavior in the first place -
which is the fact that SystemColor objects can mutate their getRGB()
values if the desktop colors change and if you cache a PaintContext with
the old rgb value then it could become wrong if the SystemColor mutates.
All this really requires is comparing the current rgb value to the one
that is in the cached context, but when we made the change initially in
JDK 7 we decided it was a good time to get rid of the questionable
caching anyway since returning a new context when the rgb value changes
would arguably still be violating the rather unnecessarily strict docs
in any case.
So, I guess it is reasonable to fix (though I'm still curious if anyone
but the JCK tests might rely on the behavior), but please fix it in a
way that is compatible with the SystemColor rgb mutation so that we
don't regress that bug at the same time...
Keith Seitz wrote:
> OpenJDK 6 fails to meet the API requirements for Color.createContext.
> Specifically: "The same PaintContext is returned, regardless of whether
> or not r, r2d, xform, or hints are null." As it is today,
> Color.createContext will return a different PaintContext every time it
> is called.
> The attached patch corrects this.
More information about the 2d-dev