Merge ~kondor-dani/compiz:annotate_fix2 into compiz:master

Proposed by Daniel Kondor
Status: Merged
Approved by: Dmitry Shachnev
Approved revision: 939cb14bea4852ee81d1d0d568874208472fcb44
Merged at revision: 7a327f3b305d878b1a41d007f0d672f0411c06f9
Proposed branch: ~kondor-dani/compiz:annotate_fix2
Merge into: compiz:master
Diff against target: 191 lines (+43/-35)
2 files modified
plugins/annotate/src/annotate.cpp (+41/-34)
plugins/annotate/src/annotate.h (+2/-1)
Reviewer Review Type Date Requested Status
Alberts Muktupāvels Approve
Dmitry Shachnev Approve
Review via email: mp+383958@code.launchpad.net

This proposal supersedes a proposal from 2020-05-14.

Commit message

Make annotate plugin D-Bus interface working, and clean up code.

Description of the change

Second iteration of fix for bug #1878545

Changes moved to separate commits.

Cause of bug (in plugins/annotate/src/annotate.cpp):
 -- "tool" variable in AnnoScreen::draw() gets overwritten between lines 305 and 322 (is it undefined behavior to save the c_str() of the value returned by CompOption::getStringOptionNamed()?)
 -- AnnoScreen::draw() needs to call handleEventSetEnabled() and glPaintOutputSetEnabled() to actually draw anything on the screen

Changes:
 -- store tool in a local std::string
 -- add missing calls to ensure result is drawn on the screen

To post a comment you must log in.
Revision history for this message
Alberts Muktupāvels (muktupavels) : Posted in a previous version of this proposal
Revision history for this message
Dmitry Shachnev (mitya57) wrote : Posted in a previous version of this proposal

I am setting it to Needs Information per Alberts' review.

review: Needs Information
Revision history for this message
Alberts Muktupāvels (muktupavels) wrote : Posted in a previous version of this proposal

Your example - "dbus-send --print-reply --type=method_call --dest=org.freedesktop.compiz /org/freedesktop/compiz/annotate/screen0/draw org.freedesktop.compiz.activate string:tool" looks incomplete or wrong. From dbus plugin code - "Activate can be used to trigger any existing action. Arguments should be a pair of { string, bool|int32|double|string }."

Revision history for this message
Daniel Kondor (kondor-dani) wrote : Posted in a previous version of this proposal

The example works (on this branch), since the draw() function fills in everything with default values.

Full example would be e.g.:

dbus-send --print-reply --type=method_call --dest=org.freedesktop.compiz /org/freedesktop/compiz/annotate/screen0/draw org.freedesktop.compiz.activate string:root int32:416 string:tool string:line string:x1 double:100.0 string:y1 double:200.0 string:x2 double:200.0 string:y2 double:300.0 string:fill_color string:"#ff00ffff"

Revision history for this message
Alberts Muktupāvels (muktupavels) wrote : Posted in a previous version of this proposal

Please use separate commits for separate problems

One for enabling painting - that seems main problem why nothing are drawn on screen, right?

Then fix tool problem as next commit. Looks like draw function has one more similar problem - in text drawing case.

And please remove unneeded empty line removal.

Revision history for this message
Daniel Kondor (kondor-dani) wrote : Posted in a previous version of this proposal

> Please use separate commits for separate problems
>
> One for enabling painting - that seems main problem why nothing are drawn on
> screen, right?
draw() does nothing without fixing the issue with tool.

I'll create separate commits for these.

>
> Then fix tool problem as next commit. Looks like draw function has one more
> similar problem - in text drawing case.
Indeed, I haven't tested this.

E.g. calling:

dbus-send --print-reply --type=method_call --dest=org.freedesktop.compiz /org/freedesktop/compiz/annotate/screen0/draw org.freedesktop.compiz.activate string:tool string:text string:text string:aaaa string:x double:100.0 string:y double:100.0

prints "Sans" on the screen instead of "aaaa", which is given as a parameter. I'll add a fix for this as well.

>
> And please remove unneeded empty line removal.

Revision history for this message
Daniel Kondor (kondor-dani) : Posted in a previous version of this proposal
Revision history for this message
Dmitry Shachnev (mitya57) :
Revision history for this message
Alberts Muktupāvels (muktupavels) wrote :

- Please next time just force push to existing merge request. :)

- Looks like you forgot cython3 change, just use separate commit for it.

- Could you check if adding cScreen->damageRegion would be enough? I still think that handleEventSetEnabled should not be needed.

Thanks!

Revision history for this message
Dmitry Shachnev (mitya57) wrote :

> - Looks like you forgot cython3 change, just use separate commit for it.

A separate merge proposal for cython3 change will be even better, as this will add a separate changelog entry for it.

Revision history for this message
Daniel Kondor (kondor-dani) wrote :

> - Could you check if adding cScreen->damageRegion would be enough? I still
> think that handleEventSetEnabled should not be needed.

Yes, it works that way as well! I've added a commit -- note the extra logic needed to calculate the region to pass. I've also noticed that these extents are already calculated by all the draw*() functions and seem to be not used later.

Revision history for this message
Daniel Kondor (kondor-dani) wrote :

I've added one more commit removing the code that seems to be unused in the draw*() functions.

Revision history for this message
Dmitry Shachnev (mitya57) wrote :

Have you seen my inline comment about simplifying the comparisons?

Revision history for this message
Daniel Kondor (kondor-dani) wrote :

Yes, sure, I can easily add a commit for that, but I'm concerned since this will change the behavior from case-insensitve to case-sensitive comparison (the point of strcasecmp() is that it's case-insensitve).

Based on the fact that no one reported this bug for years, my guess is that it's very unlikely that any code relies on this behavior :) -- still it might be better to have a separate merge for that. Let me know what you think.

Revision history for this message
Dmitry Shachnev (mitya57) wrote :

Ok, looks good to me now.

review: Approve
Revision history for this message
Alberts Muktupāvels (muktupavels) wrote :

- Please prefix commit message title with annotate:.

- "need to call handleEventSetEnabled() to draw on screen" and "use damageRegion() instead of handleEventSetEnabled() in draw()" should be one commit.

- See diff comments.

Revision history for this message
Daniel Kondor (kondor-dani) wrote :

Ok, I'm trying to fix remaining issues.

