~mc-return/compiz/compiz.merge-src-header-files-cleanup

« back to all changes in this revision

Viewing changes to plugins/expo/src/glow.cpp

  • Committer: MC Return
  • Date: 2013-06-20 05:56:13 UTC
  • mfrom: (3724.2.16 0.9.10)
  • Revision ID: mc.return@gmx.net-20130620055613-8dp00nmw2jpm3ptu
Merged latest lp:compiz and fixed conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include "expo.h"
28
28
#include "group_glow.h"
29
29
 
30
 
#define WIN_REAL_X(w) (w->x () - w->border ().left)
31
 
#define WIN_REAL_Y(w) (w->y () - w->border ().top)
32
 
#define WIN_REAL_WIDTH(w) (w->width () + 2 * w->geometry ().border () + \
33
 
                           w->border ().left + w->border ().right)
34
 
#define WIN_REAL_HEIGHT(w) (w->height () + 2 * w->geometry ().border () + \
35
 
                            w->border ().top + w->border ().bottom)
36
 
 
37
 
const GlowTextureProperties glowTextureProperties = {
 
30
const GlowTextureProperties glowTextureProperties =
 
31
{
38
32
    /* GlowTextureRectangular */
39
33
    glowTexRect, 32, 21
40
34
};
43
37
 * GroupWindow::paintGlow
44
38
 *
45
39
 * Takes our glow texture, stretches the appropriate positions in the glow texture,
46
 
 * adds those geometries (so plugins like wobby and deform this texture correctly)
 
40
 * adds those geometries (so plugins like wobby deform this texture correctly)
47
41
 * and then draws the glow texture with this geometry (plugins like wobbly and friends
48
42
 * will automatically deform the texture based on our set geometry)
49
43
 */
50
44
 
51
45
void
52
46
ExpoWindow::paintGlow (const GLMatrix            &transform,
53
 
                       const GLWindowPaintAttrib &attrib,
54
 
                       const CompRegion          &paintRegion,
55
 
                       unsigned int               mask)
 
47
                       const GLWindowPaintAttrib &attrib,
 
48
                       const CompRegion          &paintRegion,
 
49
                       unsigned int              mask)
56
50
{
57
51
    CompRegion      reg;
58
 
    int             i;
59
52
    GLushort        colorData[4];
60
53
    const GLushort *selColorData = ExpoScreen::get (screen)->optionGetSelectedColor ();
61
 
    float           alpha = (float) selColorData[3] / 65535.0f;
 
54
    float           alpha        = static_cast <float> (selColorData[3] / 65535.0f);
62
55
 
63
56
    /* Premultiply color */
64
57
    colorData[0] = selColorData[0] * alpha;
71
64
    /* There are 8 glow parts of the glow texture which we wish to paint
72
65
     * separately with different transformations
73
66
     */
74
 
    for (i = 0; i < NUM_GLOWQUADS; i++)
 
67
    for (int i = 0; i < NUM_GLOWQUADS; ++i)
75
68
    {
76
69
        /* Using precalculated quads here */
77
70
        reg = CompRegion (mGlowQuads[i].mBox);
87
80
 
88
81
            matl.push_back (mGlowQuads[i].mMatrix);
89
82
            /* Add color data for all 6 vertices of the quad */
90
 
            for (int n = 0; n < 6; n++)
 
83
            for (int n = 0; n < 6; ++n)
91
84
                gWindow->vertexBuffer ()->addColors (1, colorData);
 
85
 
92
86
            gWindow->glAddGeometry (matl, reg, paintRegion);
93
87
        }
94
88
    }
116
110
/*
117
111
 * ExpoWindow::computeGlowQuads
118
112
 *
119
 
 * This function computures the matrix transformation required for each
 
113
 * This function computes the matrix transformation required for each
120
114
 * part of the glow texture which we wish to stretch to some rectangular
121
115
 * dimensions
122
116
 *
153
147
void
154
148
ExpoWindow::computeGlowQuads (GLTexture::Matrix *matrix)
155
149
{
156
 
    CompRect          *box;
157
 
    int               x1, x2, y1, y2;
158
 
    GLTexture::Matrix *quadMatrix;
159
 
    int               glowSize, glowOffset;
160
 
    CompWindow        *w = window;
161
 
 
162
150
    /* Passing NULL to this function frees the glow quads
163
151
     * (so the window is not painted with glow) */
