Adding average fps counter.
Removing rsLight from libRS

Change-Id: I8622efd10619dc120d37f3a12122e9c7fc34ff2e
diff --git a/Android.mk b/Android.mk
index 37c418b..05c1a48 100644
--- a/Android.mk
+++ b/Android.mk
@@ -83,7 +83,6 @@
 	rsElement.cpp \
 	rsFileA3D.cpp \
 	rsFont.cpp \
-	rsLight.cpp \
 	rsLocklessFifo.cpp \
 	rsObjectBase.cpp \
 	rsMatrix.cpp \
diff --git a/RenderScript.h b/RenderScript.h
index 13ae1fb..66e27f3 100644
--- a/RenderScript.h
+++ b/RenderScript.h
@@ -40,7 +40,6 @@
 typedef void * RsScript;
 typedef void * RsMesh;
 typedef void * RsType;
-typedef void * RsLight;
 typedef void * RsObjectBase;
 
 typedef void * RsProgram;
@@ -242,7 +241,6 @@
     RS_A3D_CLASS_ID_PROGRAM_STORE,
     RS_A3D_CLASS_ID_SAMPLER,
     RS_A3D_CLASS_ID_ANIMATION,
-    RS_A3D_CLASS_ID_LIGHT,
     RS_A3D_CLASS_ID_ADAPTER_1D,
     RS_A3D_CLASS_ID_ADAPTER_2D,
     RS_A3D_CLASS_ID_SCRIPT_C
diff --git a/RenderScriptEnv.h b/RenderScriptEnv.h
index c83ece4..b82eaf1 100644
--- a/RenderScriptEnv.h
+++ b/RenderScriptEnv.h
@@ -13,8 +13,6 @@
 typedef void * RsType;
 typedef void * RsProgramFragment;
 typedef void * RsProgramStore;
-typedef void * RsLight;
-
 
 typedef struct {
     float m[16];
diff --git a/rsContext.cpp b/rsContext.cpp
index 493a092..30add62 100644
--- a/rsContext.cpp
+++ b/rsContext.cpp
@@ -188,6 +188,9 @@
     mTimeFrame = mTimeLast;
     mTimeLastFrame = mTimeLast;
     mTimerActive = RS_TIMER_INTERNAL;
+    mAverageFPSFrameCount = 0;
+    mAverageFPSStartTime = mTimeLast;
+    mAverageFPS = 0;
     timerReset();
 }
 
@@ -195,6 +198,16 @@
 {
     mTimeLastFrame = mTimeFrame;
     mTimeFrame = getTime();
+    // Update average fps
+    const uint64_t averageFramerateInterval = 1000 * 1000000;
+    mAverageFPSFrameCount ++;
+    uint64_t inverval = mTimeFrame - mAverageFPSStartTime;
+    if(inverval >= averageFramerateInterval) {
+        inverval = inverval / 1000000;
+        mAverageFPS = (mAverageFPSFrameCount * 1000) / inverval;
+        mAverageFPSFrameCount = 0;
+        mAverageFPSStartTime = mTimeFrame;
+    }
 }
 
 void Context::timerSet(Timers tm)
@@ -218,12 +231,13 @@
 
 
     if (props.mLogTimes) {
-        LOGV("RS: Frame (%i),   Script %2.1f (%i),  Clear & Swap %2.1f (%i),  Idle %2.1f (%lli),  Internal %2.1f (%lli)",
+        LOGV("RS: Frame (%i),   Script %2.1f (%i),  Clear & Swap %2.1f (%i),  Idle %2.1f (%lli),  Internal %2.1f (%lli), Avg fps: %u",
              mTimeMSLastFrame,
              100.0 * mTimers[RS_TIMER_SCRIPT] / total, mTimeMSLastScript,
              100.0 * mTimers[RS_TIMER_CLEAR_SWAP] / total, mTimeMSLastSwap,
              100.0 * mTimers[RS_TIMER_IDLE] / total, mTimers[RS_TIMER_IDLE] / 1000000,
-             100.0 * mTimers[RS_TIMER_INTERNAL] / total, mTimers[RS_TIMER_INTERNAL] / 1000000);
+             100.0 * mTimers[RS_TIMER_INTERNAL] / total, mTimers[RS_TIMER_INTERNAL] / 1000000,
+             mAverageFPS);
     }
 }
 
