Mir

Merge lp:~vanvugt/mir/fix-1193020 into lp:~mir-team/mir/trunk

Proposed by Daniel van Vugt
Status: Merged
Approved by: Daniel van Vugt
Approved revision: no longer in the source branch.
Merged at revision: 771
Proposed branch: lp:~vanvugt/mir/fix-1193020
Merge into: lp:~mir-team/mir/trunk
Diff against target: 225 lines (+68/-33)
6 files modified
include/server/mir/graphics/renderable.h (+1/-1)
include/server/mir/surfaces/surface.h (+4/-1)
include/test/mir_test_doubles/mock_renderable.h (+1/-1)
src/server/surfaces/surface.cpp (+36/-28)
tests/unit-tests/graphics/test_gl_renderer.cpp (+3/-2)
tests/unit-tests/surfaces/test_surface.cpp (+23/-0)
To merge this branch: bzr merge lp:~vanvugt/mir/fix-1193020
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Thomas Voß (community) Approve
Chris Halse Rogers Approve
Robert Ancell Approve
Review via email: mp+171070@code.launchpad.net

Commit message

Cache the transformation matrix; only recalculate it when some part of the
transformation changes. (LP: #1193020)

To post a comment you must log in.
Revision history for this message
Thomas Voß (thomas-voss) wrote :

Looks good, a minor niggle, though: If we cache the transformation matrix we should return a const reference instead of a copy. I won't block on it, though, and we can have a follow-up mp.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Kevin DuBois (kdub) wrote :

unit tests first in tdd :) I think the behavior with checking transformation_size is correct, but it would be nice to have a test to check the case where the buffer stream's size changes. (esp since it should be a short test)
other than that, seems ok.

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Thomas: Good point about a reference. It would change interfaces though.

Kevin: Good point about TDD. However the tests and testability changed significantly as my approach changed. The design of the tests unfortunately depended very much on the implementation in this case.

Revision history for this message
Thomas Voß (thomas-voss) wrote :

