blob: 145fb75b3d7ade72e0511c3918e9f55f18380465 [file] [log] [blame]
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.android.pts.opengl.reference;
import com.android.pts.opengl.GLActivityIntentKeys;
import com.android.pts.opengl.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import java.util.HashMap;
import java.util.concurrent.Semaphore;
public class GLReferenceActivity extends Activity {
private final static int GAME_ACTIVITY_CODE = 1;
private int mNumFrames;
private int mTimeout;
public boolean mSuccess = false;
public double mUILoadTime;
public double[] mSetUpTimes;
public double[] mUpdateTimes;
public double[] mRenderTimes;
private Semaphore mSemaphore = new Semaphore(0);
@Override
public void onCreate(Bundle data) {
super.onCreate(data);
Intent intent = getIntent();
mNumFrames = intent.getIntExtra(GLActivityIntentKeys.INTENT_EXTRA_NUM_FRAMES, 0);
mTimeout = intent.getIntExtra(GLActivityIntentKeys.INTENT_EXTRA_TIMEOUT, 0);
double start = System.currentTimeMillis();
setContentView(R.layout.main);
mUILoadTime = System.currentTimeMillis() - start;
// Start benchmark
intent = new Intent(this, GLGameActivity.class);
intent.putExtra(GLActivityIntentKeys.INTENT_EXTRA_NUM_FRAMES, mNumFrames);
intent.putExtra(GLActivityIntentKeys.INTENT_EXTRA_TIMEOUT, mTimeout);
startActivityForResult(intent, GAME_ACTIVITY_CODE);
}
public void waitForCompletion() throws Exception {
// Wait for semiphore.
mSemaphore.acquire();
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == GAME_ACTIVITY_CODE) {
if (resultCode == RESULT_OK) {
// Benchmark passed
mSuccess = true;
mSetUpTimes = data.getDoubleArrayExtra(GLGameActivity.SET_UP_TIME);
mUpdateTimes = data.getDoubleArrayExtra(GLGameActivity.UPDATE_TIMES);
mRenderTimes = data.getDoubleArrayExtra(GLGameActivity.RENDER_TIMES);
}
// Release semiphore.
mSemaphore.release();
}
}
}