not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kwin / scene_opengl.h
blob6be75c6ea63c360997f2012a5d7e8277afd6cdfc
1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
21 #ifndef KWIN_SCENE_OPENGL_H
22 #define KWIN_SCENE_OPENGL_H
24 #include "scene.h"
26 #include "kwinglutils.h"
28 #ifdef KWIN_HAVE_OPENGL_COMPOSITING
30 #ifdef HAVE_XSHM
31 #include <X11/extensions/XShm.h>
32 #endif
34 namespace KWin
37 class SceneOpenGL
38 : public Scene
40 public:
41 class Texture;
42 class Window;
43 SceneOpenGL( Workspace* ws );
44 virtual ~SceneOpenGL();
45 virtual bool initFailed() const;
46 virtual CompositingType compositingType() const { return OpenGLCompositing; }
47 virtual void paint( QRegion damage, ToplevelList windows );
48 virtual void windowGeometryShapeChanged( Toplevel* );
49 virtual void windowOpacityChanged( Toplevel* );
50 virtual void windowAdded( Toplevel* );
51 virtual void windowClosed( Toplevel*, Deleted* );
52 virtual void windowDeleted( Deleted* );
53 protected:
54 virtual void paintGenericScreen( int mask, ScreenPaintData data );
55 virtual void paintBackground( QRegion region );
56 private:
57 bool selectMode();
58 bool initTfp();
59 bool initShm();
60 void cleanupShm();
61 bool initBuffer();
62 bool initRenderingContext();
63 bool initBufferConfigs();
64 bool initDrawableConfigs();
65 void waitSync();
66 void flushBuffer( int mask, QRegion damage );
67 bool selfCheck();
68 GC gcroot;
69 class FBConfigInfo
71 public:
72 GLXFBConfig fbconfig;
73 int bind_texture_format;
74 int y_inverted;
75 int mipmap;
77 Drawable buffer;
78 GLXFBConfig fbcbuffer;
79 static bool db;
80 static GLXFBConfig fbcbuffer_db;
81 static GLXFBConfig fbcbuffer_nondb;
82 static FBConfigInfo fbcdrawableinfo[ 32 + 1 ];
83 static GLXDrawable glxbuffer;
84 static GLXContext ctxbuffer;
85 static GLXContext ctxdrawable;
86 static GLXDrawable last_pixmap; // for a workaround in bindTexture()
87 static bool tfp_mode;
88 static bool shm_mode;
89 QHash< Toplevel*, Window* > windows;
90 #ifdef HAVE_XSHM
91 static XShmSegmentInfo shm;
92 #endif
93 bool init_ok;
96 class SceneOpenGL::Texture
97 : public GLTexture
99 public:
100 Texture();
101 Texture( const Pixmap& pix, const QSize& size, int depth );
102 virtual ~Texture();
104 using GLTexture::load;
105 virtual bool load( const Pixmap& pix, const QSize& size, int depth,
106 QRegion region );
107 virtual bool load( const Pixmap& pix, const QSize& size, int depth );
108 virtual bool load( const QImage& image, GLenum target = GL_TEXTURE_2D );
109 virtual bool load( const QPixmap& pixmap, GLenum target = GL_TEXTURE_2D );
110 virtual void discard();
111 virtual void release(); // undo the tfp_mode binding
112 virtual void bind();
113 virtual void unbind();
115 protected:
116 void findTarget();
117 QRegion optimizeBindDamage( const QRegion& reg, int limit );
118 void createTexture();
120 private:
121 void init();
123 GLXPixmap bound_glxpixmap; // the glx pixmap the texture is bound to, only for tfp_mode
126 class SceneOpenGL::Window
127 : public Scene::Window
129 public:
130 Window( Toplevel* c );
131 virtual ~Window();
132 virtual void performPaint( int mask, QRegion region, WindowPaintData data );
133 virtual void pixmapDiscarded();
134 bool bindTexture();
135 void discardTexture();
136 void checkTextureSize();
138 protected:
139 void renderQuads( int mask, const QRegion& region, const WindowQuadList& quads );
140 void prepareStates( double opacity, double brightness, double saturation, GLShader* shader );
141 void prepareRenderStates( double opacity, double brightness, double saturation );
142 void prepareShaderRenderStates( double opacity, double brightness, double saturation, GLShader* shader );
143 void restoreStates( double opacity, double brightness, double saturation, GLShader* shader );
144 void restoreRenderStates( double opacity, double brightness, double saturation );
145 void restoreShaderRenderStates( double opacity, double brightness, double saturation, GLShader* shader );
147 private:
148 Texture texture;
151 } // namespace
153 #endif
155 #endif