Commit 34f37400 authored by Martin Flöser's avatar Martin Flöser

ShowFPS effect ported to GLES

parent d467fc1b
......@@ -72,6 +72,7 @@ include( minimizeanimation/CMakeLists.txt )
include( presentwindows/CMakeLists.txt )
include( resize/CMakeLists.txt )
include( scalein/CMakeLists.txt )
include( showfps/CMakeLists.txt )
include( showpaint/CMakeLists.txt )
include( slide/CMakeLists.txt )
include( slideback/CMakeLists.txt )
......@@ -84,7 +85,6 @@ include( zoom/CMakeLists.txt )
if( NOT KWIN_HAVE_OPENGLES_COMPOSITING )
include( logout/CMakeLists.txt )
include( shadow/CMakeLists.txt )
include( showfps/CMakeLists.txt )
endif( NOT KWIN_HAVE_OPENGLES_COMPOSITING )
# OpenGL-specific effects
......
......@@ -30,12 +30,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "translucency/translucency_config.h"
#include "presentwindows/presentwindows_config.h"
#include "resize/resize_config.h"
#include "showfps/showfps_config.h"
#include "thumbnailaside/thumbnailaside_config.h"
#include "zoom/zoom_config.h"
#ifndef KWIN_HAVE_OPENGLES
#include "shadow/shadow_config.h"
#include "showfps/showfps_config.h"
#endif
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
......@@ -72,12 +72,12 @@ KWIN_EFFECT_CONFIG_MULTIPLE( builtins,
KWIN_EFFECT_CONFIG_SINGLE( magiclamp, MagicLampEffectConfig )
KWIN_EFFECT_CONFIG_SINGLE( presentwindows, PresentWindowsEffectConfig )
KWIN_EFFECT_CONFIG_SINGLE( resize, ResizeEffectConfig )
KWIN_EFFECT_CONFIG_SINGLE( showfps, ShowFpsEffectConfig )
KWIN_EFFECT_CONFIG_SINGLE( translucency, TranslucencyEffectConfig )
KWIN_EFFECT_CONFIG_SINGLE( thumbnailaside, ThumbnailAsideEffectConfig )
KWIN_EFFECT_CONFIG_SINGLE( zoom, ZoomEffectConfig )
#ifndef KWIN_HAVE_OPENGLES
KWIN_EFFECT_CONFIG_SINGLE( shadow, ShadowEffectConfig )
KWIN_EFFECT_CONFIG_SINGLE( showfps, ShowFpsEffectConfig )
#endif
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
......
......@@ -38,6 +38,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <math.h>
#include <QPainter>
#include <QVector2D>
namespace KWin
{
......@@ -184,38 +185,58 @@ void ShowFpsEffect::paintGL( int fps )
{
int x = this->x;
int y = this->y;
#ifndef KWIN_HAVE_OPENGLES
glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT );
#endif
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
// TODO painting first the background white and then the contents
// means that the contents also blend with the background, I guess
glColor4f( 1, 1, 1, alpha ); // white
glBegin( GL_QUADS );
glVertex2i( x, y );
glVertex2i( x + 2*NUM_PAINTS + FPS_WIDTH, y );
glVertex2i( x + 2*NUM_PAINTS + FPS_WIDTH, y + MAX_TIME );
glVertex2i( x, y + MAX_TIME );
glEnd();
if (ShaderManager::instance()->isValid()) {
ShaderManager::instance()->pushShader(ShaderManager::ColorShader);
}
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
vbo->reset();
QColor color(255, 255, 255);
color.setAlphaF(alpha);
vbo->setColor(color);
QVector<float> verts;
verts.reserve(12);
verts << x + 2*NUM_PAINTS + FPS_WIDTH << y;
verts << x << y;
verts << x << y + MAX_TIME;
verts << x << y + MAX_TIME;
verts << x + 2*NUM_PAINTS + FPS_WIDTH << y + MAX_TIME;
verts << x + 2*NUM_PAINTS + FPS_WIDTH << y;
vbo->setData(6, 2, verts.constData(), NULL);
vbo->render(GL_TRIANGLES);
y += MAX_TIME; // paint up from the bottom
glBegin( GL_QUADS );
glColor4f( 0, 0, 1, alpha ); // blue
glVertex2i( x, y );
glVertex2i( x + FPS_WIDTH, y );
glVertex2i( x + FPS_WIDTH, y - fps );
glVertex2i( x, y - fps );
glEnd();
glColor4f( 0, 0, 0, alpha ); // black
glBegin( GL_LINES );
color.setRed(0);
color.setGreen(0);
vbo->setColor(color);
verts.clear();
verts << x + FPS_WIDTH << y - fps;
verts << x << y - fps;
verts << x << y;
verts << x << y;
verts << x + FPS_WIDTH << y;
verts << x + FPS_WIDTH << y - fps;
vbo->setData(6, 2, verts.constData(), NULL);
vbo->render(GL_TRIANGLES);
color.setBlue(0);
vbo->setColor(color);
QVector<float> vertices;
for( int i = 10;
i < MAX_TIME;
i += 10 )
{
glVertex2i( x, y - i );
glVertex2i( x + FPS_WIDTH, y - i );
vertices << x << y - i;
vertices << x + FPS_WIDTH << y - i;
}
glEnd();
vbo->setData(vertices.size()/2, 2, vertices.constData(), NULL);
vbo->render(GL_LINES);
x += FPS_WIDTH;
// Paint FPS graph
......@@ -224,12 +245,18 @@ void ShowFpsEffect::paintGL( int fps )
// Paint amount of rendered pixels graph
paintDrawSizeGraph( x, y );
if (ShaderManager::instance()->isValid()) {
ShaderManager::instance()->popShader();
}
// Paint FPS numerical value
paintFPSText(fps);
// Paint paint sizes
glDisable(GL_BLEND);
#ifndef KWIN_HAVE_OPENGLES
glPopAttrib();
#endif
}
#endif
......@@ -328,34 +355,50 @@ void ShowFpsEffect::paintGraph( int x, int y, QList<int> values, QList<int> line
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
if( effects->compositingType() == OpenGLCompositing)
{
glColor4f( 0, 0, 0, alpha ); // black
glBegin( GL_LINES );
QColor color(0, 0, 0);
color.setAlphaF(alpha);
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
vbo->reset();
vbo->setColor(color);
QVector<float> verts;
// First draw the lines
foreach( int h, lines)
{
glVertex2i( x, y - h );
glVertex2i( x + values.count(), y - h );
verts << x << y - h;
verts << x + values.count() << y - h;
}
vbo->setData(verts.size()/2, 2, verts.constData(), NULL);
vbo->render(GL_LINES);
// Then the graph values
glColor4f( 0.5, 0.5, 0.5, alpha );
for( int i = 0; i < values.count(); i++ )
{
int lastValue = 0;
verts.clear();
for (int i = 0; i < values.count(); i++) {
int value = values[ i ];
if( colorize )
{
if( value <= 10 )
glColor4f( 0, 1, 0, alpha ); // green
else if( value <= 20 )
glColor4f( 1, 1, 0, alpha ); // yellow
else if( value <= 50 )
glColor4f( 1, 0, 0, alpha ); // red
else
glColor4f( 0, 0, 0, alpha ); // black
if (colorize && value != lastValue) {
if (!verts.isEmpty()) {
vbo->setData(verts.size()/2, 2, verts.constData(), NULL);
vbo->render(GL_LINES);
}
verts.clear();
if (value <= 10) {
color = QColor(0, 255, 0);
} else if (value <= 20) {
color= QColor(255, 255, 0);
} else if( value <= 50 ) {
color = QColor(255, 0, 0);
} else {
color = QColor(0, 0, 0);
}
glVertex2i( x + values.count() - i, y );
glVertex2i( x + values.count() - i, y - value );
vbo->setColor(color);
}
glEnd();
verts << x + values.count() - i << y;
verts << x + values.count() - i << y - value;
lastValue = value;
}
if (!verts.isEmpty()) {
vbo->setData(verts.size()/2, 2, verts.constData(), NULL);
vbo->render(GL_LINES);
}
}
#endif
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
......@@ -443,7 +486,14 @@ void ShowFpsEffect::paintFPSText(int fps)
delete fpsText;
fpsText = new GLTexture(im);
fpsText->bind();
if (ShaderManager::instance()->isValid()) {
GLShader *shader = ShaderManager::instance()->pushShader(ShaderManager::SimpleShader);
shader->setUniform("offset", QVector2D(0, 0));
}
fpsText->render(QRegion(fpsTextRect), fpsTextRect);
if (ShaderManager::instance()->isValid()) {
ShaderManager::instance()->popShader();
}
fpsText->unbind();
effects->addRepaint(fpsTextRect);
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment