Merge lp:~mc-return/compiz/compiz.merge-fix1106270-showmouse-plugin-needs-port-to-GLES into lp:compiz/0.9.9

Proposed by MC Return
Status: Merged
Approved by: Timo Jyrinki
Approved revision: 3591
Merged at revision: 3590
Proposed branch: lp:~mc-return/compiz/compiz.merge-fix1106270-showmouse-plugin-needs-port-to-GLES
Merge into: lp:compiz/0.9.9
Diff against target: 506 lines (+176/-213)
5 files modified
debian/compiz-plugins.install.armel (+2/-0)
debian/compiz-plugins.install.armhf (+2/-0)
plugins/CMakeLists.txt (+0/-1)
plugins/showmouse/src/showmouse.cpp (+164/-197)
plugins/showmouse/src/showmouse.h (+8/-15)
To merge this branch: bzr merge lp:~mc-return/compiz/compiz.merge-fix1106270-showmouse-plugin-needs-port-to-GLES
Reviewer Review Type Date Requested Status
Timo Jyrinki Approve
Michail Bitzes (community) Approve
MC Return Needs Resubmitting
Sam Spilsbury Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+145069@code.launchpad.net

Commit message

Showmouse plugin OpenGL|ES port.

Thanks go to Michail Bitzes for porting Firepaint first,
as those 2 plugins share a lot of code, his work made this
job here possible in the first place.

Build showmouse for OpenGL|ES as well.
Also install showmouse on armel and armhf.

(LP: #1106270)

To post a comment you must log in.
Revision history for this message
Sam Spilsbury (smspillaz) wrote :

Again, well done, thanks for the effort.

The only things I would point out are:

1. You probably need to update .install.armhf too (only .install.armel is updated)
2. Coding style: spaces between both brackets () and operators foo + bar not foo+ bar

Revision history for this message
Sam Spilsbury (smspillaz) :
review: Needs Fixing
3588. By MC Return

Also install showmouse on armhf

3589. By MC Return

Hopefully fixed coding style

Revision history for this message
MC Return (mc-return) wrote :

> Again, well done, thanks for the effort.
>
Most credit in this case goes to Michail Bitzes.

> The only things I would point out are:
>
> 1. You probably need to update .install.armhf too (only .install.armel is
> updated)

Seems I forgot to save the file before the commit. Thanks for noticing. Fixed.

> 2. Coding style: spaces between both brackets () and operators foo + bar not
> foo+ bar

I hope I got them all. We need to fix those for firepaint as well then, seems
they slipped through there as well...

review: Needs Resubmitting
Revision history for this message
Sam Spilsbury (smspillaz) wrote :

Not able to test it at the moment but code wise this is a +1 from me.

review: Approve
Revision history for this message
Michail Bitzes (bitzesmichail) wrote :

Line 83 in showmouse.cpp:

I think it's:
      if (particles.size () * 6 * 3 > vertices_cache.size ())
Not:
      if (particles.size () > vertices_cache.size ())

vertices_cache needs space for 6 vertices, 3 for each triangle(2 triangles per particle), each vertex is stored as 3 GLfloats.

It could be inverted like that(and similarly for the rest caches):
      if (vertices_cache.size () < particles.size () * 6 * 3)
it makes reading it a bit clearer.

review: Needs Fixing
3590. By MC Return

Fixed wrong calculation in if condition, vertices_cache needs place for 6 vertices
(3 for each triangle, 2 triangles per particle)
Also inverted the statements in the if conditions checking cache_size to improve
readability
Credits & thanks (once again): Michail Bitzes

3591. By MC Return

Fixed indentation

Revision history for this message
MC Return (mc-return) wrote :

> Line 83 in showmouse.cpp:
>
> I think it's:
> if (particles.size () * 6 * 3 > vertices_cache.size ())
> Not:
> if (particles.size () > vertices_cache.size ())
>
> vertices_cache needs space for 6 vertices, 3 for each triangle(2 triangles per
> particle), each vertex is stored as 3 GLfloats.
>
> It could be inverted like that(and similarly for the rest caches):
> if (vertices_cache.size () < particles.size () * 6 * 3)
> it makes reading it a bit clearer.

Hopefully fixed now. :) Thanks for noticing.
Michail, could you (and do you want to) do some wizard GLES magic as well ?

