Merge lp:~alan-griffiths/mir/resize-examples into lp:mir
- resize-examples
- Merge into development-branch
Status: | Merged |
---|---|
Approved by: | Alberto Aguirre |
Approved revision: | no longer in the source branch. |
Merged at revision: | 4188 |
Proposed branch: | lp:~alan-griffiths/mir/resize-examples |
Merge into: | lp:mir |
Prerequisite: | lp:~alan-griffiths/mir/mir_window_get_connection |
Diff against target: |
514 lines (+222/-124) 10 files modified
examples/client_helpers.cpp (+38/-1) examples/client_helpers.h (+1/-0) examples/client_touch_validator.cpp (+4/-1) examples/eglapp.c (+18/-16) examples/eglapp.h (+1/-0) examples/eglsquare.cpp (+120/-100) examples/multi_stream.cpp (+6/-6) examples/prerendered_frames.c (+32/-0) examples/target.c (+1/-0) src/utils/vanity.c (+1/-0) |
To merge this branch: | bzr merge lp:~alan-griffiths/mir/resize-examples |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mir CI Bot | continuous-integration | Approve | |
Alberto Aguirre (community) | Approve | ||
Review via email: mp+325170@code.launchpad.net |
Commit message
Fix window resize logic in example code
Description of the change
Alberto Aguirre (albaguirre) wrote : | # |
It looks like this would be a pretty common thing a client needs to do:
mir_
MirWindowSpec* spec = mir_create_
mir_
mir_
mir_
Maybe a convenience api should be introduced? maybe mir_window_
Mir CI Bot (mir-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:4193
https:/
Executed test runs:
SUCCESS: 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:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Preview Diff
1 | === modified file 'examples/client_helpers.cpp' | |||
2 | --- examples/client_helpers.cpp 2017-05-23 10:51:47 +0000 | |||
3 | +++ examples/client_helpers.cpp 2017-06-06 15:58:12 +0000 | |||
4 | @@ -51,8 +51,14 @@ | |||
5 | 51 | } | 51 | } |
6 | 52 | 52 | ||
7 | 53 | mir::examples::NormalWindow::NormalWindow( | 53 | mir::examples::NormalWindow::NormalWindow( |
8 | 54 | Connection& connection, unsigned int width, unsigned int height, MirRenderSurface* surface) : | ||
9 | 55 | window{create_window(connection, width, height, surface), &mir_window_release_sync} | ||
10 | 56 | { | ||
11 | 57 | } | ||
12 | 58 | |||
13 | 59 | mir::examples::NormalWindow::NormalWindow( | ||
14 | 54 | mir::examples::Connection& connection, unsigned int width, unsigned int height, mir::examples::Context& eglcontext) : | 60 | mir::examples::Connection& connection, unsigned int width, unsigned int height, mir::examples::Context& eglcontext) : |
16 | 55 | window{create_window(connection, width, height, eglcontext.mir_surface()), &mir_window_release_sync} | 61 | NormalWindow(connection, width, height, eglcontext.mir_surface()) |
17 | 56 | { | 62 | { |
18 | 57 | } | 63 | } |
19 | 58 | 64 | ||
20 | @@ -61,6 +67,34 @@ | |||
21 | 61 | return window.get(); | 67 | return window.get(); |
22 | 62 | } | 68 | } |
23 | 63 | 69 | ||
24 | 70 | namespace | ||
25 | 71 | { | ||
26 | 72 | void handle_window_event(MirWindow* window, MirEvent const* event, void* context) | ||
27 | 73 | { | ||
28 | 74 | auto const surface = (MirRenderSurface*)context; | ||
29 | 75 | |||
30 | 76 | switch (mir_event_get_type(event)) | ||
31 | 77 | { | ||
32 | 78 | case mir_event_type_resize: | ||
33 | 79 | { | ||
34 | 80 | MirResizeEvent const* resize = mir_event_get_resize_event(event); | ||
35 | 81 | int const new_width = mir_resize_event_get_width(resize); | ||
36 | 82 | int const new_height = mir_resize_event_get_height(resize); | ||
37 | 83 | |||
38 | 84 | mir_render_surface_set_size(surface, new_width, new_height); | ||
39 | 85 | MirWindowSpec* spec = mir_create_window_spec(mir_window_get_connection(window)); | ||
40 | 86 | mir_window_spec_add_render_surface(spec, surface, new_width, new_height, 0, 0); | ||
41 | 87 | mir_window_apply_spec(window, spec); | ||
42 | 88 | mir_window_spec_release(spec); | ||
43 | 89 | break; | ||
44 | 90 | } | ||
45 | 91 | |||
46 | 92 | default: | ||
47 | 93 | break; | ||
48 | 94 | } | ||
49 | 95 | } | ||
50 | 96 | } | ||
51 | 97 | |||
52 | 64 | MirWindow* me::NormalWindow::create_window( | 98 | MirWindow* me::NormalWindow::create_window( |
53 | 65 | MirConnection* connection, unsigned int width, unsigned int height, MirRenderSurface* surface) | 99 | MirConnection* connection, unsigned int width, unsigned int height, MirRenderSurface* surface) |
54 | 66 | { | 100 | { |
55 | @@ -72,7 +106,10 @@ | |||
56 | 72 | mir_window_spec_set_name(spec.get(), __PRETTY_FUNCTION__); | 106 | mir_window_spec_set_name(spec.get(), __PRETTY_FUNCTION__); |
57 | 73 | 107 | ||
58 | 74 | if (surface) | 108 | if (surface) |
59 | 109 | { | ||
60 | 75 | mir_window_spec_add_render_surface(spec.get(), surface, width, height, 0, 0); | 110 | mir_window_spec_add_render_surface(spec.get(), surface, width, height, 0, 0); |
61 | 111 | mir_window_spec_set_event_handler(spec.get(), &handle_window_event, surface); | ||
62 | 112 | } | ||
63 | 76 | 113 | ||
64 | 77 | auto window = mir_create_window_sync(spec.get()); | 114 | auto window = mir_create_window_sync(spec.get()); |
65 | 78 | return window; | 115 | return window; |
66 | 79 | 116 | ||
67 | === modified file 'examples/client_helpers.h' | |||
68 | --- examples/client_helpers.h 2017-05-26 13:52:51 +0000 | |||
69 | +++ examples/client_helpers.h 2017-06-06 15:58:12 +0000 | |||
70 | @@ -86,6 +86,7 @@ | |||
71 | 86 | public: | 86 | public: |
72 | 87 | NormalWindow(Connection& connection, unsigned int width, unsigned int height); | 87 | NormalWindow(Connection& connection, unsigned int width, unsigned int height); |
73 | 88 | NormalWindow(Connection& connection, unsigned int width, unsigned int height, Context& eglcontext); | 88 | NormalWindow(Connection& connection, unsigned int width, unsigned int height, Context& eglcontext); |
74 | 89 | NormalWindow(Connection& connection, unsigned int width, unsigned int height, MirRenderSurface* surface); | ||
75 | 89 | 90 | ||
76 | 90 | operator MirWindow*() const; | 91 | operator MirWindow*() const; |
77 | 91 | private: | 92 | private: |
78 | 92 | 93 | ||
79 | === modified file 'examples/client_touch_validator.cpp' | |||
80 | --- examples/client_touch_validator.cpp 2017-05-08 03:04:26 +0000 | |||
81 | +++ examples/client_touch_validator.cpp 2017-06-06 15:58:12 +0000 | |||
82 | @@ -134,7 +134,7 @@ | |||
83 | 134 | state->record_event(tev); | 134 | state->record_event(tev); |
84 | 135 | } | 135 | } |
85 | 136 | 136 | ||
87 | 137 | void on_event(MirWindow * /*surface*/, const MirEvent *event, void *context) | 137 | void on_event(MirWindow *window, const MirEvent *event, void *context) |
88 | 138 | { | 138 | { |
89 | 139 | TouchState *state = (TouchState*)context; | 139 | TouchState *state = (TouchState*)context; |
90 | 140 | 140 | ||
91 | @@ -143,6 +143,9 @@ | |||
92 | 143 | case mir_event_type_input: | 143 | case mir_event_type_input: |
93 | 144 | on_input_event(state, mir_event_get_input_event(event)); | 144 | on_input_event(state, mir_event_get_input_event(event)); |
94 | 145 | break; | 145 | break; |
95 | 146 | case mir_event_type_resize: | ||
96 | 147 | egl_app_handle_resize_event(window, mir_event_get_resize_event(event)); | ||
97 | 148 | break; | ||
98 | 146 | case mir_event_type_close_window: | 149 | case mir_event_type_close_window: |
99 | 147 | abort(); | 150 | abort(); |
100 | 148 | break; | 151 | break; |
101 | 149 | 152 | ||
102 | === modified file 'examples/eglapp.c' | |||
103 | --- examples/eglapp.c 2017-05-19 16:18:30 +0000 | |||
104 | +++ examples/eglapp.c 2017-06-06 15:58:12 +0000 | |||
105 | @@ -183,13 +183,24 @@ | |||
106 | 183 | * support for event queuing (directing them to another thread) or | 183 | * support for event queuing (directing them to another thread) or |
107 | 184 | * full single-threaded callbacks. (LP: #1194384). | 184 | * full single-threaded callbacks. (LP: #1194384). |
108 | 185 | */ | 185 | */ |
116 | 186 | { | 186 | egl_app_handle_resize_event(window, mir_event_get_resize_event(ev)); |
117 | 187 | MirResizeEvent const* resize = mir_event_get_resize_event(ev); | 187 | break; |
118 | 188 | int const new_width = mir_resize_event_get_width(resize); | 188 | case mir_event_type_close_window: |
119 | 189 | int const new_height = mir_resize_event_get_height(resize); | 189 | printf("Received close event from server.\n"); |
120 | 190 | 190 | running = 0; | |
121 | 191 | printf("Resized to %dx%d\n", new_width, new_height); | 191 | break; |
122 | 192 | if (surface) | 192 | default: |
123 | 193 | break; | ||
124 | 194 | } | ||
125 | 195 | } | ||
126 | 196 | |||
127 | 197 | void egl_app_handle_resize_event(MirWindow* window, MirResizeEvent const* resize) | ||
128 | 198 | { | ||
129 | 199 | int const new_width = mir_resize_event_get_width(resize); | ||
130 | 200 | int const new_height = mir_resize_event_get_height(resize); | ||
131 | 201 | |||
132 | 202 | printf("Resized to %dx%d\n", new_width, new_height); | ||
133 | 203 | if (surface) | ||
134 | 193 | { | 204 | { |
135 | 194 | mir_render_surface_set_size(surface, new_width, new_height); | 205 | mir_render_surface_set_size(surface, new_width, new_height); |
136 | 195 | MirWindowSpec* spec = mir_create_window_spec(connection); | 206 | MirWindowSpec* spec = mir_create_window_spec(connection); |
137 | @@ -197,15 +208,6 @@ | |||
138 | 197 | mir_window_apply_spec(window, spec); | 208 | mir_window_apply_spec(window, spec); |
139 | 198 | mir_window_spec_release(spec); | 209 | mir_window_spec_release(spec); |
140 | 199 | } | 210 | } |
141 | 200 | } | ||
142 | 201 | break; | ||
143 | 202 | case mir_event_type_close_window: | ||
144 | 203 | printf("Received close event from server.\n"); | ||
145 | 204 | running = 0; | ||
146 | 205 | break; | ||
147 | 206 | default: | ||
148 | 207 | break; | ||
149 | 208 | } | ||
150 | 209 | } | 211 | } |
151 | 210 | 212 | ||
152 | 211 | static void show_help(struct mir_eglapp_arg const* const* arg_lists) | 213 | static void show_help(struct mir_eglapp_arg const* const* arg_lists) |
153 | 212 | 214 | ||
154 | === modified file 'examples/eglapp.h' | |||
155 | --- examples/eglapp.h 2017-05-08 03:04:26 +0000 | |||
156 | +++ examples/eglapp.h 2017-06-06 15:58:12 +0000 | |||
157 | @@ -45,6 +45,7 @@ | |||
158 | 45 | mir_eglapp_bool mir_eglapp_running(void); | 45 | mir_eglapp_bool mir_eglapp_running(void); |
159 | 46 | void mir_eglapp_cleanup(void); | 46 | void mir_eglapp_cleanup(void); |
160 | 47 | void mir_eglapp_handle_event(MirWindow* window, MirEvent const* ev, void* unused); | 47 | void mir_eglapp_handle_event(MirWindow* window, MirEvent const* ev, void* unused); |
161 | 48 | void egl_app_handle_resize_event(MirWindow* window, MirResizeEvent const* resize); | ||
162 | 48 | double mir_eglapp_display_hz(void); | 49 | double mir_eglapp_display_hz(void); |
163 | 49 | 50 | ||
164 | 50 | MirConnection* mir_eglapp_native_connection(); | 51 | MirConnection* mir_eglapp_native_connection(); |
165 | 51 | 52 | ||
166 | === modified file 'examples/eglsquare.cpp' | |||
167 | --- examples/eglsquare.cpp 2017-06-05 09:37:52 +0000 | |||
168 | +++ examples/eglsquare.cpp 2017-06-06 15:58:12 +0000 | |||
169 | @@ -127,106 +127,126 @@ | |||
170 | 127 | if (worker.joinable()) worker.join(); | 127 | if (worker.joinable()) worker.join(); |
171 | 128 | } | 128 | } |
172 | 129 | 129 | ||
273 | 130 | void on_event(MirEvent const* ev) | 130 | void on_event(MirEvent const* event) |
274 | 131 | { | 131 | { |
275 | 132 | if (mir_event_get_type(ev) != mir_event_type_input) | 132 | switch (mir_event_get_type(event)) |
276 | 133 | return; | 133 | { |
277 | 134 | float x{0.0f}; | 134 | case mir_event_type_resize: |
278 | 135 | float y{0.0f}; | 135 | { |
279 | 136 | auto ievent = mir_event_get_input_event(ev); | 136 | MirResizeEvent const* resize = mir_event_get_resize_event(event); |
280 | 137 | if (mir_input_event_get_type(ievent) == mir_input_event_type_touch) | 137 | int const new_width = mir_resize_event_get_width(resize); |
281 | 138 | { | 138 | int const new_height = mir_resize_event_get_height(resize); |
282 | 139 | auto tev = mir_input_event_get_touch_event(ievent); | 139 | |
283 | 140 | x = mir_touch_event_axis_value(tev, 0, mir_touch_axis_x); | 140 | mir_render_surface_set_size(context.mir_surface(), new_width, new_height); |
284 | 141 | y = mir_touch_event_axis_value(tev, 0, mir_touch_axis_y); | 141 | MirWindowSpec* spec = mir_create_window_spec(mir_window_get_connection(window)); |
285 | 142 | } | 142 | mir_window_spec_add_render_surface(spec, context.mir_surface(), new_width, new_height, 0, 0); |
286 | 143 | else if (mir_input_event_get_type(ievent) == mir_input_event_type_pointer) | 143 | mir_window_apply_spec(window, spec); |
287 | 144 | { | 144 | mir_window_spec_release(spec); |
288 | 145 | auto pev = mir_input_event_get_pointer_event(ievent); | 145 | break; |
289 | 146 | x = mir_pointer_event_axis_value(pev, mir_pointer_axis_x); | 146 | } |
290 | 147 | y = mir_pointer_event_axis_value(pev, mir_pointer_axis_y); | 147 | |
291 | 148 | } | 148 | case mir_event_type_input: |
292 | 149 | else | 149 | { |
293 | 150 | { | 150 | float x{0.0f}; |
294 | 151 | return; | 151 | float y{0.0f}; |
295 | 152 | } | 152 | auto ievent = mir_event_get_input_event(event); |
296 | 153 | 153 | if (mir_input_event_get_type(ievent) == mir_input_event_type_touch) | |
297 | 154 | pos = Pos{x, y}; | 154 | { |
298 | 155 | cv.notify_one(); | 155 | auto tev = mir_input_event_get_touch_event(ievent); |
299 | 156 | } | 156 | x = mir_touch_event_axis_value(tev, 0, mir_touch_axis_x); |
300 | 157 | 157 | y = mir_touch_event_axis_value(tev, 0, mir_touch_axis_y); | |
301 | 158 | SquareRenderingSurface(SquareRenderingSurface const&) = delete; | 158 | } |
302 | 159 | SquareRenderingSurface& operator=(SquareRenderingSurface const&) = delete; | 159 | else if (mir_input_event_get_type(ievent) == mir_input_event_type_pointer) |
303 | 160 | private: | 160 | { |
304 | 161 | struct OutputDimensions | 161 | auto pev = mir_input_event_get_pointer_event(ievent); |
305 | 162 | { | 162 | x = mir_pointer_event_axis_value(pev, mir_pointer_axis_x); |
306 | 163 | unsigned int const width; | 163 | y = mir_pointer_event_axis_value(pev, mir_pointer_axis_y); |
307 | 164 | unsigned int const height; | 164 | } |
308 | 165 | } const dimensions; | 165 | else |
309 | 166 | 166 | { | |
310 | 167 | me::Context context; | 167 | return; |
311 | 168 | me::NormalWindow window; | 168 | } |
312 | 169 | RenderProgram program; | 169 | |
313 | 170 | 170 | pos = Pos{x, y}; | |
314 | 171 | OutputDimensions active_output_dimensions(MirConnection* connection) | 171 | cv.notify_one(); |
315 | 172 | { | 172 | } |
316 | 173 | unsigned int width{0}; | 173 | |
317 | 174 | unsigned int height{0}; | 174 | default:; |
318 | 175 | auto display_config = mir_connection_create_display_configuration(connection); | 175 | } |
319 | 176 | auto num_outputs = mir_display_config_get_num_outputs(display_config); | 176 | } |
320 | 177 | for (auto i = 0; i < num_outputs; i++) | 177 | |
321 | 178 | { | 178 | SquareRenderingSurface(SquareRenderingSurface const&) = delete; |
322 | 179 | auto output = mir_display_config_get_output(display_config, i); | 179 | SquareRenderingSurface& operator=(SquareRenderingSurface const&) = delete; |
323 | 180 | auto state = mir_output_get_connection_state(output); | 180 | private: |
324 | 181 | if (state == mir_output_connection_state_connected && mir_output_is_enabled(output)) | 181 | struct OutputDimensions |
325 | 182 | { | 182 | { |
326 | 183 | auto mode = mir_output_get_current_mode(output); | 183 | unsigned int const width; |
327 | 184 | width = mir_output_mode_get_width(mode); | 184 | unsigned int const height; |
328 | 185 | height = mir_output_mode_get_height(mode); | 185 | } const dimensions; |
329 | 186 | break; | 186 | |
330 | 187 | } | 187 | me::Context context; |
331 | 188 | } | 188 | me::NormalWindow window; |
332 | 189 | mir_display_config_release(display_config); | 189 | RenderProgram program; |
333 | 190 | if (width == 0 || height == 0) | 190 | |
334 | 191 | throw std::logic_error("could not determine display size"); | 191 | OutputDimensions active_output_dimensions(MirConnection* connection) |
335 | 192 | return {width, height}; | 192 | { |
336 | 193 | } | 193 | unsigned int width{0}; |
337 | 194 | 194 | unsigned int height{0}; | |
338 | 195 | static void on_event(MirWindow*, const MirEvent *event, void *context) | 195 | auto display_config = mir_connection_create_display_configuration(connection); |
339 | 196 | { | 196 | auto num_outputs = mir_display_config_get_num_outputs(display_config); |
340 | 197 | auto surface = reinterpret_cast<SquareRenderingSurface*>(context); | 197 | for (auto i = 0; i < num_outputs; i++) |
341 | 198 | if (surface) surface->on_event(event); | 198 | { |
342 | 199 | } | 199 | auto output = mir_display_config_get_output(display_config, i); |
343 | 200 | 200 | auto state = mir_output_get_connection_state(output); | |
344 | 201 | private: | 201 | if (state == mir_output_connection_state_connected && mir_output_is_enabled(output)) |
345 | 202 | void do_work() | 202 | { |
346 | 203 | { | 203 | auto mode = mir_output_get_current_mode(output); |
347 | 204 | std::unique_lock<decltype(mutex)> lock(mutex); | 204 | width = mir_output_mode_get_width(mode); |
348 | 205 | 205 | height = mir_output_mode_get_height(mode); | |
349 | 206 | while (true) | 206 | break; |
350 | 207 | { | 207 | } |
351 | 208 | cv.wait(lock); | 208 | } |
352 | 209 | 209 | mir_display_config_release(display_config); | |
353 | 210 | if (!running) return; | 210 | if (width == 0 || height == 0) |
354 | 211 | 211 | throw std::logic_error("could not determine display size"); | |
355 | 212 | Pos pos = this->pos; | 212 | return {width, height}; |
356 | 213 | 213 | } | |
357 | 214 | context.make_current(); | 214 | |
358 | 215 | program.draw( | 215 | static void on_event(MirWindow*, const MirEvent *event, void *context) |
359 | 216 | pos.x/static_cast<float>(dimensions.width)*2.0 - 1.0, | 216 | { |
360 | 217 | pos.y/static_cast<float>(dimensions.height)*-2.0 + 1.0); | 217 | auto surface = reinterpret_cast<SquareRenderingSurface*>(context); |
361 | 218 | context.swapbuffers(); | 218 | if (surface) surface->on_event(event); |
362 | 219 | } | 219 | } |
363 | 220 | } | 220 | |
364 | 221 | 221 | private: | |
365 | 222 | struct Pos { float x; float y; }; | 222 | void do_work() |
366 | 223 | std::atomic<Pos> pos; | 223 | { |
367 | 224 | 224 | std::unique_lock<decltype(mutex)> lock(mutex); | |
368 | 225 | std::thread worker; | 225 | |
369 | 226 | std::condition_variable cv; | 226 | while (true) |
370 | 227 | std::mutex mutex; | 227 | { |
371 | 228 | bool running{true}; | 228 | cv.wait(lock); |
372 | 229 | }; | 229 | |
373 | 230 | if (!running) return; | ||
374 | 231 | |||
375 | 232 | Pos pos = this->pos; | ||
376 | 233 | |||
377 | 234 | context.make_current(); | ||
378 | 235 | program.draw( | ||
379 | 236 | pos.x/static_cast<float>(dimensions.width)*2.0 - 1.0, | ||
380 | 237 | pos.y/static_cast<float>(dimensions.height)*-2.0 + 1.0); | ||
381 | 238 | context.swapbuffers(); | ||
382 | 239 | } | ||
383 | 240 | } | ||
384 | 241 | |||
385 | 242 | struct Pos { float x; float y; }; | ||
386 | 243 | std::atomic<Pos> pos; | ||
387 | 244 | |||
388 | 245 | std::thread worker; | ||
389 | 246 | std::condition_variable cv; | ||
390 | 247 | std::mutex mutex; | ||
391 | 248 | bool running{true}; | ||
392 | 249 | }; | ||
393 | 230 | } | 250 | } |
394 | 231 | 251 | ||
395 | 232 | int main(int argc, char *argv[]) | 252 | int main(int argc, char *argv[]) |
396 | 233 | 253 | ||
397 | === modified file 'examples/multi_stream.cpp' | |||
398 | --- examples/multi_stream.cpp 2017-05-23 10:51:47 +0000 | |||
399 | +++ examples/multi_stream.cpp 2017-06-06 15:58:12 +0000 | |||
400 | @@ -49,8 +49,6 @@ | |||
401 | 49 | 49 | ||
402 | 50 | int displacement_x{0}; | 50 | int displacement_x{0}; |
403 | 51 | int displacement_y{0}; | 51 | int displacement_y{0}; |
404 | 52 | int width{0}; | ||
405 | 53 | int height{0}; | ||
406 | 54 | 52 | ||
407 | 55 | MyBufferStream& operator=(MyBufferStream &&) = default; | 53 | MyBufferStream& operator=(MyBufferStream &&) = default; |
408 | 56 | MyBufferStream(MyBufferStream &&) = default; | 54 | MyBufferStream(MyBufferStream &&) = default; |
409 | @@ -278,7 +276,7 @@ | |||
410 | 278 | 0 | 276 | 0 |
411 | 279 | }; | 277 | }; |
412 | 280 | 278 | ||
414 | 281 | me::NormalWindow window{connection, 200, 200}; | 279 | me::NormalWindow window{connection, 200, 200, stream[0]}; |
415 | 282 | 280 | ||
416 | 283 | while (poll(&signal_poll, 1, 0) <= 0) | 281 | while (poll(&signal_poll, 1, 0) <= 0) |
417 | 284 | { | 282 | { |
418 | @@ -302,8 +300,12 @@ | |||
419 | 302 | auto spec = mir_create_window_spec(connection); | 300 | auto spec = mir_create_window_spec(connection); |
420 | 303 | for (auto& s : stream) | 301 | for (auto& s : stream) |
421 | 304 | { | 302 | { |
422 | 303 | int width{0}; | ||
423 | 304 | int height{0}; | ||
424 | 305 | mir_render_surface_get_size(s, &width, &height); | ||
425 | 306 | |||
426 | 305 | mir_buffer_stream_swap_buffers_sync(s); | 307 | mir_buffer_stream_swap_buffers_sync(s); |
428 | 306 | mir_window_spec_add_render_surface(spec, s, s.width, s.height, s.displacement_x, s.displacement_y); | 308 | mir_window_spec_add_render_surface(spec, s, width, height, s.displacement_x, s.displacement_y); |
429 | 307 | } | 309 | } |
430 | 308 | mir_window_apply_spec(window, spec); | 310 | mir_window_apply_spec(window, spec); |
431 | 309 | mir_window_spec_release(spec); | 311 | mir_window_spec_release(spec); |
432 | @@ -322,8 +324,6 @@ | |||
433 | 322 | int displacement_y) | 324 | int displacement_y) |
434 | 323 | : displacement_x{displacement_x}, | 325 | : displacement_x{displacement_x}, |
435 | 324 | displacement_y{displacement_y}, | 326 | displacement_y{displacement_y}, |
436 | 325 | width{width}, | ||
437 | 326 | height{height}, | ||
438 | 327 | stream{mir_connection_create_render_surface_sync(connection, width, height), &mir_render_surface_release}, | 327 | stream{mir_connection_create_render_surface_sync(connection, width, height), &mir_render_surface_release}, |
439 | 328 | bs{get_stream(connection, width, height)} | 328 | bs{get_stream(connection, width, height)} |
440 | 329 | { | 329 | { |
441 | 330 | 330 | ||
442 | === modified file 'examples/prerendered_frames.c' | |||
443 | --- examples/prerendered_frames.c 2017-05-19 13:49:04 +0000 | |||
444 | +++ examples/prerendered_frames.c 2017-06-06 15:58:12 +0000 | |||
445 | @@ -92,6 +92,36 @@ | |||
446 | 92 | rendering = 0; | 92 | rendering = 0; |
447 | 93 | } | 93 | } |
448 | 94 | 94 | ||
449 | 95 | static void handle_window_event(MirWindow* window, MirEvent const* event, void* context) | ||
450 | 96 | { | ||
451 | 97 | MirRenderSurface* const surface = (MirRenderSurface*)context; | ||
452 | 98 | |||
453 | 99 | switch (mir_event_get_type(event)) | ||
454 | 100 | { | ||
455 | 101 | case mir_event_type_resize: | ||
456 | 102 | { | ||
457 | 103 | MirResizeEvent const* resize = mir_event_get_resize_event(event); | ||
458 | 104 | int const new_width = mir_resize_event_get_width(resize); | ||
459 | 105 | int const new_height = mir_resize_event_get_height(resize); | ||
460 | 106 | |||
461 | 107 | mir_render_surface_set_size(surface, new_width, new_height); | ||
462 | 108 | MirWindowSpec* spec = mir_create_window_spec(mir_window_get_connection(window)); | ||
463 | 109 | mir_window_spec_add_render_surface(spec, surface, new_width, new_height, 0, 0); | ||
464 | 110 | mir_window_apply_spec(window, spec); | ||
465 | 111 | mir_window_spec_release(spec); | ||
466 | 112 | break; | ||
467 | 113 | } | ||
468 | 114 | |||
469 | 115 | case mir_event_type_close_window: | ||
470 | 116 | printf("Received close event from server.\n"); | ||
471 | 117 | rendering = 0; | ||
472 | 118 | break; | ||
473 | 119 | |||
474 | 120 | default: | ||
475 | 121 | break; | ||
476 | 122 | } | ||
477 | 123 | } | ||
478 | 124 | |||
479 | 95 | int main(int argc, char** argv) | 125 | int main(int argc, char** argv) |
480 | 96 | { | 126 | { |
481 | 97 | static char const *socket_file = NULL; | 127 | static char const *socket_file = NULL; |
482 | @@ -165,6 +195,8 @@ | |||
483 | 165 | MirWindowSpec* spec = mir_create_normal_window_spec(connection, width, height); | 195 | MirWindowSpec* spec = mir_create_normal_window_spec(connection, width, height); |
484 | 166 | mir_window_spec_add_render_surface( | 196 | mir_window_spec_add_render_surface( |
485 | 167 | spec, surface, width, height, displacement_x, displacement_y); | 197 | spec, surface, width, height, displacement_x, displacement_y); |
486 | 198 | mir_window_spec_set_event_handler(spec, &handle_window_event, surface); | ||
487 | 199 | mir_window_spec_set_name(spec, "prerendered_frames"); | ||
488 | 168 | MirWindow* window = mir_create_window_sync(spec); | 200 | MirWindow* window = mir_create_window_sync(spec); |
489 | 169 | if (!mir_window_is_valid(window)) | 201 | if (!mir_window_is_valid(window)) |
490 | 170 | { | 202 | { |
491 | 171 | 203 | ||
492 | === modified file 'examples/target.c' | |||
493 | --- examples/target.c 2017-05-08 03:04:26 +0000 | |||
494 | +++ examples/target.c 2017-06-06 15:58:12 +0000 | |||
495 | @@ -196,6 +196,7 @@ | |||
496 | 196 | get_all_touch_points(mir_event_get_input_event(event), &state->touch); | 196 | get_all_touch_points(mir_event_get_input_event(event), &state->touch); |
497 | 197 | break; | 197 | break; |
498 | 198 | case mir_event_type_resize: | 198 | case mir_event_type_resize: |
499 | 199 | egl_app_handle_resize_event(surface, mir_event_get_resize_event(event)); | ||
500 | 199 | state->resized = true; | 200 | state->resized = true; |
501 | 200 | break; | 201 | break; |
502 | 201 | case mir_event_type_close_window: | 202 | case mir_event_type_close_window: |
503 | 202 | 203 | ||
504 | === modified file 'src/utils/vanity.c' | |||
505 | --- src/utils/vanity.c 2017-05-08 03:04:26 +0000 | |||
506 | +++ src/utils/vanity.c 2017-06-06 15:58:12 +0000 | |||
507 | @@ -176,6 +176,7 @@ | |||
508 | 176 | handled = on_surface_event(mir_event_get_window_event(event), state); | 176 | handled = on_surface_event(mir_event_get_window_event(event), state); |
509 | 177 | break; | 177 | break; |
510 | 178 | case mir_event_type_resize: | 178 | case mir_event_type_resize: |
511 | 179 | egl_app_handle_resize_event(surface, mir_event_get_resize_event(event)); | ||
512 | 179 | state->resized = true; | 180 | state->resized = true; |
513 | 180 | break; | 181 | break; |
514 | 181 | default: | 182 | default: |
LGTM.