Mir

Merge lp:~kdub/mir/consumer-usage-bits into lp:mir

Proposed by Kevin DuBois
Status: Merged
Merged at revision: 2902
Proposed branch: lp:~kdub/mir/consumer-usage-bits
Merge into: lp:mir
Diff against target: 127 lines (+46/-2)
5 files modified
src/platforms/android/client/egl_native_surface_interpreter.cpp (+11/-2)
src/platforms/android/client/egl_native_surface_interpreter.h (+2/-0)
src/platforms/android/server/server_render_window.cpp (+2/-0)
tests/unit-tests/client/android/test_egl_native_surface_interpreter.cpp (+23/-0)
tests/unit-tests/graphics/android/test_server_interpreter.cpp (+8/-0)
To merge this branch: bzr merge lp:~kdub/mir/consumer-usage-bits
Reviewer Review Type Date Requested Status
Alexandros Frantzis (community) Approve
Daniel van Vugt Approve
PS Jenkins bot (community) continuous-integration Needs Fixing
Review via email: mp+269903@code.launchpad.net

Commit message

android: support the NATIVE_WINDOW_CONSUMER_USAGE_BITS query. We recently encountered a device that made use of this query.

Description of the change

android: support the NATIVE_WINDOW_CONSUMER_USAGE_BITS query. We recently encountered a device that made use of this query.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Cool.

Just a note the code would be slightly easier to follow and potentially more efficient without using these:
  + unsigned int const hardware_bits;
  + unsigned int const software_bits;
Although the optimizer will make it the same, it's still easier to read if you don't have to look elsewhere to see what flags are set.

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

