~mc-return/compiz/compiz.merge-src-screen.cpp-improvements

« back to all changes in this revision

Viewing changes to plugins/opengl/window.cpp

  • Committer: Dennis kasprzyk
  • Author(s): Dennis Kasprzyk
  • Date: 2009-03-15 05:09:18 UTC
  • Revision ID: git-v1:163f6b6f3c3b7764987cbdf8e03cc355edeaa499
New generalized build system.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2008 Dennis Kasprzyk
3
 
 * Copyright © 2007 Novell, Inc.
4
 
 *
5
 
 * Permission to use, copy, modify, distribute, and sell this software
6
 
 * and its documentation for any purpose is hereby granted without
7
 
 * fee, provided that the above copyright notice appear in all copies
8
 
 * and that both that copyright notice and this permission notice
9
 
 * appear in supporting documentation, and that the name of
10
 
 * Dennis Kasprzyk not be used in advertising or publicity pertaining to
11
 
 * distribution of the software without specific, written prior permission.
12
 
 * Dennis Kasprzyk makes no representations about the suitability of this
13
 
 * software for any purpose. It is provided "as is" without express or
14
 
 * implied warranty.
15
 
 *
16
 
 * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17
 
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
18
 
 * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19
 
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
20
 
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
21
 
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
22
 
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23
 
 *
24
 
 * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
25
 
 *          David Reveman <davidr@novell.com>
26
 
 */
27
 
 
28
 
#include "privates.h"
29
 
 
30
 
GLWindow::GLWindow (CompWindow *w) :
31
 
    PrivateHandler<GLWindow, CompWindow, COMPIZ_OPENGL_ABI> (w),
32
 
    priv (new PrivateGLWindow (w, this))
33
 
{
34
 
    CompositeWindow *cw = CompositeWindow::get (w);
35
 
        
36
 
    priv->paint.opacity    = cw->opacity ();
37
 
    priv->paint.brightness = cw->brightness ();
38
 
    priv->paint.saturation = cw->saturation ();
39
 
 
40
 
    priv->lastPaint = priv->paint;
41
 
 
42
 
}
43
 
 
44
 
GLWindow::~GLWindow ()
45
 
{
46
 
    delete priv;
47
 
}
48
 
 
49
 
PrivateGLWindow::PrivateGLWindow (CompWindow *w,
50
 
                                  GLWindow   *gw) :
51
 
    window (w),
52
 
    gWindow (gw),
53
 
    cWindow (CompositeWindow::get (w)),
54
 
    gScreen (GLScreen::get (screen)),
55
 
    textures (),
56
 
    regions (),
57
 
    updateReg (true),
58
 
    clip (),
59
 
    bindFailed (false),
60
 
    geometry (),
61
 
    icons ()
62
 
{
63
 
    paint.xScale        = 1.0f;
64
 
    paint.yScale        = 1.0f;
65
 
    paint.xTranslate    = 0.0f;
66
 
    paint.yTranslate    = 0.0f;
67
 
 
68
 
    WindowInterface::setHandler (w);
69
 
    CompositeWindowInterface::setHandler (cWindow);
70
 
}
71
 
 
72
 
PrivateGLWindow::~PrivateGLWindow ()
73
 
{
74
 
}
75
 
 
76
 
void
77
 
PrivateGLWindow::setWindowMatrix ()
78
 
{
79
 
    if (textures.size () != matrices.size ())
80
 
        matrices.resize (textures.size ());
81
 
    
82
 
    for (unsigned int i = 0; i < textures.size (); i++)
83
 
    {
84
 
        matrices[i] = textures[i]->matrix ();
85
 
        matrices[i].x0 -= ((window->geometry ().x () - window->input ().left) *
86
 
                           matrices[i].xx);
87
 
        matrices[i].y0 -= ((window->geometry ().y () - window->input ().top) *
88
 
                           matrices[i].yy);
89
 
    }
90
 
}
91
 
 
92
 
bool
93
 
GLWindow::bind ()
94
 
