Home | History | Annotate | Download | only in reference
      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
     25 Java_com_android_pts_opengl_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     ReferenceRenderer* renderer = new ReferenceRenderer(ANativeWindow_fromSurface(env, surface));
     36 
     37     bool success = renderer->setUp();
     38     env->SetDoubleArrayRegion(
     39             setUpTimes, 0, ReferenceRenderer::NUM_SETUP_TIMES, renderer->mSetUpTimes);
     40 
     41     double updates[numFrames];
     42     double renders[numFrames];
     43     for (int i = 0; i < numFrames && success; i++) {
     44         double t0 = GLUtils::currentTimeMillis();
     45         success = renderer->update(i);
     46         double t1 = GLUtils::currentTimeMillis();
     47         success = success && renderer->draw();
     48         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 
     56     success = renderer->tearDown() && success;
     57     delete renderer;
     58     renderer = NULL;
     59     return success;
     60 }
     61