Bug 111436 - Improve performance of SVG transcoder
Summary: Improve performance of SVG transcoder
Status: RESOLVED FIXED
Alias: None
Product: GMF-Runtime
Classification: Modeling
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P1 enhancement
Target Milestone: 1.0   Edit
Assignee: Steven R. Shaw CLA
QA Contact:
URL:
Whiteboard:
Keywords: api, performance
Depends on:
Blocks:
 
Reported: 2005-10-04 09:35 EDT by Steven R. Shaw CLA
Modified: 2010-07-19 12:28 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steven R. Shaw CLA 2005-10-04 09:35:15 EDT
Possibilities include:
- Improve performance of SVG transcoder to render directly to SWT image 
instead of converting from BufferedImage
- Case for when you are rendering a large image as a background for a diagram 
editor.  Perhaps we also need to optimize the RenderedImage class to support a 
partial rectangle such that we only end up rendering a portion of the image 
based on the viewport.
Comment 1 Min Idzelis CLA 2005-10-05 16:48:50 EDT
Ideally, it would be great if instead of using images at all, you would draw
directly to the SWT GC. This was not possible in previous releases of SWT. Now
with SWT 3.1's addition of advanced graphics support this is doable. Batik has a
class that you can fill in with the primitives needed to do this. 

Refer to DefaultGraphics2D 

http://xml.apache.org/batik/javadoc/org/apache/batik/ext/awt/g2d/DefaultGraphics2D.html
Comment 2 Min Idzelis CLA 2005-10-05 16:52:46 EDT
As an aside, I think BIRT has a SVG renderer/exporter. There may be
opportunities for code reuse between the two projects. 
Comment 3 Steven R. Shaw CLA 2005-10-06 14:35:45 EDT
Changing component to "Runtime Diagram"
Comment 4 Tom Macdougall CLA 2005-11-04 16:08:19 EST
I will improving the test for SVG method in RenderedImageFactory. I noticed 
that the SVGImage keeps an XML Document and the byte array buffer (from 
AbstractRenderedImage) of the original XML document stream in memory (twice 
the memory for one SVG). The XML Document might need to be a WeakReference to 
save on the memory or maybe keep an URI of sorts.

The byte array buffer is keeping the entire XML documents' contents in memory 
(which could be quite large). Maybe we could use some form of 
InputStream/Reader implementations so that data is kept only in memory on-
demand and then released. We could keep SWT images in memory (because they 
appear in the UI) and the fileName/URI. A new InputStream/Reader could be 
opened to perform any required operations on-demand.
Comment 5 Steven R. Shaw CLA 2005-11-29 11:42:59 EST
Delivered to head:

General performance improvements to the RenderedImage infrastructure:
- Avoid recalculation of buffer checkSum on rerender of image
- Cache SVGDocument on first render to avoid recalculating it on subsequent renderings.
- Improved conversion of BufferedImage to swt Image.
- Removed buffer copy in AbstractRenderedImage
- Removed redundant copy of BufferedImage in ImageTranscoderEx
- Improved caching in ScalableImageFigure to minimize re-rendering

Achieved approximatly 25% improvement in performance for subsequent re-renderings of an SVG.

Still to do (investigate):
- allow extensibility of RenderedImageFactory
- asynchronous rendering
- remove java.awt dependency from root infrastructure.
- separate awt components into different plug-in 
Comment 6 Steven R. Shaw CLA 2005-12-02 13:57:59 EST
added api keyword
Comment 7 Steven R. Shaw CLA 2005-12-05 15:36:04 EST
Description:
Some improvements to the SVG rendering capability in GMF to support: 
- asynchronous rendering of SVG files to avoid locking up the UI during rendering operation. 
- removing of java.awt package dependency from the root and public classes to enable future plug-in separation and extensibility of the RenderedImage infrastructure. 
- allow maximum rendering size to avoid rendering a huge image unnecessarily.  This is useful for display. 

