Best Way To Render
I am writing a Logic Analyzer host side software (for the logic), and rendering is taking too much resources. This is what the render looks like:
(just the View Window): http://i.imgur.com/Zt70k.png
I have tried:
1) Rendering everything everytime - slow and memory intensive
2) Layers with an alpha, and having 5 layers. 2 are always rendered, and the other 3 are rendered only if it changes, for example, the data layer only if zoom/pan changes. Also slow
The second is my current one. When I profile it, the top 2 major users of time are methods not in my program. One of them is fillRect (which I use, but it is pointing to something else, in a Java SE class). I use this prior to every rendering to fill with transparency, so as to avoid "ghosting". This was changed from making a new BufferedImage everytime, which was even slower.
The other major usage is something I am not familiar with, but was some sort of compositing. I am thinking that this is drawing the transparent BufferedImages to a common BufferedImage.
Together, these 2 account for almost 100% of the rendering time. What can I do to speed it up? Here is the code. It is very messy, as I am slowly converting it, and has some extraneous code. The render method is what is called everytime.
Complete Render Code: [Java] /* * To change this template, choose Tools | Templates * and open the templa - Pastebin.com
Just the relevant bits: // // NOT COMPILABLE // public BufferedImage render(int w, int h, int xP, i - Pastebin.com
I researched it a bit, I found some websites claiming that the Graphics API is one of the hardest to work with because it is so poorly documented in terms of behavior. The example I found was that it uses hardware acceleration, but as soon as you use the setRGB method, it stops.
Step -1: Render everything that is static to a BufferedImage, this is your background refresh image. (updated rarely)
[Note: do all drawing to one master buffered image: lets call it buffer]
Step 1: Draw background to buffer
Step 2: Draw highlighted rectangle to buffer
Step 3: Draw time tags to buffer
Step 4: Draw lines for each channel to buffer
Step 5: Draw buffer to screen (graphics object)
Repeat 1-5 in a loop (make sure to put in a timer or Thread.sleep(...) as to not use all CPU)
This will be fast.
Another option is to encapsulate each of the channels in a panel, and do similar as above.
Also. For performance use createCompatibleImage:
Graphics2D g2d = (Graphics2D)g;
BufferedImage buffer = (g2d).getDeviceConfiguration().createCompatibleImage(