Page 1 of 1

Preload large PNGs to reduce UI stutter?

Posted: 01 Sep 2021, 12:29
by MarkSim
When I open a view containing large PNGs, the UI pauses (the animations stutter) while they are loaded and processed. These particular PNGs are not specified in the XAML; the ImageSource can change so it is a bound value.

I've managed to reduce the problem to it only happening the first time I use any particular PNGs by caching the Ptr<BitmapImage> used by filename. So for a particular PNG, like "test1.png", the same Ptr<BitmapImage> will be returned. I'm guessing Noesis recognises this and uses its internal cache to get the PNG data previously loaded..

There is a point in the code where I could preload these images without any ill effect. Is there any way I can get Noesis to preload and preprocess the BitmapImage in code without having to do some horrible hack like rending all the files invisibly in a parent view?

I currently do bitmapImage->Init() when I cache it, which I can see calls the TextureProvider to get info like width and height ... if only there was a similar call to load and process the whole thing... Or to shell that processes out to a thread..?

Thanks!

Re: Preload large PNGs to reduce UI stutter?

Posted: 01 Sep 2021, 12:47
by jsantos
Are you implementing your own TextureProvider? Because that way you can preload whatever you may need. You can also load the texture in a different thread and once it it ready you can use the Reload mechanism available in that API.

Re: Preload large PNGs to reduce UI stutter?

Posted: 01 Sep 2021, 13:56
by MarkSim
Ah! Good point, I will give that a try. Thanks :-)

Re: Preload large PNGs to reduce UI stutter?

Posted: 02 Sep 2021, 19:17
by MarkSim
Is RaiseTextureChanged() thread safe? I mean - can I call it from my Worker Thread once it has finished loading? Or is it better to somehow signal the main thread to call it?

Re: Preload large PNGs to reduce UI stutter?

Posted: 03 Sep 2021, 13:06
by jsantos
It is not thread-safe. You need to invoke it from the main thread.