Sonntag, 8. Juni 2008

Glyph cache...

There aren't any nice images to show this time, however:

Over the weekend I implemented a glyphcache, so that I do not have to upload the glyph-images to the X-Server every time I draw some of them.
The whole thing was quite simple (beside some usual fighting with C), escpecially because XRender does already provide a glyph-centric API so I don't have to mess arround with pixmaps I cache the glyphs to - this is all done by X behind the scenes.

Althought there is already a glyph-cache in OpenJDK (jdk/src/share/native/sun/font/AccelGlyphCache), it does focus a lot on whats need for D3D/OGL and does too much for XRender (just overhead), but on the other hand does not provide some features which are needed, especially the ability to guarantee that a set of glyphs is in the cache.

The OGL backend draws its glyphs one after another, however with XRender we first have to upload all glyphs and later draw them all with a single command. So if we have to draw 1000 individual glyphs, but the cache can only hold 512, well, it will break.
Another nice feature implemented is, that inserting a new glyph will never throw out a glyph which is known to be used in the following glyph-blit.
All those things would be hard to implement with the existing cache, especially because OGL and D3D pipelines use a fixed-size texture for caching their glyphs, furthermore they would not benefit a lot from those changes.

Some things seem to be implemented too complex, and some are ... well not nice solutions (I currently squeeze an integer value into a pointer), but beside that it worked out quite well.

Time for drawing string rotated 50x:
X11: 6ms
X11-AA: 82ms
XR: 2ms
XR-AA: 2ms

X11 is the traditional X11 Java2d backend, XR the XR_ender backend I currently work on. -AA just means with grayscale antialiasing enabled.

Note that this was done using XAA (the old accaleration architecture) and quite likely is not even hardware accelerated. With recent improvements in EXA I hope for even better results and hw-accaleration.
Please note that XR still had some logging-code in, so it would be even a bit faster :)

1 Kommentar:

Dmitri hat gesagt…

Those are pretty sweet numbers!

BTW, I suggest that you make the performance measurements with J2DBench (j2se/src/share/demo/java2d/J2DBench) benchmark. Let me know if you need help in how to use it..


You'll need to select a VI destination, then go to the text tab and select say drawString. You can also select whether to draw AA or not, and with/w/o transform or alpha compositing.

Dmitri