164
152
 
166
154
    {
167
155
        if (!mGlowQuads)
168
156
            mGlowQuads = new GlowQuad[NUM_GLOWQUADS];
 
157
 
169
158
        if (!mGlowQuads)
170
159
            return;
171
160
    }
176
165
            delete[] mGlowQuads;
177
166
            mGlowQuads = NULL;
178
167
        }
 
168
 
179
169
        return;
180
170
    }
181
171
 
182
 
    glowSize = 48;
183
 
    glowOffset = (glowSize * ExpoScreen::get (screen)->mGlowTextureProperties->glowOffset /
184
 
                  ExpoScreen::get (screen)->mGlowTextureProperties->textureSize) + 1;
 
172
    /* TODO: Make glowSize configurable via CCSM */
 
173
    int glowSize   = 48;
 
174
    int glowOffset = (glowSize * ExpoScreen::get (screen)->mGlowTextureProperties->glowOffset /
 
175
                      ExpoScreen::get (screen)->mGlowTextureProperties->textureSize) + 1;
185
176
 
186
177
    /* Top left corner */
187
 
    box = &mGlowQuads[GLOWQUAD_TOPLEFT].mBox;
 
178
    CompRect *box                        = &mGlowQuads[GLOWQUAD_TOPLEFT].mBox;
188
179
    mGlowQuads[GLOWQUAD_TOPLEFT].mMatrix = *matrix;
189
 
    quadMatrix = &mGlowQuads[GLOWQUAD_TOPLEFT].mMatrix;
 
180
    GLTexture::Matrix *quadMatrix        = &mGlowQuads[GLOWQUAD_TOPLEFT].mMatrix;
 
181
 
 
182
    /* Precalculate some values we need multiple times */
 
183
 
 
184
    CompWindow *w = window;
 
185
 
 
186
    int winRealX = w->x () - w->border ().left;
 
187
    int winRealY = w->y () - w->border ().top;
190
188
 
191
189
    /* Set the desired rect dimensions
192
190
     * for the part of the glow we are painting */
193
191
 
194
 
    x1 = WIN_REAL_X (w) - glowSize + glowOffset;
195
 
    y1 = WIN_REAL_Y (w) - glowSize + glowOffset;
 
192
    int   x1                = winRealX - glowSize + glowOffset;
 
193
    int   y1                = winRealY - glowSize + glowOffset;
 
194
 
 
195
    int   winRealWidth      = w->geometry ().widthIncBorders ();
 
196
    int   winRealHeight     = w->geometry ().heightIncBorders ();
 
197
 
 
198
    int   halfWinRealWidth  = winRealWidth  / 2;
 
199
    int   halfWinRealHeight = winRealHeight / 2;
 
200
 
 
201
    int   xPlusHalfWidth    = winRealX + halfWinRealWidth;
 
202
    int   yPlusHalfHeight   = winRealY + halfWinRealHeight;
 
203
 
 
204
    int   xPlusGlowOff      = winRealX + glowOffset;
 
205
    int   yPlusGlowOff      = winRealY + glowOffset;
 
206
 
 
207
    int   xMinusGlowOff     = winRealX - glowOffset;
 
208
    int   yMinusGlowOff     = winRealY - glowOffset;
 
209
 
 
210
    float glowPart          = 1.0f / glowSize;
196
211
 
197
212
    /* 2x2 Matrix here, adjust both x and y scale factors
198
213
     * and the x and y position
205
220
     * multiplied by the scale factors
206
221
     */
207
222
 
208
 
    quadMatrix->xx = 1.0f / glowSize;
209
 
    quadMatrix->yy = 1.0f / (glowSize);
 
223
    quadMatrix->xx = quadMatrix->yy = glowPart;
210
224
    quadMatrix->x0 = -(x1 * quadMatrix->xx);
211
225
    quadMatrix->y0 = -(y1 * quadMatrix->yy);
212
226
 
