After update openfl and lime version,android FPS is lower than before

after i update openfl and lime version,android FPS is low than before.

int the old version( openfl=3.6.1 ,lime=2.9.1, hxcpp=3.2.212,ndk-r8b,Android Target Api=22 , legacy mode),in android platform,the fps is fast(stable or switching page alway is 60)

but,when i upgrade the newest version(openfl=4.7.3 ,lime=3.7.2,ndk-r13b-64bit, Android Target Api=23 ,next mode),in android platform,the fps is slow(stable is 60,switching page is30~40)

how to improve the performance of new version?
(I using the stablexui).

and i found that ,in the legacy mode:

class MainView extends GLSurfaceView {

this View is using GLSurfaceView .

but in the next mode,

class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
    View.OnKeyListener, View.OnTouchListener, SensorEventListener  {

the view is using SurfaceView.

is this reason?

in the next mode.

var type:String = NativeCFFI.lime_renderer_get_type (handle);
		
		haxe.Log.trace("@create type=" + type);
		
		
		switch (type) {
			
			case "opengl":
				
				var context = new GLRenderContext ();
				
				useHardware = true;
				parent.context = OPENGL (context);
				parent.type = OPENGL;
				
				if (GL.context == null) {
					
					GL.context = context;
					
				}
				haxe.Log.trace("@create using opengl ...");
			
			default:
				
				useHardware = false;
				
				#if lime_cairo
				render ();
				parent.context = CAIRO (cairo);
				#end
				parent.type = CAIRO;
			
		}

i add debug trace code,and the output is:

02-15 11:58:33.406 32661 32695 I trace : NativeRenderer.hx:70: @create type=opengl
02-15 11:58:33.406 32661 32695 I trace : NativeRenderer.hx:88: @create using opengl .

Do you know if you are using vector graphics? This is drawn in software, which is more costly on mobile than on the desktop. If your project uses them a lot, this could have an effect.

If you do, it also may be helpful to know if they are being scaled or rotated. This will cause it to be redrawn (though there is a define that can disable that behavior)

the src of bmp is png format,no vector graphics.but the image has scaled by runtime fixed number(depend on devices).the background using the ‘TiledSlice9’ skin of stablexui (http://ui.stablex.ru/doc/#ru/stablex/ui/skins/TiledSlice9.html).

I found the slow resion is:

private function _skinDrawSlice(w:Widget, bmp:BitmapData, src:Rectangle, dst:Rectangle) : Void {

        var mx : Matrix = new Matrix();
        mx.translate(-src.x, -src.y);
        mx.scale(dst.width / src.width, dst.height / src.height);
        mx.translate(dst.x, dst.y);

        w.graphics.beginBitmapFill(bmp, mx, false, this.smooth);
        w.graphics.drawRect(dst.x, dst.y, dst.width, dst.height);
        w.graphics.endFill();
    }

 w.graphics.beginBitmapFill(bmp, mx, false, this.smooth);  

using mx is very very slow!

I modify to

if (use_tile){
			
			if (tileset == null){
				tileset = new Tileset (bmp);
			}
			var t_tile_w = Math.round(w.w);
			var t_tile_h = Math.round(w.h);
			
			//haxe.Log.trace("@draw tile! w,h="+t_tile_w+","+t_tile_h);
			
			if (tilemap != null){
				if (t_tile_w != tile_w || t_tile_h != tile_h){
					if(tilemap.parent!=null){
						tilemap.parent.removeChild(tilemap);
					}
					tilemap = null;
				}
			} 
			
			if (tilemap == null){
				tile_w = t_tile_w;
				tile_h = t_tile_h;
				tilemap = new Tilemap(tile_w, tile_h, tileset, this.smooth);
				w.addChildAt(tilemap,0);//重要
				
			}
			while(tilemap.numTiles > 0){
				tilemap.removeTileAt(0);
			}
			var d = @:privateAccess tileset.__data;
			if (d.length > 0){
				@:privateAccess tileset.__data=[];
			}
		}
		
		var tile_i = -1;
        for (y in 0...(vTileCount+2)) {
          dst.x = 0;
          for (x in 0...(hTileCount+2)) {

            // Set the src rect
			
            var hSizeIndex = if (x == 0) {0;} else {if (x == hTileCount +1) {2;} else {1;}};
            var vSizeIndex = if (y == 0) {0;} else {if (y == vTileCount +1) {2;} else {1;}};
            src.x = srcRect.x + sum(hSizes.slice(0,hSizeIndex));
            src.y = srcRect.y + sum(vSizes.slice(0,vSizeIndex));
           

            // Set the distination width, based on the source width
           
			src.width = hSizes[hSizeIndex];
			src.height = vSizes[vSizeIndex];
			dst.width  = src.width  * scaleX;
			dst.height = src.height * scaleY;
				
			if (use_tile){
				tileset.addRect (src);
				tile_i++;
				var	tile = new openfl.display.Tile (tile_i, dst.x, dst.y, (dst.width + 2) / src.width, (dst.height + 2) / src.height);
				tilemap.addTile (tile);
			}else{
				
				this._skinDrawSlice(w, bmp, src, dst);
			
			}
            // Update destination x position
            dst.x += dst.width;
          }
          // Update destination y position
          dst.y += dst.height;
        }

and also midify the by the similar code.


the FPS is up to 60~80!

1 Like

Nice!

Yes, the graphics code uses a software renderer, which is expensive on mobile devices. Tilemap should behave much better :slight_smile: