Z
Z
Zakharov Alexander2011-12-14 16:33:42
Java
Zakharov Alexander, 2011-12-14 16:33:42

java custom gradient

Hello, dear users of habrahabr.

I wanted to write my own gradient in java (JRE 1.6.29, Eclipse, Windows, awt). I wrote, but he makes me very sad. Tupit and very strong. Even on a small square - 300ms per paint - a lot. I looked at the source codes, for example, a linear gradient. I saw a kind of "caching" there. But, in order not to spoil the fever, I decided to simply copy the implementation of the LinearGradientPaint source codes under a different name, say, LinearGradientPaint_test (together with the LinearGradientPaintContext -> LinearGradientPaintContext_test, MultipleLinearGradient_test, MultipleLinearGradientContext_test classes). But here's what's amazing: simply copying the source code from the linear gradient ... gave the same brakes as my gradient!!!

question:

Is there any way to speed up the drawing of a custom gradient? Or maybe someone knows why the custom gradient is so slow?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zakharov Alexander, 2011-12-16
@AlexZaharow

There is some information on this subject. I contacted the person maintaining the site:
http://www.jhlabs.com/index.html
he replied:
The problem is that Java doesn't actually use the source for these gradients but instead has a special optimized version (I think running on the GPU). It detects if the gradient is an instance of one of the built in gradients and then switches to this special code, so the code in the gradient classes is never actually run.
Freely translated:
Java does not use the original code provided in the sources, but instead has an optimized version (which I believe runs on the GPU). Java detects if a gradient is "inline" then switches to special code so the code in its gradient classes is never actually executed.
I also noticed that the debugger still stops at the LinearGradient constructor, but it doesn’t stop at the fillRaster function.
A little bonus (there are very few tutorials on the internet explaining how to create gradient fills):
An example of a no-frills gradient:
asserttrue.blogspot.com/2010/01/how-to-iimplement-custom-paint-in-50.html
An example of a cone gradient (with caching, otherwise it’s generally stupid):
www.jug-muenster.de/java2d-conical-gradient-paint-674/ Found
nothing else. If anyone finds - throw a link, I will be very grateful.
I noticed a bright use of a non-standard fill in the Adobe Illustrator product (gradient mesh). Shustro works. Good example of gradient mesh:
Owl nose: www.digitalartsonline.co.uk/tutorials/?featureid=3221873&pn=2
Match fire (login required): demiart.ru/forum/index.php?showtopic=172676
Linear and radial gradient fills there also differ from standard fills, but not much. I don’t use Photoshop as an example, because it uses its fills exclusively as bitmap filters (by the way, in the light of the above, it becomes clear why they take so long to draw).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question