2
* Copyright © 2008 Dennis Kasprzyk
3
* Copyright © 2007 Novell, Inc.
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
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.
24
* Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
25
* David Reveman <davidr@novell.com>
30
GLWindow::GLWindow (CompWindow *w) :
31
PrivateHandler<GLWindow, CompWindow, COMPIZ_OPENGL_ABI> (w),
32
priv (new PrivateGLWindow (w, this))
34
CompositeWindow *cw = CompositeWindow::get (w);
36
priv->paint.opacity = cw->opacity ();
37
priv->paint.brightness = cw->brightness ();
38
priv->paint.saturation = cw->saturation ();
40
priv->lastPaint = priv->paint;
44
GLWindow::~GLWindow ()
49
PrivateGLWindow::PrivateGLWindow (CompWindow *w,
53
cWindow (CompositeWindow::get (w)),
54
gScreen (GLScreen::get (screen)),
65
paint.xTranslate = 0.0f;
66
paint.yTranslate = 0.0f;
68
WindowInterface::setHandler (w);
69
CompositeWindowInterface::setHandler (cWindow);
72
PrivateGLWindow::~PrivateGLWindow ()
77
PrivateGLWindow::setWindowMatrix ()
79
if (textures.size () != matrices.size ())
80
matrices.resize (textures.size ());
82
for (unsigned int i = 0; i < textures.size (); i++)
84
matrices[i] = textures[i]->matrix ();
85
matrices[i].x0 -= ((window->geometry ().x () - window->input ().left) *
87
matrices[i].y0 -= ((window->geometry ().y () - window->input ().top) *
95
CompWindowExtents i = priv->window->input ();
97
if (!priv->cWindow->pixmap () && !priv->cWindow->bind ())
101
GLTexture::bindPixmapToTexture (priv->cWindow->pixmap (),
102
priv->window->size ().width () +
104
priv->window->size ().height () +
106
priv->window->depth ());
107
if (priv->textures.empty ())
109
compLogMessage ("opengl", CompLogLevelInfo,
110
"Couldn't bind redirected window 0x%x to "
111
"texture\n", (int) priv->window->id ());
114
priv->setWindowMatrix ();
115
priv->updateReg = true;
123
if (priv->cWindow->pixmap ())
125
priv->textures.clear ();
126
priv->cWindow->release ();
131
GLWindowInterface::glPaint (const GLWindowPaintAttrib &attrib,
132
const GLMatrix &transform,
133
const CompRegion ®ion,
135
WRAPABLE_DEF (glPaint, attrib, transform, region, mask)
138
GLWindowInterface::glDraw (const GLMatrix &transform,
139
GLFragment::Attrib &fragment,
140
const CompRegion ®ion,
142
WRAPABLE_DEF (glDraw, transform, fragment, region, mask)
145
GLWindowInterface::glAddGeometry (const GLTexture::MatrixList &matrix,
146
const CompRegion ®ion,
147
const CompRegion &clip)
148
WRAPABLE_DEF (glAddGeometry, matrix, region, clip)
151
GLWindowInterface::glDrawTexture (GLTexture *texture,
152
GLFragment::Attrib &fragment,
154
WRAPABLE_DEF (glDrawTexture, texture, fragment, mask)
157
GLWindowInterface::glDrawGeometry ()
158
WRAPABLE_DEF (glDrawGeometry)
161
GLWindow::clip () const
166
GLWindowPaintAttrib &
167
GLWindow::paintAttrib ()
172
GLWindowPaintAttrib &
173
GLWindow::lastPaintAttrib ()
175
return priv->lastPaint;
180
PrivateGLWindow::resizeNotify (int dx, int dy, int dwidth, int dheight)
182
window->resizeNotify (dx, dy, dwidth, dheight);
189
PrivateGLWindow::moveNotify (int dx, int dy, bool now)
191
window->moveNotify (dx, dy, now);
197
PrivateGLWindow::windowNotify (CompWindowNotify n)
201
case CompWindowNotifyUnmap:
202
case CompWindowNotifyReparent:
203
case CompWindowNotifyUnreparent:
204
case CompWindowNotifyFrameUpdate:
212
window->windowNotify (n);
216
GLWindow::updatePaintAttribs ()
218
CompositeWindow *cw = CompositeWindow::get (priv->window);
220
priv->paint.opacity = cw->opacity ();
221
priv->paint.brightness = cw->brightness ();
222
priv->paint.saturation = cw->saturation ();
226
GLWindow::geometry ()
228
return priv->geometry;
231
GLWindow::Geometry::Geometry () :
244
GLWindow::Geometry::~Geometry ()
254
GLWindow::Geometry::reset ()
256
vCount = indexCount = 0;
260
GLWindow::Geometry::moreVertices (int newSize)
262
if (newSize > vertexSize)
266
nVertices = (GLfloat *)
267
realloc (vertices, sizeof (GLfloat) * newSize);
271
vertices = nVertices;
272
vertexSize = newSize;
279
GLWindow::Geometry::moreIndices (int newSize)
281
if (newSize > indexSize)
285
nIndices = (GLushort *)
286
realloc (indices, sizeof (GLushort) * newSize);
297
const GLTexture::List &
298
GLWindow::textures () const
300
return priv->textures;
303
const GLTexture::MatrixList &
304
GLWindow::matrices () const
306
return priv->matrices;
310
GLWindow::getIcon (int width, int height)
313
CompIcon *i = priv->window->getIcon (width, height);
318
if (!i->width () || !i->height ())
321
foreach (GLIcon &icon, priv->icons)
323
return icon.textures[0];
326
icon.textures = GLTexture::imageBufferToTexture ((char *) i->data (), *i);
328
if (icon.textures.size () > 1 || icon.textures.size () == 0)
331
priv->icons.push_back (icon);
333
return icon.textures[0];
337
PrivateGLWindow::updateFrameRegion (CompRegion ®ion)
339
window->updateFrameRegion (region);
344
PrivateGLWindow::updateWindowRegions ()
346
if (regions.size () != textures.size ())
347
regions.resize (textures.size ());
348
for (unsigned int i = 0; i < textures.size (); i++)
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 ();
359
GLWindow::lastMask () const
361
return priv->lastMask;