Merge lp:~alan-griffiths/mir/move-miral-to-mir-cleanup-playground into lp:mir
- move-miral-to-mir-cleanup-playground
- Merge into development-branch
Proposed by
Alan Griffiths
Status: | Superseded |
---|---|
Proposed branch: | lp:~alan-griffiths/mir/move-miral-to-mir-cleanup-playground |
Merge into: | lp:mir |
Prerequisite: | lp:~alan-griffiths/mir/move-miral-to-mir-cleanup |
Diff against target: |
3504 lines (+2/-3095) 43 files modified
examples/miral-shell/CMakeLists.txt (+0/-68) include/miral/miral/command_line_option.h (+0/-112) include/miral/miral/window_management_policy_addendum3.h (+0/-71) include/server/mir/compositor/scene_element.h (+0/-4) include/server/mir/scene/surface.h (+0/-1) include/test/mir/test/doubles/stub_surface.h (+0/-1) playground/CMakeLists.txt (+1/-22) playground/demo-shell/CMakeLists.txt (+0/-19) playground/demo-shell/demo_compositor.cpp (+0/-204) playground/demo-shell/demo_compositor.h (+0/-79) playground/demo-shell/demo_renderer.cpp (+0/-402) playground/demo-shell/demo_renderer.h (+0/-90) playground/demo-shell/demo_shell.cpp (+0/-120) playground/demo-shell/typo/CMakeLists.txt (+0/-23) playground/demo-shell/typo/typo_freetype_renderer.cpp (+0/-125) playground/demo-shell/typo/typo_freetype_renderer.h (+0/-44) playground/demo-shell/typo/typo_glcache.cpp (+0/-99) playground/demo-shell/typo/typo_glcache.h (+0/-56) playground/demo-shell/typo/typo_renderer.cpp (+0/-59) playground/demo-shell/typo/typo_renderer.h (+0/-61) playground/demo-shell/typo/typo_stub_renderer.cpp (+0/-47) playground/demo-shell/typo/typo_stub_renderer.h (+0/-34) playground/demo-shell/window_manager.cpp (+0/-611) playground/demo-shell/window_manager.h (+0/-97) playground/server_configuration.cpp (+0/-86) playground/server_configuration.h (+0/-49) playground/server_example_display_configuration_policy.cpp (+0/-115) playground/server_example_display_configuration_policy.h (+0/-62) src/include/server/mir/compositor/decoration.h (+0/-38) src/miral/CMakeLists.txt (+0/-142) src/miral/miral.pc.in (+0/-12) src/miral/mirclientcpp.pc.in (+0/-10) src/server/scene/basic_surface.cpp (+0/-6) src/server/scene/basic_surface.h (+1/-1) src/server/scene/surface_stack.cpp (+0/-11) tests/include/mir/test/doubles/stub_scene_element.h (+0/-6) tests/include/mir/test/doubles/stub_scene_surface.h (+0/-1) tests/mir_test_framework/stub_surface.cpp (+0/-5) tests/unit-tests/CMakeLists.txt (+0/-2) tests/unit-tests/compositor/test_default_display_buffer_compositor.cpp (+0/-7) tests/unit-tests/scene/test_basic_surface.cpp (+0/-14) tests/unit-tests/scene/test_surface.cpp (+0/-21) tests/unit-tests/scene/test_surface_stack.cpp (+0/-58) |
To merge this branch: | bzr merge lp:~alan-griffiths/mir/move-miral-to-mir-cleanup-playground |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mir development team | Pending | ||
Review via email: mp+329939@code.launchpad.net |
Commit message
Incorporate miral project into mir source tree
This is a third pass at removing code obsoleted by MirAL
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'examples/miral-shell/CMakeLists.txt' | |||
2 | --- examples/miral-shell/CMakeLists.txt 2017-08-30 15:50:37 +0000 | |||
3 | +++ examples/miral-shell/CMakeLists.txt 2017-08-30 15:50:38 +0000 | |||
4 | @@ -1,70 +1,3 @@ | |||
5 | 1 | <<<<<<< TREE | ||
6 | 2 | include_directories( | ||
7 | 3 | ${PROJECT_SOURCE_DIR}/include/miral | ||
8 | 4 | ${PROJECT_SOURCE_DIR}/include/client | ||
9 | 5 | ) | ||
10 | 6 | |||
11 | 7 | add_subdirectory(spinner) | ||
12 | 8 | add_subdirectory(desktop) | ||
13 | 9 | |||
14 | 10 | add_custom_target(miral-run ALL | ||
15 | 11 | cp ${CMAKE_CURRENT_SOURCE_DIR}/miral-run.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/miral-run | ||
16 | 12 | ) | ||
17 | 13 | |||
18 | 14 | install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/miral-run | ||
19 | 15 | DESTINATION ${CMAKE_INSTALL_PREFIX}/bin | ||
20 | 16 | ) | ||
21 | 17 | |||
22 | 18 | add_custom_target(miral-xrun ALL | ||
23 | 19 | cp ${CMAKE_CURRENT_SOURCE_DIR}/miral-xrun.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/miral-xrun | ||
24 | 20 | ) | ||
25 | 21 | |||
26 | 22 | install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/miral-xrun | ||
27 | 23 | DESTINATION ${CMAKE_INSTALL_PREFIX}/bin | ||
28 | 24 | ) | ||
29 | 25 | |||
30 | 26 | add_custom_target(miral-screencast ALL | ||
31 | 27 | cp ${CMAKE_CURRENT_SOURCE_DIR}/miral-screencast.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/miral-screencast | ||
32 | 28 | ) | ||
33 | 29 | |||
34 | 30 | install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/miral-screencast | ||
35 | 31 | DESTINATION ${CMAKE_INSTALL_PREFIX}/bin | ||
36 | 32 | ) | ||
37 | 33 | |||
38 | 34 | add_custom_target(miral-desktop ALL | ||
39 | 35 | cp ${CMAKE_CURRENT_SOURCE_DIR}/miral-desktop.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/miral-desktop | ||
40 | 36 | ) | ||
41 | 37 | |||
42 | 38 | install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/miral-desktop | ||
43 | 39 | DESTINATION ${CMAKE_INSTALL_PREFIX}/bin | ||
44 | 40 | ) | ||
45 | 41 | |||
46 | 42 | add_custom_target(miral-app ALL | ||
47 | 43 | cp ${CMAKE_CURRENT_SOURCE_DIR}/miral-app.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/miral-app | ||
48 | 44 | ) | ||
49 | 45 | |||
50 | 46 | install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/miral-app | ||
51 | 47 | DESTINATION ${CMAKE_INSTALL_PREFIX}/bin | ||
52 | 48 | ) | ||
53 | 49 | |||
54 | 50 | mir_add_wrapped_executable(miral-shell | ||
55 | 51 | shell_main.cpp | ||
56 | 52 | tiling_window_manager.cpp tiling_window_manager.h | ||
57 | 53 | floating_window_manager.cpp floating_window_manager.h | ||
58 | 54 | decoration_provider.cpp decoration_provider.h | ||
59 | 55 | titlebar_config.cpp titlebar_config.h | ||
60 | 56 | ) | ||
61 | 57 | |||
62 | 58 | pkg_check_modules(FREETYPE freetype2 REQUIRED) | ||
63 | 59 | target_include_directories(miral-shell PRIVATE ${FREETYPE_INCLUDE_DIRS}) | ||
64 | 60 | target_compile_definitions(miral-shell PRIVATE -DTYPO_SUPPORTS_FREETYPE) | ||
65 | 61 | target_link_libraries(miral-shell | ||
66 | 62 | miral-spinner | ||
67 | 63 | miral | ||
68 | 64 | ${FREETYPE_LIBRARIES} | ||
69 | 65 | ) | ||
70 | 66 | |||
71 | 67 | ======= | ||
72 | 68 | include_directories( | 1 | include_directories( |
73 | 69 | ${PROJECT_SOURCE_DIR}/include/miral | 2 | ${PROJECT_SOURCE_DIR}/include/miral |
74 | 70 | ${PROJECT_SOURCE_DIR}/include/client | 3 | ${PROJECT_SOURCE_DIR}/include/client |
75 | @@ -134,4 +67,3 @@ | |||
76 | 134 | miral | 67 | miral |
77 | 135 | ) | 68 | ) |
78 | 136 | 69 | ||
79 | 137 | >>>>>>> MERGE-SOURCE | ||
80 | 138 | 70 | ||
81 | === modified file 'include/miral/miral/command_line_option.h' | |||
82 | --- include/miral/miral/command_line_option.h 2017-08-30 15:50:37 +0000 | |||
83 | +++ include/miral/miral/command_line_option.h 2017-08-30 15:50:38 +0000 | |||
84 | @@ -1,114 +1,3 @@ | |||
85 | 1 | <<<<<<< TREE | ||
86 | 2 | /* | ||
87 | 3 | * Copyright © 2016 Canonical Ltd. | ||
88 | 4 | * | ||
89 | 5 | * This program is free software: you can redistribute it and/or modify it | ||
90 | 6 | * under the terms of the GNU General Public License version 2 or 3 as | ||
91 | 7 | * published by the Free Software Foundation. | ||
92 | 8 | * | ||
93 | 9 | * This program is distributed in the hope that it will be useful, | ||
94 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
95 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
96 | 12 | * GNU General Public License for more details. | ||
97 | 13 | * | ||
98 | 14 | * You should have received a copy of the GNU General Public License | ||
99 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
100 | 16 | * | ||
101 | 17 | * Authored by: Alan Griffiths <alan@octopull.co.uk> | ||
102 | 18 | */ | ||
103 | 19 | |||
104 | 20 | #ifndef MIRAL_COMMAND_LINE_OPTION_H | ||
105 | 21 | #define MIRAL_COMMAND_LINE_OPTION_H | ||
106 | 22 | |||
107 | 23 | #include <mir/optional_value.h> | ||
108 | 24 | |||
109 | 25 | #include <functional> | ||
110 | 26 | #include <memory> | ||
111 | 27 | #include <string> | ||
112 | 28 | |||
113 | 29 | namespace mir { class Server; } | ||
114 | 30 | |||
115 | 31 | namespace miral | ||
116 | 32 | { | ||
117 | 33 | /// Add a user configuration option to Mir's option handling. | ||
118 | 34 | /// By default the callback will be invoked following Mir initialisation but | ||
119 | 35 | /// prior to the server starting. The value supplied to the callback will come | ||
120 | 36 | /// from the command line, environment variable, config file or the default. | ||
121 | 37 | /// | ||
122 | 38 | /// \note Except for re-ordering implied by "pre_init()" the callbacks will be | ||
123 | 39 | /// invoked in the order supplied. | ||
124 | 40 | class CommandLineOption | ||
125 | 41 | { | ||
126 | 42 | public: | ||
127 | 43 | CommandLineOption( | ||
128 | 44 | std::function<void(int value)> callback, | ||
129 | 45 | std::string const& option, | ||
130 | 46 | std::string const& description, | ||
131 | 47 | int default_value); | ||
132 | 48 | |||
133 | 49 | CommandLineOption( | ||
134 | 50 | std::function<void(double value)> callback, | ||
135 | 51 | std::string const& option, | ||
136 | 52 | std::string const& description, | ||
137 | 53 | double default_value); | ||
138 | 54 | |||
139 | 55 | CommandLineOption( | ||
140 | 56 | std::function<void(std::string const& value)> callback, | ||
141 | 57 | std::string const& option, | ||
142 | 58 | std::string const& description, | ||
143 | 59 | std::string const& default_value); | ||
144 | 60 | |||
145 | 61 | CommandLineOption( | ||
146 | 62 | std::function<void(std::string const& value)> callback, | ||
147 | 63 | std::string const& option, | ||
148 | 64 | std::string const& description, | ||
149 | 65 | char const* default_value); | ||
150 | 66 | |||
151 | 67 | CommandLineOption( | ||
152 | 68 | std::function<void(bool value)> callback, | ||
153 | 69 | std::string const& option, | ||
154 | 70 | std::string const& description, | ||
155 | 71 | bool default_value); | ||
156 | 72 | |||
157 | 73 | CommandLineOption( | ||
158 | 74 | std::function<void(mir::optional_value<int> const& value)> callback, | ||
159 | 75 | std::string const& option, | ||
160 | 76 | std::string const& description); | ||
161 | 77 | |||
162 | 78 | CommandLineOption( | ||
163 | 79 | std::function<void(mir::optional_value<std::string> const& value)> callback, | ||
164 | 80 | std::string const& option, | ||
165 | 81 | std::string const& description); | ||
166 | 82 | |||
167 | 83 | CommandLineOption( | ||
168 | 84 | std::function<void(mir::optional_value<bool> const& value)> callback, | ||
169 | 85 | std::string const& option, | ||
170 | 86 | std::string const& description); | ||
171 | 87 | |||
172 | 88 | CommandLineOption( | ||
173 | 89 | std::function<void(bool is_set)> callback, | ||
174 | 90 | std::string const& option, | ||
175 | 91 | std::string const& description); | ||
176 | 92 | |||
177 | 93 | void operator()(mir::Server& server) const; | ||
178 | 94 | |||
179 | 95 | // Call the callback *before* Mir initialization starts | ||
180 | 96 | friend auto pre_init(CommandLineOption const& clo) -> CommandLineOption; | ||
181 | 97 | |||
182 | 98 | ~CommandLineOption(); | ||
183 | 99 | CommandLineOption(CommandLineOption const&); | ||
184 | 100 | auto operator=(CommandLineOption const&) -> CommandLineOption&; | ||
185 | 101 | |||
186 | 102 | private: | ||
187 | 103 | struct Self; | ||
188 | 104 | std::shared_ptr<Self> self; | ||
189 | 105 | }; | ||
190 | 106 | |||
191 | 107 | auto pre_init(CommandLineOption const& clo) -> CommandLineOption; | ||
192 | 108 | } | ||
193 | 109 | |||
194 | 110 | #endif //MIRAL_COMMAND_LINE_OPTION_H | ||
195 | 111 | ======= | ||
196 | 112 | /* | 1 | /* |
197 | 113 | * Copyright © 2016 Canonical Ltd. | 2 | * Copyright © 2016 Canonical Ltd. |
198 | 114 | * | 3 | * |
199 | @@ -223,4 +112,3 @@ | |||
200 | 223 | } | 112 | } |
201 | 224 | 113 | ||
202 | 225 | #endif //MIRAL_COMMAND_LINE_OPTION_H | 114 | #endif //MIRAL_COMMAND_LINE_OPTION_H |
203 | 226 | >>>>>>> MERGE-SOURCE | ||
204 | 227 | 115 | ||
205 | === modified file 'include/miral/miral/window_management_policy_addendum3.h' | |||
206 | --- include/miral/miral/window_management_policy_addendum3.h 2017-08-30 15:50:37 +0000 | |||
207 | +++ include/miral/miral/window_management_policy_addendum3.h 2017-08-30 15:50:38 +0000 | |||
208 | @@ -1,73 +1,3 @@ | |||
209 | 1 | <<<<<<< TREE | ||
210 | 2 | /* | ||
211 | 3 | * Copyright © 2017 Canonical Ltd. | ||
212 | 4 | * | ||
213 | 5 | * This program is free software: you can redistribute it and/or modify it | ||
214 | 6 | * under the terms of the GNU General Public License version 2 or 3 as | ||
215 | 7 | * published by the Free Software Foundation. | ||
216 | 8 | * | ||
217 | 9 | * This program is distributed in the hope that it will be useful, | ||
218 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
219 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
220 | 12 | * GNU General Public License for more details. | ||
221 | 13 | * | ||
222 | 14 | * You should have received a copy of the GNU General Public License | ||
223 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
224 | 16 | * | ||
225 | 17 | * Authored by: Alan Griffiths <alan@octopull.co.uk> | ||
226 | 18 | */ | ||
227 | 19 | |||
228 | 20 | #ifndef MIRAL_WINDOW_MANAGEMENT_POLICY_ADDENDUM3_H | ||
229 | 21 | #define MIRAL_WINDOW_MANAGEMENT_POLICY_ADDENDUM3_H | ||
230 | 22 | |||
231 | 23 | #include <mir_toolkit/client_types.h> | ||
232 | 24 | |||
233 | 25 | #include <mir/geometry/rectangles.h> | ||
234 | 26 | #include <mir_toolkit/mir_version_number.h> | ||
235 | 27 | |||
236 | 28 | namespace miral | ||
237 | 29 | { | ||
238 | 30 | using namespace mir::geometry; | ||
239 | 31 | struct WindowInfo; | ||
240 | 32 | |||
241 | 33 | /** | ||
242 | 34 | * Handle additional client requests. | ||
243 | 35 | * | ||
244 | 36 | * \note This interface is intended to be implemented by a WindowManagementPolicy | ||
245 | 37 | * implementation, we can't add these functions directly to that interface without | ||
246 | 38 | * breaking ABI (the vtab could be incompatible). | ||
247 | 39 | * When initializing the window manager this interface will be detected by | ||
248 | 40 | * dynamic_cast and registered accordingly. | ||
249 | 41 | */ | ||
250 | 42 | class WindowManagementPolicyAddendum3 | ||
251 | 43 | { | ||
252 | 44 | public: | ||
253 | 45 | /** Confirm (and optionally adjust) the placement of a window on the display. | ||
254 | 46 | * Called when (re)placing fullscreen, maximized, horizontally maximised and | ||
255 | 47 | * vertically maximized windows to allow adjustment for decorations. | ||
256 | 48 | * | ||
257 | 49 | * @param window_info the window | ||
258 | 50 | * @param new_placement the suggested placement | ||
259 | 51 | * | ||
260 | 52 | * @return the confirmed placement of the window | ||
261 | 53 | */ | ||
262 | 54 | virtual auto confirm_placement_on_display( | ||
263 | 55 | WindowInfo const& window_info, | ||
264 | 56 | MirWindowState new_state, | ||
265 | 57 | Rectangle const& new_placement) -> Rectangle = 0; | ||
266 | 58 | |||
267 | 59 | virtual ~WindowManagementPolicyAddendum3() = default; | ||
268 | 60 | WindowManagementPolicyAddendum3() = default; | ||
269 | 61 | WindowManagementPolicyAddendum3(WindowManagementPolicyAddendum3 const&) = delete; | ||
270 | 62 | WindowManagementPolicyAddendum3& operator=(WindowManagementPolicyAddendum3 const&) = delete; | ||
271 | 63 | }; | ||
272 | 64 | #if MIRAL_VERSION >= MIR_VERSION_NUMBER(2, 0, 0) | ||
273 | 65 | #error "We've presumably broken ABI - please roll this interface into WindowManagementPolicy" | ||
274 | 66 | #endif | ||
275 | 67 | } | ||
276 | 68 | |||
277 | 69 | #endif //MIRAL_WINDOW_MANAGEMENT_POLICY_ADDENDUM3_H | ||
278 | 70 | ======= | ||
279 | 71 | /* | 1 | /* |
280 | 72 | * Copyright © 2017 Canonical Ltd. | 2 | * Copyright © 2017 Canonical Ltd. |
281 | 73 | * | 3 | * |
282 | @@ -137,4 +67,3 @@ | |||
283 | 137 | } | 67 | } |
284 | 138 | 68 | ||
285 | 139 | #endif //MIRAL_WINDOW_MANAGEMENT_POLICY_ADDENDUM3_H | 69 | #endif //MIRAL_WINDOW_MANAGEMENT_POLICY_ADDENDUM3_H |
286 | 140 | >>>>>>> MERGE-SOURCE | ||
287 | 141 | 70 | ||
288 | === modified file 'include/server/mir/compositor/scene_element.h' | |||
289 | --- include/server/mir/compositor/scene_element.h 2017-07-28 17:00:43 +0000 | |||
290 | +++ include/server/mir/compositor/scene_element.h 2017-08-30 15:50:38 +0000 | |||
291 | @@ -39,10 +39,6 @@ | |||
292 | 39 | virtual void rendered() = 0; | 39 | virtual void rendered() = 0; |
293 | 40 | virtual void occluded() = 0; | 40 | virtual void occluded() = 0; |
294 | 41 | 41 | ||
295 | 42 | //TODO: Decoration is opaque on purpose. It is only used by an internal example, | ||
296 | 43 | // and this function should be removed from the public API. | ||
297 | 44 | virtual std::unique_ptr<Decoration> decoration() const = 0; | ||
298 | 45 | |||
299 | 46 | protected: | 42 | protected: |
300 | 47 | SceneElement() = default; | 43 | SceneElement() = default; |
301 | 48 | SceneElement(SceneElement const&) = delete; | 44 | SceneElement(SceneElement const&) = delete; |
302 | 49 | 45 | ||
303 | === modified file 'include/server/mir/scene/surface.h' | |||
304 | --- include/server/mir/scene/surface.h 2017-07-28 17:00:43 +0000 | |||
305 | +++ include/server/mir/scene/surface.h 2017-08-30 15:50:38 +0000 | |||
306 | @@ -66,7 +66,6 @@ | |||
307 | 66 | virtual graphics::RenderableList generate_renderables(compositor::CompositorID id) const = 0; | 66 | virtual graphics::RenderableList generate_renderables(compositor::CompositorID id) const = 0; |
308 | 67 | virtual int buffers_ready_for_compositor(void const* compositor_id) const = 0; | 67 | virtual int buffers_ready_for_compositor(void const* compositor_id) const = 0; |
309 | 68 | 68 | ||
310 | 69 | virtual float alpha() const = 0; //only used in examples/ | ||
311 | 70 | virtual MirWindowType type() const = 0; | 69 | virtual MirWindowType type() const = 0; |
312 | 71 | virtual MirWindowState state() const = 0; | 70 | virtual MirWindowState state() const = 0; |
313 | 72 | virtual void hide() = 0; | 71 | virtual void hide() = 0; |
314 | 73 | 72 | ||
315 | === modified file 'include/test/mir/test/doubles/stub_surface.h' | |||
316 | --- include/test/mir/test/doubles/stub_surface.h 2017-07-28 17:00:43 +0000 | |||
317 | +++ include/test/mir/test/doubles/stub_surface.h 2017-08-30 15:50:38 +0000 | |||
318 | @@ -32,7 +32,6 @@ | |||
319 | 32 | { | 32 | { |
320 | 33 | std::string name() const override; | 33 | std::string name() const override; |
321 | 34 | void move_to(geometry::Point const& top_left) override; | 34 | void move_to(geometry::Point const& top_left) override; |
322 | 35 | float alpha() const override; | ||
323 | 36 | geometry::Size size() const override; | 35 | geometry::Size size() const override; |
324 | 37 | geometry::Size client_size() const override; | 36 | geometry::Size client_size() const override; |
325 | 38 | std::shared_ptr<frontend::BufferStream> primary_buffer_stream() const override; | 37 | std::shared_ptr<frontend::BufferStream> primary_buffer_stream() const override; |
326 | 39 | 38 | ||
327 | === modified file 'playground/CMakeLists.txt' | |||
328 | --- playground/CMakeLists.txt 2017-08-30 15:50:37 +0000 | |||
329 | +++ playground/CMakeLists.txt 2017-08-30 15:50:38 +0000 | |||
330 | @@ -1,27 +1,6 @@ | |||
331 | 1 | |||
332 | 2 | include_directories( | 1 | include_directories( |
333 | 3 | ${PROJECT_SOURCE_DIR}/src/include/server | ||
334 | 4 | ${PROJECT_SOURCE_DIR}/src/include/platform | ||
335 | 5 | ${PROJECT_SOURCE_DIR}/src/include/common | ||
336 | 6 | ${PROJECT_SOURCE_DIR}/src/include/gl | ||
337 | 7 | ${PROJECT_SOURCE_DIR}/src/include/client | ||
338 | 8 | ${PROJECT_SOURCE_DIR}/src/renderers | ||
339 | 9 | ${PROJECT_SOURCE_DIR}/include/client | 2 | ${PROJECT_SOURCE_DIR}/include/client |
355 | 10 | ${PROJECT_SOURCE_DIR}/include/server | 3 | ) |
341 | 11 | ${PROJECT_SOURCE_DIR}/include/platform | ||
342 | 12 | ${PROJECT_SOURCE_DIR}/include/renderer | ||
343 | 13 | ${PROJECT_SOURCE_DIR}/include/renderers/gl | ||
344 | 14 | ${PROJECT_SOURCE_DIR}/examples/ | ||
345 | 15 | ) | ||
346 | 16 | |||
347 | 17 | add_library(playgroundserverconfig STATIC | ||
348 | 18 | server_configuration.cpp | ||
349 | 19 | server_example_display_configuration_policy.cpp | ||
350 | 20 | ) | ||
351 | 21 | |||
352 | 22 | add_subdirectory(demo-shell/) | ||
353 | 23 | |||
354 | 24 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") | ||
356 | 25 | 4 | ||
357 | 26 | mir_add_wrapped_executable(mir_demo_client_egldiamond_render_surface | 5 | mir_add_wrapped_executable(mir_demo_client_egldiamond_render_surface |
358 | 27 | egldiamond_render_surface.c | 6 | egldiamond_render_surface.c |
359 | 28 | 7 | ||
360 | === removed directory 'playground/demo-shell' | |||
361 | === removed file 'playground/demo-shell/CMakeLists.txt' | |||
362 | --- playground/demo-shell/CMakeLists.txt 2017-05-08 03:04:26 +0000 | |||
363 | +++ playground/demo-shell/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
364 | @@ -1,19 +0,0 @@ | |||
365 | 1 | add_library(demo-shell STATIC | ||
366 | 2 | demo_compositor.cpp | ||
367 | 3 | demo_renderer.cpp | ||
368 | 4 | window_manager.cpp | ||
369 | 5 | ) | ||
370 | 6 | |||
371 | 7 | add_subdirectory(typo) | ||
372 | 8 | target_link_libraries(demo-shell typo) | ||
373 | 9 | |||
374 | 10 | mir_add_wrapped_executable(mir_proving_server | ||
375 | 11 | demo_shell.cpp | ||
376 | 12 | ) | ||
377 | 13 | |||
378 | 14 | target_link_libraries(mir_proving_server | ||
379 | 15 | demo-shell | ||
380 | 16 | mirserver | ||
381 | 17 | playgroundserverconfig | ||
382 | 18 | exampleserverconfig | ||
383 | 19 | ) | ||
384 | 20 | 0 | ||
385 | === removed file 'playground/demo-shell/demo_compositor.cpp' | |||
386 | --- playground/demo-shell/demo_compositor.cpp 2017-07-28 17:00:43 +0000 | |||
387 | +++ playground/demo-shell/demo_compositor.cpp 1970-01-01 00:00:00 +0000 | |||
388 | @@ -1,204 +0,0 @@ | |||
389 | 1 | /* | ||
390 | 2 | * Copyright © 2014 Canonical Ltd. | ||
391 | 3 | * | ||
392 | 4 | * This program is free software: you can redistribute it and/or modify | ||
393 | 5 | * it under the terms of the GNU General Public License version 2 or 3 as | ||
394 | 6 | * published by the Free Software Foundation. | ||
395 | 7 | * | ||
396 | 8 | * This program is distributed in the hope that it will be useful, | ||
397 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
398 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
399 | 11 | * GNU General Public License for more details. | ||
400 | 12 | * | ||
401 | 13 | * You should have received a copy of the GNU General Public License | ||
402 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
403 | 15 | * | ||
404 | 16 | * Authored by: Kevin DuBois <kevin.dubois@canonical.com> | ||
405 | 17 | */ | ||
406 | 18 | |||
407 | 19 | #include "mir/graphics/display_buffer.h" | ||
408 | 20 | #include "mir/compositor/compositor_report.h" | ||
409 | 21 | #include "mir/compositor/scene_element.h" | ||
410 | 22 | #include "demo_compositor.h" | ||
411 | 23 | |||
412 | 24 | namespace me = mir::examples; | ||
413 | 25 | namespace mg = mir::graphics; | ||
414 | 26 | namespace mc = mir::compositor; | ||
415 | 27 | namespace geom = mir::geometry; | ||
416 | 28 | |||
417 | 29 | std::mutex me::DemoCompositor::instances_mutex; | ||
418 | 30 | std::unordered_set<me::DemoCompositor*> me::DemoCompositor::instances; | ||
419 | 31 | |||
420 | 32 | me::DemoCompositor::DemoCompositor( | ||
421 | 33 | mg::DisplayBuffer& display_buffer, | ||
422 | 34 | std::shared_ptr<mc::CompositorReport> const& report) : | ||
423 | 35 | display_buffer(display_buffer), | ||
424 | 36 | report(report), | ||
425 | 37 | viewport(display_buffer.view_area()), | ||
426 | 38 | zoom_mag{1.0f}, | ||
427 | 39 | renderer( | ||
428 | 40 | display_buffer, | ||
429 | 41 | 30.0f, //titlebar_height | ||
430 | 42 | 80.0f) //shadow_radius | ||
431 | 43 | { | ||
432 | 44 | std::lock_guard<std::mutex> lock(instances_mutex); | ||
433 | 45 | instances.insert(this); | ||
434 | 46 | } | ||
435 | 47 | |||
436 | 48 | me::DemoCompositor::~DemoCompositor() | ||
437 | 49 | { | ||
438 | 50 | std::lock_guard<std::mutex> lock(instances_mutex); | ||
439 | 51 | instances.erase(this); | ||
440 | 52 | } | ||
441 | 53 | |||
442 | 54 | void me::DemoCompositor::for_each(std::function<void(DemoCompositor&)> f) | ||
443 | 55 | { | ||
444 | 56 | std::lock_guard<std::mutex> lock(instances_mutex); | ||
445 | 57 | for (auto& i : instances) | ||
446 | 58 | f(*i); | ||
447 | 59 | } | ||
448 | 60 | |||
449 | 61 | void me::DemoCompositor::composite(mc::SceneElementSequence&& elements) | ||
450 | 62 | { | ||
451 | 63 | report->began_frame(this); | ||
452 | 64 | //a simple filtering out of renderables that shouldn't be drawn | ||
453 | 65 | //the elements should be notified if they are rendered or not | ||
454 | 66 | bool nonrenderlist_elements{false}; | ||
455 | 67 | mg::RenderableList renderable_list; | ||
456 | 68 | DecorMap decorated; | ||
457 | 69 | |||
458 | 70 | for(auto const& it : elements) | ||
459 | 71 | { | ||
460 | 72 | auto const& renderable = it->renderable(); | ||
461 | 73 | |||
462 | 74 | bool embellished = false; | ||
463 | 75 | if (auto decor = it->decoration()) | ||
464 | 76 | { | ||
465 | 77 | embellished = decor->type != mc::Decoration::Type::none; | ||
466 | 78 | decorated[renderable->id()] = std::move(decor); | ||
467 | 79 | } | ||
468 | 80 | |||
469 | 81 | if (embellished || viewport.overlaps(renderable->screen_position())) | ||
470 | 82 | { | ||
471 | 83 | renderable_list.push_back(renderable); | ||
472 | 84 | |||
473 | 85 | /* | ||
474 | 86 | * TODO: This logic could be replaced more cleanly in future by | ||
475 | 87 | * the surface stack logic setting decoration status more | ||
476 | 88 | * accurately for fullscreen surfaces. | ||
477 | 89 | */ | ||
478 | 90 | // Fullscreen and opaque? Definitely no embellishment | ||
479 | 91 | if (renderable->screen_position() == viewport && | ||
480 | 92 | renderable->alpha() == 1.0f && | ||
481 | 93 | !renderable->shaped() && | ||
482 | 94 | renderable->transformation() == glm::mat4()) | ||
483 | 95 | { | ||
484 | 96 | embellished = false; | ||
485 | 97 | nonrenderlist_elements = false; // Don't care what's underneath | ||
486 | 98 | } | ||
487 | 99 | |||
488 | 100 | it->rendered(); | ||
489 | 101 | } | ||
490 | 102 | else | ||
491 | 103 | { | ||
492 | 104 | it->occluded(); | ||
493 | 105 | } | ||
494 | 106 | nonrenderlist_elements |= embellished; | ||
495 | 107 | } | ||
496 | 108 | |||
497 | 109 | /* | ||
498 | 110 | * Note: Buffer lifetimes are ensured by the two objects holding | ||
499 | 111 | * references to them; elements and renderable_list. | ||
500 | 112 | * So no buffer is going to be released back to the client till | ||
501 | 113 | * both of those containers get destroyed (end of the function). | ||
502 | 114 | * Actually, there's a third reference held by the texture cache | ||
503 | 115 | * in GLRenderer, but that gets released earlier in render(). | ||
504 | 116 | */ | ||
505 | 117 | elements.clear(); // Release those that didn't make it to renderable_list | ||
506 | 118 | |||
507 | 119 | if (!nonrenderlist_elements && | ||
508 | 120 | viewport == display_buffer.view_area() && // no bypass while zoomed | ||
509 | 121 | display_buffer.overlay(renderable_list)) | ||
510 | 122 | { | ||
511 | 123 | report->renderables_in_frame(this, renderable_list); | ||
512 | 124 | renderer.suspend(); | ||
513 | 125 | } | ||
514 | 126 | else | ||
515 | 127 | { | ||
516 | 128 | renderer.set_output_transform(display_buffer.transformation()); | ||
517 | 129 | update_viewport(); | ||
518 | 130 | renderer.set_viewport(viewport); | ||
519 | 131 | renderer.begin(std::move(decorated)); | ||
520 | 132 | renderer.render(renderable_list); | ||
521 | 133 | |||
522 | 134 | report->renderables_in_frame(this, renderable_list); | ||
523 | 135 | report->rendered_frame(this); | ||
524 | 136 | |||
525 | 137 | // Release buffers back to the clients now that the swap has returned. | ||
526 | 138 | // It's important to do this before starting on the potentially slow | ||
527 | 139 | // flip() ... | ||
528 | 140 | // FIXME: This clear() call is blocking a little (LP: #1395421) | ||
529 | 141 | renderable_list.clear(); | ||
530 | 142 | } | ||
531 | 143 | |||
532 | 144 | report->finished_frame(this); | ||
533 | 145 | } | ||
534 | 146 | |||
535 | 147 | void me::DemoCompositor::on_cursor_movement( | ||
536 | 148 | geometry::Point const& p) | ||
537 | 149 | { | ||
538 | 150 | cursor_pos = p; | ||
539 | 151 | if (zoom_mag != 1.0f) | ||
540 | 152 | update_viewport(); | ||
541 | 153 | } | ||
542 | 154 | |||
543 | 155 | void me::DemoCompositor::zoom(float mag) | ||
544 | 156 | { | ||
545 | 157 | zoom_mag = mag; | ||
546 | 158 | update_viewport(); | ||
547 | 159 | } | ||
548 | 160 | |||
549 | 161 | void me::DemoCompositor::set_colour_effect(me::ColourEffect e) | ||
550 | 162 | { | ||
551 | 163 | renderer.set_colour_effect(e); | ||
552 | 164 | } | ||
553 | 165 | |||
554 | 166 | void me::DemoCompositor::update_viewport() | ||
555 | 167 | { | ||
556 | 168 | auto const& view_area = display_buffer.view_area(); | ||
557 | 169 | |||
558 | 170 | if (zoom_mag == 1.0f) | ||
559 | 171 | { | ||
560 | 172 | // The below calculations should yield the same result as this, but | ||
561 | 173 | // just in case there are any floating point precision errors, | ||
562 | 174 | // set it precisely: | ||
563 | 175 | viewport = view_area; | ||
564 | 176 | } | ||
565 | 177 | else | ||
566 | 178 | { | ||
567 | 179 | int db_width = view_area.size.width.as_int(); | ||
568 | 180 | int db_height = view_area.size.height.as_int(); | ||
569 | 181 | int db_x = view_area.top_left.x.as_int(); | ||
570 | 182 | int db_y = view_area.top_left.y.as_int(); | ||
571 | 183 | |||
572 | 184 | float zoom_width = db_width / zoom_mag; | ||
573 | 185 | float zoom_height = db_height / zoom_mag; | ||
574 | 186 | |||
575 | 187 | // Note the 0.5f. This is because cursors (and all input in general) | ||
576 | 188 | // measures coordinates at the centre of a pixel. But GL measures to | ||
577 | 189 | // the top-left corner of a pixel. | ||
578 | 190 | float screen_x = cursor_pos.x.as_int() + 0.5f - db_x; | ||
579 | 191 | float screen_y = cursor_pos.y.as_int() + 0.5f - db_y; | ||
580 | 192 | |||
581 | 193 | float normal_x = screen_x / db_width; | ||
582 | 194 | float normal_y = screen_y / db_height; | ||
583 | 195 | |||
584 | 196 | // Position the viewport so the cursor location matches up. | ||
585 | 197 | // This assumes the hardware cursor still traverses the physical | ||
586 | 198 | // screen and isn't being warped. | ||
587 | 199 | int zoom_x = db_x + (db_width - zoom_width) * normal_x; | ||
588 | 200 | int zoom_y = db_y + (db_height - zoom_height) * normal_y; | ||
589 | 201 | |||
590 | 202 | viewport = {{zoom_x, zoom_y}, {zoom_width, zoom_height}}; | ||
591 | 203 | } | ||
592 | 204 | } | ||
593 | 205 | 0 | ||
594 | === removed file 'playground/demo-shell/demo_compositor.h' | |||
595 | --- playground/demo-shell/demo_compositor.h 2017-07-28 17:00:43 +0000 | |||
596 | +++ playground/demo-shell/demo_compositor.h 1970-01-01 00:00:00 +0000 | |||
597 | @@ -1,79 +0,0 @@ | |||
598 | 1 | /* | ||
599 | 2 | * Copyright © 2014 Canonical Ltd. | ||
600 | 3 | * | ||
601 | 4 | * This program is free software: you can redistribute it and/or modify | ||
602 | 5 | * it under the terms of the GNU General Public License version 2 or 3 as | ||
603 | 6 | * published by the Free Software Foundation. | ||
604 | 7 | * | ||
605 | 8 | * This program is distributed in the hope that it will be useful, | ||
606 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
607 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
608 | 11 | * GNU General Public License for more details. | ||
609 | 12 | * | ||
610 | 13 | * You should have received a copy of the GNU General Public License | ||
611 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
612 | 15 | * | ||
613 | 16 | * Authored by: Kevin DuBois <kevin.dubois@canonical.com> | ||
614 | 17 | */ | ||
615 | 18 | |||
616 | 19 | #ifndef MIR_EXAMPLES_DEMO_COMPOSITOR_H_ | ||
617 | 20 | #define MIR_EXAMPLES_DEMO_COMPOSITOR_H_ | ||
618 | 21 | |||
619 | 22 | #include "mir/compositor/display_buffer_compositor.h" | ||
620 | 23 | #include "mir/compositor/scene.h" | ||
621 | 24 | #include "mir/geometry/rectangle.h" | ||
622 | 25 | #include "mir/graphics/renderable.h" | ||
623 | 26 | #include "demo_renderer.h" | ||
624 | 27 | |||
625 | 28 | #include <mutex> | ||
626 | 29 | #include <set> | ||
627 | 30 | |||
628 | 31 | namespace mir | ||
629 | 32 | { | ||
630 | 33 | namespace compositor | ||
631 | 34 | { | ||
632 | 35 | class Scene; | ||
633 | 36 | class CompositorReport; | ||
634 | 37 | } | ||
635 | 38 | namespace graphics | ||
636 | 39 | { | ||
637 | 40 | class DisplayBuffer; | ||
638 | 41 | } | ||
639 | 42 | namespace examples | ||
640 | 43 | { | ||
641 | 44 | |||
642 | 45 | class DemoCompositor : public compositor::DisplayBufferCompositor | ||
643 | 46 | { | ||
644 | 47 | public: | ||
645 | 48 | DemoCompositor( | ||
646 | 49 | graphics::DisplayBuffer& display_buffer, | ||
647 | 50 | std::shared_ptr<compositor::CompositorReport> const& report); | ||
648 | 51 | ~DemoCompositor(); | ||
649 | 52 | |||
650 | 53 | void composite(compositor::SceneElementSequence&& elements) override; | ||
651 | 54 | |||
652 | 55 | void zoom(float mag); | ||
653 | 56 | void on_cursor_movement(geometry::Point const& p); | ||
654 | 57 | |||
655 | 58 | void set_colour_effect(ColourEffect); | ||
656 | 59 | |||
657 | 60 | static void for_each(std::function<void(DemoCompositor&)> f); | ||
658 | 61 | |||
659 | 62 | private: | ||
660 | 63 | void update_viewport(); | ||
661 | 64 | |||
662 | 65 | graphics::DisplayBuffer& display_buffer; | ||
663 | 66 | std::shared_ptr<compositor::CompositorReport> const report; | ||
664 | 67 | geometry::Rectangle viewport; | ||
665 | 68 | geometry::Point cursor_pos; | ||
666 | 69 | float zoom_mag; | ||
667 | 70 | DemoRenderer renderer; | ||
668 | 71 | |||
669 | 72 | static std::mutex instances_mutex; | ||
670 | 73 | static std::unordered_set<DemoCompositor*> instances; | ||
671 | 74 | }; | ||
672 | 75 | |||
673 | 76 | } // namespace examples | ||
674 | 77 | } // namespace mir | ||
675 | 78 | |||
676 | 79 | #endif // MIR_EXAMPLES_DEMO_COMPOSITOR_H_ | ||
677 | 80 | 0 | ||
678 | === removed file 'playground/demo-shell/demo_renderer.cpp' | |||
679 | --- playground/demo-shell/demo_renderer.cpp 2017-07-28 17:00:43 +0000 | |||
680 | +++ playground/demo-shell/demo_renderer.cpp 1970-01-01 00:00:00 +0000 | |||
681 | @@ -1,402 +0,0 @@ | |||
682 | 1 | /* | ||
683 | 2 | * Copyright © 2014 Canonical Ltd. | ||
684 | 3 | * | ||
685 | 4 | * This program is free software: you can redistribute it and/or modify | ||
686 | 5 | * it under the terms of the GNU General Public License version 2 or 3 as | ||
687 | 6 | * published by the Free Software Foundation. | ||
688 | 7 | * | ||
689 | 8 | * This program is distributed in the hope that it will be useful, | ||
690 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
691 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
692 | 11 | * GNU General Public License for more details. | ||
693 | 12 | * | ||
694 | 13 | * You should have received a copy of the GNU General Public License | ||
695 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
696 | 15 | * | ||
697 | 16 | * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com> | ||
698 | 17 | */ | ||
699 | 18 | |||
700 | 19 | #define MIR_LOG_COMPONENT "DemoRenderer" | ||
701 | 20 | |||
702 | 21 | #include "typo_stub_renderer.h" | ||
703 | 22 | #ifdef TYPO_SUPPORTS_FREETYPE | ||
704 | 23 | #include "typo_freetype_renderer.h" | ||
705 | 24 | #endif | ||
706 | 25 | #include "demo_renderer.h" | ||
707 | 26 | #include <mir/graphics/renderable.h> | ||
708 | 27 | #include <mir/log.h> | ||
709 | 28 | #include <cmath> | ||
710 | 29 | |||
711 | 30 | using namespace mir; | ||
712 | 31 | using namespace mir::examples; | ||
713 | 32 | using namespace mir::geometry; | ||
714 | 33 | using namespace mir::compositor; | ||
715 | 34 | using namespace mir::renderer; | ||
716 | 35 | |||
717 | 36 | namespace | ||
718 | 37 | { | ||
719 | 38 | |||
720 | 39 | struct Color | ||
721 | 40 | { | ||
722 | 41 | GLubyte r, g, b, a; | ||
723 | 42 | }; | ||
724 | 43 | |||
725 | 44 | float penumbra_curve(float x) | ||
726 | 45 | { | ||
727 | 46 | return 1.0f - std::sin(x * M_PI / 2.0f); | ||
728 | 47 | } | ||
729 | 48 | |||
730 | 49 | GLuint generate_shadow_corner_texture(float opacity) | ||
731 | 50 | { | ||
732 | 51 | struct Texel | ||
733 | 52 | { | ||
734 | 53 | GLubyte luminance; | ||
735 | 54 | GLubyte alpha; | ||
736 | 55 | }; | ||
737 | 56 | |||
738 | 57 | int const width = 256; | ||
739 | 58 | Texel image[width][width]; | ||
740 | 59 | |||
741 | 60 | int const max = width - 1; | ||
742 | 61 | for (int y = 0; y < width; ++y) | ||
743 | 62 | { | ||
744 | 63 | float curve_y = opacity * 255.0f * | ||
745 | 64 | penumbra_curve(static_cast<float>(y) / max); | ||
746 | 65 | for (int x = 0; x < width; ++x) | ||
747 | 66 | { | ||
748 | 67 | Texel *t = &image[y][x]; | ||
749 | 68 | t->luminance = 0; | ||
750 | 69 | t->alpha = curve_y * penumbra_curve(static_cast<float>(x) / max); | ||
751 | 70 | } | ||
752 | 71 | } | ||
753 | 72 | |||
754 | 73 | GLuint corner; | ||
755 | 74 | glGenTextures(1, &corner); | ||
756 | 75 | glBindTexture(GL_TEXTURE_2D, corner); | ||
757 | 76 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||
758 | 77 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
759 | 78 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | ||
760 | 79 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | ||
761 | 80 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, | ||
762 | 81 | width, width, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, | ||
763 | 82 | image); | ||
764 | 83 | |||
765 | 84 | return corner; | ||
766 | 85 | } | ||
767 | 86 | |||
768 | 87 | GLuint generate_frame_corner_texture(float corner_radius, | ||
769 | 88 | Color const& color, | ||
770 | 89 | GLubyte highlight) | ||
771 | 90 | { | ||
772 | 91 | int const height = 256; | ||
773 | 92 | /* | ||
774 | 93 | * GCC 4.9 with optimizations enabled will generate armhf NEON/VFP instructions | ||
775 | 94 | * here that are not understood/implemented by Valgrind (but are by hardware), | ||
776 | 95 | * causing Valgrind to crash: | ||
777 | 96 | * eebe 0acc vcvt.s32.f32 s0, s0, #8 | ||
778 | 97 | * So this clumsy expression below tricks the compiler into not using those | ||
779 | 98 | * optimized ARM instructions that Valgrind doesn't support yet: | ||
780 | 99 | */ | ||
781 | 100 | int const width = height / (1.0f / corner_radius); | ||
782 | 101 | Color image[height * height]; // Worst case still much faster than the heap | ||
783 | 102 | |||
784 | 103 | int const cx = width; | ||
785 | 104 | int const cy = cx; | ||
786 | 105 | int const radius_sqr = cx * cy; | ||
787 | 106 | |||
788 | 107 | for (int y = 0; y < height; ++y) | ||
789 | 108 | { | ||
790 | 109 | for (int x = 0; x < width; ++x) | ||
791 | 110 | { | ||
792 | 111 | Color col = color; | ||
793 | 112 | |||
794 | 113 | // Set gradient | ||
795 | 114 | if (y < cy) | ||
796 | 115 | { | ||
797 | 116 | float brighten = (1.0f - (static_cast<float>(y) / cy)) * | ||
798 | 117 | std::sin(x * M_PI / (2 * (width - 1))); | ||
799 | 118 | |||
800 | 119 | col.r += (highlight - col.r) * brighten; | ||
801 | 120 | col.g += (highlight - col.g) * brighten; | ||
802 | 121 | col.b += (highlight - col.b) * brighten; | ||
803 | 122 | } | ||
804 | 123 | |||
805 | 124 | // Cut out the corner in a circular shape. | ||
806 | 125 | if (x < cx && y < cy) | ||
807 | 126 | { | ||
808 | 127 | int dx = cx - x; | ||
809 | 128 | int dy = cy - y; | ||
810 | 129 | if (dx * dx + dy * dy >= radius_sqr) | ||
811 | 130 | col = {0, 0, 0, 0}; | ||
812 | 131 | } | ||
813 | 132 | |||
814 | 133 | image[y * width + x] = col; | ||
815 | 134 | } | ||
816 | 135 | } | ||
817 | 136 | |||
818 | 137 | GLuint corner; | ||
819 | 138 | glGenTextures(1, &corner); | ||
820 | 139 | glBindTexture(GL_TEXTURE_2D, corner); | ||
821 | 140 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, | ||
822 | 141 | GL_LINEAR_MIPMAP_LINEAR); | ||
823 | 142 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
824 | 143 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | ||
825 | 144 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | ||
826 | 145 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, | ||
827 | 146 | width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, | ||
828 | 147 | image); | ||
829 | 148 | glGenerateMipmap(GL_TEXTURE_2D); // Antialiasing please | ||
830 | 149 | |||
831 | 150 | return corner; | ||
832 | 151 | } | ||
833 | 152 | |||
834 | 153 | static const GLchar inverse_fshader[] = | ||
835 | 154 | { | ||
836 | 155 | "#ifdef GL_ES\n" | ||
837 | 156 | "precision mediump float;\n" | ||
838 | 157 | "#endif\n" | ||
839 | 158 | "uniform sampler2D tex;\n" | ||
840 | 159 | "uniform float alpha;\n" | ||
841 | 160 | "varying vec2 v_texcoord;\n" | ||
842 | 161 | "void main() {\n" | ||
843 | 162 | " vec4 f = texture2D(tex, v_texcoord);\n" | ||
844 | 163 | " vec3 inverted = (vec3(1.0) - (f.rgb / f.a)) * f.a;\n" | ||
845 | 164 | " gl_FragColor = alpha*vec4(inverted, f.a);\n" | ||
846 | 165 | "}\n" | ||
847 | 166 | }; | ||
848 | 167 | static const GLchar contrast_fshader[] = | ||
849 | 168 | { | ||
850 | 169 | "#ifdef GL_ES\n" | ||
851 | 170 | "precision mediump float;\n" | ||
852 | 171 | "#endif\n" | ||
853 | 172 | "uniform sampler2D tex;\n" | ||
854 | 173 | "uniform float alpha;\n" | ||
855 | 174 | "varying vec2 v_texcoord;\n" | ||
856 | 175 | "void main() {\n" | ||
857 | 176 | " vec4 raw = texture2D(tex, v_texcoord);\n" | ||
858 | 177 | " vec3 bent = (1.0 - cos(raw.rgb * 3.141592654)) / 2.0;\n" | ||
859 | 178 | " gl_FragColor = alpha * vec4(bent, raw.a);\n" | ||
860 | 179 | "}\n" | ||
861 | 180 | }; | ||
862 | 181 | |||
863 | 182 | } // namespace | ||
864 | 183 | |||
865 | 184 | DemoRenderer::DemoRenderer( | ||
866 | 185 | graphics::DisplayBuffer& display_buffer, | ||
867 | 186 | float const titlebar_height, | ||
868 | 187 | float const shadow_radius) : | ||
869 | 188 | renderer::gl::Renderer(display_buffer), | ||
870 | 189 | titlebar_height{titlebar_height}, | ||
871 | 190 | shadow_radius{shadow_radius}, | ||
872 | 191 | corner_radius{0.5f}, | ||
873 | 192 | colour_effect{none}, | ||
874 | 193 | inverse_program(family.add_program(vshader, inverse_fshader)), | ||
875 | 194 | contrast_program(family.add_program(vshader, contrast_fshader)), | ||
876 | 195 | title_cache(std::make_shared<typo::StubRenderer>()) | ||
877 | 196 | { | ||
878 | 197 | shadow_corner_tex = generate_shadow_corner_texture(0.4f); | ||
879 | 198 | titlebar_corner_tex = generate_frame_corner_texture(corner_radius, | ||
880 | 199 | {128,128,128,255}, | ||
881 | 200 | 255); | ||
882 | 201 | |||
883 | 202 | clear_color[0] = clear_color[1] = clear_color[2] = 0.2f; | ||
884 | 203 | clear_color[3] = 1.0f; | ||
885 | 204 | |||
886 | 205 | #ifdef TYPO_SUPPORTS_FREETYPE | ||
887 | 206 | const char title_font_path[] = "/usr/share/fonts/truetype/liberation/LiberationSans-Bold.ttf"; | ||
888 | 207 | auto ftrenderer = std::make_shared<typo::FreetypeRenderer>(); | ||
889 | 208 | if (ftrenderer->load(title_font_path, 128)) | ||
890 | 209 | title_cache.change_renderer(ftrenderer); | ||
891 | 210 | else | ||
892 | 211 | mir::log_error("Failed to load titlebar font: %s", title_font_path); | ||
893 | 212 | #endif | ||
894 | 213 | } | ||
895 | 214 | |||
896 | 215 | DemoRenderer::~DemoRenderer() | ||
897 | 216 | { | ||
898 | 217 | glDeleteTextures(1, &shadow_corner_tex); | ||
899 | 218 | glDeleteTextures(1, &titlebar_corner_tex); | ||
900 | 219 | } | ||
901 | 220 | |||
902 | 221 | void DemoRenderer::begin(DecorMap&& d) const | ||
903 | 222 | { | ||
904 | 223 | decor_map = std::move(d); | ||
905 | 224 | title_cache.drop_unused(); | ||
906 | 225 | title_cache.mark_all_unused(); | ||
907 | 226 | } | ||
908 | 227 | |||
909 | 228 | void DemoRenderer::tessellate(std::vector<gl::Primitive>& primitives, | ||
910 | 229 | graphics::Renderable const& renderable) const | ||
911 | 230 | { | ||
912 | 231 | renderer::gl::Renderer::tessellate(primitives, renderable); | ||
913 | 232 | auto d = decor_map.find(renderable.id()); | ||
914 | 233 | if (d != decor_map.end()) | ||
915 | 234 | { | ||
916 | 235 | auto& decor = d->second; | ||
917 | 236 | if (decor->type != Decoration::Type::none) | ||
918 | 237 | { | ||
919 | 238 | tessellate_shadow(primitives, renderable, shadow_radius); | ||
920 | 239 | tessellate_frame(primitives, renderable, titlebar_height, | ||
921 | 240 | decor->name.c_str()); | ||
922 | 241 | } | ||
923 | 242 | } | ||
924 | 243 | } | ||
925 | 244 | |||
926 | 245 | void DemoRenderer::tessellate_shadow(std::vector<gl::Primitive>& primitives, | ||
927 | 246 | graphics::Renderable const& renderable, | ||
928 | 247 | float radius) const | ||
929 | 248 | { | ||
930 | 249 | auto const& rect = renderable.screen_position(); | ||
931 | 250 | GLfloat left = rect.top_left.x.as_int(); | ||
932 | 251 | GLfloat right = left + rect.size.width.as_int(); | ||
933 | 252 | GLfloat top = rect.top_left.y.as_int(); | ||
934 | 253 | GLfloat bottom = top + rect.size.height.as_int(); | ||
935 | 254 | |||
936 | 255 | auto n = primitives.size(); | ||
937 | 256 | primitives.resize(n + 8); | ||
938 | 257 | |||
939 | 258 | GLfloat rightr = right + radius; | ||
940 | 259 | GLfloat leftr = left - radius; | ||
941 | 260 | GLfloat topr = top - radius; | ||
942 | 261 | GLfloat bottomr = bottom + radius; | ||
943 | 262 | |||
944 | 263 | auto& right_shadow = primitives[n++]; | ||
945 | 264 | right_shadow.tex_id = shadow_corner_tex; | ||
946 | 265 | right_shadow.vertices[0] = {{right, top, 0.0f}, {0.0f, 0.0f}}; | ||
947 | 266 | right_shadow.vertices[1] = {{rightr, top, 0.0f}, {1.0f, 0.0f}}; | ||
948 | 267 | right_shadow.vertices[2] = {{rightr, bottom, 0.0f}, {1.0f, 0.0f}}; | ||
949 | 268 | right_shadow.vertices[3] = {{right, bottom, 0.0f}, {0.0f, 0.0f}}; | ||
950 | 269 | |||
951 | 270 | auto& left_shadow = primitives[n++]; | ||
952 | 271 | left_shadow.tex_id = shadow_corner_tex; | ||
953 | 272 | left_shadow.vertices[0] = {{leftr, top, 0.0f}, {1.0f, 0.0f}}; | ||
954 | 273 | left_shadow.vertices[1] = {{left, top, 0.0f}, {0.0f, 0.0f}}; | ||
955 | 274 | left_shadow.vertices[2] = {{left, bottom, 0.0f}, {0.0f, 0.0f}}; | ||
956 | 275 | left_shadow.vertices[3] = {{leftr, bottom, 0.0f}, {1.0f, 0.0f}}; | ||
957 | 276 | |||
958 | 277 | auto& top_shadow = primitives[n++]; | ||
959 | 278 | top_shadow.tex_id = shadow_corner_tex; | ||
960 | 279 | top_shadow.vertices[0] = {{left, topr, 0.0f}, {1.0f, 0.0f}}; | ||
961 | 280 | top_shadow.vertices[1] = {{right, topr, 0.0f}, {1.0f, 0.0f}}; | ||
962 | 281 | top_shadow.vertices[2] = {{right, top, 0.0f}, {0.0f, 0.0f}}; | ||
963 | 282 | top_shadow.vertices[3] = {{left, top, 0.0f}, {0.0f, 0.0f}}; | ||
964 | 283 | |||
965 | 284 | auto& bottom_shadow = primitives[n++]; | ||
966 | 285 | bottom_shadow.tex_id = shadow_corner_tex; | ||
967 | 286 | bottom_shadow.vertices[0] = {{left, bottom, 0.0f}, {0.0f, 0.0f}}; | ||
968 | 287 | bottom_shadow.vertices[1] = {{right, bottom, 0.0f}, {0.0f, 0.0f}}; | ||
969 | 288 | bottom_shadow.vertices[2] = {{right, bottomr, 0.0f}, {1.0f, 0.0f}}; | ||
970 | 289 | bottom_shadow.vertices[3] = {{left, bottomr, 0.0f}, {1.0f, 0.0f}}; | ||
971 | 290 | |||
972 | 291 | auto& tr_shadow = primitives[n++]; | ||
973 | 292 | tr_shadow.tex_id = shadow_corner_tex; | ||
974 | 293 | tr_shadow.vertices[0] = {{right, top, 0.0f}, {0.0f, 0.0f}}; | ||
975 | 294 | tr_shadow.vertices[1] = {{right, topr, 0.0f}, {1.0f, 0.0f}}; | ||
976 | 295 | tr_shadow.vertices[2] = {{rightr, topr, 0.0f}, {1.0f, 1.0f}}; | ||
977 | 296 | tr_shadow.vertices[3] = {{rightr, top, 0.0f}, {0.0f, 1.0f}}; | ||
978 | 297 | |||
979 | 298 | auto& br_shadow = primitives[n++]; | ||
980 | 299 | br_shadow.tex_id = shadow_corner_tex; | ||
981 | 300 | br_shadow.vertices[0] = {{right, bottom, 0.0f}, {0.0f, 0.0f}}; | ||
982 | 301 | br_shadow.vertices[1] = {{rightr, bottom, 0.0f}, {1.0f, 0.0f}}; | ||
983 | 302 | br_shadow.vertices[2] = {{rightr, bottomr, 0.0f}, {1.0f, 1.0f}}; | ||
984 | 303 | br_shadow.vertices[3] = {{right, bottomr, 0.0f}, {0.0f, 1.0f}}; | ||
985 | 304 | |||
986 | 305 | auto& bl_shadow = primitives[n++]; | ||
987 | 306 | bl_shadow.tex_id = shadow_corner_tex; | ||
988 | 307 | bl_shadow.vertices[0] = {{left, bottom, 0.0f}, {0.0f, 0.0f}}; | ||
989 | 308 | bl_shadow.vertices[1] = {{left, bottomr, 0.0f}, {1.0f, 0.0f}}; | ||
990 | 309 | bl_shadow.vertices[2] = {{leftr, bottomr, 0.0f}, {1.0f, 1.0f}}; | ||
991 | 310 | bl_shadow.vertices[3] = {{leftr, bottom, 0.0f}, {0.0f, 1.0f}}; | ||
992 | 311 | |||
993 | 312 | auto& tl_shadow = primitives[n++]; | ||
994 | 313 | tl_shadow.tex_id = shadow_corner_tex; | ||
995 | 314 | tl_shadow.vertices[0] = {{left, top, 0.0f}, {0.0f, 0.0f}}; | ||
996 | 315 | tl_shadow.vertices[1] = {{leftr, top, 0.0f}, {1.0f, 0.0f}}; | ||
997 | 316 | tl_shadow.vertices[2] = {{leftr, topr, 0.0f}, {1.0f, 1.0f}}; | ||
998 | 317 | tl_shadow.vertices[3] = {{left, topr, 0.0f}, {0.0f, 1.0f}}; | ||
999 | 318 | } | ||
1000 | 319 | |||
1001 | 320 | void DemoRenderer::tessellate_frame(std::vector<gl::Primitive>& primitives, | ||
1002 | 321 | graphics::Renderable const& renderable, | ||
1003 | 322 | float titlebar_height, | ||
1004 | 323 | char const* name) const | ||
1005 | 324 | { | ||
1006 | 325 | auto const& rect = renderable.screen_position(); | ||
1007 | 326 | GLfloat left = rect.top_left.x.as_int(); | ||
1008 | 327 | GLfloat right = left + rect.size.width.as_int(); | ||
1009 | 328 | GLfloat top = rect.top_left.y.as_int(); | ||
1010 | 329 | |||
1011 | 330 | auto n = primitives.size(); | ||
1012 | 331 | primitives.resize(n + 4); | ||
1013 | 332 | |||
1014 | 333 | GLfloat htop = top - titlebar_height; | ||
1015 | 334 | GLfloat in = titlebar_height * corner_radius; | ||
1016 | 335 | GLfloat inleft = left + in; | ||
1017 | 336 | GLfloat inright = right - in; | ||
1018 | 337 | |||
1019 | 338 | GLfloat mid = (left + right) / 2.0f; | ||
1020 | 339 | if (inleft > mid) inleft = mid; | ||
1021 | 340 | if (inright < mid) inright = mid; | ||
1022 | 341 | |||
1023 | 342 | auto& top_left_corner = primitives[n++]; | ||
1024 | 343 | top_left_corner.tex_id = titlebar_corner_tex; | ||
1025 | 344 | top_left_corner.vertices[0] = {{left, htop, 0.0f}, {0.0f, 0.0f}}; | ||
1026 | 345 | top_left_corner.vertices[1] = {{inleft, htop, 0.0f}, {1.0f, 0.0f}}; | ||
1027 | 346 | top_left_corner.vertices[2] = {{inleft, top, 0.0f}, {1.0f, 1.0f}}; | ||
1028 | 347 | top_left_corner.vertices[3] = {{left, top, 0.0f}, {0.0f, 1.0f}}; | ||
1029 | 348 | |||
1030 | 349 | auto& top_right_corner = primitives[n++]; | ||
1031 | 350 | top_right_corner.tex_id = titlebar_corner_tex; | ||
1032 | 351 | top_right_corner.vertices[0] = {{inright, htop, 0.0f}, {1.0f, 0.0f}}; | ||
1033 | 352 | top_right_corner.vertices[1] = {{right, htop, 0.0f}, {0.0f, 0.0f}}; | ||
1034 | 353 | top_right_corner.vertices[2] = {{right, top, 0.0f}, {0.0f, 1.0f}}; | ||
1035 | 354 | top_right_corner.vertices[3] = {{inright, top, 0.0f}, {1.0f, 1.0f}}; | ||
1036 | 355 | |||
1037 | 356 | auto& titlebar = primitives[n++]; | ||
1038 | 357 | titlebar.tex_id = titlebar_corner_tex; | ||
1039 | 358 | titlebar.vertices[0] = {{inleft, htop, 0.0f}, {1.0f, 0.0f}}; | ||
1040 | 359 | titlebar.vertices[1] = {{inright, htop, 0.0f}, {1.0f, 0.0f}}; | ||
1041 | 360 | titlebar.vertices[2] = {{inright, top, 0.0f}, {1.0f, 1.0f}}; | ||
1042 | 361 | titlebar.vertices[3] = {{inleft, top, 0.0f}, {1.0f, 1.0f}}; | ||
1043 | 362 | |||
1044 | 363 | auto str = title_cache.get(name); | ||
1045 | 364 | GLfloat text_vin = titlebar_height / 5; | ||
1046 | 365 | GLfloat text_top = htop + text_vin; | ||
1047 | 366 | GLfloat text_bot = top - text_vin; | ||
1048 | 367 | GLfloat text_height = text_bot - text_top; | ||
1049 | 368 | GLfloat text_scale = text_height / str.height; | ||
1050 | 369 | GLfloat text_left = inleft; | ||
1051 | 370 | GLfloat text_right = text_left + text_scale * str.width; | ||
1052 | 371 | GLfloat text_u = 1.0f; | ||
1053 | 372 | if (text_right > inright) // Title too long for window | ||
1054 | 373 | { | ||
1055 | 374 | text_u = (inright - text_left) / (text_right - text_left); | ||
1056 | 375 | text_right = inright; | ||
1057 | 376 | } | ||
1058 | 377 | |||
1059 | 378 | auto& text_prim = primitives[n++]; | ||
1060 | 379 | text_prim.tex_id = str.tex; | ||
1061 | 380 | text_prim.vertices[0] = {{text_left, text_top, 0.0f}, {0.0f, 0.0f}}; | ||
1062 | 381 | text_prim.vertices[1] = {{text_right, text_top, 0.0f}, {text_u, 0.0f}}; | ||
1063 | 382 | text_prim.vertices[2] = {{text_right, text_bot, 0.0f}, {text_u, 1.0f}}; | ||
1064 | 383 | text_prim.vertices[3] = {{text_left, text_bot, 0.0f}, {0.0f, 1.0f}}; | ||
1065 | 384 | } | ||
1066 | 385 | |||
1067 | 386 | void DemoRenderer::set_colour_effect(ColourEffect e) | ||
1068 | 387 | { | ||
1069 | 388 | colour_effect = e; | ||
1070 | 389 | } | ||
1071 | 390 | |||
1072 | 391 | void DemoRenderer::draw(graphics::Renderable const& renderable, | ||
1073 | 392 | renderer::gl::Renderer::Program const& current_program) const | ||
1074 | 393 | { | ||
1075 | 394 | const renderer::gl::Renderer::Program* const programs[ColourEffect::neffects] = | ||
1076 | 395 | { | ||
1077 | 396 | ¤t_program, | ||
1078 | 397 | &inverse_program, | ||
1079 | 398 | &contrast_program | ||
1080 | 399 | }; | ||
1081 | 400 | |||
1082 | 401 | renderer::gl::Renderer::draw(renderable, *programs[colour_effect]); | ||
1083 | 402 | } | ||
1084 | 403 | 0 | ||
1085 | === removed file 'playground/demo-shell/demo_renderer.h' | |||
1086 | --- playground/demo-shell/demo_renderer.h 2017-07-28 17:00:43 +0000 | |||
1087 | +++ playground/demo-shell/demo_renderer.h 1970-01-01 00:00:00 +0000 | |||
1088 | @@ -1,90 +0,0 @@ | |||
1089 | 1 | /* | ||
1090 | 2 | * Copyright © 2014 Canonical Ltd. | ||
1091 | 3 | * | ||
1092 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1093 | 5 | * it under the terms of the GNU General Public License version 2 or 3 as | ||
1094 | 6 | * published by the Free Software Foundation. | ||
1095 | 7 | * | ||
1096 | 8 | * This program is distributed in the hope that it will be useful, | ||
1097 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1098 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1099 | 11 | * GNU General Public License for more details. | ||
1100 | 12 | * | ||
1101 | 13 | * You should have received a copy of the GNU General Public License | ||
1102 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1103 | 15 | * | ||
1104 | 16 | * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com> | ||
1105 | 17 | */ | ||
1106 | 18 | |||
1107 | 19 | #ifndef MIR_EXAMPLES_DEMO_RENDERER_H_ | ||
1108 | 20 | #define MIR_EXAMPLES_DEMO_RENDERER_H_ | ||
1109 | 21 | |||
1110 | 22 | #include "gl/renderer.h" | ||
1111 | 23 | #include "mir/compositor/decoration.h" | ||
1112 | 24 | #include "typo_glcache.h" | ||
1113 | 25 | |||
1114 | 26 | #include <unordered_map> | ||
1115 | 27 | |||
1116 | 28 | namespace mir | ||
1117 | 29 | { | ||
1118 | 30 | namespace examples | ||
1119 | 31 | { | ||
1120 | 32 | |||
1121 | 33 | enum ColourEffect | ||
1122 | 34 | { | ||
1123 | 35 | none, | ||
1124 | 36 | inverse, | ||
1125 | 37 | contrast, | ||
1126 | 38 | neffects | ||
1127 | 39 | }; | ||
1128 | 40 | |||
1129 | 41 | typedef std::unordered_map<graphics::Renderable::ID, | ||
1130 | 42 | std::unique_ptr<compositor::Decoration>> DecorMap; | ||
1131 | 43 | |||
1132 | 44 | class DemoRenderer : public renderer::gl::Renderer | ||
1133 | 45 | { | ||
1134 | 46 | public: | ||
1135 | 47 | DemoRenderer( | ||
1136 | 48 | graphics::DisplayBuffer& display_buffer, | ||
1137 | 49 | float const titlebar_height, | ||
1138 | 50 | float const shadow_radius); | ||
1139 | 51 | ~DemoRenderer(); | ||
1140 | 52 | |||
1141 | 53 | void begin(DecorMap&&) const; | ||
1142 | 54 | void set_colour_effect(ColourEffect); | ||
1143 | 55 | |||
1144 | 56 | protected: | ||
1145 | 57 | void tessellate(std::vector<gl::Primitive>& primitives, | ||
1146 | 58 | graphics::Renderable const& renderable) const override; | ||
1147 | 59 | |||
1148 | 60 | void draw(graphics::Renderable const& renderable, | ||
1149 | 61 | Renderer::Program const& prog) const override; | ||
1150 | 62 | |||
1151 | 63 | private: | ||
1152 | 64 | void tessellate_shadow( | ||
1153 | 65 | std::vector<gl::Primitive>& primitives, | ||
1154 | 66 | graphics::Renderable const& renderable, | ||
1155 | 67 | float radius) const; | ||
1156 | 68 | void tessellate_frame( | ||
1157 | 69 | std::vector<gl::Primitive>& primitives, | ||
1158 | 70 | graphics::Renderable const& renderable, | ||
1159 | 71 | float titlebar_height, | ||
1160 | 72 | char const* name) const; | ||
1161 | 73 | |||
1162 | 74 | float const titlebar_height; | ||
1163 | 75 | float const shadow_radius; | ||
1164 | 76 | float const corner_radius; | ||
1165 | 77 | GLuint shadow_corner_tex; | ||
1166 | 78 | GLuint titlebar_corner_tex; | ||
1167 | 79 | |||
1168 | 80 | ColourEffect colour_effect; | ||
1169 | 81 | Program inverse_program, contrast_program; | ||
1170 | 82 | |||
1171 | 83 | mutable DecorMap decor_map; | ||
1172 | 84 | mutable typo::GLCache title_cache; | ||
1173 | 85 | }; | ||
1174 | 86 | |||
1175 | 87 | } // namespace examples | ||
1176 | 88 | } // namespace mir | ||
1177 | 89 | |||
1178 | 90 | #endif // MIR_EXAMPLES_DEMO_RENDERER_H_ | ||
1179 | 91 | 0 | ||
1180 | === removed file 'playground/demo-shell/demo_shell.cpp' | |||
1181 | --- playground/demo-shell/demo_shell.cpp 2017-07-28 17:00:43 +0000 | |||
1182 | +++ playground/demo-shell/demo_shell.cpp 1970-01-01 00:00:00 +0000 | |||
1183 | @@ -1,120 +0,0 @@ | |||
1184 | 1 | /* | ||
1185 | 2 | * Copyright © 2013-2015 Canonical Ltd. | ||
1186 | 3 | * | ||
1187 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1188 | 5 | * it under the terms of the GNU General Public License version 2 or 3 as | ||
1189 | 6 | * published by the Free Software Foundation. | ||
1190 | 7 | * | ||
1191 | 8 | * This program is distributed in the hope that it will be useful, | ||
1192 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1193 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1194 | 11 | * GNU General Public License for more details. | ||
1195 | 12 | * | ||
1196 | 13 | * You should have received a copy of the GNU General Public License | ||
1197 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1198 | 15 | * | ||
1199 | 16 | * Authored by: Robert Carr <robert.carr@canonical.com> | ||
1200 | 17 | */ | ||
1201 | 18 | |||
1202 | 19 | /// \example demo_shell.cpp A simple mir shell | ||
1203 | 20 | |||
1204 | 21 | #include "demo_compositor.h" | ||
1205 | 22 | #include "window_manager.h" | ||
1206 | 23 | #include "../server_configuration.h" | ||
1207 | 24 | |||
1208 | 25 | #include "mir/run_mir.h" | ||
1209 | 26 | #include "mir/report_exception.h" | ||
1210 | 27 | #include "mir/graphics/display.h" | ||
1211 | 28 | #include "mir/input/composite_event_filter.h" | ||
1212 | 29 | #include "mir/compositor/display_buffer_compositor_factory.h" | ||
1213 | 30 | #include "mir/renderer/renderer_factory.h" | ||
1214 | 31 | #include "mir/options/option.h" | ||
1215 | 32 | #include "server_example_host_lifecycle_event_listener.h" | ||
1216 | 33 | |||
1217 | 34 | #include <iostream> | ||
1218 | 35 | |||
1219 | 36 | namespace me = mir::examples; | ||
1220 | 37 | namespace ms = mir::scene; | ||
1221 | 38 | namespace mg = mir::graphics; | ||
1222 | 39 | namespace mf = mir::frontend; | ||
1223 | 40 | namespace mi = mir::input; | ||
1224 | 41 | namespace mc = mir::compositor; | ||
1225 | 42 | namespace msh = mir::shell; | ||
1226 | 43 | |||
1227 | 44 | namespace mir | ||
1228 | 45 | { | ||
1229 | 46 | namespace examples | ||
1230 | 47 | { | ||
1231 | 48 | class DisplayBufferCompositorFactory : public mc::DisplayBufferCompositorFactory | ||
1232 | 49 | { | ||
1233 | 50 | public: | ||
1234 | 51 | DisplayBufferCompositorFactory( | ||
1235 | 52 | std::shared_ptr<mc::CompositorReport> const& report) : | ||
1236 | 53 | report(report) | ||
1237 | 54 | { | ||
1238 | 55 | } | ||
1239 | 56 | |||
1240 | 57 | std::unique_ptr<mc::DisplayBufferCompositor> create_compositor_for( | ||
1241 | 58 | mg::DisplayBuffer& display_buffer) override | ||
1242 | 59 | { | ||
1243 | 60 | return std::unique_ptr<mc::DisplayBufferCompositor>( | ||
1244 | 61 | new me::DemoCompositor{display_buffer, report}); | ||
1245 | 62 | } | ||
1246 | 63 | |||
1247 | 64 | private: | ||
1248 | 65 | std::shared_ptr<mc::CompositorReport> const report; | ||
1249 | 66 | }; | ||
1250 | 67 | |||
1251 | 68 | class DemoServerConfiguration : public mir::examples::ServerConfiguration | ||
1252 | 69 | { | ||
1253 | 70 | public: | ||
1254 | 71 | using mir::examples::ServerConfiguration::ServerConfiguration; | ||
1255 | 72 | |||
1256 | 73 | std::shared_ptr<compositor::DisplayBufferCompositorFactory> the_display_buffer_compositor_factory() override | ||
1257 | 74 | { | ||
1258 | 75 | return display_buffer_compositor_factory( | ||
1259 | 76 | [this]() | ||
1260 | 77 | { | ||
1261 | 78 | return std::make_shared<me::DisplayBufferCompositorFactory>( | ||
1262 | 79 | the_compositor_report()); | ||
1263 | 80 | }); | ||
1264 | 81 | } | ||
1265 | 82 | |||
1266 | 83 | std::shared_ptr<msh::HostLifecycleEventListener> the_host_lifecycle_event_listener() override | ||
1267 | 84 | { | ||
1268 | 85 | return host_lifecycle_event_listener( | ||
1269 | 86 | [this]() | ||
1270 | 87 | { | ||
1271 | 88 | return std::make_shared<HostLifecycleEventListener>(the_logger()); | ||
1272 | 89 | }); | ||
1273 | 90 | } | ||
1274 | 91 | }; | ||
1275 | 92 | |||
1276 | 93 | } | ||
1277 | 94 | } | ||
1278 | 95 | |||
1279 | 96 | int main(int argc, char const* argv[]) | ||
1280 | 97 | try | ||
1281 | 98 | { | ||
1282 | 99 | me::DemoServerConfiguration config(argc, argv); | ||
1283 | 100 | |||
1284 | 101 | auto wm = std::make_shared<me::WindowManager>(); | ||
1285 | 102 | |||
1286 | 103 | mir::run_mir(config, [&config, &wm](mir::DisplayServer&) | ||
1287 | 104 | { | ||
1288 | 105 | // We use this strange two stage initialization to avoid a circular dependency between the EventFilters | ||
1289 | 106 | // and the SessionStore | ||
1290 | 107 | wm->set_focus_controller(config.the_focus_controller()); | ||
1291 | 108 | wm->set_display(config.the_display()); | ||
1292 | 109 | wm->set_compositor(config.the_compositor()); | ||
1293 | 110 | wm->set_input_scene(config.the_input_scene()); | ||
1294 | 111 | |||
1295 | 112 | config.the_composite_event_filter()->prepend(wm); | ||
1296 | 113 | }); | ||
1297 | 114 | return 0; | ||
1298 | 115 | } | ||
1299 | 116 | catch (...) | ||
1300 | 117 | { | ||
1301 | 118 | mir::report_exception(std::cerr); | ||
1302 | 119 | return 1; | ||
1303 | 120 | } | ||
1304 | 121 | 0 | ||
1305 | === removed directory 'playground/demo-shell/typo' | |||
1306 | === removed file 'playground/demo-shell/typo/CMakeLists.txt' | |||
1307 | --- playground/demo-shell/typo/CMakeLists.txt 2017-05-08 03:04:26 +0000 | |||
1308 | +++ playground/demo-shell/typo/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
1309 | @@ -1,23 +0,0 @@ | |||
1310 | 1 | find_package(PkgConfig) | ||
1311 | 2 | |||
1312 | 3 | pkg_search_module(FREETYPE freetype2) | ||
1313 | 4 | if (FREETYPE_FOUND) | ||
1314 | 5 | set(OPTIONAL_SRCS typo_freetype_renderer.cpp) | ||
1315 | 6 | endif () | ||
1316 | 7 | |||
1317 | 8 | add_library(typo STATIC | ||
1318 | 9 | typo_renderer.cpp | ||
1319 | 10 | typo_stub_renderer.cpp | ||
1320 | 11 | typo_glcache.cpp | ||
1321 | 12 | ${OPTIONAL_SRCS} | ||
1322 | 13 | ) | ||
1323 | 14 | |||
1324 | 15 | target_link_libraries(typo ${GL_LIBRARIES}) | ||
1325 | 16 | target_include_directories(typo PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) | ||
1326 | 17 | |||
1327 | 18 | if (FREETYPE_FOUND) | ||
1328 | 19 | target_compile_definitions(typo PUBLIC -DTYPO_SUPPORTS_FREETYPE) | ||
1329 | 20 | target_link_libraries(typo ${FREETYPE_LIBRARIES}) | ||
1330 | 21 | target_include_directories(typo PUBLIC ${FREETYPE_INCLUDE_DIRS}) | ||
1331 | 22 | endif () | ||
1332 | 23 | |||
1333 | 24 | 0 | ||
1334 | === removed file 'playground/demo-shell/typo/typo_freetype_renderer.cpp' | |||
1335 | --- playground/demo-shell/typo/typo_freetype_renderer.cpp 2017-07-28 17:00:43 +0000 | |||
1336 | +++ playground/demo-shell/typo/typo_freetype_renderer.cpp 1970-01-01 00:00:00 +0000 | |||
1337 | @@ -1,125 +0,0 @@ | |||
1338 | 1 | /* | ||
1339 | 2 | * Copyright © 2015 Canonical Ltd. | ||
1340 | 3 | * | ||
1341 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1342 | 5 | * it under the terms of the GNU General Public License version 2 or 3 as | ||
1343 | 6 | * published by the Free Software Foundation. | ||
1344 | 7 | * | ||
1345 | 8 | * This program is distributed in the hope that it will be useful, | ||
1346 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1347 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1348 | 11 | * GNU General Public License for more details. | ||
1349 | 12 | * | ||
1350 | 13 | * You should have received a copy of the GNU General Public License | ||
1351 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1352 | 15 | * | ||
1353 | 16 | * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com> | ||
1354 | 17 | */ | ||
1355 | 18 | |||
1356 | 19 | #include "typo_freetype_renderer.h" | ||
1357 | 20 | #include <stdexcept> | ||
1358 | 21 | #include <cstring> | ||
1359 | 22 | |||
1360 | 23 | using namespace mir::typo; | ||
1361 | 24 | |||
1362 | 25 | FreetypeRenderer::FreetypeRenderer() | ||
1363 | 26 | : lib(nullptr), face(nullptr), preferred_height(16) | ||
1364 | 27 | { | ||
1365 | 28 | if (FT_Init_FreeType(&lib)) | ||
1366 | 29 | throw std::runtime_error("FreeType init failed"); | ||
1367 | 30 | } | ||
1368 | 31 | |||
1369 | 32 | FreetypeRenderer::~FreetypeRenderer() | ||
1370 | 33 | { | ||
1371 | 34 | if (face) FT_Done_Face(face); | ||
1372 | 35 | if (lib) FT_Done_FreeType(lib); | ||
1373 | 36 | } | ||
1374 | 37 | |||
1375 | 38 | bool FreetypeRenderer::load(char const* font_path, int pref_height) | ||
1376 | 39 | { | ||
1377 | 40 | preferred_height = pref_height; | ||
1378 | 41 | |||
1379 | 42 | if (face) | ||
1380 | 43 | { | ||
1381 | 44 | FT_Done_Face(face); | ||
1382 | 45 | face = nullptr; | ||
1383 | 46 | } | ||
1384 | 47 | if (FT_New_Face(lib, font_path, 0, &face)) | ||
1385 | 48 | return false; | ||
1386 | 49 | |||
1387 | 50 | FT_Set_Pixel_Sizes(face, 0, preferred_height); | ||
1388 | 51 | |||
1389 | 52 | return true; | ||
1390 | 53 | } | ||
1391 | 54 | |||
1392 | 55 | void FreetypeRenderer::render(char const* str, Image& img) | ||
1393 | 56 | { | ||
1394 | 57 | int minx = 0, maxx = 0, miny = 0, maxy = 0; | ||
1395 | 58 | int penx = 0, peny = 0; | ||
1396 | 59 | FT_GlyphSlot slot = face->glyph; | ||
1397 | 60 | |||
1398 | 61 | char const* s = str; | ||
1399 | 62 | while (unsigned long u = unicode_from_utf8(&s)) | ||
1400 | 63 | { | ||
1401 | 64 | auto glyph = FT_Get_Char_Index(face, u); | ||
1402 | 65 | FT_Load_Glyph(face, glyph, FT_LOAD_DEFAULT); | ||
1403 | 66 | FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL); | ||
1404 | 67 | |||
1405 | 68 | int left = penx + slot->bitmap_left; | ||
1406 | 69 | if (left < minx) minx = left; | ||
1407 | 70 | |||
1408 | 71 | int right = left + slot->bitmap.width; | ||
1409 | 72 | if (right > maxx) maxx = right; | ||
1410 | 73 | |||
1411 | 74 | int top = peny - slot->bitmap_top; | ||
1412 | 75 | if (top < miny) miny = top; | ||
1413 | 76 | |||
1414 | 77 | int bottom = top + slot->bitmap.rows; | ||
1415 | 78 | if (bottom > maxy) maxy = bottom; | ||
1416 | 79 | |||
1417 | 80 | penx += slot->advance.x >> 6; | ||
1418 | 81 | peny += slot->advance.y >> 6; | ||
1419 | 82 | } | ||
1420 | 83 | |||
1421 | 84 | int const padding = preferred_height / 8; // Allow mipmapping to smear | ||
1422 | 85 | int width = maxx - minx + 1 + 2*padding; | ||
1423 | 86 | int height = maxy - miny + 1; | ||
1424 | 87 | if (height < preferred_height) // e.g. str has no descenders, but make | ||
1425 | 88 | height = preferred_height; // room so we get a consistent height | ||
1426 | 89 | height += 2*padding; | ||
1427 | 90 | penx = -minx + padding; | ||
1428 | 91 | peny = -miny + padding; | ||
1429 | 92 | |||
1430 | 93 | img.reserve(width, height, Image::alpha8); | ||
1431 | 94 | |||
1432 | 95 | s = str; | ||
1433 | 96 | while (unsigned long u = unicode_from_utf8(&s)) | ||
1434 | 97 | { | ||
1435 | 98 | auto glyph = FT_Get_Char_Index(face, u); | ||
1436 | 99 | FT_Load_Glyph(face, glyph, FT_LOAD_DEFAULT); | ||
1437 | 100 | FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL); | ||
1438 | 101 | |||
1439 | 102 | auto& bitmap = slot->bitmap; | ||
1440 | 103 | int x = penx + slot->bitmap_left; | ||
1441 | 104 | int y = peny - slot->bitmap_top; | ||
1442 | 105 | int right = x + bitmap.width; | ||
1443 | 106 | int bottom = y + bitmap.rows; | ||
1444 | 107 | |||
1445 | 108 | if (x >= 0 && right <= width && y >= 0 && bottom <= height) | ||
1446 | 109 | { | ||
1447 | 110 | unsigned char* src = bitmap.buffer; | ||
1448 | 111 | unsigned char* dest = img.data() + y*img.stride() + x; | ||
1449 | 112 | |||
1450 | 113 | int ylimit = y + bitmap.rows; | ||
1451 | 114 | for (; y < ylimit; ++y) | ||
1452 | 115 | { | ||
1453 | 116 | memcpy(dest, src, bitmap.width); | ||
1454 | 117 | src += bitmap.pitch; | ||
1455 | 118 | dest += img.stride(); | ||
1456 | 119 | } | ||
1457 | 120 | } | ||
1458 | 121 | |||
1459 | 122 | penx += slot->advance.x >> 6; | ||
1460 | 123 | peny += slot->advance.y >> 6; | ||
1461 | 124 | } | ||
1462 | 125 | } | ||
1463 | 126 | 0 | ||
1464 | === removed file 'playground/demo-shell/typo/typo_freetype_renderer.h' | |||
1465 | --- playground/demo-shell/typo/typo_freetype_renderer.h 2017-07-28 17:00:43 +0000 | |||
1466 | +++ playground/demo-shell/typo/typo_freetype_renderer.h 1970-01-01 00:00:00 +0000 | |||
1467 | @@ -1,44 +0,0 @@ | |||
1468 | 1 | /* | ||
1469 | 2 | * Copyright © 2015 Canonical Ltd. | ||
1470 | 3 | * | ||
1471 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1472 | 5 | * it under the terms of the GNU General Public License version 2 or 3 as | ||
1473 | 6 | * published by the Free Software Foundation. | ||
1474 | 7 | * | ||
1475 | 8 | * This program is distributed in the hope that it will be useful, | ||
1476 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1477 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1478 | 11 | * GNU General Public License for more details. | ||
1479 | 12 | * | ||
1480 | 13 | * You should have received a copy of the GNU General Public License | ||
1481 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1482 | 15 | * | ||
1483 | 16 | * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com> | ||
1484 | 17 | */ | ||
1485 | 18 | |||
1486 | 19 | #ifndef MIR_TYPO_FREETYPE_RENDERER_H_ | ||
1487 | 20 | #define MIR_TYPO_FREETYPE_RENDERER_H_ | ||
1488 | 21 | |||
1489 | 22 | #include "typo_renderer.h" | ||
1490 | 23 | #include <ft2build.h> | ||
1491 | 24 | #include FT_FREETYPE_H | ||
1492 | 25 | |||
1493 | 26 | namespace mir { namespace typo { | ||
1494 | 27 | |||
1495 | 28 | class FreetypeRenderer : public Renderer | ||
1496 | 29 | { | ||
1497 | 30 | public: | ||
1498 | 31 | FreetypeRenderer(); | ||
1499 | 32 | ~FreetypeRenderer(); | ||
1500 | 33 | bool load(char const* font_path, int pref_height); | ||
1501 | 34 | void render(char const* str, Image& img) override; | ||
1502 | 35 | |||
1503 | 36 | private: | ||
1504 | 37 | FT_Library lib; | ||
1505 | 38 | FT_Face face; | ||
1506 | 39 | int preferred_height; | ||
1507 | 40 | }; | ||
1508 | 41 | |||
1509 | 42 | } } // namespace mir::typo | ||
1510 | 43 | |||
1511 | 44 | #endif // MIR_TYPO_FREETYPE_RENDERER_H_ | ||
1512 | 45 | 0 | ||
1513 | === removed file 'playground/demo-shell/typo/typo_glcache.cpp' | |||
1514 | --- playground/demo-shell/typo/typo_glcache.cpp 2017-07-28 17:00:43 +0000 | |||
1515 | +++ playground/demo-shell/typo/typo_glcache.cpp 1970-01-01 00:00:00 +0000 | |||
1516 | @@ -1,99 +0,0 @@ | |||
1517 | 1 | /* | ||
1518 | 2 | * Copyright © 2015 Canonical Ltd. | ||
1519 | 3 | * | ||
1520 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1521 | 5 | * it under the terms of the GNU General Public License version 2 or 3 as | ||
1522 | 6 | * published by the Free Software Foundation. | ||
1523 | 7 | * | ||
1524 | 8 | * This program is distributed in the hope that it will be useful, | ||
1525 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1526 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1527 | 11 | * GNU General Public License for more details. | ||
1528 | 12 | * | ||
1529 | 13 | * You should have received a copy of the GNU General Public License | ||
1530 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1531 | 15 | * | ||
1532 | 16 | * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com> | ||
1533 | 17 | */ | ||
1534 | 18 | |||
1535 | 19 | #include "typo_glcache.h" | ||
1536 | 20 | #include MIR_SERVER_GL_H | ||
1537 | 21 | |||
1538 | 22 | using namespace mir::typo; | ||
1539 | 23 | |||
1540 | 24 | GLCache::GLCache(std::shared_ptr<Renderer> const& r) | ||
1541 | 25 | : renderer(r) | ||
1542 | 26 | { | ||
1543 | 27 | } | ||
1544 | 28 | |||
1545 | 29 | GLCache::~GLCache() | ||
1546 | 30 | { | ||
1547 | 31 | clear(); | ||
1548 | 32 | } | ||
1549 | 33 | |||
1550 | 34 | void GLCache::change_renderer(std::shared_ptr<Renderer> const& r) | ||
1551 | 35 | { | ||
1552 | 36 | clear(); | ||
1553 | 37 | renderer = r; | ||
1554 | 38 | } | ||
1555 | 39 | |||
1556 | 40 | void GLCache::clear() | ||
1557 | 41 | { | ||
1558 | 42 | for (auto& e : map) | ||
1559 | 43 | glDeleteTextures(1, &e.second.tex); | ||
1560 | 44 | map.clear(); | ||
1561 | 45 | } | ||
1562 | 46 | |||
1563 | 47 | void GLCache::mark_all_unused() | ||
1564 | 48 | { | ||
1565 | 49 | for (auto& e : map) | ||
1566 | 50 | e.second.used = false; | ||
1567 | 51 | } | ||
1568 | 52 | |||
1569 | 53 | void GLCache::drop_unused() | ||
1570 | 54 | { | ||
1571 | 55 | for (auto e = map.begin(); e != map.end();) | ||
1572 | 56 | { | ||
1573 | 57 | if (!e->second.used) | ||
1574 | 58 | { | ||
1575 | 59 | glDeleteTextures(1, &e->second.tex); | ||
1576 | 60 | e = map.erase(e); | ||
1577 | 61 | } | ||
1578 | 62 | else | ||
1579 | 63 | e++; | ||
1580 | 64 | } | ||
1581 | 65 | } | ||
1582 | 66 | |||
1583 | 67 | bool GLCache::Entry::valid() const | ||
1584 | 68 | { | ||
1585 | 69 | return width > 0 && height > 0; | ||
1586 | 70 | } | ||
1587 | 71 | |||
1588 | 72 | GLCache::Entry const& GLCache::get(char const* str) | ||
1589 | 73 | { | ||
1590 | 74 | Entry& entry = map[str]; | ||
1591 | 75 | if (!entry.valid()) | ||
1592 | 76 | { | ||
1593 | 77 | Renderer::Image img; | ||
1594 | 78 | renderer->render(str, img); | ||
1595 | 79 | if (img.data()) | ||
1596 | 80 | { | ||
1597 | 81 | entry.width = img.width(); | ||
1598 | 82 | entry.height = img.height(); | ||
1599 | 83 | glGenTextures(1, &entry.tex); | ||
1600 | 84 | glBindTexture(GL_TEXTURE_2D, entry.tex); | ||
1601 | 85 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, | ||
1602 | 86 | GL_LINEAR_MIPMAP_NEAREST); | ||
1603 | 87 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
1604 | 88 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | ||
1605 | 89 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | ||
1606 | 90 | glPixelStorei(GL_UNPACK_ALIGNMENT, img.alignment()); | ||
1607 | 91 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, | ||
1608 | 92 | img.width(), img.height(), 0, GL_ALPHA, | ||
1609 | 93 | GL_UNSIGNED_BYTE, img.data()); | ||
1610 | 94 | glGenerateMipmap(GL_TEXTURE_2D); // Antialiasing shrinkage please | ||
1611 | 95 | } | ||
1612 | 96 | } | ||
1613 | 97 | entry.used = true; | ||
1614 | 98 | return entry; | ||
1615 | 99 | } | ||
1616 | 100 | 0 | ||
1617 | === removed file 'playground/demo-shell/typo/typo_glcache.h' | |||
1618 | --- playground/demo-shell/typo/typo_glcache.h 2017-07-28 17:00:43 +0000 | |||
1619 | +++ playground/demo-shell/typo/typo_glcache.h 1970-01-01 00:00:00 +0000 | |||
1620 | @@ -1,56 +0,0 @@ | |||
1621 | 1 | /* | ||
1622 | 2 | * Copyright © 2015 Canonical Ltd. | ||
1623 | 3 | * | ||
1624 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1625 | 5 | * it under the terms of the GNU General Public License version 2 or 3 as | ||
1626 | 6 | * published by the Free Software Foundation. | ||
1627 | 7 | * | ||
1628 | 8 | * This program is distributed in the hope that it will be useful, | ||
1629 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1630 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1631 | 11 | * GNU General Public License for more details. | ||
1632 | 12 | * | ||
1633 | 13 | * You should have received a copy of the GNU General Public License | ||
1634 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1635 | 15 | * | ||
1636 | 16 | * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com> | ||
1637 | 17 | */ | ||
1638 | 18 | |||
1639 | 19 | #ifndef MIR_TYPO_GLCACHE_H_ | ||
1640 | 20 | #define MIR_TYPO_GLCACHE_H_ | ||
1641 | 21 | |||
1642 | 22 | #include "typo_renderer.h" | ||
1643 | 23 | #include <string> | ||
1644 | 24 | #include <unordered_map> | ||
1645 | 25 | #include <memory> | ||
1646 | 26 | |||
1647 | 27 | namespace mir { namespace typo { | ||
1648 | 28 | |||
1649 | 29 | class GLCache | ||
1650 | 30 | { | ||
1651 | 31 | public: | ||
1652 | 32 | struct Entry | ||
1653 | 33 | { | ||
1654 | 34 | bool valid() const; | ||
1655 | 35 | unsigned int tex = 0; | ||
1656 | 36 | int width = 0, height = 0; | ||
1657 | 37 | bool used = false; | ||
1658 | 38 | }; | ||
1659 | 39 | |||
1660 | 40 | explicit GLCache(std::shared_ptr<Renderer> const&); | ||
1661 | 41 | ~GLCache(); | ||
1662 | 42 | void change_renderer(std::shared_ptr<Renderer> const&); | ||
1663 | 43 | Entry const& get(char const* str); | ||
1664 | 44 | void clear(); | ||
1665 | 45 | void mark_all_unused(); | ||
1666 | 46 | void drop_unused(); | ||
1667 | 47 | |||
1668 | 48 | private: | ||
1669 | 49 | typedef std::unordered_map<std::string, Entry> Map; | ||
1670 | 50 | Map map; | ||
1671 | 51 | std::shared_ptr<Renderer> renderer; | ||
1672 | 52 | }; | ||
1673 | 53 | |||
1674 | 54 | } } // namespace mir::typo | ||
1675 | 55 | |||
1676 | 56 | #endif // MIR_TYPO_GLCACHE_H_ | ||
1677 | 57 | 0 | ||
1678 | === removed file 'playground/demo-shell/typo/typo_renderer.cpp' | |||
1679 | --- playground/demo-shell/typo/typo_renderer.cpp 2017-07-28 17:00:43 +0000 | |||
1680 | +++ playground/demo-shell/typo/typo_renderer.cpp 1970-01-01 00:00:00 +0000 | |||
1681 | @@ -1,59 +0,0 @@ | |||
1682 | 1 | /* | ||
1683 | 2 | * Copyright © 2015 Canonical Ltd. | ||
1684 | 3 | * | ||
1685 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1686 | 5 | * it under the terms of the GNU General Public License version 2 or 3 as | ||
1687 | 6 | * published by the Free Software Foundation. | ||
1688 | 7 | * | ||
1689 | 8 | * This program is distributed in the hope that it will be useful, | ||
1690 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1691 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1692 | 11 | * GNU General Public License for more details. | ||
1693 | 12 | * | ||
1694 | 13 | * You should have received a copy of the GNU General Public License | ||
1695 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1696 | 15 | * | ||
1697 | 16 | * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com> | ||
1698 | 17 | */ | ||
1699 | 18 | |||
1700 | 19 | #include "typo_renderer.h" | ||
1701 | 20 | #include <cstring> | ||
1702 | 21 | |||
1703 | 22 | using namespace mir::typo; | ||
1704 | 23 | |||
1705 | 24 | Renderer::Image::Image() | ||
1706 | 25 | : buf(nullptr), width_(0), stride_(0), height_(0), align_(4), | ||
1707 | 26 | format_(alpha8) | ||
1708 | 27 | { | ||
1709 | 28 | } | ||
1710 | 29 | |||
1711 | 30 | Renderer::Image::~Image() | ||
1712 | 31 | { | ||
1713 | 32 | delete[] buf; | ||
1714 | 33 | } | ||
1715 | 34 | |||
1716 | 35 | void Renderer::Image::reserve(int w, int h, Format f) | ||
1717 | 36 | { | ||
1718 | 37 | width_ = w; | ||
1719 | 38 | height_ = h; | ||
1720 | 39 | format_ = f; | ||
1721 | 40 | int const bpp = 1; // format is always alpha8 | ||
1722 | 41 | stride_ = (((width_ * bpp) + align_ - 1) / align_) * align_; | ||
1723 | 42 | delete[] buf; | ||
1724 | 43 | auto size = stride_ * height_; | ||
1725 | 44 | buf = new unsigned char[size]; | ||
1726 | 45 | memset(buf, 0, size); | ||
1727 | 46 | } | ||
1728 | 47 | |||
1729 | 48 | Renderer::~Renderer() | ||
1730 | 49 | { | ||
1731 | 50 | } | ||
1732 | 51 | |||
1733 | 52 | unsigned long Renderer::unicode_from_utf8(char const** utf8) | ||
1734 | 53 | { | ||
1735 | 54 | int char_len = 1; // TODO: Add support for non-ASCII UTF-8 | ||
1736 | 55 | unsigned long unicode = **utf8; | ||
1737 | 56 | if (unicode) | ||
1738 | 57 | *utf8 += char_len; | ||
1739 | 58 | return unicode; | ||
1740 | 59 | } | ||
1741 | 60 | 0 | ||
1742 | === removed file 'playground/demo-shell/typo/typo_renderer.h' | |||
1743 | --- playground/demo-shell/typo/typo_renderer.h 2017-07-28 17:00:43 +0000 | |||
1744 | +++ playground/demo-shell/typo/typo_renderer.h 1970-01-01 00:00:00 +0000 | |||
1745 | @@ -1,61 +0,0 @@ | |||
1746 | 1 | /* | ||
1747 | 2 | * Copyright © 2015 Canonical Ltd. | ||
1748 | 3 | * | ||
1749 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1750 | 5 | * it under the terms of the GNU General Public License version 2 or 3 as | ||
1751 | 6 | * published by the Free Software Foundation. | ||
1752 | 7 | * | ||
1753 | 8 | * This program is distributed in the hope that it will be useful, | ||
1754 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1755 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1756 | 11 | * GNU General Public License for more details. | ||
1757 | 12 | * | ||
1758 | 13 | * You should have received a copy of the GNU General Public License | ||
1759 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1760 | 15 | * | ||
1761 | 16 | * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com> | ||
1762 | 17 | */ | ||
1763 | 18 | |||
1764 | 19 | #ifndef MIR_TYPO_RENDERER_H_ | ||
1765 | 20 | #define MIR_TYPO_RENDERER_H_ | ||
1766 | 21 | |||
1767 | 22 | namespace mir { namespace typo { | ||
1768 | 23 | |||
1769 | 24 | class Renderer | ||
1770 | 25 | { | ||
1771 | 26 | public: | ||
1772 | 27 | class Image | ||
1773 | 28 | { | ||
1774 | 29 | public: | ||
1775 | 30 | Image(); | ||
1776 | 31 | Image(Image const&) = delete; | ||
1777 | 32 | Image(Image const&&) = delete; | ||
1778 | 33 | Image& operator=(Image const&) = delete; | ||
1779 | 34 | ~Image(); | ||
1780 | 35 | |||
1781 | 36 | typedef enum {alpha8} Format; | ||
1782 | 37 | |||
1783 | 38 | void reserve(int w, int h, Format f); | ||
1784 | 39 | unsigned char* data() const { return buf; }; | ||
1785 | 40 | int width() const { return width_; } | ||
1786 | 41 | int height() const { return height_; } | ||
1787 | 42 | int stride() const { return stride_; } | ||
1788 | 43 | int alignment() const { return align_; } | ||
1789 | 44 | Format format() const { return format_; } | ||
1790 | 45 | |||
1791 | 46 | private: | ||
1792 | 47 | unsigned char* buf; | ||
1793 | 48 | int width_, stride_, height_, align_; | ||
1794 | 49 | Format format_; | ||
1795 | 50 | }; | ||
1796 | 51 | |||
1797 | 52 | virtual ~Renderer(); | ||
1798 | 53 | virtual void render(char const* str, Image& img) = 0; | ||
1799 | 54 | |||
1800 | 55 | protected: | ||
1801 | 56 | static unsigned long unicode_from_utf8(char const** utf8); | ||
1802 | 57 | }; | ||
1803 | 58 | |||
1804 | 59 | } } // namespace mir::typo | ||
1805 | 60 | |||
1806 | 61 | #endif // MIR_TYPO_RENDERER_H_ | ||
1807 | 62 | 0 | ||
1808 | === removed file 'playground/demo-shell/typo/typo_stub_renderer.cpp' | |||
1809 | --- playground/demo-shell/typo/typo_stub_renderer.cpp 2017-07-28 17:00:43 +0000 | |||
1810 | +++ playground/demo-shell/typo/typo_stub_renderer.cpp 1970-01-01 00:00:00 +0000 | |||
1811 | @@ -1,47 +0,0 @@ | |||
1812 | 1 | /* | ||
1813 | 2 | * Copyright © 2015 Canonical Ltd. | ||
1814 | 3 | * | ||
1815 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1816 | 5 | * it under the terms of the GNU General Public License version 2 or 3 as | ||
1817 | 6 | * published by the Free Software Foundation. | ||
1818 | 7 | * | ||
1819 | 8 | * This program is distributed in the hope that it will be useful, | ||
1820 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1821 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1822 | 11 | * GNU General Public License for more details. | ||
1823 | 12 | * | ||
1824 | 13 | * You should have received a copy of the GNU General Public License | ||
1825 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1826 | 15 | * | ||
1827 | 16 | * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com> | ||
1828 | 17 | */ | ||
1829 | 18 | |||
1830 | 19 | #include "typo_stub_renderer.h" | ||
1831 | 20 | #include <cstring> | ||
1832 | 21 | |||
1833 | 22 | using namespace mir::typo; | ||
1834 | 23 | |||
1835 | 24 | void StubRenderer::render(char const* str, Image& img) | ||
1836 | 25 | { | ||
1837 | 26 | int const char_width = 8; | ||
1838 | 27 | int const char_height = 16; | ||
1839 | 28 | int const char_space = 2; | ||
1840 | 29 | int const tex_height = 20; | ||
1841 | 30 | int const len = strlen(str); | ||
1842 | 31 | int const top = (tex_height - char_height) / 2; | ||
1843 | 32 | |||
1844 | 33 | img.reserve(len*(char_width+char_space) - char_space, tex_height, | ||
1845 | 34 | Image::alpha8); | ||
1846 | 35 | |||
1847 | 36 | char const* s = str; | ||
1848 | 37 | for (int n = 0; unicode_from_utf8(&s); ++n) | ||
1849 | 38 | { | ||
1850 | 39 | unsigned char* row = img.data() + top*img.stride() + | ||
1851 | 40 | n*(char_width+char_space); | ||
1852 | 41 | for (int y = 0; y < char_height; ++y) | ||
1853 | 42 | { | ||
1854 | 43 | memset(row, 255, char_width); | ||
1855 | 44 | row += img.stride(); | ||
1856 | 45 | } | ||
1857 | 46 | } | ||
1858 | 47 | } | ||
1859 | 48 | 0 | ||
1860 | === removed file 'playground/demo-shell/typo/typo_stub_renderer.h' | |||
1861 | --- playground/demo-shell/typo/typo_stub_renderer.h 2017-07-28 17:00:43 +0000 | |||
1862 | +++ playground/demo-shell/typo/typo_stub_renderer.h 1970-01-01 00:00:00 +0000 | |||
1863 | @@ -1,34 +0,0 @@ | |||
1864 | 1 | /* | ||
1865 | 2 | * Copyright © 2015 Canonical Ltd. | ||
1866 | 3 | * | ||
1867 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1868 | 5 | * it under the terms of the GNU General Public License version 2 or 3 as | ||
1869 | 6 | * published by the Free Software Foundation. | ||
1870 | 7 | * | ||
1871 | 8 | * This program is distributed in the hope that it will be useful, | ||
1872 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1873 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1874 | 11 | * GNU General Public License for more details. | ||
1875 | 12 | * | ||
1876 | 13 | * You should have received a copy of the GNU General Public License | ||
1877 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1878 | 15 | * | ||
1879 | 16 | * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com> | ||
1880 | 17 | */ | ||
1881 | 18 | |||
1882 | 19 | #ifndef MIR_TYPO_STUB_RENDERER_H_ | ||
1883 | 20 | #define MIR_TYPO_STUB_RENDERER_H_ | ||
1884 | 21 | |||
1885 | 22 | #include "typo_renderer.h" | ||
1886 | 23 | |||
1887 | 24 | namespace mir { namespace typo { | ||
1888 | 25 | |||
1889 | 26 | class StubRenderer : public Renderer | ||
1890 | 27 | { | ||
1891 | 28 | public: | ||
1892 | 29 | void render(char const* str, Image& img) override; | ||
1893 | 30 | }; | ||
1894 | 31 | |||
1895 | 32 | } } // namespace mir::typo | ||
1896 | 33 | |||
1897 | 34 | #endif // MIR_TYPO_STUB_RENDERER_H_ | ||
1898 | 35 | 0 | ||
1899 | === removed file 'playground/demo-shell/window_manager.cpp' | |||
1900 | --- playground/demo-shell/window_manager.cpp 2017-07-28 17:00:43 +0000 | |||
1901 | +++ playground/demo-shell/window_manager.cpp 1970-01-01 00:00:00 +0000 | |||
1902 | @@ -1,611 +0,0 @@ | |||
1903 | 1 | /* | ||
1904 | 2 | * Copyright © 2013 Canonical Ltd. | ||
1905 | 3 | * | ||
1906 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
1907 | 5 | * under the terms of the GNU General Public License version 2 or 3, | ||
1908 | 6 | * as published by the Free Software Foundation. | ||
1909 | 7 | * | ||
1910 | 8 | * This program is distributed in the hope that it will be useful, | ||
1911 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1912 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1913 | 11 | * GNU General Public License for more details. | ||
1914 | 12 | * | ||
1915 | 13 | * You should have received a copy of the GNU General Public License | ||
1916 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1917 | 15 | * | ||
1918 | 16 | * Authored by: Robert Carr <robert.carr@canonical.com> | ||
1919 | 17 | * Daniel van Vugt <daniel.van.vugt@canonical.com> | ||
1920 | 18 | */ | ||
1921 | 19 | |||
1922 | 20 | #include "window_manager.h" | ||
1923 | 21 | #include "demo_compositor.h" | ||
1924 | 22 | |||
1925 | 23 | #include "mir/shell/focus_controller.h" | ||
1926 | 24 | #include "mir/scene/session.h" | ||
1927 | 25 | #include "mir/scene/surface.h" | ||
1928 | 26 | #include "mir/graphics/display.h" | ||
1929 | 27 | #include "mir/graphics/display_configuration.h" | ||
1930 | 28 | #include "mir/compositor/compositor.h" | ||
1931 | 29 | |||
1932 | 30 | #include <linux/input.h> | ||
1933 | 31 | |||
1934 | 32 | #include <cassert> | ||
1935 | 33 | #include <cstdlib> | ||
1936 | 34 | #include <cmath> | ||
1937 | 35 | |||
1938 | 36 | namespace me = mir::examples; | ||
1939 | 37 | namespace msh = mir::shell; | ||
1940 | 38 | namespace mg = mir::graphics; | ||
1941 | 39 | namespace mc = mir::compositor; | ||
1942 | 40 | namespace mi = mir::input; | ||
1943 | 41 | |||
1944 | 42 | namespace | ||
1945 | 43 | { | ||
1946 | 44 | const int min_swipe_distance = 100; // How long must a swipe be to act on? | ||
1947 | 45 | } | ||
1948 | 46 | |||
1949 | 47 | me::WindowManager::WindowManager() | ||
1950 | 48 | : old_pinch_diam(0.0f), max_fingers(0) | ||
1951 | 49 | { | ||
1952 | 50 | } | ||
1953 | 51 | |||
1954 | 52 | void me::WindowManager::set_focus_controller(std::shared_ptr<msh::FocusController> const& controller) | ||
1955 | 53 | { | ||
1956 | 54 | focus_controller = controller; | ||
1957 | 55 | } | ||
1958 | 56 | |||
1959 | 57 | void me::WindowManager::set_display(std::shared_ptr<mg::Display> const& dpy) | ||
1960 | 58 | { | ||
1961 | 59 | display = dpy; | ||
1962 | 60 | } | ||
1963 | 61 | |||
1964 | 62 | void me::WindowManager::set_compositor(std::shared_ptr<mc::Compositor> const& cptor) | ||
1965 | 63 | { | ||
1966 | 64 | compositor = cptor; | ||
1967 | 65 | } | ||
1968 | 66 | |||
1969 | 67 | void me::WindowManager::set_input_scene(std::shared_ptr<mi::Scene> const& s) | ||
1970 | 68 | { | ||
1971 | 69 | input_scene = s; | ||
1972 | 70 | } | ||
1973 | 71 | |||
1974 | 72 | void me::WindowManager::force_redraw() | ||
1975 | 73 | { | ||
1976 | 74 | // This is clumsy, but the only option our architecture allows us for now | ||
1977 | 75 | // Same hack as used in TouchspotController... | ||
1978 | 76 | input_scene->emit_scene_changed(); | ||
1979 | 77 | } | ||
1980 | 78 | |||
1981 | 79 | namespace | ||
1982 | 80 | { | ||
1983 | 81 | |||
1984 | 82 | mir::geometry::Point average_pointer(MirTouchEvent const* tev) | ||
1985 | 83 | { | ||
1986 | 84 | using namespace mir; | ||
1987 | 85 | using namespace geometry; | ||
1988 | 86 | |||
1989 | 87 | int x = 0, y = 0; | ||
1990 | 88 | int count = mir_touch_event_point_count(tev); | ||
1991 | 89 | |||
1992 | 90 | for (int i = 0; i < count; i++) | ||
1993 | 91 | { | ||
1994 | 92 | x += mir_touch_event_axis_value(tev, i, mir_touch_axis_x); | ||
1995 | 93 | y += mir_touch_event_axis_value(tev, i, mir_touch_axis_y); | ||
1996 | 94 | } | ||
1997 | 95 | |||
1998 | 96 | x /= count; | ||
1999 | 97 | y /= count; | ||
2000 | 98 | |||
2001 | 99 | return Point{x, y}; | ||
2002 | 100 | } | ||
2003 | 101 | |||
2004 | 102 | float measure_pinch(MirTouchEvent const* tev, | ||
2005 | 103 | mir::geometry::Displacement& dir) | ||
2006 | 104 | { | ||
2007 | 105 | int count = mir_touch_event_point_count(tev); | ||
2008 | 106 | int max = 0; | ||
2009 | 107 | |||
2010 | 108 | for (int i = 0; i < count; i++) | ||
2011 | 109 | { | ||
2012 | 110 | for (int j = 0; j < i; j++) | ||
2013 | 111 | { | ||
2014 | 112 | int dx = mir_touch_event_axis_value(tev, i, mir_touch_axis_x) - | ||
2015 | 113 | mir_touch_event_axis_value(tev, j, mir_touch_axis_x); | ||
2016 | 114 | int dy = mir_touch_event_axis_value(tev, i, mir_touch_axis_y) - | ||
2017 | 115 | mir_touch_event_axis_value(tev, j, mir_touch_axis_y); | ||
2018 | 116 | |||
2019 | 117 | int sqr = dx*dx + dy*dy; | ||
2020 | 118 | |||
2021 | 119 | if (sqr > max) | ||
2022 | 120 | { | ||
2023 | 121 | max = sqr; | ||
2024 | 122 | dir = mir::geometry::Displacement{dx, dy}; | ||
2025 | 123 | } | ||
2026 | 124 | } | ||
2027 | 125 | } | ||
2028 | 126 | |||
2029 | 127 | return sqrtf(max); // return pinch diameter | ||
2030 | 128 | } | ||
2031 | 129 | |||
2032 | 130 | } // namespace | ||
2033 | 131 | |||
2034 | 132 | |||
2035 | 133 | void me::WindowManager::toggle(ColourEffect which) | ||
2036 | 134 | { | ||
2037 | 135 | colour_effect = (colour_effect == which) ? none : which; | ||
2038 | 136 | me::DemoCompositor::for_each([this](me::DemoCompositor& c) | ||
2039 | 137 | { | ||
2040 | 138 | c.set_colour_effect(colour_effect); | ||
2041 | 139 | }); | ||
2042 | 140 | force_redraw(); | ||
2043 | 141 | } | ||
2044 | 142 | |||
2045 | 143 | void me::WindowManager::save_edges(scene::Surface& surf, | ||
2046 | 144 | geometry::Point const& p) | ||
2047 | 145 | { | ||
2048 | 146 | int width = surf.size().width.as_int(); | ||
2049 | 147 | int height = surf.size().height.as_int(); | ||
2050 | 148 | |||
2051 | 149 | int left = surf.top_left().x.as_int(); | ||
2052 | 150 | int right = left + width; | ||
2053 | 151 | int top = surf.top_left().y.as_int(); | ||
2054 | 152 | int bottom = top + height; | ||
2055 | 153 | |||
2056 | 154 | int leftish = left + width/3; | ||
2057 | 155 | int rightish = right - width/3; | ||
2058 | 156 | int topish = top + height/3; | ||
2059 | 157 | int bottomish = bottom - height/3; | ||
2060 | 158 | |||
2061 | 159 | int click_x = p.x.as_int(); | ||
2062 | 160 | xedge = (click_x <= leftish) ? left_edge : | ||
2063 | 161 | (click_x >= rightish) ? right_edge : | ||
2064 | 162 | hmiddle; | ||
2065 | 163 | |||
2066 | 164 | int click_y = p.y.as_int(); | ||
2067 | 165 | yedge = (click_y <= topish) ? top_edge : | ||
2068 | 166 | (click_y >= bottomish) ? bottom_edge : | ||
2069 | 167 | vmiddle; | ||
2070 | 168 | } | ||
2071 | 169 | |||
2072 | 170 | void me::WindowManager::resize(scene::Surface& surf, | ||
2073 | 171 | geometry::Point const& cursor) const | ||
2074 | 172 | { | ||
2075 | 173 | int width = surf.size().width.as_int(); | ||
2076 | 174 | int height = surf.size().height.as_int(); | ||
2077 | 175 | |||
2078 | 176 | int left = surf.top_left().x.as_int(); | ||
2079 | 177 | int right = left + width; | ||
2080 | 178 | int top = surf.top_left().y.as_int(); | ||
2081 | 179 | int bottom = top + height; | ||
2082 | 180 | |||
2083 | 181 | geometry::Displacement drag = cursor - old_cursor; | ||
2084 | 182 | int dx = drag.dx.as_int(); | ||
2085 | 183 | int dy = drag.dy.as_int(); | ||
2086 | 184 | |||
2087 | 185 | if (xedge == left_edge && dx < width) | ||
2088 | 186 | left = old_pos.x.as_int() + dx; | ||
2089 | 187 | else if (xedge == right_edge) | ||
2090 | 188 | right = old_pos.x.as_int() + old_size.width.as_int() + dx; | ||
2091 | 189 | |||
2092 | 190 | if (yedge == top_edge && dy < height) | ||
2093 | 191 | top = old_pos.y.as_int() + dy; | ||
2094 | 192 | else if (yedge == bottom_edge) | ||
2095 | 193 | bottom = old_pos.y.as_int() + old_size.height.as_int() + dy; | ||
2096 | 194 | |||
2097 | 195 | surf.move_to({left, top}); | ||
2098 | 196 | surf.resize({right-left, bottom-top}); | ||
2099 | 197 | } | ||
2100 | 198 | |||
2101 | 199 | bool me::WindowManager::handle_key_event(MirKeyboardEvent const* kev) | ||
2102 | 200 | { | ||
2103 | 201 | static bool display_off = false; | ||
2104 | 202 | |||
2105 | 203 | if (mir_keyboard_event_action(kev) != mir_keyboard_action_down) | ||
2106 | 204 | return false; | ||
2107 | 205 | |||
2108 | 206 | auto modifiers = mir_keyboard_event_modifiers(kev); | ||
2109 | 207 | auto scan_code = mir_keyboard_event_scan_code(kev); | ||
2110 | 208 | |||
2111 | 209 | if (modifiers & mir_input_event_modifier_alt && | ||
2112 | 210 | scan_code == KEY_TAB) // TODO: Use keycode once we support keymapping on the server side | ||
2113 | 211 | { | ||
2114 | 212 | focus_controller->focus_next_session(); | ||
2115 | 213 | if (auto const surface = focus_controller->focused_surface()) | ||
2116 | 214 | focus_controller->raise({surface}); | ||
2117 | 215 | return true; | ||
2118 | 216 | } | ||
2119 | 217 | else if (modifiers & mir_input_event_modifier_alt && | ||
2120 | 218 | scan_code == KEY_GRAVE) | ||
2121 | 219 | { | ||
2122 | 220 | if (auto const prev = focus_controller->focused_surface()) | ||
2123 | 221 | { | ||
2124 | 222 | auto const app = focus_controller->focused_session(); | ||
2125 | 223 | auto const next = app->surface_after(prev); | ||
2126 | 224 | focus_controller->set_focus_to(app, next); | ||
2127 | 225 | focus_controller->raise({next}); | ||
2128 | 226 | } | ||
2129 | 227 | return true; | ||
2130 | 228 | } | ||
2131 | 229 | else if (modifiers & mir_input_event_modifier_alt && | ||
2132 | 230 | scan_code == KEY_F4) | ||
2133 | 231 | { | ||
2134 | 232 | auto const surf = focus_controller->focused_surface(); | ||
2135 | 233 | if (surf) | ||
2136 | 234 | surf->request_client_surface_close(); | ||
2137 | 235 | return true; | ||
2138 | 236 | } | ||
2139 | 237 | else if ((modifiers & mir_input_event_modifier_alt && | ||
2140 | 238 | scan_code == KEY_P) || | ||
2141 | 239 | (scan_code == KEY_POWER)) | ||
2142 | 240 | { | ||
2143 | 241 | compositor->stop(); | ||
2144 | 242 | auto conf = display->configuration(); | ||
2145 | 243 | MirPowerMode new_power_mode = display_off ? | ||
2146 | 244 | mir_power_mode_on : mir_power_mode_off; | ||
2147 | 245 | conf->for_each_output( | ||
2148 | 246 | [&](mg::UserDisplayConfigurationOutput& output) -> void | ||
2149 | 247 | { | ||
2150 | 248 | output.power_mode = new_power_mode; | ||
2151 | 249 | }); | ||
2152 | 250 | display_off = !display_off; | ||
2153 | 251 | |||
2154 | 252 | display->configure(*conf.get()); | ||
2155 | 253 | if (!display_off) | ||
2156 | 254 | compositor->start(); | ||
2157 | 255 | return true; | ||
2158 | 256 | } | ||
2159 | 257 | else if ((modifiers & mir_input_event_modifier_alt) && | ||
2160 | 258 | (modifiers & mir_input_event_modifier_ctrl) && | ||
2161 | 259 | (scan_code == KEY_ESC)) | ||
2162 | 260 | { | ||
2163 | 261 | std::abort(); | ||
2164 | 262 | return true; | ||
2165 | 263 | } | ||
2166 | 264 | else if ((modifiers & mir_input_event_modifier_alt) && | ||
2167 | 265 | (modifiers & mir_input_event_modifier_ctrl) && | ||
2168 | 266 | (scan_code == KEY_L) && | ||
2169 | 267 | focus_controller) | ||
2170 | 268 | { | ||
2171 | 269 | auto const app = focus_controller->focused_session(); | ||
2172 | 270 | if (app) | ||
2173 | 271 | { | ||
2174 | 272 | app->set_lifecycle_state(mir_lifecycle_state_will_suspend); | ||
2175 | 273 | } | ||
2176 | 274 | } | ||
2177 | 275 | else if ((modifiers & mir_input_event_modifier_alt) && | ||
2178 | 276 | (modifiers & mir_input_event_modifier_ctrl)) | ||
2179 | 277 | { | ||
2180 | 278 | MirOrientation orientation = mir_orientation_normal; | ||
2181 | 279 | bool rotating = true; | ||
2182 | 280 | int mode_change = 0; | ||
2183 | 281 | bool preferred_mode = false; | ||
2184 | 282 | switch (scan_code) | ||
2185 | 283 | { | ||
2186 | 284 | case KEY_UP: orientation = mir_orientation_normal; break; | ||
2187 | 285 | case KEY_DOWN: orientation = mir_orientation_inverted; break; | ||
2188 | 286 | case KEY_LEFT: orientation = mir_orientation_left; break; | ||
2189 | 287 | case KEY_RIGHT: orientation = mir_orientation_right; break; | ||
2190 | 288 | default: rotating = false; break; | ||
2191 | 289 | } | ||
2192 | 290 | switch (scan_code) | ||
2193 | 291 | { | ||
2194 | 292 | case KEY_MINUS: mode_change = -1; break; | ||
2195 | 293 | case KEY_EQUAL: mode_change = +1; break; | ||
2196 | 294 | case KEY_0: preferred_mode = true; break; | ||
2197 | 295 | default: break; | ||
2198 | 296 | } | ||
2199 | 297 | |||
2200 | 298 | if (rotating || mode_change || preferred_mode) | ||
2201 | 299 | { | ||
2202 | 300 | auto conf = display->configuration(); | ||
2203 | 301 | conf->for_each_output( | ||
2204 | 302 | [&](mg::UserDisplayConfigurationOutput& output) -> void | ||
2205 | 303 | { | ||
2206 | 304 | // Only apply changes to the monitor the cursor is on | ||
2207 | 305 | if (!output.extents().contains(old_cursor)) | ||
2208 | 306 | return; | ||
2209 | 307 | if (rotating) | ||
2210 | 308 | output.orientation = orientation; | ||
2211 | 309 | if (preferred_mode) | ||
2212 | 310 | { | ||
2213 | 311 | output.current_mode_index = | ||
2214 | 312 | output.preferred_mode_index; | ||
2215 | 313 | } | ||
2216 | 314 | else if (mode_change) | ||
2217 | 315 | { | ||
2218 | 316 | size_t nmodes = output.modes.size(); | ||
2219 | 317 | if (nmodes) | ||
2220 | 318 | output.current_mode_index = | ||
2221 | 319 | (output.current_mode_index + nmodes + | ||
2222 | 320 | mode_change) % nmodes; | ||
2223 | 321 | } | ||
2224 | 322 | }); | ||
2225 | 323 | |||
2226 | 324 | if (!rotating) compositor->stop(); | ||
2227 | 325 | display->configure(*conf); | ||
2228 | 326 | if (!rotating) compositor->start(); | ||
2229 | 327 | force_redraw(); | ||
2230 | 328 | return true; | ||
2231 | 329 | } | ||
2232 | 330 | } | ||
2233 | 331 | else if ((scan_code == KEY_VOLUMEDOWN || | ||
2234 | 332 | scan_code == KEY_VOLUMEUP) && | ||
2235 | 333 | max_fingers == 1) | ||
2236 | 334 | { | ||
2237 | 335 | int delta = (scan_code == KEY_VOLUMEDOWN) ? -1 : +1; | ||
2238 | 336 | static const MirOrientation order[4] = | ||
2239 | 337 | { | ||
2240 | 338 | mir_orientation_normal, | ||
2241 | 339 | mir_orientation_right, | ||
2242 | 340 | mir_orientation_inverted, | ||
2243 | 341 | mir_orientation_left | ||
2244 | 342 | }; | ||
2245 | 343 | compositor->stop(); | ||
2246 | 344 | auto conf = display->configuration(); | ||
2247 | 345 | conf->for_each_output( | ||
2248 | 346 | [&](mg::UserDisplayConfigurationOutput& output) | ||
2249 | 347 | { | ||
2250 | 348 | int i = 0; | ||
2251 | 349 | for (; i < 4; ++i) | ||
2252 | 350 | { | ||
2253 | 351 | if (output.orientation == order[i]) | ||
2254 | 352 | break; | ||
2255 | 353 | } | ||
2256 | 354 | output.orientation = order[(i+4+delta) % 4]; | ||
2257 | 355 | }); | ||
2258 | 356 | display->configure(*conf.get()); | ||
2259 | 357 | compositor->start(); | ||
2260 | 358 | return true; | ||
2261 | 359 | } | ||
2262 | 360 | else if (modifiers & mir_input_event_modifier_meta && | ||
2263 | 361 | scan_code == KEY_N) | ||
2264 | 362 | { | ||
2265 | 363 | toggle(inverse); | ||
2266 | 364 | return true; | ||
2267 | 365 | } | ||
2268 | 366 | else if (modifiers & mir_input_event_modifier_meta && | ||
2269 | 367 | scan_code == KEY_C) | ||
2270 | 368 | { | ||
2271 | 369 | toggle(contrast); | ||
2272 | 370 | return true; | ||
2273 | 371 | } | ||
2274 | 372 | return false; | ||
2275 | 373 | } | ||
2276 | 374 | |||
2277 | 375 | |||
2278 | 376 | bool me::WindowManager::handle_pointer_event(MirPointerEvent const* pev) | ||
2279 | 377 | { | ||
2280 | 378 | bool handled = false; | ||
2281 | 379 | |||
2282 | 380 | geometry::Point cursor{mir_pointer_event_axis_value(pev, mir_pointer_axis_x), | ||
2283 | 381 | mir_pointer_event_axis_value(pev, mir_pointer_axis_y)}; | ||
2284 | 382 | auto action = mir_pointer_event_action(pev); | ||
2285 | 383 | auto modifiers = mir_pointer_event_modifiers(pev); | ||
2286 | 384 | auto vscroll = mir_pointer_event_axis_value(pev, mir_pointer_axis_vscroll); | ||
2287 | 385 | auto primary_button_pressed = mir_pointer_event_button_state(pev, mir_pointer_button_primary); | ||
2288 | 386 | auto tertiary_button_pressed = mir_pointer_event_button_state(pev, mir_pointer_button_tertiary); | ||
2289 | 387 | |||
2290 | 388 | float new_zoom_mag = 0.0f; // zero means unchanged | ||
2291 | 389 | |||
2292 | 390 | if (modifiers & mir_input_event_modifier_meta && | ||
2293 | 391 | action == mir_pointer_action_motion && | ||
2294 | 392 | vscroll != 0.0f) | ||
2295 | 393 | { | ||
2296 | 394 | zoom_exponent += vscroll; | ||
2297 | 395 | |||
2298 | 396 | // Negative exponents do work too, but disable them until | ||
2299 | 397 | // there's a clear edge to the desktop. | ||
2300 | 398 | if (zoom_exponent < 0) | ||
2301 | 399 | zoom_exponent = 0; | ||
2302 | 400 | |||
2303 | 401 | new_zoom_mag = powf(1.2f, zoom_exponent); | ||
2304 | 402 | handled = true; | ||
2305 | 403 | } | ||
2306 | 404 | |||
2307 | 405 | me::DemoCompositor::for_each( | ||
2308 | 406 | [new_zoom_mag,&cursor](me::DemoCompositor& c) | ||
2309 | 407 | { | ||
2310 | 408 | if (new_zoom_mag > 0.0f) | ||
2311 | 409 | c.zoom(new_zoom_mag); | ||
2312 | 410 | c.on_cursor_movement(cursor); | ||
2313 | 411 | }); | ||
2314 | 412 | |||
2315 | 413 | if (zoom_exponent || new_zoom_mag) | ||
2316 | 414 | force_redraw(); | ||
2317 | 415 | |||
2318 | 416 | auto const surf = focus_controller->focused_surface(); | ||
2319 | 417 | if (surf && | ||
2320 | 418 | (modifiers & mir_input_event_modifier_alt) && (primary_button_pressed || tertiary_button_pressed)) | ||
2321 | 419 | { | ||
2322 | 420 | // Start of a gesture: When the latest finger/button goes down | ||
2323 | 421 | if (action == mir_pointer_action_button_down) | ||
2324 | 422 | { | ||
2325 | 423 | click = cursor; | ||
2326 | 424 | save_edges(*surf, click); | ||
2327 | 425 | handled = true; | ||
2328 | 426 | } | ||
2329 | 427 | else if (action == mir_pointer_action_motion) | ||
2330 | 428 | { | ||
2331 | 429 | geometry::Displacement drag = cursor - old_cursor; | ||
2332 | 430 | |||
2333 | 431 | if (tertiary_button_pressed) | ||
2334 | 432 | { // Resize by mouse middle button | ||
2335 | 433 | resize(*surf, cursor); | ||
2336 | 434 | } | ||
2337 | 435 | else | ||
2338 | 436 | { | ||
2339 | 437 | surf->move_to(old_pos + drag); | ||
2340 | 438 | } | ||
2341 | 439 | |||
2342 | 440 | handled = true; | ||
2343 | 441 | } | ||
2344 | 442 | |||
2345 | 443 | old_pos = surf->top_left(); | ||
2346 | 444 | old_size = surf->size(); | ||
2347 | 445 | } | ||
2348 | 446 | |||
2349 | 447 | if (surf && | ||
2350 | 448 | (modifiers & mir_input_event_modifier_alt) && | ||
2351 | 449 | action == mir_pointer_action_motion && | ||
2352 | 450 | vscroll) | ||
2353 | 451 | { | ||
2354 | 452 | float alpha = surf->alpha(); | ||
2355 | 453 | alpha += vscroll > 0.0f ? 0.1f : -0.1f; | ||
2356 | 454 | if (alpha < 0.0f) | ||
2357 | 455 | alpha = 0.0f; | ||
2358 | 456 | else if (alpha > 1.0f) | ||
2359 | 457 | alpha = 1.0f; | ||
2360 | 458 | surf->set_alpha(alpha); | ||
2361 | 459 | handled = true; | ||
2362 | 460 | } | ||
2363 | 461 | |||
2364 | 462 | old_cursor = cursor; | ||
2365 | 463 | return handled; | ||
2366 | 464 | } | ||
2367 | 465 | |||
2368 | 466 | namespace | ||
2369 | 467 | { | ||
2370 | 468 | bool any_touches_went_down(MirTouchEvent const* tev) | ||
2371 | 469 | { | ||
2372 | 470 | auto count = mir_touch_event_point_count(tev); | ||
2373 | 471 | for (unsigned i = 0; i < count; i++) | ||
2374 | 472 | { | ||
2375 | 473 | if (mir_touch_event_action(tev, i) == mir_touch_action_down) | ||
2376 | 474 | return true; | ||
2377 | 475 | } | ||
2378 | 476 | return false; | ||
2379 | 477 | } | ||
2380 | 478 | bool last_touch_released(MirTouchEvent const* tev) | ||
2381 | 479 | { | ||
2382 | 480 | auto count = mir_touch_event_point_count(tev); | ||
2383 | 481 | if (count > 1) | ||
2384 | 482 | return false; | ||
2385 | 483 | return mir_touch_event_action(tev, 0) == mir_touch_action_up; | ||
2386 | 484 | } | ||
2387 | 485 | } | ||
2388 | 486 | |||
2389 | 487 | bool me::WindowManager::handle_touch_event(MirTouchEvent const* tev) | ||
2390 | 488 | { | ||
2391 | 489 | bool handled = false; | ||
2392 | 490 | geometry::Point cursor = average_pointer(tev); | ||
2393 | 491 | |||
2394 | 492 | auto const& modifiers = mir_touch_event_modifiers(tev); | ||
2395 | 493 | |||
2396 | 494 | int fingers = mir_touch_event_point_count(tev); | ||
2397 | 495 | |||
2398 | 496 | if (fingers > max_fingers) | ||
2399 | 497 | max_fingers = fingers; | ||
2400 | 498 | |||
2401 | 499 | auto const surf = focus_controller->focused_surface(); | ||
2402 | 500 | if (surf && | ||
2403 | 501 | (modifiers & mir_input_event_modifier_alt || | ||
2404 | 502 | fingers >= 3)) | ||
2405 | 503 | { | ||
2406 | 504 | geometry::Displacement pinch_dir; | ||
2407 | 505 | auto pinch_diam = | ||
2408 | 506 | measure_pinch(tev, pinch_dir); | ||
2409 | 507 | |||
2410 | 508 | // Start of a gesture: When the latest finger/button goes down | ||
2411 | 509 | if (any_touches_went_down(tev)) | ||
2412 | 510 | { | ||
2413 | 511 | click = cursor; | ||
2414 | 512 | save_edges(*surf, click); | ||
2415 | 513 | handled = true; | ||
2416 | 514 | } | ||
2417 | 515 | else if(max_fingers <= 3) // Avoid accidental movement | ||
2418 | 516 | { | ||
2419 | 517 | geometry::Displacement drag = cursor - old_cursor; | ||
2420 | 518 | |||
2421 | 519 | surf->move_to(old_pos + drag); | ||
2422 | 520 | |||
2423 | 521 | if (fingers == 3) | ||
2424 | 522 | { // Resize by pinch/zoom | ||
2425 | 523 | float diam_delta = pinch_diam - old_pinch_diam; | ||
2426 | 524 | /* | ||
2427 | 525 | * Resize vector (dx,dy) has length=diam_delta and | ||
2428 | 526 | * direction=pinch_dir, so solve for (dx,dy)... | ||
2429 | 527 | */ | ||
2430 | 528 | float lenlen = diam_delta * diam_delta; | ||
2431 | 529 | int x = pinch_dir.dx.as_int(); | ||
2432 | 530 | int y = pinch_dir.dy.as_int(); | ||
2433 | 531 | int xx = x * x; | ||
2434 | 532 | int yy = y * y; | ||
2435 | 533 | int xxyy = xx + yy; | ||
2436 | 534 | int dx = sqrtf(lenlen * xx / xxyy); | ||
2437 | 535 | int dy = sqrtf(lenlen * yy / xxyy); | ||
2438 | 536 | if (diam_delta < 0.0f) | ||
2439 | 537 | { | ||
2440 | 538 | dx = -dx; | ||
2441 | 539 | dy = -dy; | ||
2442 | 540 | } | ||
2443 | 541 | |||
2444 | 542 | int width = old_size.width.as_int() + dx; | ||
2445 | 543 | int height = old_size.height.as_int() + dy; | ||
2446 | 544 | surf->resize({width, height}); | ||
2447 | 545 | } | ||
2448 | 546 | |||
2449 | 547 | handled = true; | ||
2450 | 548 | } | ||
2451 | 549 | |||
2452 | 550 | old_pos = surf->top_left(); | ||
2453 | 551 | old_size = surf->size(); | ||
2454 | 552 | old_pinch_diam = pinch_diam; | ||
2455 | 553 | } | ||
2456 | 554 | |||
2457 | 555 | auto gesture_ended = last_touch_released(tev); | ||
2458 | 556 | |||
2459 | 557 | if (max_fingers == 4 && gesture_ended) | ||
2460 | 558 | { // Four fingers released | ||
2461 | 559 | geometry::Displacement dir = cursor - click; | ||
2462 | 560 | if (abs(dir.dx.as_int()) >= min_swipe_distance) | ||
2463 | 561 | { | ||
2464 | 562 | focus_controller->focus_next_session(); | ||
2465 | 563 | if (auto const surface = focus_controller->focused_surface()) | ||
2466 | 564 | focus_controller->raise({surface}); | ||
2467 | 565 | handled = true; | ||
2468 | 566 | } | ||
2469 | 567 | } | ||
2470 | 568 | |||
2471 | 569 | if (fingers == 1 && gesture_ended) | ||
2472 | 570 | max_fingers = 0; | ||
2473 | 571 | |||
2474 | 572 | old_cursor = cursor; | ||
2475 | 573 | |||
2476 | 574 | /* | ||
2477 | 575 | * For now we reserve all 3 or 4 finger gestures for window manipulation. | ||
2478 | 576 | * Make sure clients don't receive spurious events in the process... | ||
2479 | 577 | */ | ||
2480 | 578 | handled |= (max_fingers == 3 || max_fingers == 4); | ||
2481 | 579 | |||
2482 | 580 | return handled; | ||
2483 | 581 | } | ||
2484 | 582 | |||
2485 | 583 | bool me::WindowManager::handle(MirEvent const& event) | ||
2486 | 584 | { | ||
2487 | 585 | assert(focus_controller); | ||
2488 | 586 | assert(display); | ||
2489 | 587 | assert(compositor); | ||
2490 | 588 | |||
2491 | 589 | if (mir_event_get_type(&event) != mir_event_type_input) | ||
2492 | 590 | return false; | ||
2493 | 591 | auto iev = mir_event_get_input_event(&event); | ||
2494 | 592 | auto input_type = mir_input_event_get_type(iev); | ||
2495 | 593 | |||
2496 | 594 | if (input_type == mir_input_event_type_key) | ||
2497 | 595 | { | ||
2498 | 596 | return handle_key_event(mir_input_event_get_keyboard_event(iev)); | ||
2499 | 597 | } | ||
2500 | 598 | else if (input_type == mir_input_event_type_pointer && | ||
2501 | 599 | focus_controller) | ||
2502 | 600 | { | ||
2503 | 601 | return handle_pointer_event(mir_input_event_get_pointer_event(iev)); | ||
2504 | 602 | } | ||
2505 | 603 | else if (input_type == mir_input_event_type_touch && | ||
2506 | 604 | focus_controller) | ||
2507 | 605 | { | ||
2508 | 606 | return handle_touch_event(mir_input_event_get_touch_event(iev)); | ||
2509 | 607 | } | ||
2510 | 608 | |||
2511 | 609 | |||
2512 | 610 | return false; | ||
2513 | 611 | } | ||
2514 | 612 | 0 | ||
2515 | === removed file 'playground/demo-shell/window_manager.h' | |||
2516 | --- playground/demo-shell/window_manager.h 2017-07-28 17:00:43 +0000 | |||
2517 | +++ playground/demo-shell/window_manager.h 1970-01-01 00:00:00 +0000 | |||
2518 | @@ -1,97 +0,0 @@ | |||
2519 | 1 | /* | ||
2520 | 2 | * Copyright © 2013 Canonical Ltd. | ||
2521 | 3 | * | ||
2522 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
2523 | 5 | * under the terms of the GNU General Public License version 2 or 3, | ||
2524 | 6 | * as published by the Free Software Foundation. | ||
2525 | 7 | * | ||
2526 | 8 | * This program is distributed in the hope that it will be useful, | ||
2527 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2528 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2529 | 11 | * GNU General Public License for more details. | ||
2530 | 12 | * | ||
2531 | 13 | * You should have received a copy of the GNU General Public License | ||
2532 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2533 | 15 | * | ||
2534 | 16 | * Authored by: Robert Carr <robert.carr@canonical.com> | ||
2535 | 17 | */ | ||
2536 | 18 | |||
2537 | 19 | #ifndef MIR_EXAMPLES_WINDOW_MANAGER_H_ | ||
2538 | 20 | #define MIR_EXAMPLES_WINDOW_MANAGER_H_ | ||
2539 | 21 | |||
2540 | 22 | #include "mir/input/event_filter.h" | ||
2541 | 23 | #include "mir/input/scene.h" | ||
2542 | 24 | #include "mir/geometry/displacement.h" | ||
2543 | 25 | #include "mir/geometry/size.h" | ||
2544 | 26 | #include "demo_renderer.h" | ||
2545 | 27 | |||
2546 | 28 | #include <memory> | ||
2547 | 29 | |||
2548 | 30 | namespace mir | ||
2549 | 31 | { | ||
2550 | 32 | namespace shell | ||
2551 | 33 | { | ||
2552 | 34 | class FocusController; | ||
2553 | 35 | } | ||
2554 | 36 | namespace graphics | ||
2555 | 37 | { | ||
2556 | 38 | class Display; | ||
2557 | 39 | } | ||
2558 | 40 | namespace compositor | ||
2559 | 41 | { | ||
2560 | 42 | class Compositor; | ||
2561 | 43 | } | ||
2562 | 44 | |||
2563 | 45 | namespace scene { class Surface; } | ||
2564 | 46 | |||
2565 | 47 | namespace examples | ||
2566 | 48 | { | ||
2567 | 49 | |||
2568 | 50 | class WindowManager : public input::EventFilter | ||
2569 | 51 | { | ||
2570 | 52 | public: | ||
2571 | 53 | WindowManager(); | ||
2572 | 54 | ~WindowManager() = default; | ||
2573 | 55 | |||
2574 | 56 | void set_focus_controller(std::shared_ptr<shell::FocusController> const& focus_controller); | ||
2575 | 57 | void set_display(std::shared_ptr<graphics::Display> const& display); | ||
2576 | 58 | void set_compositor(std::shared_ptr<compositor::Compositor> const& compositor); | ||
2577 | 59 | void set_input_scene(std::shared_ptr<input::Scene> const& scene); | ||
2578 | 60 | void force_redraw(); | ||
2579 | 61 | |||
2580 | 62 | bool handle(MirEvent const& event) override; | ||
2581 | 63 | |||
2582 | 64 | protected: | ||
2583 | 65 | WindowManager(const WindowManager&) = delete; | ||
2584 | 66 | WindowManager& operator=(const WindowManager&) = delete; | ||
2585 | 67 | |||
2586 | 68 | private: | ||
2587 | 69 | std::shared_ptr<shell::FocusController> focus_controller; | ||
2588 | 70 | std::shared_ptr<graphics::Display> display; | ||
2589 | 71 | std::shared_ptr<compositor::Compositor> compositor; | ||
2590 | 72 | std::shared_ptr<input::Scene> input_scene; | ||
2591 | 73 | |||
2592 | 74 | geometry::Point click; | ||
2593 | 75 | geometry::Point old_pos; | ||
2594 | 76 | geometry::Point old_cursor; | ||
2595 | 77 | geometry::Size old_size; | ||
2596 | 78 | float old_pinch_diam; | ||
2597 | 79 | int max_fingers; // Maximum number of fingers touched during gesture | ||
2598 | 80 | float zoom_exponent = 0.0f; | ||
2599 | 81 | ColourEffect colour_effect = none; | ||
2600 | 82 | |||
2601 | 83 | void toggle(ColourEffect); | ||
2602 | 84 | |||
2603 | 85 | enum {left_edge, hmiddle, right_edge} xedge = hmiddle; | ||
2604 | 86 | enum {top_edge, vmiddle, bottom_edge} yedge = vmiddle; | ||
2605 | 87 | void save_edges(scene::Surface& surf, geometry::Point const& p); | ||
2606 | 88 | void resize(scene::Surface& surf, geometry::Point const& cursor) const; | ||
2607 | 89 | bool handle_key_event(MirKeyboardEvent const* event); | ||
2608 | 90 | bool handle_touch_event(MirTouchEvent const* event); | ||
2609 | 91 | bool handle_pointer_event(MirPointerEvent const* event); | ||
2610 | 92 | }; | ||
2611 | 93 | |||
2612 | 94 | } | ||
2613 | 95 | } // namespace mir | ||
2614 | 96 | |||
2615 | 97 | #endif // MIR_EXAMPLES_WINDOW_MANAGER_H_ | ||
2616 | 98 | 0 | ||
2617 | === removed file 'playground/server_configuration.cpp' | |||
2618 | --- playground/server_configuration.cpp 2017-07-28 17:00:43 +0000 | |||
2619 | +++ playground/server_configuration.cpp 1970-01-01 00:00:00 +0000 | |||
2620 | @@ -1,86 +0,0 @@ | |||
2621 | 1 | /* | ||
2622 | 2 | * Copyright © 2013-2014 Canonical Ltd. | ||
2623 | 3 | * | ||
2624 | 4 | * This program is free software: you can redistribute it and/or modify | ||
2625 | 5 | * it under the terms of the GNU General Public License version 2 or 3 as | ||
2626 | 6 | * published by the Free Software Foundation. | ||
2627 | 7 | * | ||
2628 | 8 | * This program is distributed in the hope that it will be useful, | ||
2629 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2630 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2631 | 11 | * GNU General Public License for more details. | ||
2632 | 12 | * | ||
2633 | 13 | * You should have received a copy of the GNU General Public License | ||
2634 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2635 | 15 | * | ||
2636 | 16 | * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com> | ||
2637 | 17 | */ | ||
2638 | 18 | |||
2639 | 19 | #include "server_configuration.h" | ||
2640 | 20 | #include "mir/options/default_configuration.h" | ||
2641 | 21 | #include "mir/input/composite_event_filter.h" | ||
2642 | 22 | #include "mir/graphics/default_display_configuration_policy.h" | ||
2643 | 23 | #include "mir/main_loop.h" | ||
2644 | 24 | |||
2645 | 25 | #include "server_example_display_configuration_policy.h" | ||
2646 | 26 | #include "server_example_input_event_filter.h" | ||
2647 | 27 | |||
2648 | 28 | namespace me = mir::examples; | ||
2649 | 29 | namespace mg = mir::graphics; | ||
2650 | 30 | |||
2651 | 31 | namespace | ||
2652 | 32 | { | ||
2653 | 33 | std::shared_ptr<mir::options::DefaultConfiguration> const& customize( | ||
2654 | 34 | std::shared_ptr<mir::options::DefaultConfiguration> const& opt) | ||
2655 | 35 | { | ||
2656 | 36 | opt->add_options()(me::display_config_opt, | ||
2657 | 37 | boost::program_options::value<std::string>()-> | ||
2658 | 38 | default_value(me::clone_opt_val), | ||
2659 | 39 | me::display_config_descr); | ||
2660 | 40 | |||
2661 | 41 | return opt; | ||
2662 | 42 | } | ||
2663 | 43 | } | ||
2664 | 44 | |||
2665 | 45 | me::ServerConfiguration::ServerConfiguration(std::shared_ptr<options::DefaultConfiguration> const& configuration_options) : | ||
2666 | 46 | DefaultServerConfiguration(customize(configuration_options)) | ||
2667 | 47 | { | ||
2668 | 48 | } | ||
2669 | 49 | |||
2670 | 50 | me::ServerConfiguration::ServerConfiguration(int argc, char const** argv) : | ||
2671 | 51 | ServerConfiguration(std::make_shared<options::DefaultConfiguration>(argc, argv)) | ||
2672 | 52 | { | ||
2673 | 53 | } | ||
2674 | 54 | |||
2675 | 55 | std::shared_ptr<mg::DisplayConfigurationPolicy> | ||
2676 | 56 | me::ServerConfiguration::the_display_configuration_policy() | ||
2677 | 57 | { | ||
2678 | 58 | return display_configuration_policy( | ||
2679 | 59 | [this]() -> std::shared_ptr<mg::DisplayConfigurationPolicy> | ||
2680 | 60 | { | ||
2681 | 61 | auto display_config = the_options()->get<std::string>(me::display_config_opt); | ||
2682 | 62 | |||
2683 | 63 | if (display_config == me::sidebyside_opt_val) | ||
2684 | 64 | return std::make_shared<mg::SideBySideDisplayConfigurationPolicy>(); | ||
2685 | 65 | else if (display_config == me::single_opt_val) | ||
2686 | 66 | return std::make_shared<mg::SingleDisplayConfigurationPolicy>(); | ||
2687 | 67 | else | ||
2688 | 68 | return DefaultServerConfiguration::the_display_configuration_policy(); | ||
2689 | 69 | }); | ||
2690 | 70 | } | ||
2691 | 71 | |||
2692 | 72 | std::shared_ptr<mir::input::CompositeEventFilter> | ||
2693 | 73 | me::ServerConfiguration::the_composite_event_filter() | ||
2694 | 74 | { | ||
2695 | 75 | return composite_event_filter( | ||
2696 | 76 | [this]() -> std::shared_ptr<mir::input::CompositeEventFilter> | ||
2697 | 77 | { | ||
2698 | 78 | if (!quit_filter) | ||
2699 | 79 | quit_filter = std::make_shared<me::QuitFilter>([this] { the_main_loop()->stop(); }); | ||
2700 | 80 | |||
2701 | 81 | auto composite_filter = DefaultServerConfiguration::the_composite_event_filter(); | ||
2702 | 82 | composite_filter->append(quit_filter); | ||
2703 | 83 | |||
2704 | 84 | return composite_filter; | ||
2705 | 85 | }); | ||
2706 | 86 | } | ||
2707 | 87 | 0 | ||
2708 | === removed file 'playground/server_configuration.h' | |||
2709 | --- playground/server_configuration.h 2017-07-28 17:00:43 +0000 | |||
2710 | +++ playground/server_configuration.h 1970-01-01 00:00:00 +0000 | |||
2711 | @@ -1,49 +0,0 @@ | |||
2712 | 1 | /* | ||
2713 | 2 | * Copyright © 2013-2014 Canonical Ltd. | ||
2714 | 3 | * | ||
2715 | 4 | * This program is free software: you can redistribute it and/or modify | ||
2716 | 5 | * it under the terms of the GNU General Public License version 2 or 3 as | ||
2717 | 6 | * published by the Free Software Foundation. | ||
2718 | 7 | * | ||
2719 | 8 | * This program is distributed in the hope that it will be useful, | ||
2720 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2721 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2722 | 11 | * GNU General Public License for more details. | ||
2723 | 12 | * | ||
2724 | 13 | * You should have received a copy of the GNU General Public License | ||
2725 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2726 | 15 | * | ||
2727 | 16 | * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com> | ||
2728 | 17 | */ | ||
2729 | 18 | |||
2730 | 19 | #ifndef MIR_EXAMPLES_SERVER_CONFIGURATION_H_ | ||
2731 | 20 | #define MIR_EXAMPLES_SERVER_CONFIGURATION_H_ | ||
2732 | 21 | |||
2733 | 22 | #include "mir/default_server_configuration.h" | ||
2734 | 23 | |||
2735 | 24 | namespace mir | ||
2736 | 25 | { | ||
2737 | 26 | namespace options | ||
2738 | 27 | { | ||
2739 | 28 | class DefaultConfiguration; | ||
2740 | 29 | } | ||
2741 | 30 | |||
2742 | 31 | namespace examples | ||
2743 | 32 | { | ||
2744 | 33 | |||
2745 | 34 | class ServerConfiguration : public DefaultServerConfiguration | ||
2746 | 35 | { | ||
2747 | 36 | public: | ||
2748 | 37 | ServerConfiguration(int argc, char const** argv); | ||
2749 | 38 | explicit ServerConfiguration(std::shared_ptr<options::DefaultConfiguration> const& configuration_options); | ||
2750 | 39 | |||
2751 | 40 | std::shared_ptr<graphics::DisplayConfigurationPolicy> the_display_configuration_policy() override; | ||
2752 | 41 | std::shared_ptr<input::CompositeEventFilter> the_composite_event_filter() override; | ||
2753 | 42 | |||
2754 | 43 | private: | ||
2755 | 44 | std::shared_ptr<input::EventFilter> quit_filter; | ||
2756 | 45 | }; | ||
2757 | 46 | } | ||
2758 | 47 | } | ||
2759 | 48 | |||
2760 | 49 | #endif /* MIR_EXAMPLES_SERVER_CONFIGURATION_H_ */ | ||
2761 | 50 | 0 | ||
2762 | === removed file 'playground/server_example_display_configuration_policy.cpp' | |||
2763 | --- playground/server_example_display_configuration_policy.cpp 2017-07-28 17:00:43 +0000 | |||
2764 | +++ playground/server_example_display_configuration_policy.cpp 1970-01-01 00:00:00 +0000 | |||
2765 | @@ -1,115 +0,0 @@ | |||
2766 | 1 | /* | ||
2767 | 2 | * Copyright © 2014 Canonical Ltd. | ||
2768 | 3 | * | ||
2769 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
2770 | 5 | * under the terms of the GNU General Public License version 2 or 3, | ||
2771 | 6 | * as published by the Free Software Foundation. | ||
2772 | 7 | * | ||
2773 | 8 | * This program is distributed in the hope that it will be useful, | ||
2774 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2775 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2776 | 11 | * GNU General Public License for more details. | ||
2777 | 12 | * | ||
2778 | 13 | * You should have received a copy of the GNU General Public License | ||
2779 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2780 | 15 | * | ||
2781 | 16 | * Authored By: Alan Griffiths <alan@octopull.co.uk> | ||
2782 | 17 | */ | ||
2783 | 18 | |||
2784 | 19 | #include "server_example_display_configuration_policy.h" | ||
2785 | 20 | #include "mir/graphics/default_display_configuration_policy.h" | ||
2786 | 21 | |||
2787 | 22 | #include "mir/graphics/display_configuration.h" | ||
2788 | 23 | #include "mir/server.h" | ||
2789 | 24 | #include "mir/options/option.h" | ||
2790 | 25 | |||
2791 | 26 | #include <algorithm> | ||
2792 | 27 | #include <unordered_map> | ||
2793 | 28 | #include <stdexcept> | ||
2794 | 29 | |||
2795 | 30 | namespace geom = mir::geometry; | ||
2796 | 31 | namespace me = mir::examples; | ||
2797 | 32 | namespace mg = mir::graphics; | ||
2798 | 33 | |||
2799 | 34 | ///\example server_example_display_configuration_policy.cpp | ||
2800 | 35 | /// Demonstrate custom display configuration policies for "sidebyside" and "single" | ||
2801 | 36 | |||
2802 | 37 | char const* const me::display_config_opt = "display-config"; | ||
2803 | 38 | char const* const me::display_config_descr = "Display configuration [{clone,sidebyside,single}]"; | ||
2804 | 39 | |||
2805 | 40 | char const* const me::clone_opt_val = "clone"; | ||
2806 | 41 | char const* const me::sidebyside_opt_val = "sidebyside"; | ||
2807 | 42 | char const* const me::single_opt_val = "single"; | ||
2808 | 43 | |||
2809 | 44 | char const* const me::display_alpha_opt = "translucent"; | ||
2810 | 45 | char const* const me::display_alpha_descr = "Select a display mode with alpha[{on,off}]"; | ||
2811 | 46 | |||
2812 | 47 | char const* const me::display_alpha_off = "off"; | ||
2813 | 48 | char const* const me::display_alpha_on = "on"; | ||
2814 | 49 | |||
2815 | 50 | namespace | ||
2816 | 51 | { | ||
2817 | 52 | bool contains_alpha(MirPixelFormat format) | ||
2818 | 53 | { | ||
2819 | 54 | return (format == mir_pixel_format_abgr_8888 || | ||
2820 | 55 | format == mir_pixel_format_argb_8888); | ||
2821 | 56 | } | ||
2822 | 57 | } | ||
2823 | 58 | |||
2824 | 59 | me::PixelFormatSelector::PixelFormatSelector(std::shared_ptr<DisplayConfigurationPolicy> const& base_policy, | ||
2825 | 60 | bool with_alpha) | ||
2826 | 61 | : base_policy{base_policy}, | ||
2827 | 62 | with_alpha{with_alpha} | ||
2828 | 63 | {} | ||
2829 | 64 | |||
2830 | 65 | void me::PixelFormatSelector::apply_to(graphics::DisplayConfiguration & conf) | ||
2831 | 66 | { | ||
2832 | 67 | base_policy->apply_to(conf); | ||
2833 | 68 | conf.for_each_output( | ||
2834 | 69 | [&](graphics::UserDisplayConfigurationOutput& conf_output) | ||
2835 | 70 | { | ||
2836 | 71 | if (!conf_output.connected || !conf_output.used) return; | ||
2837 | 72 | |||
2838 | 73 | auto const& pos = find_if(conf_output.pixel_formats.begin(), | ||
2839 | 74 | conf_output.pixel_formats.end(), | ||
2840 | 75 | [&](MirPixelFormat format) -> bool | ||
2841 | 76 | { | ||
2842 | 77 | return contains_alpha(format) == with_alpha; | ||
2843 | 78 | } | ||
2844 | 79 | ); | ||
2845 | 80 | |||
2846 | 81 | // keep the default settings if nothing was found | ||
2847 | 82 | if (pos == conf_output.pixel_formats.end()) | ||
2848 | 83 | return; | ||
2849 | 84 | |||
2850 | 85 | conf_output.current_format = *pos; | ||
2851 | 86 | }); | ||
2852 | 87 | } | ||
2853 | 88 | |||
2854 | 89 | void me::add_display_configuration_options_to(mir::Server& server) | ||
2855 | 90 | { | ||
2856 | 91 | // Add choice of monitor configuration | ||
2857 | 92 | server.add_configuration_option( | ||
2858 | 93 | me::display_config_opt, me::display_config_descr, me::clone_opt_val); | ||
2859 | 94 | server.add_configuration_option( | ||
2860 | 95 | me::display_alpha_opt, me::display_alpha_descr, me::display_alpha_off); | ||
2861 | 96 | |||
2862 | 97 | server.wrap_display_configuration_policy( | ||
2863 | 98 | [&](std::shared_ptr<mg::DisplayConfigurationPolicy> const& wrapped) | ||
2864 | 99 | -> std::shared_ptr<mg::DisplayConfigurationPolicy> | ||
2865 | 100 | { | ||
2866 | 101 | auto const options = server.get_options(); | ||
2867 | 102 | auto display_layout = options->get<std::string>(me::display_config_opt); | ||
2868 | 103 | auto with_alpha = options->get<std::string>(me::display_alpha_opt) == me::display_alpha_on; | ||
2869 | 104 | |||
2870 | 105 | auto layout_selector = wrapped; | ||
2871 | 106 | |||
2872 | 107 | if (display_layout == me::sidebyside_opt_val) | ||
2873 | 108 | layout_selector = std::make_shared<mg::SideBySideDisplayConfigurationPolicy>(); | ||
2874 | 109 | else if (display_layout == me::single_opt_val) | ||
2875 | 110 | layout_selector = std::make_shared<mg::SingleDisplayConfigurationPolicy>(); | ||
2876 | 111 | |||
2877 | 112 | // Whatever the layout select a pixel format with requested alpha | ||
2878 | 113 | return std::make_shared<me::PixelFormatSelector>(layout_selector, with_alpha); | ||
2879 | 114 | }); | ||
2880 | 115 | } | ||
2881 | 116 | 0 | ||
2882 | === removed file 'playground/server_example_display_configuration_policy.h' | |||
2883 | --- playground/server_example_display_configuration_policy.h 2017-07-28 17:00:43 +0000 | |||
2884 | +++ playground/server_example_display_configuration_policy.h 1970-01-01 00:00:00 +0000 | |||
2885 | @@ -1,62 +0,0 @@ | |||
2886 | 1 | /* | ||
2887 | 2 | * Copyright © 2014 Canonical Ltd. | ||
2888 | 3 | * | ||
2889 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
2890 | 5 | * under the terms of the GNU General Public License version 2 or 3, | ||
2891 | 6 | * as published by the Free Software Foundation. | ||
2892 | 7 | * | ||
2893 | 8 | * This program is distributed in the hope that it will be useful, | ||
2894 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2895 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2896 | 11 | * GNU General Public License for more details. | ||
2897 | 12 | * | ||
2898 | 13 | * You should have received a copy of the GNU General Public License | ||
2899 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2900 | 15 | * | ||
2901 | 16 | * Authored By: Alan Griffiths <alan@octopull.co.uk> | ||
2902 | 17 | */ | ||
2903 | 18 | |||
2904 | 19 | #ifndef MIR_EXAMPLE_DISPLAY_CONFIGURATION_POLICY_H_ | ||
2905 | 20 | #define MIR_EXAMPLE_DISPLAY_CONFIGURATION_POLICY_H_ | ||
2906 | 21 | |||
2907 | 22 | #include "mir/graphics/display_configuration_policy.h" | ||
2908 | 23 | |||
2909 | 24 | #include <memory> | ||
2910 | 25 | |||
2911 | 26 | namespace mir | ||
2912 | 27 | { | ||
2913 | 28 | class Server; | ||
2914 | 29 | |||
2915 | 30 | namespace examples | ||
2916 | 31 | { | ||
2917 | 32 | extern char const* const display_config_opt; | ||
2918 | 33 | extern char const* const display_config_descr; | ||
2919 | 34 | extern char const* const clone_opt_val; | ||
2920 | 35 | extern char const* const sidebyside_opt_val; | ||
2921 | 36 | extern char const* const single_opt_val; | ||
2922 | 37 | extern char const* const display_alpha_opt; | ||
2923 | 38 | extern char const* const display_alpha_descr; | ||
2924 | 39 | extern char const* const display_alpha_off; | ||
2925 | 40 | extern char const* const display_alpha_on; | ||
2926 | 41 | |||
2927 | 42 | /** | ||
2928 | 43 | * \brief Example of a DisplayConfigurationPolicy that tries to find | ||
2929 | 44 | * an opaque or transparent pixel format, or falls back to the default | ||
2930 | 45 | * if not found. | ||
2931 | 46 | */ | ||
2932 | 47 | class PixelFormatSelector : public graphics::DisplayConfigurationPolicy | ||
2933 | 48 | { | ||
2934 | 49 | public: | ||
2935 | 50 | PixelFormatSelector(std::shared_ptr<graphics::DisplayConfigurationPolicy> const& base_policy, | ||
2936 | 51 | bool with_alpha); | ||
2937 | 52 | virtual void apply_to(graphics::DisplayConfiguration& conf); | ||
2938 | 53 | private: | ||
2939 | 54 | std::shared_ptr<graphics::DisplayConfigurationPolicy> const base_policy; | ||
2940 | 55 | bool const with_alpha; | ||
2941 | 56 | }; | ||
2942 | 57 | |||
2943 | 58 | void add_display_configuration_options_to(Server& server); | ||
2944 | 59 | } | ||
2945 | 60 | } | ||
2946 | 61 | |||
2947 | 62 | #endif /* MIR_EXAMPLE_DISPLAY_CONFIGURATION_POLICY_H_ */ | ||
2948 | 63 | 0 | ||
2949 | === removed file 'src/include/server/mir/compositor/decoration.h' | |||
2950 | --- src/include/server/mir/compositor/decoration.h 2017-07-28 17:00:43 +0000 | |||
2951 | +++ src/include/server/mir/compositor/decoration.h 1970-01-01 00:00:00 +0000 | |||
2952 | @@ -1,38 +0,0 @@ | |||
2953 | 1 | /* | ||
2954 | 2 | * Copyright © 2015 Canonical Ltd. | ||
2955 | 3 | * | ||
2956 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
2957 | 5 | * under the terms of the GNU General Public License version 2 or 3, | ||
2958 | 6 | * as published by the Free Software Foundation. | ||
2959 | 7 | * | ||
2960 | 8 | * This program is distributed in the hope that it will be useful, | ||
2961 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2962 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2963 | 11 | * GNU General Public License for more details. | ||
2964 | 12 | * | ||
2965 | 13 | * You should have received a copy of the GNU General Public License | ||
2966 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2967 | 15 | * | ||
2968 | 16 | * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com> | ||
2969 | 17 | */ | ||
2970 | 18 | |||
2971 | 19 | #ifndef MIR_COMPOSITOR_DECORATION_H_ | ||
2972 | 20 | #define MIR_COMPOSITOR_DECORATION_H_ | ||
2973 | 21 | |||
2974 | 22 | #include <string> | ||
2975 | 23 | |||
2976 | 24 | namespace mir { namespace compositor { | ||
2977 | 25 | |||
2978 | 26 | struct Decoration | ||
2979 | 27 | { | ||
2980 | 28 | enum class Type {none, surface} type; | ||
2981 | 29 | std::string name; | ||
2982 | 30 | |||
2983 | 31 | Decoration() : type{Type::none} {} | ||
2984 | 32 | Decoration(Type t, std::string const& n) : type{t}, name{n} {} | ||
2985 | 33 | operator bool() const { return type != Type::none; } | ||
2986 | 34 | }; | ||
2987 | 35 | |||
2988 | 36 | } } // namespace mir::compositor | ||
2989 | 37 | |||
2990 | 38 | #endif // MIR_COMPOSITOR_DECORATION_H_ | ||
2991 | 39 | 0 | ||
2992 | === modified file 'src/miral/CMakeLists.txt' | |||
2993 | --- src/miral/CMakeLists.txt 2017-08-30 15:50:37 +0000 | |||
2994 | +++ src/miral/CMakeLists.txt 2017-08-30 15:50:38 +0000 | |||
2995 | @@ -1,4 +1,3 @@ | |||
2996 | 1 | <<<<<<< TREE | ||
2997 | 2 | set(MIRAL_VERSION_MAJOR 1) | 1 | set(MIRAL_VERSION_MAJOR 1) |
2998 | 3 | set(MIRAL_VERSION_MINOR 5) | 2 | set(MIRAL_VERSION_MINOR 5) |
2999 | 4 | set(MIRAL_VERSION_PATCH 0) | 3 | set(MIRAL_VERSION_PATCH 0) |
3000 | @@ -135,146 +134,6 @@ | |||
3001 | 135 | ${miral_include}/miral/version.h | 134 | ${miral_include}/miral/version.h |
3002 | 136 | ) | 135 | ) |
3003 | 137 | 136 | ||
3004 | 138 | install(TARGETS miral LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}") | ||
3005 | 139 | install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/miral DESTINATION "${INCLUDEDIR}") | ||
3006 | 140 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/miral.pc | ||
3007 | 141 | ${CMAKE_CURRENT_BINARY_DIR}/mirclientcpp.pc DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig") | ||
3008 | 142 | ======= | ||
3009 | 143 | set(MIRAL_VERSION_MAJOR 1) | ||
3010 | 144 | set(MIRAL_VERSION_MINOR 5) | ||
3011 | 145 | set(MIRAL_VERSION_PATCH 0) | ||
3012 | 146 | |||
3013 | 147 | if(${CMAKE_COMPILER_IS_GNUCXX}) | ||
3014 | 148 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto") | ||
3015 | 149 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto") | ||
3016 | 150 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -flto") | ||
3017 | 151 | set(CMAKE_AR "gcc-ar") | ||
3018 | 152 | set(CMAKE_NM "gcc-nm") | ||
3019 | 153 | set(CMAKE_RANLIB "gcc-ranlib") | ||
3020 | 154 | endif() | ||
3021 | 155 | |||
3022 | 156 | include_directories( | ||
3023 | 157 | ${PROJECT_SOURCE_DIR}/include/platform | ||
3024 | 158 | ${PROJECT_SOURCE_DIR}/include/client | ||
3025 | 159 | ${PROJECT_SOURCE_DIR}/include/server | ||
3026 | 160 | ) | ||
3027 | 161 | |||
3028 | 162 | set(MIRAL_ABI 2) | ||
3029 | 163 | set(symbol_map ${CMAKE_CURRENT_SOURCE_DIR}/symbols.map) | ||
3030 | 164 | set(miral_include ${PROJECT_SOURCE_DIR}/include/miral) | ||
3031 | 165 | |||
3032 | 166 | add_library(mirclientcpp INTERFACE) | ||
3033 | 167 | |||
3034 | 168 | add_library(miral-internal STATIC | ||
3035 | 169 | basic_window_manager.cpp basic_window_manager.h window_manager_tools_implementation.h | ||
3036 | 170 | coordinate_translator.cpp coordinate_translator.h | ||
3037 | 171 | display_configuration_listeners.cpp display_configuration_listeners.h | ||
3038 | 172 | mru_window_list.cpp mru_window_list.h | ||
3039 | 173 | window_management_trace.cpp window_management_trace.h | ||
3040 | 174 | xcursor_loader.cpp xcursor_loader.h | ||
3041 | 175 | xcursor.c xcursor.h | ||
3042 | 176 | both_versions.h | ||
3043 | 177 | join_client_threads.h | ||
3044 | 178 | ) | ||
3045 | 179 | |||
3046 | 180 | set_source_files_properties(xcursor.c PROPERTIES COMPILE_DEFINITIONS _GNU_SOURCE) | ||
3047 | 181 | |||
3048 | 182 | add_library(miral SHARED | ||
3049 | 183 | active_outputs.cpp ${miral_include}/miral/active_outputs.h | ||
3050 | 184 | add_init_callback.cpp ${miral_include}/miral/add_init_callback.h | ||
3051 | 185 | application.cpp ${miral_include}/miral/application.h | ||
3052 | 186 | application_authorizer.cpp ${miral_include}/miral/application_authorizer.h | ||
3053 | 187 | application_info.cpp ${miral_include}/miral/application_info.h | ||
3054 | 188 | canonical_window_manager.cpp ${miral_include}/miral/canonical_window_manager.h | ||
3055 | 189 | command_line_option.cpp ${miral_include}/miral/command_line_option.h | ||
3056 | 190 | cursor_theme.cpp ${miral_include}/miral/cursor_theme.h | ||
3057 | 191 | debug_extension.cpp ${miral_include}/miral/debug_extension.h | ||
3058 | 192 | keymap.cpp ${miral_include}/miral/keymap.h | ||
3059 | 193 | runner.cpp ${miral_include}/miral/runner.h | ||
3060 | 194 | display_configuration_option.cpp ${miral_include}/miral/display_configuration_option.h | ||
3061 | 195 | output.cpp ${miral_include}/miral/output.h | ||
3062 | 196 | append_event_filter.cpp ${miral_include}/miral/append_event_filter.h | ||
3063 | 197 | window.cpp ${miral_include}/miral/window.h | ||
3064 | 198 | window_info.cpp ${miral_include}/miral/window_info.h | ||
3065 | 199 | window_management_options.cpp ${miral_include}/miral/window_management_options.h | ||
3066 | 200 | window_specification.cpp ${miral_include}/miral/window_specification.h | ||
3067 | 201 | internal_client.cpp ${miral_include}/miral/internal_client.h | ||
3068 | 202 | set_command_line_handler.cpp ${miral_include}/miral/set_command_line_handler.h | ||
3069 | 203 | set_terminator.cpp ${miral_include}/miral/set_terminator.h | ||
3070 | 204 | set_window_management_policy.cpp ${miral_include}/miral/set_window_management_policy.h | ||
3071 | 205 | workspace_policy.cpp ${miral_include}/miral/workspace_policy.h | ||
3072 | 206 | window_management_policy.cpp ${miral_include}/miral/window_management_policy.h | ||
3073 | 207 | window_manager_tools.cpp ${miral_include}/miral/window_manager_tools.h | ||
3074 | 208 | ${miral_include}/miral/window_management_policy_addendum2.h | ||
3075 | 209 | ${miral_include}/miral/window_management_policy_addendum3.h | ||
3076 | 210 | ${miral_include}/mir/client/blob.h | ||
3077 | 211 | ${miral_include}/mir/client/cookie.h | ||
3078 | 212 | ${miral_include}/mir/client/window_spec.h | ||
3079 | 213 | ${miral_include}/mir/client/window_id.h | ||
3080 | 214 | ${miral_include}/mir/client/connection.h | ||
3081 | 215 | ${miral_include}/mir/client/display_config.h | ||
3082 | 216 | ${miral_include}/mir/client/window.h | ||
3083 | 217 | ) | ||
3084 | 218 | |||
3085 | 219 | target_include_directories(mirclientcpp | ||
3086 | 220 | INTERFACE "${miral_include}" ${MIRCLIENT_INCLUDE_DIRS} | ||
3087 | 221 | ) | ||
3088 | 222 | |||
3089 | 223 | target_include_directories(miral-internal | ||
3090 | 224 | PRIVATE "${miral_include}" ${MIRCLIENT_INCLUDE_DIRS} | ||
3091 | 225 | PRIVATE ${MIRSERVER_INCLUDE_DIRS} | ||
3092 | 226 | ) | ||
3093 | 227 | |||
3094 | 228 | target_include_directories(miral | ||
3095 | 229 | PUBLIC "${miral_include}" ${MIRCLIENT_INCLUDE_DIRS} | ||
3096 | 230 | PRIVATE ${MIRSERVER_INCLUDE_DIRS} | ||
3097 | 231 | ) | ||
3098 | 232 | |||
3099 | 233 | target_link_libraries(miral | ||
3100 | 234 | PUBLIC | ||
3101 | 235 | mirclient | ||
3102 | 236 | mircommon | ||
3103 | 237 | PRIVATE | ||
3104 | 238 | miral-internal | ||
3105 | 239 | mirserver | ||
3106 | 240 | ) | ||
3107 | 241 | |||
3108 | 242 | set_target_properties(miral | ||
3109 | 243 | PROPERTIES | ||
3110 | 244 | SOVERSION ${MIRAL_ABI} | ||
3111 | 245 | LINK_FLAGS "-Wl,--exclude-libs=ALL -Wl,--version-script,${symbol_map}" | ||
3112 | 246 | LINK_DEPENDS ${symbol_map} | ||
3113 | 247 | ) | ||
3114 | 248 | |||
3115 | 249 | # clang generates slightly different symbols (but we don't care) | ||
3116 | 250 | if (CMAKE_COMPILER_IS_GNUCXX) | ||
3117 | 251 | add_custom_target(check-miral-symbols ALL | ||
3118 | 252 | DEPENDS miral ${PROJECT_SOURCE_DIR}/debian/libmiral${MIRAL_ABI}.symbols | ||
3119 | 253 | COMMAND rm -f ${CMAKE_CURRENT_BINARY_DIR}/libmiral${MIRAL_ABI}.symbols | ||
3120 | 254 | COMMAND dpkg-gensymbols -e${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libmiral.so.${MIRAL_ABI} -plibmiral${MIRAL_ABI} -O${CMAKE_CURRENT_BINARY_DIR}/libmiral${MIRAL_ABI}.symbols | ||
3121 | 255 | WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" | ||
3122 | 256 | VERBATIM | ||
3123 | 257 | ) | ||
3124 | 258 | endif() | ||
3125 | 259 | |||
3126 | 260 | set(LIBDIR "${CMAKE_INSTALL_FULL_LIBDIR}") | ||
3127 | 261 | set(INCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include") | ||
3128 | 262 | |||
3129 | 263 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/miral.pc.in | ||
3130 | 264 | ${CMAKE_CURRENT_BINARY_DIR}/miral.pc | ||
3131 | 265 | @ONLY | ||
3132 | 266 | ) | ||
3133 | 267 | |||
3134 | 268 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/mirclientcpp.pc.in | ||
3135 | 269 | ${CMAKE_CURRENT_BINARY_DIR}/mirclientcpp.pc | ||
3136 | 270 | @ONLY | ||
3137 | 271 | ) | ||
3138 | 272 | |||
3139 | 273 | configure_file( | ||
3140 | 274 | ${CMAKE_CURRENT_SOURCE_DIR}/version.h.in | ||
3141 | 275 | ${miral_include}/miral/version.h | ||
3142 | 276 | ) | ||
3143 | 277 | |||
3144 | 278 | if(TARGET doc) | 137 | if(TARGET doc) |
3145 | 279 | add_custom_target(regenerate-miral-symbols-map | 138 | add_custom_target(regenerate-miral-symbols-map |
3146 | 280 | ${CMAKE_CURRENT_SOURCE_DIR}/process_doxygen_xml.py ${CMAKE_BINARY_DIR}/doc/xml/*.xml > ${symbol_map} | 139 | ${CMAKE_CURRENT_SOURCE_DIR}/process_doxygen_xml.py ${CMAKE_BINARY_DIR}/doc/xml/*.xml > ${symbol_map} |
3147 | @@ -285,4 +144,3 @@ | |||
3148 | 285 | install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/miral DESTINATION "${INCLUDEDIR}") | 144 | install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/miral DESTINATION "${INCLUDEDIR}") |
3149 | 286 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/miral.pc | 145 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/miral.pc |
3150 | 287 | ${CMAKE_CURRENT_BINARY_DIR}/mirclientcpp.pc DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig") | 146 | ${CMAKE_CURRENT_BINARY_DIR}/mirclientcpp.pc DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig") |
3151 | 288 | >>>>>>> MERGE-SOURCE | ||
3152 | 289 | 147 | ||
3153 | === modified file 'src/miral/miral.pc.in' | |||
3154 | --- src/miral/miral.pc.in 2017-08-30 15:50:37 +0000 | |||
3155 | +++ src/miral/miral.pc.in 2017-08-29 09:17:03 +0000 | |||
3156 | @@ -1,4 +1,3 @@ | |||
3157 | 1 | <<<<<<< TREE | ||
3158 | 2 | libdir=@LIBDIR@ | 1 | libdir=@LIBDIR@ |
3159 | 3 | includedir=@INCLUDEDIR@/miral | 2 | includedir=@INCLUDEDIR@/miral |
3160 | 4 | 3 | ||
3161 | @@ -8,14 +7,3 @@ | |||
3162 | 8 | Requires: mirclientcpp | 7 | Requires: mirclientcpp |
3163 | 9 | Libs: -L${libdir} -lmiral | 8 | Libs: -L${libdir} -lmiral |
3164 | 10 | Cflags: -I${includedir} | 9 | Cflags: -I${includedir} |
3165 | 11 | ======= | ||
3166 | 12 | libdir=@LIBDIR@ | ||
3167 | 13 | includedir=@INCLUDEDIR@ | ||
3168 | 14 | |||
3169 | 15 | Name: miral | ||
3170 | 16 | Description: Mir Abstraction Layer library | ||
3171 | 17 | Version: @MIRAL_VERSION@ | ||
3172 | 18 | Requires: mirclientcpp | ||
3173 | 19 | Libs: -L${libdir} -lmiral | ||
3174 | 20 | Cflags: -I${includedir} | ||
3175 | 21 | >>>>>>> MERGE-SOURCE | ||
3176 | 22 | 10 | ||
3177 | === modified file 'src/miral/mirclientcpp.pc.in' | |||
3178 | --- src/miral/mirclientcpp.pc.in 2017-08-30 15:50:37 +0000 | |||
3179 | +++ src/miral/mirclientcpp.pc.in 2017-08-29 09:17:03 +0000 | |||
3180 | @@ -1,4 +1,3 @@ | |||
3181 | 1 | <<<<<<< TREE | ||
3182 | 2 | includedir=@INCLUDEDIR@/miral | 1 | includedir=@INCLUDEDIR@/miral |
3183 | 3 | 2 | ||
3184 | 4 | Name: mirclientcpp | 3 | Name: mirclientcpp |
3185 | @@ -6,12 +5,3 @@ | |||
3186 | 6 | Version: @MIRAL_VERSION@ | 5 | Version: @MIRAL_VERSION@ |
3187 | 7 | Requires: mirclient | 6 | Requires: mirclient |
3188 | 8 | Cflags: -I${includedir} | 7 | Cflags: -I${includedir} |
3189 | 9 | ======= | ||
3190 | 10 | includedir=@INCLUDEDIR@ | ||
3191 | 11 | |||
3192 | 12 | Name: mirclientcpp | ||
3193 | 13 | Description: Mir Abstraction Layer C++ wrapper for mirclient | ||
3194 | 14 | Version: @MIRAL_VERSION@ | ||
3195 | 15 | Requires: mirclient | ||
3196 | 16 | Cflags: -I${includedir} | ||
3197 | 17 | >>>>>>> MERGE-SOURCE | ||
3198 | 18 | 8 | ||
3199 | === modified file 'src/server/scene/basic_surface.cpp' | |||
3200 | --- src/server/scene/basic_surface.cpp 2017-07-28 17:00:43 +0000 | |||
3201 | +++ src/server/scene/basic_surface.cpp 2017-08-30 15:50:38 +0000 | |||
3202 | @@ -289,12 +289,6 @@ | |||
3203 | 289 | observers.moved_to(top_left); | 289 | observers.moved_to(top_left); |
3204 | 290 | } | 290 | } |
3205 | 291 | 291 | ||
3206 | 292 | float ms::BasicSurface::alpha() const | ||
3207 | 293 | { | ||
3208 | 294 | std::unique_lock<std::mutex> lk(guard); | ||
3209 | 295 | return surface_alpha; | ||
3210 | 296 | } | ||
3211 | 297 | |||
3212 | 298 | void ms::BasicSurface::set_hidden(bool hide) | 292 | void ms::BasicSurface::set_hidden(bool hide) |
3213 | 299 | { | 293 | { |
3214 | 300 | { | 294 | { |
3215 | 301 | 295 | ||
3216 | === modified file 'src/server/scene/basic_surface.h' | |||
3217 | --- src/server/scene/basic_surface.h 2017-07-28 17:00:43 +0000 | |||
3218 | +++ src/server/scene/basic_surface.h 2017-08-30 15:50:38 +0000 | |||
3219 | @@ -79,7 +79,7 @@ | |||
3220 | 79 | 79 | ||
3221 | 80 | std::string name() const override; | 80 | std::string name() const override; |
3222 | 81 | void move_to(geometry::Point const& top_left) override; | 81 | void move_to(geometry::Point const& top_left) override; |
3224 | 82 | float alpha() const override; | 82 | |
3225 | 83 | void set_hidden(bool is_hidden); | 83 | void set_hidden(bool is_hidden); |
3226 | 84 | 84 | ||
3227 | 85 | geometry::Size size() const override; | 85 | geometry::Size size() const override; |
3228 | 86 | 86 | ||
3229 | === modified file 'src/server/scene/surface_stack.cpp' | |||
3230 | --- src/server/scene/surface_stack.cpp 2017-07-28 17:00:43 +0000 | |||
3231 | +++ src/server/scene/surface_stack.cpp 2017-08-30 15:50:38 +0000 | |||
3232 | @@ -23,7 +23,6 @@ | |||
3233 | 23 | #include "mir/scene/surface.h" | 23 | #include "mir/scene/surface.h" |
3234 | 24 | #include "mir/scene/scene_report.h" | 24 | #include "mir/scene/scene_report.h" |
3235 | 25 | #include "mir/compositor/scene_element.h" | 25 | #include "mir/compositor/scene_element.h" |
3236 | 26 | #include "mir/compositor/decoration.h" | ||
3237 | 27 | #include "mir/graphics/renderable.h" | 26 | #include "mir/graphics/renderable.h" |
3238 | 28 | 27 | ||
3239 | 29 | #include <boost/throw_exception.hpp> | 28 | #include <boost/throw_exception.hpp> |
3240 | @@ -73,11 +72,6 @@ | |||
3241 | 73 | tracker->occluded_in(cid); | 72 | tracker->occluded_in(cid); |
3242 | 74 | } | 73 | } |
3243 | 75 | 74 | ||
3244 | 76 | std::unique_ptr<mc::Decoration> decoration() const override | ||
3245 | 77 | { | ||
3246 | 78 | return std::make_unique<mc::Decoration>(mc::Decoration::Type::surface, surface_name); | ||
3247 | 79 | } | ||
3248 | 80 | |||
3249 | 81 | private: | 75 | private: |
3250 | 82 | std::shared_ptr<mg::Renderable> const renderable_; | 76 | std::shared_ptr<mg::Renderable> const renderable_; |
3251 | 83 | std::shared_ptr<ms::RenderingTracker> const tracker; | 77 | std::shared_ptr<ms::RenderingTracker> const tracker; |
3252 | @@ -108,11 +102,6 @@ | |||
3253 | 108 | { | 102 | { |
3254 | 109 | } | 103 | } |
3255 | 110 | 104 | ||
3256 | 111 | std::unique_ptr<mc::Decoration> decoration() const override | ||
3257 | 112 | { | ||
3258 | 113 | return std::make_unique<mc::Decoration>(); | ||
3259 | 114 | } | ||
3260 | 115 | |||
3261 | 116 | private: | 105 | private: |
3262 | 117 | std::shared_ptr<mg::Renderable> const renderable_; | 106 | std::shared_ptr<mg::Renderable> const renderable_; |
3263 | 118 | }; | 107 | }; |
3264 | 119 | 108 | ||
3265 | === modified file 'tests/include/mir/test/doubles/stub_scene_element.h' | |||
3266 | --- tests/include/mir/test/doubles/stub_scene_element.h 2017-07-28 17:00:43 +0000 | |||
3267 | +++ tests/include/mir/test/doubles/stub_scene_element.h 2017-08-30 15:50:38 +0000 | |||
3268 | @@ -20,7 +20,6 @@ | |||
3269 | 20 | #define MIR_TEST_DOUBLES_STUB_SCENE_ELEMENT_H_ | 20 | #define MIR_TEST_DOUBLES_STUB_SCENE_ELEMENT_H_ |
3270 | 21 | 21 | ||
3271 | 22 | #include "mir/compositor/scene_element.h" | 22 | #include "mir/compositor/scene_element.h" |
3272 | 23 | #include "mir/compositor/decoration.h" | ||
3273 | 24 | #include "stub_renderable.h" | 23 | #include "stub_renderable.h" |
3274 | 25 | 24 | ||
3275 | 26 | namespace mir | 25 | namespace mir |
3276 | @@ -56,11 +55,6 @@ | |||
3277 | 56 | { | 55 | { |
3278 | 57 | } | 56 | } |
3279 | 58 | 57 | ||
3280 | 59 | std::unique_ptr<compositor::Decoration> decoration() const override | ||
3281 | 60 | { | ||
3282 | 61 | return nullptr; | ||
3283 | 62 | } | ||
3284 | 63 | |||
3285 | 64 | private: | 58 | private: |
3286 | 65 | std::shared_ptr<graphics::Renderable> const renderable_; | 59 | std::shared_ptr<graphics::Renderable> const renderable_; |
3287 | 66 | }; | 60 | }; |
3288 | 67 | 61 | ||
3289 | === modified file 'tests/include/mir/test/doubles/stub_scene_surface.h' | |||
3290 | --- tests/include/mir/test/doubles/stub_scene_surface.h 2017-07-28 17:00:43 +0000 | |||
3291 | +++ tests/include/mir/test/doubles/stub_scene_surface.h 2017-08-30 15:50:38 +0000 | |||
3292 | @@ -53,7 +53,6 @@ | |||
3293 | 53 | graphics::RenderableList generate_renderables(compositor::CompositorID) const override { return {}; } | 53 | graphics::RenderableList generate_renderables(compositor::CompositorID) const override { return {}; } |
3294 | 54 | int buffers_ready_for_compositor(void const*) const override { return 0; } | 54 | int buffers_ready_for_compositor(void const*) const override { return 0; } |
3295 | 55 | 55 | ||
3296 | 56 | float alpha() const override { return 0.0f;} | ||
3297 | 57 | MirWindowType type() const override { return mir_window_type_normal; } | 56 | MirWindowType type() const override { return mir_window_type_normal; } |
3298 | 58 | MirWindowState state() const override { return mir_window_state_unknown; } | 57 | MirWindowState state() const override { return mir_window_state_unknown; } |
3299 | 59 | 58 | ||
3300 | 60 | 59 | ||
3301 | === modified file 'tests/mir_test_framework/stub_surface.cpp' | |||
3302 | --- tests/mir_test_framework/stub_surface.cpp 2017-07-28 17:00:43 +0000 | |||
3303 | +++ tests/mir_test_framework/stub_surface.cpp 2017-08-30 15:50:38 +0000 | |||
3304 | @@ -29,11 +29,6 @@ | |||
3305 | 29 | { | 29 | { |
3306 | 30 | } | 30 | } |
3307 | 31 | 31 | ||
3308 | 32 | float mtd::StubSurface::alpha() const | ||
3309 | 33 | { | ||
3310 | 34 | return 0; | ||
3311 | 35 | } | ||
3312 | 36 | |||
3313 | 37 | mir::geometry::Size mtd::StubSurface::size() const | 32 | mir::geometry::Size mtd::StubSurface::size() const |
3314 | 38 | { | 33 | { |
3315 | 39 | return {}; | 34 | return {}; |
3316 | 40 | 35 | ||
3317 | === modified file 'tests/unit-tests/CMakeLists.txt' | |||
3318 | --- tests/unit-tests/CMakeLists.txt 2017-05-08 03:04:26 +0000 | |||
3319 | +++ tests/unit-tests/CMakeLists.txt 2017-08-30 15:50:38 +0000 | |||
3320 | @@ -122,7 +122,6 @@ | |||
3321 | 122 | 122 | ||
3322 | 123 | exampleserverconfig | 123 | exampleserverconfig |
3323 | 124 | mirdraw | 124 | mirdraw |
3324 | 125 | demo-shell | ||
3325 | 126 | mircommon | 125 | mircommon |
3326 | 127 | client_platform_common | 126 | client_platform_common |
3327 | 128 | server_platform_common | 127 | server_platform_common |
3328 | @@ -166,7 +165,6 @@ | |||
3329 | 166 | 165 | ||
3330 | 167 | exampleserverconfig | 166 | exampleserverconfig |
3331 | 168 | mirdraw | 167 | mirdraw |
3332 | 169 | demo-shell | ||
3333 | 170 | mircommon | 168 | mircommon |
3334 | 171 | client_platform_common | 169 | client_platform_common |
3335 | 172 | 170 | ||
3336 | 173 | 171 | ||
3337 | === modified file 'tests/unit-tests/compositor/test_default_display_buffer_compositor.cpp' | |||
3338 | --- tests/unit-tests/compositor/test_default_display_buffer_compositor.cpp 2017-07-28 17:00:43 +0000 | |||
3339 | +++ tests/unit-tests/compositor/test_default_display_buffer_compositor.cpp 2017-08-30 15:50:38 +0000 | |||
3340 | @@ -18,7 +18,6 @@ | |||
3341 | 18 | 18 | ||
3342 | 19 | #include "src/server/compositor/default_display_buffer_compositor.h" | 19 | #include "src/server/compositor/default_display_buffer_compositor.h" |
3343 | 20 | #include "mir/compositor/display_buffer_compositor.h" | 20 | #include "mir/compositor/display_buffer_compositor.h" |
3344 | 21 | #include "mir/compositor/decoration.h" | ||
3345 | 22 | #include "src/server/report/null_report_factory.h" | 21 | #include "src/server/report/null_report_factory.h" |
3346 | 23 | #include "mir/compositor/scene.h" | 22 | #include "mir/compositor/scene.h" |
3347 | 24 | #include "mir/renderer/renderer.h" | 23 | #include "mir/renderer/renderer.h" |
3348 | @@ -74,11 +73,6 @@ | |||
3349 | 74 | { | 73 | { |
3350 | 75 | } | 74 | } |
3351 | 76 | 75 | ||
3352 | 77 | std::unique_ptr<mc::Decoration> decoration() const override | ||
3353 | 78 | { | ||
3354 | 79 | return nullptr; | ||
3355 | 80 | } | ||
3356 | 81 | |||
3357 | 82 | private: | 76 | private: |
3358 | 83 | std::shared_ptr<mg::Renderable> const renderable_; | 77 | std::shared_ptr<mg::Renderable> const renderable_; |
3359 | 84 | }; | 78 | }; |
3360 | @@ -346,7 +340,6 @@ | |||
3361 | 346 | } | 340 | } |
3362 | 347 | 341 | ||
3363 | 348 | MOCK_CONST_METHOD0(renderable, std::shared_ptr<mir::graphics::Renderable>()); | 342 | MOCK_CONST_METHOD0(renderable, std::shared_ptr<mir::graphics::Renderable>()); |
3364 | 349 | MOCK_CONST_METHOD0(decoration, std::unique_ptr<mc::Decoration>()); | ||
3365 | 350 | MOCK_METHOD0(rendered, void()); | 343 | MOCK_METHOD0(rendered, void()); |
3366 | 351 | MOCK_METHOD0(occluded, void()); | 344 | MOCK_METHOD0(occluded, void()); |
3367 | 352 | }; | 345 | }; |
3368 | 353 | 346 | ||
3369 | === modified file 'tests/unit-tests/scene/test_basic_surface.cpp' | |||
3370 | --- tests/unit-tests/scene/test_basic_surface.cpp 2017-07-28 17:00:43 +0000 | |||
3371 | +++ tests/unit-tests/scene/test_basic_surface.cpp 2017-08-30 15:50:38 +0000 | |||
3372 | @@ -229,24 +229,10 @@ | |||
3373 | 229 | EXPECT_EQ(trans, got); | 229 | EXPECT_EQ(trans, got); |
3374 | 230 | } | 230 | } |
3375 | 231 | 231 | ||
3376 | 232 | TEST_F(BasicSurfaceTest, test_surface_set_alpha_notifies_changes) | ||
3377 | 233 | { | ||
3378 | 234 | using namespace testing; | ||
3379 | 235 | EXPECT_CALL(mock_callback, call()) | ||
3380 | 236 | .Times(1); | ||
3381 | 237 | |||
3382 | 238 | surface.add_observer(observer); | ||
3383 | 239 | |||
3384 | 240 | float alpha = 0.5f; | ||
3385 | 241 | surface.set_alpha(0.5f); | ||
3386 | 242 | EXPECT_THAT(alpha, FloatEq(surface.alpha())); | ||
3387 | 243 | } | ||
3388 | 244 | |||
3389 | 245 | TEST_F(BasicSurfaceTest, test_surface_is_opaque_by_default) | 232 | TEST_F(BasicSurfaceTest, test_surface_is_opaque_by_default) |
3390 | 246 | { | 233 | { |
3391 | 247 | using namespace testing; | 234 | using namespace testing; |
3392 | 248 | 235 | ||
3393 | 249 | EXPECT_THAT(1.0f, FloatEq(surface.alpha())); | ||
3394 | 250 | auto renderables = surface.generate_renderables(compositor_id); | 236 | auto renderables = surface.generate_renderables(compositor_id); |
3395 | 251 | ASSERT_THAT(renderables.size(), testing::Eq(1)); | 237 | ASSERT_THAT(renderables.size(), testing::Eq(1)); |
3396 | 252 | EXPECT_FALSE(renderables[0]->shaped()); | 238 | EXPECT_FALSE(renderables[0]->shaped()); |
3397 | 253 | 239 | ||
3398 | === modified file 'tests/unit-tests/scene/test_surface.cpp' | |||
3399 | --- tests/unit-tests/scene/test_surface.cpp 2017-07-28 17:00:43 +0000 | |||
3400 | +++ tests/unit-tests/scene/test_surface.cpp 2017-08-30 15:50:38 +0000 | |||
3401 | @@ -331,27 +331,6 @@ | |||
3402 | 331 | } | 331 | } |
3403 | 332 | } | 332 | } |
3404 | 333 | 333 | ||
3405 | 334 | TEST_F(SurfaceCreation, test_surface_set_alpha) | ||
3406 | 335 | { | ||
3407 | 336 | using namespace testing; | ||
3408 | 337 | |||
3409 | 338 | float alpha = 0.5f; | ||
3410 | 339 | |||
3411 | 340 | surface.set_alpha(alpha); | ||
3412 | 341 | EXPECT_FLOAT_EQ(alpha, surface.alpha()); | ||
3413 | 342 | auto renderables = surface.generate_renderables(nullptr); | ||
3414 | 343 | ASSERT_THAT(renderables.size(), Ge(1)); | ||
3415 | 344 | EXPECT_FLOAT_EQ(alpha, renderables[0]->alpha()); | ||
3416 | 345 | |||
3417 | 346 | alpha = 0.1; | ||
3418 | 347 | |||
3419 | 348 | surface.set_alpha(alpha); | ||
3420 | 349 | EXPECT_FLOAT_EQ(alpha, surface.alpha()); | ||
3421 | 350 | renderables = surface.generate_renderables(nullptr); | ||
3422 | 351 | ASSERT_THAT(renderables.size(), Ge(1)); | ||
3423 | 352 | EXPECT_FLOAT_EQ(alpha, renderables[0]->alpha()); | ||
3424 | 353 | } | ||
3425 | 354 | |||
3426 | 355 | TEST_F(SurfaceCreation, consume_calls_send_event) | 334 | TEST_F(SurfaceCreation, consume_calls_send_event) |
3427 | 356 | { | 335 | { |
3428 | 357 | using namespace testing; | 336 | using namespace testing; |
3429 | 358 | 337 | ||
3430 | === modified file 'tests/unit-tests/scene/test_surface_stack.cpp' | |||
3431 | --- tests/unit-tests/scene/test_surface_stack.cpp 2017-07-28 17:00:43 +0000 | |||
3432 | +++ tests/unit-tests/scene/test_surface_stack.cpp 2017-08-30 15:50:38 +0000 | |||
3433 | @@ -22,7 +22,6 @@ | |||
3434 | 22 | #include "mir/scene/observer.h" | 22 | #include "mir/scene/observer.h" |
3435 | 23 | #include "mir/scene/surface_creation_parameters.h" | 23 | #include "mir/scene/surface_creation_parameters.h" |
3436 | 24 | #include "mir/compositor/scene_element.h" | 24 | #include "mir/compositor/scene_element.h" |
3437 | 25 | #include "mir/compositor/decoration.h" | ||
3438 | 26 | #include "src/server/report/null_report_factory.h" | 25 | #include "src/server/report/null_report_factory.h" |
3439 | 27 | #include "src/server/scene/basic_surface.h" | 26 | #include "src/server/scene/basic_surface.h" |
3440 | 28 | #include "src/server/compositor/stream.h" | 27 | #include "src/server/compositor/stream.h" |
3441 | @@ -226,63 +225,6 @@ | |||
3442 | 226 | SceneElementForStream(stub_buffer_stream2))); | 225 | SceneElementForStream(stub_buffer_stream2))); |
3443 | 227 | } | 226 | } |
3444 | 228 | 227 | ||
3445 | 229 | TEST_F(SurfaceStack, decor_name_is_surface_name) | ||
3446 | 230 | { | ||
3447 | 231 | using namespace testing; | ||
3448 | 232 | |||
3449 | 233 | ms::SurfaceStack stack{report}; | ||
3450 | 234 | auto surface = std::make_shared<ms::BasicSurface>( | ||
3451 | 235 | std::string("Mary had a little lamb"), | ||
3452 | 236 | geom::Rectangle{{},{}}, | ||
3453 | 237 | mir_pointer_unconfined, | ||
3454 | 238 | std::list<ms::StreamInfo> { { std::make_shared<mtd::StubBufferStream>(), {}, {} } }, | ||
3455 | 239 | std::shared_ptr<mg::CursorImage>(), | ||
3456 | 240 | report); | ||
3457 | 241 | stack.add_surface(surface, default_params.input_mode); | ||
3458 | 242 | surface->configure(mir_window_attrib_visibility, | ||
3459 | 243 | mir_window_visibility_exposed); | ||
3460 | 244 | |||
3461 | 245 | auto elements = stack.scene_elements_for(compositor_id); | ||
3462 | 246 | ASSERT_EQ(1, elements.size()); | ||
3463 | 247 | |||
3464 | 248 | auto& element = elements.front(); | ||
3465 | 249 | |||
3466 | 250 | auto decor = element->decoration(); | ||
3467 | 251 | ASSERT_THAT(decor, Ne(nullptr)); | ||
3468 | 252 | EXPECT_EQ(mc::Decoration::Type::surface, decor->type); | ||
3469 | 253 | EXPECT_EQ("Mary had a little lamb", decor->name); | ||
3470 | 254 | } | ||
3471 | 255 | |||
3472 | 256 | TEST_F(SurfaceStack, gets_surface_renames) | ||
3473 | 257 | { | ||
3474 | 258 | using namespace testing; | ||
3475 | 259 | |||
3476 | 260 | ms::SurfaceStack stack{report}; | ||
3477 | 261 | auto surface = std::make_shared<ms::BasicSurface>( | ||
3478 | 262 | std::string("username@hostname: /"), | ||
3479 | 263 | geom::Rectangle{{},{}}, | ||
3480 | 264 | mir_pointer_unconfined, | ||
3481 | 265 | std::list<ms::StreamInfo> { { std::make_shared<mtd::StubBufferStream>(), {}, {} } }, | ||
3482 | 266 | std::shared_ptr<mg::CursorImage>(), | ||
3483 | 267 | report); | ||
3484 | 268 | stack.add_surface(surface, default_params.input_mode); | ||
3485 | 269 | surface->configure(mir_window_attrib_visibility, | ||
3486 | 270 | mir_window_visibility_exposed); | ||
3487 | 271 | |||
3488 | 272 | // (change directory in shell app) | ||
3489 | 273 | surface->rename("username@hostname: ~/Documents"); | ||
3490 | 274 | |||
3491 | 275 | auto elements = stack.scene_elements_for(compositor_id); | ||
3492 | 276 | ASSERT_EQ(1, elements.size()); | ||
3493 | 277 | |||
3494 | 278 | auto& element = elements.front(); | ||
3495 | 279 | |||
3496 | 280 | auto decor = element->decoration(); | ||
3497 | 281 | ASSERT_THAT(decor, Ne(nullptr)); | ||
3498 | 282 | EXPECT_EQ(mc::Decoration::Type::surface, decor->type); | ||
3499 | 283 | EXPECT_EQ("username@hostname: ~/Documents", decor->name); | ||
3500 | 284 | } | ||
3501 | 285 | |||
3502 | 286 | TEST_F(SurfaceStack, scene_counts_pending_accurately) | 228 | TEST_F(SurfaceStack, scene_counts_pending_accurately) |
3503 | 287 | { | 229 | { |
3504 | 288 | using namespace testing; | 230 | using namespace testing; |