tools/qttracereplay/main.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
child 7 f7bc934e204c
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    54     void paintEvent(QPaintEvent *event);
    54     void paintEvent(QPaintEvent *event);
    55 
    55 
    56 public slots:
    56 public slots:
    57     void updateRect();
    57     void updateRect();
    58 
    58 
    59 private:
    59 public:
    60     QList<QRegion> updates;
    60     QList<QRegion> updates;
    61     QPaintBuffer buffer;
    61     QPaintBuffer buffer;
    62 
    62 
    63     int currentFrame;
    63     int currentFrame;
    64     int currentIteration;
    64     int currentIteration;
    68     QString filename;
    68     QString filename;
    69 };
    69 };
    70 
    70 
    71 void ReplayWidget::updateRect()
    71 void ReplayWidget::updateRect()
    72 {
    72 {
    73     update(updates.at(currentFrame));
    73     if (!updates.isEmpty())
       
    74         update(updates.at(currentFrame));
    74 }
    75 }
    75 
    76 
    76 void ReplayWidget::paintEvent(QPaintEvent *)
    77 void ReplayWidget::paintEvent(QPaintEvent *)
    77 {
    78 {
    78     QPainter p(this);
    79     QPainter p(this);
   136 {
   137 {
   137     setWindowTitle(filename);
   138     setWindowTitle(filename);
   138     QFile file(filename);
   139     QFile file(filename);
   139 
   140 
   140     QRect bounds;
   141     QRect bounds;
   141     if (file.open(QIODevice::ReadOnly)) {
   142     if (!file.open(QIODevice::ReadOnly)) {
   142         QDataStream in(&file);
   143         printf("Failed to load input file '%s'\n", qPrintable(filename_));
   143         in >> buffer >> updates;
   144         return;
   144     }
   145     }
   145 
   146 
   146     qDebug() << "Read paint buffer with" << buffer.numFrames() << "frames";
   147     QDataStream in(&file);
       
   148 
       
   149     char *data;
       
   150     uint size;
       
   151     in.readBytes(data, size);
       
   152     bool isTraceFile = size == 7 && qstrncmp(data, "qttrace", 7) == 0;
       
   153     delete [] data;
       
   154     if (!isTraceFile) {
       
   155         printf("File '%s' is not a trace file\n", qPrintable(filename_));
       
   156         return;
       
   157     }
       
   158 
       
   159     in >> buffer >> updates;
       
   160     printf("Read paint buffer with %d frames\n", buffer.numFrames());
   147 
   161 
   148     resize(buffer.boundingRect().size().toSize());
   162     resize(buffer.boundingRect().size().toSize());
   149 
   163 
   150     setAutoFillBackground(false);
   164     setAutoFillBackground(false);
   151     setAttribute(Qt::WA_NoSystemBackground);
   165     setAttribute(Qt::WA_NoSystemBackground);
   155 
   169 
   156 int main(int argc, char **argv)
   170 int main(int argc, char **argv)
   157 {
   171 {
   158     QApplication app(argc, argv);
   172     QApplication app(argc, argv);
   159 
   173 
   160     if (argc <= 1) {
   174     if (argc <= 1 || qstrcmp(argv[1], "-h") == 0 || qstrcmp(argv[1], "--help") == 0) {
   161         printf("Usage: %s filename\n", argv[0]);
   175         printf("Replays a tracefile generated with '-graphicssystem trace'\n");
       
   176         printf("Usage:\n  > %s [traceFile]\n", argv[0]);
       
   177         return 1;
       
   178     }
       
   179 
       
   180     QFile file(argv[1]);
       
   181     if (!file.exists()) {
       
   182         printf("%s does not exist\n", argv[1]);
   162         return 1;
   183         return 1;
   163     }
   184     }
   164 
   185 
   165     ReplayWidget *widget = new ReplayWidget(argv[1]);
   186     ReplayWidget *widget = new ReplayWidget(argv[1]);
   166     widget->show();
       
   167 
   187 
   168     return app.exec();
   188     if (!widget->updates.isEmpty()) {
       
   189         widget->show();
       
   190         return app.exec();
       
   191     }
       
   192 
   169 }
   193 }
   170 #include "main.moc"
   194 #include "main.moc"