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: 503
Last edited:

sorex

Expert
Licensed User
Longtime 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
Longtime 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
Longtime 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
Longtime 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
Longtime 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
Longtime User
I went back to the old method. I needed too much trickery to get it working right.
 

ilan

Expert
Licensed User
Longtime 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.
 

ilan

Expert
Licensed User
Longtime User
hi, this is an old thread but i have to ask the question (sorry).
i have an old game where i use Acclerated Surface and i just wanted to update it but i am not able to build the app that worked fine in the past.
i am using the v1.12 and i also see that there was no update to this lib in the last 7 years.

my question is do i need to re-write everything again without using AS lib or could there be a fix for my error?


java.lang.NoClassDefFoundError: Failed resolution of: Lflm/b4a/accelerview/AcceleratedCanvas;
at java.lang.reflect.Executable.getParameterTypesInternal(Native Method)
at java.lang.reflect.Method.getParameterTypes(Method.java:186)
at java.lang.Class.getDeclaredMethods(Class.java:1884)
at anywheresoftware.b4a.BA.loadHtSubs(BA.java:522)
at www.sagital.paratr.game.onCreate(game.java:38)
at android.app.Activity.performCreate(Activity.java:7994)
at android.app.Activity.performCreate(Activity.java:7978)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.ClassNotFoundException: flm.b4a.accelerview.AcceleratedCanvas
... 20 more

thanx :)
 
Last edited:

ilan

Expert
Licensed User
Longtime User
thanx for checking fred. i don't know why it's not working. i tried another game i made long time ago using Accelerated Surface and it also throws the same error.
i will have a closer look on it. thanx 🙏
 

ilan

Expert
Licensed User
Longtime User
ps: i use Android 12 and B4a v11.80 (64 bit)
 

ilan

Expert
Licensed User
Longtime User
ok, after making many tests i can confirm.
Accelerated Surface works fine with b4a 11.2 and Android 12 but above b4a 11.2 i get this crash. so it is not related to the android version, it is related to b4a version. :oops:
(the included examples crash too when using b4a version bigger then v11.2)
 

ilan

Expert
Licensed User
Longtime User
I've just tried a couple of the demos included with version 1.12 and they work fine for me with B4A 11.80 and a Pixel 4a with Android 12.
have you tried example: AcceleratedSurface.b4a ?
 

redbeardrob

Member
Licensed User
Longtime User
I don't see a way in the library to draw a bitmap rotated(or with matrix) with a srcRect, to choose which tile from a sprite sheet to draw. Is there a way to do this with this library?
 
Top