Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.openglperf.cts;
     18 
     19 import android.app.Activity;
     20 import android.content.Intent;
     21 import android.os.Bundle;
     22 import android.view.WindowManager;
     23 
     24 import java.util.concurrent.Semaphore;
     25 import java.util.concurrent.TimeUnit;
     26 
     27 /**
     28  * Activity which runs GL test and measure FPS with given parameters passed from
     29  * Intent. For the meaning of parameters, check {@PlanetsRenderingParam}
     30  */
     31 public class GlPlanetsActivity extends Activity implements
     32         RenderCompletionListener {
     33     public static final String INTENT_EXTRA_NUM_PLANETS = "numPlanets";
     34     public static final String INTENT_EXTRA_USE_VBO_VERTICES = "useVboVertices";
     35     public static final String INTENT_EXTRA_USE_VBO_INDICES = "useVboIndiices";
     36     public static final String INTENT_EXTRA_NUM_FRAMES = "numFrames";
     37     public static final String INTENT_EXTRA_NUM_INDEX_BUFFERS = "numIndexBuffers";
     38 
     39     public static final String INTENT_RESULT_FPS = "fps";
     40     public static final String INTENT_RESULT_NUM_TRIANGLES = "numTrigngles";
     41 
     42     private final Semaphore mSem = new Semaphore(0);
     43     private float mAverageFps;
     44     private int mNumTriangles;
     45     private int[] mFrameInterval;
     46 
     47     private PlanetsSurfaceView mView;
     48 
     49     public boolean waitForGlPlanetsCompletionWithTimeout(long timeoutInSecs)
     50             throws InterruptedException {
     51         return mSem.tryAcquire(timeoutInSecs, TimeUnit.SECONDS);
     52     }
     53 
     54     public float getAverageFps() {
     55         return mAverageFps;
     56     }
     57 
     58     public int getNumTriangles() {
     59         return mNumTriangles;
     60     }
     61 
     62     /**
     63      * Time interval between each frame's rendering in ms.
     64      * The first value will be invalid, so client should discard them.
     65      * @return can return null if INTENT_EXTRA_NUM_FRAMES was not set in intent.
     66      */
     67     public int[] getFrameInterval() {
     68         return mFrameInterval;
     69     }
     70 
     71     @Override
     72     public void onCreate(Bundle savedInstanceState) {
     73         super.onCreate(savedInstanceState);
     74         getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
     75                 | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
     76                 | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
     77         Intent intent = getIntent();
     78         PlanetsRenderingParam param = new PlanetsRenderingParam();
     79         param.mNumPlanets = intent.getIntExtra(INTENT_EXTRA_NUM_PLANETS, param.mNumPlanets);
     80         param.mUseVboForVertices = intent.getBooleanExtra(INTENT_EXTRA_USE_VBO_VERTICES,
     81                 param.mUseVboForVertices);
     82         param.mUseVboForIndices = intent.getBooleanExtra(INTENT_EXTRA_USE_VBO_INDICES,
     83                 param.mUseVboForIndices);
     84         param.mNumFrames = intent.getIntExtra(INTENT_EXTRA_NUM_FRAMES, param.mNumFrames);
     85         param.mNumIndicesPerVertex = intent.getIntExtra(INTENT_EXTRA_NUM_INDEX_BUFFERS,
     86                 param.mNumIndicesPerVertex);
     87         mView = new PlanetsSurfaceView(this, param, this);
     88         setContentView(mView);
     89     }
     90 
     91     @Override
     92     public void onRenderCompletion(float averageFps, int numTriangles,  int[] frameInterval) {
     93         mAverageFps = averageFps;
     94         mNumTriangles = numTriangles;
     95         mFrameInterval = frameInterval;
     96         mSem.release();
     97     }
     98 
     99     @Override
    100     protected void onResume() {
    101         super.onResume();
    102         mView.onResume();
    103     }
    104 
    105     @Override
    106     protected void onPause() {
    107         super.onPause();
    108         mView.onPause();
    109     }
    110 }
    111