Mir

Merge lp:~afrantzis/mir/fix-incorrect-client-color-1172163 into lp:~mir-team/mir/trunk

Proposed by Alexandros Frantzis
Status: Merged
Approved by: Daniel van Vugt
Approved revision: no longer in the source branch.
Merged at revision: 662
Proposed branch: lp:~afrantzis/mir/fix-incorrect-client-color-1172163
Merge into: lp:~mir-team/mir/trunk
Diff against target: 179 lines (+110/-12)
3 files modified
examples/multiwin.c (+0/-6)
src/client/mir_surface.cpp (+2/-5)
tests/unit-tests/client/test_client_mir_surface.cpp (+108/-1)
To merge this branch: bzr merge lp:~afrantzis/mir/fix-incorrect-client-color-1172163
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Daniel van Vugt Approve
Alan Griffiths Approve
Review via email: mp+161992@code.launchpad.net

Commit message

client: Properly report a CPU region's pixel format

Description of the change

client: Properly report a CPU region's pixel format

To post a comment you must log in.
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

LGTM

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

Works for me. Bug fixed.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/multiwin.c'
2--- examples/multiwin.c 2013-04-24 07:50:13 +0000
3+++ examples/multiwin.c 2013-05-01 23:52:31 +0000
4@@ -52,12 +52,6 @@
5 switch (format)
6 {
7 case mir_pixel_format_abgr_8888:
8- /*
9- * XXX
10- * This is right according to the docs in mir_toolkit/c_types.h.
11- * However Mir seems to be mixing up red and blue, rendering this
12- * as ARGB on my system.
13- */
14 pixel =
15 (uint32_t)color->a << 24 |
16 (uint32_t)color->b << 16 |
17
18=== modified file 'src/client/mir_surface.cpp'
19--- src/client/mir_surface.cpp 2013-04-24 05:22:20 +0000
20+++ src/client/mir_surface.cpp 2013-05-01 23:52:31 +0000
21@@ -109,8 +109,7 @@
22 region_out.width = secured_region->width.as_uint32_t();
23 region_out.height = secured_region->height.as_uint32_t();
24 region_out.stride = secured_region->stride.as_uint32_t();
25- //todo: fix
26- region_out.pixel_format = mir_pixel_format_abgr_8888;
27+ region_out.pixel_format = static_cast<MirPixelFormat>(secured_region->format);
28
29 region_out.vaddr = secured_region->vaddr.get();
30 }
31@@ -142,9 +141,7 @@
32 better to have a more developed geometry::PixelFormat that can handle this */
33 geom::PixelFormat MirSurface::convert_ipc_pf_to_geometry(gp::int32 pf)
34 {
35- if (pf == mir_pixel_format_abgr_8888)
36- return geom::PixelFormat::abgr_8888;
37- return geom::PixelFormat::invalid;
38+ return static_cast<geom::PixelFormat>(pf);
39 }
40
41 void MirSurface::process_incoming_buffer()
42
43=== modified file 'tests/unit-tests/client/test_client_mir_surface.cpp'
44--- tests/unit-tests/client/test_client_mir_surface.cpp 2013-04-25 09:48:54 +0000
45+++ tests/unit-tests/client/test_client_mir_surface.cpp 2013-05-01 23:52:31 +0000
46@@ -60,6 +60,7 @@
47 width_sent = 891;
48 height_sent = 458;
49 pf_sent = mir_pixel_format_abgr_8888;
50+ stride_sent = 66;
51
52 input_fd = open("/dev/null", O_APPEND);
53 }
54@@ -108,7 +109,7 @@
55 {
56 server_package.data[i] = (global_buffer_id + i) * 2;
57 }
58- server_package.stride = 66;
59+ server_package.stride = stride_sent;
60 }
61
62 MirBufferPackage server_package;
63@@ -116,6 +117,7 @@
64 int width_sent;
65 int height_sent;
66 int pf_sent;
67+ int stride_sent;
68
69 int input_fd;
70
71@@ -558,3 +560,108 @@
72 EXPECT_EQ(mir_surface_state_unknown,
73 surface->attrib(mir_surface_attrib_state));
74 }
75+
76+namespace
77+{
78+
79+struct StubBuffer : public mcl::ClientBuffer
80+{
81+ StubBuffer(geom::Size size, geom::Stride stride, geom::PixelFormat pf)
82+ : size_{size}, stride_{stride}, pf_{pf}
83+ {
84+ }
85+
86+ std::shared_ptr<mcl::MemoryRegion> secure_for_cpu_write()
87+ {
88+ auto raw = new mcl::MemoryRegion{size_.width,
89+ size_.height,
90+ stride_,
91+ pf_,
92+ nullptr};
93+
94+ return std::shared_ptr<mcl::MemoryRegion>(raw);
95+ }
96+
97+ geom::Size size() const { return size_; }
98+ geom::Stride stride() const { return stride_; }
99+ geom::PixelFormat pixel_format() const { return pf_; }
100+ uint32_t age() const { return 0; }
101+ void increment_age() {}
102+ void mark_as_submitted() {}
103+
104+ std::shared_ptr<MirBufferPackage> get_buffer_package() const
105+ {
106+ return std::shared_ptr<MirBufferPackage>();
107+ }
108+
109+ MirNativeBuffer get_native_handle()
110+ {
111+ return MirNativeBuffer();
112+ }
113+
114+ geom::Size size_;
115+ geom::Stride stride_;
116+ geom::PixelFormat pf_;
117+};
118+
119+struct StubClientBufferFactory : public mcl::ClientBufferFactory
120+{
121+ std::shared_ptr<mcl::ClientBuffer> create_buffer(
122+ std::shared_ptr<MirBufferPackage> const& package,
123+ geom::Size size, geom::PixelFormat pf)
124+ {
125+ return std::make_shared<StubBuffer>(size,
126+ geom::Stride{package->stride},
127+ pf);
128+ }
129+};
130+
131+}
132+TEST_F(MirClientSurfaceTest, get_cpu_region_returns_correct_data)
133+{
134+ using namespace testing;
135+
136+ struct TestDataEntry
137+ {
138+ int width;
139+ int height;
140+ int stride;
141+ MirPixelFormat pf;
142+ };
143+
144+ std::vector<TestDataEntry> test_data{
145+ {100, 200, 300, mir_pixel_format_argb_8888},
146+ {101, 201, 301, mir_pixel_format_xrgb_8888},
147+ {102, 202, 302, mir_pixel_format_bgr_888}
148+ };
149+
150+ auto stub_buffer_factory = std::make_shared<StubClientBufferFactory>();
151+
152+ for (auto& td : test_data)
153+ {
154+ mock_server_tool->width_sent = td.width;
155+ mock_server_tool->height_sent = td.height;
156+ mock_server_tool->stride_sent = td.stride;
157+ mock_server_tool->pf_sent = td.pf;
158+
159+ auto surface = std::make_shared<MirSurface>(connection.get(),
160+ *client_comm_channel,
161+ logger,
162+ stub_buffer_factory,
163+ input_platform,
164+ params,
165+ &empty_callback,
166+ nullptr);
167+
168+ auto wait_handle = surface->get_create_wait_handle();
169+ wait_handle->wait_for_result();
170+
171+ MirGraphicsRegion region;
172+ surface->get_cpu_region(region);
173+
174+ EXPECT_EQ(mock_server_tool->width_sent, region.width);
175+ EXPECT_EQ(mock_server_tool->height_sent, region.height);
176+ EXPECT_EQ(mock_server_tool->stride_sent, region.stride);
177+ EXPECT_EQ(mock_server_tool->pf_sent, region.pixel_format);
178+ }
179+}

Subscribers

People subscribed via source and target branches