213
 
    x2 = MIN (WIN_REAL_X (w) + glowOffset,
214
 
              WIN_REAL_X (w) + (WIN_REAL_WIDTH (w) / 2));
215
 
    y2 = MIN (WIN_REAL_Y (w) + glowOffset,
216
 
              WIN_REAL_Y (w) + (WIN_REAL_HEIGHT (w) / 2));
 
227
    int x2 = MIN (xPlusGlowOff,
 
228
                  xPlusHalfWidth);
 
229
    int y2 = MIN (yPlusGlowOff,
 
230
                  yPlusHalfHeight);
217
231
 
218
232
    *box = CompRect (x1, y1, x2 - x1, y2 - y1);
219
233
 
225
239
    /* Set the desired rect dimensions
226
240
     * for the part of the glow we are painting */
227
241
 
228
 
    x1 = WIN_REAL_X (w) + WIN_REAL_WIDTH (w) - glowOffset;
229
 
    y1 = WIN_REAL_Y (w) - glowSize + glowOffset;
230
 
    x2 = WIN_REAL_X (w) + WIN_REAL_WIDTH (w) + glowSize - glowOffset;
 
242
    x1 = xMinusGlowOff + winRealWidth;
 
243
    y1 = yPlusGlowOff - glowSize;
 
244
    x2 = x1 + glowSize;
231
245
 
232
246
    /* 2x2 Matrix here, adjust both x and y scale factors
233
247
     * and the x and y position
242
256
     * need the inverse of that which is 1 - x1 * xx
243
257
     */
244
258
 
245
 
    quadMatrix->xx = -1.0f / glowSize;
246
 
    quadMatrix->yy = 1.0f / glowSize;
247
 
    quadMatrix->x0 = 1.0 - (x1 * quadMatrix->xx);
 
259
    quadMatrix->xx = -glowPart;
 
260
    quadMatrix->yy =  glowPart;
 
261
    quadMatrix->x0 =  1.0 - (x1 * quadMatrix->xx);
248
262
    quadMatrix->y0 = -(y1 * quadMatrix->yy);
249
263
 
250
 
    x1 = MAX (WIN_REAL_X (w) + WIN_REAL_WIDTH (w) - glowOffset,
251
 
              WIN_REAL_X (w) + (WIN_REAL_WIDTH (w) / 2));
252
 
    y2 = MIN (WIN_REAL_Y (w) + glowOffset,
253
 
              WIN_REAL_Y (w) + (WIN_REAL_HEIGHT (w) / 2));
 
264
    x1 = MAX (xMinusGlowOff + winRealWidth,
 
265
              xPlusHalfWidth);
 
266
    y2 = MIN (yPlusGlowOff,
 
267
              yPlusHalfHeight);
254
268
 
255
269
    *box = CompRect (x1, y1, x2 - x1, y2 - y1);
256
270
 
259
273
    mGlowQuads[GLOWQUAD_BOTTOMLEFT].mMatrix = *matrix;
260
274
    quadMatrix = &mGlowQuads[GLOWQUAD_BOTTOMLEFT].mMatrix;
261
275
 
262
 
    x1 = WIN_REAL_X (w) - glowSize + glowOffset;
263
 
    y1 = WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) - glowOffset;
264
 
    /* x2 = WIN_REAL_X (w) + glowOffset; */
265
 
    y2 = WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) + glowSize - glowOffset;
 
276
    x1 = xPlusGlowOff - glowSize;
 
277
    y1 = yMinusGlowOff + winRealHeight;
 
278
    /* x2 = xPlusGlowOff; */
 
279
    y2 = yMinusGlowOff + winRealHeight + glowSize;
266
280
 
267
281
    /* 2x2 Matrix here, adjust both x and y scale factors
268
282
     * and the x and y position
277
291
     * need the inverse of that which is 1 - y1 * yy
278
292
     */
279
293
 
280
 
    quadMatrix->xx = 1.0f / glowSize;
281
 
    quadMatrix->yy = -1.0f / glowSize;
 
294
    quadMatrix->xx =  glowPart;
 
295
    quadMatrix->yy = -glowPart;
282
296
    quadMatrix->x0 = -(x1 * quadMatrix->xx);
