Start of Reference Application Implementation.

Refactoring of primitive benchmarks.

Change-Id: I42005505ec6cb53808b748728606785a52b306f5
diff --git a/suite/pts/deviceTests/opengl/jni/primitive/Trace.h b/suite/pts/deviceTests/opengl/jni/Trace.h
similarity index 100%
rename from suite/pts/deviceTests/opengl/jni/primitive/Trace.h
rename to suite/pts/deviceTests/opengl/jni/Trace.h
diff --git a/suite/pts/deviceTests/opengl/jni/primitive/fullpipeline/FullPipelineProgram.cpp b/suite/pts/deviceTests/opengl/jni/graphics/BasicProgram.cpp
similarity index 89%
rename from suite/pts/deviceTests/opengl/jni/primitive/fullpipeline/FullPipelineProgram.cpp
rename to suite/pts/deviceTests/opengl/jni/graphics/BasicProgram.cpp
index b06cdd2..2b5ebbd 100644
--- a/suite/pts/deviceTests/opengl/jni/primitive/fullpipeline/FullPipelineProgram.cpp
+++ b/suite/pts/deviceTests/opengl/jni/graphics/BasicProgram.cpp
@@ -12,13 +12,13 @@
  * the License.
  */
 
-#include "FullPipelineProgram.h"
+#include "BasicProgram.h"
 
 #include <EGL/egl.h>
 #include <GLES2/gl2.h>
 #include <GLES2/gl2ext.h>
 
-FullPipelineProgram::FullPipelineProgram(GLuint programId) :
+BasicProgram::BasicProgram(GLuint programId) :
         Program(programId) {
     mLightPosInModelSpace[0] = 0.0f;
     mLightPosInModelSpace[1] = 2.0f;
@@ -33,7 +33,7 @@
     mTexCoordHandle = glGetAttribLocation(programId, "a_TexCoordinate");
 }
 