review: Needs Resubmitting
Revision history for this message
Michail Bitzes (bitzesmichail) wrote :

Yes, I will look at wizard soon.

You can also fix the C++-style comments in showmouse.cpp, there are several, including the ones in my code ("//first triangle" etc)

(http://wiki.compiz.org/Development/CodingStyle says that only /* */ comments should be used)

Revision history for this message
MC Return (mc-return) wrote :

> Yes, I will look at wizard soon.
>
Cool, that are awesome news :)

> You can also fix the C++-style comments in showmouse.cpp, there are several,
> including the ones in my code ("//first triangle" etc)
>
> (http://wiki.compiz.org/Development/CodingStyle says that only /* */ comments
> should be used)
I think it is no big deal to use "//" comments for one-liners, not sure if those
really need fixing...

Revision history for this message
Michail Bitzes (bitzesmichail) :
review: Approve
Revision history for this message
Timo Jyrinki (timo-jyrinki) wrote :

Looks and builds fine for me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/compiz-plugins.install.armel'
2--- debian/compiz-plugins.install.armel 2013-01-24 08:14:41 +0000
3+++ debian/compiz-plugins.install.armel 2013-01-27 19:37:21 +0000
4@@ -33,6 +33,8 @@
5 debian/tmp/usr/*/compiz/*shelf.*
6 debian/tmp/usr/*/compiz/*shift.*
7 debian/tmp/usr/*/compiz/*showdesktop.*
8+debian/tmp/usr/*/compiz/*showmouse.*
9+debian/tmp/usr/share/compiz/showmouse
10 debian/tmp/usr/*/compiz/*switcher.*
11 debian/tmp/usr/*/compiz/*text.*
12 debian/tmp/usr/*/compiz/*titleinfo.*
13
14=== modified file 'debian/compiz-plugins.install.armhf'
15--- debian/compiz-plugins.install.armhf 2013-01-24 08:14:41 +0000
16+++ debian/compiz-plugins.install.armhf 2013-01-27 19:37:21 +0000
17@@ -33,6 +33,8 @@
18 debian/tmp/usr/*/compiz/*shelf.*
19 debian/tmp/usr/*/compiz/*shift.*
20 debian/tmp/usr/*/compiz/*showdesktop.*
21+debian/tmp/usr/*/compiz/*showmouse.*
22+debian/tmp/usr/share/compiz/showmouse
23 debian/tmp/usr/*/compiz/*switcher.*
24 debian/tmp/usr/*/compiz/*text.*
25 debian/tmp/usr/*/compiz/*titleinfo.*
26
27=== modified file 'plugins/CMakeLists.txt'
28--- plugins/CMakeLists.txt 2013-01-20 11:15:20 +0000
29+++ plugins/CMakeLists.txt 2013-01-27 19:37:21 +0000
30@@ -46,7 +46,6 @@
31 set (COMPIZ_DISABLE_PLUGIN_BENCH ON)
32 set (COMPIZ_DISABLE_PLUGIN_SHOWREPAINT ON)
33 set (COMPIZ_DISABLE_PLUGIN_WIDGET ON)
34- set (COMPIZ_DISABLE_PLUGIN_SHOWMOUSE ON)
35 set (COMPIZ_DISABLE_PLUGIN_SPLASH ON)
36 set (COMPIZ_DISABLE_PLUGIN_THUMBNAIL ON)
37 set (COMPIZ_DISABLE_PLUGIN_WIZARD ON)
38
39=== modified file 'plugins/showmouse/src/showmouse.cpp'
40--- plugins/showmouse/src/showmouse.cpp 2013-01-07 19:48:41 +0000
41+++ plugins/showmouse/src/showmouse.cpp 2013-01-27 19:37:21 +0000
42@@ -84,20 +84,10 @@
43 darken = 0;
44
45 // Initialize cache
46- vertices_cache.cache = NULL;
47- colors_cache.cache = NULL;
48- coords_cache.cache = NULL;
49- dcolors_cache.cache = NULL;
50-
51- vertices_cache.count = 0;
52- colors_cache.count = 0;
53- coords_cache.count = 0;
54- dcolors_cache.count = 0;
55-
56- vertices_cache.size = 0;
57- colors_cache.size = 0;
58- coords_cache.size = 0;
59- dcolors_cache.size = 0;
60+ vertices_cache.clear ();
61+ coords_cache.clear ();
62+ colors_cache.clear ();
63+ dcolors_cache.clear ();
64
65 for (int i = 0; i < f_numParticles; i++)
66 {
67@@ -108,14 +98,23 @@
68 }
69
70 void
71-ParticleSystem::drawParticles ()
72+ParticleSystem::drawParticles (const GLMatrix &transform)
73 {
74- GLfloat *dcolors;
75- GLfloat *vertices;
76- GLfloat *coords;
77- GLfloat *colors;
78-
79- glPushMatrix ();
80+ int i, j, k, l;
81+
82+ /* Check that the cache is big enough */
83+ if (vertices_cache.size () < particles.size () * 6 * 3)
84+ vertices_cache.resize (particles.size () * 6 * 3);
85+
86+ if (coords_cache.size () < particles.size () * 6 * 2)
87+ coords_cache.resize (particles.size () * 6 * 2);
88+
89+ if (colors_cache.size () < particles.size () * 6 * 4)
90+ colors_cache.resize (particles.size () * 6 * 4);
91+
92+ if (darken > 0)
93+ if (dcolors_cache.size () < particles.size () * 6 * 4)
94+ dcolors_cache.resize (particles.size () * 6 * 4);
95
96 glEnable (GL_BLEND);
97
98@@ -125,172 +124,171 @@
99 glEnable (GL_TEXTURE_2D);
100 }
101
102- glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
103-
104- /* Check that the cache is big enough */
105-
106- if (particles.size () > vertices_cache.count)
107- {
108- vertices_cache.cache = (GLfloat *) realloc (vertices_cache.cache,
109- particles.size () * 4 * 3 *
110- sizeof (GLfloat));
111- vertices_cache.size = particles.size () * 4 * 3;
112- vertices_cache.count = particles.size ();
113- }
114-
115- if (particles.size () > coords_cache.count)
116- {
117- coords_cache.cache = (GLfloat *) realloc (coords_cache.cache,
118- particles.size () * 4 * 2 *
119- sizeof (GLfloat));
120- coords_cache.size = particles.size () * 4 * 2;
121- coords_cache.count = particles.size ();
122- }
123-
124- if (particles.size () > colors_cache.count)
125- {
126- colors_cache.cache = (GLfloat *) realloc (colors_cache.cache,
127- particles.size () * 4 * 4 *
128- sizeof (GLfloat));
129- colors_cache.size = particles.size () * 4 * 4;
130- colors_cache.count = particles.size ();
131- }
132-
133- if (darken > 0)
134- {
135- if (dcolors_cache.count < particles.size ())
136- {
137- dcolors_cache.cache = (GLfloat *) realloc (dcolors_cache.cache,
138- particles.size () * 4 * 4 *
139- sizeof (GLfloat));
140- dcolors_cache.size = particles.size () * 4 * 4;
141- dcolors_cache.count = particles.size ();
142- }
143- }
144-
145- dcolors = dcolors_cache.cache;
146- vertices = vertices_cache.cache;
147- coords = coords_cache.cache;
148- colors = colors_cache.cache;
149-
150- int numActive = 0;
151-
152+ i = j = k = l = 0;
153+
154+ /* use 2 triangles per particle */
155 foreach (Particle &part, particles)
156 {
157 if (part.life > 0.0f)
158 {
159- numActive += 4;
160-
161 float w = part.width / 2;
162 float h = part.height / 2;
163
164+ GLushort r, g, b, a, dark_a;
165+
166+ r = part.r * 65535.0f;
167+ g = part.g * 65535.0f;
168+ b = part.b * 65535.0f;
169+ a = part.life * part.a * 65535.0f;
170+ dark_a = part.life * part.a * darken * 65535.0f;
171+
172 w += (w * part.w_mod) * part.life;
173 h += (h * part.h_mod) * part.life;
174
175- vertices[0] = part.x - w;
176- vertices[1] = part.y - h;
177- vertices[2] = part.z;
178-
179- vertices[3] = part.x - w;
180- vertices[4] = part.y + h;
181- vertices[5] = part.z;
182-
183- vertices[6] = part.x + w;
184- vertices[7] = part.y + h;
185- vertices[8] = part.z;
186-
187- vertices[9] = part.x + w;
188- vertices[10] = part.y - h;
189- vertices[11] = part.z;
190-
191- vertices += 12;
192-
193- coords[0] = 0.0;
194- coords[1] = 0.0;
195-
196- coords[2] = 0.0;
197- coords[3] = 1.0;
198-
199- coords[4] = 1.0;
200- coords[5] = 1.0;
201-
202- coords[6] = 1.0;
203- coords[7] = 0.0;
204-
205- coords += 8;
206-
207- colors[0] = part.r;
208- colors[1] = part.g;
209- colors[2] = part.b;
210- colors[3] = part.life * part.a;
211- colors[4] = part.r;
212- colors[5] = part.g;
213- colors[6] = part.b;
214- colors[7] = part.life * part.a;
215- colors[8] = part.r;
216- colors[9] = part.g;
217- colors[10] = part.b;
218- colors[11] = part.life * part.a;
219- colors[12] = part.r;
220- colors[13] = part.g;
221- colors[14] = part.b;
222- colors[15] = part.life * part.a;
223-
224- colors += 16;
225-
226- if (darken > 0)
227+ //first triangle
228+ vertices_cache[i + 0] = part.x - w;
229+ vertices_cache[i + 1] = part.y - h;
230+ vertices_cache[i + 2] = part.z;
231+
232+ vertices_cache[i + 3] = part.x - w;
233+ vertices_cache[i + 4] = part.y + h;
234+ vertices_cache[i + 5] = part.z;
235+
236+ vertices_cache[i + 6] = part.x + w;
237+ vertices_cache[i + 7] = part.y + h;
238+ vertices_cache[i + 8] = part.z;
239+
240+ //second triangle
241+ vertices_cache[i + 9] = part.x + w;
242+ vertices_cache[i + 10] = part.y + h;
243+ vertices_cache[i + 11] = part.z;
244+
245+ vertices_cache[i + 12] = part.x + w;
246+ vertices_cache[i + 13] = part.y - h;
247+ vertices_cache[i + 14] = part.z;
248+
249+ vertices_cache[i + 15] = part.x - w;
250+ vertices_cache[i + 16] = part.y - h;
251+ vertices_cache[i + 17] = part.z;
252+
253+ i += 18;
254+
255+ coords_cache[j + 0] = 0.0;
256+ coords_cache[j + 1] = 0.0;
257+
258+ coords_cache[j + 2] = 0.0;
259+ coords_cache[j + 3] = 1.0;
260+
261+ coords_cache[j + 4] = 1.0;
262+ coords_cache[j + 5] = 1.0;
263+
264+ //second
265+ coords_cache[j + 6] = 1.0;
266+ coords_cache[j + 7] = 1.0;
267+
268+ coords_cache[j + 8] = 1.0;
269+ coords_cache[j + 9] = 0.0;
270+
271+ coords_cache[j + 10] = 0.0;
272+ coords_cache[j + 11] = 0.0;
273+
274+ j += 12;
275+
276+ colors_cache[k + 0] = r;
277+ colors_cache[k + 1] = g;
278+ colors_cache[k + 2] = b;
279+ colors_cache[k + 3] = a;
280+
281+ colors_cache[k + 4] = r;
282+ colors_cache[k + 5] = g;
283+ colors_cache[k + 6] = b;
284+ colors_cache[k + 7] = a;
285+
286+ colors_cache[k + 8] = r;
287+ colors_cache[k + 9] = g;
288+ colors_cache[k + 10] = b;
289+ colors_cache[k + 11] = a;
290+
291+ //second
292+ colors_cache[k + 12] = r;
293+ colors_cache[k + 13] = g;
294+ colors_cache[k + 14] = b;
295+ colors_cache[k + 15] = a;
296+
297+ colors_cache[k + 16] = r;
298+ colors_cache[k + 17] = g;
299+ colors_cache[k + 18] = b;
300+ colors_cache[k + 19] = a;
301+
302+ colors_cache[k + 20] = r;
303+ colors_cache[k + 21] = g;
304+ colors_cache[k + 22] = b;
305+ colors_cache[k + 23] = a;
306+
307+ k += 24;
308+
309+ if(darken > 0)
310 {
311-
312- dcolors[0] = part.r;
313- dcolors[1] = part.g;
314- dcolors[2] = part.b;
315- dcolors[3] = part.life * part.a * darken;
316- dcolors[4] = part.r;
317- dcolors[5] = part.g;
318- dcolors[6] = part.b;
319- dcolors[7] = part.life * part.a * darken;
320- dcolors[8] = part.r;
321- dcolors[9] = part.g;
322- dcolors[10] = part.b;
323- dcolors[11] = part.life * part.a * darken;
324- dcolors[12] = part.r;
325- dcolors[13] = part.g;
326- dcolors[14] = part.b;
327- dcolors[15] = part.life * part.a * darken;
328-
329- dcolors += 16;
330+ dcolors_cache[l + 0] = r;
331+ dcolors_cache[l + 1] = g;
332+ dcolors_cache[l + 2] = b;
333+ dcolors_cache[l + 3] = dark_a;
334+
335+ dcolors_cache[l + 4] = r;
336+ dcolors_cache[l + 5] = g;
337+ dcolors_cache[l + 6] = b;
338+ dcolors_cache[l + 7] = dark_a;
339+
340+ dcolors_cache[l + 8] = r;
341+ dcolors_cache[l + 9] = g;
342+ dcolors_cache[l + 10] = b;
343+ dcolors_cache[l + 11] = dark_a;
344+
345+ //second
346+ dcolors_cache[l + 12] = r;
347+ dcolors_cache[l + 13] = g;
348+ dcolors_cache[l + 14] = b;
349+ dcolors_cache[l + 15] = dark_a;
350+
351+ dcolors_cache[l + 16] = r;
352+ dcolors_cache[l + 17] = g;
353+ dcolors_cache[l + 18] = b;
354+ dcolors_cache[l + 19] = dark_a;
355+
356+ dcolors_cache[l + 20] = r;
357+ dcolors_cache[l + 21] = g;
358+ dcolors_cache[l + 22] = b;
359+ dcolors_cache[l + 23] = dark_a;
360+
361+ l += 24;
362 }
363 }
364 }
365- glEnableClientState (GL_VERTEX_ARRAY);
366- glEnableClientState (GL_TEXTURE_COORD_ARRAY);
367- glEnableClientState (GL_COLOR_ARRAY);
368-
369- glTexCoordPointer (2, GL_FLOAT, 2 * sizeof (GLfloat), coords_cache.cache);
370- glVertexPointer (3, GL_FLOAT, 3 * sizeof (GLfloat), vertices_cache.cache);
371-
372- // darken the background
373+
374+ GLVertexBuffer *stream = GLVertexBuffer::streamingBuffer ();
375
376 if (darken > 0)
377 {
378 glBlendFunc (GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
379- glColorPointer (4, GL_FLOAT, 4 * sizeof (GLfloat), dcolors_cache.cache);
380- glDrawArrays (GL_QUADS, 0, numActive);
381+ stream->begin (GL_TRIANGLES);
382+ stream->addVertices (i / 3, &vertices_cache[0]);
383+ stream->addTexCoords (0, j / 2, &coords_cache[0]);
384+ stream->addColors (l / 4, &dcolors_cache[0]);
385+
386+ if (stream->end ())
387+ stream->render (transform);
388 }
389
390 // draw particles
391 glBlendFunc (GL_SRC_ALPHA, blendMode);
392-
393- glColorPointer (4, GL_FLOAT, 4 * sizeof (GLfloat), colors_cache.cache);
394- glDrawArrays (GL_QUADS, 0, numActive);
395- glDisableClientState (GL_COLOR_ARRAY);
396- glDisableClientState (GL_TEXTURE_COORD_ARRAY);
397- glDisableClientState (GL_VERTEX_ARRAY);
398-
399- glPopMatrix ();
400- glColor4usv (defaultColor);
401-
402- GLScreen::get(screen)->setTexEnvMode (GL_REPLACE); // ???
403+ stream->begin (GL_TRIANGLES);
404+
405+ stream->addVertices (i / 3, &vertices_cache[0]);
406+ stream->addTexCoords (0, j / 2, &coords_cache[0]);
407+ stream->addColors (k / 4, &colors_cache[0]);
408+
409+ if (stream->end ())
410+ stream->render (transform);
411
412 glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
413 glDisable (GL_TEXTURE_2D);
414@@ -333,30 +331,6 @@
415
416 if (tex)
417 glDeleteTextures (1, &tex);
418-
419- if (vertices_cache.cache)
420- {
421- free (vertices_cache.cache);
422- vertices_cache.cache = NULL;
423- }
424-
425- if (colors_cache.cache)
426- {
427- free (colors_cache.cache);
428- colors_cache.cache = NULL;
429- }
430-
431- if (coords_cache.cache)
432- {
433- free (coords_cache.cache);
434- coords_cache.cache = NULL;
435- }
436-
437- if (dcolors_cache.cache)
438- {
439- free (dcolors_cache.cache);
440- dcolors_cache.cache = NULL;
441- }
442 }
443
444 static void
445@@ -591,14 +565,7 @@
446
447 sTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA);
448
449- glPushMatrix ();
450- glLoadMatrixf (sTransform.getMatrix ());
451-
452- ps.drawParticles ();
453-
454- glPopMatrix();
455-
456- glColor4usv (defaultColor);
457+ ps.drawParticles (sTransform);
458
459 return status;
460 }
461
462=== modified file 'plugins/showmouse/src/showmouse.h'
463--- plugins/showmouse/src/showmouse.h 2012-09-04 15:33:44 +0000
464+++ plugins/showmouse/src/showmouse.h 2013-01-27 19:37:21 +0000
465@@ -62,15 +62,6 @@
466 float zo; /* orginal Z position */
467 };
468
469-class ParticleCache
470-{
471- public:
472-
473- GLfloat *cache;
474- unsigned int count;
475- unsigned int size;
476-};
477-
478 class ParticleSystem
479 {
480 public:
481@@ -87,17 +78,19 @@
482 float darken;
483 GLuint blendMode;
484
485- /* Moved from drawParticles to get rid of spurious malloc's */
486- ParticleCache vertices_cache;
487- ParticleCache coords_cache;
488- ParticleCache colors_cache;
489- ParticleCache dcolors_cache;
490+ /* Cache used in drawParticles
491+ It's here to avoid multiple mem allocation
492+ during drawing */
493+ std::vector<GLfloat> vertices_cache;
494+ std::vector<GLfloat> coords_cache;
495+ std::vector<GLushort> colors_cache;
496+ std::vector<GLushort> dcolors_cache;
497
498 void
499 initParticles (int f_numParticles);
500
501 void
502- drawParticles ();
503+ drawParticles (const GLMatrix &transform);
504
505 void
506 updateParticles (float time);

Subscribers

People subscribed via source and target branches