283
297
    quadMatrix->y0 = 1.0f - (y1 * quadMatrix->yy);
284
298
 
285
 
    y1 = MAX (WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) - glowOffset,
286
 
              WIN_REAL_Y (w) + (WIN_REAL_HEIGHT (w) / 2));
287
 
    x2 = MIN (WIN_REAL_X (w) + glowOffset,
288
 
              WIN_REAL_X (w) + (WIN_REAL_WIDTH (w) / 2));
 
299
    y1 = MAX (winRealY + winRealHeight - glowOffset,
 
300
              yPlusHalfHeight);
 
301
    x2 = MIN (xPlusGlowOff,
 
302
              xPlusHalfWidth);
289
303
 
290
304
    *box = CompRect (x1, y1, x2 - x1, y2 - y1);
291
305
 
294
308
    mGlowQuads[GLOWQUAD_BOTTOMRIGHT].mMatrix = *matrix;
295
309
    quadMatrix = &mGlowQuads[GLOWQUAD_BOTTOMRIGHT].mMatrix;
296
310
 
297
 
    x1 = WIN_REAL_X (w) + WIN_REAL_WIDTH (w) - glowOffset;
298
 
    y1 = WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) - glowOffset;
299
 
    x2 = WIN_REAL_X (w) + WIN_REAL_WIDTH (w) + glowSize - glowOffset;
300
 
    y2 = WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) + glowSize - glowOffset;
 
311
    x1 = xMinusGlowOff + winRealWidth;
 
312
    y1 = yMinusGlowOff + winRealHeight;
 
313
    x2 = x1 + glowSize;
 
314
    y2 = y1 + glowSize;
301
315
 
302
316
    /* 2x2 Matrix here, adjust both x and y scale factors
303
317
     * and the x and y position
310
324
     * multiplied by the scale factors
311
325
     */
312
326
 
313
 
    quadMatrix->xx = -1.0f / glowSize;
314
 
    quadMatrix->yy = -1.0f / glowSize;
 
327
    quadMatrix->xx = -glowPart;
 
328
    quadMatrix->yy = -glowPart;
315
329
    quadMatrix->x0 = 1.0 - (x1 * quadMatrix->xx);
316
330
    quadMatrix->y0 = 1.0 - (y1 * quadMatrix->yy);
317
331
 
318
 
    x1 = MAX (WIN_REAL_X (w) + WIN_REAL_WIDTH (w) - glowOffset,
319
 
              WIN_REAL_X (w) + (WIN_REAL_WIDTH (w) / 2));
320
 
    y1 = MAX (WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) - glowOffset,
321
 
              WIN_REAL_Y (w) + (WIN_REAL_HEIGHT (w) / 2));
 
332
    x1 = MAX (xMinusGlowOff + winRealWidth,
 
333
              xPlusHalfWidth);
 
334
    y1 = MAX (yMinusGlowOff + winRealHeight,
 
335
              yPlusHalfHeight);
322
336
 
323
337
    *box = CompRect (x1, y1, x2 - x1, y2 - y1);
324
338
 
327
341
    mGlowQuads[GLOWQUAD_TOP].mMatrix = *matrix;
328
342
    quadMatrix = &mGlowQuads[GLOWQUAD_TOP].mMatrix;
329
343
 
330
 
    x1 = WIN_REAL_X (w) + glowOffset;
331
 
    y1 = WIN_REAL_Y (w) - glowSize + glowOffset;
332
 
    x2 = WIN_REAL_X (w) + WIN_REAL_WIDTH (w) - glowOffset;
333
 
    y2 = WIN_REAL_Y (w) + glowOffset;
 
344
    x1 = xPlusGlowOff;
 
345
    y1 = yPlusGlowOff - glowSize;
 
346
    x2 = xMinusGlowOff + winRealWidth;
 
347
    y2 = yPlusGlowOff;
334
348
 
335
349
    /* 2x2 Matrix here, adjust both x and y scale factors
336
350
     * and the x and y position
344
358
     */
345
359
 
346
360
    quadMatrix->xx = 0.0f;
347
 
    quadMatrix->yy = 1.0f / glowSize;
 
