Path Drawing Performance
Hi Moagrius,
Thanks for your contributions to this library. Much appreciated!
I'm currently working on an app that requires a number of paths to be drawn using TileView. At the moment panning performance is good, however as soon as I zoom and have to redraw the paths I get pretty bad performance.
Can you suggest a work around for this?
I think I need to draw the paths off the UI thread. I was thinking of using a SurfaceView and adding it to the TileView view group like suggested in issue 132. Do you think this approach would be appropriate.
Thanks,
Martin
Hey Martin,
I feel your pain - in my experience, line drawing is either A) horribly non-performant or B) ugly. Have you seen this wiki page? https://github.com/moagrius/TileView/wiki/Paths
As you can tell, I have not ended up with a great solution. You could compute the paths off the UI thread, but IIUC you must draw them on the UI thread.
If drawLines is not an option, I'd probably resort to drawing my own Bitmap and overlaying it manually - not an easy fix, and one that's not guaranteed to perform better, but you might be able to get away with some tricks on a drawing surface that are not immediately available in the existing path drawing API.
Post back if you find something that you think works well.
Hey Moagrius,
I wanted to post to let you know I think I have come up with a solution to overlaying paths and still get the performance I am looking for.
Basically I've stopped using the TileView path manager and instead I've overlayed a second transparent TileView over my current one. I render the paths using a canvas, process the Bitmap so its divided into appropriate segments and then let TileView display this. If I want to render a different set of Paths I just quickly re-render the Bitmap and repeat.
Anyway, there is one problem however. I'm passing all touch events from the top TileView to the background one. They scale in sync, that is all fine. However when the background TileView zooms in it doesn't seem to be picking up the higher res images.
Can you point me at what triggers these to be picked up or suggest a solution?
Ill post some pictures when I'm finished if your interested :)
Thanks, Martin
I'm definitely interested in seeing what you've put together. I also wonder if it might be easier to just draw the paths directly onto the tiles you're rendering, with a custom BitmapProvider (known as BitmapDecoder in the previous version... are you aware version 2 has been released since your original post?)
to answer your question directly, the tile set is selected by DetailManager.getDetailLevelForScale https://github.com/moagrius/TileView/blob/master/tileview/src/main/java/com/qozix/tileview/detail/DetailLevelManager.java#L158
Note that it will search the list of detail levels registered, starting from the largest and working it's way down. when it finds a detail level with a scale less than the current scale, it then picks the one immediately before it (so it always finds the smallest level that is larger than the current scale, so tiles should only scale larger than 100% if a detail level is not available, generally when going above 1f).
LMK if that makes sense. Also, check out version 2 - the API isn't drastically changed but it's more performant generally, and might be easier to hook into (e.g., addScalingViewGroup might be interesting for what you're doing).
Hey Moagrius,
Thanks for the reply. This turned out to be extremely useful! I've shelved the part of the implementation I was working on in favor of the BitmapDecoder approach (I've picked this project up from someone, the code base was pretty extensive so I am still getting familiar with aspects of the framework).
I've kept my overlay rendering class and utility I built to chop the bitmaps up for use in TileView. When I open an activity that contains TileView I kick off my renderer. From here my custom BitmapDecoder basically goes through these steps.
I'm now getting excellent performance now even with the hundreds or so paths since they are all pre-rendered.
One last question however. When I pan across TileView, tiles only render when we stop panning. At the moment I am using a placeholder image as my downsample so there is still something the user can see.
Is it possible to disable this "only load when not scrolling" or is performance just terrible? If so could you point me to where I could do this? My actually full scale images are not ridiculously massive so I was wondering if this could be an option.
Edit: Forgot to add. I noticed there was massive updates in v2 - thanks for pointing this out. At the moment the amount of time required to move over to this is massive considering what we have built already against v1. It is definitely something I plan to do in the future though.
Thanks again,
Martin
The tile provider approach sounds like a good way to go, glad you got that worked out.
In version 1, there's a method in TileView called onDrag, which calls suppressRender - this is what prevents tiles from rendering while dragging happens.
FWIW, version 2 will render while panning out of the box, and instead listens for scroll change - so as long as scroll changes within 100ms of last check, it won't render, but it doesn't actually suppress during drag (you can have your finger down and stop or move very slowly and get tiles to render).
Also, you're going to get much better performance in version 2 - tiles were ImageViews in version 1, now they're just bitmaps put in 1 view per detail level - that change by itself greatly increased performance. Most of the API is similar, and hopefully it wouldn't take too long to convert.
good luck!
Hi Moagrius,
I've decided that the performance benefits of moving to version 2 is probably worth the work, and there is going to be a lot of it I'm sure!
I noticed that version 2 seems to have lost the downsample functionality? Is this the case?
There is a massive amount of path drawing code built around v1 that is going to break. Is moving to v2 so I want to make sure I'm not loosing this before I have to rewrite all my old implementation.
Cheers, Martin
Hey Martin,
Sounds good - post back when you've got something. There's nothing you can do in v1 that you can't do in v2, but the downsample paradigm no longer has it's own API or special manager, etc. The wiki shows how to get the same effect using an ImageView, here: https://github.com/moagrius/TileView#add-a-down-sampled-image-beneath-the-tile-layer
HTH
Doh! Don't know how I missed that. Thanks for pointing it out :+1:
I have v2 running very simply without the overlay. I actually got to this stage quicker than expected. Performance seems much better! Looking forward to getting the overlay going.
:+1:
I managed to have very good performance with a different approach in CompositePathView. Instead of rendering a Path in the Canvas, i used the Canvas.drawLines. See :
http://stackoverflow.com/questions/15039829/drawing-paths-and-hardware-acceleration
To get a "smooth" path, i added those two preperties to the paint : Paint.setStrokeJoin(Paint.Join.ROUND); Paint.setStrokeCap(Paint.Cap.ROUND);
Even with all points selected in the RealMapTileViewActivity, the zoom keeps being perfectly smooth.

If you are interested i can make a pull request.
Thanks for posting - yes, drawLines is much more performant, but does not offer as many options as drawPath (you can see that was my first suggestion to the OP: https://github.com/moagrius/TileView/issues/199#issuecomment-142410337). I may extend the API to allow drawLines, but I don't want to replace it - drawPath with small paths works well and looks great.
Ok then - drawLines is not an option to me, because i will render the path from a GPX record, which may contain hundreds of points.
yeah specific needs might require custom solutions, as the OP found as well
Nice job btw with this api. I will try to use it for my app, and the path issue was the last holding me. I still have some small issues to report, but we will see later ;)
glad to hear it, thank you
hi @peterLaurence, I have try the Canvas.drawLines but the path/line does not draw out. Can you demo to me your method how to implement the method to draw the path with good performance in tileView?
@FrancisORB I need to publish my changes in a new branch in my fork of TileView. Let me know if you are still interested (so i have at least one reason to do it ;)
@peterLaurence Thank for your reply, I have solved my problem.