Frames per scond

All your problems with Audio, Video and Images.

Frames per scond

Postby Ghost » Wed Feb 16, 2011 9:12 am

Hi, I have been drawing on canvas and after writing a Timer class to count FPS, I've noticed that FPS on emulator is ~14 - 20, and on phone it's ~60 - 80. Is it normal? (Phone is xperia x10 mini pro). And why does FPS keep jumping from 60 to 80? All I do is clean canvas to white, draw circle and text showing FPS.

Code looks like this:
Code: Select all
   public void run() {
      Canvas c;
      long nTime = 0;
      int nFrames = 0;
      int nCurrFrames = 0;
      while (m_bRunning) {
         nTime += m_Timer.getTimeDelta();
         nFrames++;
         c = null;
         try {
            c = m_SurfaceHolder.lockCanvas(null);
            synchronized (m_SurfaceHolder) {
               //m_MainView.onDraw(c);
               Paint paint = new Paint();
               paint.setColor(Color.CYAN);
               c.drawColor(Color.WHITE);
               if (nTime >= 1000) {
                  nCurrFrames = nFrames;
                  nTime = 0;
                  nFrames = 0;
               }
               c.drawText("" + nCurrFrames, 120, 120, paint);
               c.drawCircle(100, 100, 10, paint);
            }
         }
         finally {
            m_SurfaceHolder.unlockCanvasAndPost(c);
         }
      }
   }

m_Timer.getTimeDelta() returns time in milliseconds since last call to this method.
If there are ways to speed up this, plase tell me ;)

Thank you,
Martin
Ghost
Developer
Developer
 
Posts: 26
Joined: Fri Feb 11, 2011 2:50 pm

Top

Re: Frames per scond

Postby imbroken » Thu Feb 17, 2011 10:08 pm

maybe you should reuse your paint object instead creating several in the while loop.
imbroken
Senior Developer
Senior Developer
 
Posts: 131
Joined: Thu Jan 06, 2011 6:57 pm
Location: Germnay

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Exabot [Bot] and 11 guests