Another side note: If you find yourself writing simple tests that essentially just replicate the implementation I believe it's better to not have those tests at all. They don't provide value because the implementer (or maintainer who might be changing things) is equally likely to break the test in the same way as the implementation. Because they believe the implementation is right and so just keep the test in sync with the implementation. So such tests provide no benefit.

Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/platforms/android/client/egl_native_surface_interpreter.cpp'
2--- src/platforms/android/client/egl_native_surface_interpreter.cpp 2015-06-18 14:33:10 +0000
3+++ src/platforms/android/client/egl_native_surface_interpreter.cpp 2015-09-02 12:23:57 +0000
4@@ -21,6 +21,7 @@
5 #include "mir/frontend/client_constants.h"
6 #include "mir/client_buffer.h"
7 #include <system/window.h>
8+#include <hardware/gralloc.h>
9 #include <stdexcept>
10
11 namespace mcla=mir::client::android;
12@@ -29,8 +30,11 @@
13 mcla::EGLNativeSurfaceInterpreter::EGLNativeSurfaceInterpreter(EGLNativeSurface& surface)
14 : surface(surface),
15 driver_pixel_format(-1),
16- sync_ops(std::make_shared<mga::RealSyncFileOps>())
17-
18+ sync_ops(std::make_shared<mga::RealSyncFileOps>()),
19+ hardware_bits( GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER ),
20+ software_bits(
21+ GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN |
22+ GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_TEXTURE )
23 {
24 }
25
26@@ -76,6 +80,11 @@
27 return 2;
28 case NATIVE_WINDOW_CONCRETE_TYPE:
29 return NATIVE_WINDOW_SURFACE;
30+ case NATIVE_WINDOW_CONSUMER_USAGE_BITS:
31+ if (surface.get_parameters().buffer_usage == mir_buffer_usage_hardware)
32+ return hardware_bits;
33+ else
34+ return software_bits;
35 default:
36 throw std::runtime_error("driver requested unsupported query");
37 }
38
39=== modified file 'src/platforms/android/client/egl_native_surface_interpreter.h'
40--- src/platforms/android/client/egl_native_surface_interpreter.h 2015-06-17 05:20:42 +0000
41+++ src/platforms/android/client/egl_native_surface_interpreter.h 2015-09-02 12:23:57 +0000
42@@ -52,6 +52,8 @@
43 EGLNativeSurface& surface;
44 int driver_pixel_format;
45 std::shared_ptr<graphics::android::SyncFileOps> const sync_ops;
46+ unsigned int const hardware_bits;
47+ unsigned int const software_bits;
48 };
49
50 }
51
52=== modified file 'src/platforms/android/server/server_render_window.cpp'
53--- src/platforms/android/server/server_render_window.cpp 2015-07-21 04:30:03 +0000
54+++ src/platforms/android/server/server_render_window.cpp 2015-09-02 12:23:57 +0000
55@@ -84,6 +84,8 @@
56 return 1;
57 case NATIVE_WINDOW_CONCRETE_TYPE:
58 return NATIVE_WINDOW_FRAMEBUFFER;
59+ case NATIVE_WINDOW_CONSUMER_USAGE_BITS:
60+ return GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB;
61 default:
62 {
63 std::stringstream sstream;
64
65=== modified file 'tests/unit-tests/client/android/test_egl_native_surface_interpreter.cpp'
66--- tests/unit-tests/client/android/test_egl_native_surface_interpreter.cpp 2015-06-25 03:00:08 +0000
67+++ tests/unit-tests/client/android/test_egl_native_surface_interpreter.cpp 2015-09-02 12:23:57 +0000
68@@ -25,6 +25,7 @@
69 #include "mir/test/doubles/stub_android_native_buffer.h"
70 #include "mir/test/fake_shared.h"
71 #include <system/window.h>
72+#include <hardware/gralloc.h>
73 #include <gmock/gmock.h>
74 #include <gtest/gtest.h>
75
76@@ -267,3 +268,25 @@
77 mcla::EGLNativeSurfaceInterpreter interpreter(mock_surface);
78 interpreter.dispatch_driver_request_buffer_count(new_size);
79 }
80+
81+TEST_F(AndroidInterpreter, returns_proper_usage_bits_based_on_surface)
82+{
83+ using namespace testing;
84+ MirSurfaceParameters const software = { "", 1, 2, mir_pixel_format_abgr_8888, mir_buffer_usage_software, 0 };
85+ MirSurfaceParameters const hardware = { "", 1, 2, mir_pixel_format_abgr_8888, mir_buffer_usage_hardware, 0 };
86+
87+ testing::NiceMock<MockMirSurface> mock_surface{surf_params};
88+ mcla::EGLNativeSurfaceInterpreter interpreter(mock_surface);
89+
90+ EXPECT_CALL(mock_surface, get_parameters())
91+ .Times(2)
92+ .WillOnce(Return(software))
93+ .WillOnce(Return(hardware));
94+
95+ auto const hardware_bits = GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER;
96+ auto const software_bits =
97+ GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN |
98+ GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_TEXTURE;
99+ EXPECT_THAT(interpreter.driver_requests_info(NATIVE_WINDOW_CONSUMER_USAGE_BITS), Eq(software_bits));
100+ EXPECT_THAT(interpreter.driver_requests_info(NATIVE_WINDOW_CONSUMER_USAGE_BITS), Eq(hardware_bits));
101+}
102
103=== modified file 'tests/unit-tests/graphics/android/test_server_interpreter.cpp'
104--- tests/unit-tests/graphics/android/test_server_interpreter.cpp 2015-06-25 03:00:08 +0000
105+++ tests/unit-tests/graphics/android/test_server_interpreter.cpp 2015-09-02 12:23:57 +0000
106@@ -26,6 +26,7 @@
107 #include "mir/test/fake_shared.h"
108 #include "mir/test/doubles/mock_android_native_buffer.h"
109 #include "mir_toolkit/common.h"
110+#include <hardware/gralloc.h>
111 #include <gtest/gtest.h>
112 #include <gmock/gmock.h>
113 #include <stdexcept>
114@@ -96,6 +97,13 @@
115 EXPECT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, render_window.driver_requests_info(NATIVE_WINDOW_FORMAT));
116 }
117
118+TEST_F(ServerRenderWindow, returns_usage_bits_for_fb)
119+{
120+ using namespace testing;
121+ auto bits = GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_FB;
122+ EXPECT_THAT(render_window.driver_requests_info(NATIVE_WINDOW_CONSUMER_USAGE_BITS), Eq(bits));
123+}
124+
125 TEST_F(ServerRenderWindow, returns_different_format_if_format_changes)
126 {
127 render_window.dispatch_driver_request_format(HAL_PIXEL_FORMAT_RGBX_8888);

Subscribers

People subscribed via source and target branches