Android Question Better Draw Performance

Scantech

Well-Known Member
Licensed User
Longtime User
I have 2 questions.

Which has a better performance on drawing? B4XRect or BitmapCreator DrawRect. Or are they the same?

I am really interested in faster drawing performance especially in Gradient area. My canvas draws 3 rect (using bitmapcreator) with gradient fill. 60 of them takes about 4 seconds to complete. Depending on device give or take second or two. The question for this is there anything faster than bitmapcreator in gradient area?

Thank you
 

emexes

Expert
Licensed User
JPEG choked on them too, so I halved the resolution and with a bit of luck...

Gauges60halved.jpg
Gauges15halved.jpg


tadaaa!
 
Upvote 0

emexes

Expert
Licensed User
This guy is at the opposite end of the get-the-job-done-vs-make-it-look-good spectrum to me:


Initially I thought he was using some add-in package, but, no, he's actually created gauges from scratch using just Excel.

Mind you, it took him two videos to get the job finished, and I didn't actually see the gauge needle move, but still... wow!
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

emexes

Expert
Licensed User
That's an incorrect assumption. B4XCanvas and Canvas behave exactly the same as they are based on the same APIs.
Well, I'm very glad I included the "probably" bit, then ;-) I did look at some B4X code, and all of the pixel-moving stuff that I recognised was done via the CPU, but I have no doubt that I could have missed the occasional call to the underlying OS/hardware. I'll fix up that comment above.
 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
Getting similar results out of memory using ImageView as background for Border1, Border2 and Background (complex Gradient Drawings). Added 10 to 12 (75y% x 100%x) gauges and crashed. Same as using Canvas. I can pursue further with the codes and add all the scales and labels as bitmap but i think it will result the same.

In my legacy Dashboard design, i had a background (with scales) and needle png (both small file size) eliminating most of the canvas drawing and it crashes with out of memory, too.

I guess i will keep it the original Klaus Design and rid of fancy borders and gradient. I think it will hold up and not crash. I will test it.

Update: Klaus original Design also crashes at 15 gauges. :(
 
Last edited:
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
I modified the DrawScale Event only. Its a bit messy. i did not have time to clean it up. Related to Analog Gauges. Digital Square/Circle is not modified. Test it by clicking 'Not Used' Button to add the large gauge.
 

Attachments

  • xGauges.zip
    74.5 KB · Views: 256
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
I modified the DrawScale Event only. Its a bit messy. i did not have time to clean it up. Related to Analog Gauges. Digital Square/Circle is not modified. Test it by clicking 'Not Used' Button to add the large gauge.
yes, after tapping this button to add more and more gauges there is a visible slow down,
i can see if me used the test slider.
 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
I think i over exaggerated about the app from Google Play. I added 24 (100%x) Gauges and threw an exception out of memory fault. It was slowing down the app, too. The good thing about it, the app did not close. Just the Gauges layout part closed.

I believe with heap memory in manifest, my app is able to hold up to 20. I will test it.

Erel stands correct as always. :)
 

Attachments

  • Gauges.png
    Gauges.png
    89.6 KB · Views: 225
Last edited:
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
i think the way you created this Gauges is not optimal. at release mode currently it get slow after 10+ gauges.

u waste a lot of memory, but u can see only one screen.
i would try one static background and one overlay with the animations.
 
Last edited:
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
i think the way you created this Gauges is not optimal. at release mode currently it get slow after 10+ gauges.

u waste a lot of memory, but u can see only one screen.
i would try one static background and one overlay with the animations.

The Design before this had 1 static background and overlay with animation. Similar result. Slow down will occur.
 
Upvote 0

emexes

Expert
Licensed User
Slow down will occur.

Mate, I got home this evening saw ^^^ and I'm like: challenge accepted!

Previously I've used a separate panel for each gauge, but both you and MarkusR referred to using "one static background and one overlay", which leaves me outvoted both quantitively and qualitively ;-) so I've given that method a go. Personally, I think the results aren't too shabby (performance-wise... presentation-wise, bear in mind that the background, dials and needles are all alpha-channeled BitMaps, so if you need fancy psuedo-reflective highlights or needles with eyeholes or whatever, that is no problem, I'm just too lazy to do it).

Starting easy, we have 16 gauges at a tad under 50 fps:

Screenshot_20190403-195528[1].png


then we crank it up a bit to your required 60 gauges and we're still buzzing along nicely

Screenshot_20190403-195541[1].png


and then we wonder: what happens if we go full-throttle... and we're still over 30 fps!

Screenshot_20190403-195549[1].png


although, admittedly, the total workload in pixel-count terms is probably not changing much, so we wouldn't expect the time taken per frame to change much either. And you'll be needing CPU time to do other stuff as well, so that will lower the fps, but... with 16 gauges taking somewhere between 12 and 21 ms to draw and get to the display, at 10 fps that leaves you 80% CPU left to do other stuff, and at 20 fps you've still got more than 50%. Plus that's from a single-core perspective.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
@emexes
great :)
give it also numbers and a prerenderd shapes as background :D
 
Upvote 0

emexes

Expert
Licensed User
@emexes
give it also numbers and a prerenderd shapes as background :D
You know that costs extra, right? ;-)

Or are you saying that there is some trap awaiting in displaying numbers? Like, the needle rotation is done in hardware by the GPU, but text display is slow?

Hmm.

I really don't want to, but...
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
My implementation:

SS-2019-04-03_13.43.46.png


It is based on BitmapCreator and it is cross platform.

I aim to draw at 30 FPS as the visual difference will be insignificant in this case.
The seekbar at the bottom does nothing. It is only used to show that the UI is responsive.
 

Attachments

  • 1.zip
    10.7 KB · Views: 218
Last edited:
Upvote 0
Top