From 971fe0107cd783e76fb21ca392f8012d88ff797f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCbking?= Date: Sun, 4 Aug 2013 14:50:38 +0200 Subject: [PATCH] support fps counter text on xrender BUG: 323006 FIXED-IN: 4.11 REVIEW: 111878 --- effects/showfps/showfps.cpp | 40 +++++++++++++++++++++++-------------- effects/showfps/showfps.h | 2 +- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/effects/showfps/showfps.cpp b/effects/showfps/showfps.cpp index 0439941b23..1ab7d57f6d 100644 --- a/effects/showfps/showfps.cpp +++ b/effects/showfps/showfps.cpp @@ -232,7 +232,18 @@ void ShowFpsEffect::paintGL(int fps) paintDrawSizeGraph(x, y); // Paint FPS numerical value - paintFPSText(fps); + if (fpsTextRect.isValid()) { + delete fpsText; + fpsText = new GLTexture(fpsTextImage(fps)); + fpsText->bind(); + ShaderBinder binder(ShaderManager::SimpleShader); + if (effects->compositingType() == OpenGL2Compositing) { + binder.shader()->setUniform("offset", QVector2D(0, 0)); + } + fpsText->render(QRegion(fpsTextRect), fpsTextRect); + fpsText->unbind(); + effects->addRepaint(fpsTextRect); + } // Paint paint sizes glDisable(GL_BLEND); @@ -284,6 +295,15 @@ void ShowFpsEffect::paintXrender(int fps) // Paint amount of rendered pixels graph paintDrawSizeGraph(x + FPS_WIDTH + MAX_TIME, y); + + // Paint FPS numerical value + if (fpsTextRect.isValid()) { + QImage textImg(fpsTextImage(fps)); + XRenderPicture textPic(textImg); + xcb_render_composite(connection(), XCB_RENDER_PICT_OP_OVER, textPic, XCB_RENDER_PICTURE_NONE, + effects->xrenderBufferPicture(), 0, 0, 0, 0, fpsTextRect.x(), fpsTextRect.y(), textImg.width(), textImg.height()); + effects->addRepaint(fpsTextRect); + } } #endif @@ -450,26 +470,16 @@ void ShowFpsEffect::postPaintScreen() effects->addRepaint(fps_rect); } -void ShowFpsEffect::paintFPSText(int fps) +QImage ShowFpsEffect::fpsTextImage(int fps) { - if (!fpsTextRect.isValid()) - return; QImage im(100, 100, QImage::Format_ARGB32); - im.fill(0); + im.fill(Qt::transparent); QPainter painter(&im); painter.setFont(textFont); painter.setPen(textColor); painter.drawText(QRect(0, 0, 100, 100), textAlign, QString::number(fps)); - delete fpsText; - fpsText = new GLTexture(im); - fpsText->bind(); - ShaderBinder binder(ShaderManager::SimpleShader); - if (effects->compositingType() == OpenGL2Compositing) { - binder.shader()->setUniform("offset", QVector2D(0, 0)); - } - fpsText->render(QRegion(fpsTextRect), fpsTextRect); - fpsText->unbind(); - effects->addRepaint(fpsTextRect); + painter.end(); + return im; } } // namespace diff --git a/effects/showfps/showfps.h b/effects/showfps/showfps.h index 5f46d0c5d5..3c30c39be0 100644 --- a/effects/showfps/showfps.h +++ b/effects/showfps/showfps.h @@ -80,7 +80,7 @@ private: void paintFPSGraph(int x, int y); void paintDrawSizeGraph(int x, int y); void paintGraph(int x, int y, QList values, QList lines, bool colorize); - void paintFPSText(int fps); + QImage fpsTextImage(int fps); QTime t; enum { NUM_PAINTS = 100 }; // remember time needed to paint this many paints int paints[ NUM_PAINTS ]; // time needed to paint