@@ -255,17 +269,17 @@
 void Context::displayDebugStats()
 {
     char buffer[128];
-    sprintf(buffer, "Frame %i ms, Script %i ms", mTimeMSLastFrame, mTimeMSLastScript);
+    sprintf(buffer, "Avg fps %u, Frame %i ms, Script %i ms", mAverageFPS, mTimeMSLastFrame, mTimeMSLastScript);
     float oldR, oldG, oldB, oldA;
     mStateFont.getFontColor(&oldR, &oldG, &oldB, &oldA);
     uint32_t bufferLen = strlen(buffer);
 
     float shadowCol = 0.1f;
     mStateFont.setFontColor(shadowCol, shadowCol, shadowCol, 1.0f);
-    mStateFont.renderText(buffer, bufferLen, 5, getHeight() - 5);
+    mStateFont.renderText(buffer, bufferLen, 5, getHeight() - 6);
 
     mStateFont.setFontColor(1.0f, 0.7f, 0.0f, 1.0f);
-    mStateFont.renderText(buffer, bufferLen, 4, getHeight() - 6);
+    mStateFont.renderText(buffer, bufferLen, 4, getHeight() - 7);
 
     mStateFont.setFontColor(oldR, oldG, oldB, oldA);
 }
diff --git a/rsContext.h b/rsContext.h
index dabe196..8a8b8a8 100644
--- a/rsContext.h
+++ b/rsContext.h
@@ -30,7 +30,6 @@
 #include "rsAllocation.h"
 #include "rsAdapter.h"
 #include "rsSampler.h"
-#include "rsLight.h"
 #include "rsFont.h"
 #include "rsProgramFragment.h"
 #include "rsProgramStore.h"
@@ -94,7 +93,6 @@
     ProgramStoreState mStateFragmentStore;
     ProgramRasterState mStateRaster;
     ProgramVertexState mStateVertex;
-    LightState mStateLight;
     VertexArrayState mStateVertexArray;
     FontState mStateFont;
 
@@ -296,6 +294,9 @@
     uint32_t mTimeMSLastFrame;
     uint32_t mTimeMSLastScript;
     uint32_t mTimeMSLastSwap;
+    uint32_t mAverageFPSFrameCount;
+    uint64_t mAverageFPSStartTime;
+    uint32_t mAverageFPS;
 };
 
 }
diff --git a/rsContextHostStub.h b/rsContextHostStub.h
index 06298e8..aa0205d 100644
--- a/rsContextHostStub.h
+++ b/rsContextHostStub.h
@@ -30,7 +30,6 @@
 #include "rsAllocation.h"
 #include "rsAdapter.h"
 #include "rsSampler.h"
-#include "rsLight.h"
 #include "rsProgramFragment.h"
 #include "rsProgramStore.h"
 #include "rsProgramRaster.h"
@@ -68,7 +67,6 @@
     ProgramStoreState mStateFragmentStore;
     //ProgramRasterState mStateRaster;
     //ProgramVertexState mStateVertex;
-    LightState mStateLight;
     VertexArrayState mStateVertexArray;
 
     //ScriptCState mScriptC;
diff --git a/rsFileA3D.cpp b/rsFileA3D.cpp
index 893598f..c90edc2 100644
--- a/rsFileA3D.cpp
+++ b/rsFileA3D.cpp
@@ -278,9 +278,6 @@
         case RS_A3D_CLASS_ID_ANIMATION:
             entry->mRsObj = Animation::createFromStream(mRSC, mReadStream);
             break;
-        case RS_A3D_CLASS_ID_LIGHT:
-            entry->mRsObj = Light::createFromStream(mRSC, mReadStream);
-            break;
         case RS_A3D_CLASS_ID_ADAPTER_1D:
             entry->mRsObj = Adapter1D::createFromStream(mRSC, mReadStream);
             break;
diff --git a/rsFont.cpp b/rsFont.cpp
index cc2b76a..b9de7e1 100644
--- a/rsFont.cpp
+++ b/rsFont.cpp
@@ -825,7 +825,7 @@
     mConstants.mFontColor[3] = a;
 
     mConstants.mGamma = 1.0f;
