Bug 788400 - Part 1: Add a frame counter to OGLLayers. r=jmuizelaar

This commit is contained in:
Benoit Girard 2012-09-05 16:24:54 -04:00
Родитель 6667c8fbd7
Коммит d2c9c87488
2 изменённых файлов: 29 добавлений и 0 удалений

Просмотреть файл

@ -104,6 +104,8 @@ struct FPSState {
void DrawFPS(TimeStamp, GLContext*, ShaderProgramOGL*);
static void DrawFrameCounter(GLContext* context);
void NotifyShadowTreeTransaction() {
mTransactionFps.AddFrame(TimeStamp::Now());
}
@ -569,6 +571,7 @@ LayerManagerOGL::Initialize(nsRefPtr<GLContext> aContext, bool force)
if (NS_IsMainThread()) {
Preferences::AddBoolVarCache(&sDrawFPS, "layers.acceleration.draw-fps");
Preferences::AddBoolVarCache(&sFrameCounter, "layers.acceleration.frame-counter");
} else {
// We have to dispatch an event to the main thread to read the pref.
class ReadDrawFPSPref : public nsRunnable {
@ -576,6 +579,7 @@ LayerManagerOGL::Initialize(nsRefPtr<GLContext> aContext, bool force)
NS_IMETHOD Run()
{
Preferences::AddBoolVarCache(&sDrawFPS, "layers.acceleration.draw-fps");
Preferences::AddBoolVarCache(&sFrameCounter, "layers.acceleration.frame-counter");
return NS_OK;
}
};
@ -747,6 +751,28 @@ LayerManagerOGL::RootLayer() const
}
bool LayerManagerOGL::sDrawFPS = false;
bool LayerManagerOGL::sFrameCounter = false;
static uint16_t sFrameCount = 0;
void
FPSState::DrawFrameCounter(GLContext* context)
{
// We intentionally overflow at 2^16.
uint16_t frameNumber = sFrameCount++;
for (size_t i = 0; i < 16; i++) {
context->fScissor(3*i, 0, 3, 3);
// We should do this using a single draw call
// instead of 16 glClear()
if ((frameNumber >> i) & 0x1) {
context->fClearColor(0.0, 0.0, 0.0, 0.0);
} else {
context->fClearColor(1.0, 1.0, 1.0, 0.0);
}
context->fClear(LOCAL_GL_COLOR_BUFFER_BIT);
}
}
// |aTexCoordRect| is the rectangle from the texture that we want to
// draw using the given program. The program already has a necessary
@ -948,6 +974,8 @@ LayerManagerOGL::Render()
if (mFPS) {
mFPS->DrawFPS(TimeStamp::Now(), mGLContext, GetProgram(Copy2DProgramType));
} else if (sFrameCounter) {
DrawFrameCounter(mGLContext);
}
if (mGLContext->IsDoubleBuffered()) {

Просмотреть файл

@ -442,6 +442,7 @@ private:
nsAutoPtr<FPSState> mFPS;
static bool sDrawFPS;
static bool sFrameCounter;
};
/**