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 waitForGlPlanetsCompletionWithTimeout(long timeoutInSecs)49 public boolean waitForGlPlanetsCompletionWithTimeout(long timeoutInSecs) 50 throws InterruptedException { 51 return mSem.tryAcquire(timeoutInSecs, TimeUnit.SECONDS); 52 } 53 getAverageFps()54 public float getAverageFps() { 55 return mAverageFps; 56 } 57 getNumTriangles()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 */ getFrameInterval()67 public int[] getFrameInterval() { 68 return mFrameInterval; 69 } 70 71 @Override onCreate(Bundle savedInstanceState)72 public void onCreate(Bundle savedInstanceState) { 73 super.onCreate(savedInstanceState); 74 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 75 Intent intent = getIntent(); 76 PlanetsRenderingParam param = new PlanetsRenderingParam(); 77 param.mNumPlanets = intent.getIntExtra(INTENT_EXTRA_NUM_PLANETS, param.mNumPlanets); 78 param.mUseVboForVertices = intent.getBooleanExtra(INTENT_EXTRA_USE_VBO_VERTICES, 79 param.mUseVboForVertices); 80 param.mUseVboForIndices = intent.getBooleanExtra(INTENT_EXTRA_USE_VBO_INDICES, 81 param.mUseVboForIndices); 82 param.mNumFrames = intent.getIntExtra(INTENT_EXTRA_NUM_FRAMES, param.mNumFrames); 83 param.mNumIndicesPerVertex = intent.getIntExtra(INTENT_EXTRA_NUM_INDEX_BUFFERS, 84 param.mNumIndicesPerVertex); 85 mView = new PlanetsSurfaceView(this, param, this); 86 setContentView(mView); 87 } 88 89 @Override onRenderCompletion(float averageFps, int numTriangles, int[] frameInterval)90 public void onRenderCompletion(float averageFps, int numTriangles, int[] frameInterval) { 91 mAverageFps = averageFps; 92 mNumTriangles = numTriangles; 93 mFrameInterval = frameInterval; 94 mSem.release(); 95 } 96 97 @Override onResume()98 protected void onResume() { 99 super.onResume(); 100 mView.onResume(); 101 } 102 103 @Override onPause()104 protected void onPause() { 105 super.onPause(); 106 mView.onPause(); 107 } 108 }