android - Drawing multiple lines on canvas with paint with shader cause performance issues -


inside surfaceview in separate thread on canvas draw ~50 bezier curves paint been set have gradient in following code:

lineargradient gradient = new lineargradient(0, 0, 0, height, color.black, color.white, shader.tilemode.mirror); paint.setshader(gradient);

setting shader paint causes serious performance issues - view starts lagging. if comment out setting shader paint works brilliant, issue in gradient.

thread code:

private class drawingrunnable implements runnable {      private final surfaceholder surfaceholder;     private final myview surfaceview;      public drawingrunnable(surfaceholder surfaceholder, myview surfaceview) {         this.surfaceholder = surfaceholder;         this.surfaceview = surfaceview;     }      @override     public void run() {         while (isrunning) {              canvas canvas = null;             try {                 canvas = surfaceholder.lockcanvas(null);                  if (canvas != null) {                     canvas.drawcolor(color.transparent, porterduff.mode.clear);                     synchronized (surfaceholder) {                         surfaceview.drawmyheavyview(canvas);                     }                 }             } catch (throwable e) {                 timber.w(e, "error occurred while drawing surface view");             } {                 if (canvas != null) {                     surfaceholder.unlockcanvasandpost(canvas);                 }             }         }     } } 

drawing on canvas:

protected void drawmyheavyview(canvas canvas) {      (int index = 0; index < 50; index++) {          path.reset();         path.moveto(x1, y1);          modifysomeamplituderandomvalues(index);          path.quadto(x3, amplitude[index], x2, y2);          canvas.drawpath(path, paint);     } } 

you should assume unknown params (e.g. x1, y1, x2, etc.) parts of view business logic , aren't valuable current duscussion.

can please advise what's wrong?

p.s.: i'm not allocating lineargradient in ondraw or so.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -