Merge lp:~smspillaz/compiz/compiz..merge-fix-1075578-workspacenames-flickering-during-display.damage_correctly into lp:compiz/0.9.9

Proposed by Sam Spilsbury
Status: Superseded
Proposed branch: lp:~smspillaz/compiz/compiz..merge-fix-1075578-workspacenames-flickering-during-display.damage_correctly
Merge into: lp:compiz/0.9.9
Prerequisite: lp:~mc-return/compiz/compiz.merge-fix-1075578-workspacenames-flickering-during-display
Diff against target: 183 lines (+73/-22)
2 files modified
plugins/workspacenames/src/workspacenames.cpp (+63/-22)
plugins/workspacenames/src/workspacenames.h (+10/-0)
To merge this branch: bzr merge lp:~smspillaz/compiz/compiz..merge-fix-1075578-workspacenames-flickering-during-display.damage_correctly
Reviewer Review Type Date Requested Status
Compiz Maintainers Pending
Review via email: mp+156264@code.launchpad.net

This proposal supersedes a proposal from 2013-03-30.

This proposal has been superseded by a proposal from 2013-03-30.

Commit message

Damage the text area correctly. Extract the method used to determine where the text area was into a separate function and use that to determine where our damage area should be. Also fix a few errors that happened on the last frame of animation.

Description of the change

Damage the text area correctly. Extract the method used to determine where the text area was into a separate function and use that to determine where our damage area should be. Also fix a few errors that happened on the last frame of animation.

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

I'll explain again what's going on here:

8 +namespace
9 +{
10 + const float TEXT_BORDER = 10.0f;
11 +}
12 +

I pulled "border" out of drawText and made it a constant. I figure it must be for the damage border around the text itself.

23 +CompPoint
24 +WSNamesScreen::getTextPlacementPosition ()
...

All I've done here is pull out the code which determines where the text actually goes on screen into a separate function. We can use it again later in both the paint and damage code, eg:

62 +void
63 +WSNamesScreen::damageTextArea ()
64 +{
65 + const CompPoint pos (getTextPlacementPosition ());
66 +

and

77 +void
78 +WSNamesScreen::drawText (const GLMatrix &matrix)
79 +{
80 + GLfloat alpha = 0.0f;
81 +
82 + /* assign y (for the lower corner!) according to the setting */
83 + const CompPoint p = getTextPlacementPosition ();

In the damage function here:

62 +void
63 +WSNamesScreen::damageTextArea ()
64 +{
65 + const CompPoint pos (getTextPlacementPosition ());
66 +
67 + /* The placement position is from the lower corner, so we
68 + * need to move it back up by height */
69 + CompRect area (pos.x () - TEXT_BORDER,
70 + pos.y () - TEXT_BORDER - textData.getHeight () ,
71 + textData.getWidth () + TEXT_BORDER * 2,
72 + textData.getHeight () + TEXT_BORDER * 2);
73 +
74 + cScreen->damageRegion (area);
75 +}

The only gotcha was that the workspacenames plugin is a little unconventional and gives the co-ords for the text area relative to its bottom-left corner as opposed to its top-left corner. So we have to subtract the height of the text area in order to get the top-left corner to pass it to damageRegion.

127 + /* Only damage when the */
128 + if (shouldDrawText ())
129 + damageTextArea ();
130 +
131 + cScreen->donePaint ();
132
133 - cScreen->donePaint ();
134 + /* Clear text data if done with fadeout */
135 + if (!timer && !timeoutHandle.active ())
136 + textData.clear ();

We don't want to be calling damageScreen or damageRegion on every frame. Its bad for power usage and performance. So, we only call it if we should be drawing text to the screen on this frame.

I also moved the call to textData.clear () from:

115 -
116 - if (!timer)
117 - textData.clear ();

to:

135 + if (!timer && !timeoutHandle.active ())
136 + textData.clear ();

In donePaint. I don't know why it was like that in this plugin, but the best practice for this is to always clean up paint-related data after animations have completed in donePaint, so that you paint at least one frame at the end as though there was no text object.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/workspacenames/src/workspacenames.cpp'
2--- plugins/workspacenames/src/workspacenames.cpp 2013-03-30 14:35:37 +0000
3+++ plugins/workspacenames/src/workspacenames.cpp 2013-03-30 14:35:38 +0000
4@@ -24,6 +24,12 @@
5
6 #include "workspacenames.h"
7
8+namespace
9+{
10+ const float TEXT_BORDER = 10.0f;
11+}
12+
13+
14 CompString
15 WSNamesScreen::getCurrentWSName ()
16 {
17@@ -81,16 +87,14 @@
18 textData.renderText (name, attrib);
19 }
20
21-void
22-WSNamesScreen::drawText (const GLMatrix &matrix)
23+CompPoint
24+WSNamesScreen::getTextPlacementPosition ()
25 {
26- GLfloat alpha;
27- float x, y, border = 10.0f;
28 CompRect oe = screen->getCurrentOutputExtents ();
29-
30- x = oe.centerX () - textData.getWidth () / 2;
31-
32- /* assign y (for the lower corner!) according to the setting */
33+ float x = oe.centerX () - textData.getWidth () / 2;
34+ float y = 0;
35+ const float border = TEXT_BORDER;
36+
37 switch (optionGetTextPlacement ())
38 {
39 case WorkspacenamesOptions::TextPlacementCenteredOnScreen:
40@@ -103,7 +107,7 @@
41
42 if (optionGetTextPlacement () ==
43 WorkspacenamesOptions::TextPlacementTopOfScreen)
44- y = oe.y1 () + workArea.y () +
45+ y = oe.y1 () + workArea.y () +
46 (2 * border) + textData.getHeight ();
47 else
48 y = oe.y1 () + workArea.y () +
49@@ -111,16 +115,49 @@
50 }
51 break;
52 default:
53- return;
54+ return CompPoint (floor (x),
55+ oe.centerY () - textData.getHeight () / 2);
56 break;
57 }
58
59+ return CompPoint (floor (x), floor (y));
60+}
61+
62+void
63+WSNamesScreen::damageTextArea ()
64+{
65+ const CompPoint pos (getTextPlacementPosition ());
66+
67+ /* The placement position is from the lower corner, so we
68+ * need to move it back up by height */
69+ CompRect area (pos.x () - TEXT_BORDER,
70+ pos.y () - TEXT_BORDER - textData.getHeight () ,
71+ textData.getWidth () + TEXT_BORDER * 2,
72+ textData.getHeight () + TEXT_BORDER * 2);
73+
74+ cScreen->damageRegion (area);
75+}
76+
77+void
78+WSNamesScreen::drawText (const GLMatrix &matrix)
79+{
80+ GLfloat alpha = 0.0f;
81+
82+ /* assign y (for the lower corner!) according to the setting */
83+ const CompPoint p = getTextPlacementPosition ();
84+
85 if (timer)
86 alpha = timer / (optionGetFadeTime () * 1000.0f);
87- else
88+ else if (timeoutHandle.active ())
89 alpha = 1.0f;
90
91- textData.draw (matrix, floor (x), floor (y), alpha);
92+ textData.draw (matrix, p.x (), p.y (), alpha);
93+}
94+
95+bool
96+WSNamesScreen::shouldDrawText ()
97+{
98+ return textData.getWidth () && textData.getHeight ();
99 }
100
101 bool
102@@ -132,7 +169,7 @@
103 {
104 bool status = gScreen->glPaintOutput (attrib, transform, region, output, mask);
105
106- if (textData.getWidth () && textData.getHeight ())
107+ if (shouldDrawText ())
108 {
109 GLMatrix sTransform (transform);
110
111@@ -151,9 +188,6 @@
112 {
113 timer -= msSinceLastPaint;
114 timer = MAX (timer, 0);
115-
116- if (!timer)
117- textData.clear ();
118 }
119
120 cScreen->preparePaint (msSinceLastPaint);
121@@ -162,20 +196,27 @@
122 void
123 WSNamesScreen::donePaint ()
124 {
125- /* FIXME: better only damage paint region */
126- cScreen->damageScreen ();
127+ /* Only damage when the */
128+ if (shouldDrawText ())
129+ damageTextArea ();
130+
131+ cScreen->donePaint ();
132
133- cScreen->donePaint ();
134+ /* Clear text data if done with fadeout */
135+ if (!timer && !timeoutHandle.active ())
136+ textData.clear ();
137 }
138
139 bool
140 WSNamesScreen::hideTimeout ()
141 {
142 timer = optionGetFadeTime () * 1000;
143+
144+ /* Clear immediately if there is no fadeout */
145 if (!timer)
146 textData.clear ();
147-
148- cScreen->damageScreen ();
149+
150+ damageTextArea ();
151
152 timeoutHandle.stop ();
153
154@@ -201,7 +242,7 @@
155 renderNameText ();
156 timeoutHandle.start (timeout, timeout + 200);
157
158- cScreen->damageScreen ();
159+ damageTextArea ();
160 }
161 }
162
163
164=== modified file 'plugins/workspacenames/src/workspacenames.h'
165--- plugins/workspacenames/src/workspacenames.h 2012-06-22 12:27:42 +0000
166+++ plugins/workspacenames/src/workspacenames.h 2013-03-30 14:35:38 +0000
167@@ -79,6 +79,16 @@
168
169 void
170 handleEvent (XEvent *);
171+
172+ CompPoint
173+ getTextPlacementPosition ();
174+
175+ void
176+ damageTextArea ();
177+
178+ private:
179+
180+ bool shouldDrawText ();
181 };
182
183 class WorkspacenamesPluginVTable :

Subscribers

People subscribed via source and target branches