1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 package android.opengl2.cts.reference; 15 16 import android.app.Activity; 17 import android.content.Intent; 18 import android.opengl2.cts.GLActivityIntentKeys; 19 import android.os.Bundle; 20 21 import java.util.concurrent.Semaphore; 22 23 public class GLReferenceActivity extends Activity { 24 25 private final static int GAME_ACTIVITY_CODE = 1; 26 27 private volatile Exception mException; 28 private int mNumFrames; 29 private int mTimeout; 30 31 public double[] mSetUpTimes; 32 public double[] mUpdateTimes; 33 public double[] mRenderTimes; 34 35 private Semaphore mSemaphore = new Semaphore(0); 36 37 @Override onCreate(Bundle data)38 public void onCreate(Bundle data) { 39 super.onCreate(data); 40 Intent intent = getIntent(); 41 mNumFrames = intent.getIntExtra(GLActivityIntentKeys.INTENT_EXTRA_NUM_FRAMES, 0); 42 mTimeout = intent.getIntExtra(GLActivityIntentKeys.INTENT_EXTRA_TIMEOUT, 0); 43 44 // Start benchmark 45 intent = new Intent(this, GLGameActivity.class); 46 intent.putExtra(GLActivityIntentKeys.INTENT_EXTRA_NUM_FRAMES, mNumFrames); 47 intent.putExtra(GLActivityIntentKeys.INTENT_EXTRA_TIMEOUT, mTimeout); 48 startActivityForResult(intent, GAME_ACTIVITY_CODE); 49 } 50 waitForCompletion()51 public void waitForCompletion() throws Exception { 52 // Wait for semiphore. 53 mSemaphore.acquire(); 54 if (mException != null) { 55 throw mException; 56 } 57 } 58 setException(Exception e)59 private synchronized void setException(Exception e) { 60 if (mException == null) { 61 mException = e; 62 } 63 } 64 onActivityResult(int requestCode, int resultCode, Intent data)65 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 66 if (requestCode == GAME_ACTIVITY_CODE) { 67 if (resultCode == RESULT_OK) { 68 // Benchmark passed 69 mSetUpTimes = data.getDoubleArrayExtra(GLGameActivity.SET_UP_TIME); 70 mUpdateTimes = data.getDoubleArrayExtra(GLGameActivity.UPDATE_TIMES); 71 mRenderTimes = data.getDoubleArrayExtra(GLGameActivity.RENDER_TIMES); 72 } else { 73 setException(new Exception("Benchmark failed to run")); 74 } 75 // Release semiphore. 76 mSemaphore.release(); 77 finish(); 78 } 79 } 80 81 } 82