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 <algorithm> // for min
|
2014-05-09 06:50:00 -07:00
|
|
|
#include <stddef.h> // for size_t
|
|
|
|
#include <map> // for std::map
|
2013-08-11 16:17:23 -07:00
|
|
|
#include "GLDefs.h" // for GLuint
|
2014-05-09 06:50:00 -07:00
|
|
|
#include "mozilla/RefPtr.h" // for TemporaryRef, RefCounted
|
2013-08-11 16:17:23 -07:00
|
|
|
#include "mozilla/TimeStamp.h" // for TimeStamp, TimeDuration
|
|
|
|
#include "nsTArray.h" // for nsAutoTArray, nsTArray_Impl, etc
|
2014-05-09 06:50:00 -07:00
|
|
|
#include "prio.h" // for NSPR file i/o
|
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;
|
2014-05-09 06:50:00 -07:00
|
|
|
class Compositor;
|
|
|
|
|
|
|
|
// Dump the FPS histogram every 10 seconds or kMaxFrameFPS
|
|
|
|
const int kFpsDumpInterval = 10;
|
|
|
|
|
|
|
|
// On desktop, we can have 240 hz monitors, so 10 seconds
|
|
|
|
// times 240 frames = 2400
|
|
|
|
const int kMaxFrames = 2400;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The FPSCounter tracks how often we composite or have a layer transaction.
|
|
|
|
* At each composite / layer transaction, we record the timestamp.
|
|
|
|
* After kFpsDumpInterval number of composites / transactions, we calculate
|
|
|
|
* the average and standard deviation of frames composited. We dump a histogram,
|
|
|
|
* which allows for more statistically significant measurements. We also dump
|
|
|
|
* absolute frame composite times to a file on the device.
|
|
|
|
* The FPS counters displayed on screen are based on how many frames we
|
|
|
|
* composited within the last ~1 second. The more accurate measurement is to
|
|
|
|
* grab the histogram from stderr or grab the FPS timestamp dumps written to file.
|
|
|
|
*
|
|
|
|
* To enable dumping to file, enable
|
|
|
|
* layers.acceleration.draw-fps.write-to-file pref.
|
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
|
|
|
|
|
|
|
double AddFrameAndGetFps(TimeStamp aCurrentFrame) {
|
|
|
|
AddFrame(aCurrentFrame);
|
|
|
|
return EstimateFps(aCurrentFrame);
|
|
|
|
}
|
2014-05-09 06:50:00 -07:00
|
|
|
* To enable printing histogram data to logcat,
|
|
|
|
* enable layers.acceleration.draw-fps.print-histogram
|
|
|
|
*
|
|
|
|
* Use the HasNext(), GetNextTimeStamp() like an iterator to read the data,
|
|
|
|
* backwards in time. This abstracts away the mechanics of reading the data.
|
|
|
|
*/
|
|
|
|
class FPSCounter {
|
|
|
|
public:
|
|
|
|
FPSCounter(const char* aName);
|
|
|
|
~FPSCounter();
|
|
|
|
|
|
|
|
void AddFrame(TimeStamp aTimestamp);
|
|
|
|
double AddFrameAndGetFps(TimeStamp aTimestamp);
|
|
|
|
double GetFPS(TimeStamp aTimestamp);
|
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
|
|
|
|
|
|
|
private:
|
2014-05-09 06:50:00 -07:00
|
|
|
void Init();
|
|
|
|
bool CapturedFullInterval(TimeStamp aTimestamp);
|
|
|
|
|
|
|
|
// Used while iterating backwards over the data
|
|
|
|
void ResetReverseIterator();
|
|
|
|
bool HasNext(TimeStamp aTimestamp, double aDuration = kFpsDumpInterval);
|
|
|
|
TimeStamp GetNextTimeStamp();
|
|
|
|
int GetLatestReadIndex();
|
|
|
|
TimeStamp GetLatestTimeStamp();
|
|
|
|
void WriteFrameTimeStamps(PRFileDesc* fd);
|
|
|
|
bool IteratedFullInterval(TimeStamp aTimestamp, double aDuration);
|
|
|
|
|
|
|
|
void PrintFPS();
|
|
|
|
int BuildHistogram(std::map<int, int>& aHistogram);
|
|
|
|
void PrintHistogram(std::map<int, int>& aHistogram);
|
|
|
|
double GetMean(std::map<int,int> aHistogram);
|
|
|
|
double GetStdDev(std::map<int, int> aHistogram);
|
|
|
|
nsresult WriteFrameTimeStamps();
|
|
|
|
|
|
|
|
/***
|
|
|
|
* mFrameTimestamps is a psuedo circular buffer
|
|
|
|
* Since we have a constant write time and don't
|
|
|
|
* read at an offset except our latest write
|
|
|
|
* we don't need an explicit read pointer.
|
|
|
|
*/
|
|
|
|
nsAutoTArray<TimeStamp, kMaxFrames> mFrameTimestamps;
|
|
|
|
int mWriteIndex; // points to next open write slot
|
|
|
|
int mIteratorIndex; // used only when iterating
|
|
|
|
const char* mFPSName;
|
|
|
|
TimeStamp mLastInterval;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
struct FPSState {
|
2014-05-09 06:50:00 -07:00
|
|
|
FPSState();
|
2014-05-08 13:49:01 -07:00
|
|
|
void DrawFPS(TimeStamp, int offsetX, int offsetY, 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
|
|
|
|
2014-05-09 06:50:00 -07:00
|
|
|
FPSCounter mCompositionFps;
|
|
|
|
FPSCounter mTransactionFps;
|
|
|
|
|
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_
|