aboutsummaryrefslogtreecommitdiff
path: root/util/fbcompose/OpenGLScreen.hh
blob: 1ab06081905d8a469cc3acd259727fd739f02215 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/** OpenGLScreen.hh file for the fluxbox compositor. */

// Copyright (c) 2011 Gediminas Liktaras (gliktaras at gmail dot com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.


#ifndef FBCOMPOSITOR_XRENDERAUTOSCREEN_HH
#define FBCOMPOSITOR_XRENDERAUTOSCREEN_HH


#include "BaseScreen.hh"
#include "OpenGLPlugin.hh"
#include "OpenGLShaders.hh"
#include "OpenGLTexPartitioner.hh"
#include "OpenGLWindow.hh"

#include <GL/glxew.h>
#include <GL/glx.h>


namespace FbCompositor {

    class BaseCompWindow;
    class CompositorConfig;


    /**
     * Manages screen in OpenGL rendering mode.
     */
    class OpenGLScreen : public BaseScreen {
    public:
        //--- CONSTRUCTORS AND DESTRUCTORS -------------------------------------

        /** Constructor. */
        OpenGLScreen(int screen_number, const CompositorConfig &config);

        /** Destructor. */
        ~OpenGLScreen();


        //--- OTHER INITIALIZATION ---------------------------------------------

        /** Initializes the screen's plugins. */
        void initPlugins(const CompositorConfig &config);


        //--- DEFAULT OPENGL OBJECT ACCESSORS ----------------------------------

        /** \returns the default element buffer (rectangle, corners in order of NW, NE, SW, SE). */
        OpenGLBufferPtr defaultElementBuffer() const;

        /** \returns the default primitive position buffer (four corners of the root window). */
        OpenGLBufferPtr defaultPrimPosBuffer() const;

        /** \returns the default texture position buffer (the whole texture). */
        OpenGLBufferPtr defaultTexCoordBuffer() const;


        /** \returns the default black texture. */
        OpenGL2DTexturePtr blackTexture() const;

        /** \returns the default white texture. */
        OpenGL2DTexturePtr whiteTexture() const;


        //--- OTHER ACCESSORS --------------------------------------------------

        /** \return the main GLX context. */
        GLXContext context() const;

        /** \returns the main GLXFBConfig. */
        GLXFBConfig fbConfig() const;

        /** \returns maximum supported texture size. */
        int maxTextureSize() const;


        //--- SCREEN MANIPULATION ----------------------------------------------

        /** Notifies the screen of the background change. */
        void setRootPixmapChanged();

        /** Notifies the screen of a root window change. */
        void setRootWindowSizeChanged();


        //--- SCREEN RENDERING -------------------------------------------------

        /** Renders the screen's contents. */
        void renderScreen();


    protected:
        //--- WINDOW MANIPULATION ----------------------------------------------

        /** Creates a window object from its XID. */
        BaseCompWindow *createWindowObject(Window window);


    private:
        //--- INITIALIZATION FUNCTIONS -----------------------------------------

        /** Creates OpenGL resources. */
        void createResources();

        /** Early initialization of GLX function pointers. */
        void earlyInitGLXPointers();

        /** Finds the maximum usable texture size. */
        void findMaxTextureSize();

        /** Finishes the initialization of the rendering context and surface. */
        void finishRenderingInit();

        /** Initializes GLEW. */
        void initGlew();

        /** Finish plugin initialization. */
        void initPlugins();

        /** Initializes the rendering context. */
        void initRenderingContext();

        /** Initializes the rendering surface. */
        void initRenderingSurface();


        //--- OTHER FUNCTIONS --------------------------------------------------

        /** Renews the background texture. */
        void updateBackgroundTexture();

        /** React to the geometry change of the root window. */
        void updateOnRootWindowResize();


        //--- RENDERING FUNCTIONS ----------------------------------------------

        /** Render the desktop background. */
        void renderBackground();

        /** Perform extra rendering jobs from plugins. */
        void renderExtraJobs();

        /** Render the reconfigure rectangle. */
        void renderReconfigureRect();

        /** Render a particular window onto the screen. */
        void renderWindow(OpenGLWindow &window);