-void FullPipelineProgram::before(Matrix& model, Matrix& view, Matrix& projection) {
+void BasicProgram::before(Matrix& model, Matrix& view, Matrix& projection) {
     Program::before(model, view, projection);
     mLightModelMatrix.identity();
 
diff --git a/suite/pts/deviceTests/opengl/jni/primitive/fullpipeline/FullPipelineProgram.h b/suite/pts/deviceTests/opengl/jni/graphics/BasicProgram.h
similarity index 81%
rename from suite/pts/deviceTests/opengl/jni/primitive/fullpipeline/FullPipelineProgram.h
rename to suite/pts/deviceTests/opengl/jni/graphics/BasicProgram.h
index 3eab1c4..d397719 100644
--- a/suite/pts/deviceTests/opengl/jni/primitive/fullpipeline/FullPipelineProgram.h
+++ b/suite/pts/deviceTests/opengl/jni/graphics/BasicProgram.h
@@ -11,20 +11,20 @@
  * or implied. See the License for the specific language governing permissions and limitations under
  * the License.
  */
-#ifndef FULLPIPELINEPROGRAM_H
-#define FULLPIPELINEPROGRAM_H
+#ifndef BASICPROGRAM_H
+#define BASICPROGRAM_H
 
-#include <graphics/Matrix.h>
-#include <graphics/Program.h>
+#include "Matrix.h"
+#include "Program.h"
 
 #include <EGL/egl.h>
 #include <GLES2/gl2.h>
 #include <GLES2/gl2ext.h>
 
-class FullPipelineProgram: public Program {
+class BasicProgram: public Program {
 public:
-    FullPipelineProgram(GLuint programId);
-    virtual ~FullPipelineProgram() {};
+    BasicProgram(GLuint programId);
+    virtual ~BasicProgram() {};
     Matrix mMVMatrix;
     Matrix mMVPMatrix;
     Matrix mLightModelMatrix;
diff --git a/suite/pts/deviceTests/opengl/jni/graphics/GLUtils.cpp b/suite/pts/deviceTests/opengl/jni/graphics/GLUtils.cpp
index 5b74bf3..ed6f84b 100644
--- a/suite/pts/deviceTests/opengl/jni/graphics/GLUtils.cpp
+++ b/suite/pts/deviceTests/opengl/jni/graphics/GLUtils.cpp
@@ -14,6 +14,7 @@
 
 #include "GLUtils.h"
 #include <stdlib.h>
+#include <sys/time.h>
 
 #define LOG_TAG "PTS_OPENGL"
 #define LOG_NDEBUG 0
@@ -80,6 +81,12 @@
     return program;
 }
 
+double GLUtils::currentTimeMillis() {
+    struct timeval tv;
+    gettimeofday(&tv, (struct timezone *) NULL);
+    return tv.tv_sec * 1000.0 + tv.tv_usec / 1000.0;
+}
+
 // Rounds a number up to the smallest power of 2 that is greater than the original number.
 int GLUtils::roundUpToSmallestPowerOf2(int x) {
     if (x < 0) {
diff --git a/suite/pts/deviceTests/opengl/jni/graphics/GLUtils.h b/suite/pts/deviceTests/opengl/jni/graphics/GLUtils.h
index 8708103..3d3bafd 100644
--- a/suite/pts/deviceTests/opengl/jni/graphics/GLUtils.h
+++ b/suite/pts/deviceTests/opengl/jni/graphics/GLUtils.h
@@ -23,6 +23,7 @@
     // Creates a program with the given vertex and fragment shader source code.
     static GLuint createProgram(const char** vertexSource,
             const char** fragmentSource);
+    static double currentTimeMillis();
     // Rounds a number up to the smallest power of 2 that is greater than the original number.
     static int roundUpToSmallestPowerOf2(int x);
     // Generates a random texture of the given dimensions.
diff --git a/suite/pts/deviceTests/opengl/jni/primitive/Renderer.cpp b/suite/pts/deviceTests/opengl/jni/graphics/Renderer.cpp
similarity index 99%
rename from suite/pts/deviceTests/opengl/jni/primitive/Renderer.cpp
rename to suite/pts/deviceTests/opengl/jni/graphics/Renderer.cpp
index fa3ec83..ece115e 100644
--- a/suite/pts/deviceTests/opengl/jni/primitive/Renderer.cpp
+++ b/suite/pts/deviceTests/opengl/jni/graphics/Renderer.cpp
@@ -18,7 +18,7 @@
 #define LOG_NDEBUG 0
 #include <utils/Log.h>
 
-#include <primitive/Trace.h>
+#include <Trace.h>
 
 static const EGLint contextAttribs[] = {
         EGL_CONTEXT_CLIENT_VERSION, 2,
diff --git a/suite/pts/deviceTests/opengl/jni/primitive/Renderer.h b/suite/pts/deviceTests/opengl/jni/graphics/Renderer.h
similarity index 100%
rename from suite/pts/deviceTests/opengl/jni/primitive/Renderer.h
rename to suite/pts/deviceTests/opengl/jni/graphics/Renderer.h
diff --git a/suite/pts/deviceTests/opengl/jni/primitive/GLPrimitive.cpp b/suite/pts/deviceTests/opengl/jni/primitive/GLPrimitive.cpp
index 1d9cc88..687a0d2 100644
--- a/suite/pts/deviceTests/opengl/jni/primitive/GLPrimitive.cpp
+++ b/suite/pts/deviceTests/opengl/jni/primitive/GLPrimitive.cpp
@@ -14,12 +14,13 @@
 #include <jni.h>
 
 #include <stdlib.h>
-#include <sys/time.h>
 
 #include <android/native_window.h>
 #include <android/native_window_jni.h>
 
-#include "Renderer.h"
+#include <graphics/GLUtils.h>
+#include <graphics/Renderer.h>
+
 #include "fullpipeline/FullPipelineRenderer.h"
 #include "pixeloutput/PixelOutputRenderer.h"
 #include "shaderperf/ShaderPerfRenderer.h"
@@ -28,14 +29,8 @@
 // Holds the current benchmark's renderer.
 Renderer* gRenderer = NULL;
 
-double currentTimeMillis() {
-    struct timeval tv;
-    gettimeofday(&tv, (struct timezone *) NULL);
-    return tv.tv_sec * 1000.0 + tv.tv_usec / 1000.0;
-}
-
 extern "C" JNIEXPORT jboolean JNICALL
-Java_com_android_pts_opengl_primitive_GLActivity_startBenchmark(
+Java_com_android_pts_opengl_primitive_GLPrimitiveActivity_startBenchmark(
         JNIEnv* env, jclass clazz, jint numFrames, jdoubleArray frameTimes) {
     if (gRenderer == NULL) {
         return false;
@@ -45,7 +40,7 @@
     bool success = gRenderer->setUp();
 
     // Records the start time.
-    double start = currentTimeMillis();
+    double start = GLUtils::currentTimeMillis();
 
     // Draw off the screen.
     for (int i = 0; i < numFrames && success; i++) {
@@ -54,7 +49,7 @@
     }
 
     // Records the end time.
-    double end = currentTimeMillis();
+    double end = GLUtils::currentTimeMillis();
 
     // Sets the times in the Java array.
     double times[] = {start, end};
@@ -69,28 +64,28 @@
 
 // The following functions create the renderers for the various benchmarks.
 extern "C" JNIEXPORT void JNICALL
-Java_com_android_pts_opengl_primitive_GLActivity_setupFullPipelineBenchmark(
+Java_com_android_pts_opengl_primitive_GLPrimitiveActivity_setupFullPipelineBenchmark(
         JNIEnv* env, jclass clazz, jobject surface, jboolean offscreen, jint workload) {
     gRenderer = new FullPipelineRenderer(
             ANativeWindow_fromSurface(env, surface), offscreen, workload);
 }
 
 extern "C" JNIEXPORT void JNICALL
-Java_com_android_pts_opengl_primitive_GLActivity_setupPixelOutputBenchmark(
+Java_com_android_pts_opengl_primitive_GLPrimitiveActivity_setupPixelOutputBenchmark(
         JNIEnv* env, jclass clazz, jobject surface, jboolean offscreen, jint workload) {
     gRenderer = new PixelOutputRenderer(
             ANativeWindow_fromSurface(env, surface), offscreen, workload);
 }
 
 extern "C" JNIEXPORT void JNICALL
-Java_com_android_pts_opengl_primitive_GLActivity_setupShaderPerfBenchmark(
+Java_com_android_pts_opengl_primitive_GLPrimitiveActivity_setupShaderPerfBenchmark(
         JNIEnv* env, jclass clazz, jobject surface, jboolean offscreen, jint workload) {
     gRenderer = new ShaderPerfRenderer(
             ANativeWindow_fromSurface(env, surface), offscreen, workload);
 }
 
 extern "C" JNIEXPORT void JNICALL
-Java_com_android_pts_opengl_primitive_GLActivity_setupContextSwitchBenchmark(
+Java_com_android_pts_opengl_primitive_GLPrimitiveActivity_setupContextSwitchBenchmark(
         JNIEnv* env, jclass clazz, jobject surface, jboolean offscreen, jint workload) {
     if (workload <= 8) {
         // This test uses 8 iterations, so workload can't be more than 8.
diff --git a/suite/pts/deviceTests/opengl/jni/primitive/contextswitch/ContextSwitchRenderer.cpp b/suite/pts/deviceTests/opengl/jni/primitive/contextswitch/ContextSwitchRenderer.cpp
index e365db6..44e8909 100644
--- a/suite/pts/deviceTests/opengl/jni/primitive/contextswitch/ContextSwitchRenderer.cpp
+++ b/suite/pts/deviceTests/opengl/jni/primitive/contextswitch/ContextSwitchRenderer.cpp
@@ -23,11 +23,7 @@
 #include "ContextSwitchRenderer.h"
 #include <graphics/GLUtils.h>
 
-#define LOG_TAG "PTS_OPENGL"
-#define LOG_NDEBUG 0
-#include <utils/Log.h>
-
-#include <primitive/Trace.h>
+#include <Trace.h>
 
 static const EGLint contextAttribs[] =
         { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
@@ -112,12 +108,6 @@
         }
     }
 
-    GLuint err = glGetError();
-    if (err != GL_NO_ERROR) {
-        ALOGE("GLError %d", err);
-        return false;
-    }
-
     return true;
 }
 
diff --git a/suite/pts/deviceTests/opengl/jni/primitive/contextswitch/ContextSwitchRenderer.h b/suite/pts/deviceTests/opengl/jni/primitive/contextswitch/ContextSwitchRenderer.h
index d4e7595..9ab05e3 100644
--- a/suite/pts/deviceTests/opengl/jni/primitive/contextswitch/ContextSwitchRenderer.h
+++ b/suite/pts/deviceTests/opengl/jni/primitive/contextswitch/ContextSwitchRenderer.h
@@ -14,7 +14,7 @@
 #ifndef CONTEXTSWITCHRENDERER_H
 #define CONTEXTSWITCHRENDERER_H
 
-#include <primitive/Renderer.h>
+#include <graphics/Renderer.h>
 
 class ContextSwitchRenderer: public Renderer {
 public:
diff --git a/suite/pts/deviceTests/opengl/jni/primitive/fullpipeline/FullPipelineMesh.cpp b/suite/pts/deviceTests/opengl/jni/primitive/fullpipeline/FullPipelineMesh.cpp
index c0e5250..bf1b9d2 100644
--- a/suite/pts/deviceTests/opengl/jni/primitive/fullpipeline/FullPipelineMesh.cpp
+++ b/suite/pts/deviceTests/opengl/jni/primitive/fullpipeline/FullPipelineMesh.cpp
@@ -13,14 +13,15 @@
  */
 
 #include "FullPipelineMesh.h"
-#include "FullPipelineProgram.h"
+
+#include <graphics/BasicProgram.h>
 
 FullPipelineMesh::FullPipelineMesh(const Mesh* mesh) :
         MeshNode(mesh) {
 }
 
 void FullPipelineMesh::before(Program& program, Matrix& model, Matrix& view, Matrix& projection) {
-    FullPipelineProgram& prog = (FullPipelineProgram&) program;
+    BasicProgram& prog = (BasicProgram&) program;
 
     glActiveTexture(GL_TEXTURE0);
     // Bind the texture to this unit.
diff --git a/suite/pts/deviceTests/opengl/jni/primitive/fullpipeline/FullPipelineRenderer.cpp b/suite/pts/deviceTests/opengl/jni/primitive/fullpipeline/FullPipelineRenderer.cpp
index f178912..da65420 100644
--- a/suite/pts/deviceTests/opengl/jni/primitive/fullpipeline/FullPipelineRenderer.cpp
+++ b/suite/pts/deviceTests/opengl/jni/primitive/fullpipeline/FullPipelineRenderer.cpp
@@ -16,17 +16,12 @@
 #include <GLES2/gl2ext.h>
 
 #include "FullPipelineMesh.h"
-#include "FullPipelineProgram.h"
 #include "FullPipelineRenderer.h"
-#include <graphics/Mesh.h>
+
 #include <graphics/TransformationNode.h>
 #include <graphics/GLUtils.h>
 
-#define LOG_TAG "PTS_OPENGL"
-#define LOG_NDEBUG 0
-#include <utils/Log.h>
-
-#include <primitive/Trace.h>
+#include <Trace.h>
 
 static const int FP_NUM_VERTICES = 6;
 
@@ -98,7 +93,8 @@
 
 FullPipelineRenderer::FullPipelineRenderer(ANativeWindow* window, bool offscreen, int workload) :
         Renderer(window, offscreen, workload), mProgram(NULL), mSceneGraph(NULL),
-        mModelMatrix(NULL), mViewMatrix(NULL), mProjectionMatrix(NULL), mMesh(NULL) {
+        mModelMatrix(NULL), mViewMatrix(NULL), mProjectionMatrix(NULL), mMesh(NULL),
+        mTextureId(0) {
 }
 
 bool FullPipelineRenderer::setUp() {
@@ -110,7 +106,7 @@
     mProgramId = GLUtils::createProgram(&FP_VERTEX, &FP_FRAGMENT);
     if (mProgramId == 0)
         return false;
-    mProgram = new FullPipelineProgram(mProgramId);
+    mProgram = new BasicProgram(mProgramId);
 
     mModelMatrix = new Matrix();
 
diff --git a/suite/pts/deviceTests/opengl/jni/primitive/fullpipeline/FullPipelineRenderer.h b/suite/pts/deviceTests/opengl/jni/primitive/fullpipeline/FullPipelineRenderer.h
index 14efcf6..b0b31a2 100644
--- a/suite/pts/deviceTests/opengl/jni/primitive/fullpipeline/FullPipelineRenderer.h
+++ b/suite/pts/deviceTests/opengl/jni/primitive/fullpipeline/FullPipelineRenderer.h
@@ -14,11 +14,10 @@
 #ifndef FULLPIPELINERENDERER_H
 #define FULLPIPELINERENDERER_H
 
-#include "FullPipelineProgram.h"
-
-#include <primitive/Renderer.h>
+#include <graphics/BasicProgram.h>
 #include <graphics/Matrix.h>
 #include <graphics/Mesh.h>
+#include <graphics/Renderer.h>
 #include <graphics/ProgramNode.h>
 
 class FullPipelineRenderer: public Renderer {
@@ -29,7 +28,7 @@
     bool tearDown();
     bool draw();
 private:
-    FullPipelineProgram* mProgram;
+    BasicProgram* mProgram;
     ProgramNode* mSceneGraph;
     Matrix* mModelMatrix;
     Matrix* mViewMatrix;
diff --git a/suite/pts/deviceTests/opengl/jni/primitive/pixeloutput/PixelOutputRenderer.cpp b/suite/pts/deviceTests/opengl/jni/primitive/pixeloutput/PixelOutputRenderer.cpp
index 2f3d647..321235d 100644
--- a/suite/pts/deviceTests/opengl/jni/primitive/pixeloutput/PixelOutputRenderer.cpp
+++ b/suite/pts/deviceTests/opengl/jni/primitive/pixeloutput/PixelOutputRenderer.cpp
@@ -14,11 +14,7 @@
 #include "PixelOutputRenderer.h"
 #include <graphics/GLUtils.h>
 
-#define LOG_TAG "PTS_OPENGL"
-#define LOG_NDEBUG 0
-#include <utils/Log.h>
-
-#include <primitive/Trace.h>
+#include <Trace.h>
 
 static const int PO_NUM_VERTICES = 6;
 
diff --git a/suite/pts/deviceTests/opengl/jni/primitive/pixeloutput/PixelOutputRenderer.h b/suite/pts/deviceTests/opengl/jni/primitive/pixeloutput/PixelOutputRenderer.h
index 90b3f2a..11ffab9 100644
--- a/suite/pts/deviceTests/opengl/jni/primitive/pixeloutput/PixelOutputRenderer.h
+++ b/suite/pts/deviceTests/opengl/jni/primitive/pixeloutput/PixelOutputRenderer.h
@@ -14,7 +14,7 @@
 #ifndef PIXELOUTPUTRENDERER_H
 #define PIXELOUTPUTRENDERER_H
 
-#include <primitive/Renderer.h>
+#include <graphics/Renderer.h>
 
 class PixelOutputRenderer: public Renderer {
 public:
diff --git a/suite/pts/deviceTests/opengl/jni/primitive/shaderperf/ShaderPerfRenderer.cpp b/suite/pts/deviceTests/opengl/jni/primitive/shaderperf/ShaderPerfRenderer.cpp
index 156f81e..cff8599 100644
--- a/suite/pts/deviceTests/opengl/jni/primitive/shaderperf/ShaderPerfRenderer.cpp
+++ b/suite/pts/deviceTests/opengl/jni/primitive/shaderperf/ShaderPerfRenderer.cpp
@@ -16,11 +16,7 @@
 
 #include <math.h>
 
-#define LOG_TAG "PTS_OPENGL"
-#define LOG_NDEBUG 0
-#include <utils/Log.h>
-
-#include <primitive/Trace.h>
+#include <Trace.h>
 
 static const float GOLDEN_RATIO = (1.0f + sqrt(5.0f)) / 2.0f;
 
@@ -141,12 +137,6 @@
     }
     delete[] m;
 
-    GLuint err = glGetError();
-    if (err != GL_NO_ERROR) {
-        ALOGE("GLError %d", err);
-        return false;
-    }
-
     return true;
 }
 
diff --git a/suite/pts/deviceTests/opengl/jni/primitive/shaderperf/ShaderPerfRenderer.h b/suite/pts/deviceTests/opengl/jni/primitive/shaderperf/ShaderPerfRenderer.h
index 3537eba..096e231 100644
--- a/suite/pts/deviceTests/opengl/jni/primitive/shaderperf/ShaderPerfRenderer.h
+++ b/suite/pts/deviceTests/opengl/jni/primitive/shaderperf/ShaderPerfRenderer.h
@@ -14,7 +14,7 @@
 #ifndef SHADERPERFRENDERER_H
 #define SHADERPERFRENDERER_H
 
-#include <primitive/Renderer.h>
+#include <graphics/Renderer.h>
 
 class ShaderPerfRenderer: public Renderer {
 public:
diff --git a/suite/pts/deviceTests/opengl/jni/reference/GLReference.cpp b/suite/pts/deviceTests/opengl/jni/reference/GLReference.cpp
new file mode 100644
index 0000000..53a262e
--- /dev/null
+++ b/suite/pts/deviceTests/opengl/jni/reference/GLReference.cpp
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+#include <jni.h>
+
+extern "C" JNIEXPORT jboolean JNICALL
+Java_com_android_pts_opengl_reference_GLGameActivity_startBenchmark(
+        JNIEnv* env, jclass clazz, jobject surface, jint numFrames,
+        jdoubleArray setUpTimes, jdoubleArray updateTimes, jdoubleArray renderTimes) {
+    // TODO
+    return true;
+}