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 <stdlib.h> 17 18 #include <android/native_window.h> 19 #include <android/native_window_jni.h> 20 21 #include <graphics/GLUtils.h> 22 #include <graphics/Renderer.h> 23 24 #include "fullpipeline/FullPipelineRenderer.h" 25 #include "pixeloutput/PixelOutputRenderer.h" 26 #include "shaderperf/ShaderPerfRenderer.h" 27 #include "contextswitch/ContextSwitchRenderer.h" 28 29 // Holds the current benchmark's renderer. 30 Renderer* gRenderer = NULL; 31 32 extern "C" JNIEXPORT jboolean JNICALL 33 Java_com_android_cts_opengl_primitive_GLPrimitiveActivity_startBenchmark( 34 JNIEnv* env, jclass clazz, jint numFrames, jdoubleArray frameTimes) { 35 if (gRenderer == NULL) { 36 return false; 37 } 38 39 // Sets up the renderer. 40 bool success = gRenderer->setUp(); 41 42 // Records the start time. 43 double start = GLUtils::currentTimeMillis(); 44 45 // Offscreen renders 100 tiles per frame so reduce the number of frames to render. 46 if (gRenderer->mOffscreen) { 47 numFrames /= Renderer::OFFSCREEN_INNER_FRAMES; 48 } 49 50 // Draw off the screen. 51 for (int i = 0; i < numFrames && success; i++) { 52 // Draw a frame. 53 success = gRenderer->draw(); 54 } 55 56 // Records the end time. 57 double end = GLUtils::currentTimeMillis(); 58 59 // Sets the times in the Java array. 60 double times[] = {start, end}; 61 env->SetDoubleArrayRegion(frameTimes, 0, 2, times); 62 63 // Tears down and deletes the renderer. 64 success = gRenderer->tearDown() && success; 65 delete gRenderer; 66 gRenderer = NULL; 67 return success; 68 } 69 70 // The following functions create the renderers for the various benchmarks. 71 extern "C" JNIEXPORT void JNICALL 72 Java_com_android_cts_opengl_primitive_GLPrimitiveActivity_setupFullPipelineBenchmark( 73 JNIEnv* env, jclass clazz, jobject surface, jboolean offscreen, jint workload) { 74 gRenderer = new FullPipelineRenderer( 75 ANativeWindow_fromSurface(env, surface), offscreen, workload); 76 } 77 78 extern "C" JNIEXPORT void JNICALL 79 Java_com_android_cts_opengl_primitive_GLPrimitiveActivity_setupPixelOutputBenchmark( 80 JNIEnv* env, jclass clazz, jobject surface, jboolean offscreen, jint workload) { 81 gRenderer = new PixelOutputRenderer( 82 ANativeWindow_fromSurface(env, surface), offscreen, workload); 83 } 84 85 extern "C" JNIEXPORT void JNICALL 86 Java_com_android_cts_opengl_primitive_GLPrimitiveActivity_setupShaderPerfBenchmark( 87 JNIEnv* env, jclass clazz, jobject surface, jboolean offscreen, jint workload) { 88 gRenderer = new ShaderPerfRenderer( 89 ANativeWindow_fromSurface(env, surface), offscreen, workload); 90 } 91 92 extern "C" JNIEXPORT void JNICALL 93 Java_com_android_cts_opengl_primitive_GLPrimitiveActivity_setupContextSwitchBenchmark( 94 JNIEnv* env, jclass clazz, jobject surface, jboolean offscreen, jint workload) { 95 if (workload <= 8) { 96 // This test uses 8 iterations, so workload can't be more than 8. 97 gRenderer = new ContextSwitchRenderer( 98 ANativeWindow_fromSurface(env, surface), offscreen, workload); 99 } 100 } 101