Mir

Merge lp:~alan-griffiths/mir/move-miral-to-mir-cleanup-playground into lp:mir

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
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

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
=== modified file 'examples/miral-shell/CMakeLists.txt'
--- examples/miral-shell/CMakeLists.txt 2017-08-30 15:50:37 +0000
+++ examples/miral-shell/CMakeLists.txt 2017-08-30 15:50:38 +0000
@@ -1,70 +1,3 @@
1<<<<<<< TREE
2include_directories(
3 ${PROJECT_SOURCE_DIR}/include/miral
4 ${PROJECT_SOURCE_DIR}/include/client
5)
6
7add_subdirectory(spinner)
8add_subdirectory(desktop)
9
10add_custom_target(miral-run ALL
11 cp ${CMAKE_CURRENT_SOURCE_DIR}/miral-run.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/miral-run
12)
13
14install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/miral-run
15 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
16)
17
18add_custom_target(miral-xrun ALL
19 cp ${CMAKE_CURRENT_SOURCE_DIR}/miral-xrun.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/miral-xrun
20)
21
22install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/miral-xrun
23 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
24)
25
26add_custom_target(miral-screencast ALL
27 cp ${CMAKE_CURRENT_SOURCE_DIR}/miral-screencast.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/miral-screencast
28)
29
30install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/miral-screencast
31 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
32)
33
34add_custom_target(miral-desktop ALL
35 cp ${CMAKE_CURRENT_SOURCE_DIR}/miral-desktop.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/miral-desktop
36)
37
38install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/miral-desktop
39 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
40)
41
42add_custom_target(miral-app ALL
43 cp ${CMAKE_CURRENT_SOURCE_DIR}/miral-app.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/miral-app
44)
45
46install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/miral-app
47 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
48)
49
50mir_add_wrapped_executable(miral-shell
51 shell_main.cpp
52 tiling_window_manager.cpp tiling_window_manager.h
53 floating_window_manager.cpp floating_window_manager.h
54 decoration_provider.cpp decoration_provider.h
55 titlebar_config.cpp titlebar_config.h
56)
57
58pkg_check_modules(FREETYPE freetype2 REQUIRED)
59target_include_directories(miral-shell PRIVATE ${FREETYPE_INCLUDE_DIRS})
60target_compile_definitions(miral-shell PRIVATE -DTYPO_SUPPORTS_FREETYPE)
61target_link_libraries(miral-shell
62 miral-spinner
63 miral
64 ${FREETYPE_LIBRARIES}
65)
66
67=======
68include_directories(1include_directories(
69 ${PROJECT_SOURCE_DIR}/include/miral2 ${PROJECT_SOURCE_DIR}/include/miral
70 ${PROJECT_SOURCE_DIR}/include/client3 ${PROJECT_SOURCE_DIR}/include/client
@@ -134,4 +67,3 @@
134 miral67 miral
135)68)
13669
137>>>>>>> MERGE-SOURCE
13870
=== modified file 'include/miral/miral/command_line_option.h'
--- include/miral/miral/command_line_option.h 2017-08-30 15:50:37 +0000
+++ include/miral/miral/command_line_option.h 2017-08-30 15:50:38 +0000
@@ -1,114 +1,3 @@
1<<<<<<< TREE
2/*
3 * Copyright © 2016 Canonical Ltd.
4 *
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 or 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Alan Griffiths <alan@octopull.co.uk>
18 */
19
20#ifndef MIRAL_COMMAND_LINE_OPTION_H
21#define MIRAL_COMMAND_LINE_OPTION_H
22
23#include <mir/optional_value.h>
24
25#include <functional>
26#include <memory>
27#include <string>
28
29namespace mir { class Server; }
30
31namespace miral
32{
33/// Add a user configuration option to Mir's option handling.
34/// By default the callback will be invoked following Mir initialisation but
35/// prior to the server starting. The value supplied to the callback will come
36/// from the command line, environment variable, config file or the default.
37///
38/// \note Except for re-ordering implied by "pre_init()" the callbacks will be
39/// invoked in the order supplied.
40class CommandLineOption
41{
42public:
43 CommandLineOption(
44 std::function<void(int value)> callback,
45 std::string const& option,
46 std::string const& description,
47 int default_value);
48
49 CommandLineOption(
50 std::function<void(double value)> callback,
51 std::string const& option,
52 std::string const& description,
53 double default_value);
54
55 CommandLineOption(
56 std::function<void(std::string const& value)> callback,
57 std::string const& option,
58 std::string const& description,
59 std::string const& default_value);
60
61 CommandLineOption(
62 std::function<void(std::string const& value)> callback,
63 std::string const& option,
64 std::string const& description,
65 char const* default_value);
66
67 CommandLineOption(
68 std::function<void(bool value)> callback,
69 std::string const& option,
70 std::string const& description,
71 bool default_value);
72
73 CommandLineOption(
74 std::function<void(mir::optional_value<int> const& value)> callback,
75 std::string const& option,
76 std::string const& description);
77
78 CommandLineOption(
79 std::function<void(mir::optional_value<std::string> const& value)> callback,
80 std::string const& option,
81 std::string const& description);
82
83 CommandLineOption(
84 std::function<void(mir::optional_value<bool> const& value)> callback,
85 std::string const& option,
86 std::string const& description);
87
88 CommandLineOption(
89 std::function<void(bool is_set)> callback,
90 std::string const& option,
91 std::string const& description);
92
93 void operator()(mir::Server& server) const;
94
95 // Call the callback *before* Mir initialization starts
96 friend auto pre_init(CommandLineOption const& clo) -> CommandLineOption;
97
98 ~CommandLineOption();
99 CommandLineOption(CommandLineOption const&);
100 auto operator=(CommandLineOption const&) -> CommandLineOption&;
101
102private:
103 struct Self;
104 std::shared_ptr<Self> self;
105};
106
107auto pre_init(CommandLineOption const& clo) -> CommandLineOption;
108}
109
110#endif //MIRAL_COMMAND_LINE_OPTION_H
111=======
112/*1/*
113 * Copyright © 2016 Canonical Ltd.2 * Copyright © 2016 Canonical Ltd.
114 *3 *
@@ -223,4 +112,3 @@
223}112}
224113
225#endif //MIRAL_COMMAND_LINE_OPTION_H114#endif //MIRAL_COMMAND_LINE_OPTION_H
226>>>>>>> MERGE-SOURCE
227115
=== modified file 'include/miral/miral/window_management_policy_addendum3.h'
--- include/miral/miral/window_management_policy_addendum3.h 2017-08-30 15:50:37 +0000
+++ include/miral/miral/window_management_policy_addendum3.h 2017-08-30 15:50:38 +0000
@@ -1,73 +1,3 @@
1<<<<<<< TREE
2/*
3 * Copyright © 2017 Canonical Ltd.
4 *
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 or 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Alan Griffiths <alan@octopull.co.uk>
18 */
19
20#ifndef MIRAL_WINDOW_MANAGEMENT_POLICY_ADDENDUM3_H
21#define MIRAL_WINDOW_MANAGEMENT_POLICY_ADDENDUM3_H
22
23#include <mir_toolkit/client_types.h>
24
25#include <mir/geometry/rectangles.h>
26#include <mir_toolkit/mir_version_number.h>
27
28namespace miral
29{
30using namespace mir::geometry;
31struct WindowInfo;
32
33/**
34 * Handle additional client requests.
35 *
36 * \note This interface is intended to be implemented by a WindowManagementPolicy
37 * implementation, we can't add these functions directly to that interface without
38 * breaking ABI (the vtab could be incompatible).
39 * When initializing the window manager this interface will be detected by
40 * dynamic_cast and registered accordingly.
41 */
42class WindowManagementPolicyAddendum3
43{
44public:
45 /** Confirm (and optionally adjust) the placement of a window on the display.
46 * Called when (re)placing fullscreen, maximized, horizontally maximised and
47 * vertically maximized windows to allow adjustment for decorations.
48 *
49 * @param window_info the window
50 * @param new_placement the suggested placement
51 *
52 * @return the confirmed placement of the window
53 */
54 virtual auto confirm_placement_on_display(
55 WindowInfo const& window_info,
56 MirWindowState new_state,
57 Rectangle const& new_placement) -> Rectangle = 0;
58
59 virtual ~WindowManagementPolicyAddendum3() = default;
60 WindowManagementPolicyAddendum3() = default;
61 WindowManagementPolicyAddendum3(WindowManagementPolicyAddendum3 const&) = delete;
62 WindowManagementPolicyAddendum3& operator=(WindowManagementPolicyAddendum3 const&) = delete;
63};
64#if MIRAL_VERSION >= MIR_VERSION_NUMBER(2, 0, 0)
65#error "We've presumably broken ABI - please roll this interface into WindowManagementPolicy"
66#endif
67}
68
69#endif //MIRAL_WINDOW_MANAGEMENT_POLICY_ADDENDUM3_H
70=======
71/*1/*
72 * Copyright © 2017 Canonical Ltd.2 * Copyright © 2017 Canonical Ltd.
73 *3 *
@@ -137,4 +67,3 @@
137}67}
13868
139#endif //MIRAL_WINDOW_MANAGEMENT_POLICY_ADDENDUM3_H69#endif //MIRAL_WINDOW_MANAGEMENT_POLICY_ADDENDUM3_H
140>>>>>>> MERGE-SOURCE
14170
=== modified file 'include/server/mir/compositor/scene_element.h'
--- include/server/mir/compositor/scene_element.h 2017-07-28 17:00:43 +0000
+++ include/server/mir/compositor/scene_element.h 2017-08-30 15:50:38 +0000
@@ -39,10 +39,6 @@
39 virtual void rendered() = 0;39 virtual void rendered() = 0;
40 virtual void occluded() = 0;40 virtual void occluded() = 0;
4141
42 //TODO: Decoration is opaque on purpose. It is only used by an internal example,
43 // and this function should be removed from the public API.
44 virtual std::unique_ptr<Decoration> decoration() const = 0;
45
46protected:42protected:
47 SceneElement() = default;43 SceneElement() = default;
48 SceneElement(SceneElement const&) = delete;44 SceneElement(SceneElement const&) = delete;
4945
=== modified file 'include/server/mir/scene/surface.h'
--- include/server/mir/scene/surface.h 2017-07-28 17:00:43 +0000
+++ include/server/mir/scene/surface.h 2017-08-30 15:50:38 +0000
@@ -66,7 +66,6 @@
66 virtual graphics::RenderableList generate_renderables(compositor::CompositorID id) const = 0; 66 virtual graphics::RenderableList generate_renderables(compositor::CompositorID id) const = 0;
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;
6868
69 virtual float alpha() const = 0; //only used in examples/
70 virtual MirWindowType type() const = 0;69 virtual MirWindowType type() const = 0;
71 virtual MirWindowState state() const = 0;70 virtual MirWindowState state() const = 0;
72 virtual void hide() = 0;71 virtual void hide() = 0;
7372
=== modified file 'include/test/mir/test/doubles/stub_surface.h'
--- include/test/mir/test/doubles/stub_surface.h 2017-07-28 17:00:43 +0000
+++ include/test/mir/test/doubles/stub_surface.h 2017-08-30 15:50:38 +0000
@@ -32,7 +32,6 @@
32{32{
33 std::string name() const override;33 std::string name() const override;
34 void move_to(geometry::Point const& top_left) override;34 void move_to(geometry::Point const& top_left) override;
35 float alpha() const override;
36 geometry::Size size() const override;35 geometry::Size size() const override;
37 geometry::Size client_size() const override;36 geometry::Size client_size() const override;
38 std::shared_ptr<frontend::BufferStream> primary_buffer_stream() const override;37 std::shared_ptr<frontend::BufferStream> primary_buffer_stream() const override;
3938
=== modified file 'playground/CMakeLists.txt'
--- playground/CMakeLists.txt 2017-08-30 15:50:37 +0000
+++ playground/CMakeLists.txt 2017-08-30 15:50:38 +0000
@@ -1,27 +1,6 @@
1
2include_directories(1include_directories(
3 ${PROJECT_SOURCE_DIR}/src/include/server
4 ${PROJECT_SOURCE_DIR}/src/include/platform
5 ${PROJECT_SOURCE_DIR}/src/include/common
6 ${PROJECT_SOURCE_DIR}/src/include/gl
7 ${PROJECT_SOURCE_DIR}/src/include/client
8 ${PROJECT_SOURCE_DIR}/src/renderers
9 ${PROJECT_SOURCE_DIR}/include/client2 ${PROJECT_SOURCE_DIR}/include/client
10 ${PROJECT_SOURCE_DIR}/include/server3)
11 ${PROJECT_SOURCE_DIR}/include/platform
12 ${PROJECT_SOURCE_DIR}/include/renderer
13 ${PROJECT_SOURCE_DIR}/include/renderers/gl
14 ${PROJECT_SOURCE_DIR}/examples/
15)
16
17add_library(playgroundserverconfig STATIC
18 server_configuration.cpp
19 server_example_display_configuration_policy.cpp
20)
21
22add_subdirectory(demo-shell/)
23
24set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
254
26mir_add_wrapped_executable(mir_demo_client_egldiamond_render_surface5mir_add_wrapped_executable(mir_demo_client_egldiamond_render_surface
27 egldiamond_render_surface.c6 egldiamond_render_surface.c
287
=== removed directory 'playground/demo-shell'
=== removed file 'playground/demo-shell/CMakeLists.txt'
--- playground/demo-shell/CMakeLists.txt 2017-05-08 03:04:26 +0000
+++ playground/demo-shell/CMakeLists.txt 1970-01-01 00:00:00 +0000
@@ -1,19 +0,0 @@
1add_library(demo-shell STATIC
2 demo_compositor.cpp
3 demo_renderer.cpp
4 window_manager.cpp
5)
6
7add_subdirectory(typo)
8target_link_libraries(demo-shell typo)
9
10mir_add_wrapped_executable(mir_proving_server
11 demo_shell.cpp
12)
13
14target_link_libraries(mir_proving_server
15 demo-shell
16 mirserver
17 playgroundserverconfig
18 exampleserverconfig
19)
200
=== removed file 'playground/demo-shell/demo_compositor.cpp'
--- playground/demo-shell/demo_compositor.cpp 2017-07-28 17:00:43 +0000
+++ playground/demo-shell/demo_compositor.cpp 1970-01-01 00:00:00 +0000
@@ -1,204 +0,0 @@
1/*
2 * Copyright © 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 or 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
17 */
18
19#include "mir/graphics/display_buffer.h"
20#include "mir/compositor/compositor_report.h"
21#include "mir/compositor/scene_element.h"
22#include "demo_compositor.h"
23
24namespace me = mir::examples;
25namespace mg = mir::graphics;
26namespace mc = mir::compositor;
27namespace geom = mir::geometry;
28
29std::mutex me::DemoCompositor::instances_mutex;
30std::unordered_set<me::DemoCompositor*> me::DemoCompositor::instances;
31
32me::DemoCompositor::DemoCompositor(
33 mg::DisplayBuffer& display_buffer,
34 std::shared_ptr<mc::CompositorReport> const& report) :
35 display_buffer(display_buffer),
36 report(report),
37 viewport(display_buffer.view_area()),
38 zoom_mag{1.0f},
39 renderer(
40 display_buffer,
41 30.0f, //titlebar_height
42 80.0f) //shadow_radius
43{
44 std::lock_guard<std::mutex> lock(instances_mutex);
45 instances.insert(this);
46}
47
48me::DemoCompositor::~DemoCompositor()
49{
50 std::lock_guard<std::mutex> lock(instances_mutex);
51 instances.erase(this);
52}
53
54void me::DemoCompositor::for_each(std::function<void(DemoCompositor&)> f)
55{
56 std::lock_guard<std::mutex> lock(instances_mutex);
57 for (auto& i : instances)
58 f(*i);
59}
60
61void me::DemoCompositor::composite(mc::SceneElementSequence&& elements)
62{
63 report->began_frame(this);
64 //a simple filtering out of renderables that shouldn't be drawn
65 //the elements should be notified if they are rendered or not
66 bool nonrenderlist_elements{false};
67 mg::RenderableList renderable_list;
68 DecorMap decorated;
69
70 for(auto const& it : elements)
71 {
72 auto const& renderable = it->renderable();
73
74 bool embellished = false;
75 if (auto decor = it->decoration())
76 {
77 embellished = decor->type != mc::Decoration::Type::none;
78 decorated[renderable->id()] = std::move(decor);
79 }
80
81 if (embellished || viewport.overlaps(renderable->screen_position()))
82 {
83 renderable_list.push_back(renderable);
84
85 /*
86 * TODO: This logic could be replaced more cleanly in future by
87 * the surface stack logic setting decoration status more
88 * accurately for fullscreen surfaces.
89 */
90 // Fullscreen and opaque? Definitely no embellishment
91 if (renderable->screen_position() == viewport &&
92 renderable->alpha() == 1.0f &&
93 !renderable->shaped() &&
94 renderable->transformation() == glm::mat4())
95 {
96 embellished = false;
97 nonrenderlist_elements = false; // Don't care what's underneath
98 }
99
100 it->rendered();
101 }
102 else
103 {
104 it->occluded();
105 }
106 nonrenderlist_elements |= embellished;
107 }
108
109 /*
110 * Note: Buffer lifetimes are ensured by the two objects holding
111 * references to them; elements and renderable_list.
112 * So no buffer is going to be released back to the client till
113 * both of those containers get destroyed (end of the function).
114 * Actually, there's a third reference held by the texture cache
115 * in GLRenderer, but that gets released earlier in render().
116 */
117 elements.clear(); // Release those that didn't make it to renderable_list
118
119 if (!nonrenderlist_elements &&
120 viewport == display_buffer.view_area() && // no bypass while zoomed
121 display_buffer.overlay(renderable_list))
122 {
123 report->renderables_in_frame(this, renderable_list);
124 renderer.suspend();
125 }
126 else
127 {
128 renderer.set_output_transform(display_buffer.transformation());
129 update_viewport();
130 renderer.set_viewport(viewport);
131 renderer.begin(std::move(decorated));
132 renderer.render(renderable_list);
133
134 report->renderables_in_frame(this, renderable_list);
135 report->rendered_frame(this);
136
137 // Release buffers back to the clients now that the swap has returned.
138 // It's important to do this before starting on the potentially slow
139 // flip() ...
140 // FIXME: This clear() call is blocking a little (LP: #1395421)
141 renderable_list.clear();
142 }
143
144 report->finished_frame(this);
145}
146
147void me::DemoCompositor::on_cursor_movement(
148 geometry::Point const& p)
149{
150 cursor_pos = p;
151 if (zoom_mag != 1.0f)
152 update_viewport();
153}
154
155void me::DemoCompositor::zoom(float mag)
156{
157 zoom_mag = mag;
158 update_viewport();
159}
160
161void me::DemoCompositor::set_colour_effect(me::ColourEffect e)
162{
163 renderer.set_colour_effect(e);
164}
165
166void me::DemoCompositor::update_viewport()
167{
168 auto const& view_area = display_buffer.view_area();
169
170 if (zoom_mag == 1.0f)
171 {
172 // The below calculations should yield the same result as this, but
173 // just in case there are any floating point precision errors,
174 // set it precisely:
175 viewport = view_area;
176 }
177 else
178 {
179 int db_width = view_area.size.width.as_int();
180 int db_height = view_area.size.height.as_int();
181 int db_x = view_area.top_left.x.as_int();
182 int db_y = view_area.top_left.y.as_int();
183
184 float zoom_width = db_width / zoom_mag;
185 float zoom_height = db_height / zoom_mag;
186
187 // Note the 0.5f. This is because cursors (and all input in general)
188 // measures coordinates at the centre of a pixel. But GL measures to
189 // the top-left corner of a pixel.
190 float screen_x = cursor_pos.x.as_int() + 0.5f - db_x;
191 float screen_y = cursor_pos.y.as_int() + 0.5f - db_y;
192
193 float normal_x = screen_x / db_width;
194 float normal_y = screen_y / db_height;
195
196 // Position the viewport so the cursor location matches up.
197 // This assumes the hardware cursor still traverses the physical
198 // screen and isn't being warped.
199 int zoom_x = db_x + (db_width - zoom_width) * normal_x;
200 int zoom_y = db_y + (db_height - zoom_height) * normal_y;
201
202 viewport = {{zoom_x, zoom_y}, {zoom_width, zoom_height}};
203 }
204}
2050
=== removed file 'playground/demo-shell/demo_compositor.h'
--- playground/demo-shell/demo_compositor.h 2017-07-28 17:00:43 +0000
+++ playground/demo-shell/demo_compositor.h 1970-01-01 00:00:00 +0000
@@ -1,79 +0,0 @@
1/*
2 * Copyright © 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 or 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
17 */
18
19#ifndef MIR_EXAMPLES_DEMO_COMPOSITOR_H_
20#define MIR_EXAMPLES_DEMO_COMPOSITOR_H_
21
22#include "mir/compositor/display_buffer_compositor.h"
23#include "mir/compositor/scene.h"
24#include "mir/geometry/rectangle.h"
25#include "mir/graphics/renderable.h"
26#include "demo_renderer.h"
27
28#include <mutex>
29#include <set>
30
31namespace mir
32{
33namespace compositor
34{
35class Scene;
36class CompositorReport;
37}
38namespace graphics
39{
40class DisplayBuffer;
41}
42namespace examples
43{
44
45class DemoCompositor : public compositor::DisplayBufferCompositor
46{
47public:
48 DemoCompositor(
49 graphics::DisplayBuffer& display_buffer,
50 std::shared_ptr<compositor::CompositorReport> const& report);
51 ~DemoCompositor();
52
53 void composite(compositor::SceneElementSequence&& elements) override;
54
55 void zoom(float mag);
56 void on_cursor_movement(geometry::Point const& p);
57
58 void set_colour_effect(ColourEffect);
59
60 static void for_each(std::function<void(DemoCompositor&)> f);
61
62private:
63 void update_viewport();
64
65 graphics::DisplayBuffer& display_buffer;
66 std::shared_ptr<compositor::CompositorReport> const report;
67 geometry::Rectangle viewport;
68 geometry::Point cursor_pos;
69 float zoom_mag;
70 DemoRenderer renderer;
71
72 static std::mutex instances_mutex;
73 static std::unordered_set<DemoCompositor*> instances;
74};
75
76} // namespace examples
77} // namespace mir
78
79#endif // MIR_EXAMPLES_DEMO_COMPOSITOR_H_
800
=== removed file 'playground/demo-shell/demo_renderer.cpp'
--- playground/demo-shell/demo_renderer.cpp 2017-07-28 17:00:43 +0000
+++ playground/demo-shell/demo_renderer.cpp 1970-01-01 00:00:00 +0000
@@ -1,402 +0,0 @@
1/*
2 * Copyright © 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 or 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com>
17 */
18
19#define MIR_LOG_COMPONENT "DemoRenderer"
20
21#include "typo_stub_renderer.h"
22#ifdef TYPO_SUPPORTS_FREETYPE
23#include "typo_freetype_renderer.h"
24#endif
25#include "demo_renderer.h"
26#include <mir/graphics/renderable.h>
27#include <mir/log.h>
28#include <cmath>
29
30using namespace mir;
31using namespace mir::examples;
32using namespace mir::geometry;
33using namespace mir::compositor;
34using namespace mir::renderer;
35
36namespace
37{
38
39struct Color
40{
41 GLubyte r, g, b, a;
42};
43
44float penumbra_curve(float x)
45{
46 return 1.0f - std::sin(x * M_PI / 2.0f);
47}
48
49GLuint generate_shadow_corner_texture(float opacity)
50{
51 struct Texel
52 {
53 GLubyte luminance;
54 GLubyte alpha;
55 };
56
57 int const width = 256;
58 Texel image[width][width];
59
60 int const max = width - 1;
61 for (int y = 0; y < width; ++y)
62 {
63 float curve_y = opacity * 255.0f *
64 penumbra_curve(static_cast<float>(y) / max);
65 for (int x = 0; x < width; ++x)
66 {
67 Texel *t = &image[y][x];
68 t->luminance = 0;
69 t->alpha = curve_y * penumbra_curve(static_cast<float>(x) / max);
70 }
71 }
72
73 GLuint corner;
74 glGenTextures(1, &corner);
75 glBindTexture(GL_TEXTURE_2D, corner);
76 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
77 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
78 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
79 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
80 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA,
81 width, width, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE,
82 image);
83
84 return corner;
85}
86
87GLuint generate_frame_corner_texture(float corner_radius,
88 Color const& color,
89 GLubyte highlight)
90{
91 int const height = 256;
92/*
93 * GCC 4.9 with optimizations enabled will generate armhf NEON/VFP instructions
94 * here that are not understood/implemented by Valgrind (but are by hardware),
95 * causing Valgrind to crash:
96 * eebe 0acc vcvt.s32.f32 s0, s0, #8
97 * So this clumsy expression below tricks the compiler into not using those
98 * optimized ARM instructions that Valgrind doesn't support yet:
99 */
100 int const width = height / (1.0f / corner_radius);
101 Color image[height * height]; // Worst case still much faster than the heap
102
103 int const cx = width;
104 int const cy = cx;
105 int const radius_sqr = cx * cy;
106
107 for (int y = 0; y < height; ++y)
108 {
109 for (int x = 0; x < width; ++x)
110 {
111 Color col = color;
112
113 // Set gradient
114 if (y < cy)
115 {
116 float brighten = (1.0f - (static_cast<float>(y) / cy)) *
117 std::sin(x * M_PI / (2 * (width - 1)));
118
119 col.r += (highlight - col.r) * brighten;
120 col.g += (highlight - col.g) * brighten;
121 col.b += (highlight - col.b) * brighten;
122 }
123
124 // Cut out the corner in a circular shape.
125 if (x < cx && y < cy)
126 {
127 int dx = cx - x;
128 int dy = cy - y;
129 if (dx * dx + dy * dy >= radius_sqr)
130 col = {0, 0, 0, 0};
131 }
132
133 image[y * width + x] = col;
134 }
135 }
136
137 GLuint corner;
138 glGenTextures(1, &corner);
139 glBindTexture(GL_TEXTURE_2D, corner);
140 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
141 GL_LINEAR_MIPMAP_LINEAR);
142 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
143 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
144 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
145 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
146 width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
147 image);
148 glGenerateMipmap(GL_TEXTURE_2D); // Antialiasing please
149
150 return corner;
151}
152
153static const GLchar inverse_fshader[] =
154{
155 "#ifdef GL_ES\n"
156 "precision mediump float;\n"
157 "#endif\n"
158 "uniform sampler2D tex;\n"
159 "uniform float alpha;\n"
160 "varying vec2 v_texcoord;\n"
161 "void main() {\n"
162 " vec4 f = texture2D(tex, v_texcoord);\n"
163 " vec3 inverted = (vec3(1.0) - (f.rgb / f.a)) * f.a;\n"
164 " gl_FragColor = alpha*vec4(inverted, f.a);\n"
165 "}\n"
166};
167static const GLchar contrast_fshader[] =
168{
169 "#ifdef GL_ES\n"
170 "precision mediump float;\n"
171 "#endif\n"
172 "uniform sampler2D tex;\n"
173 "uniform float alpha;\n"
174 "varying vec2 v_texcoord;\n"
175 "void main() {\n"
176 " vec4 raw = texture2D(tex, v_texcoord);\n"
177 " vec3 bent = (1.0 - cos(raw.rgb * 3.141592654)) / 2.0;\n"
178 " gl_FragColor = alpha * vec4(bent, raw.a);\n"
179 "}\n"
180};
181
182} // namespace
183
184DemoRenderer::DemoRenderer(
185 graphics::DisplayBuffer& display_buffer,
186 float const titlebar_height,
187 float const shadow_radius) :
188 renderer::gl::Renderer(display_buffer),
189 titlebar_height{titlebar_height},
190 shadow_radius{shadow_radius},
191 corner_radius{0.5f},
192 colour_effect{none},
193 inverse_program(family.add_program(vshader, inverse_fshader)),
194 contrast_program(family.add_program(vshader, contrast_fshader)),
195 title_cache(std::make_shared<typo::StubRenderer>())
196{
197 shadow_corner_tex = generate_shadow_corner_texture(0.4f);
198 titlebar_corner_tex = generate_frame_corner_texture(corner_radius,
199 {128,128,128,255},
200 255);
201
202 clear_color[0] = clear_color[1] = clear_color[2] = 0.2f;
203 clear_color[3] = 1.0f;
204
205#ifdef TYPO_SUPPORTS_FREETYPE
206 const char title_font_path[] = "/usr/share/fonts/truetype/liberation/LiberationSans-Bold.ttf";
207 auto ftrenderer = std::make_shared<typo::FreetypeRenderer>();
208 if (ftrenderer->load(title_font_path, 128))
209 title_cache.change_renderer(ftrenderer);
210 else
211 mir::log_error("Failed to load titlebar font: %s", title_font_path);
212#endif
213}
214
215DemoRenderer::~DemoRenderer()
216{
217 glDeleteTextures(1, &shadow_corner_tex);
218 glDeleteTextures(1, &titlebar_corner_tex);
219}
220
221void DemoRenderer::begin(DecorMap&& d) const
222{
223 decor_map = std::move(d);
224 title_cache.drop_unused();
225 title_cache.mark_all_unused();
226}
227
228void DemoRenderer::tessellate(std::vector<gl::Primitive>& primitives,
229 graphics::Renderable const& renderable) const
230{
231 renderer::gl::Renderer::tessellate(primitives, renderable);
232 auto d = decor_map.find(renderable.id());
233 if (d != decor_map.end())
234 {
235 auto& decor = d->second;
236 if (decor->type != Decoration::Type::none)
237 {
238 tessellate_shadow(primitives, renderable, shadow_radius);
239 tessellate_frame(primitives, renderable, titlebar_height,
240 decor->name.c_str());
241 }
242 }
243}
244
245void DemoRenderer::tessellate_shadow(std::vector<gl::Primitive>& primitives,
246 graphics::Renderable const& renderable,
247 float radius) const
248{
249 auto const& rect = renderable.screen_position();
250 GLfloat left = rect.top_left.x.as_int();
251 GLfloat right = left + rect.size.width.as_int();
252 GLfloat top = rect.top_left.y.as_int();
253 GLfloat bottom = top + rect.size.height.as_int();
254
255 auto n = primitives.size();
256 primitives.resize(n + 8);
257
258 GLfloat rightr = right + radius;
259 GLfloat leftr = left - radius;
260 GLfloat topr = top - radius;
261 GLfloat bottomr = bottom + radius;
262
263 auto& right_shadow = primitives[n++];
264 right_shadow.tex_id = shadow_corner_tex;
265 right_shadow.vertices[0] = {{right, top, 0.0f}, {0.0f, 0.0f}};
266 right_shadow.vertices[1] = {{rightr, top, 0.0f}, {1.0f, 0.0f}};
267 right_shadow.vertices[2] = {{rightr, bottom, 0.0f}, {1.0f, 0.0f}};
268 right_shadow.vertices[3] = {{right, bottom, 0.0f}, {0.0f, 0.0f}};
269
270 auto& left_shadow = primitives[n++];
271 left_shadow.tex_id = shadow_corner_tex;
272 left_shadow.vertices[0] = {{leftr, top, 0.0f}, {1.0f, 0.0f}};
273 left_shadow.vertices[1] = {{left, top, 0.0f}, {0.0f, 0.0f}};
274 left_shadow.vertices[2] = {{left, bottom, 0.0f}, {0.0f, 0.0f}};
275 left_shadow.vertices[3] = {{leftr, bottom, 0.0f}, {1.0f, 0.0f}};
276
277 auto& top_shadow = primitives[n++];
278 top_shadow.tex_id = shadow_corner_tex;
279 top_shadow.vertices[0] = {{left, topr, 0.0f}, {1.0f, 0.0f}};
280 top_shadow.vertices[1] = {{right, topr, 0.0f}, {1.0f, 0.0f}};
281 top_shadow.vertices[2] = {{right, top, 0.0f}, {0.0f, 0.0f}};
282 top_shadow.vertices[3] = {{left, top, 0.0f}, {0.0f, 0.0f}};
283
284 auto& bottom_shadow = primitives[n++];
285 bottom_shadow.tex_id = shadow_corner_tex;
286 bottom_shadow.vertices[0] = {{left, bottom, 0.0f}, {0.0f, 0.0f}};
287 bottom_shadow.vertices[1] = {{right, bottom, 0.0f}, {0.0f, 0.0f}};
288 bottom_shadow.vertices[2] = {{right, bottomr, 0.0f}, {1.0f, 0.0f}};
289 bottom_shadow.vertices[3] = {{left, bottomr, 0.0f}, {1.0f, 0.0f}};
290
291 auto& tr_shadow = primitives[n++];
292 tr_shadow.tex_id = shadow_corner_tex;
293 tr_shadow.vertices[0] = {{right, top, 0.0f}, {0.0f, 0.0f}};
294 tr_shadow.vertices[1] = {{right, topr, 0.0f}, {1.0f, 0.0f}};
295 tr_shadow.vertices[2] = {{rightr, topr, 0.0f}, {1.0f, 1.0f}};
296 tr_shadow.vertices[3] = {{rightr, top, 0.0f}, {0.0f, 1.0f}};
297
298 auto& br_shadow = primitives[n++];
299 br_shadow.tex_id = shadow_corner_tex;
300 br_shadow.vertices[0] = {{right, bottom, 0.0f}, {0.0f, 0.0f}};
301 br_shadow.vertices[1] = {{rightr, bottom, 0.0f}, {1.0f, 0.0f}};
302 br_shadow.vertices[2] = {{rightr, bottomr, 0.0f}, {1.0f, 1.0f}};
303 br_shadow.vertices[3] = {{right, bottomr, 0.0f}, {0.0f, 1.0f}};
304
305 auto& bl_shadow = primitives[n++];
306 bl_shadow.tex_id = shadow_corner_tex;
307 bl_shadow.vertices[0] = {{left, bottom, 0.0f}, {0.0f, 0.0f}};
308 bl_shadow.vertices[1] = {{left, bottomr, 0.0f}, {1.0f, 0.0f}};
309 bl_shadow.vertices[2] = {{leftr, bottomr, 0.0f}, {1.0f, 1.0f}};
310 bl_shadow.vertices[3] = {{leftr, bottom, 0.0f}, {0.0f, 1.0f}};
311
312 auto& tl_shadow = primitives[n++];
313 tl_shadow.tex_id = shadow_corner_tex;
314 tl_shadow.vertices[0] = {{left, top, 0.0f}, {0.0f, 0.0f}};
315 tl_shadow.vertices[1] = {{leftr, top, 0.0f}, {1.0f, 0.0f}};
316 tl_shadow.vertices[2] = {{leftr, topr, 0.0f}, {1.0f, 1.0f}};
317 tl_shadow.vertices[3] = {{left, topr, 0.0f}, {0.0f, 1.0f}};
318}
319
320void DemoRenderer::tessellate_frame(std::vector<gl::Primitive>& primitives,
321 graphics::Renderable const& renderable,
322 float titlebar_height,
323 char const* name) const
324{
325 auto const& rect = renderable.screen_position();
326 GLfloat left = rect.top_left.x.as_int();
327 GLfloat right = left + rect.size.width.as_int();
328 GLfloat top = rect.top_left.y.as_int();
329
330 auto n = primitives.size();
331 primitives.resize(n + 4);
332
333 GLfloat htop = top - titlebar_height;
334 GLfloat in = titlebar_height * corner_radius;
335 GLfloat inleft = left + in;
336 GLfloat inright = right - in;
337
338 GLfloat mid = (left + right) / 2.0f;
339 if (inleft > mid) inleft = mid;
340 if (inright < mid) inright = mid;
341
342 auto& top_left_corner = primitives[n++];
343 top_left_corner.tex_id = titlebar_corner_tex;
344 top_left_corner.vertices[0] = {{left, htop, 0.0f}, {0.0f, 0.0f}};
345 top_left_corner.vertices[1] = {{inleft, htop, 0.0f}, {1.0f, 0.0f}};
346 top_left_corner.vertices[2] = {{inleft, top, 0.0f}, {1.0f, 1.0f}};
347 top_left_corner.vertices[3] = {{left, top, 0.0f}, {0.0f, 1.0f}};
348
349 auto& top_right_corner = primitives[n++];
350 top_right_corner.tex_id = titlebar_corner_tex;
351 top_right_corner.vertices[0] = {{inright, htop, 0.0f}, {1.0f, 0.0f}};
352 top_right_corner.vertices[1] = {{right, htop, 0.0f}, {0.0f, 0.0f}};
353 top_right_corner.vertices[2] = {{right, top, 0.0f}, {0.0f, 1.0f}};
354 top_right_corner.vertices[3] = {{inright, top, 0.0f}, {1.0f, 1.0f}};
355
356 auto& titlebar = primitives[n++];
357 titlebar.tex_id = titlebar_corner_tex;
358 titlebar.vertices[0] = {{inleft, htop, 0.0f}, {1.0f, 0.0f}};
359 titlebar.vertices[1] = {{inright, htop, 0.0f}, {1.0f, 0.0f}};
360 titlebar.vertices[2] = {{inright, top, 0.0f}, {1.0f, 1.0f}};
361 titlebar.vertices[3] = {{inleft, top, 0.0f}, {1.0f, 1.0f}};
362
363 auto str = title_cache.get(name);
364 GLfloat text_vin = titlebar_height / 5;
365 GLfloat text_top = htop + text_vin;
366 GLfloat text_bot = top - text_vin;
367 GLfloat text_height = text_bot - text_top;
368 GLfloat text_scale = text_height / str.height;
369 GLfloat text_left = inleft;
370 GLfloat text_right = text_left + text_scale * str.width;
371 GLfloat text_u = 1.0f;
372 if (text_right > inright) // Title too long for window
373 {
374 text_u = (inright - text_left) / (text_right - text_left);
375 text_right = inright;
376 }
377
378 auto& text_prim = primitives[n++];
379 text_prim.tex_id = str.tex;
380 text_prim.vertices[0] = {{text_left, text_top, 0.0f}, {0.0f, 0.0f}};
381 text_prim.vertices[1] = {{text_right, text_top, 0.0f}, {text_u, 0.0f}};
382 text_prim.vertices[2] = {{text_right, text_bot, 0.0f}, {text_u, 1.0f}};
383 text_prim.vertices[3] = {{text_left, text_bot, 0.0f}, {0.0f, 1.0f}};
384}
385
386void DemoRenderer::set_colour_effect(ColourEffect e)
387{
388 colour_effect = e;
389}
390
391void DemoRenderer::draw(graphics::Renderable const& renderable,
392 renderer::gl::Renderer::Program const& current_program) const
393{
394 const renderer::gl::Renderer::Program* const programs[ColourEffect::neffects] =
395 {
396 &current_program,
397 &inverse_program,
398 &contrast_program
399 };
400
401 renderer::gl::Renderer::draw(renderable, *programs[colour_effect]);
402}
4030
=== removed file 'playground/demo-shell/demo_renderer.h'
--- playground/demo-shell/demo_renderer.h 2017-07-28 17:00:43 +0000
+++ playground/demo-shell/demo_renderer.h 1970-01-01 00:00:00 +0000
@@ -1,90 +0,0 @@
1/*
2 * Copyright © 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 or 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com>
17 */
18
19#ifndef MIR_EXAMPLES_DEMO_RENDERER_H_
20#define MIR_EXAMPLES_DEMO_RENDERER_H_
21
22#include "gl/renderer.h"
23#include "mir/compositor/decoration.h"
24#include "typo_glcache.h"
25
26#include <unordered_map>
27
28namespace mir
29{
30namespace examples
31{
32
33enum ColourEffect
34{
35 none,
36 inverse,
37 contrast,
38 neffects
39};
40
41typedef std::unordered_map<graphics::Renderable::ID,
42 std::unique_ptr<compositor::Decoration>> DecorMap;
43
44class DemoRenderer : public renderer::gl::Renderer
45{
46public:
47 DemoRenderer(
48 graphics::DisplayBuffer& display_buffer,
49 float const titlebar_height,
50 float const shadow_radius);
51 ~DemoRenderer();
52
53 void begin(DecorMap&&) const;
54 void set_colour_effect(ColourEffect);
55
56protected:
57 void tessellate(std::vector<gl::Primitive>& primitives,
58 graphics::Renderable const& renderable) const override;
59
60 void draw(graphics::Renderable const& renderable,
61 Renderer::Program const& prog) const override;
62
63private:
64 void tessellate_shadow(
65 std::vector<gl::Primitive>& primitives,
66 graphics::Renderable const& renderable,
67 float radius) const;
68 void tessellate_frame(
69 std::vector<gl::Primitive>& primitives,
70 graphics::Renderable const& renderable,
71 float titlebar_height,
72 char const* name) const;
73
74 float const titlebar_height;
75 float const shadow_radius;
76 float const corner_radius;
77 GLuint shadow_corner_tex;
78 GLuint titlebar_corner_tex;
79
80 ColourEffect colour_effect;
81 Program inverse_program, contrast_program;
82
83 mutable DecorMap decor_map;
84 mutable typo::GLCache title_cache;
85};
86
87} // namespace examples
88} // namespace mir
89
90#endif // MIR_EXAMPLES_DEMO_RENDERER_H_
910
=== removed file 'playground/demo-shell/demo_shell.cpp'
--- playground/demo-shell/demo_shell.cpp 2017-07-28 17:00:43 +0000
+++ playground/demo-shell/demo_shell.cpp 1970-01-01 00:00:00 +0000
@@ -1,120 +0,0 @@
1/*
2 * Copyright © 2013-2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 or 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Robert Carr <robert.carr@canonical.com>
17 */
18
19/// \example demo_shell.cpp A simple mir shell
20
21#include "demo_compositor.h"
22#include "window_manager.h"
23#include "../server_configuration.h"
24
25#include "mir/run_mir.h"
26#include "mir/report_exception.h"
27#include "mir/graphics/display.h"
28#include "mir/input/composite_event_filter.h"
29#include "mir/compositor/display_buffer_compositor_factory.h"
30#include "mir/renderer/renderer_factory.h"
31#include "mir/options/option.h"
32#include "server_example_host_lifecycle_event_listener.h"
33
34#include <iostream>
35
36namespace me = mir::examples;
37namespace ms = mir::scene;
38namespace mg = mir::graphics;
39namespace mf = mir::frontend;
40namespace mi = mir::input;
41namespace mc = mir::compositor;
42namespace msh = mir::shell;
43
44namespace mir
45{
46namespace examples
47{
48class DisplayBufferCompositorFactory : public mc::DisplayBufferCompositorFactory
49{
50public:
51 DisplayBufferCompositorFactory(
52 std::shared_ptr<mc::CompositorReport> const& report) :
53 report(report)
54 {
55 }
56
57 std::unique_ptr<mc::DisplayBufferCompositor> create_compositor_for(
58 mg::DisplayBuffer& display_buffer) override
59 {
60 return std::unique_ptr<mc::DisplayBufferCompositor>(
61 new me::DemoCompositor{display_buffer, report});
62 }
63
64private:
65 std::shared_ptr<mc::CompositorReport> const report;
66};
67
68class DemoServerConfiguration : public mir::examples::ServerConfiguration
69{
70public:
71 using mir::examples::ServerConfiguration::ServerConfiguration;
72
73 std::shared_ptr<compositor::DisplayBufferCompositorFactory> the_display_buffer_compositor_factory() override
74 {
75 return display_buffer_compositor_factory(
76 [this]()
77 {
78 return std::make_shared<me::DisplayBufferCompositorFactory>(
79 the_compositor_report());
80 });
81 }
82
83 std::shared_ptr<msh::HostLifecycleEventListener> the_host_lifecycle_event_listener() override
84 {
85 return host_lifecycle_event_listener(
86 [this]()
87 {
88 return std::make_shared<HostLifecycleEventListener>(the_logger());
89 });
90 }
91};
92
93}
94}
95
96int main(int argc, char const* argv[])
97try
98{
99 me::DemoServerConfiguration config(argc, argv);
100
101 auto wm = std::make_shared<me::WindowManager>();
102
103 mir::run_mir(config, [&config, &wm](mir::DisplayServer&)
104 {
105 // We use this strange two stage initialization to avoid a circular dependency between the EventFilters
106 // and the SessionStore
107 wm->set_focus_controller(config.the_focus_controller());
108 wm->set_display(config.the_display());
109 wm->set_compositor(config.the_compositor());
110 wm->set_input_scene(config.the_input_scene());
111
112 config.the_composite_event_filter()->prepend(wm);
113 });
114 return 0;
115}
116catch (...)
117{
118 mir::report_exception(std::cerr);
119 return 1;
120}
1210
=== removed directory 'playground/demo-shell/typo'
=== removed file 'playground/demo-shell/typo/CMakeLists.txt'
--- playground/demo-shell/typo/CMakeLists.txt 2017-05-08 03:04:26 +0000
+++ playground/demo-shell/typo/CMakeLists.txt 1970-01-01 00:00:00 +0000
@@ -1,23 +0,0 @@
1find_package(PkgConfig)
2
3pkg_search_module(FREETYPE freetype2)
4if (FREETYPE_FOUND)
5 set(OPTIONAL_SRCS typo_freetype_renderer.cpp)
6endif ()
7
8add_library(typo STATIC
9 typo_renderer.cpp
10 typo_stub_renderer.cpp
11 typo_glcache.cpp
12 ${OPTIONAL_SRCS}
13)
14
15target_link_libraries(typo ${GL_LIBRARIES})
16target_include_directories(typo PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
17
18if (FREETYPE_FOUND)
19 target_compile_definitions(typo PUBLIC -DTYPO_SUPPORTS_FREETYPE)
20 target_link_libraries(typo ${FREETYPE_LIBRARIES})
21 target_include_directories(typo PUBLIC ${FREETYPE_INCLUDE_DIRS})
22endif ()
23
240
=== removed file 'playground/demo-shell/typo/typo_freetype_renderer.cpp'
--- playground/demo-shell/typo/typo_freetype_renderer.cpp 2017-07-28 17:00:43 +0000
+++ playground/demo-shell/typo/typo_freetype_renderer.cpp 1970-01-01 00:00:00 +0000
@@ -1,125 +0,0 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 or 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com>
17 */
18
19#include "typo_freetype_renderer.h"
20#include <stdexcept>
21#include <cstring>
22
23using namespace mir::typo;
24
25FreetypeRenderer::FreetypeRenderer()
26 : lib(nullptr), face(nullptr), preferred_height(16)
27{
28 if (FT_Init_FreeType(&lib))
29 throw std::runtime_error("FreeType init failed");
30}
31
32FreetypeRenderer::~FreetypeRenderer()
33{
34 if (face) FT_Done_Face(face);
35 if (lib) FT_Done_FreeType(lib);
36}
37
38bool FreetypeRenderer::load(char const* font_path, int pref_height)
39{
40 preferred_height = pref_height;
41
42 if (face)
43 {
44 FT_Done_Face(face);
45 face = nullptr;
46 }
47 if (FT_New_Face(lib, font_path, 0, &face))
48 return false;
49
50 FT_Set_Pixel_Sizes(face, 0, preferred_height);
51
52 return true;
53}
54
55void FreetypeRenderer::render(char const* str, Image& img)
56{
57 int minx = 0, maxx = 0, miny = 0, maxy = 0;
58 int penx = 0, peny = 0;
59 FT_GlyphSlot slot = face->glyph;
60
61 char const* s = str;
62 while (unsigned long u = unicode_from_utf8(&s))
63 {
64 auto glyph = FT_Get_Char_Index(face, u);
65 FT_Load_Glyph(face, glyph, FT_LOAD_DEFAULT);
66 FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL);
67
68 int left = penx + slot->bitmap_left;
69 if (left < minx) minx = left;
70
71 int right = left + slot->bitmap.width;
72 if (right > maxx) maxx = right;
73
74 int top = peny - slot->bitmap_top;
75 if (top < miny) miny = top;
76
77 int bottom = top + slot->bitmap.rows;
78 if (bottom > maxy) maxy = bottom;
79
80 penx += slot->advance.x >> 6;
81 peny += slot->advance.y >> 6;
82 }
83
84 int const padding = preferred_height / 8; // Allow mipmapping to smear
85 int width = maxx - minx + 1 + 2*padding;
86 int height = maxy - miny + 1;
87 if (height < preferred_height) // e.g. str has no descenders, but make
88 height = preferred_height; // room so we get a consistent height
89 height += 2*padding;
90 penx = -minx + padding;
91 peny = -miny + padding;
92
93 img.reserve(width, height, Image::alpha8);
94
95 s = str;
96 while (unsigned long u = unicode_from_utf8(&s))
97 {
98 auto glyph = FT_Get_Char_Index(face, u);
99 FT_Load_Glyph(face, glyph, FT_LOAD_DEFAULT);
100 FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL);
101
102 auto& bitmap = slot->bitmap;
103 int x = penx + slot->bitmap_left;
104 int y = peny - slot->bitmap_top;
105 int right = x + bitmap.width;
106 int bottom = y + bitmap.rows;
107
108 if (x >= 0 && right <= width && y >= 0 && bottom <= height)
109 {
110 unsigned char* src = bitmap.buffer;
111 unsigned char* dest = img.data() + y*img.stride() + x;
112
113 int ylimit = y + bitmap.rows;
114 for (; y < ylimit; ++y)
115 {
116 memcpy(dest, src, bitmap.width);
117 src += bitmap.pitch;
118 dest += img.stride();
119 }
120 }
121
122 penx += slot->advance.x >> 6;
123 peny += slot->advance.y >> 6;
124 }
125}
1260
=== removed file 'playground/demo-shell/typo/typo_freetype_renderer.h'
--- playground/demo-shell/typo/typo_freetype_renderer.h 2017-07-28 17:00:43 +0000
+++ playground/demo-shell/typo/typo_freetype_renderer.h 1970-01-01 00:00:00 +0000
@@ -1,44 +0,0 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 or 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com>
17 */
18
19#ifndef MIR_TYPO_FREETYPE_RENDERER_H_
20#define MIR_TYPO_FREETYPE_RENDERER_H_
21
22#include "typo_renderer.h"
23#include <ft2build.h>
24#include FT_FREETYPE_H
25
26namespace mir { namespace typo {
27
28class FreetypeRenderer : public Renderer
29{
30public:
31 FreetypeRenderer();
32 ~FreetypeRenderer();
33 bool load(char const* font_path, int pref_height);
34 void render(char const* str, Image& img) override;
35
36private:
37 FT_Library lib;
38 FT_Face face;
39 int preferred_height;
40};
41
42} } // namespace mir::typo
43
44#endif // MIR_TYPO_FREETYPE_RENDERER_H_
450
=== removed file 'playground/demo-shell/typo/typo_glcache.cpp'
--- playground/demo-shell/typo/typo_glcache.cpp 2017-07-28 17:00:43 +0000
+++ playground/demo-shell/typo/typo_glcache.cpp 1970-01-01 00:00:00 +0000
@@ -1,99 +0,0 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 or 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com>
17 */
18
19#include "typo_glcache.h"
20#include MIR_SERVER_GL_H
21
22using namespace mir::typo;
23
24GLCache::GLCache(std::shared_ptr<Renderer> const& r)
25 : renderer(r)
26{
27}
28
29GLCache::~GLCache()
30{
31 clear();
32}
33
34void GLCache::change_renderer(std::shared_ptr<Renderer> const& r)
35{
36 clear();
37 renderer = r;
38}
39
40void GLCache::clear()
41{
42 for (auto& e : map)
43 glDeleteTextures(1, &e.second.tex);
44 map.clear();
45}
46
47void GLCache::mark_all_unused()
48{
49 for (auto& e : map)
50 e.second.used = false;
51}
52
53void GLCache::drop_unused()
54{
55 for (auto e = map.begin(); e != map.end();)
56 {
57 if (!e->second.used)
58 {
59 glDeleteTextures(1, &e->second.tex);
60 e = map.erase(e);
61 }
62 else
63 e++;
64 }
65}
66
67bool GLCache::Entry::valid() const
68{
69 return width > 0 && height > 0;
70}
71
72GLCache::Entry const& GLCache::get(char const* str)
73{
74 Entry& entry = map[str];
75 if (!entry.valid())
76 {
77 Renderer::Image img;
78 renderer->render(str, img);
79 if (img.data())
80 {
81 entry.width = img.width();
82 entry.height = img.height();
83 glGenTextures(1, &entry.tex);
84 glBindTexture(GL_TEXTURE_2D, entry.tex);
85 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
86 GL_LINEAR_MIPMAP_NEAREST);
87 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
88 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
89 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
90 glPixelStorei(GL_UNPACK_ALIGNMENT, img.alignment());
91 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA,
92 img.width(), img.height(), 0, GL_ALPHA,
93 GL_UNSIGNED_BYTE, img.data());
94 glGenerateMipmap(GL_TEXTURE_2D); // Antialiasing shrinkage please
95 }
96 }
97 entry.used = true;
98 return entry;
99}
1000
=== removed file 'playground/demo-shell/typo/typo_glcache.h'
--- playground/demo-shell/typo/typo_glcache.h 2017-07-28 17:00:43 +0000
+++ playground/demo-shell/typo/typo_glcache.h 1970-01-01 00:00:00 +0000
@@ -1,56 +0,0 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 or 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com>
17 */
18
19#ifndef MIR_TYPO_GLCACHE_H_
20#define MIR_TYPO_GLCACHE_H_
21
22#include "typo_renderer.h"
23#include <string>
24#include <unordered_map>
25#include <memory>
26
27namespace mir { namespace typo {
28
29class GLCache
30{
31public:
32 struct Entry
33 {
34 bool valid() const;
35 unsigned int tex = 0;
36 int width = 0, height = 0;
37 bool used = false;
38 };
39
40 explicit GLCache(std::shared_ptr<Renderer> const&);
41 ~GLCache();
42 void change_renderer(std::shared_ptr<Renderer> const&);
43 Entry const& get(char const* str);
44 void clear();
45 void mark_all_unused();
46 void drop_unused();
47
48private:
49 typedef std::unordered_map<std::string, Entry> Map;
50 Map map;
51 std::shared_ptr<Renderer> renderer;
52};
53
54} } // namespace mir::typo
55
56#endif // MIR_TYPO_GLCACHE_H_
570
=== removed file 'playground/demo-shell/typo/typo_renderer.cpp'
--- playground/demo-shell/typo/typo_renderer.cpp 2017-07-28 17:00:43 +0000
+++ playground/demo-shell/typo/typo_renderer.cpp 1970-01-01 00:00:00 +0000
@@ -1,59 +0,0 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 or 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com>
17 */
18
19#include "typo_renderer.h"
20#include <cstring>
21
22using namespace mir::typo;
23
24Renderer::Image::Image()
25 : buf(nullptr), width_(0), stride_(0), height_(0), align_(4),
26 format_(alpha8)
27{
28}
29
30Renderer::Image::~Image()
31{
32 delete[] buf;
33}
34
35void Renderer::Image::reserve(int w, int h, Format f)
36{
37 width_ = w;
38 height_ = h;
39 format_ = f;
40 int const bpp = 1; // format is always alpha8
41 stride_ = (((width_ * bpp) + align_ - 1) / align_) * align_;
42 delete[] buf;
43 auto size = stride_ * height_;
44 buf = new unsigned char[size];
45 memset(buf, 0, size);
46}
47
48Renderer::~Renderer()
49{
50}
51
52unsigned long Renderer::unicode_from_utf8(char const** utf8)
53{
54 int char_len = 1; // TODO: Add support for non-ASCII UTF-8
55 unsigned long unicode = **utf8;
56 if (unicode)
57 *utf8 += char_len;
58 return unicode;
59}
600
=== removed file 'playground/demo-shell/typo/typo_renderer.h'
--- playground/demo-shell/typo/typo_renderer.h 2017-07-28 17:00:43 +0000
+++ playground/demo-shell/typo/typo_renderer.h 1970-01-01 00:00:00 +0000
@@ -1,61 +0,0 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 or 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com>
17 */
18
19#ifndef MIR_TYPO_RENDERER_H_
20#define MIR_TYPO_RENDERER_H_
21
22namespace mir { namespace typo {
23
24class Renderer
25{
26public:
27 class Image
28 {
29 public:
30 Image();
31 Image(Image const&) = delete;
32 Image(Image const&&) = delete;
33 Image& operator=(Image const&) = delete;
34 ~Image();
35
36 typedef enum {alpha8} Format;
37
38 void reserve(int w, int h, Format f);
39 unsigned char* data() const { return buf; };
40 int width() const { return width_; }
41 int height() const { return height_; }
42 int stride() const { return stride_; }
43 int alignment() const { return align_; }
44 Format format() const { return format_; }
45
46 private:
47 unsigned char* buf;
48 int width_, stride_, height_, align_;
49 Format format_;
50 };
51
52 virtual ~Renderer();
53 virtual void render(char const* str, Image& img) = 0;
54
55protected:
56 static unsigned long unicode_from_utf8(char const** utf8);
57};
58
59} } // namespace mir::typo
60
61#endif // MIR_TYPO_RENDERER_H_
620
=== removed file 'playground/demo-shell/typo/typo_stub_renderer.cpp'
--- playground/demo-shell/typo/typo_stub_renderer.cpp 2017-07-28 17:00:43 +0000
+++ playground/demo-shell/typo/typo_stub_renderer.cpp 1970-01-01 00:00:00 +0000
@@ -1,47 +0,0 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 or 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com>
17 */
18
19#include "typo_stub_renderer.h"
20#include <cstring>
21
22using namespace mir::typo;
23
24void StubRenderer::render(char const* str, Image& img)
25{
26 int const char_width = 8;
27 int const char_height = 16;
28 int const char_space = 2;
29 int const tex_height = 20;
30 int const len = strlen(str);
31 int const top = (tex_height - char_height) / 2;
32
33 img.reserve(len*(char_width+char_space) - char_space, tex_height,
34 Image::alpha8);
35
36 char const* s = str;
37 for (int n = 0; unicode_from_utf8(&s); ++n)
38 {
39 unsigned char* row = img.data() + top*img.stride() +
40 n*(char_width+char_space);
41 for (int y = 0; y < char_height; ++y)
42 {
43 memset(row, 255, char_width);
44 row += img.stride();
45 }
46 }
47}
480
=== removed file 'playground/demo-shell/typo/typo_stub_renderer.h'
--- playground/demo-shell/typo/typo_stub_renderer.h 2017-07-28 17:00:43 +0000
+++ playground/demo-shell/typo/typo_stub_renderer.h 1970-01-01 00:00:00 +0000
@@ -1,34 +0,0 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 or 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com>
17 */
18
19#ifndef MIR_TYPO_STUB_RENDERER_H_
20#define MIR_TYPO_STUB_RENDERER_H_
21
22#include "typo_renderer.h"
23
24namespace mir { namespace typo {
25
26class StubRenderer : public Renderer
27{
28public:
29 void render(char const* str, Image& img) override;
30};
31
32} } // namespace mir::typo
33
34#endif // MIR_TYPO_STUB_RENDERER_H_
350
=== removed file 'playground/demo-shell/window_manager.cpp'
--- playground/demo-shell/window_manager.cpp 2017-07-28 17:00:43 +0000
+++ playground/demo-shell/window_manager.cpp 1970-01-01 00:00:00 +0000
@@ -1,611 +0,0 @@
1/*
2 * Copyright © 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 or 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Robert Carr <robert.carr@canonical.com>
17 * Daniel van Vugt <daniel.van.vugt@canonical.com>
18 */
19
20#include "window_manager.h"
21#include "demo_compositor.h"
22
23#include "mir/shell/focus_controller.h"
24#include "mir/scene/session.h"
25#include "mir/scene/surface.h"
26#include "mir/graphics/display.h"
27#include "mir/graphics/display_configuration.h"
28#include "mir/compositor/compositor.h"
29
30#include <linux/input.h>
31
32#include <cassert>
33#include <cstdlib>
34#include <cmath>
35
36namespace me = mir::examples;
37namespace msh = mir::shell;
38namespace mg = mir::graphics;
39namespace mc = mir::compositor;
40namespace mi = mir::input;
41
42namespace
43{
44const int min_swipe_distance = 100; // How long must a swipe be to act on?
45}
46
47me::WindowManager::WindowManager()
48 : old_pinch_diam(0.0f), max_fingers(0)
49{
50}
51
52void me::WindowManager::set_focus_controller(std::shared_ptr<msh::FocusController> const& controller)
53{
54 focus_controller = controller;
55}
56
57void me::WindowManager::set_display(std::shared_ptr<mg::Display> const& dpy)
58{
59 display = dpy;
60}
61
62void me::WindowManager::set_compositor(std::shared_ptr<mc::Compositor> const& cptor)
63{
64 compositor = cptor;
65}
66
67void me::WindowManager::set_input_scene(std::shared_ptr<mi::Scene> const& s)
68{
69 input_scene = s;
70}
71
72void me::WindowManager::force_redraw()
73{
74 // This is clumsy, but the only option our architecture allows us for now
75 // Same hack as used in TouchspotController...
76 input_scene->emit_scene_changed();
77}
78
79namespace
80{
81
82mir::geometry::Point average_pointer(MirTouchEvent const* tev)
83{
84 using namespace mir;
85 using namespace geometry;
86
87 int x = 0, y = 0;
88 int count = mir_touch_event_point_count(tev);
89
90 for (int i = 0; i < count; i++)
91 {
92 x += mir_touch_event_axis_value(tev, i, mir_touch_axis_x);
93 y += mir_touch_event_axis_value(tev, i, mir_touch_axis_y);
94 }
95
96 x /= count;
97 y /= count;
98
99 return Point{x, y};
100}
101
102float measure_pinch(MirTouchEvent const* tev,
103 mir::geometry::Displacement& dir)
104{
105 int count = mir_touch_event_point_count(tev);
106 int max = 0;
107
108 for (int i = 0; i < count; i++)
109 {
110 for (int j = 0; j < i; j++)
111 {
112 int dx = mir_touch_event_axis_value(tev, i, mir_touch_axis_x) -
113 mir_touch_event_axis_value(tev, j, mir_touch_axis_x);
114 int dy = mir_touch_event_axis_value(tev, i, mir_touch_axis_y) -
115 mir_touch_event_axis_value(tev, j, mir_touch_axis_y);
116
117 int sqr = dx*dx + dy*dy;
118
119 if (sqr > max)
120 {
121 max = sqr;
122 dir = mir::geometry::Displacement{dx, dy};
123 }
124 }
125 }
126
127 return sqrtf(max); // return pinch diameter
128}
129
130} // namespace
131
132
133void me::WindowManager::toggle(ColourEffect which)
134{
135 colour_effect = (colour_effect == which) ? none : which;
136 me::DemoCompositor::for_each([this](me::DemoCompositor& c)
137 {
138 c.set_colour_effect(colour_effect);
139 });
140 force_redraw();
141}
142
143void me::WindowManager::save_edges(scene::Surface& surf,
144 geometry::Point const& p)
145{
146 int width = surf.size().width.as_int();
147 int height = surf.size().height.as_int();
148
149 int left = surf.top_left().x.as_int();
150 int right = left + width;
151 int top = surf.top_left().y.as_int();
152 int bottom = top + height;
153
154 int leftish = left + width/3;
155 int rightish = right - width/3;
156 int topish = top + height/3;
157 int bottomish = bottom - height/3;
158
159 int click_x = p.x.as_int();
160 xedge = (click_x <= leftish) ? left_edge :
161 (click_x >= rightish) ? right_edge :
162 hmiddle;
163
164 int click_y = p.y.as_int();
165 yedge = (click_y <= topish) ? top_edge :
166 (click_y >= bottomish) ? bottom_edge :
167 vmiddle;
168}
169
170void me::WindowManager::resize(scene::Surface& surf,
171 geometry::Point const& cursor) const
172{
173 int width = surf.size().width.as_int();
174 int height = surf.size().height.as_int();
175
176 int left = surf.top_left().x.as_int();
177 int right = left + width;
178 int top = surf.top_left().y.as_int();
179 int bottom = top + height;
180
181 geometry::Displacement drag = cursor - old_cursor;
182 int dx = drag.dx.as_int();
183 int dy = drag.dy.as_int();
184
185 if (xedge == left_edge && dx < width)
186 left = old_pos.x.as_int() + dx;
187 else if (xedge == right_edge)
188 right = old_pos.x.as_int() + old_size.width.as_int() + dx;
189
190 if (yedge == top_edge && dy < height)
191 top = old_pos.y.as_int() + dy;
192 else if (yedge == bottom_edge)
193 bottom = old_pos.y.as_int() + old_size.height.as_int() + dy;
194
195 surf.move_to({left, top});
196 surf.resize({right-left, bottom-top});
197}
198
199bool me::WindowManager::handle_key_event(MirKeyboardEvent const* kev)
200{
201 static bool display_off = false;
202
203 if (mir_keyboard_event_action(kev) != mir_keyboard_action_down)
204 return false;
205
206 auto modifiers = mir_keyboard_event_modifiers(kev);
207 auto scan_code = mir_keyboard_event_scan_code(kev);
208
209 if (modifiers & mir_input_event_modifier_alt &&
210 scan_code == KEY_TAB) // TODO: Use keycode once we support keymapping on the server side
211 {
212 focus_controller->focus_next_session();
213 if (auto const surface = focus_controller->focused_surface())
214 focus_controller->raise({surface});
215 return true;
216 }
217 else if (modifiers & mir_input_event_modifier_alt &&
218 scan_code == KEY_GRAVE)
219 {
220 if (auto const prev = focus_controller->focused_surface())
221 {
222 auto const app = focus_controller->focused_session();
223 auto const next = app->surface_after(prev);
224 focus_controller->set_focus_to(app, next);
225 focus_controller->raise({next});
226 }
227 return true;
228 }
229 else if (modifiers & mir_input_event_modifier_alt &&
230 scan_code == KEY_F4)
231 {
232 auto const surf = focus_controller->focused_surface();
233 if (surf)
234 surf->request_client_surface_close();
235 return true;
236 }
237 else if ((modifiers & mir_input_event_modifier_alt &&
238 scan_code == KEY_P) ||
239 (scan_code == KEY_POWER))
240 {
241 compositor->stop();
242 auto conf = display->configuration();
243 MirPowerMode new_power_mode = display_off ?
244 mir_power_mode_on : mir_power_mode_off;
245 conf->for_each_output(
246 [&](mg::UserDisplayConfigurationOutput& output) -> void
247 {
248 output.power_mode = new_power_mode;
249 });
250 display_off = !display_off;
251
252 display->configure(*conf.get());
253 if (!display_off)
254 compositor->start();
255 return true;
256 }
257 else if ((modifiers & mir_input_event_modifier_alt) &&
258 (modifiers & mir_input_event_modifier_ctrl) &&
259 (scan_code == KEY_ESC))
260 {
261 std::abort();
262 return true;
263 }
264 else if ((modifiers & mir_input_event_modifier_alt) &&
265 (modifiers & mir_input_event_modifier_ctrl) &&
266 (scan_code == KEY_L) &&
267 focus_controller)
268 {
269 auto const app = focus_controller->focused_session();
270 if (app)
271 {
272 app->set_lifecycle_state(mir_lifecycle_state_will_suspend);
273 }
274 }
275 else if ((modifiers & mir_input_event_modifier_alt) &&
276 (modifiers & mir_input_event_modifier_ctrl))
277 {
278 MirOrientation orientation = mir_orientation_normal;
279 bool rotating = true;
280 int mode_change = 0;
281 bool preferred_mode = false;
282 switch (scan_code)
283 {
284 case KEY_UP: orientation = mir_orientation_normal; break;
285 case KEY_DOWN: orientation = mir_orientation_inverted; break;
286 case KEY_LEFT: orientation = mir_orientation_left; break;
287 case KEY_RIGHT: orientation = mir_orientation_right; break;
288 default: rotating = false; break;
289 }
290 switch (scan_code)
291 {
292 case KEY_MINUS: mode_change = -1; break;
293 case KEY_EQUAL: mode_change = +1; break;
294 case KEY_0: preferred_mode = true; break;
295 default: break;
296 }
297
298 if (rotating || mode_change || preferred_mode)
299 {
300 auto conf = display->configuration();
301 conf->for_each_output(
302 [&](mg::UserDisplayConfigurationOutput& output) -> void
303 {
304 // Only apply changes to the monitor the cursor is on
305 if (!output.extents().contains(old_cursor))
306 return;
307 if (rotating)
308 output.orientation = orientation;
309 if (preferred_mode)
310 {
311 output.current_mode_index =
312 output.preferred_mode_index;
313 }
314 else if (mode_change)
315 {
316 size_t nmodes = output.modes.size();
317 if (nmodes)
318 output.current_mode_index =
319 (output.current_mode_index + nmodes +
320 mode_change) % nmodes;
321 }
322 });
323
324 if (!rotating) compositor->stop();
325 display->configure(*conf);
326 if (!rotating) compositor->start();
327 force_redraw();
328 return true;
329 }
330 }
331 else if ((scan_code == KEY_VOLUMEDOWN ||
332 scan_code == KEY_VOLUMEUP) &&
333 max_fingers == 1)
334 {
335 int delta = (scan_code == KEY_VOLUMEDOWN) ? -1 : +1;
336 static const MirOrientation order[4] =
337 {
338 mir_orientation_normal,
339 mir_orientation_right,
340 mir_orientation_inverted,
341 mir_orientation_left
342 };
343 compositor->stop();
344 auto conf = display->configuration();
345 conf->for_each_output(
346 [&](mg::UserDisplayConfigurationOutput& output)
347 {
348 int i = 0;
349 for (; i < 4; ++i)
350 {
351 if (output.orientation == order[i])
352 break;
353 }
354 output.orientation = order[(i+4+delta) % 4];
355 });
356 display->configure(*conf.get());
357 compositor->start();
358 return true;
359 }
360 else if (modifiers & mir_input_event_modifier_meta &&
361 scan_code == KEY_N)
362 {
363 toggle(inverse);
364 return true;
365 }
366 else if (modifiers & mir_input_event_modifier_meta &&
367 scan_code == KEY_C)
368 {
369 toggle(contrast);
370 return true;
371 }
372 return false;
373}
374
375
376bool me::WindowManager::handle_pointer_event(MirPointerEvent const* pev)
377{
378 bool handled = false;
379
380 geometry::Point cursor{mir_pointer_event_axis_value(pev, mir_pointer_axis_x),
381 mir_pointer_event_axis_value(pev, mir_pointer_axis_y)};
382 auto action = mir_pointer_event_action(pev);
383 auto modifiers = mir_pointer_event_modifiers(pev);
384 auto vscroll = mir_pointer_event_axis_value(pev, mir_pointer_axis_vscroll);
385 auto primary_button_pressed = mir_pointer_event_button_state(pev, mir_pointer_button_primary);
386 auto tertiary_button_pressed = mir_pointer_event_button_state(pev, mir_pointer_button_tertiary);
387
388 float new_zoom_mag = 0.0f; // zero means unchanged
389
390 if (modifiers & mir_input_event_modifier_meta &&
391 action == mir_pointer_action_motion &&
392 vscroll != 0.0f)
393 {
394 zoom_exponent += vscroll;
395
396 // Negative exponents do work too, but disable them until
397 // there's a clear edge to the desktop.
398 if (zoom_exponent < 0)
399 zoom_exponent = 0;
400
401 new_zoom_mag = powf(1.2f, zoom_exponent);
402 handled = true;
403 }
404
405 me::DemoCompositor::for_each(
406 [new_zoom_mag,&cursor](me::DemoCompositor& c)
407 {
408 if (new_zoom_mag > 0.0f)
409 c.zoom(new_zoom_mag);
410 c.on_cursor_movement(cursor);
411 });
412
413 if (zoom_exponent || new_zoom_mag)
414 force_redraw();
415
416 auto const surf = focus_controller->focused_surface();
417 if (surf &&
418 (modifiers & mir_input_event_modifier_alt) && (primary_button_pressed || tertiary_button_pressed))
419 {
420 // Start of a gesture: When the latest finger/button goes down
421 if (action == mir_pointer_action_button_down)
422 {
423 click = cursor;
424 save_edges(*surf, click);
425 handled = true;
426 }
427 else if (action == mir_pointer_action_motion)
428 {
429 geometry::Displacement drag = cursor - old_cursor;
430
431 if (tertiary_button_pressed)
432 { // Resize by mouse middle button
433 resize(*surf, cursor);
434 }
435 else
436 {
437 surf->move_to(old_pos + drag);
438 }
439
440 handled = true;
441 }
442
443 old_pos = surf->top_left();
444 old_size = surf->size();
445 }
446
447 if (surf &&
448 (modifiers & mir_input_event_modifier_alt) &&
449 action == mir_pointer_action_motion &&
450 vscroll)
451 {
452 float alpha = surf->alpha();
453 alpha += vscroll > 0.0f ? 0.1f : -0.1f;
454 if (alpha < 0.0f)
455 alpha = 0.0f;
456 else if (alpha > 1.0f)
457 alpha = 1.0f;
458 surf->set_alpha(alpha);
459 handled = true;
460 }
461
462 old_cursor = cursor;
463 return handled;
464}
465
466namespace
467{
468bool any_touches_went_down(MirTouchEvent const* tev)
469{
470 auto count = mir_touch_event_point_count(tev);
471 for (unsigned i = 0; i < count; i++)
472 {
473 if (mir_touch_event_action(tev, i) == mir_touch_action_down)
474 return true;
475 }
476 return false;
477}
478bool last_touch_released(MirTouchEvent const* tev)
479{
480 auto count = mir_touch_event_point_count(tev);
481 if (count > 1)
482 return false;
483 return mir_touch_event_action(tev, 0) == mir_touch_action_up;
484}
485}
486
487bool me::WindowManager::handle_touch_event(MirTouchEvent const* tev)
488{
489 bool handled = false;
490 geometry::Point cursor = average_pointer(tev);
491
492 auto const& modifiers = mir_touch_event_modifiers(tev);
493
494 int fingers = mir_touch_event_point_count(tev);
495
496 if (fingers > max_fingers)
497 max_fingers = fingers;
498
499 auto const surf = focus_controller->focused_surface();
500 if (surf &&
501 (modifiers & mir_input_event_modifier_alt ||
502 fingers >= 3))
503 {
504 geometry::Displacement pinch_dir;
505 auto pinch_diam =
506 measure_pinch(tev, pinch_dir);
507
508 // Start of a gesture: When the latest finger/button goes down
509 if (any_touches_went_down(tev))
510 {
511 click = cursor;
512 save_edges(*surf, click);
513 handled = true;
514 }
515 else if(max_fingers <= 3) // Avoid accidental movement
516 {
517 geometry::Displacement drag = cursor - old_cursor;
518
519 surf->move_to(old_pos + drag);
520
521 if (fingers == 3)
522 { // Resize by pinch/zoom
523 float diam_delta = pinch_diam - old_pinch_diam;
524 /*
525 * Resize vector (dx,dy) has length=diam_delta and
526 * direction=pinch_dir, so solve for (dx,dy)...
527 */
528 float lenlen = diam_delta * diam_delta;
529 int x = pinch_dir.dx.as_int();
530 int y = pinch_dir.dy.as_int();
531 int xx = x * x;
532 int yy = y * y;
533 int xxyy = xx + yy;
534 int dx = sqrtf(lenlen * xx / xxyy);
535 int dy = sqrtf(lenlen * yy / xxyy);
536 if (diam_delta < 0.0f)
537 {
538 dx = -dx;
539 dy = -dy;
540 }
541
542 int width = old_size.width.as_int() + dx;
543 int height = old_size.height.as_int() + dy;
544 surf->resize({width, height});
545 }
546
547 handled = true;
548 }
549
550 old_pos = surf->top_left();
551 old_size = surf->size();
552 old_pinch_diam = pinch_diam;
553 }
554
555 auto gesture_ended = last_touch_released(tev);
556
557 if (max_fingers == 4 && gesture_ended)
558 { // Four fingers released
559 geometry::Displacement dir = cursor - click;
560 if (abs(dir.dx.as_int()) >= min_swipe_distance)
561 {
562 focus_controller->focus_next_session();
563 if (auto const surface = focus_controller->focused_surface())
564 focus_controller->raise({surface});
565 handled = true;
566 }
567 }
568
569 if (fingers == 1 && gesture_ended)
570 max_fingers = 0;
571
572 old_cursor = cursor;
573
574 /*
575 * For now we reserve all 3 or 4 finger gestures for window manipulation.
576 * Make sure clients don't receive spurious events in the process...
577 */
578 handled |= (max_fingers == 3 || max_fingers == 4);
579
580 return handled;
581}
582
583bool me::WindowManager::handle(MirEvent const& event)
584{
585 assert(focus_controller);
586 assert(display);
587 assert(compositor);
588
589 if (mir_event_get_type(&event) != mir_event_type_input)
590 return false;
591 auto iev = mir_event_get_input_event(&event);
592 auto input_type = mir_input_event_get_type(iev);
593
594 if (input_type == mir_input_event_type_key)
595 {
596 return handle_key_event(mir_input_event_get_keyboard_event(iev));
597 }
598 else if (input_type == mir_input_event_type_pointer &&
599 focus_controller)
600 {
601 return handle_pointer_event(mir_input_event_get_pointer_event(iev));
602 }
603 else if (input_type == mir_input_event_type_touch &&
604 focus_controller)
605 {
606 return handle_touch_event(mir_input_event_get_touch_event(iev));
607 }
608
609
610 return false;
611}
6120
=== removed file 'playground/demo-shell/window_manager.h'
--- playground/demo-shell/window_manager.h 2017-07-28 17:00:43 +0000
+++ playground/demo-shell/window_manager.h 1970-01-01 00:00:00 +0000
@@ -1,97 +0,0 @@
1/*
2 * Copyright © 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 or 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Robert Carr <robert.carr@canonical.com>
17 */
18
19#ifndef MIR_EXAMPLES_WINDOW_MANAGER_H_
20#define MIR_EXAMPLES_WINDOW_MANAGER_H_
21
22#include "mir/input/event_filter.h"
23#include "mir/input/scene.h"
24#include "mir/geometry/displacement.h"
25#include "mir/geometry/size.h"
26#include "demo_renderer.h"
27
28#include <memory>
29
30namespace mir
31{
32namespace shell
33{
34class FocusController;
35}
36namespace graphics
37{
38class Display;
39}
40namespace compositor
41{
42class Compositor;
43}
44
45namespace scene { class Surface; }
46
47namespace examples
48{
49
50class WindowManager : public input::EventFilter
51{
52public:
53 WindowManager();
54 ~WindowManager() = default;
55
56 void set_focus_controller(std::shared_ptr<shell::FocusController> const& focus_controller);
57 void set_display(std::shared_ptr<graphics::Display> const& display);
58 void set_compositor(std::shared_ptr<compositor::Compositor> const& compositor);
59 void set_input_scene(std::shared_ptr<input::Scene> const& scene);
60 void force_redraw();
61
62 bool handle(MirEvent const& event) override;
63
64protected:
65 WindowManager(const WindowManager&) = delete;
66 WindowManager& operator=(const WindowManager&) = delete;
67
68private:
69 std::shared_ptr<shell::FocusController> focus_controller;
70 std::shared_ptr<graphics::Display> display;
71 std::shared_ptr<compositor::Compositor> compositor;
72 std::shared_ptr<input::Scene> input_scene;
73
74 geometry::Point click;
75 geometry::Point old_pos;
76 geometry::Point old_cursor;
77 geometry::Size old_size;
78 float old_pinch_diam;
79 int max_fingers; // Maximum number of fingers touched during gesture
80 float zoom_exponent = 0.0f;
81 ColourEffect colour_effect = none;
82
83 void toggle(ColourEffect);
84
85 enum {left_edge, hmiddle, right_edge} xedge = hmiddle;
86 enum {top_edge, vmiddle, bottom_edge} yedge = vmiddle;
87 void save_edges(scene::Surface& surf, geometry::Point const& p);
88 void resize(scene::Surface& surf, geometry::Point const& cursor) const;
89 bool handle_key_event(MirKeyboardEvent const* event);
90 bool handle_touch_event(MirTouchEvent const* event);
91 bool handle_pointer_event(MirPointerEvent const* event);
92};
93
94}
95} // namespace mir
96
97#endif // MIR_EXAMPLES_WINDOW_MANAGER_H_
980
=== removed file 'playground/server_configuration.cpp'
--- playground/server_configuration.cpp 2017-07-28 17:00:43 +0000
+++ playground/server_configuration.cpp 1970-01-01 00:00:00 +0000
@@ -1,86 +0,0 @@
1/*
2 * Copyright © 2013-2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 or 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
17 */
18
19#include "server_configuration.h"
20#include "mir/options/default_configuration.h"
21#include "mir/input/composite_event_filter.h"
22#include "mir/graphics/default_display_configuration_policy.h"
23#include "mir/main_loop.h"
24
25#include "server_example_display_configuration_policy.h"
26#include "server_example_input_event_filter.h"
27
28namespace me = mir::examples;
29namespace mg = mir::graphics;
30
31namespace
32{
33std::shared_ptr<mir::options::DefaultConfiguration> const& customize(
34 std::shared_ptr<mir::options::DefaultConfiguration> const& opt)
35{
36 opt->add_options()(me::display_config_opt,
37 boost::program_options::value<std::string>()->
38 default_value(me::clone_opt_val),
39 me::display_config_descr);
40
41 return opt;
42}
43}
44
45me::ServerConfiguration::ServerConfiguration(std::shared_ptr<options::DefaultConfiguration> const& configuration_options) :
46 DefaultServerConfiguration(customize(configuration_options))
47{
48}
49
50me::ServerConfiguration::ServerConfiguration(int argc, char const** argv) :
51 ServerConfiguration(std::make_shared<options::DefaultConfiguration>(argc, argv))
52{
53}
54
55std::shared_ptr<mg::DisplayConfigurationPolicy>
56me::ServerConfiguration::the_display_configuration_policy()
57{
58 return display_configuration_policy(
59 [this]() -> std::shared_ptr<mg::DisplayConfigurationPolicy>
60 {
61 auto display_config = the_options()->get<std::string>(me::display_config_opt);
62
63 if (display_config == me::sidebyside_opt_val)
64 return std::make_shared<mg::SideBySideDisplayConfigurationPolicy>();
65 else if (display_config == me::single_opt_val)
66 return std::make_shared<mg::SingleDisplayConfigurationPolicy>();
67 else
68 return DefaultServerConfiguration::the_display_configuration_policy();
69 });
70}
71
72std::shared_ptr<mir::input::CompositeEventFilter>
73me::ServerConfiguration::the_composite_event_filter()
74{
75 return composite_event_filter(
76 [this]() -> std::shared_ptr<mir::input::CompositeEventFilter>
77 {
78 if (!quit_filter)
79 quit_filter = std::make_shared<me::QuitFilter>([this] { the_main_loop()->stop(); });
80
81 auto composite_filter = DefaultServerConfiguration::the_composite_event_filter();
82 composite_filter->append(quit_filter);
83
84 return composite_filter;
85 });
86}
870
=== removed file 'playground/server_configuration.h'
--- playground/server_configuration.h 2017-07-28 17:00:43 +0000
+++ playground/server_configuration.h 1970-01-01 00:00:00 +0000
@@ -1,49 +0,0 @@
1/*
2 * Copyright © 2013-2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 or 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
17 */
18
19#ifndef MIR_EXAMPLES_SERVER_CONFIGURATION_H_
20#define MIR_EXAMPLES_SERVER_CONFIGURATION_H_
21
22#include "mir/default_server_configuration.h"
23
24namespace mir
25{
26namespace options
27{
28class DefaultConfiguration;
29}
30
31namespace examples
32{
33
34class ServerConfiguration : public DefaultServerConfiguration
35{
36public:
37 ServerConfiguration(int argc, char const** argv);
38 explicit ServerConfiguration(std::shared_ptr<options::DefaultConfiguration> const& configuration_options);
39
40 std::shared_ptr<graphics::DisplayConfigurationPolicy> the_display_configuration_policy() override;
41 std::shared_ptr<input::CompositeEventFilter> the_composite_event_filter() override;
42
43private:
44 std::shared_ptr<input::EventFilter> quit_filter;
45};
46}
47}
48
49#endif /* MIR_EXAMPLES_SERVER_CONFIGURATION_H_ */
500
=== removed file 'playground/server_example_display_configuration_policy.cpp'
--- playground/server_example_display_configuration_policy.cpp 2017-07-28 17:00:43 +0000
+++ playground/server_example_display_configuration_policy.cpp 1970-01-01 00:00:00 +0000
@@ -1,115 +0,0 @@
1/*
2 * Copyright © 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 or 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored By: Alan Griffiths <alan@octopull.co.uk>
17 */
18
19#include "server_example_display_configuration_policy.h"
20#include "mir/graphics/default_display_configuration_policy.h"
21
22#include "mir/graphics/display_configuration.h"
23#include "mir/server.h"
24#include "mir/options/option.h"
25
26#include <algorithm>
27#include <unordered_map>
28#include <stdexcept>
29
30namespace geom = mir::geometry;
31namespace me = mir::examples;
32namespace mg = mir::graphics;
33
34///\example server_example_display_configuration_policy.cpp
35/// Demonstrate custom display configuration policies for "sidebyside" and "single"
36
37char const* const me::display_config_opt = "display-config";
38char const* const me::display_config_descr = "Display configuration [{clone,sidebyside,single}]";
39
40char const* const me::clone_opt_val = "clone";
41char const* const me::sidebyside_opt_val = "sidebyside";
42char const* const me::single_opt_val = "single";
43
44char const* const me::display_alpha_opt = "translucent";
45char const* const me::display_alpha_descr = "Select a display mode with alpha[{on,off}]";
46
47char const* const me::display_alpha_off = "off";
48char const* const me::display_alpha_on = "on";
49
50namespace
51{
52bool contains_alpha(MirPixelFormat format)
53{
54 return (format == mir_pixel_format_abgr_8888 ||
55 format == mir_pixel_format_argb_8888);
56}
57}
58
59me::PixelFormatSelector::PixelFormatSelector(std::shared_ptr<DisplayConfigurationPolicy> const& base_policy,
60 bool with_alpha)
61 : base_policy{base_policy},
62 with_alpha{with_alpha}
63{}
64
65void me::PixelFormatSelector::apply_to(graphics::DisplayConfiguration & conf)
66{
67 base_policy->apply_to(conf);
68 conf.for_each_output(
69 [&](graphics::UserDisplayConfigurationOutput& conf_output)
70 {
71 if (!conf_output.connected || !conf_output.used) return;
72
73 auto const& pos = find_if(conf_output.pixel_formats.begin(),
74 conf_output.pixel_formats.end(),
75 [&](MirPixelFormat format) -> bool
76 {
77 return contains_alpha(format) == with_alpha;
78 }
79 );
80
81 // keep the default settings if nothing was found
82 if (pos == conf_output.pixel_formats.end())
83 return;
84
85 conf_output.current_format = *pos;
86 });
87}
88
89void me::add_display_configuration_options_to(mir::Server& server)
90{
91 // Add choice of monitor configuration
92 server.add_configuration_option(
93 me::display_config_opt, me::display_config_descr, me::clone_opt_val);
94 server.add_configuration_option(
95 me::display_alpha_opt, me::display_alpha_descr, me::display_alpha_off);
96
97 server.wrap_display_configuration_policy(
98 [&](std::shared_ptr<mg::DisplayConfigurationPolicy> const& wrapped)
99 -> std::shared_ptr<mg::DisplayConfigurationPolicy>
100 {
101 auto const options = server.get_options();
102 auto display_layout = options->get<std::string>(me::display_config_opt);
103 auto with_alpha = options->get<std::string>(me::display_alpha_opt) == me::display_alpha_on;
104
105 auto layout_selector = wrapped;
106
107 if (display_layout == me::sidebyside_opt_val)
108 layout_selector = std::make_shared<mg::SideBySideDisplayConfigurationPolicy>();
109 else if (display_layout == me::single_opt_val)
110 layout_selector = std::make_shared<mg::SingleDisplayConfigurationPolicy>();
111
112 // Whatever the layout select a pixel format with requested alpha
113 return std::make_shared<me::PixelFormatSelector>(layout_selector, with_alpha);
114 });
115}
1160
=== removed file 'playground/server_example_display_configuration_policy.h'
--- playground/server_example_display_configuration_policy.h 2017-07-28 17:00:43 +0000
+++ playground/server_example_display_configuration_policy.h 1970-01-01 00:00:00 +0000
@@ -1,62 +0,0 @@
1/*
2 * Copyright © 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 or 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored By: Alan Griffiths <alan@octopull.co.uk>
17 */
18
19#ifndef MIR_EXAMPLE_DISPLAY_CONFIGURATION_POLICY_H_
20#define MIR_EXAMPLE_DISPLAY_CONFIGURATION_POLICY_H_
21
22#include "mir/graphics/display_configuration_policy.h"
23
24#include <memory>
25
26namespace mir
27{
28class Server;
29
30namespace examples
31{
32extern char const* const display_config_opt;
33extern char const* const display_config_descr;
34extern char const* const clone_opt_val;
35extern char const* const sidebyside_opt_val;
36extern char const* const single_opt_val;
37extern char const* const display_alpha_opt;
38extern char const* const display_alpha_descr;
39extern char const* const display_alpha_off;
40extern char const* const display_alpha_on;
41
42/**
43 * \brief Example of a DisplayConfigurationPolicy that tries to find
44 * an opaque or transparent pixel format, or falls back to the default
45 * if not found.
46 */
47class PixelFormatSelector : public graphics::DisplayConfigurationPolicy
48{
49public:
50 PixelFormatSelector(std::shared_ptr<graphics::DisplayConfigurationPolicy> const& base_policy,
51 bool with_alpha);
52 virtual void apply_to(graphics::DisplayConfiguration& conf);
53private:
54 std::shared_ptr<graphics::DisplayConfigurationPolicy> const base_policy;
55 bool const with_alpha;
56};
57
58void add_display_configuration_options_to(Server& server);
59}
60}
61
62#endif /* MIR_EXAMPLE_DISPLAY_CONFIGURATION_POLICY_H_ */
630
=== removed file 'src/include/server/mir/compositor/decoration.h'
--- src/include/server/mir/compositor/decoration.h 2017-07-28 17:00:43 +0000
+++ src/include/server/mir/compositor/decoration.h 1970-01-01 00:00:00 +0000
@@ -1,38 +0,0 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 or 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com>
17 */
18
19#ifndef MIR_COMPOSITOR_DECORATION_H_
20#define MIR_COMPOSITOR_DECORATION_H_
21
22#include <string>
23
24namespace mir { namespace compositor {
25
26struct Decoration
27{
28 enum class Type {none, surface} type;
29 std::string name;
30
31 Decoration() : type{Type::none} {}
32 Decoration(Type t, std::string const& n) : type{t}, name{n} {}
33 operator bool() const { return type != Type::none; }
34};
35
36} } // namespace mir::compositor
37
38#endif // MIR_COMPOSITOR_DECORATION_H_
390
=== modified file 'src/miral/CMakeLists.txt'
--- src/miral/CMakeLists.txt 2017-08-30 15:50:37 +0000
+++ src/miral/CMakeLists.txt 2017-08-30 15:50:38 +0000
@@ -1,4 +1,3 @@
1<<<<<<< TREE
2set(MIRAL_VERSION_MAJOR 1)1set(MIRAL_VERSION_MAJOR 1)
3set(MIRAL_VERSION_MINOR 5)2set(MIRAL_VERSION_MINOR 5)
4set(MIRAL_VERSION_PATCH 0)3set(MIRAL_VERSION_PATCH 0)
@@ -135,146 +134,6 @@
135 ${miral_include}/miral/version.h134 ${miral_include}/miral/version.h
136)135)
137136
138install(TARGETS miral LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")
139install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/miral DESTINATION "${INCLUDEDIR}")
140install(FILES ${CMAKE_CURRENT_BINARY_DIR}/miral.pc
141 ${CMAKE_CURRENT_BINARY_DIR}/mirclientcpp.pc DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig")
142=======
143set(MIRAL_VERSION_MAJOR 1)
144set(MIRAL_VERSION_MINOR 5)
145set(MIRAL_VERSION_PATCH 0)
146
147if(${CMAKE_COMPILER_IS_GNUCXX})
148 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto")
149 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
150 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -flto")
151 set(CMAKE_AR "gcc-ar")
152 set(CMAKE_NM "gcc-nm")
153 set(CMAKE_RANLIB "gcc-ranlib")
154endif()
155
156include_directories(
157 ${PROJECT_SOURCE_DIR}/include/platform
158 ${PROJECT_SOURCE_DIR}/include/client
159 ${PROJECT_SOURCE_DIR}/include/server
160)
161
162set(MIRAL_ABI 2)
163set(symbol_map ${CMAKE_CURRENT_SOURCE_DIR}/symbols.map)
164set(miral_include ${PROJECT_SOURCE_DIR}/include/miral)
165
166add_library(mirclientcpp INTERFACE)
167
168add_library(miral-internal STATIC
169 basic_window_manager.cpp basic_window_manager.h window_manager_tools_implementation.h
170 coordinate_translator.cpp coordinate_translator.h
171 display_configuration_listeners.cpp display_configuration_listeners.h
172 mru_window_list.cpp mru_window_list.h
173 window_management_trace.cpp window_management_trace.h
174 xcursor_loader.cpp xcursor_loader.h
175 xcursor.c xcursor.h
176 both_versions.h
177 join_client_threads.h
178)
179
180set_source_files_properties(xcursor.c PROPERTIES COMPILE_DEFINITIONS _GNU_SOURCE)
181
182add_library(miral SHARED
183 active_outputs.cpp ${miral_include}/miral/active_outputs.h
184 add_init_callback.cpp ${miral_include}/miral/add_init_callback.h
185 application.cpp ${miral_include}/miral/application.h
186 application_authorizer.cpp ${miral_include}/miral/application_authorizer.h
187 application_info.cpp ${miral_include}/miral/application_info.h
188 canonical_window_manager.cpp ${miral_include}/miral/canonical_window_manager.h
189 command_line_option.cpp ${miral_include}/miral/command_line_option.h
190 cursor_theme.cpp ${miral_include}/miral/cursor_theme.h
191 debug_extension.cpp ${miral_include}/miral/debug_extension.h
192 keymap.cpp ${miral_include}/miral/keymap.h
193 runner.cpp ${miral_include}/miral/runner.h
194 display_configuration_option.cpp ${miral_include}/miral/display_configuration_option.h
195 output.cpp ${miral_include}/miral/output.h
196 append_event_filter.cpp ${miral_include}/miral/append_event_filter.h
197 window.cpp ${miral_include}/miral/window.h
198 window_info.cpp ${miral_include}/miral/window_info.h
199 window_management_options.cpp ${miral_include}/miral/window_management_options.h
200 window_specification.cpp ${miral_include}/miral/window_specification.h
201 internal_client.cpp ${miral_include}/miral/internal_client.h
202 set_command_line_handler.cpp ${miral_include}/miral/set_command_line_handler.h
203 set_terminator.cpp ${miral_include}/miral/set_terminator.h
204 set_window_management_policy.cpp ${miral_include}/miral/set_window_management_policy.h
205 workspace_policy.cpp ${miral_include}/miral/workspace_policy.h
206 window_management_policy.cpp ${miral_include}/miral/window_management_policy.h
207 window_manager_tools.cpp ${miral_include}/miral/window_manager_tools.h
208 ${miral_include}/miral/window_management_policy_addendum2.h
209 ${miral_include}/miral/window_management_policy_addendum3.h
210 ${miral_include}/mir/client/blob.h
211 ${miral_include}/mir/client/cookie.h
212 ${miral_include}/mir/client/window_spec.h
213 ${miral_include}/mir/client/window_id.h
214 ${miral_include}/mir/client/connection.h
215 ${miral_include}/mir/client/display_config.h
216 ${miral_include}/mir/client/window.h
217)
218
219target_include_directories(mirclientcpp
220 INTERFACE "${miral_include}" ${MIRCLIENT_INCLUDE_DIRS}
221)
222
223target_include_directories(miral-internal
224 PRIVATE "${miral_include}" ${MIRCLIENT_INCLUDE_DIRS}
225 PRIVATE ${MIRSERVER_INCLUDE_DIRS}
226)
227
228target_include_directories(miral
229 PUBLIC "${miral_include}" ${MIRCLIENT_INCLUDE_DIRS}
230 PRIVATE ${MIRSERVER_INCLUDE_DIRS}
231)
232
233target_link_libraries(miral
234 PUBLIC
235 mirclient
236 mircommon
237 PRIVATE
238 miral-internal
239 mirserver
240)
241
242set_target_properties(miral
243 PROPERTIES
244 SOVERSION ${MIRAL_ABI}
245 LINK_FLAGS "-Wl,--exclude-libs=ALL -Wl,--version-script,${symbol_map}"
246 LINK_DEPENDS ${symbol_map}
247)
248
249# clang generates slightly different symbols (but we don't care)
250if (CMAKE_COMPILER_IS_GNUCXX)
251 add_custom_target(check-miral-symbols ALL
252 DEPENDS miral ${PROJECT_SOURCE_DIR}/debian/libmiral${MIRAL_ABI}.symbols
253 COMMAND rm -f ${CMAKE_CURRENT_BINARY_DIR}/libmiral${MIRAL_ABI}.symbols
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
255 WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
256 VERBATIM
257 )
258endif()
259
260set(LIBDIR "${CMAKE_INSTALL_FULL_LIBDIR}")
261set(INCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include")
262
263configure_file(${CMAKE_CURRENT_SOURCE_DIR}/miral.pc.in
264 ${CMAKE_CURRENT_BINARY_DIR}/miral.pc
265 @ONLY
266)
267
268configure_file(${CMAKE_CURRENT_SOURCE_DIR}/mirclientcpp.pc.in
269 ${CMAKE_CURRENT_BINARY_DIR}/mirclientcpp.pc
270 @ONLY
271)
272
273configure_file(
274 ${CMAKE_CURRENT_SOURCE_DIR}/version.h.in
275 ${miral_include}/miral/version.h
276)
277
278if(TARGET doc)137if(TARGET doc)
279 add_custom_target(regenerate-miral-symbols-map138 add_custom_target(regenerate-miral-symbols-map
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}
@@ -285,4 +144,3 @@
285install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/miral DESTINATION "${INCLUDEDIR}")144install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/miral DESTINATION "${INCLUDEDIR}")
286install(FILES ${CMAKE_CURRENT_BINARY_DIR}/miral.pc145install(FILES ${CMAKE_CURRENT_BINARY_DIR}/miral.pc
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")
288>>>>>>> MERGE-SOURCE
289147
=== modified file 'src/miral/miral.pc.in'
--- src/miral/miral.pc.in 2017-08-30 15:50:37 +0000
+++ src/miral/miral.pc.in 2017-08-29 09:17:03 +0000
@@ -1,4 +1,3 @@
1<<<<<<< TREE
2libdir=@LIBDIR@1libdir=@LIBDIR@
3includedir=@INCLUDEDIR@/miral2includedir=@INCLUDEDIR@/miral
43
@@ -8,14 +7,3 @@
8Requires: mirclientcpp7Requires: mirclientcpp
9Libs: -L${libdir} -lmiral8Libs: -L${libdir} -lmiral
10Cflags: -I${includedir}9Cflags: -I${includedir}
11=======
12libdir=@LIBDIR@
13includedir=@INCLUDEDIR@
14
15Name: miral
16Description: Mir Abstraction Layer library
17Version: @MIRAL_VERSION@
18Requires: mirclientcpp
19Libs: -L${libdir} -lmiral
20Cflags: -I${includedir}
21>>>>>>> MERGE-SOURCE
2210
=== modified file 'src/miral/mirclientcpp.pc.in'
--- src/miral/mirclientcpp.pc.in 2017-08-30 15:50:37 +0000
+++ src/miral/mirclientcpp.pc.in 2017-08-29 09:17:03 +0000
@@ -1,4 +1,3 @@
1<<<<<<< TREE
2includedir=@INCLUDEDIR@/miral1includedir=@INCLUDEDIR@/miral
32
4Name: mirclientcpp3Name: mirclientcpp
@@ -6,12 +5,3 @@
6Version: @MIRAL_VERSION@5Version: @MIRAL_VERSION@
7Requires: mirclient6Requires: mirclient
8Cflags: -I${includedir}7Cflags: -I${includedir}
9=======
10includedir=@INCLUDEDIR@
11
12Name: mirclientcpp
13Description: Mir Abstraction Layer C++ wrapper for mirclient
14Version: @MIRAL_VERSION@
15Requires: mirclient
16Cflags: -I${includedir}
17>>>>>>> MERGE-SOURCE
188
=== modified file 'src/server/scene/basic_surface.cpp'
--- src/server/scene/basic_surface.cpp 2017-07-28 17:00:43 +0000
+++ src/server/scene/basic_surface.cpp 2017-08-30 15:50:38 +0000
@@ -289,12 +289,6 @@
289 observers.moved_to(top_left);289 observers.moved_to(top_left);
290}290}
291291
292float ms::BasicSurface::alpha() const
293{
294 std::unique_lock<std::mutex> lk(guard);
295 return surface_alpha;
296}
297
298void ms::BasicSurface::set_hidden(bool hide)292void ms::BasicSurface::set_hidden(bool hide)
299{293{
300 {294 {
301295
=== modified file 'src/server/scene/basic_surface.h'
--- src/server/scene/basic_surface.h 2017-07-28 17:00:43 +0000
+++ src/server/scene/basic_surface.h 2017-08-30 15:50:38 +0000
@@ -79,7 +79,7 @@
7979
80 std::string name() const override;80 std::string name() const override;
81 void move_to(geometry::Point const& top_left) override;81 void move_to(geometry::Point const& top_left) override;
82 float alpha() const override;82
83 void set_hidden(bool is_hidden);83 void set_hidden(bool is_hidden);
8484
85 geometry::Size size() const override;85 geometry::Size size() const override;
8686
=== modified file 'src/server/scene/surface_stack.cpp'
--- src/server/scene/surface_stack.cpp 2017-07-28 17:00:43 +0000
+++ src/server/scene/surface_stack.cpp 2017-08-30 15:50:38 +0000
@@ -23,7 +23,6 @@
23#include "mir/scene/surface.h"23#include "mir/scene/surface.h"
24#include "mir/scene/scene_report.h"24#include "mir/scene/scene_report.h"
25#include "mir/compositor/scene_element.h"25#include "mir/compositor/scene_element.h"
26#include "mir/compositor/decoration.h"
27#include "mir/graphics/renderable.h"26#include "mir/graphics/renderable.h"
2827
29#include <boost/throw_exception.hpp>28#include <boost/throw_exception.hpp>
@@ -73,11 +72,6 @@
73 tracker->occluded_in(cid);72 tracker->occluded_in(cid);
74 }73 }
7574
76 std::unique_ptr<mc::Decoration> decoration() const override
77 {
78 return std::make_unique<mc::Decoration>(mc::Decoration::Type::surface, surface_name);
79 }
80
81private:75private:
82 std::shared_ptr<mg::Renderable> const renderable_;76 std::shared_ptr<mg::Renderable> const renderable_;
83 std::shared_ptr<ms::RenderingTracker> const tracker;77 std::shared_ptr<ms::RenderingTracker> const tracker;
@@ -108,11 +102,6 @@
108 {102 {
109 }103 }
110104
111 std::unique_ptr<mc::Decoration> decoration() const override
112 {
113 return std::make_unique<mc::Decoration>();
114 }
115
116private:105private:
117 std::shared_ptr<mg::Renderable> const renderable_;106 std::shared_ptr<mg::Renderable> const renderable_;
118};107};
119108
=== modified file 'tests/include/mir/test/doubles/stub_scene_element.h'
--- tests/include/mir/test/doubles/stub_scene_element.h 2017-07-28 17:00:43 +0000
+++ tests/include/mir/test/doubles/stub_scene_element.h 2017-08-30 15:50:38 +0000
@@ -20,7 +20,6 @@
20#define MIR_TEST_DOUBLES_STUB_SCENE_ELEMENT_H_20#define MIR_TEST_DOUBLES_STUB_SCENE_ELEMENT_H_
2121
22#include "mir/compositor/scene_element.h"22#include "mir/compositor/scene_element.h"
23#include "mir/compositor/decoration.h"
24#include "stub_renderable.h"23#include "stub_renderable.h"
2524
26namespace mir25namespace mir
@@ -56,11 +55,6 @@
56 {55 {
57 }56 }
5857
59 std::unique_ptr<compositor::Decoration> decoration() const override
60 {
61 return nullptr;
62 }
63
64private:58private:
65 std::shared_ptr<graphics::Renderable> const renderable_;59 std::shared_ptr<graphics::Renderable> const renderable_;
66};60};
6761
=== modified file 'tests/include/mir/test/doubles/stub_scene_surface.h'
--- tests/include/mir/test/doubles/stub_scene_surface.h 2017-07-28 17:00:43 +0000
+++ tests/include/mir/test/doubles/stub_scene_surface.h 2017-08-30 15:50:38 +0000
@@ -53,7 +53,6 @@
53 graphics::RenderableList generate_renderables(compositor::CompositorID) const override { return {}; }53 graphics::RenderableList generate_renderables(compositor::CompositorID) const override { return {}; }
54 int buffers_ready_for_compositor(void const*) const override { return 0; }54 int buffers_ready_for_compositor(void const*) const override { return 0; }
5555
56 float alpha() const override { return 0.0f;}
57 MirWindowType type() const override { return mir_window_type_normal; }56 MirWindowType type() const override { return mir_window_type_normal; }
58 MirWindowState state() const override { return mir_window_state_unknown; }57 MirWindowState state() const override { return mir_window_state_unknown; }
5958
6059
=== modified file 'tests/mir_test_framework/stub_surface.cpp'
--- tests/mir_test_framework/stub_surface.cpp 2017-07-28 17:00:43 +0000
+++ tests/mir_test_framework/stub_surface.cpp 2017-08-30 15:50:38 +0000
@@ -29,11 +29,6 @@
29{29{
30}30}
3131
32float mtd::StubSurface::alpha() const
33{
34 return 0;
35}
36
37mir::geometry::Size mtd::StubSurface::size() const32mir::geometry::Size mtd::StubSurface::size() const
38{33{
39 return {};34 return {};
4035
=== modified file 'tests/unit-tests/CMakeLists.txt'
--- tests/unit-tests/CMakeLists.txt 2017-05-08 03:04:26 +0000
+++ tests/unit-tests/CMakeLists.txt 2017-08-30 15:50:38 +0000
@@ -122,7 +122,6 @@
122122
123 exampleserverconfig123 exampleserverconfig
124 mirdraw124 mirdraw
125 demo-shell
126 mircommon125 mircommon
127 client_platform_common126 client_platform_common
128 server_platform_common127 server_platform_common
@@ -166,7 +165,6 @@
166165
167 exampleserverconfig166 exampleserverconfig
168 mirdraw167 mirdraw
169 demo-shell
170 mircommon168 mircommon
171 client_platform_common169 client_platform_common
172170
173171
=== modified file 'tests/unit-tests/compositor/test_default_display_buffer_compositor.cpp'
--- tests/unit-tests/compositor/test_default_display_buffer_compositor.cpp 2017-07-28 17:00:43 +0000
+++ tests/unit-tests/compositor/test_default_display_buffer_compositor.cpp 2017-08-30 15:50:38 +0000
@@ -18,7 +18,6 @@
1818
19#include "src/server/compositor/default_display_buffer_compositor.h"19#include "src/server/compositor/default_display_buffer_compositor.h"
20#include "mir/compositor/display_buffer_compositor.h"20#include "mir/compositor/display_buffer_compositor.h"
21#include "mir/compositor/decoration.h"
22#include "src/server/report/null_report_factory.h"21#include "src/server/report/null_report_factory.h"
23#include "mir/compositor/scene.h"22#include "mir/compositor/scene.h"
24#include "mir/renderer/renderer.h"23#include "mir/renderer/renderer.h"
@@ -74,11 +73,6 @@
74 {73 {
75 }74 }
7675
77 std::unique_ptr<mc::Decoration> decoration() const override
78 {
79 return nullptr;
80 }
81
82private:76private:
83 std::shared_ptr<mg::Renderable> const renderable_;77 std::shared_ptr<mg::Renderable> const renderable_;
84};78};
@@ -346,7 +340,6 @@
346 }340 }
347341
348 MOCK_CONST_METHOD0(renderable, std::shared_ptr<mir::graphics::Renderable>());342 MOCK_CONST_METHOD0(renderable, std::shared_ptr<mir::graphics::Renderable>());
349 MOCK_CONST_METHOD0(decoration, std::unique_ptr<mc::Decoration>());
350 MOCK_METHOD0(rendered, void());343 MOCK_METHOD0(rendered, void());
351 MOCK_METHOD0(occluded, void());344 MOCK_METHOD0(occluded, void());
352};345};
353346
=== modified file 'tests/unit-tests/scene/test_basic_surface.cpp'
--- tests/unit-tests/scene/test_basic_surface.cpp 2017-07-28 17:00:43 +0000
+++ tests/unit-tests/scene/test_basic_surface.cpp 2017-08-30 15:50:38 +0000
@@ -229,24 +229,10 @@
229 EXPECT_EQ(trans, got);229 EXPECT_EQ(trans, got);
230}230}
231231
232TEST_F(BasicSurfaceTest, test_surface_set_alpha_notifies_changes)
233{
234 using namespace testing;
235 EXPECT_CALL(mock_callback, call())
236 .Times(1);
237
238 surface.add_observer(observer);
239
240 float alpha = 0.5f;
241 surface.set_alpha(0.5f);
242 EXPECT_THAT(alpha, FloatEq(surface.alpha()));
243}
244
245TEST_F(BasicSurfaceTest, test_surface_is_opaque_by_default)232TEST_F(BasicSurfaceTest, test_surface_is_opaque_by_default)
246{233{
247 using namespace testing;234 using namespace testing;
248235
249 EXPECT_THAT(1.0f, FloatEq(surface.alpha()));
250 auto renderables = surface.generate_renderables(compositor_id);236 auto renderables = surface.generate_renderables(compositor_id);
251 ASSERT_THAT(renderables.size(), testing::Eq(1));237 ASSERT_THAT(renderables.size(), testing::Eq(1));
252 EXPECT_FALSE(renderables[0]->shaped());238 EXPECT_FALSE(renderables[0]->shaped());
253239
=== modified file 'tests/unit-tests/scene/test_surface.cpp'
--- tests/unit-tests/scene/test_surface.cpp 2017-07-28 17:00:43 +0000
+++ tests/unit-tests/scene/test_surface.cpp 2017-08-30 15:50:38 +0000
@@ -331,27 +331,6 @@
331 }331 }
332}332}
333333
334TEST_F(SurfaceCreation, test_surface_set_alpha)
335{
336 using namespace testing;
337
338 float alpha = 0.5f;
339
340 surface.set_alpha(alpha);
341 EXPECT_FLOAT_EQ(alpha, surface.alpha());
342 auto renderables = surface.generate_renderables(nullptr);
343 ASSERT_THAT(renderables.size(), Ge(1));
344 EXPECT_FLOAT_EQ(alpha, renderables[0]->alpha());
345
346 alpha = 0.1;
347
348 surface.set_alpha(alpha);
349 EXPECT_FLOAT_EQ(alpha, surface.alpha());
350 renderables = surface.generate_renderables(nullptr);
351 ASSERT_THAT(renderables.size(), Ge(1));
352 EXPECT_FLOAT_EQ(alpha, renderables[0]->alpha());
353}
354
355TEST_F(SurfaceCreation, consume_calls_send_event)334TEST_F(SurfaceCreation, consume_calls_send_event)
356{335{
357 using namespace testing;336 using namespace testing;
358337
=== modified file 'tests/unit-tests/scene/test_surface_stack.cpp'
--- tests/unit-tests/scene/test_surface_stack.cpp 2017-07-28 17:00:43 +0000
+++ tests/unit-tests/scene/test_surface_stack.cpp 2017-08-30 15:50:38 +0000
@@ -22,7 +22,6 @@
22#include "mir/scene/observer.h"22#include "mir/scene/observer.h"
23#include "mir/scene/surface_creation_parameters.h"23#include "mir/scene/surface_creation_parameters.h"
24#include "mir/compositor/scene_element.h"24#include "mir/compositor/scene_element.h"
25#include "mir/compositor/decoration.h"
26#include "src/server/report/null_report_factory.h"25#include "src/server/report/null_report_factory.h"
27#include "src/server/scene/basic_surface.h"26#include "src/server/scene/basic_surface.h"
28#include "src/server/compositor/stream.h"27#include "src/server/compositor/stream.h"
@@ -226,63 +225,6 @@
226 SceneElementForStream(stub_buffer_stream2)));225 SceneElementForStream(stub_buffer_stream2)));
227}226}
228227
229TEST_F(SurfaceStack, decor_name_is_surface_name)
230{
231 using namespace testing;
232
233 ms::SurfaceStack stack{report};
234 auto surface = std::make_shared<ms::BasicSurface>(
235 std::string("Mary had a little lamb"),
236 geom::Rectangle{{},{}},
237 mir_pointer_unconfined,
238 std::list<ms::StreamInfo> { { std::make_shared<mtd::StubBufferStream>(), {}, {} } },
239 std::shared_ptr<mg::CursorImage>(),
240 report);
241 stack.add_surface(surface, default_params.input_mode);
242 surface->configure(mir_window_attrib_visibility,
243 mir_window_visibility_exposed);
244
245 auto elements = stack.scene_elements_for(compositor_id);
246 ASSERT_EQ(1, elements.size());
247
248 auto& element = elements.front();
249
250 auto decor = element->decoration();
251 ASSERT_THAT(decor, Ne(nullptr));
252 EXPECT_EQ(mc::Decoration::Type::surface, decor->type);
253 EXPECT_EQ("Mary had a little lamb", decor->name);
254}
255
256TEST_F(SurfaceStack, gets_surface_renames)
257{
258 using namespace testing;
259
260 ms::SurfaceStack stack{report};
261 auto surface = std::make_shared<ms::BasicSurface>(
262 std::string("username@hostname: /"),
263 geom::Rectangle{{},{}},
264 mir_pointer_unconfined,
265 std::list<ms::StreamInfo> { { std::make_shared<mtd::StubBufferStream>(), {}, {} } },
266 std::shared_ptr<mg::CursorImage>(),
267 report);
268 stack.add_surface(surface, default_params.input_mode);
269 surface->configure(mir_window_attrib_visibility,
270 mir_window_visibility_exposed);
271
272 // (change directory in shell app)
273 surface->rename("username@hostname: ~/Documents");
274
275 auto elements = stack.scene_elements_for(compositor_id);
276 ASSERT_EQ(1, elements.size());
277
278 auto& element = elements.front();
279
280 auto decor = element->decoration();
281 ASSERT_THAT(decor, Ne(nullptr));
282 EXPECT_EQ(mc::Decoration::Type::surface, decor->type);
283 EXPECT_EQ("username@hostname: ~/Documents", decor->name);
284}
285
286TEST_F(SurfaceStack, scene_counts_pending_accurately)228TEST_F(SurfaceStack, scene_counts_pending_accurately)
287{229{
288 using namespace testing;230 using namespace testing;

Subscribers

People subscribed via source and target branches