-    const int32_t luminance = (r * 2.0f + g * 5.0f + b) / 8.0f;
+    const float luminance = (r * 2.0f + g * 5.0f + b) / 8.0f;
     if (luminance <= mBlackThreshold) {
         mConstants.mGamma = mBlackGamma;
     } else if (luminance >= mWhiteThreshold) {
diff --git a/rsLight.cpp b/rsLight.cpp
deleted file mode 100644
index eab9a07..0000000
--- a/rsLight.cpp
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Copyright (C) 2009 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.
- */
-
-#ifndef ANDROID_RS_BUILD_FOR_HOST
-#include "rsContext.h"
-#include <GLES/gl.h>
-#else
-#include "rsContextHostStub.h"
-#include <OpenGL/gl.h>
-#endif //ANDROID_RS_BUILD_FOR_HOST
-
-using namespace android;
-using namespace android::renderscript;
-
-
-Light::Light(Context *rsc, bool isLocal, bool isMono) : ObjectBase(rsc)
-{
-    mAllocFile = __FILE__;
-    mAllocLine = __LINE__;
-    mIsLocal = isLocal;
-    mIsMono = isMono;
-
-    mPosition[0] = 0;
-    mPosition[1] = 0;
-    mPosition[2] = 1;
-    mPosition[3] = 0;
-
-    mColor[0] = 1.f;
-    mColor[1] = 1.f;
-    mColor[2] = 1.f;
-    mColor[3] = 1.f;
-}
-
-Light::~Light()
-{
-}
-
-void Light::setPosition(float x, float y, float z)
-{
-    mPosition[0] = x;
-    mPosition[1] = y;
-    mPosition[2] = z;
-}
-
-void Light::setColor(float r, float g, float b)
-{
-    mColor[0] = r;
-    mColor[1] = g;
-    mColor[2] = b;
-}
-
-void Light::setupGL(uint32_t num) const
-{
-    glLightfv(GL_LIGHT0 + num, GL_DIFFUSE, mColor);
-    glLightfv(GL_LIGHT0 + num, GL_SPECULAR, mColor);
-    glLightfv(GL_LIGHT0 + num, GL_POSITION, mPosition);
-}
-
-void Light::serialize(OStream *stream) const
-{
-    
-}
-
-Light *Light::createFromStream(Context *rsc, IStream *stream)
-{
-    return NULL;
-}
-
-////////////////////////////////////////////
-
-LightState::LightState()
-{
-    clear();
-}
-
-LightState::~LightState()
-{
-}
-
-void LightState::clear()
-{
-    mIsLocal = false;
-    mIsMono = false;
-}
-
-
-////////////////////////////////////////////////////
-//
-
-namespace android {
-namespace renderscript {
-
-void rsi_LightBegin(Context *rsc)
-{
-    rsc->mStateLight.clear();
-}
-
-void rsi_LightSetLocal(Context *rsc, bool isLocal)
-{
-    rsc->mStateLight.mIsLocal = isLocal;
-}
-
-void rsi_LightSetMonochromatic(Context *rsc, bool isMono)
-{
-    rsc->mStateLight.mIsMono = isMono;
-}
-
-RsLight rsi_LightCreate(Context *rsc)
-{
-    Light *l = new Light(rsc, rsc->mStateLight.mIsLocal,
-                         rsc->mStateLight.mIsMono);
-    l->incUserRef();
-    return l;
-}
-
-void rsi_LightSetColor(Context *rsc, RsLight vl, float r, float g, float b)
-{
-    Light *l = static_cast<Light *>(vl);
-    l->setColor(r, g, b);
-}
-
-void rsi_LightSetPosition(Context *rsc, RsLight vl, float x, float y, float z)
-{
-    Light *l = static_cast<Light *>(vl);
-    l->setPosition(x, y, z);
-}
-
-
-
-}
-}
diff --git a/rsLight.h b/rsLight.h
deleted file mode 100644
index bd58979..0000000
--- a/rsLight.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2009 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.
- */
-
-#ifndef ANDROID_LIGHT_H
-#define ANDROID_LIGHT_H
-
-
-#include "rsObjectBase.h"
-
-// ---------------------------------------------------------------------------
-namespace android {
-namespace renderscript {
-
-
-// An element is a group of Components that occupies one cell in a structure.
-class Light : public ObjectBase
-{
-public:
-    Light(Context *, bool isLocal, bool isMono);
-    virtual ~Light();
-
-    // Values, mutable after creation.
-    void setPosition(float x, float y, float z);
-    void setColor(float r, float g, float b);
-
-    void setupGL(uint32_t num) const;
-    virtual void serialize(OStream *stream) const;
-    virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_LIGHT; }
-    static Light *createFromStream(Context *rsc, IStream *stream);
-
-protected:
-    float mColor[4];
-    float mPosition[4];
-    bool mIsLocal;
-    bool mIsMono;
-};
-
-
-class LightState {
-public:
-    LightState();
-    ~LightState();
-
-    void clear();
-
-    bool mIsMono;
-    bool mIsLocal;
-};
-
-
-}
-}
-#endif //ANDROID_LIGHT_H
-
diff --git a/rsVertexArray.h b/rsVertexArray.h
index bd76d87..dea7d41 100644
--- a/rsVertexArray.h
+++ b/rsVertexArray.h
@@ -62,7 +62,6 @@
     }
 
     void add(const Attrib &, uint32_t stride);
-    //void addLegacy(uint32_t type, uint32_t size, uint32_t stride, bool normalized, uint32_t offset);
     void add(uint32_t type, uint32_t size, uint32_t stride, bool normalized, uint32_t offset, const char *name);
 
     void setupGL2(const Context *rsc, class VertexArrayState *, ShaderCache *) const;
@@ -89,7 +88,7 @@
 
 }
 }
-#endif //ANDROID_LIGHT_H
+#endif //ANDROID_VERTEX_ARRAY_H