• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <jni.h>
15 
16 #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 
24 extern "C" JNIEXPORT jboolean JNICALL
Java_android_opengl2_cts_reference_GLGameActivity_startBenchmark(JNIEnv * env,jclass,jobject assetManager,jobject surface,jint numFrames,jdoubleArray setUpTimes,jdoubleArray updateTimes,jdoubleArray renderTimes)25 Java_android_opengl2_cts_reference_GLGameActivity_startBenchmark(
26     JNIEnv* env, jclass /*clazz*/, jobject assetManager, jobject surface, jint numFrames,
27         jdoubleArray setUpTimes, jdoubleArray updateTimes, jdoubleArray renderTimes) {
28 
29     GLUtils::setEnvAndAssetManager(env, assetManager);
30 
31     if (numFrames > (ReferenceRenderer::FRAMES_PER_SCENE * ReferenceRenderer::NUM_SCENES)) {
32         return false;
33     }
34 
35     ANativeWindow* nativeWindow = ANativeWindow_fromSurface(env, surface);
36     ReferenceRenderer* renderer = new ReferenceRenderer(nativeWindow);
37     bool success = renderer->eglSetUp();
38     success = renderer->setUp(0) && success;
39     env->SetDoubleArrayRegion(
40             setUpTimes, 0, ReferenceRenderer::NUM_SETUP_TIMES, renderer->mSetUpTimes);
41 
42     double updates[numFrames];
43     double renders[numFrames];
44     for (int i = 0; i < numFrames && success; i++) {
45         double t0 = GLUtils::currentTimeMillis();
46         success = renderer->update(i);
47         double t1 = GLUtils::currentTimeMillis();
48         success = success && renderer->draw();
49         double t2 = GLUtils::currentTimeMillis();
50         updates[i] = t1 - t0;
51         renders[i] = t2 - t1;
52     }
53 
54     env->SetDoubleArrayRegion(updateTimes, 0, numFrames, updates);
55     env->SetDoubleArrayRegion(renderTimes, 0, numFrames, renders);
56 
57     success = renderer->tearDown() && success;
58     renderer->eglTearDown();
59     delete renderer;
60     renderer = NULL;
61 
62     ANativeWindow_release(nativeWindow);
63 
64     return success;
65 }
66