{
95
 
    CompWindowExtents i = priv->window->input ();
96
 
 
97
 
    if (!priv->cWindow->pixmap () && !priv->cWindow->bind ())
98
 
        return false;
99
 
 
100
 
    priv->textures =
101
 
        GLTexture::bindPixmapToTexture (priv->cWindow->pixmap (),
102
 
                                        priv->window->size ().width () +
103
 
                                        i.left + i.right,
104
 
                                        priv->window->size ().height () +
105
 
                                        i.top + i.bottom,
106
 
                                        priv->window->depth ());
107
 
    if (priv->textures.empty ())
108
 
    {
109
 
        compLogMessage ("opengl", CompLogLevelInfo,
110
 
                        "Couldn't bind redirected window 0x%x to "
111
 
                        "texture\n", (int) priv->window->id ());
112
 
    }
113
 
 
114
 
    priv->setWindowMatrix ();
115
 
    priv->updateReg = true;
116
 
 
117
 
    return true;
118
 
}
119
 
 
120
 
void
121
 
GLWindow::release ()
122
 
{
123
 
    if (priv->cWindow->pixmap ())
124
 
    {
125
 
        priv->textures.clear ();
126
 
        priv->cWindow->release ();
127
 
    }
128
 
}
129
 
 
130
 
bool
131
 
GLWindowInterface::glPaint (const GLWindowPaintAttrib &attrib,
132
 
                            const GLMatrix            &transform,
133
 
                            const CompRegion          &region,
134
 
                            unsigned int              mask)
135
 
    WRAPABLE_DEF (glPaint, attrib, transform, region, mask)
136
 
 
137
 
bool
138
 
GLWindowInterface::glDraw (const GLMatrix     &transform,
139
 
                           GLFragment::Attrib &fragment,
140
 
                           const CompRegion   &region,
141
 
                           unsigned int       mask)
142
 
    WRAPABLE_DEF (glDraw, transform, fragment, region, mask)
143
 
 
144
 
void
145
 
GLWindowInterface::glAddGeometry (const GLTexture::MatrixList &matrix,
146
 
                                  const CompRegion            &region,
147
 
                                  const CompRegion            &clip)
148
 
    WRAPABLE_DEF (glAddGeometry, matrix, region, clip)
149
 
 
150
 
void
151
 
GLWindowInterface::glDrawTexture (GLTexture          *texture,
152
 
                                  GLFragment::Attrib &fragment,
153
 
                                  unsigned int       mask)
154
 
    WRAPABLE_DEF (glDrawTexture, texture, fragment, mask)
155
 
 
156
 
void
157
 
GLWindowInterface::glDrawGeometry ()
158
 
    WRAPABLE_DEF (glDrawGeometry)
159
 
 
160
 
const CompRegion &
161
 
GLWindow::clip () const
162
 
{
163
 
    return priv->clip;
164
 
}
165
 
 
166
 
GLWindowPaintAttrib &
167
 
GLWindow::paintAttrib ()
168
 
{
169
 
    return priv->paint;
170
 
}
171
 
 
172
 
GLWindowPaintAttrib &
173
 
GLWindow::lastPaintAttrib ()
174
 
{
175
 
    return priv->lastPaint;
176
 
}
177
 
 
178
 
 
179
 
void
180
 
PrivateGLWindow::resizeNotify (int dx, int dy, int dwidth, int dheight)
181
 
{
182
 
    window->resizeNotify (dx, dy, dwidth, dheight);
183
 
    setWindowMatrix ();
184
 
    updateReg = true;
185
 
    gWindow->release ();
186
 
}
187
 
 
188
 
void
189
 
PrivateGLWindow::moveNotify (int dx, int dy, bool now)
190
 
{
191
 
    window->moveNotify (dx, dy, now);
192
 
    updateReg = true;
193
 
    setWindowMatrix ();
194
 
}
195
 
 
196
 
void
197
 
PrivateGLWindow::windowNotify (CompWindowNotify n)
198
 
{
199
 
    switch (n)
200
 
    {
201
 
        case CompWindowNotifyUnmap:
202
 
        case CompWindowNotifyReparent:
203
 
        case CompWindowNotifyUnreparent:
204
 
        case CompWindowNotifyFrameUpdate:
205
 
            gWindow->release ();
206
 
            break;
207
 
        default:
208
 
            break;
209
 
        
210
 
    }
211
 
 
212
 
    window->windowNotify (n);
213
 
}
214
 
 
215
 
void
216
 
GLWindow::updatePaintAttribs ()
217
 
{
218
 
    CompositeWindow *cw = CompositeWindow::get (priv->window);
219
 
 
220
 
    priv->paint.opacity    = cw->opacity ();
221
 
    priv->paint.brightness = cw->brightness ();
222
 
    priv->paint.saturation = cw->saturation ();
223
 
}
224
 
 
225
 