Summary of changes: (Old api is currently preserved in deprecated form) 
- Subclass RenderedImage interface from IAdaptable to allow implementors to adapt to different image formats.  Specifically this allows the removal of the getBufferedImage method and instead clients can call getAdapter(BufferedImage.class) instead.  Or if native rendering support to BufferedImage isn't supported clients can use ImageConverter.convert( myRenderedImage.getSWTImage() ). 
- RenderInfo#getFillColor and RenderInfo#getOutlineColor have been deprecated and replaced with replaced by getBackgroundColor and getForegroundColor respectively.  They return RGB values. 
- RenderInfo#setValues(int width, int height, java.awt.Color fill, java.awt.Color outline,boolean maintainAspectRatio,boolean antialias) is deprecated and replaced with RenderInfo#setValues(int width, int height, boolean maintainAspectRatio, boolean antialias, RGB background, RGB foreground).  Note: color parameters have been moved to the end of the method signature to avoid ambiguous null parameters and to group other parameters more appropriately. 
Comment 8 Steven R. Shaw CLA 2005-12-05 15:37:23 EST
Users of ScaleableImageFigure should benefit from these changes
Comment 9 Steven R. Shaw CLA 2005-12-05 16:38:57 EST
Refer to bugzilla 119319 for handling the following:
- allow extensibility of RenderedImageFactory
- separate awt components into different plug-in 
Comment 10 Steven R. Shaw CLA 2005-12-14 10:16:29 EST
I may re-open this or create another bugzilla to address rendering directly to an SWT image instead of the indirection we have now.  Apparently there is an example of how to accomplish this in the PrintTranscoder file.
Comment 11 Dave Carlson CLA 2005-12-14 16:32:02 EST
Steven,

Would it be possible to generalize this, or include an option to reder the SVG directly onto an SWT Canvas (instead of Image) for inclusion in a View or Editor?

For the past three years I've been using the j2d4swt plugins from www.holongate.org to create Eclipse viewers for SVG graphics.  These low-level SWT graphics are not my forte, but I'd be very interested in contributing where I can to create a reusable SVGCanvas for presenting SVG documents.  As part of this, I need (and have implemented) mouse listeners for detecting click regions on the canvas by using the Batik SVGDocument.
Comment 12 Steven R. Shaw CLA 2005-12-14 16:39:12 EST
Yes, it looks like that is possible.  I'm experimenting with rendering the SVG directly to an swt Graphics object.  If this is successful, then there is no need for the indirection to an Image (though it would still be supported).  I would probably extend the RenderedImage api to have a render(Graphics g) api in order for this to to work.

In future, if the RenderedImage infrastructure is integrated into GEF, the Graphics api could support it directly.
Comment 13 Min Idzelis CLA 2005-12-14 16:41:51 EST
Ok, this is a sorta way out there comment, but if rendering directly to a Graphics object is possible - would it be possible at all to create Figures out of the SVG? 
Comment 14 Steven R. Shaw CLA 2005-12-14 17:09:54 EST
I think that's what ScaleableImageFigure satisfies.  Even if I'm successful, directly rendering to the Graphics object, it wouldn't change the usage scenario for ScaleableImageFigure.  It would merely improve rendering performance.
Comment 15 Dave Carlson CLA 2005-12-14 17:16:57 EST
Great, thanks!  Please ping this bugzilla (or my email) when something is checked into CVS for rendering to Graphics, and I'll try some experimentation.  I may have other requests for API to enable an SVGCanvas with mouse event listeners, e.g. public access to the loaded SVGDocument instance.

Is there any timeframe for integrating RenderedImage with GEF?  Is this possible in the GMF 1.0 release timeframe?
Comment 16 Steven R. Shaw CLA 2006-01-03 10:15:13 EST
I've created a new delegator class: Graphics2DToGraphicsAdaptor that allows the Batik renderer to paint directly onto an SWT GC.  This improves rendering performance by up to 50%.  It currently delegates directly to an swt GC instead of the draw2d Graphics class because draw2d doesn't expose all the capabilities of advanced graphics such as Transform.  This means we still have a level of indirection through the SWT Image before rendering in the draw2d world.  Once this is resolved, then performance could be improved even more by exposing an api on RenderedImage to draw on a Graphics directly.
Comment 17 Richard Gronback CLA 2008-08-13 13:06:21 EDT
[target cleanup] 1.0 M4 was the original target milestone for this bug
Comment 18 Eclipse Webmaster CLA 2010-07-19 12:28:33 EDT
[GMF Restructure] Bug 319140 : product GMF and component
Runtime Diagram was the original product and component for this bug