361
    quadMatrix->yy = glowPart;
348
362
    quadMatrix->x0 = 1.0;
349
363
    quadMatrix->y0 = -(y1 * quadMatrix->yy);
350
364
 
355
369
    mGlowQuads[GLOWQUAD_BOTTOM].mMatrix = *matrix;
356
370
    quadMatrix = &mGlowQuads[GLOWQUAD_BOTTOM].mMatrix;
357
371
 
358
 
    x1 = WIN_REAL_X (w) + glowOffset;
359
 
    y1 = WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) - glowOffset;
360
 
    x2 = WIN_REAL_X (w) + WIN_REAL_WIDTH (w) - glowOffset;
361
 
    y2 = WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) + glowSize - glowOffset;
 
372
    x1 = xPlusGlowOff;
 
373
    y1 = yMinusGlowOff + winRealHeight;
 
374
    x2 = xMinusGlowOff + winRealWidth;
 
375
    y2 = y1 + glowSize;
362
376
 
363
377
    /* 2x2 Matrix here, adjust both x and y scale factors
364
378
     * and the x and y position
372
386
     */
373
387
 
374
388
    quadMatrix->xx = 0.0f;
375
 
    quadMatrix->yy = -1.0f / glowSize;
 
389
    quadMatrix->yy = -glowPart;
376
390
    quadMatrix->x0 = 1.0;
377
391
    quadMatrix->y0 = 1.0 - (y1 * quadMatrix->yy);
378
392
 
383
397
    mGlowQuads[GLOWQUAD_LEFT].mMatrix = *matrix;
384
398
    quadMatrix = &mGlowQuads[GLOWQUAD_LEFT].mMatrix;
385
399
 
386
 
    x1 = WIN_REAL_X (w) - glowSize + glowOffset;
387
 
    y1 = WIN_REAL_Y (w) + glowOffset;
388
 
    x2 = WIN_REAL_X (w) + glowOffset;
389
 
    y2 = WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) - glowOffset;
 
400
    x1 = xPlusGlowOff - glowSize;
 
401
    y1 = yPlusGlowOff;
 
402
    x2 = xPlusGlowOff;
 
403
    y2 = yMinusGlowOff + winRealHeight;
390
404
 
391
405
    /* 2x2 Matrix here, adjust both x and y scale factors
392
406
     * and the x and y position
399
413
     * multiplied by the scale factors
400
414
     */
401
415
 
402
 
    quadMatrix->xx = 1.0f / glowSize;
 
416
    quadMatrix->xx = glowPart;
403
417
    quadMatrix->yy = 0.0f;
404
418
    quadMatrix->x0 = -(x1 * quadMatrix->xx);
405
419
    quadMatrix->y0 = 1.0;
411
425
    mGlowQuads[GLOWQUAD_RIGHT].mMatrix = *matrix;
412
426
    quadMatrix = &mGlowQuads[GLOWQUAD_RIGHT].mMatrix;
413
427
 
414
 
    x1 = WIN_REAL_X (w) + WIN_REAL_WIDTH (w) - glowOffset;
415
 
    y1 = WIN_REAL_Y (w) + glowOffset;
416
 
    x2 = WIN_REAL_X (w) + WIN_REAL_WIDTH (w) + glowSize - glowOffset;
417
 
    y2 = WIN_REAL_Y (w) + WIN_REAL_HEIGHT (w) - glowOffset;
 
428
    x1 = xMinusGlowOff + winRealWidth;
 
429
    y1 = yPlusGlowOff;
 
430
    x2 = xMinusGlowOff + winRealWidth + glowSize;
 
431
    y2 = yMinusGlowOff + winRealHeight;
418
432
 
419
433
    /* 2x2 Matrix here, adjust both x and y scale factors
420
434
     * and the x and y position
427
441
     * multiplied by the scale factors
428
442
     */
429
443
 
430
 
    quadMatrix->xx = -1.0f / glowSize;
 
444
    quadMatrix->xx = -glowPart;
431
445
    quadMatrix->yy = 0.0f;
432
446
    quadMatrix->x0 = 1.0 - (x1 * quadMatrix->xx);
433
447
    quadMatrix->y0 = 1.0;