Also, I've tried squashing the previous commits, but the result doesn't look right :( -- I'll try to do it again.

Revision history for this message
Daniel Kondor (kondor-dani) wrote :

I've fixed the git history and added commits based on the review comments.

Revision history for this message
Dmitry Shachnev (mitya57) wrote :

> revert change of return type of AnnoScreen::drawText()

Maybe you can squash this into the commit that changed the return type?

Otherwise, looks good to me. Alberts, what do you think?

Revision history for this message
Alberts Muktupāvels (muktupavels) wrote :

There are indentation problems that would be nice to fix. See inline/diff comments.

Also please prefix commit messages with "annotate:". You can use `git rebase -i a9d598a` to do that. Choose r or reword to edit commit messages.

Otherwise looks good. Thanks!

Revision history for this message
Daniel Kondor (kondor-dani) wrote :

Ok, I think I was able to fix the indentation -- I didn't realize before that arguments are supposed to line up with the opening parentheses :)

Let me know if you see any other issue.

Revision history for this message
Alberts Muktupāvels (muktupavels) wrote :

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/plugins/annotate/src/annotate.cpp b/plugins/annotate/src/annotate.cpp
2index f415d6c..4f8285f 100644
3--- a/plugins/annotate/src/annotate.cpp
4+++ b/plugins/annotate/src/annotate.cpp
5@@ -169,13 +169,10 @@ AnnoScreen::drawRectangle (double x,
6
7 if (cr)
8 {
9- double ex1, ey1, ex2, ey2;
10-
11 setSourceColor (cr, fillColor);
12 cairo_rectangle (cr, x, y, w, h);
13 cairo_fill_preserve (cr);
14 cairo_set_line_width (cr, strokeWidth);
15- cairo_stroke_extents (cr, &ex1, &ey1, &ex2, &ey2);
16 setSourceColor (cr, strokeColor);
17 cairo_stroke (cr);
18
19@@ -195,12 +192,9 @@ AnnoScreen::drawLine (double x1,
20
21 if (cr)
22 {
23- double ex1, ey1, ex2, ey2;
24-
25 cairo_set_line_width (cr, width);
26 cairo_move_to (cr, x1, y1);
27 cairo_line_to (cr, x2, y2);
28- cairo_stroke_extents (cr, &ex1, &ey1, &ex2, &ey2);
29 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
30 setSourceColor (cr, color);
31 cairo_stroke (cr);
32@@ -219,9 +213,9 @@ AnnoScreen::drawText (double x,
33 cairo_font_weight_t fontWeight,
34 unsigned short *fillColor,
35 unsigned short *strokeColor,
36- double strokeWidth)
37+ double strokeWidth,
38+ CompRect& damageRect)
39 {
40- REGION reg;
41 cairo_t *cr = cairoContext ();
42
43 if (cr)
44@@ -240,14 +234,10 @@ AnnoScreen::drawText (double x,
45 setSourceColor (cr, strokeColor);
46 cairo_stroke (cr);
47 cairo_restore (cr);
48-
49- reg.rects = &reg.extents;
50- reg.numRects = 1;
51-
52- reg.extents.x1 = x;
53- reg.extents.y1 = y + extents.y_bearing - 2.0;
54- reg.extents.x2 = x + extents.width + 20.0;
55- reg.extents.y2 = y + extents.height;
56+
57+ damageRect.setGeometry (x, y + extents.y_bearing - 2.0,
58+ extents.width + 20.0,
59+ extents.height - extents.y_bearing + 2.0);
60
61 content = true;
62 }
63@@ -299,10 +289,11 @@ AnnoScreen::draw (CompAction *action,
64
65 if (cr)
66 {
67- const char *tool;
68+ CompString tool;
69 unsigned short *fillColor, *strokeColor;
70+ CompRect damageRect;
71
72- tool = CompOption::getStringOptionNamed (options, "tool", "line").c_str ();
73+ tool = CompOption::getStringOptionNamed (options, "tool", "line");
74
75 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
76 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
77@@ -319,7 +310,7 @@ AnnoScreen::draw (CompAction *action,
78 strokeWidth = CompOption::getFloatOptionNamed (options, "stroke_width",
79 strokeWidth);
80
81- if (strcasecmp (tool, "rectangle") == 0)
82+ if (strcasecmp (tool.c_str (), "rectangle") == 0)
83 {
84 double x = CompOption::getFloatOptionNamed (options, "x", 0);
85 double y = CompOption::getFloatOptionNamed (options, "y", 0);
86@@ -328,8 +319,10 @@ AnnoScreen::draw (CompAction *action,
87
88 drawRectangle (x, y, w, h, fillColor, strokeColor,
89 strokeWidth);
90+ damageRect.setGeometry (x, y, w, h);
91+
92 }
93- else if (strcasecmp (tool, "ellipse") == 0)
94+ else if (strcasecmp (tool.c_str (), "ellipse") == 0)
95 {
96 double xc = CompOption::getFloatOptionNamed (options, "xc", 0);
97 double yc = CompOption::getFloatOptionNamed (options, "yc", 0);
98@@ -338,35 +331,38 @@ AnnoScreen::draw (CompAction *action,
99
100 drawEllipse (xc, yc, xr, yr, fillColor, strokeColor,
101 strokeWidth);
102+ damageRect.setGeometry (xc - xr, yc - yr, 2 * xr, 2 * yr);
103 }
104- else if (strcasecmp (tool, "line") == 0)
105+ else if (strcasecmp (tool.c_str (), "line") == 0)
106 {
107 double x1 = CompOption::getFloatOptionNamed (options, "x1", 0);
108 double y1 = CompOption::getFloatOptionNamed (options, "y1", 0);
109 double x2 = CompOption::getFloatOptionNamed (options, "x2", 100);
110 double y2 = CompOption::getFloatOptionNamed (options, "y2", 100);
111
112- drawLine (x1, y1, x2, y2, strokeWidth, fillColor);
113+ drawLine (x1, y1, x2, y2, strokeWidth, strokeColor);
114+ damageRect.setGeometry (MIN (x1, x2), MIN (y1, y2),
115+ abs (x1 - x2), abs (y1 - y2) );
116 }
117- else if (strcasecmp (tool, "text") == 0)
118+ else if (strcasecmp (tool.c_str (), "text") == 0)
119 {
120- const char *text, *family;
121+ CompString text, family;
122 cairo_font_slant_t slant;
123 cairo_font_weight_t weight;
124- const char *str;
125+ CompString str;
126
127- str = CompOption::getStringOptionNamed (options, "slant", "").c_str ();
128+ str = CompOption::getStringOptionNamed (options, "slant", "");
129
130- if (strcasecmp (str, "oblique") == 0)
131+ if (strcasecmp (str.c_str (), "oblique") == 0)
132 slant = CAIRO_FONT_SLANT_OBLIQUE;
133- else if (strcasecmp (str, "italic") == 0)
134+ else if (strcasecmp (str.c_str (), "italic") == 0)
135 slant = CAIRO_FONT_SLANT_ITALIC;
136 else
137 slant = CAIRO_FONT_SLANT_NORMAL;
138
139- str = CompOption::getStringOptionNamed (options, "weight", "").c_str ();
140+ str = CompOption::getStringOptionNamed (options, "weight", "");
141
142- if (strcasecmp (str, "bold") == 0)
143+ if (strcasecmp (str.c_str (), "bold") == 0)
144 weight = CAIRO_FONT_WEIGHT_BOLD;
145 else
146 weight = CAIRO_FONT_WEIGHT_NORMAL;
147@@ -374,16 +370,27 @@ AnnoScreen::draw (CompAction *action,
148 double x = CompOption::getFloatOptionNamed (options, "x", 0);
149 double y = CompOption::getFloatOptionNamed (options, "y", 0);
150
151- text = CompOption::getStringOptionNamed (options, "text", "").c_str ();
152+ text = CompOption::getStringOptionNamed (options, "text", "");
153
154 family = CompOption::getStringOptionNamed (options, "family",
155- "Sans").c_str ();
156+ "Sans");
157
158 double size = CompOption::getFloatOptionNamed (options, "size", 36.0);
159
160- drawText (x, y, text, family, size, slant, weight,
161- fillColor, strokeColor, strokeWidth);
162+ drawText (x, y, text.c_str (), family.c_str (), size, slant,
163+ weight, fillColor, strokeColor, strokeWidth, damageRect);
164 }
165+ else
166+ return true;
167+
168+ /* Add border width to the damage region */
169+ damageRect.setGeometry (damageRect.x () - (strokeWidth / 2),
170+ damageRect.y () - (strokeWidth / 2),
171+ damageRect.width () + strokeWidth + 1,
172+ damageRect.height () + strokeWidth + 1);
173+
174+ cScreen->damageRegion (damageRect);
175+ gScreen->glPaintOutputSetEnabled (this, true);
176 }
177
178 return true;
179diff --git a/plugins/annotate/src/annotate.h b/plugins/annotate/src/annotate.h
180index 0df450c..273557a 100644
181--- a/plugins/annotate/src/annotate.h
182+++ b/plugins/annotate/src/annotate.h
183@@ -136,7 +136,8 @@ class AnnoScreen :
184 cairo_font_weight_t fontWeight,
185 unsigned short *fillColor,
186 unsigned short *strokeColor,
187- double strokeWidth);
188+ double strokeWidth,
189+ CompRect& damageRect);
190
191 /* Actions */
192

Subscribers

People subscribed via source and target branches