mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-07-29 12:18:39 +00:00
增加帧率统计
This commit is contained in:
parent
c4931a813b
commit
df81adcb22
3 changed files with 110 additions and 2 deletions
|
@ -33,7 +33,8 @@ SOURCES += \
|
|||
server.cpp \
|
||||
convert.cpp \
|
||||
frames.cpp \
|
||||
yuvglwidget.cpp
|
||||
yuvglwidget.cpp \
|
||||
fpscounter.cpp
|
||||
|
||||
HEADERS += \
|
||||
dialog.h \
|
||||
|
@ -42,7 +43,8 @@ HEADERS += \
|
|||
server.h \
|
||||
convert.h \
|
||||
frames.h \
|
||||
yuvglwidget.h
|
||||
yuvglwidget.h \
|
||||
fpscounter.h
|
||||
|
||||
FORMS += \
|
||||
dialog.ui
|
||||
|
|
74
src/fpscounter.cpp
Normal file
74
src/fpscounter.cpp
Normal file
|
@ -0,0 +1,74 @@
|
|||
#include <QDebug>
|
||||
|
||||
#include "fpscounter.h"
|
||||
|
||||
FpsCounter::FpsCounter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
FpsCounter::~FpsCounter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FpsCounter::fpsCounterInit()
|
||||
{
|
||||
m_started = false;
|
||||
// no need to initialize the other fields, they are meaningful only when
|
||||
// started is true
|
||||
}
|
||||
|
||||
void FpsCounter::fpsCounterStart()
|
||||
{
|
||||
m_started = true;
|
||||
m_timeCounter.start();
|
||||
m_rendered = 0;
|
||||
#ifdef SKIP_FRAMES
|
||||
m_skipped = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void FpsCounter::fpsCounterStop()
|
||||
{
|
||||
m_started = false;
|
||||
}
|
||||
|
||||
void FpsCounter::fpsCounterAddRenderedFrame()
|
||||
{
|
||||
checkExpired();
|
||||
m_rendered++;
|
||||
}
|
||||
|
||||
void FpsCounter::checkExpired()
|
||||
{
|
||||
if (m_timeCounter.elapsed() >= 1000) {
|
||||
displayFps();
|
||||
m_timeCounter.restart();
|
||||
m_rendered = 0;
|
||||
#ifdef SKIP_FRAMES
|
||||
m_skipped = 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void FpsCounter::displayFps()
|
||||
{
|
||||
#ifdef SKIP_FRAMES
|
||||
if (m_skipped) {
|
||||
//qInfo << "%d fps (+%d frames skipped)", m_rendered, m_skipped);
|
||||
} else {
|
||||
#endif
|
||||
//qInfo m_rendered << "fps";
|
||||
#ifdef SKIP_FRAMES
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef SKIP_FRAMES
|
||||
void FpsCounter::fpsCounterAddSkippedFrame()
|
||||
{
|
||||
checkExpired();
|
||||
m_skipped++;
|
||||
}
|
||||
#endif
|
32
src/fpscounter.h
Normal file
32
src/fpscounter.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
#ifndef FPSCOUNTER_H
|
||||
#define FPSCOUNTER_H
|
||||
#include <QTime>
|
||||
|
||||
class FpsCounter
|
||||
{
|
||||
public:
|
||||
FpsCounter();
|
||||
virtual ~FpsCounter();
|
||||
|
||||
void fpsCounterInit();
|
||||
void fpsCounterStart();
|
||||
void fpsCounterStop();
|
||||
void fpsCounterAddRenderedFrame();
|
||||
#ifdef SKIP_FRAMES
|
||||
void fpsCounterAddSkippedFrame();
|
||||
#endif
|
||||
|
||||
private:
|
||||
void checkExpired();
|
||||
void displayFps();
|
||||
|
||||
private:
|
||||
bool m_started = false;
|
||||
QTime m_timeCounter;
|
||||
quint32 m_rendered = 0;
|
||||
#ifdef SKIP_FRAMES
|
||||
quint32 m_skipped = 0;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // FPSCOUNTER_H
|
Loading…
Add table
Add a link
Reference in a new issue