2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
|
2011-03-27 10:33:07 +00:00
|
|
|
Copyright (C) 2009, 2010, 2011 Martin Gräßlin <mgraesslin@kde.org>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#ifndef KWIN_SCENE_OPENGL_H
|
|
|
|
#define KWIN_SCENE_OPENGL_H
|
|
|
|
|
|
|
|
#include "scene.h"
|
2011-03-27 10:33:07 +00:00
|
|
|
#include "shadow.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include "kwinglutils.h"
|
2011-07-18 15:55:39 +00:00
|
|
|
#include "kwingltexture_p.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_XSHM
|
|
|
|
#include <X11/extensions/XShm.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
class SceneOpenGL
|
|
|
|
: public Scene
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-06-15 16:35:00 +00:00
|
|
|
Q_OBJECT
|
2011-01-30 14:34:42 +00:00
|
|
|
public:
|
|
|
|
class EffectFrame;
|
|
|
|
class Texture;
|
2011-07-18 15:55:39 +00:00
|
|
|
class TexturePrivate;
|
2011-01-30 14:34:42 +00:00
|
|
|
class Window;
|
|
|
|
SceneOpenGL(Workspace* ws);
|
|
|
|
virtual ~SceneOpenGL();
|
|
|
|
virtual bool initFailed() const;
|
|
|
|
virtual CompositingType compositingType() const {
|
|
|
|
return OpenGLCompositing;
|
|
|
|
}
|
|
|
|
virtual void paint(QRegion damage, ToplevelList windows);
|
|
|
|
virtual void windowAdded(Toplevel*);
|
|
|
|
virtual void windowDeleted(Deleted*);
|
2011-02-17 17:37:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
protected:
|
|
|
|
virtual void paintGenericScreen(int mask, ScreenPaintData data);
|
|
|
|
virtual void paintBackground(QRegion region);
|
2011-02-17 17:37:43 +00:00
|
|
|
QMatrix4x4 transformation(int mask, const ScreenPaintData &data) const;
|
2011-06-19 20:18:21 +00:00
|
|
|
public Q_SLOTS:
|
2011-06-15 17:13:56 +00:00
|
|
|
virtual void windowOpacityChanged(KWin::Toplevel* c);
|
2011-06-19 20:07:19 +00:00
|
|
|
virtual void windowGeometryShapeChanged(KWin::Toplevel* c);
|
2011-06-21 10:30:42 +00:00
|
|
|
virtual void windowClosed(KWin::Toplevel* c, KWin::Deleted* deleted);
|
2011-01-30 14:34:42 +00:00
|
|
|
private:
|
|
|
|
bool selectMode();
|
|
|
|
bool initTfp();
|
|
|
|
bool initBuffer();
|
|
|
|
bool initRenderingContext();
|
|
|
|
bool initBufferConfigs();
|
|
|
|
bool initDrawableConfigs();
|
|
|
|
void waitSync();
|
|
|
|
void flushBuffer(int mask, QRegion damage);
|
|
|
|
GC gcroot;
|
|
|
|
class FBConfigInfo
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
public:
|
2010-11-20 12:27:47 +00:00
|
|
|
#ifndef KWIN_HAVE_OPENGLES
|
2011-01-30 14:34:42 +00:00
|
|
|
GLXFBConfig fbconfig;
|
2010-11-20 12:27:47 +00:00
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
int bind_texture_format;
|
|
|
|
int texture_targets;
|
|
|
|
int y_inverted;
|
|
|
|
int mipmap;
|
|
|
|
};
|
2010-11-20 12:27:47 +00:00
|
|
|
#ifndef KWIN_HAVE_OPENGLES
|
2011-01-30 14:34:42 +00:00
|
|
|
Drawable buffer;
|
|
|
|
GLXFBConfig fbcbuffer;
|
2010-11-20 12:27:47 +00:00
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
static bool db;
|
2010-11-20 12:27:47 +00:00
|
|
|
#ifndef KWIN_HAVE_OPENGLES
|
2011-01-30 14:34:42 +00:00
|
|
|
static GLXFBConfig fbcbuffer_db;
|
|
|
|
static GLXFBConfig fbcbuffer_nondb;
|
|
|
|
static FBConfigInfo fbcdrawableinfo[ 32 + 1 ];
|
|
|
|
static GLXDrawable glxbuffer;
|
|
|
|
static GLXContext ctxbuffer;
|
|
|
|
static GLXContext ctxdrawable;
|
|
|
|
static GLXDrawable last_pixmap; // for a workaround in bindTexture()
|
2010-11-20 12:27:47 +00:00
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
QHash< Toplevel*, Window* > windows;
|
|
|
|
bool init_ok;
|
|
|
|
bool debug;
|
|
|
|
};
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-07-18 15:55:39 +00:00
|
|
|
class SceneOpenGL::TexturePrivate
|
|
|
|
: public GLTexturePrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TexturePrivate();
|
|
|
|
virtual ~TexturePrivate();
|
|
|
|
|
|
|
|
virtual void bind();
|
|
|
|
virtual void unbind();
|
|
|
|
virtual void release();
|
|
|
|
|
|
|
|
#ifndef KWIN_HAVE_OPENGLES
|
|
|
|
GLXPixmap m_glxpixmap; // the glx pixmap the texture is bound to, only for tfp_mode
|
|
|
|
#endif
|
|
|
|
private:
|
|
|
|
Q_DISABLE_COPY(TexturePrivate)
|
|
|
|
};
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
class SceneOpenGL::Texture
|
|
|
|
: public GLTexture
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Texture();
|
2011-07-18 15:55:39 +00:00
|
|
|
Texture(const Texture& tex);
|
2011-05-12 16:52:38 +00:00
|
|
|
Texture(const QPixmap& pix, GLenum target = GL_TEXTURE_2D);
|
2011-01-30 14:34:42 +00:00
|
|
|
virtual ~Texture();
|
|
|
|
|
2011-07-18 15:55:39 +00:00
|
|
|
Texture & operator = (const Texture& tex);
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
using GLTexture::load;
|
|
|
|
virtual bool load(const QImage& image, GLenum target = GL_TEXTURE_2D);
|
|
|
|
virtual bool load(const QPixmap& pixmap, GLenum target = GL_TEXTURE_2D);
|
|
|
|
virtual void discard();
|
|
|
|
|
|
|
|
protected:
|
2011-05-12 16:52:38 +00:00
|
|
|
Texture(const Pixmap& pix, const QSize& size, int depth);
|
2011-01-30 14:34:42 +00:00
|
|
|
void findTarget();
|
2011-05-12 16:52:38 +00:00
|
|
|
virtual bool load(const Pixmap& pix, const QSize& size, int depth,
|
|
|
|
QRegion region);
|
|
|
|
virtual bool load(const Pixmap& pix, const QSize& size, int depth);
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2011-07-18 15:55:39 +00:00
|
|
|
Texture(TexturePrivate& dd);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-07-18 15:55:39 +00:00
|
|
|
private:
|
2011-08-27 07:31:38 +00:00
|
|
|
Q_DECLARE_PRIVATE(Texture)
|
2011-05-12 16:52:38 +00:00
|
|
|
|
|
|
|
friend class SceneOpenGL::Window;
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
class SceneOpenGL::Window
|
|
|
|
: public Scene::Window
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Window(Toplevel* c);
|
|
|
|
virtual ~Window();
|
|
|
|
virtual void performPaint(int mask, QRegion region, WindowPaintData data);
|
|
|
|
virtual void pixmapDiscarded();
|
|
|
|
bool bindTexture();
|
|
|
|
void discardTexture();
|
|
|
|
void checkTextureSize();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
enum TextureType {
|
|
|
|
Content,
|
|
|
|
DecorationTop,
|
|
|
|
DecorationLeft,
|
|
|
|
DecorationRight,
|
2011-03-27 10:33:07 +00:00
|
|
|
DecorationBottom,
|
|
|
|
Shadow
|
2007-04-29 17:35:43 +00:00
|
|
|
};
|
2011-02-15 17:10:54 +00:00
|
|
|
|
|
|
|
QMatrix4x4 transformation(int mask, const WindowPaintData &data) const;
|
2011-01-30 14:34:42 +00:00
|
|
|
void paintDecoration(const QPixmap* decoration, TextureType decorationType, const QRegion& region, const QRect& rect, const WindowPaintData& data, const WindowQuadList& quads, bool updateDeco);
|
2011-06-23 17:06:12 +00:00
|
|
|
void paintShadow(const QRegion ®ion, const WindowPaintData &data);
|
2011-07-01 16:04:15 +00:00
|
|
|
void makeDecorationArrays(const WindowQuadList& quads, const QRect &rect, Texture *tex) const;
|
2011-06-23 17:06:12 +00:00
|
|
|
void renderQuads(int, const QRegion& region, const WindowQuadList& quads, GLTexture* tex, bool normalized = false);
|
2011-01-30 14:34:42 +00:00
|
|
|
void prepareStates(TextureType type, double opacity, double brightness, double saturation, GLShader* shader);
|
2011-06-23 17:06:12 +00:00
|
|
|
void prepareStates(TextureType type, double opacity, double brightness, double saturation, GLShader* shader, GLTexture *texture);
|
|
|
|
void prepareRenderStates(TextureType type, double opacity, double brightness, double saturation, GLTexture *tex);
|
2011-01-30 14:34:42 +00:00
|
|
|
void prepareShaderRenderStates(TextureType type, double opacity, double brightness, double saturation, GLShader* shader);
|
|
|
|
void restoreStates(TextureType type, double opacity, double brightness, double saturation, GLShader* shader);
|
2011-06-23 17:06:12 +00:00
|
|
|
void restoreStates(TextureType type, double opacity, double brightness, double saturation, GLShader* shader, GLTexture *texture);
|
|
|
|
void restoreRenderStates(TextureType type, double opacity, double brightness, double saturation, GLTexture *tex);
|
2011-01-30 14:34:42 +00:00
|
|
|
void restoreShaderRenderStates(TextureType type, double opacity, double brightness, double saturation, GLShader* shader);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Texture texture;
|
|
|
|
Texture topTexture;
|
|
|
|
Texture leftTexture;
|
|
|
|
Texture rightTexture;
|
|
|
|
Texture bottomTexture;
|
|
|
|
};
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-07-18 16:32:37 +00:00
|
|
|
class SceneOpenGL::EffectFrame
|
|
|
|
: public Scene::EffectFrame
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
EffectFrame(EffectFrameImpl* frame);
|
|
|
|
virtual ~EffectFrame();
|
|
|
|
|
|
|
|
virtual void free();
|
|
|
|
virtual void freeIconFrame();
|
|
|
|
virtual void freeTextFrame();
|
|
|
|
virtual void freeSelection();
|
|
|
|
|
|
|
|
virtual void render(QRegion region, double opacity, double frameOpacity);
|
|
|
|
|
|
|
|
virtual void crossFadeIcon();
|
|
|
|
virtual void crossFadeText();
|
|
|
|
|
|
|
|
static void cleanup();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void updateTexture();
|
|
|
|
void updateTextTexture();
|
|
|
|
|
|
|
|
Texture* m_texture;
|
|
|
|
Texture* m_textTexture;
|
|
|
|
Texture* m_oldTextTexture;
|
|
|
|
QPixmap* m_textPixmap; // need to keep the pixmap around to workaround some driver problems
|
|
|
|
Texture* m_iconTexture;
|
|
|
|
Texture* m_oldIconTexture;
|
|
|
|
Texture* m_selectionTexture;
|
|
|
|
GLVertexBuffer* m_unstyledVBO;
|
|
|
|
|
|
|
|
static Texture* m_unstyledTexture;
|
|
|
|
static QPixmap* m_unstyledPixmap; // need to keep the pixmap around to workaround some driver problems
|
|
|
|
static void updateUnstyledTexture(); // Update OpenGL unstyled frame texture
|
|
|
|
};
|
2010-07-18 16:32:37 +00:00
|
|
|
|
2011-03-27 10:33:07 +00:00
|
|
|
/**
|
|
|
|
* @short OpenGL implementation of Shadow.
|
|
|
|
*
|
|
|
|
* This class extends Shadow by the Elements required for OpenGL rendering.
|
|
|
|
* @author Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
**/
|
|
|
|
class SceneOpenGLShadow
|
|
|
|
: public Shadow
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SceneOpenGLShadow(Toplevel *toplevel);
|
|
|
|
virtual ~SceneOpenGLShadow();
|
|
|
|
|
2011-06-23 17:06:12 +00:00
|
|
|
GLTexture *shadowTexture() {
|
|
|
|
return m_texture;
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
virtual void buildQuads();
|
|
|
|
virtual bool prepareBackend();
|
2011-03-27 10:33:07 +00:00
|
|
|
private:
|
2011-06-23 17:06:12 +00:00
|
|
|
GLTexture *m_texture;
|
2011-03-27 10:33:07 +00:00
|
|
|
};
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif
|