Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2013-11-17 18:07:08 -08:00
|
|
|
#ifndef mozilla_layers_opengl_FPSCounter_h_
|
|
|
|
#define mozilla_layers_opengl_FPSCounter_h_
|
|
|
|
|
2013-08-11 16:17:23 -07:00
|
|
|
#include <stddef.h> // for size_t
|
|
|
|
#include <algorithm> // for min
|
|
|
|
#include "GLDefs.h" // for GLuint
|
|
|
|
#include "mozilla/TimeStamp.h" // for TimeStamp, TimeDuration
|
|
|
|
#include "nsTArray.h" // for nsAutoTArray, nsTArray_Impl, etc
|
2013-08-22 12:04:55 -07:00
|
|
|
#include "VBOArena.h" // for gl::VBOArena
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gl {
|
|
|
|
class GLContext;
|
|
|
|
}
|
|
|
|
namespace layers {
|
|
|
|
|
2014-02-10 14:14:11 -08:00
|
|
|
class DataTextureSource;
|
2013-08-11 16:17:23 -07:00
|
|
|
class ShaderProgramOGL;
|
|
|
|
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
const double kFpsWindowMs = 250.0;
|
|
|
|
const size_t kNumFrameTimeStamps = 16;
|
|
|
|
struct FPSCounter {
|
|
|
|
FPSCounter() : mCurrentFrameIndex(0) {
|
|
|
|
mFrames.SetLength(kNumFrameTimeStamps);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We keep a circular buffer of the time points at which the last K
|
|
|
|
// frames were drawn. To estimate FPS, we count the number of
|
|
|
|
// frames we've drawn within the last kFPSWindowMs milliseconds and
|
|
|
|
// divide by the amount time since the first of those frames.
|
|
|
|
nsAutoTArray<TimeStamp, kNumFrameTimeStamps> mFrames;
|
|
|
|
size_t mCurrentFrameIndex;
|
|
|
|
|
|
|
|
void AddFrame(TimeStamp aNewFrame) {
|
|
|
|
mFrames[mCurrentFrameIndex] = aNewFrame;
|
|
|
|
mCurrentFrameIndex = (mCurrentFrameIndex + 1) % kNumFrameTimeStamps;
|
|
|
|
}
|
|
|
|
|
|
|
|
double AddFrameAndGetFps(TimeStamp aCurrentFrame) {
|
|
|
|
AddFrame(aCurrentFrame);
|
|
|
|
return EstimateFps(aCurrentFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
double GetFpsAt(TimeStamp aNow) {
|
|
|
|
return EstimateFps(aNow);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
double EstimateFps(TimeStamp aNow) {
|
|
|
|
TimeStamp beginningOfWindow =
|
|
|
|
(aNow - TimeDuration::FromMilliseconds(kFpsWindowMs));
|
|
|
|
TimeStamp earliestFrameInWindow = aNow;
|
|
|
|
size_t numFramesDrawnInWindow = 0;
|
|
|
|
for (size_t i = 0; i < kNumFrameTimeStamps; ++i) {
|
|
|
|
const TimeStamp& frame = mFrames[i];
|
|
|
|
if (!frame.IsNull() && frame > beginningOfWindow) {
|
|
|
|
++numFramesDrawnInWindow;
|
|
|
|
earliestFrameInWindow = std::min(earliestFrameInWindow, frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
double realWindowSecs = (aNow - earliestFrameInWindow).ToSeconds();
|
|
|
|
if (realWindowSecs == 0.0 || numFramesDrawnInWindow == 1) {
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
return double(numFramesDrawnInWindow - 1) / realWindowSecs;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FPSState {
|
|
|
|
FPSCounter mCompositionFps;
|
|
|
|
FPSCounter mTransactionFps;
|
|
|
|
|
2014-02-10 14:14:11 -08:00
|
|
|
FPSState() {}
|
2013-11-01 08:51:32 -07:00
|
|
|
|
2014-02-10 14:14:11 -08:00
|
|
|
void DrawFPS(TimeStamp, unsigned, Compositor* aCompositor);
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
|
|
|
|
void NotifyShadowTreeTransaction() {
|
|
|
|
mTransactionFps.AddFrame(TimeStamp::Now());
|
|
|
|
}
|
2014-02-10 14:14:11 -08:00
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<DataTextureSource> mFPSTextureSource;
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2013-11-17 18:07:08 -08:00
|
|
|
|
|
|
|
#endif // mozilla_layers_opengl_FPSCounter_h_
|