Merge lp:~alan-griffiths/mir/fix-1717061 into lp:mir
- fix-1717061
- Merge into development-branch
Status: | Merged |
---|---|
Merged at revision: | 4255 |
Proposed branch: | lp:~alan-griffiths/mir/fix-1717061 |
Merge into: | lp:mir |
Prerequisite: | lp:~alan-griffiths/mir/fix-FTBFS-on-artful-clang |
Diff against target: |
316 lines (+160/-23) 7 files modified
debian/changelog (+2/-0) src/miral/CMakeLists.txt (+1/-0) src/miral/window_info.cpp (+49/-15) src/miral/window_info_defaults.h (+36/-0) src/miral/window_management_trace.cpp (+10/-8) tests/miral/CMakeLists.txt (+1/-0) tests/miral/window_info.cpp (+61/-0) |
To merge this branch: | bzr merge lp:~alan-griffiths/mir/fix-1717061 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mir CI Bot | continuous-integration | Needs Fixing | |
Gerry Boland (community) | Approve | ||
Review via email: mp+330820@code.launchpad.net |
Commit message
Clamp the window aspect ratio dimensions (to avoid ldiv0) and define default window settings in one place. (LP: #1717061)
Description of the change
Mir CI Bot (mir-ci-bot) wrote : | # |
Mir CI Bot (mir-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:4256
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
ABORTED: https:/
ABORTED: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
Gerry Boland (gerboland) wrote : | # |
+unsigned clamp_dim(unsigned dim)
+{
+ return std::min<unsigned long>(std:
+}
Why max "long" - the signedness of it confuses me. What is this clamping "dim" to?
If sizeof(unsigned) < sizeof(long), this always returns "dim", so the only interesting case is if sizeof(unsigned) == sizeof(long), where this clamps dim in the bottom 1/2 of the unsigned ints. Intended?
Alan Griffiths (alan-griffiths) wrote : | # |
> +unsigned clamp_dim(unsigned dim)
> +{
> + return std::min<unsigned long>(std:
> +}
>
> Why max "long" - the signedness of it confuses me. What is this clamping "dim"
> to?
>
> If sizeof(unsigned) < sizeof(long), this always returns "dim", so the only
> interesting case is if sizeof(unsigned) == sizeof(long), where this clamps dim
> in the bottom 1/2 of the unsigned ints. Intended?
That was the intent, yes. To clamp dim to the shared range of long and unsigned int.
Gerry Boland (gerboland) wrote : | # |
So you want bottom 1/2 only to ensure the sign bit is always positive. Ok
Mir CI Bot (mir-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:4258
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Mir CI Bot (mir-ci-bot) wrote : | # |
FAILED: Autolanding.
More details in the following jenkins job:
https:/
Executed test runs:
FAILURE: https:/
None: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Mir CI Bot (mir-ci-bot) wrote : | # |
FAILED: Autolanding.
More details in the following jenkins job:
https:/
Executed test runs:
FAILURE: https:/
None: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
Alan Griffiths (alan-griffiths) wrote : | # |
Landing by hand
Preview Diff
1 | === modified file 'debian/changelog' |
2 | --- debian/changelog 2017-09-14 09:27:21 +0000 |
3 | +++ debian/changelog 2017-09-18 08:45:41 +0000 |
4 | @@ -47,6 +47,8 @@ |
5 | . [miral-shell] Don't allow splashscreen to be occluded (LP: #1705973) |
6 | . [miral-shell] Update maximized windows on display changes (LP: #1705695) |
7 | . Make racy DragAndDrop test reliable. (LP: #1704780) |
8 | + . [libmiral] Define default window settings in one place and clamp the |
9 | + actual values to avoid ldiv0. (LP: #1717061) |
10 | |
11 | -- Alan Griffiths <alan.griffiths@canonical.com> Thu, 10 Aug 2017 11:54:30 +0000 |
12 | |
13 | |
14 | === modified file 'src/miral/CMakeLists.txt' |
15 | --- src/miral/CMakeLists.txt 2017-09-08 08:45:02 +0000 |
16 | +++ src/miral/CMakeLists.txt 2017-09-18 08:45:41 +0000 |
17 | @@ -61,6 +61,7 @@ |
18 | window_manager_tools.cpp ${miral_include}/miral/window_manager_tools.h |
19 | ${miral_include}/miral/window_management_policy_addendum2.h |
20 | ${miral_include}/miral/window_management_policy_addendum3.h |
21 | + window_info_defaults.h |
22 | ) |
23 | |
24 | target_include_directories(mirclientcpp |
25 | |
26 | === modified file 'src/miral/window_info.cpp' |
27 | --- src/miral/window_info.cpp 2017-08-21 14:18:55 +0000 |
28 | +++ src/miral/window_info.cpp 2017-09-18 08:45:41 +0000 |
29 | @@ -17,6 +17,7 @@ |
30 | */ |
31 | |
32 | #include "miral/window_info.h" |
33 | +#include "window_info_defaults.h" |
34 | |
35 | #include "both_versions.h" |
36 | |
37 | @@ -35,7 +36,40 @@ |
38 | { |
39 | return optional_value.is_set() ? optional_value.value() : default_; |
40 | } |
41 | -} |
42 | + |
43 | +unsigned clamp_dim(unsigned dim) |
44 | +{ |
45 | + return std::min<unsigned long>(std::numeric_limits<long>::max(), dim); |
46 | +} |
47 | + |
48 | +// For our convenience when doing calculations we clamp the dimensions of the aspect ratio |
49 | +// so they will fit into a long without overflow. |
50 | +miral::WindowInfo::AspectRatio clamp(miral::WindowInfo::AspectRatio const& source) |
51 | +{ |
52 | + return {clamp_dim(source.width), clamp_dim(source.height)}; |
53 | +} |
54 | + |
55 | +miral::Width clamp(miral::Width const& source) |
56 | +{ |
57 | + return std::min(miral::default_max_width, std::max(miral::default_min_width, source)); |
58 | +} |
59 | + |
60 | +miral::Height clamp(miral::Height const& source) |
61 | +{ |
62 | + return std::min(miral::default_max_height, std::max(miral::default_min_height, source)); |
63 | +} |
64 | +} |
65 | + |
66 | +miral::Width const miral::default_min_width{0}; |
67 | +miral::Height const miral::default_min_height{0}; |
68 | +miral::Width const miral::default_max_width{std::numeric_limits<int>::max()}; |
69 | +miral::Height const miral::default_max_height{std::numeric_limits<int>::max()}; |
70 | +miral::DeltaX const miral::default_width_inc{1}; |
71 | +miral::DeltaY const miral::default_height_inc{1}; |
72 | +miral::WindowInfo::AspectRatio const miral::default_min_aspect_ratio{ |
73 | + clamp(WindowInfo::AspectRatio{0U, std::numeric_limits<unsigned>::max()})}; |
74 | +miral::WindowInfo::AspectRatio const miral::default_max_aspect_ratio{ |
75 | + clamp(WindowInfo::AspectRatio{std::numeric_limits<unsigned>::max(), 0U})}; |
76 | |
77 | struct miral::WindowInfo::Self |
78 | { |
79 | @@ -71,16 +105,16 @@ |
80 | type{optional_value_or_default(params.type(), mir_window_type_normal)}, |
81 | state{optional_value_or_default(params.state(), mir_window_state_restored)}, |
82 | restore_rect{params.top_left().value(), params.size().value()}, |
83 | - min_width{optional_value_or_default(params.min_width())}, |
84 | - min_height{optional_value_or_default(params.min_height())}, |
85 | - max_width{optional_value_or_default(params.max_width(), Width{std::numeric_limits<int>::max()})}, |
86 | - max_height{optional_value_or_default(params.max_height(), Height{std::numeric_limits<int>::max()})}, |
87 | + min_width{optional_value_or_default(params.min_width(), miral::default_min_width)}, |
88 | + min_height{optional_value_or_default(params.min_height(), miral::default_min_height)}, |
89 | + max_width{optional_value_or_default(params.max_width(), miral::default_max_width)}, |
90 | + max_height{optional_value_or_default(params.max_height(), miral::default_max_height)}, |
91 | preferred_orientation{optional_value_or_default(params.preferred_orientation(), mir_orientation_mode_any)}, |
92 | confine_pointer(optional_value_or_default(params.confine_pointer(), mir_pointer_unconfined)), |
93 | - width_inc{optional_value_or_default(params.width_inc(), DeltaX{1})}, |
94 | - height_inc{optional_value_or_default(params.height_inc(), DeltaY{1})}, |
95 | - min_aspect(optional_value_or_default(params.min_aspect(), AspectRatio{0U, std::numeric_limits<unsigned>::max()})), |
96 | - max_aspect(optional_value_or_default(params.max_aspect(), AspectRatio{std::numeric_limits<unsigned>::max(), 0U})), |
97 | + width_inc{optional_value_or_default(params.width_inc(), default_width_inc)}, |
98 | + height_inc{optional_value_or_default(params.height_inc(), default_height_inc)}, |
99 | + min_aspect(optional_value_or_default(params.min_aspect(), default_min_aspect_ratio)), |
100 | + max_aspect(optional_value_or_default(params.max_aspect(), default_max_aspect_ratio)), |
101 | shell_chrome(optional_value_or_default(params.shell_chrome(), mir_shell_chrome_normal)) |
102 | { |
103 | if (params.output_id().is_set()) |
104 | @@ -450,7 +484,7 @@ |
105 | |
106 | void miral::WindowInfo::min_width(mir::geometry::Width min_width) |
107 | { |
108 | - self->min_width = min_width; |
109 | + self->min_width = clamp(min_width); |
110 | } |
111 | |
112 | auto miral::WindowInfo::min_height() const -> mir::geometry::Height |
113 | @@ -460,7 +494,7 @@ |
114 | |
115 | void miral::WindowInfo::min_height(mir::geometry::Height min_height) |
116 | { |
117 | - self->min_height = min_height; |
118 | + self->min_height = clamp(min_height); |
119 | } |
120 | |
121 | auto miral::WindowInfo::max_width() const -> mir::geometry::Width |
122 | @@ -470,7 +504,7 @@ |
123 | |
124 | void miral::WindowInfo::max_width(mir::geometry::Width max_width) |
125 | { |
126 | - self->max_width = max_width; |
127 | + self->max_width = clamp(max_width); |
128 | } |
129 | |
130 | auto miral::WindowInfo::max_height() const -> mir::geometry::Height |
131 | @@ -480,7 +514,7 @@ |
132 | |
133 | void miral::WindowInfo::max_height(mir::geometry::Height max_height) |
134 | { |
135 | - self->max_height = max_height; |
136 | + self->max_height = clamp(max_height); |
137 | } |
138 | |
139 | auto miral::WindowInfo::userdata() const -> std::shared_ptr<void> |
140 | @@ -520,7 +554,7 @@ |
141 | |
142 | void miral::WindowInfo::min_aspect(AspectRatio min_aspect) |
143 | { |
144 | - self->min_aspect = min_aspect; |
145 | + self->min_aspect = clamp(min_aspect); |
146 | } |
147 | |
148 | auto miral::WindowInfo::max_aspect() const -> AspectRatio |
149 | @@ -530,7 +564,7 @@ |
150 | |
151 | void miral::WindowInfo::max_aspect(AspectRatio max_aspect) |
152 | { |
153 | - self->max_aspect = max_aspect; |
154 | + self->max_aspect = clamp(max_aspect); |
155 | } |
156 | |
157 | bool miral::WindowInfo::has_output_id() const |
158 | |
159 | === added file 'src/miral/window_info_defaults.h' |
160 | --- src/miral/window_info_defaults.h 1970-01-01 00:00:00 +0000 |
161 | +++ src/miral/window_info_defaults.h 2017-09-18 08:45:41 +0000 |
162 | @@ -0,0 +1,36 @@ |
163 | +/* |
164 | + * Copyright © 2017 Canonical Ltd. |
165 | + * |
166 | + * This program is free software: you can redistribute it and/or modify it |
167 | + * under the terms of the GNU General Public License version 2 or 3, |
168 | + * as published by the Free Software Foundation. |
169 | + * |
170 | + * This program is distributed in the hope that it will be useful, |
171 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
172 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
173 | + * GNU General Public License for more details. |
174 | + * |
175 | + * You should have received a copy of the GNU General Public License |
176 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
177 | + * |
178 | + * Authored by: Alan Griffiths <alan@octopull.co.uk> |
179 | + */ |
180 | + |
181 | +#ifndef MIR_WINDOW_INFO_DEFAULTS_H |
182 | +#define MIR_WINDOW_INFO_DEFAULTS_H |
183 | + |
184 | +#include "miral/window_info.h" |
185 | + |
186 | +namespace miral |
187 | +{ |
188 | +Width extern const default_min_width; |
189 | +Height extern const default_min_height; |
190 | +Width extern const default_max_width; |
191 | +Height extern const default_max_height; |
192 | +DeltaX extern const default_width_inc; |
193 | +DeltaY extern const default_height_inc; |
194 | +WindowInfo::AspectRatio extern const default_min_aspect_ratio; |
195 | +WindowInfo::AspectRatio extern const default_max_aspect_ratio; |
196 | +} |
197 | + |
198 | +#endif //MIR_WINDOW_INFO_DEFAULTS_H |
199 | |
200 | === modified file 'src/miral/window_management_trace.cpp' |
201 | --- src/miral/window_management_trace.cpp 2017-08-21 14:18:55 +0000 |
202 | +++ src/miral/window_management_trace.cpp 2017-09-18 08:45:41 +0000 |
203 | @@ -17,6 +17,7 @@ |
204 | */ |
205 | |
206 | #include "window_management_trace.h" |
207 | +#include "window_info_defaults.h" |
208 | |
209 | #include <miral/application_info.h> |
210 | #include <miral/window_info.h> |
211 | @@ -133,18 +134,19 @@ |
212 | APPEND(name); |
213 | APPEND(type); |
214 | APPEND(state); |
215 | + bout.append("size", info.window().size()); |
216 | if (info.state() != mir_window_state_restored) APPEND(restore_rect); |
217 | if (std::shared_ptr<mir::scene::Surface> parent = info.parent()) |
218 | bout.append("parent", parent->name()); |
219 | bout.append("children", dump_of(info.children())); |
220 | - if (info.min_width() != Width{0}) APPEND(min_width); |
221 | - if (info.min_height() != Height{0}) APPEND(min_height); |
222 | - if (info.max_width() != Width{std::numeric_limits<int>::max()}) APPEND(max_width); |
223 | - if (info.max_height() != Height{std::numeric_limits<int>::max()}) APPEND(max_height); |
224 | - if (info.width_inc() != DeltaX{1}) APPEND(width_inc); |
225 | - if (info.height_inc() != DeltaY{1}) APPEND(height_inc); |
226 | - if (info.min_aspect() != miral::WindowInfo::AspectRatio{0U, std::numeric_limits<unsigned>::max()}) APPEND(min_aspect); |
227 | - if (info.max_aspect() != miral::WindowInfo::AspectRatio{std::numeric_limits<unsigned>::max(), 0U}) APPEND(max_aspect); |
228 | + if (info.min_width() != miral::default_min_width) APPEND(min_width); |
229 | + if (info.min_height() != miral::default_min_height) APPEND(min_height); |
230 | + if (info.max_width() != miral::default_max_width) APPEND(max_width); |
231 | + if (info.max_height() != miral::default_max_height) APPEND(max_height); |
232 | + if (info.width_inc() != miral::default_width_inc) APPEND(width_inc); |
233 | + if (info.height_inc() != miral::default_height_inc) APPEND(height_inc); |
234 | + if (info.min_aspect() != miral::default_min_aspect_ratio) APPEND(min_aspect); |
235 | + if (info.max_aspect() != miral::default_max_aspect_ratio) APPEND(max_aspect); |
236 | APPEND(preferred_orientation); |
237 | APPEND(confine_pointer); |
238 | |
239 | |
240 | === modified file 'tests/miral/CMakeLists.txt' |
241 | --- tests/miral/CMakeLists.txt 2017-09-14 09:22:16 +0000 |
242 | +++ tests/miral/CMakeLists.txt 2017-09-18 08:45:41 +0000 |
243 | @@ -40,6 +40,7 @@ |
244 | workspaces.cpp |
245 | drag_and_drop.cpp |
246 | client_mediated_gestures.cpp |
247 | + window_info.cpp |
248 | ) |
249 | |
250 | target_link_libraries(miral-test |
251 | |
252 | === added file 'tests/miral/window_info.cpp' |
253 | --- tests/miral/window_info.cpp 1970-01-01 00:00:00 +0000 |
254 | +++ tests/miral/window_info.cpp 2017-09-18 08:45:41 +0000 |
255 | @@ -0,0 +1,61 @@ |
256 | +/* |
257 | + * Copyright © 2017 Canonical Ltd. |
258 | + * |
259 | + * This program is free software: you can redistribute it and/or modify it |
260 | + * under the terms of the GNU General Public License version 2 or 3 as |
261 | + * published by the Free Software Foundation. |
262 | + * |
263 | + * This program is distributed in the hope that it will be useful, |
264 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
265 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
266 | + * GNU General Public License for more details. |
267 | + * |
268 | + * You should have received a copy of the GNU General Public License |
269 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
270 | + * |
271 | + * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com> |
272 | + */ |
273 | + |
274 | +#include <miral/window_info.h> |
275 | + |
276 | +#include "mir_test_framework/process.h" |
277 | + |
278 | +#include <gtest/gtest.h> |
279 | +#include <gmock/gmock.h> |
280 | + |
281 | +using namespace miral; |
282 | +namespace mtf = mir_test_framework; |
283 | + |
284 | +namespace |
285 | +{ |
286 | +static int a_successful_exit_function() |
287 | +{ |
288 | + return EXIT_SUCCESS; |
289 | +} |
290 | +} |
291 | + |
292 | +// Test for crash http://paste.ubuntu.com/25523431/ |
293 | +TEST(WindowInfo, negative_window_size_does_not_divide_by_zero) |
294 | +{ |
295 | + auto p = mtf::fork_and_run_in_a_different_process( |
296 | + [] { |
297 | + Window window; |
298 | + WindowSpecification params; |
299 | + |
300 | + Point p{0, 0}; |
301 | + Size s{-300, -300}; |
302 | + |
303 | + params.name() = ""; |
304 | + params.top_left() = p; |
305 | + params.size() = s; |
306 | + |
307 | + WindowInfo info(window, params); |
308 | + |
309 | + info.min_width(s.width); |
310 | + info.min_height(s.height); |
311 | + |
312 | + info.constrain_resize(p, s); |
313 | + }, a_successful_exit_function); |
314 | + |
315 | + EXPECT_TRUE(p->wait_for_termination().succeeded()); |
316 | +} |
FAILED: Continuous integration, rev:4254 /mir-jenkins. ubuntu. com/job/ mir-ci/ 3662/ /mir-jenkins. ubuntu. com/job/ build-mir/ 5011/console /mir-jenkins. ubuntu. com/job/ build-0- fetch/5240 /mir-jenkins. ubuntu. com/job/ build-1- sourcepkg/ release= artful/ 5228 /mir-jenkins. ubuntu. com/job/ build-1- sourcepkg/ release= xenial/ 5228 /mir-jenkins. ubuntu. com/job/ build-1- sourcepkg/ release= zesty/5228 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= clang,platform= mesa,release= artful/ 5054 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= clang,platform= mesa,release= artful/ 5054/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= clang,platform= mesa,release= zesty/5054/ console /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= artful/ 5054 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= artful/ 5054/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= xenial/ 5054 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= xenial/ 5054/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= amd64,compiler= gcc,platform= mesa,release= zesty/5054/ console /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= cross-armhf, compiler= gcc,platform= mesa,release= artful/ 5054 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= cross-armhf, compiler= gcc,platform= mesa,release= artful/ 5054/artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= cross-armhf, compiler= gcc,platform= mesa,release= zesty/5054 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= cross-armhf, compiler= gcc,platform= mesa,release= zesty/5054/ artifact/ output/ *zip*/output. zip /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= i386,compiler= gcc,platform= mesa,release= xenial/ 5054 /mir-jenkins. ubuntu. com/job/ build-2- binpkg- mir/arch= i386,compiler= gcc,platform= mesa,release= xenial/ 5054/artifact/ output/ *zip*/output. zip
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild: /mir-jenkins. ubuntu. com/job/ mir-ci/ 3662/rebuild
https:/