        /** Execute multiple rendering jobs. */
        void executeMultipleJobs(OpenGLPlugin *plugin, const std::vector<OpenGLRenderingJob> &jobs);

        /** Execute a given rendering job. */
        void executeRenderingJob(const OpenGLRenderingJob &job);

        /** Render something onto the screen. */
        void render(GLenum rendering_mode, OpenGLBufferPtr prim_pos_buffer,
                    OpenGLBufferPtr main_tex_coord_buffer, OpenGL2DTexturePtr main_texture,
                    OpenGLBufferPtr shape_tex_coord_buffer, OpenGL2DTexturePtr shape_texture,
                    OpenGLBufferPtr element_buffer, GLuint element_count, GLfloat alpha);


        //--- MAIN RENDERING-RELATED VARIABLES ---------------------------------

        /** The main FBConfig. */
        GLXFBConfig m_fb_config;

        /** The GLX context. */
        GLXContext m_glx_context;

        /** Shaders. */
        OpenGLShaderProgramPtr m_shader_program;


        /** GLX handle to the rendering window. */
        GLXWindow m_glx_rendering_window;

        /** Rendering window. */
        Window m_rendering_window;

        /** Whether the root window has changed since the last update. */
        bool m_root_window_changed;


        //--- DESKTOP BACKGROUND RELATED ---------------------------------------

        /** The background texture. */
        OpenGL2DTexturePartitionPtr m_bg_texture;

        /** Position buffers of the background texture partitions. */
        std::vector<OpenGLBufferPtr> m_bg_pos_buffers;

        /** Whether the background changed since the last update. */
        bool m_bg_changed;


        //--- DEFAULT OPENGL ELEMENTS ------------------------------------------

        /** Default element buffer. */
        OpenGLBufferPtr m_default_element_buffer;

        /** Default primitive position buffer. */
        OpenGLBufferPtr m_default_prim_pos_buffer;

        /** Default texture position buffer. */
        OpenGLBufferPtr m_default_tex_coord_buffer;


        /** Default black texture. */
        OpenGL2DTexturePtr m_black_texture;

        /** Default white texture. */
        OpenGL2DTexturePtr m_white_texture;


        //--- RESIZE FRAME RELATED ---------------------------------------------

        /** The reconfigure rectangle element buffer. */
        OpenGLBufferPtr m_rec_rect_element_buffer;

        /** The reconfigure rectangle primitive position array buffer. */
        OpenGLBufferPtr m_rec_rect_line_pos_buffer;


        //--- OTHER VARIABLES --------------------------------------------------

        /** Whether we have a double-buffered window. */
        bool m_have_double_buffering;

        /** Maximum texture size. */
        int m_max_texture_size;
    };


    //--- INLINE FUNCTIONS -----------------------------------------------------

    // Returns the default black texture.
    inline OpenGL2DTexturePtr OpenGLScreen::blackTexture() const {
        return m_black_texture;
    }

    // Return the main GLX context.
    inline GLXContext OpenGLScreen::context() const {
        return m_glx_context;
    }

    // Returns the default element buffer.
    inline OpenGLBufferPtr OpenGLScreen::defaultElementBuffer() const {
        return m_default_element_buffer;
    }

    // Returns the default primitive position buffer.
    inline OpenGLBufferPtr OpenGLScreen::defaultPrimPosBuffer() const {
        return m_default_prim_pos_buffer;
    }

    // Returns the default texture position buffer.
    inline OpenGLBufferPtr OpenGLScreen::defaultTexCoordBuffer() const {
        return m_default_tex_coord_buffer;
    }

    // Returns the main GLXFBConfig.
    inline GLXFBConfig OpenGLScreen::fbConfig() const {
        return m_fb_config;
    }

    // Returns maximum supported texture size.
    inline int OpenGLScreen::maxTextureSize() const {
        return m_max_texture_size;
    }

    // Returns the default white texture.
    inline OpenGL2DTexturePtr OpenGLScreen::whiteTexture() const {
        return m_white_texture;
    }
}

#endif  // FBCOMPOSITOR_XRENDERAUTOSCREEN_HH