B4A Library [Lib] Accelerated surface

This library provides a dedicated drawing surface embedded inside a view, which benefits from the hardware acceleration. With it, you get the speed of OpenGL for 2D without the complexity.
It includes many Canvas methods (with anti-aliasing, matrix and camera) and a few useful methods for Bitmaps and Drawables (AlterColors, Crop, LoadNinePatch, ReduceColors, SetDensity, etc.). You can import the Matrix, Camera, Paint and Path objects from another library (if they are not wrapped).

surface.png

imageviews.jpg


You can use it to make games:

princess_tiles.png

space_enemies.png


It includes a tool (TextFactory) to do nice titles (that you can export to a bitmap):

textfactory.jpg


It supports Porter-Duff modes, color filters and texture blending (the processing time is very fast):

pdmodes.jpg


The archive includes four benchmarks:

Perf.png


Because of my lack of (free) time, don't expect answers from me about this library if you're not one of my donors.

Download the latest version (1.12)
To convert a project from v0.9x to v1.x, read this.

Hints & Tips

This library does not work with Android versions < 2 (Eclair and Froyo may exhibit performance problems, so I recommend only Gingerbread or a newer version for animations with a high FPS).
The hardware acceleration is not enabled with Android versions < 3.
 

Attachments

  • Java source - AcceleratedSurface.zip
    21.3 KB · Views: 305
Last edited:

sorex

Expert
Licensed User
is there a way to know in the redraw callback which acc. surface object is the parent of the acc. bitmap?

I want to visualize a small average over time so I need to copy the previous 1px to the left and then draw my new vertical line.

But there's no copy method only drawbitmap & drawbitmap at but I can't seem to fetch the bitmap of the current acc. bitmap that calls the redraw.
 

Informatix

Expert
Licensed User
is there a way to know in the redraw callback which acc. surface object is the parent of the acc. bitmap?
I'm not sure to understand the question.

I want to visualize a small average over time so I need to copy the previous 1px to the left and then draw my new vertical line.
But there's no copy method only drawbitmap & drawbitmap at but I can't seem to fetch the bitmap of the current acc. bitmap that calls the redraw.
Since the screen is cleared and everything is redrawn at each Draw event, I don't understand what a Copy function could do. Bitmaps don't exist as objects. You could save a screenshot of the current rendering (Acsf.bitmap), redraw it 1px to the left during the next Draw event, and repeat the operation, but I'm afraid that would be horribly slow and not really usable.
If you want to draw a kind of line chart updated each frame, store each value to be drawn in a list (adding each new value to the list in the Update event), then draw the contents of your list, from the first element to the current one.
 

sorex

Expert
Licensed User
actually it's multple strips (4) small of size (250x50 or so) where 'activity' is been shown.

it was working fine with normal bitmap drawing routines but this should be faster as it's been accelerated.

your list idea is what I was thinking of aswell. problem is these multiple objects. you don't have a clue which invalidate called the draw sub so you don't know which list you need to pick to draw the right data.
 

Informatix

Expert
Licensed User
your list idea is what I was thinking of aswell. problem is these multiple objects. you don't have a clue which invalidate called the draw sub so you don't know which list you need to pick to draw the right data.
I still don't understand. Do you mean that you have multiple AcceleratedSurface views? And a list of data to draw in each view? If yes, there's no possible confusion as each view raises its own event.
 

sorex

Expert
Licensed User
you're right, I can add a variable to the init. they now used the same one.

I'll give that a try tomorrow to see if I can make it work. a disadvantage is that you need to predict the maximum amount of subs that you need to create.

I'll keep you posted.
 

sorex

Expert
Licensed User
I went back to the old method. I needed too much trickery to get it working right.
 

ilan

Expert
Licensed User
???
I still have no idea what you're trying to do, so I can't help you.

I guess sorex has more the one ac object in his project. Like he has 4 panels of 25%x and 25%y and on each he is drawing something.

If this is true then it is not right to do it like this.

ACSurface or any other rendering engine like libgdx work with the same logic like using canvas and a timer.

You have a surface on your screen and u draw anything u want on it 60 times per second. So no need to use more then 1 acs.

But maybe i understood everything wrong.

It would be simpler to understand if we would have a video or images of what he is trying to do.
 
Top