LGTM, and Daniel convinced me that the const-qualifier (despite the required mutable's) is a good idea for const callers.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Robert Ancell (robert-ancell) :
review: Approve
Revision history for this message
Chris Halse Rogers (raof) wrote :

Looks good to me.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Thomas Voß (thomas-voss) wrote :

LGTM.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'include/server/mir/graphics/renderable.h'
--- include/server/mir/graphics/renderable.h 2013-05-01 18:07:31 +0000
+++ include/server/mir/graphics/renderable.h 2013-06-25 05:59:27 +0000
@@ -47,7 +47,7 @@
47 virtual geometry::Point top_left() const = 0;47 virtual geometry::Point top_left() const = 0;
48 virtual geometry::Size size() const = 0;48 virtual geometry::Size size() const = 0;
49 virtual std::shared_ptr<surfaces::GraphicRegion> graphic_region() const = 0;49 virtual std::shared_ptr<surfaces::GraphicRegion> graphic_region() const = 0;
50 virtual glm::mat4 transformation() const = 0;50 virtual const glm::mat4& transformation() const = 0;
51 virtual float alpha() const = 0;51 virtual float alpha() const = 0;
52 virtual bool should_be_rendered() const = 0;52 virtual bool should_be_rendered() const = 0;
5353
5454
=== modified file 'include/server/mir/surfaces/surface.h'
--- include/server/mir/surfaces/surface.h 2013-06-24 22:54:22 +0000
+++ include/server/mir/surfaces/surface.h 2013-06-25 05:59:27 +0000
@@ -67,7 +67,7 @@
67 geometry::Point top_left() const;67 geometry::Point top_left() const;
68 geometry::Size size() const;68 geometry::Size size() const;
69 std::shared_ptr<GraphicRegion> graphic_region() const;69 std::shared_ptr<GraphicRegion> graphic_region() const;
70 glm::mat4 transformation() const;70 const glm::mat4& transformation() const override;
71 float alpha() const;71 float alpha() const;
72 bool should_be_rendered() const;72 bool should_be_rendered() const;
7373
@@ -90,6 +90,9 @@
90 std::shared_ptr<input::InputChannel> const input_channel;90 std::shared_ptr<input::InputChannel> const input_channel;
9191
92 glm::mat4 rotation_matrix;92 glm::mat4 rotation_matrix;
93 mutable glm::mat4 transformation_matrix;
94 mutable geometry::Size transformation_size;
95 mutable bool transformation_dirty;
93 float alpha_value;96 float alpha_value;
9497
95 bool is_hidden;98 bool is_hidden;
9699
=== modified file 'include/test/mir_test_doubles/mock_renderable.h'
--- include/test/mir_test_doubles/mock_renderable.h 2013-05-01 18:07:31 +0000
+++ include/test/mir_test_doubles/mock_renderable.h 2013-06-25 05:59:27 +0000
@@ -44,7 +44,7 @@
44 MOCK_CONST_METHOD0(top_left, geometry::Point());44 MOCK_CONST_METHOD0(top_left, geometry::Point());
45 MOCK_CONST_METHOD0(size, geometry::Size());45 MOCK_CONST_METHOD0(size, geometry::Size());
46 MOCK_CONST_METHOD0(graphic_region, std::shared_ptr<surfaces::GraphicRegion>());46 MOCK_CONST_METHOD0(graphic_region, std::shared_ptr<surfaces::GraphicRegion>());
47 MOCK_CONST_METHOD0(transformation, glm::mat4());47 MOCK_CONST_METHOD0(transformation, const glm::mat4&());
48 MOCK_CONST_METHOD0(alpha, float());48 MOCK_CONST_METHOD0(alpha, float());
49 MOCK_CONST_METHOD0(should_be_rendered, bool());49 MOCK_CONST_METHOD0(should_be_rendered, bool());
5050
5151
=== modified file 'src/server/surfaces/surface.cpp'
--- src/server/surfaces/surface.cpp 2013-06-24 22:54:22 +0000
+++ src/server/surfaces/surface.cpp 2013-06-25 05:59:27 +0000
@@ -46,6 +46,7 @@
46 top_left_point(top_left),46 top_left_point(top_left),
47 buffer_stream(buffer_stream),47 buffer_stream(buffer_stream),
48 input_channel(input_channel),48 input_channel(input_channel),
49 transformation_dirty(true),
49 alpha_value(1.0f),50 alpha_value(1.0f),
50 is_hidden(false),51 is_hidden(false),
51 buffer_count(0),52 buffer_count(0),
@@ -73,12 +74,14 @@
73void ms::Surface::move_to(geometry::Point const& top_left)74void ms::Surface::move_to(geometry::Point const& top_left)
74{75{
75 top_left_point = top_left;76 top_left_point = top_left;
77 transformation_dirty = true;
76 notify_change();78 notify_change();
77}79}
7880
79void ms::Surface::set_rotation(float degrees, glm::vec3 const& axis)81void ms::Surface::set_rotation(float degrees, glm::vec3 const& axis)
80{82{
81 rotation_matrix = glm::rotate(glm::mat4{1.0f}, degrees, axis);83 rotation_matrix = glm::rotate(glm::mat4{1.0f}, degrees, axis);
84 transformation_dirty = true;
82 notify_change();85 notify_change();
83}86}
8487
@@ -109,38 +112,43 @@
109 return compositor_buffer();112 return compositor_buffer();
110}113}
111114
112glm::mat4 ms::Surface::transformation() const115const glm::mat4& ms::Surface::transformation() const
113{116{
114 const geom::Size sz = size();117 const geom::Size sz = size();
115118
116 const glm::vec3 top_left_vec{top_left_point.x.as_int(),119 if (transformation_dirty || transformation_size != sz)
117 top_left_point.y.as_int(),120 {
121 const glm::vec3 top_left_vec{top_left_point.x.as_int(),
122 top_left_point.y.as_int(),
123 0.0f};
124 const glm::vec3 size_vec{sz.width.as_uint32_t(),
125 sz.height.as_uint32_t(),
118 0.0f};126 0.0f};
119 const glm::vec3 size_vec{sz.width.as_uint32_t(),127
120 sz.height.as_uint32_t(),128 /* Get the center of the renderable's area */
121 0.0f};129 const glm::vec3 center_vec{top_left_vec + 0.5f * size_vec};
122130
123 /* Get the center of the renderable's area */131 /*
124 const glm::vec3 center_vec{top_left_vec + 0.5f * size_vec};132 * Every renderable is drawn using a 1x1 quad centered at 0,0.
125133 * We need to transform and scale that quad to get to its final position
126 /*134 * and size.
127 * Every renderable is drawn using a 1x1 quad centered at 0,0.135 *
128 * We need to transform and scale that quad to get to its final position136 * 1. We scale the quad vertices (from 1x1 to wxh)
129 * and size.137 * 2. We move the quad to its final position. Note that because the quad
130 *138 * is centered at (0,0), we need to translate by center_vec, not
131 * 1. We scale the quad vertices (from 1x1 to wxh)139 * top_left_vec.
132 * 2. We move the quad to its final position. Note that because the quad140 */
133 * is centered at (0,0), we need to translate by center_vec, not141 glm::mat4 pos_size_matrix;
134 * top_left_vec.142 pos_size_matrix = glm::translate(pos_size_matrix, center_vec);
135 */143 pos_size_matrix = glm::scale(pos_size_matrix, size_vec);
136 glm::mat4 pos_size_matrix;144
137 pos_size_matrix = glm::translate(pos_size_matrix, center_vec);145 // Rotate, then scale, then translate
138 pos_size_matrix = glm::scale(pos_size_matrix, size_vec);146 transformation_matrix = pos_size_matrix * rotation_matrix;
139147 transformation_size = sz;
140 // Rotate, then scale, then translate148 transformation_dirty = false;
141 const glm::mat4 transformation = pos_size_matrix * rotation_matrix;149 }
142150
143 return transformation;151 return transformation_matrix;
144}152}
145153
146float ms::Surface::alpha() const154float ms::Surface::alpha() const
147155
=== modified file 'tests/unit-tests/graphics/test_gl_renderer.cpp'
--- tests/unit-tests/graphics/test_gl_renderer.cpp 2013-06-12 15:36:31 +0000
+++ tests/unit-tests/graphics/test_gl_renderer.cpp 2013-06-25 05:59:27 +0000
@@ -34,6 +34,7 @@
34using testing::SetArgPointee;34using testing::SetArgPointee;
35using testing::InSequence;35using testing::InSequence;
36using testing::Return;36using testing::Return;
37using testing::ReturnRef;
37using testing::_;38using testing::_;
3839
39namespace mtd=mir::test::doubles;40namespace mtd=mir::test::doubles;
@@ -277,6 +278,7 @@
277 mtd::MockGL mock_gl;278 mtd::MockGL mock_gl;
278 mir::geometry::Size display_size;279 mir::geometry::Size display_size;
279 std::unique_ptr<mg::GLRenderer> renderer;280 std::unique_ptr<mg::GLRenderer> renderer;
281 glm::mat4 trans;
280};282};
281283
282void NullGraphicRegionDeleter(mtd::MockGraphicRegion * /* gr */)284void NullGraphicRegionDeleter(mtd::MockGraphicRegion * /* gr */)
@@ -303,7 +305,6 @@
303305
304 mir::geometry::Point tl;306 mir::geometry::Point tl;
305 mir::geometry::Size s;307 mir::geometry::Size s;
306 glm::mat4 transformation;
307308
308 tl.x = mir::geometry::X(1);309 tl.x = mir::geometry::X(1);
309 tl.y = mir::geometry::Y(2);310 tl.y = mir::geometry::Y(2);
@@ -319,7 +320,7 @@
319 EXPECT_CALL(mock_gl, glActiveTexture(GL_TEXTURE0));320 EXPECT_CALL(mock_gl, glActiveTexture(GL_TEXTURE0));
320321
321 EXPECT_CALL(rd, transformation())322 EXPECT_CALL(rd, transformation())
322 .WillOnce(Return(transformation));323 .WillOnce(ReturnRef(trans));
323 EXPECT_CALL(mock_gl, glUniformMatrix4fv(transform_uniform_location, 1, GL_FALSE, _));324 EXPECT_CALL(mock_gl, glUniformMatrix4fv(transform_uniform_location, 1, GL_FALSE, _));
324 EXPECT_CALL(rd, alpha())325 EXPECT_CALL(rd, alpha())
325 .WillOnce(Return(0));326 .WillOnce(Return(0));
326327
=== modified file 'tests/unit-tests/surfaces/test_surface.cpp'
--- tests/unit-tests/surfaces/test_surface.cpp 2013-06-24 22:54:22 +0000
+++ tests/unit-tests/surfaces/test_surface.cpp 2013-06-25 05:59:27 +0000
@@ -171,6 +171,8 @@
171171
172 ON_CALL(*mock_buffer_stream, secure_client_buffer())172 ON_CALL(*mock_buffer_stream, secure_client_buffer())
173 .WillByDefault(Return(std::make_shared<mtd::StubBuffer>()));173 .WillByDefault(Return(std::make_shared<mtd::StubBuffer>()));
174 ON_CALL(*mock_buffer_stream, stream_size())
175 .WillByDefault(Return(size));
174 }176 }
175177
176 std::string surface_name;178 std::string surface_name;
@@ -340,6 +342,27 @@
340 surf.set_rotation(60.0f, glm::vec3{0.0f, 0.0f, 1.0f});342 surf.set_rotation(60.0f, glm::vec3{0.0f, 0.0f, 1.0f});
341}343}
342344
345TEST_F(SurfaceCreation, test_surface_transformation_cache_refreshes)
346{
347 using namespace testing;
348
349 const geom::Point origin{geom::X{77}, geom::Y{88}};
350
351 ms::Surface surf{surface_name, origin, mock_buffer_stream,
352 std::shared_ptr<mi::InputChannel>(), null_change_cb};
353
354 glm::mat4 t0 = surf.transformation();
355 surf.move_to(geom::Point{geom::X{55}, geom::Y{66}});
356 EXPECT_NE(t0, surf.transformation());
357
358 surf.move_to(origin);
359 EXPECT_EQ(t0, surf.transformation());
360
361 surf.set_rotation(60.0f, glm::vec3{0.0f, 0.0f, 1.0f});
362 glm::mat4 t1 = surf.transformation();
363 EXPECT_NE(t0, t1);
364}
365
343TEST_F(SurfaceCreation, test_surface_texture_locks_back_buffer_from_stream)366TEST_F(SurfaceCreation, test_surface_texture_locks_back_buffer_from_stream)
344{367{
345 using namespace testing;368 using namespace testing;

Subscribers

People subscribed via source and target branches