diff options
author | Alex Sakhartchouk <alexst@google.com> | 2010-10-05 13:23:55 -0700 |
---|---|---|
committer | Alex Sakhartchouk <alexst@google.com> | 2010-10-05 13:28:09 -0700 |
commit | 76322af2a6c109a79431f019dcef6e038c030686 (patch) | |
tree | 713cd5b099fc21a0f27e1f4f468c2f31e1bb6a24 /libs/rs | |
parent | cd1b8d3665fcab89e28592838cfba1a09bc8202a (diff) | |
download | frameworks_base-76322af2a6c109a79431f019dcef6e038c030686.zip frameworks_base-76322af2a6c109a79431f019dcef6e038c030686.tar.gz frameworks_base-76322af2a6c109a79431f019dcef6e038c030686.tar.bz2 |
Adding average fps counter.
Removing rsLight from libRS
Change-Id: I8622efd10619dc120d37f3a12122e9c7fc34ff2e
Diffstat (limited to 'libs/rs')
-rw-r--r-- | libs/rs/Android.mk | 1 | ||||
-rw-r--r-- | libs/rs/RenderScript.h | 2 | ||||
-rw-r--r-- | libs/rs/RenderScriptEnv.h | 2 | ||||
-rw-r--r-- | libs/rs/rsContext.cpp | 24 | ||||
-rw-r--r-- | libs/rs/rsContext.h | 5 | ||||
-rw-r--r-- | libs/rs/rsContextHostStub.h | 2 | ||||
-rw-r--r-- | libs/rs/rsFileA3D.cpp | 3 | ||||
-rw-r--r-- | libs/rs/rsFont.cpp | 2 | ||||
-rw-r--r-- | libs/rs/rsLight.cpp | 144 | ||||
-rw-r--r-- | libs/rs/rsLight.h | 67 | ||||
-rw-r--r-- | libs/rs/rsVertexArray.h | 3 |
11 files changed, 24 insertions, 231 deletions
diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk index 37c418b..05c1a48 100644 --- a/libs/rs/Android.mk +++ b/libs/rs/Android.mk @@ -83,7 +83,6 @@ LOCAL_SRC_FILES:= \ rsElement.cpp \ rsFileA3D.cpp \ rsFont.cpp \ - rsLight.cpp \ rsLocklessFifo.cpp \ rsObjectBase.cpp \ rsMatrix.cpp \ diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h index 13ae1fb..66e27f3 100644 --- a/libs/rs/RenderScript.h +++ b/libs/rs/RenderScript.h @@ -40,7 +40,6 @@ typedef void * RsSampler; typedef void * RsScript; typedef void * RsMesh; typedef void * RsType; -typedef void * RsLight; typedef void * RsObjectBase; typedef void * RsProgram; @@ -242,7 +241,6 @@ enum RsA3DClassID { 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/libs/rs/RenderScriptEnv.h b/libs/rs/RenderScriptEnv.h index c83ece4..b82eaf1 100644 --- a/libs/rs/RenderScriptEnv.h +++ b/libs/rs/RenderScriptEnv.h @@ -13,8 +13,6 @@ typedef void * RsMesh; typedef void * RsType; typedef void * RsProgramFragment; typedef void * RsProgramStore; -typedef void * RsLight; - typedef struct { float m[16]; diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp index 493a092..30add62 100644 --- a/libs/rs/rsContext.cpp +++ b/libs/rs/rsContext.cpp @@ -188,6 +188,9 @@ void Context::timerInit() mTimeFrame = mTimeLast; mTimeLastFrame = mTimeLast; mTimerActive = RS_TIMER_INTERNAL; + mAverageFPSFrameCount = 0; + mAverageFPSStartTime = mTimeLast; + mAverageFPS = 0; timerReset(); } @@ -195,6 +198,16 @@ void Context::timerFrame() { 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 @@ void Context::timerPrint() 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 @@ static bool getProp(const char *str) 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/libs/rs/rsContext.h b/libs/rs/rsContext.h index dabe196..8a8b8a8 100644 --- a/libs/rs/rsContext.h +++ b/libs/rs/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 @@ public: ProgramStoreState mStateFragmentStore; ProgramRasterState mStateRaster; ProgramVertexState mStateVertex; - LightState mStateLight; VertexArrayState mStateVertexArray; FontState mStateFont; @@ -296,6 +294,9 @@ private: uint32_t mTimeMSLastFrame; uint32_t mTimeMSLastScript; uint32_t mTimeMSLastSwap; + uint32_t mAverageFPSFrameCount; + uint64_t mAverageFPSStartTime; + uint32_t mAverageFPS; }; } diff --git a/libs/rs/rsContextHostStub.h b/libs/rs/rsContextHostStub.h index 06298e8..aa0205d 100644 --- a/libs/rs/rsContextHostStub.h +++ b/libs/rs/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 @@ public: ProgramStoreState mStateFragmentStore; //ProgramRasterState mStateRaster; //ProgramVertexState mStateVertex; - LightState mStateLight; VertexArrayState mStateVertexArray; //ScriptCState mScriptC; diff --git a/libs/rs/rsFileA3D.cpp b/libs/rs/rsFileA3D.cpp index 893598f..c90edc2 100644 --- a/libs/rs/rsFileA3D.cpp +++ b/libs/rs/rsFileA3D.cpp @@ -278,9 +278,6 @@ ObjectBase *FileA3D::initializeFromEntry(size_t index) { 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/libs/rs/rsFont.cpp b/libs/rs/rsFont.cpp index cc2b76a..b9de7e1 100644 --- a/libs/rs/rsFont.cpp +++ b/libs/rs/rsFont.cpp @@ -825,7 +825,7 @@ void FontState::setFontColor(float r, float g, float b, float a) { 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/libs/rs/rsLight.cpp b/libs/rs/rsLight.cpp deleted file mode 100644 index eab9a07..0000000 --- a/libs/rs/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/libs/rs/rsLight.h b/libs/rs/rsLight.h deleted file mode 100644 index bd58979..0000000 --- a/libs/rs/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/libs/rs/rsVertexArray.h b/libs/rs/rsVertexArray.h index bd76d87..dea7d41 100644 --- a/libs/rs/rsVertexArray.h +++ b/libs/rs/rsVertexArray.h @@ -62,7 +62,6 @@ public: } 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 @@ public: } } -#endif //ANDROID_LIGHT_H +#endif //ANDROID_VERTEX_ARRAY_H |