Help save net neutrality! Learn more.

Multithreading and rendering - colors are grayscaled and random chars are missing

Peter M
  • Peter M

    Peter M - 2013-09-18


    When I render in multiple thread's I get different results, the following:

    1) Rendering to swt.Image creates images with randomly missing chars and grayscaled colors

    2) Rendering to awt.BufferedImage creates images with grayscaled colors only but here the text is fine.

    I am using rendering as given in the examples (in my application I use SWT only). Do you have an idea how to help the problem in 1)?

    Best, Peter

  • Peter M

    Peter M - 2013-09-19

    Ok, problem solved for the missing characters, I made the renderPage method synchronized passing a reference to each thread and it works fine. The problem with the color that is grayscaled comes up after saving with cutePDF/Ghostscript.

  • mtraut

    mtraut - 2013-09-23

    Sorry for the delay....

    Regarding the font i'm a little confused.. we strive for thread safety in the implementation where we can (e.g. it should be no problem to work on the COS model in different threads). The freetype based font rendering has its caveats but is synchronized when accessing the primitives. So maybe we should dig deeper here (someday). Your scenario does multi threaded rendering of the identical document?

    As for the grayscale: did you already open the document in another viewer to ensure that you didn't create a grayscale pdf? If not, please provide an example document.


  • Elfi Heck

    Elfi Heck - 2014-03-21

    mtraut is more qualified to comment on your font problem (it's quite busy here currently, so some patience might be required), but you might run into other strange behavior when using multiple threads. The AWT color space code is not thread safe. You'd have to synchronize color space access too.
    (To be honest, I'm not sure I understand what you're doing. You have two threads rendering on the same canvas/image? What is the benefit of doing this? And how do you divide up work between the threads?)

    Last edit: Elfi Heck 2014-03-21
  • Peter M

    Peter M - 2014-03-21

    The reason I want to use two threads. Is because I am optimizing on a scrolled canvas. When the uses changes the state e.g. scroll's/zoom/rotate/string searching the scrolled canvas is in need of images as fast as possible. Using two threads for rendering I can spped up the process a little when having multiple cores.
    To divide up work between threads I have a a single queue containing pending work, whenever a thread is ready it pull's new work form the queue. You can test a pre-release here using a single thread for rendering only:

    (runs on a 32-bit jvm)

    Best, Peter

  • mtraut

    mtraut - 2014-03-21

    Accessing the freetype slots is not threadsafe and therefore in the current code already synchronized. So either you are not on the current version or we have another, not yet known problem. Do you have some (swallowed) exceptions? Do you use an interpreter of its own for each thread? Some other context information? Did you try to debug into the text rendering code?

    In any case, rendering is not designed to be threadsafe, so there may be some leaks.

    And, as Elfi said, there are other data structures involved that too are not thread safe, so be prepared for more artifacts to appear.

  • Peter M

    Peter M - 2014-03-21

    Thank you both.

    I have tried a single interpreter shared between two threads and with two interpreters one for each thread. The result is the same - missing characters/fonts. I am using the current version of your library.

    I am using text-rendering (CSTextDevice, CSCharacterParser) in one thread and image-rendering (CSPlatformRenderer) in another thread. This works fine. Hence, I must assume it has something to do with the fonts. No, I have not tried to debug into the rendering code. But I will try. Thanks a lot.

    Best, Peter


Log in to post a comment.