blob: 18578481af741d99f3abbf3112206dd138f198dd [file] [log] [blame]
Stuart Scott4d9520f2013-03-25 15:05:36 -07001/*
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 */
Stuart Scott0a312e22013-04-03 13:48:08 -070014#include <jni.h>
Stuart Scott4d9520f2013-03-25 15:05:36 -070015
Stuart Scottc67f78d2013-04-08 13:11:04 -070016#include <android/native_window.h>
17#include <android/native_window_jni.h>
18
19#include <graphics/GLUtils.h>
20#include <graphics/Renderer.h>
21
22#include "ReferenceRenderer.h"
23
Stuart Scott0a312e22013-04-03 13:48:08 -070024extern "C" JNIEXPORT jboolean JNICALL
Stuart Scotta132af62013-11-07 10:30:32 -080025Java_com_android_cts_opengl_reference_GLGameActivity_startBenchmark(
Stuart Scott82786f42013-04-12 13:16:28 -070026 JNIEnv* env, jclass clazz, jobject assetManager, jobject surface, jint numFrames,
Stuart Scott0a312e22013-04-03 13:48:08 -070027 jdoubleArray setUpTimes, jdoubleArray updateTimes, jdoubleArray renderTimes) {
Stuart Scottc67f78d2013-04-08 13:11:04 -070028
Stuart Scott82786f42013-04-12 13:16:28 -070029 GLUtils::setEnvAndAssetManager(env, assetManager);
30
Stuart Scottc67f78d2013-04-08 13:11:04 -070031 if (numFrames > (ReferenceRenderer::FRAMES_PER_SCENE * ReferenceRenderer::NUM_SCENES)) {
32 return false;
33 }
34
Stuart Scott82786f42013-04-12 13:16:28 -070035 ReferenceRenderer* renderer = new ReferenceRenderer(ANativeWindow_fromSurface(env, surface));
Stuart Scottc67f78d2013-04-08 13:11:04 -070036
Stuart Scott82786f42013-04-12 13:16:28 -070037 bool success = renderer->setUp();
Stuart Scottc67f78d2013-04-08 13:11:04 -070038 env->SetDoubleArrayRegion(
Stuart Scott82786f42013-04-12 13:16:28 -070039 setUpTimes, 0, ReferenceRenderer::NUM_SETUP_TIMES, renderer->mSetUpTimes);
Stuart Scottc67f78d2013-04-08 13:11:04 -070040
41 double updates[numFrames];
42 double renders[numFrames];
43 for (int i = 0; i < numFrames && success; i++) {
44 double t0 = GLUtils::currentTimeMillis();
Stuart Scott82786f42013-04-12 13:16:28 -070045 success = renderer->update(i);
Stuart Scottc67f78d2013-04-08 13:11:04 -070046 double t1 = GLUtils::currentTimeMillis();
Stuart Scott82786f42013-04-12 13:16:28 -070047 success = success && renderer->draw();
Stuart Scottc67f78d2013-04-08 13:11:04 -070048 double t2 = GLUtils::currentTimeMillis();
49 updates[i] = t1 - t0;
50 renders[i] = t2 - t1;
51 }
52
53 env->SetDoubleArrayRegion(updateTimes, 0, numFrames, updates);
54 env->SetDoubleArrayRegion(renderTimes, 0, numFrames, renders);
55
Stuart Scott82786f42013-04-12 13:16:28 -070056 success = renderer->tearDown() && success;
57 delete renderer;
58 renderer = NULL;
Stuart Scottc67f78d2013-04-08 13:11:04 -070059 return success;
Stuart Scott0a312e22013-04-03 13:48:08 -070060}