GLWindow::Geometry &
226
 
GLWindow::geometry ()
227
 
{
228
 
    return priv->geometry;
229
 
}
230
 
 
231
 
GLWindow::Geometry::Geometry () :
232
 
    vertices (NULL),
233
 
    vertexSize (0),
234
 
    vertexStride (0),
235
 
    indices (NULL),
236
 
    indexSize (0),
237
 
    vCount (0),
238
 
    texUnits (0),
239
 
    texCoordSize (0),
240
 
    indexCount (0)
241
 
{
242
 
}
243
 
 
244
 
GLWindow::Geometry::~Geometry ()
245
 
{
246
 
    if (vertices)
247
 
        free (vertices);
248
 
 
249
 
    if (indices)
250
 
        free (indices);
251
 
}
252
 
 
253
 
void
254
 
GLWindow::Geometry::reset ()
255
 
{
256
 
    vCount = indexCount = 0;
257
 
}
258
 
 
259
 
bool
260
 
GLWindow::Geometry::moreVertices (int newSize)
261
 
{
262
 
    if (newSize > vertexSize)
263
 
    {
264
 
        GLfloat *nVertices;
265
 
 
266
 
        nVertices = (GLfloat *)
267
 
            realloc (vertices, sizeof (GLfloat) * newSize);
268
 
        if (!nVertices)
269
 
            return false;
270
 
 
271
 
        vertices = nVertices;
272
 
        vertexSize = newSize;
273
 
    }
274
 
 
275
 
    return true;
276
 
}
277
 
 
278
 
bool
279
 
GLWindow::Geometry::moreIndices (int newSize)
280
 
{
281
 
    if (newSize > indexSize)
282
 
    {
283
 
        GLushort *nIndices;
284
 
 
285
 
        nIndices = (GLushort *)
286
 
            realloc (indices, sizeof (GLushort) * newSize);
287
 
        if (!nIndices)
288
 
            return false;
289
 
 
290
 
        indices = nIndices;
291
 
        indexSize = newSize;
292
 
    }
293
 
 
294
 
    return true;
295
 
}
296
 
 
297
 
const GLTexture::List &
298
 
GLWindow::textures () const
299
 
{
300
 
    return priv->textures;
301
 
}
302
 
 
303
 
const GLTexture::MatrixList &
304
 
GLWindow::matrices () const
305
 
{
306
 
    return priv->matrices;
307
 
}
308
 
 
309
 
GLTexture *
310
 
GLWindow::getIcon (int width, int height)
311
 
{
312
 
    GLIcon   icon;
313
 
    CompIcon *i = priv->window->getIcon (width, height);
314
 
 
315
 
    if (!i)
316
 
        return NULL;
317
 
 
318
 
    if (!i->width () || !i->height ())
319
 
        return NULL;
320
 
 
321
 
    foreach (GLIcon &icon, priv->icons)
322
 
        if (icon.icon == i)
323
 
            return icon.textures[0];
324
 
 
325
 
    icon.icon = i;
326
 
    icon.textures = GLTexture::imageBufferToTexture ((char *) i->data (), *i);
327
 
 
328
 
    if (icon.textures.size () > 1 || icon.textures.size () == 0)
329
 
        return NULL;
330
 
 
331
 
    priv->icons.push_back (icon);
332
 
 
333
 
    return icon.textures[0];
334
 
}
335
 
 
336
 
void
337
 
PrivateGLWindow::updateFrameRegion (CompRegion &region)
338
 
{
339
 
    window->updateFrameRegion (region);
340
 
    updateReg = true;
341
 
}
342
 
 
343
 
void
344
 
PrivateGLWindow::updateWindowRegions ()
345
 
{
346
 
    if (regions.size () != textures.size ())
347
 
        regions.resize (textures.size ());
348
 
    for (unsigned int i = 0; i < textures.size (); i++)
349
 
    {
350
 
        regions[i] = CompRegion (*textures[i]);
351
 
        regions[i].translate (window->geometry ().x () - window->input ().left,
352
 
                              window->geometry ().y () - window->input ().top);
353
 
        regions[i] &= window->region ();
354
 
    }
355
 
    updateReg = false;
356
 
}
357
 
 
358
 
unsigned int
359
 
GLWindow::lastMask () const
360
 
{
361
 
    return priv->lastMask;
362
 
}