Mir

Merge lp:~kdub/mir/hwc-integration into lp:~mir-team/mir/trunk

Proposed by Kevin DuBois
Status: Merged
Approved by: Kevin DuBois
Approved revision: no longer in the source branch.
Merged at revision: 553
Proposed branch: lp:~kdub/mir/hwc-integration
Merge into: lp:~mir-team/mir/trunk
Diff against target: 1515 lines (+711/-480)
22 files modified
3rd_party/android-fbtype/FramebufferNativeWindow.cpp (+0/-2)
include/test/mir_test/hw_mock.h (+10/-0)
src/server/graphics/android/CMakeLists.txt (+3/-2)
src/server/graphics/android/android_display_allocator.cpp (+40/-0)
src/server/graphics/android/android_display_allocator.h (+42/-0)
src/server/graphics/android/android_display_factory.cpp (+60/-32)
src/server/graphics/android/android_display_factory.h (+19/-7)
src/server/graphics/android/android_display_selector.cpp (+0/-58)
src/server/graphics/android/android_display_selector.h (+0/-52)
src/server/graphics/android/android_hwc_factory.cpp (+27/-0)
src/server/graphics/android/android_hwc_factory.h (+41/-0)
src/server/graphics/android/android_platform.cpp (+7/-6)
src/server/graphics/android/display_allocator.h (+51/-0)
src/server/graphics/android/display_factory.h (+10/-16)
src/server/graphics/android/display_selector.h (+0/-49)
src/server/graphics/android/hwc_factory.h (+48/-0)
tests/integration-tests/graphics/android/CMakeLists.txt (+1/-0)
tests/integration-tests/graphics/android/test_buffer_integration.cpp (+43/-171)
tests/integration-tests/graphics/android/test_display_integration.cpp (+150/-0)
tests/unit-tests/graphics/android/CMakeLists.txt (+1/-1)
tests/unit-tests/graphics/android/test_android_display_factory.cpp (+125/-78)
tests/unit-tests/graphics/egl_mock/hw_mock.cpp (+33/-6)
To merge this branch: bzr merge lp:~kdub/mir/hwc-integration
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alexandros Frantzis (community) Approve
Robert Carr (community) Approve
Alan Griffiths Needs Information
Review via email: mp+156089@code.launchpad.net

Commit message

tie together hwc bits for the nexus4. ( Nexus 4 display should work properly now. ) also improve some of the integration testing for android drivers

Description of the change

Tie together the HWC1.1 so the server can allocate HWC1.1 displays. This involved moving about how the AndroidFBFactory works, and eliminating the AndroidFBSelector class. (it makes more sense now that we just have factory classes for allocating a display)

In light of mir's developments since the test was written, test_buffer_integration.cpp was just sort of a random cobbling together of bits that could have been cleaner. I split up the test into two files, one that tests that the code can allocate android buffers, and another that tests that we can get a gles context with the displays. I added two hwc display integration tests, these are not skipped on systems that lack hwc 1.1 support.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

210 + [](hwc_composer_device_1* device)

Indentation is too deep.

634 + EXPECT_NO_THROW({
890 + EXPECT_NO_THROW({
901 + EXPECT_NO_THROW(
... and at other places

As discussed in a previous MP, there is no real benefit in using EXPECT_NO_THROW.

805 +#include "src/server/graphics/android/android_buffer_allocator.h"
809 +#include "mir/graphics/buffer_initializer.h"
... and possibly others

From a quick glance it seems that there are unused header files in this file.

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

217 + hwc_device = hwc_factory->create_hwc_1_1(hwc_dev);

This can throw (because the ctor of HWC11Device can throw). In the context of the FBFactory, would it make sense for this to be considered a non-fatal failure (like failing to open the hardware composer in the first place), so we can fall back to GPU rendering?

1048 + std::shared_ptr<MockHWCFactory> mock_hwc_factory;

Can be const.

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

265 + std::shared_ptr<Display> create_hwc_display() const;
266 + bool can_create_hwc_display() const;
267 std::shared_ptr<Display> create_gpu_display() const;

This sort of interface makes me wonder if the logic is on the right class.

Why isn't it "std::shared_ptr<Display> create_display() const;" without the user needing to know the type of display?

review: Needs Information
Revision history for this message
Kevin DuBois (kdub) wrote :

> 265 + std::shared_ptr<Display> create_hwc_display() const;
> 266 + bool can_create_hwc_display() const;
> 267 std::shared_ptr<Display> create_gpu_display() const;
>
> This sort of interface makes me wonder if the logic is on the right class.
>
> Why isn't it "std::shared_ptr<Display> create_display() const;" without the
> user needing to know the type of display?

Thinking a bit more (and on a fresh day) I think that this a case where the test shaped the code to be useful to the test more than to the user (a test bug, of a sort!). I think the solution is to introduce an interface for the creation of mg::Display, which will eliminate this 'wart' function

Revision history for this message
Kevin DuBois (kdub) wrote :

> 210 + [](hwc_composer_device_1* device)
>
> Indentation is too deep.
>
> 634 + EXPECT_NO_THROW({
> 890 + EXPECT_NO_THROW({
> 901 + EXPECT_NO_THROW(
> ... and at other places
>
> As discussed in a previous MP, there is no real benefit in using
> EXPECT_NO_THROW.
>
I can eliminate these, although it feels strange to have a test where the expectation is just 'dont explode the system'. I'll find another way of stating the intention of the test.

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

> 210 + [](hwc_composer_device_1* device)
>
> Indentation is too deep.
made it less deep, but i'm not really sure about the spacing policy. at any rate, it looks better than it did

>
> 634 + EXPECT_NO_THROW({
> 890 + EXPECT_NO_THROW({
> 901 + EXPECT_NO_THROW(
> ... and at other places
>
> As discussed in a previous MP, there is no real benefit in using
> EXPECT_NO_THROW.

These tests were testing things that are tested later in more complicated tests in the suite, so I removed the tests using these (the things we aren't expecting a throw with are created in the other tests)

>
> 805 +#include "src/server/graphics/android/android_buffer_allocator.h"
> 809 +#include "mir/graphics/buffer_initializer.h"
> ... and possibly others
>
did an audit on the headers

Revision history for this message
Kevin DuBois (kdub) wrote :

> 265 + std::shared_ptr<Display> create_hwc_display() const;
> 266 + bool can_create_hwc_display() const;
> 267 std::shared_ptr<Display> create_gpu_display() const;
>
> This sort of interface makes me wonder if the logic is on the right class.
>
> Why isn't it "std::shared_ptr<Display> create_display() const;" without the
> user needing to know the type of display?

I reworked the tests... this interface now just has a create_fb() method

Revision history for this message
Kevin DuBois (kdub) wrote :

> 217 + hwc_device = hwc_factory->create_hwc_1_1(hwc_dev);
>
> This can throw (because the ctor of HWC11Device can throw). In the context of
> the FBFactory, would it make sense for this to be considered a non-fatal
> failure (like failing to open the hardware composer in the first place), so we
> can fall back to GPU rendering?
>

this is a good point, but I think at the time its best to let the error stop the server from initializing, as we don't have a way to log it in the display classes yet. i put a TODO in

> 1048 + std::shared_ptr<MockHWCFactory> mock_hwc_factory;
>
> Can be const.
changed

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

jenkins is down for maintenence... hopefully comes back up over weekend

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

317 +mga::AndroidFBFactory::AndroidFBFactory(std::shared_ptr<DisplayFactory> const& fb_factory,
318 + std::shared_ptr<HWCFactory> const& hwc_factory)
319 + : fb_factory(fb_factory),

s/fb_factory/display_factory/ ?

36 + virtual std::shared_ptr<Display> create_fb() const = 0;

This seems a bit strange, since we have an Android*FB*Factory::create_*fb*() returning a std::shared_ptr<*Display*>. I would expect this to be called an AndroidDisplayFactory::create_display(). We have used "Display" in different contexts (mg::Display and HWCDisplay/AndroidDisplay) and it causes some confusion/conflict.
Perhaps we should rename FBFactory->DisplayFactory, and the existing DisplayFactory->SomethingElse (FramebufferFactory, HWCDisplay->HWCFramebuffer, AndroidDisplay->GPUFramebuffer)? Thoughts?

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

^^ with the jenkins failures... i had cancelled these builds (one of which i started manually, and then the script also started a job for)... rev 594 is still building

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

Looks good!

I did have the thought when reading that with the pattern established by AndroidDisplayAllocator->AndroidDisplayFactory that HWCFactory is perhaps an HWCAllocator (given that it allows the user to select between particular interfaces for construction as opposed to abstracting this detail).

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

627 + virtual std::shared_ptr<Display> create_fb() const = 0;

s/create_fb/create_display/ ?

Revision history for this message
Kevin DuBois (kdub) wrote :

> 627 + virtual std::shared_ptr<Display> create_fb() const = 0;
>
> s/create_fb/create_display/ ?

updated to fix naming

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

1247 +struct MockDisplayFactory

MockDisplayAllocator

1330 + mga::AndroidDisplayFactory fb_factory(mock_display_factory, mock_hwc_factory);

s/fb_factory/display_factory/
s/mock_display_factory/mock_display_allocator/

Pre-approving to avoid blocking for another day.

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 '3rd_party/android-fbtype/FramebufferNativeWindow.cpp'
2--- 3rd_party/android-fbtype/FramebufferNativeWindow.cpp 2013-03-15 21:41:15 +0000
3+++ 3rd_party/android-fbtype/FramebufferNativeWindow.cpp 2013-04-02 16:08:22 +0000
4@@ -260,8 +260,6 @@
5
6 if (fenceFd > 0)
7 {
8- int timeout = -1;
9- ioctl(fenceFd, SYNC_IOC_WAIT, &timeout);
10 close(fenceFd);
11 }
12
13
14=== modified file 'include/test/mir_test/hw_mock.h'
15--- include/test/mir_test/hw_mock.h 2013-03-29 16:51:35 +0000
16+++ include/test/mir_test/hw_mock.h 2013-04-02 16:08:22 +0000
17@@ -43,6 +43,15 @@
18 hw_device_t& mock_hw_device;
19 };
20
21+class FailingHardwareModuleStub : public hw_module
22+{
23+public:
24+ FailingHardwareModuleStub();
25+ static int hw_open(const struct hw_module_t* module, const char*, struct hw_device_t** device);
26+ static int hw_close(struct hw_device_t*);
27+ hw_module_methods_t gr_methods;
28+};
29+
30 class HardwareAccessMock
31 {
32 public:
33@@ -51,6 +60,7 @@
34
35 MOCK_METHOD2(hw_get_module, int(const char *id, const struct hw_module_t**));
36
37+ bool open_count_matches_close();
38 std::shared_ptr<alloc_device_t> mock_alloc_device;
39 std::shared_ptr<hwc_composer_device_1> mock_hwc_device;
40
41
42=== modified file 'src/server/graphics/android/CMakeLists.txt'
43--- src/server/graphics/android/CMakeLists.txt 2013-03-22 21:24:13 +0000
44+++ src/server/graphics/android/CMakeLists.txt 2013-04-02 16:08:22 +0000
45@@ -14,9 +14,10 @@
46 android_display.cpp
47 hwc_display.cpp
48 hwc11_device.cpp
49- android_display_selector.cpp
50+ android_hwc_factory.cpp
51+ android_display_allocator.cpp
52 android_framebuffer_window.cpp
53- android_fb_factory.cpp
54+ android_display_factory.cpp
55 android_alloc_adaptor.cpp
56 )
57
58
59=== added file 'src/server/graphics/android/android_display_allocator.cpp'
60--- src/server/graphics/android/android_display_allocator.cpp 1970-01-01 00:00:00 +0000
61+++ src/server/graphics/android/android_display_allocator.cpp 2013-04-02 16:08:22 +0000
62@@ -0,0 +1,40 @@
63+/*
64+ * Copyright © 2013 Canonical Ltd.
65+ *
66+ * This program is free software: you can redistribute it and/or modify it
67+ * under the terms of the GNU Lesser General Public License version 3,
68+ * as published by the Free Software Foundation.
69+ *
70+ * This program is distributed in the hope that it will be useful,
71+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
72+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
73+ * GNU General Public License for more details.
74+ *
75+ * You should have received a copy of the GNU Lesser General Public License
76+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
77+ *
78+ * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
79+ */
80+
81+#include "android_display_allocator.h"
82+#include "android_display.h"
83+#include "hwc_display.h"
84+#include "android_framebuffer_window.h"
85+
86+#include <ui/FramebufferNativeWindow.h>
87+
88+namespace mga=mir::graphics::android;
89+
90+std::shared_ptr<mga::AndroidDisplay> mga::AndroidDisplayAllocator::create_gpu_display() const
91+{
92+ auto native_window = std::make_shared< ::android::FramebufferNativeWindow>();
93+ auto window = std::make_shared<mga::AndroidFramebufferWindow> (native_window);
94+ return std::make_shared<AndroidDisplay>(window);
95+}
96+
97+std::shared_ptr<mga::HWCDisplay> mga::AndroidDisplayAllocator::create_hwc_display(std::shared_ptr<HWCDevice> const& hwc_device) const
98+{
99+ auto native_window = std::make_shared< ::android::FramebufferNativeWindow>();
100+ auto window = std::make_shared<mga::AndroidFramebufferWindow> (native_window);
101+ return std::make_shared<HWCDisplay>(window, hwc_device);
102+}
103
104=== added file 'src/server/graphics/android/android_display_allocator.h'
105--- src/server/graphics/android/android_display_allocator.h 1970-01-01 00:00:00 +0000
106+++ src/server/graphics/android/android_display_allocator.h 2013-04-02 16:08:22 +0000
107@@ -0,0 +1,42 @@
108+/*
109+ * Copyright © 2013 Canonical Ltd.
110+ *
111+ * This program is free software: you can redistribute it and/or modify it
112+ * under the terms of the GNU Lesser General Public License version 3,
113+ * as published by the Free Software Foundation.
114+ *
115+ * This program is distributed in the hope that it will be useful,
116+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
117+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
118+ * GNU General Public License for more details.
119+ *
120+ * You should have received a copy of the GNU Lesser General Public License
121+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
122+ *
123+ * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
124+ */
125+
126+#ifndef MIR_GRAPHICS_ANDROID_ANDROID_DISPLAY_ALLOCATOR_H_
127+#define MIR_GRAPHICS_ANDROID_ANDROID_DISPLAY_ALLOCATOR_H_
128+
129+#include "display_allocator.h"
130+
131+namespace mir
132+{
133+namespace graphics
134+{
135+namespace android
136+{
137+
138+class AndroidDisplayAllocator : public DisplayAllocator
139+{
140+public:
141+ std::shared_ptr<AndroidDisplay> create_gpu_display() const;
142+ std::shared_ptr<HWCDisplay> create_hwc_display(std::shared_ptr<HWCDevice> const&) const;
143+
144+};
145+
146+}
147+}
148+}
149+#endif /* MIR_GRAPHICS_ANDROID_ANDROID_DISPLAY_ALLOCATOR_H_ */
150
151=== renamed file 'src/server/graphics/android/android_fb_factory.cpp' => 'src/server/graphics/android/android_display_factory.cpp'
152--- src/server/graphics/android/android_fb_factory.cpp 2013-03-29 16:51:35 +0000
153+++ src/server/graphics/android/android_display_factory.cpp 2013-04-02 16:08:22 +0000
154@@ -16,43 +16,71 @@
155 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
156 */
157
158-#include "android_fb_factory.h"
159-#include "android_framebuffer_window.h"
160+#include "android_display_factory.h"
161+#include "hwc_factory.h"
162+#include "display_allocator.h"
163 #include "android_display.h"
164 #include "hwc_display.h"
165
166-#include <ui/FramebufferNativeWindow.h>
167+#include <boost/throw_exception.hpp>
168+#include <stdexcept>
169
170 namespace mg=mir::graphics;
171 namespace mga=mir::graphics::android;
172
173-namespace
174-{
175-//TODO: kdub temporary construction of a hwc device while I work on the real one
176-class EmptyHWC : public mga::HWCDevice
177-{
178- void wait_for_vsync()
179- {
180- }
181- void commit_frame()
182- {
183- }
184-};
185-}
186-
187-std::shared_ptr<mg::Display> mga::AndroidFBFactory::create_hwc1_1_gpu_display() const
188-{
189- auto android_window = std::make_shared< ::android::FramebufferNativeWindow>();
190- auto window = std::make_shared<mga::AndroidFramebufferWindow> (android_window);
191- auto empty_hwc = std::make_shared<EmptyHWC>();
192- return std::make_shared<mga::HWCDisplay>(window, empty_hwc);
193-}
194-
195-/* note: gralloc seems to choke when this is opened/closed more than once per process. must investigate drivers further */
196-std::shared_ptr<mg::Display> mga::AndroidFBFactory::create_gpu_display() const
197-{
198- auto android_window = std::make_shared< ::android::FramebufferNativeWindow>();
199- auto window = std::make_shared<mga::AndroidFramebufferWindow> (android_window);
200-
201- return std::make_shared<mga::AndroidDisplay>(window);
202+mga::AndroidDisplayFactory::AndroidDisplayFactory(std::shared_ptr<DisplayAllocator> const& display_factory,
203+ std::shared_ptr<HWCFactory> const& hwc_factory)
204+ : display_factory(display_factory),
205+ hwc_factory(hwc_factory)
206+{
207+ const hw_module_t *hw_module;
208+ int rc = hw_get_module(HWC_HARDWARE_MODULE_ID, &hw_module);
209+ if ((rc != 0) || (hw_module == nullptr))
210+ {
211+ return;
212+ }
213+
214+ try
215+ {
216+ setup_hwc_dev(hw_module);
217+ } catch (std::runtime_error &e)
218+ {
219+ /* TODO: log error. this is nonfatal, we'll just create the backup display */
220+ }
221+}
222+
223+void mga::AndroidDisplayFactory::setup_hwc_dev(const hw_module_t* module)
224+{
225+ if ((!module->methods) || !(module->methods->open))
226+ {
227+ BOOST_THROW_EXCEPTION(std::runtime_error("display factory cannot create hwc display"));
228+ }
229+
230+ hwc_composer_device_1* hwc_device_raw = nullptr;
231+ int rc = module->methods->open(module, HWC_HARDWARE_COMPOSER, reinterpret_cast<hw_device_t**>(&hwc_device_raw));
232+
233+ if ((rc != 0) || (hwc_device_raw == nullptr))
234+ {
235+ BOOST_THROW_EXCEPTION(std::runtime_error("display hwc module unusable"));
236+ }
237+
238+ hwc_dev = std::shared_ptr<hwc_composer_device_1>(hwc_device_raw,
239+ [](hwc_composer_device_1* device)
240+ {
241+ device->common.close((hw_device_t*) device);
242+ });
243+}
244+
245+std::shared_ptr<mg::Display> mga::AndroidDisplayFactory::create_display() const
246+{
247+ if (hwc_dev && (hwc_dev->common.version == HWC_DEVICE_API_VERSION_1_1))
248+ {
249+ //TODO: once we can log things here, if this throws, we should log and recover to a gpu display
250+ auto hwc_device = hwc_factory->create_hwc_1_1(hwc_dev);
251+ return display_factory->create_hwc_display(hwc_device);
252+ }
253+ else
254+ {
255+ return display_factory->create_gpu_display();
256+ }
257 }
258
259=== renamed file 'src/server/graphics/android/android_fb_factory.h' => 'src/server/graphics/android/android_display_factory.h'
260--- src/server/graphics/android/android_fb_factory.h 2013-03-15 22:11:07 +0000
261+++ src/server/graphics/android/android_display_factory.h 2013-04-02 16:08:22 +0000
262@@ -16,10 +16,11 @@
263 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
264 */
265
266-#ifndef MIR_GRAPHICS_ANDROID_ANDROID_FB_FACTORY_H_
267-#define MIR_GRAPHICS_ANDROID_ANDROID_FB_FACTORY_H_
268+#ifndef MIR_GRAPHICS_ANDROID_ANDROID_DISPLAY_FACTORY_H_
269+#define MIR_GRAPHICS_ANDROID_ANDROID_DISPLAY_FACTORY_H_
270
271-#include "fb_factory.h"
272+#include "display_factory.h"
273+#include <hardware/hwcomposer.h>
274
275 namespace mir
276 {
277@@ -28,15 +29,26 @@
278 namespace android
279 {
280
281-class AndroidFBFactory : public FBFactory
282+class HWCFactory;
283+class HWCDevice;
284+class DisplayAllocator;
285+class AndroidDisplayFactory : public DisplayFactory
286 {
287 public:
288- std::shared_ptr<Display> create_hwc1_1_gpu_display() const;
289- std::shared_ptr<Display> create_gpu_display() const;
290+ AndroidDisplayFactory(std::shared_ptr<DisplayAllocator> const& display_factory, std::shared_ptr<HWCFactory> const& hwc_factory);
291+
292+ std::shared_ptr<Display> create_display() const;
293+
294+private:
295+ void setup_hwc_dev(const hw_module_t* module);
296+
297+ std::shared_ptr<DisplayAllocator> display_factory;
298+ std::shared_ptr<HWCFactory> hwc_factory;
299+ std::shared_ptr<hwc_composer_device_1> hwc_dev;
300 };
301
302 }
303 }
304 }
305
306-#endif /* MIR_GRAPHICS_ANDROID_ANDROID_FB_FACTORY_H_ */
307+#endif /* MIR_GRAPHICS_ANDROID_ANDROID_DISPLAY_FACTORY_H_ */
308
309=== removed file 'src/server/graphics/android/android_display_selector.cpp'
310--- src/server/graphics/android/android_display_selector.cpp 2013-03-29 16:51:35 +0000
311+++ src/server/graphics/android/android_display_selector.cpp 1970-01-01 00:00:00 +0000
312@@ -1,58 +0,0 @@
313-/*
314- * Copyright © 2013 Canonical Ltd.
315- *
316- * This program is free software: you can redistribute it and/or modify
317- * it under the terms of the GNU General Public License version 3 as
318- * published by the Free Software Foundation.
319- *
320- * This program is distributed in the hope that it will be useful,
321- * but WITHOUT ANY WARRANTY; without even the implied warranty of
322- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
323- * GNU General Public License for more details.
324- *
325- * You should have received a copy of the GNU General Public License
326- * along with this program. If not, see <http://www.gnu.org/licenses/>.
327- *
328- * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
329- */
330-
331-#include "android_display_selector.h"
332-#include "android_fb_factory.h"
333-
334-#include <hardware/hwcomposer.h>
335-
336-namespace mg=mir::graphics;
337-namespace mga=mir::graphics::android;
338-
339-mga::AndroidDisplaySelector::AndroidDisplaySelector(std::shared_ptr<mga::FBFactory> const& factory)
340- : fb_factory(factory)
341-{
342- const hw_module_t *hw_module;
343- int rc = hw_get_module(HWC_HARDWARE_MODULE_ID, &hw_module);
344-
345- if (rc != 0)
346- {
347- /* could not find hw module. use GL fallback */
348- allocate_primary_fb = std::bind(&FBFactory::create_gpu_display, fb_factory);
349- return;
350- }
351-
352- hw_device_t* hwc_device;
353- rc = hw_module->methods->open(hw_module, HWC_HARDWARE_COMPOSER, &hwc_device);
354-
355- if ((hwc_device != nullptr) &&
356- (rc == 0 ) &&
357- (hwc_device->version == HWC_DEVICE_API_VERSION_1_1))
358- {
359- allocate_primary_fb = std::bind(&FBFactory::create_hwc1_1_gpu_display, fb_factory);
360- }
361- else
362- {
363- allocate_primary_fb = std::bind(&FBFactory::create_gpu_display, fb_factory);
364- }
365-}
366-
367-std::shared_ptr<mg::Display> mga::AndroidDisplaySelector::primary_display()
368-{
369- return allocate_primary_fb();
370-}
371
372=== removed file 'src/server/graphics/android/android_display_selector.h'
373--- src/server/graphics/android/android_display_selector.h 2013-03-29 16:51:35 +0000
374+++ src/server/graphics/android/android_display_selector.h 1970-01-01 00:00:00 +0000
375@@ -1,52 +0,0 @@
376-/*
377- * Copyright © 2013 Canonical Ltd.
378- *
379- * This program is free software: you can redistribute it and/or modify
380- * it under the terms of the GNU General Public License version 3 as
381- * published by the Free Software Foundation.
382- *
383- * This program is distributed in the hope that it will be useful,
384- * but WITHOUT ANY WARRANTY; without even the implied warranty of
385- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
386- * GNU General Public License for more details.
387- *
388- * You should have received a copy of the GNU General Public License
389- * along with this program. If not, see <http://www.gnu.org/licenses/>.
390- *
391- * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
392- */
393-
394-#ifndef MIR_GRAPHICS_ANDROID_ANDROID_DISPLAY_SELECTOR_H_
395-#define MIR_GRAPHICS_ANDROID_ANDROID_DISPLAY_SELECTOR_H_
396-
397-#include "display_selector.h"
398-
399-namespace mir
400-{
401-namespace graphics
402-{
403-
404-class Display;
405-
406-namespace android
407-{
408-
409-class FBFactory;
410-
411-class AndroidDisplaySelector : public DisplaySelector
412-{
413-public:
414- AndroidDisplaySelector(std::shared_ptr<FBFactory> const& factory);
415- std::shared_ptr<Display> primary_display();
416-
417-private:
418- std::shared_ptr<FBFactory> fb_factory;
419- std::shared_ptr<Display> primary_hwc_display;
420- std::function<std::shared_ptr<Display>()> allocate_primary_fb;
421-};
422-
423-}
424-}
425-}
426-
427-#endif /* MIR_GRAPHICS_ANDROID_ANDROID_DISPLAY_SELECTOR_H_ */
428
429=== added file 'src/server/graphics/android/android_hwc_factory.cpp'
430--- src/server/graphics/android/android_hwc_factory.cpp 1970-01-01 00:00:00 +0000
431+++ src/server/graphics/android/android_hwc_factory.cpp 2013-04-02 16:08:22 +0000
432@@ -0,0 +1,27 @@
433+/*
434+ * Copyright © 2013 Canonical Ltd.
435+ *
436+ * This program is free software: you can redistribute it and/or modify it
437+ * under the terms of the GNU Lesser General Public License version 3,
438+ * as published by the Free Software Foundation.
439+ *
440+ * This program is distributed in the hope that it will be useful,
441+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
442+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
443+ * GNU General Public License for more details.
444+ *
445+ * You should have received a copy of the GNU Lesser General Public License
446+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
447+ *
448+ * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
449+ */
450+
451+#include "android_hwc_factory.h"
452+#include "hwc11_device.h"
453+
454+namespace mga=mir::graphics::android;
455+
456+std::shared_ptr<mga::HWCDevice> mga::AndroidHWCFactory::create_hwc_1_1(std::shared_ptr<hwc_composer_device_1> const& hwc_device) const
457+{
458+ return std::make_shared<mga::HWC11Device>(hwc_device);
459+}
460
461=== added file 'src/server/graphics/android/android_hwc_factory.h'
462--- src/server/graphics/android/android_hwc_factory.h 1970-01-01 00:00:00 +0000
463+++ src/server/graphics/android/android_hwc_factory.h 2013-04-02 16:08:22 +0000
464@@ -0,0 +1,41 @@
465+/*
466+ * Copyright © 2013 Canonical Ltd.
467+ *
468+ * This program is free software: you can redistribute it and/or modify it
469+ * under the terms of the GNU Lesser General Public License version 3,
470+ * as published by the Free Software Foundation.
471+ *
472+ * This program is distributed in the hope that it will be useful,
473+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
474+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
475+ * GNU General Public License for more details.
476+ *
477+ * You should have received a copy of the GNU Lesser General Public License
478+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
479+ *
480+ * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
481+ */
482+
483+#ifndef MIR_GRAPHICS_ANDROID_ANDROID_HWC_FACTORY_H_
484+#define MIR_GRAPHICS_ANDROID_ANDROID_HWC_FACTORY_H_
485+
486+#include "hwc_factory.h"
487+
488+namespace mir
489+{
490+namespace graphics
491+{
492+namespace android
493+{
494+
495+class HWCDevice;
496+class AndroidHWCFactory : public HWCFactory
497+{
498+public:
499+ std::shared_ptr<HWCDevice> create_hwc_1_1(std::shared_ptr<hwc_composer_device_1> const& hwc_device) const;
500+};
501+
502+}
503+}
504+}
505+#endif /* MIR_GRAPHICS_ANDROID_ANDROID_HWC_FACTORY_H_ */
506
507=== modified file 'src/server/graphics/android/android_platform.cpp'
508--- src/server/graphics/android/android_platform.cpp 2013-03-22 17:08:01 +0000
509+++ src/server/graphics/android/android_platform.cpp 2013-04-02 16:08:22 +0000
510@@ -19,9 +19,9 @@
511
512 #include "android_platform.h"
513 #include "android_buffer_allocator.h"
514-#include "android_display.h"
515-#include "android_display_selector.h"
516-#include "android_fb_factory.h"
517+#include "android_hwc_factory.h"
518+#include "android_display_allocator.h"
519+#include "android_display_factory.h"
520 #include "mir/graphics/platform_ipc_package.h"
521 #include "mir/compositor/buffer_id.h"
522
523@@ -37,9 +37,10 @@
524
525 std::shared_ptr<mg::Display> mga::AndroidPlatform::create_display()
526 {
527- auto fb_factory = std::make_shared<mga::AndroidFBFactory>();
528- auto selector = std::make_shared<mga::AndroidDisplaySelector>(fb_factory);
529- return selector->primary_display();
530+ auto hwc_factory = std::make_shared<mga::AndroidHWCFactory>();
531+ auto display_allocator = std::make_shared<mga::AndroidDisplayAllocator>();
532+ auto display_factory = std::make_shared<mga::AndroidDisplayFactory>(display_allocator, hwc_factory);
533+ return display_factory->create_display();
534 }
535
536 std::shared_ptr<mg::PlatformIPCPackage> mga::AndroidPlatform::get_ipc_package()
537
538=== added file 'src/server/graphics/android/display_allocator.h'
539--- src/server/graphics/android/display_allocator.h 1970-01-01 00:00:00 +0000
540+++ src/server/graphics/android/display_allocator.h 2013-04-02 16:08:22 +0000
541@@ -0,0 +1,51 @@
542+/*
543+ * Copyright © 2013 Canonical Ltd.
544+ *
545+ * This program is free software: you can redistribute it and/or modify it
546+ * under the terms of the GNU Lesser General Public License version 3,
547+ * as published by the Free Software Foundation.
548+ *
549+ * This program is distributed in the hope that it will be useful,
550+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
551+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
552+ * GNU General Public License for more details.
553+ *
554+ * You should have received a copy of the GNU Lesser General Public License
555+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
556+ *
557+ * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
558+ */
559+
560+#ifndef MIR_GRAPHICS_ANDROID_DISPLAY_ALLOCATOR_H_
561+#define MIR_GRAPHICS_ANDROID_DISPLAY_ALLOCATOR_H_
562+
563+#include <memory>
564+
565+namespace mir
566+{
567+namespace graphics
568+{
569+namespace android
570+{
571+
572+class AndroidDisplay;
573+class HWCDevice;
574+class HWCDisplay;
575+class DisplayAllocator
576+{
577+public:
578+ DisplayAllocator() = default;
579+ virtual ~DisplayAllocator() {}
580+
581+ virtual std::shared_ptr<AndroidDisplay> create_gpu_display() const = 0;
582+ virtual std::shared_ptr<HWCDisplay> create_hwc_display(std::shared_ptr<HWCDevice> const&) const = 0;
583+
584+private:
585+ DisplayAllocator(DisplayAllocator const&) = delete;
586+ DisplayAllocator& operator=(DisplayAllocator const&) = delete;
587+};
588+
589+}
590+}
591+}
592+#endif /* MIR_GRAPHICS_ANDROID_DISPLAY_ALLOCATOR_H_ */
593
594=== renamed file 'src/server/graphics/android/fb_factory.h' => 'src/server/graphics/android/display_factory.h'
595--- src/server/graphics/android/fb_factory.h 2013-03-29 16:51:35 +0000
596+++ src/server/graphics/android/display_factory.h 2013-04-02 16:08:22 +0000
597@@ -16,8 +16,8 @@
598 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
599 */
600
601-#ifndef MIR_GRAPHICS_ANDROID_FB_FACTORY_H_
602-#define MIR_GRAPHICS_ANDROID_FB_FACTORY_H_
603+#ifndef MIR_GRAPHICS_ANDROID_DISPLAY_FACTORY_H_
604+#define MIR_GRAPHICS_ANDROID_DISPLAY_FACTORY_H_
605
606 #include <memory>
607
608@@ -30,27 +30,21 @@
609 namespace android
610 {
611
612-class FBFactory
613+class DisplayFactory
614 {
615 public:
616- virtual ~FBFactory() {}
617-
618- //creates a display that will render primarily via the gpu and OpenGLES 2.0, but will use the hwc
619- //module (version 1.1) for additional functionality, such as vsync timings, and hotplug detection
620- virtual std::shared_ptr<Display> create_hwc1_1_gpu_display() const = 0;
621-
622- //creates a display that will render primarily via the gpu and OpenGLES 2.0. Primarily a fall-back mode,
623- //this display is similar to what Android does when /system/lib/hw/hwcomposer.*.so modules are not present
624- virtual std::shared_ptr<Display> create_gpu_display() const = 0;
625+ virtual ~DisplayFactory() {}
626+
627+ virtual std::shared_ptr<Display> create_display() const = 0;
628
629 protected:
630- FBFactory() = default;
631- FBFactory& operator=(FBFactory const&) = delete;
632- FBFactory(FBFactory const&) = delete;
633+ DisplayFactory() = default;
634+ DisplayFactory& operator=(DisplayFactory const&) = delete;
635+ DisplayFactory(DisplayFactory const&) = delete;
636 };
637
638 }
639 }
640 }
641
642-#endif /* MIR_GRAPHICS_ANDROID_FB_FACTORY_H_ */
643+#endif /* MIR_GRAPHICS_ANDROID_DISPLAY_FACTORY_H_ */
644
645=== removed file 'src/server/graphics/android/display_selector.h'
646--- src/server/graphics/android/display_selector.h 2013-03-29 16:51:35 +0000
647+++ src/server/graphics/android/display_selector.h 1970-01-01 00:00:00 +0000
648@@ -1,49 +0,0 @@
649-/*
650- * Copyright © 2013 Canonical Ltd.
651- *
652- * This program is free software: you can redistribute it and/or modify
653- * it under the terms of the GNU General Public License version 3 as
654- * published by the Free Software Foundation.
655- *
656- * This program is distributed in the hope that it will be useful,
657- * but WITHOUT ANY WARRANTY; without even the implied warranty of
658- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
659- * GNU General Public License for more details.
660- *
661- * You should have received a copy of the GNU General Public License
662- * along with this program. If not, see <http://www.gnu.org/licenses/>.
663- *
664- * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
665- */
666-
667-#ifndef MIR_GRAPHICS_ANDROID_DISPLAY_SELECTOR_H_
668-#define MIR_GRAPHICS_ANDROID_DISPLAY_SELECTOR_H_
669-
670-#include <memory>
671-
672-namespace mir
673-{
674-namespace graphics
675-{
676-
677-class Display;
678-namespace android
679-{
680-
681-class DisplaySelector
682-{
683-public:
684- virtual std::shared_ptr<Display> primary_display() = 0;
685- virtual ~DisplaySelector() {}
686-
687-protected:
688- DisplaySelector() = default;
689- DisplaySelector& operator=(DisplaySelector const&) = delete;
690- DisplaySelector(DisplaySelector const&) = delete;
691-};
692-
693-}
694-}
695-}
696-
697-#endif /* MIR_GRAPHICS_ANDROID_DISPLAY_SELECTOR_H_ */
698
699=== added file 'src/server/graphics/android/hwc_factory.h'
700--- src/server/graphics/android/hwc_factory.h 1970-01-01 00:00:00 +0000
701+++ src/server/graphics/android/hwc_factory.h 2013-04-02 16:08:22 +0000
702@@ -0,0 +1,48 @@
703+/*
704+ * Copyright © 2013 Canonical Ltd.
705+ *
706+ * This program is free software: you can redistribute it and/or modify it
707+ * under the terms of the GNU Lesser General Public License version 3,
708+ * as published by the Free Software Foundation.
709+ *
710+ * This program is distributed in the hope that it will be useful,
711+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
712+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
713+ * GNU General Public License for more details.
714+ *
715+ * You should have received a copy of the GNU Lesser General Public License
716+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
717+ *
718+ * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
719+ */
720+
721+#ifndef MIR_GRAPHICS_ANDROID_HWC_FACTORY_H_
722+#define MIR_GRAPHICS_ANDROID_HWC_FACTORY_H_
723+
724+#include <memory>
725+#include <hardware/hwcomposer.h>
726+
727+namespace mir
728+{
729+namespace graphics
730+{
731+namespace android
732+{
733+
734+class HWCDevice;
735+class HWCFactory
736+{
737+public:
738+ HWCFactory() = default;
739+ virtual ~HWCFactory() {}
740+
741+ virtual std::shared_ptr<HWCDevice> create_hwc_1_1(std::shared_ptr<hwc_composer_device_1> const& hwc_device) const = 0;
742+private:
743+ HWCFactory(HWCFactory const&) = delete;
744+ HWCFactory& operator=(HWCFactory const&) = delete;
745+};
746+
747+}
748+}
749+}
750+#endif /* MIR_GRAPHICS_ANDROID_HWC_FACTORY_H_ */
751
752=== modified file 'tests/integration-tests/graphics/android/CMakeLists.txt'
753--- tests/integration-tests/graphics/android/CMakeLists.txt 2013-03-13 04:54:15 +0000
754+++ tests/integration-tests/graphics/android/CMakeLists.txt 2013-04-02 16:08:22 +0000
755@@ -1,6 +1,7 @@
756 list(
757 APPEND INTEGRATION_TESTS_SRCS
758 ${CMAKE_CURRENT_SOURCE_DIR}/test_buffer_integration.cpp
759+ ${CMAKE_CURRENT_SOURCE_DIR}/test_display_integration.cpp
760 )
761
762 set(
763
764=== modified file 'tests/integration-tests/graphics/android/test_buffer_integration.cpp'
765--- tests/integration-tests/graphics/android/test_buffer_integration.cpp 2013-03-21 03:32:59 +0000
766+++ tests/integration-tests/graphics/android/test_buffer_integration.cpp 2013-04-02 16:08:22 +0000
767@@ -16,28 +16,23 @@
768 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
769 */
770
771-#include "src/server/graphics/android/android_platform.h"
772+#include "mir/graphics/platform.h"
773 #include "src/server/graphics/android/android_buffer_allocator.h"
774-#include "src/server/graphics/android/android_display.h"
775 #include "mir/graphics/buffer_initializer.h"
776 #include "mir/graphics/null_display_report.h"
777 #include "mir/compositor/swapper_factory.h"
778 #include "mir/compositor/buffer_swapper.h"
779-#include "mir/compositor/buffer_bundle_surfaces.h"
780 #include "mir/compositor/buffer_properties.h"
781
782-#include "mir/draw/graphics.h"
783 #include "mir_test/draw/android_graphics.h"
784 #include "mir_test/draw/patterns.h"
785
786 #include <gtest/gtest.h>
787-#include <stdexcept>
788
789 namespace mc=mir::compositor;
790 namespace geom=mir::geometry;
791 namespace mga=mir::graphics::android;
792 namespace mg=mir::graphics;
793-namespace md=mir::draw;
794 namespace mtd=mir::test::draw;
795
796 namespace
797@@ -46,190 +41,67 @@
798 class AndroidBufferIntegration : public ::testing::Test
799 {
800 protected:
801- static void SetUpTestCase()
802- {
803- ASSERT_FALSE(mtd::is_surface_flinger_running());
804- ASSERT_NO_THROW(
805- {
806- platform = mg::create_platform(std::make_shared<mg::NullDisplayReport>());
807- display = platform->create_display();
808- });
809- }
810-
811 virtual void SetUp()
812 {
813+ platform = mg::create_platform(std::make_shared<mg::NullDisplayReport>());
814 ASSERT_TRUE(platform != NULL);
815- ASSERT_TRUE(display != NULL);
816
817- null_buffer_initializer = std::make_shared<mg::NullBufferInitializer>();
818- allocator = platform->create_buffer_allocator(null_buffer_initializer);
819- strategy = std::make_shared<mc::SwapperFactory>(allocator);
820- size = geom::Size{geom::Width{gl_animation.texture_width()},
821- geom::Height{gl_animation.texture_height()}};
822+ size = geom::Size{geom::Width{334},
823+ geom::Height{122}};
824 pf = geom::PixelFormat::abgr_8888;
825 buffer_properties = mc::BufferProperties{size, pf, mc::BufferUsage::software};
826+ null_buffer_initializer = std::make_shared<mg::NullBufferInitializer>();
827 }
828
829- md::glAnimationBasic gl_animation;
830 std::shared_ptr<mg::BufferInitializer> null_buffer_initializer;
831- std::shared_ptr<mc::GraphicBufferAllocator> allocator;
832- std::shared_ptr<mc::SwapperFactory> strategy;
833 geom::Size size;
834 geom::PixelFormat pf;
835 mc::BufferProperties buffer_properties;
836 mtd::TestGrallocMapper sw_renderer;
837
838- /* note about display: android drivers seem to only be able to open fb once
839- per process (gralloc's framebuffer_close() doesn't seem to work). once we
840- figure out why, we can put display in the test fixture */
841- static std::shared_ptr<mg::Platform> platform;
842- static std::shared_ptr<mg::Display> display;
843+ std::shared_ptr<mg::Platform> platform;
844 };
845
846-std::shared_ptr<mg::Display> AndroidBufferIntegration::display;
847-std::shared_ptr<mg::Platform> AndroidBufferIntegration::platform;
848-
849-}
850-
851-TEST_F(AndroidBufferIntegration, post_does_not_throw)
852-{
853- using namespace testing;
854-
855- EXPECT_NO_THROW(
856- {
857- display->for_each_display_buffer([](mg::DisplayBuffer& buffer)
858- {
859- buffer.post_update();
860- });
861- });
862-}
863-
864-TEST(AndroidBufferIntegrationBasic, alloc_does_not_throw)
865-{
866- using namespace testing;
867-
868- auto null_buffer_initializer = std::make_shared<mg::NullBufferInitializer>();
869- EXPECT_NO_THROW({
870+}
871+
872+TEST_F(AndroidBufferIntegration, allocator_can_create_sw_buffer)
873+{
874+ using namespace testing;
875+
876+ auto allocator = std::make_shared<mga::AndroidBufferAllocator>(null_buffer_initializer);
877+
878+ mc::BufferProperties sw_properties{size, pf, mc::BufferUsage::software};
879+ auto test_buffer = allocator->alloc_buffer(sw_properties);
880+
881+ auto region = sw_renderer.get_graphic_region_from_package(test_buffer->get_ipc_package(), size);
882+ mtd::DrawPatternSolid red_pattern(0xFF0000FF);
883+ red_pattern.draw(region);
884+ EXPECT_TRUE(red_pattern.check(region));
885+}
886+
887+TEST_F(AndroidBufferIntegration, allocator_can_create_hw_buffer)
888+{
889+ using namespace testing;
890+
891+ mc::BufferProperties hw_properties{size, pf, mc::BufferUsage::hardware};
892+ auto allocator = std::make_shared<mga::AndroidBufferAllocator>(null_buffer_initializer);
893+
894+ //TODO: kdub it is a bit trickier to test that a gpu can render... just check creation for now
895+ auto test_buffer = allocator->alloc_buffer(hw_properties);
896+ EXPECT_NE(nullptr, test_buffer);
897+}
898+
899+TEST_F(AndroidBufferIntegration, swapper_creation_is_sane)
900+{
901+ using namespace testing;
902+
903 auto allocator = std::make_shared<mga::AndroidBufferAllocator>(null_buffer_initializer);
904 auto strategy = std::make_shared<mc::SwapperFactory>(allocator);
905- });
906-
907-}
908-TEST_F(AndroidBufferIntegration, swapper_creation_ok)
909-{
910- using namespace testing;
911-
912- mc::BufferProperties actual;
913-
914- EXPECT_NO_THROW({
915- std::unique_ptr<mc::BufferSwapper> swapper = strategy->create_swapper(actual, buffer_properties);
916- });
917-}
918-
919-TEST_F(AndroidBufferIntegration, swapper_returns_non_null)
920-{
921- using namespace testing;
922-
923- mc::BufferProperties actual;
924+ mc::BufferProperties actual;
925+ mc::BufferID id{34};
926+ auto swapper = strategy->create_swapper(actual, buffer_properties);
927 std::shared_ptr<mc::Buffer> returned_buffer;
928- mc::BufferID id{34};
929-
930- std::unique_ptr<mc::BufferSwapper> swapper = strategy->create_swapper(actual, buffer_properties);
931-
932 swapper->client_acquire(returned_buffer, id);
933+
934 EXPECT_NE(nullptr, returned_buffer);
935 }
936-
937-TEST_F(AndroidBufferIntegration, buffer_ok_with_egl_context)
938-{
939- using namespace testing;
940-
941- mtd::DrawPatternSolid red_pattern(0xFF0000FF);
942- auto allocator = std::make_shared<mga::AndroidBufferAllocator>(null_buffer_initializer);
943- auto strategy = std::make_shared<mc::SwapperFactory>(allocator);
944-
945- geom::PixelFormat pf(geom::PixelFormat::abgr_8888);
946- mc::BufferProperties buffer_properties{size, pf, mc::BufferUsage::software};
947- mc::BufferProperties actual;
948- std::unique_ptr<mc::BufferSwapper> swapper = strategy->create_swapper(actual, buffer_properties);
949- auto bundle = std::make_shared<mc::BufferBundleSurfaces>(std::move(swapper));
950-
951- gl_animation.init_gl();
952-
953- auto client_buffer = bundle->secure_client_buffer();
954- auto ipc_package = client_buffer->get_ipc_package();
955- auto region = sw_renderer.get_graphic_region_from_package(ipc_package, size);
956- red_pattern.draw(region);
957- client_buffer.reset();
958-
959- auto texture_res = bundle->lock_back_buffer();
960- gl_animation.render_gl();
961- display->for_each_display_buffer([](mg::DisplayBuffer& buffer)
962- {
963- buffer.post_update();
964- });
965- texture_res.reset();
966-}
967-
968-TEST_F(AndroidBufferIntegration, DISABLED_buffer_ok_with_egl_context_repeat)
969-{
970- using namespace testing;
971-
972- mtd::DrawPatternSolid red_pattern(0xFF0000FF);
973- mtd::DrawPatternSolid green_pattern(0xFF00FF00);
974-
975- auto allocator = std::make_shared<mga::AndroidBufferAllocator>(null_buffer_initializer);
976- auto strategy = std::make_shared<mc::SwapperFactory>(allocator);
977-
978- geom::PixelFormat pf(geom::PixelFormat::abgr_8888);
979- mc::BufferProperties buffer_properties{size, pf, mc::BufferUsage::software};
980- mc::BufferProperties actual;
981- std::unique_ptr<mc::BufferSwapper> swapper = strategy->create_swapper(actual, buffer_properties);
982- auto bundle = std::make_shared<mc::BufferBundleSurfaces>(std::move(swapper));
983-
984- gl_animation.init_gl();
985-
986- for(;;)
987- {
988- /* buffer 0 */
989- auto client_buffer = bundle->secure_client_buffer();
990- auto ipc_package = client_buffer->get_ipc_package();
991- auto region = sw_renderer.get_graphic_region_from_package(ipc_package, size);
992- red_pattern.draw(region);
993- client_buffer.reset();
994-
995- auto texture_res = bundle->lock_back_buffer();
996- gl_animation.render_gl();
997- display->for_each_display_buffer([](mg::DisplayBuffer& buffer)
998- {
999- buffer.post_update();
1000- });
1001- texture_res.reset();
1002- sleep(1);
1003-
1004- /* buffer 1 */
1005- client_buffer = bundle->secure_client_buffer();
1006- ipc_package = client_buffer->get_ipc_package();
1007- region = sw_renderer.get_graphic_region_from_package(ipc_package, size);
1008- green_pattern.draw(region);
1009- client_buffer.reset();
1010-
1011- texture_res = bundle->lock_back_buffer();
1012- gl_animation.render_gl();
1013- display->for_each_display_buffer([](mg::DisplayBuffer& buffer)
1014- {
1015- buffer.post_update();
1016- });
1017- texture_res.reset();
1018- sleep(1);
1019- }
1020-
1021-}
1022-
1023-TEST_F(AndroidBufferIntegration, display_cleanup_ok)
1024-{
1025- EXPECT_NO_THROW(
1026- {
1027- display.reset();
1028- });
1029-}
1030
1031=== added file 'tests/integration-tests/graphics/android/test_display_integration.cpp'
1032--- tests/integration-tests/graphics/android/test_display_integration.cpp 1970-01-01 00:00:00 +0000
1033+++ tests/integration-tests/graphics/android/test_display_integration.cpp 2013-04-02 16:08:22 +0000
1034@@ -0,0 +1,150 @@
1035+/*
1036+ * Copyright © 2012 Canonical Ltd.
1037+ *
1038+ * This program is free software: you can redistribute it and/or modify
1039+ * it under the terms of the GNU General Public License version 3 as
1040+ * published by the Free Software Foundation.
1041+ *
1042+ * This program is distributed in the hope that it will be useful,
1043+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1044+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1045+ * GNU General Public License for more details.
1046+ *
1047+ * You should have received a copy of the GNU General Public License
1048+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1049+ *
1050+ * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
1051+ */
1052+
1053+#include "src/server/graphics/android/android_display.h"
1054+#include "src/server/graphics/android/hwc11_device.h"
1055+#include "src/server/graphics/android/hwc_display.h"
1056+
1057+#include "mir/draw/graphics.h"
1058+#include "mir_test/draw/android_graphics.h"
1059+
1060+#include <gtest/gtest.h>
1061+#include <stdexcept>
1062+
1063+#include <ui/FramebufferNativeWindow.h>
1064+#include <hardware/hwcomposer.h>
1065+
1066+namespace mc=mir::compositor;
1067+namespace geom=mir::geometry;
1068+namespace mga=mir::graphics::android;
1069+namespace mg=mir::graphics;
1070+namespace md=mir::draw;
1071+namespace mtd=mir::test::draw;
1072+
1073+namespace
1074+{
1075+
1076+class AndroidGPUDisplay : public ::testing::Test
1077+{
1078+protected:
1079+ static void SetUpTestCase()
1080+ {
1081+ /* this is an important precondition for acquiring the display! */
1082+ ASSERT_FALSE(mtd::is_surface_flinger_running());
1083+
1084+ /* note about android_window: OMAP4 drivers seem to only be able to open fb once
1085+ per process (repeated framebuffer_{open,close}() doesn't seem to work). once we
1086+ figure out why, we can remove android_window in the test fixture */
1087+ android_window = std::make_shared< ::android::FramebufferNativeWindow>();
1088+
1089+ /* determine hwc11 capable devices so we can skip the hwc11 tests on non supported tests */
1090+ run_hwc11_tests = false;
1091+ const hw_module_t *hw_module;
1092+ int rc = hw_get_module(HWC_HARDWARE_MODULE_ID, &hw_module);
1093+ if (rc == 0)
1094+ {
1095+ hwc_composer_device_1* hwc_dev;
1096+ rc = hw_module->methods->open(hw_module, HWC_HARDWARE_COMPOSER, (hw_device_t**) &hwc_dev);
1097+ if (rc == 0)
1098+ {
1099+ hwc_device = std::shared_ptr<hwc_composer_device_1>( hwc_dev );
1100+ if (hwc_device->common.version == HWC_DEVICE_API_VERSION_1_1)
1101+ {
1102+ run_hwc11_tests = true;
1103+ }
1104+ }
1105+ }
1106+ }
1107+
1108+ md::glAnimationBasic gl_animation;
1109+
1110+ static void TearDownTestCase()
1111+ {
1112+ hwc_device.reset();
1113+ android_window.reset();
1114+ }
1115+
1116+ static bool run_hwc11_tests;
1117+ static std::shared_ptr< ::android::FramebufferNativeWindow> android_window;
1118+ static std::shared_ptr<hwc_composer_device_1> hwc_device;
1119+};
1120+
1121+std::shared_ptr< ::android::FramebufferNativeWindow> AndroidGPUDisplay::android_window;
1122+std::shared_ptr<hwc_composer_device_1> AndroidGPUDisplay::hwc_device;
1123+bool AndroidGPUDisplay::run_hwc11_tests;
1124+
1125+}
1126+
1127+/* gpu display tests. These are our back-up display modes, and should be run on every device. */
1128+TEST_F(AndroidGPUDisplay, gpu_display_post_ok)
1129+{
1130+ auto window = std::make_shared<mga::AndroidFramebufferWindow> (android_window);
1131+ auto display = std::make_shared<mga::AndroidDisplay>(window);
1132+
1133+ display->for_each_display_buffer([](mg::DisplayBuffer& buffer)
1134+ {
1135+ buffer.post_update();
1136+ });
1137+}
1138+
1139+TEST_F(AndroidGPUDisplay, gpu_display_ok_with_gles)
1140+{
1141+ using namespace testing;
1142+
1143+ auto window = std::make_shared<mga::AndroidFramebufferWindow> (android_window);
1144+ auto display = std::make_shared<mga::AndroidDisplay>(window);
1145+
1146+ gl_animation.init_gl();
1147+
1148+ display->for_each_display_buffer([this](mg::DisplayBuffer& buffer)
1149+ {
1150+ gl_animation.render_gl();
1151+ buffer.post_update();
1152+
1153+ gl_animation.render_gl();
1154+ buffer.post_update();
1155+ });
1156+}
1157+
1158+#define YELLOW "\033[33m"
1159+#define RESET "\033[0m"
1160+#define SUCCEED_IF_NO_HARDWARE_SUPPORT() \
1161+ if(!run_hwc11_tests) { SUCCEED(); std::cout << YELLOW << "--> This device does not have HWC 1.1 support. Skipping test." << RESET << std::endl; return;}
1162+
1163+TEST_F(AndroidGPUDisplay, hwc11_ok_with_gles)
1164+{
1165+ SUCCEED_IF_NO_HARDWARE_SUPPORT();
1166+
1167+ using namespace testing;
1168+
1169+ auto android_window = std::make_shared< ::android::FramebufferNativeWindow>();
1170+ auto window = std::make_shared<mga::AndroidFramebufferWindow> (android_window);
1171+ auto hwc = std::make_shared<mga::HWC11Device>(hwc_device);
1172+ auto display = std::make_shared<mga::HWCDisplay>(window, hwc);
1173+
1174+ gl_animation.init_gl();
1175+
1176+ display->for_each_display_buffer([this](mg::DisplayBuffer& buffer)
1177+ {
1178+ gl_animation.render_gl();
1179+ buffer.post_update();
1180+
1181+ gl_animation.render_gl();
1182+ buffer.post_update();
1183+ });
1184+}
1185
1186=== modified file 'tests/unit-tests/graphics/android/CMakeLists.txt'
1187--- tests/unit-tests/graphics/android/CMakeLists.txt 2013-03-22 20:59:42 +0000
1188+++ tests/unit-tests/graphics/android/CMakeLists.txt 2013-04-02 16:08:22 +0000
1189@@ -3,7 +3,7 @@
1190 ${CMAKE_CURRENT_SOURCE_DIR}/test_android_buffer_allocator.cpp
1191 ${CMAKE_CURRENT_SOURCE_DIR}/test_android_buffer_tex_bind.cpp
1192 ${CMAKE_CURRENT_SOURCE_DIR}/test_android_fb.cpp
1193- ${CMAKE_CURRENT_SOURCE_DIR}/test_android_framebuffer_selector.cpp
1194+ ${CMAKE_CURRENT_SOURCE_DIR}/test_android_display_factory.cpp
1195 ${CMAKE_CURRENT_SOURCE_DIR}/test_android_framebuffer_window.cpp
1196 ${CMAKE_CURRENT_SOURCE_DIR}/test_android_alloc_adaptor.cpp
1197 ${CMAKE_CURRENT_SOURCE_DIR}/test_android_alloc_adaptor_native_win.cpp
1198
1199=== renamed file 'tests/unit-tests/graphics/android/test_android_framebuffer_selector.cpp' => 'tests/unit-tests/graphics/android/test_android_display_factory.cpp'
1200--- tests/unit-tests/graphics/android/test_android_framebuffer_selector.cpp 2013-03-29 16:51:35 +0000
1201+++ tests/unit-tests/graphics/android/test_android_display_factory.cpp 2013-04-02 16:08:22 +0000
1202@@ -16,112 +16,159 @@
1203 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
1204 */
1205
1206-#include "src/server/graphics/android/fb_factory.h"
1207-#include "src/server/graphics/android/android_display_selector.h"
1208+#include "src/server/graphics/android/android_display_factory.h"
1209+#include "src/server/graphics/android/hwc_factory.h"
1210+#include "src/server/graphics/android/android_display_allocator.h"
1211
1212 #include "mir_test/hw_mock.h"
1213-#include "mir_test_doubles/null_display.h"
1214
1215-#include <hardware/hwcomposer.h>
1216 #include <gtest/gtest.h>
1217 #include <gmock/gmock.h>
1218+#include <stdexcept>
1219
1220 namespace mt=mir::test;
1221-namespace mtd=mir::test::doubles;
1222 namespace mga=mir::graphics::android;
1223-namespace mg=mir::graphics;
1224-namespace geom=mir::geometry;
1225-
1226-struct MockFbFactory : public mga::FBFactory
1227-{
1228- MockFbFactory()
1229- {
1230- using namespace testing;
1231- ON_CALL(*this, create_hwc1_1_gpu_display())
1232- .WillByDefault(Return(std::make_shared<mtd::NullDisplay>()));
1233+
1234+namespace
1235+{
1236+struct MockHWCFactory: public mga::HWCFactory
1237+{
1238+ MockHWCFactory()
1239+ {
1240+ using namespace testing;
1241+ ON_CALL(*this, create_hwc_1_1(_))
1242+ .WillByDefault(Return(std::shared_ptr<mga::HWCDevice>()));
1243+ }
1244+ MOCK_CONST_METHOD1(create_hwc_1_1, std::shared_ptr<mga::HWCDevice>(std::shared_ptr<hwc_composer_device_1> const&));
1245+};
1246+
1247+struct MockDisplayAllocator: public mga::DisplayAllocator
1248+{
1249+ MockDisplayAllocator()
1250+ {
1251+ using namespace testing;
1252 ON_CALL(*this, create_gpu_display())
1253- .WillByDefault(Return(std::make_shared<mtd::NullDisplay>()));
1254+ .WillByDefault(Return(std::shared_ptr<mga::AndroidDisplay>()));
1255+ ON_CALL(*this, create_hwc_display(_))
1256+ .WillByDefault(Return(std::shared_ptr<mga::HWCDisplay>()));
1257+
1258 }
1259- MOCK_CONST_METHOD0(create_hwc1_1_gpu_display, std::shared_ptr<mg::Display>());
1260- MOCK_CONST_METHOD0(create_gpu_display, std::shared_ptr<mg::Display>());
1261-
1262+ MOCK_CONST_METHOD0(create_gpu_display, std::shared_ptr<mga::AndroidDisplay>());
1263+ MOCK_CONST_METHOD1(create_hwc_display, std::shared_ptr<mga::HWCDisplay>(std::shared_ptr<mga::HWCDevice> const&));
1264 };
1265
1266-class AndroidFramebufferSelectorTest : public ::testing::Test
1267+class AndroidDisplayFactoryTest : public ::testing::Test
1268 {
1269 public:
1270- AndroidFramebufferSelectorTest()
1271- : mock_fb_factory(std::make_shared<testing::NiceMock<MockFbFactory>>())
1272- {
1273- }
1274-
1275- std::shared_ptr<MockFbFactory> mock_fb_factory;
1276+ AndroidDisplayFactoryTest()
1277+ : mock_display_allocator(std::make_shared<MockDisplayAllocator>()),
1278+ mock_hwc_factory(std::make_shared<MockHWCFactory>())
1279+ {
1280+ }
1281+
1282+ void TearDown()
1283+ {
1284+ EXPECT_TRUE(hw_access_mock.open_count_matches_close());
1285+ }
1286+
1287+ std::shared_ptr<MockDisplayAllocator> const mock_display_allocator;
1288+ std::shared_ptr<MockHWCFactory> const mock_hwc_factory;
1289 mt::HardwareAccessMock hw_access_mock;
1290 };
1291-
1292-TEST_F(AndroidFramebufferSelectorTest, hwc_selection_gets_hwc_device)
1293-{
1294- using namespace testing;
1295-
1296- EXPECT_CALL(hw_access_mock, hw_get_module(StrEq(HWC_HARDWARE_MODULE_ID), _))
1297- .Times(1);
1298-
1299- mga::AndroidDisplaySelector selector(mock_fb_factory);
1300- selector.primary_display();
1301-}
1302-
1303-TEST_F(AndroidFramebufferSelectorTest, hwc_with_hwc_device_success)
1304-{
1305- using namespace testing;
1306-
1307- EXPECT_CALL(hw_access_mock, hw_get_module(_, _))
1308- .Times(1);
1309- EXPECT_CALL(*mock_fb_factory, create_hwc1_1_gpu_display())
1310- .Times(1);
1311-
1312- mga::AndroidDisplaySelector selector(mock_fb_factory);
1313- selector.primary_display();
1314-}
1315-
1316-TEST_F(AndroidFramebufferSelectorTest, hwc_with_hwc_device_failure_because_module_not_found)
1317-{
1318- using namespace testing;
1319-
1320- EXPECT_CALL(hw_access_mock, hw_get_module(_, _))
1321+}
1322+
1323+TEST_F(AndroidDisplayFactoryTest, hwc_selection_gets_hwc_device)
1324+{
1325+ using namespace testing;
1326+
1327+ EXPECT_CALL(hw_access_mock, hw_get_module(StrEq(HWC_HARDWARE_MODULE_ID), _))
1328+ .Times(1);
1329+
1330+ mga::AndroidDisplayFactory display_factory(mock_display_allocator, mock_hwc_factory);
1331+}
1332+
1333+/* this case occurs when the system cannot find the hwc library. it is a nonfatal error because we have a backup to try */
1334+TEST_F(AndroidDisplayFactoryTest, hwc_module_unavailble_always_creates_gpu_display)
1335+{
1336+ using namespace testing;
1337+
1338+ EXPECT_CALL(hw_access_mock, hw_get_module(StrEq(HWC_HARDWARE_MODULE_ID), _))
1339 .Times(1)
1340 .WillOnce(Return(-1));
1341- EXPECT_CALL(*mock_fb_factory, create_gpu_display())
1342+
1343+ EXPECT_CALL(*mock_hwc_factory, create_hwc_1_1(_))
1344+ .Times(0);
1345+ EXPECT_CALL(*mock_display_allocator, create_hwc_display(_))
1346+ .Times(0);
1347+ EXPECT_CALL(*mock_display_allocator, create_gpu_display())
1348 .Times(1);
1349
1350- mga::AndroidDisplaySelector selector(mock_fb_factory);
1351- selector.primary_display();
1352+ mga::AndroidDisplayFactory display_factory(mock_display_allocator, mock_hwc_factory);
1353+ display_factory.create_display();
1354 }
1355
1356-TEST_F(AndroidFramebufferSelectorTest, hwc_with_hwc_device_failure_because_hwc_does_not_open)
1357+/* this case occurs when the hwc library doesn't work (error) */
1358+TEST_F(AndroidDisplayFactoryTest, hwc_module_unopenable_throws)
1359 {
1360 using namespace testing;
1361
1362- EXPECT_CALL(hw_access_mock, hw_get_module(StrEq(HWC_HARDWARE_MODULE_ID), _))
1363+ mt::FailingHardwareModuleStub failing_hwc_module_stub;
1364+ EXPECT_CALL(hw_access_mock, hw_get_module(StrEq(HWC_HARDWARE_MODULE_ID),_))
1365 .Times(1)
1366- .WillOnce(DoAll(SetArgPointee<1>(nullptr), Return(-1)));
1367-;
1368- EXPECT_CALL(*mock_fb_factory, create_gpu_display())
1369- .Times(1);
1370-
1371- mga::AndroidDisplaySelector selector(mock_fb_factory);
1372- selector.primary_display();
1373-}
1374-
1375-TEST_F(AndroidFramebufferSelectorTest, hwc_with_hwc_device_failure_because_hwc_version_not_supported)
1376+ .WillOnce(DoAll(SetArgPointee<1>(&failing_hwc_module_stub), Return(0)));
1377+
1378+ EXPECT_THROW({
1379+ mga::AndroidDisplayFactory display_factory(mock_display_allocator, mock_hwc_factory);
1380+ }, std::runtime_error);
1381+}
1382+
1383+/* this is normal operation on hwc capable device */
1384+TEST_F(AndroidDisplayFactoryTest, hwc_with_hwc_device_version_11_success)
1385+{
1386+ using namespace testing;
1387+
1388+ hw_access_mock.mock_hwc_device->common.version = HWC_DEVICE_API_VERSION_1_1;
1389+
1390+ EXPECT_CALL(*mock_hwc_factory, create_hwc_1_1(_))
1391+ .Times(1);
1392+ EXPECT_CALL(*mock_display_allocator, create_hwc_display(_))
1393+ .Times(1);
1394+
1395+ mga::AndroidDisplayFactory display_factory(mock_display_allocator, mock_hwc_factory);
1396+ display_factory.create_display();
1397+}
1398+
1399+// TODO: kdub support v 1.0 and 1.2. for the time being, alloc a fallback gpu display
1400+TEST_F(AndroidDisplayFactoryTest, hwc_with_hwc_device_failure_because_hwc_version10_not_supported)
1401 {
1402 using namespace testing;
1403
1404 hw_access_mock.mock_hwc_device->common.version = HWC_DEVICE_API_VERSION_1_0;
1405- EXPECT_CALL(hw_access_mock, hw_get_module(_, _))
1406- .Times(1);
1407- EXPECT_CALL(*mock_fb_factory, create_gpu_display())
1408- .Times(1);
1409-
1410- mga::AndroidDisplaySelector selector(mock_fb_factory);
1411- selector.primary_display();
1412+
1413+ EXPECT_CALL(*mock_hwc_factory, create_hwc_1_1(_))
1414+ .Times(0);
1415+ EXPECT_CALL(*mock_display_allocator, create_hwc_display(_))
1416+ .Times(0);
1417+ EXPECT_CALL(*mock_display_allocator, create_gpu_display())
1418+ .Times(1);
1419+
1420+ mga::AndroidDisplayFactory display_factory(mock_display_allocator, mock_hwc_factory);
1421+ display_factory.create_display();
1422+}
1423+
1424+TEST_F(AndroidDisplayFactoryTest, hwc_with_hwc_device_failure_because_hwc_version12_not_supported)
1425+{
1426+ using namespace testing;
1427+
1428+ hw_access_mock.mock_hwc_device->common.version = HWC_DEVICE_API_VERSION_1_2;
1429+
1430+ EXPECT_CALL(*mock_hwc_factory, create_hwc_1_1(_))
1431+ .Times(0);
1432+ EXPECT_CALL(*mock_display_allocator, create_hwc_display(_))
1433+ .Times(0);
1434+ EXPECT_CALL(*mock_display_allocator, create_gpu_display())
1435+ .Times(1);
1436+
1437+ mga::AndroidDisplayFactory display_factory(mock_display_allocator, mock_hwc_factory);
1438+ display_factory.create_display();
1439 }
1440
1441=== modified file 'tests/unit-tests/graphics/egl_mock/hw_mock.cpp'
1442--- tests/unit-tests/graphics/egl_mock/hw_mock.cpp 2013-03-29 16:51:35 +0000
1443+++ tests/unit-tests/graphics/egl_mock/hw_mock.cpp 2013-04-02 16:08:22 +0000
1444@@ -19,6 +19,7 @@
1445 #include "mir_test/hw_mock.h"
1446 #include "mir_test_doubles/mock_hwc_composer_device_1.h"
1447
1448+#include <atomic>
1449 #include <hardware/gralloc.h>
1450 #include <system/window.h>
1451 #include <memory>
1452@@ -26,6 +27,12 @@
1453 namespace mt = mir::test;
1454 namespace mtd = mir::test::doubles;
1455
1456+namespace
1457+{
1458+mt::HardwareAccessMock* global_hw_mock = NULL;
1459+std::atomic<int> open_count;
1460+}
1461+
1462 mt::HardwareModuleStub::HardwareModuleStub(hw_device_t& device)
1463 : mock_hw_device(device)
1464 {
1465@@ -38,17 +45,30 @@
1466 auto self = static_cast<HardwareModuleStub const*>(module);
1467 self->mock_hw_device.close = hw_close;
1468 *device = static_cast<hw_device_t*>(&self->mock_hw_device);
1469+ open_count++;
1470 return 0;
1471 }
1472
1473 int mt::HardwareModuleStub::hw_close(struct hw_device_t*)
1474 {
1475- return 0;
1476-}
1477-
1478-namespace
1479-{
1480-mt::HardwareAccessMock* global_hw_mock = NULL;
1481+ open_count--;
1482+ return 0;
1483+}
1484+
1485+mt::FailingHardwareModuleStub::FailingHardwareModuleStub()
1486+{
1487+ gr_methods.open = hw_open;
1488+ methods = &gr_methods;
1489+}
1490+
1491+int mt::FailingHardwareModuleStub::hw_open(const struct hw_module_t*, const char*, struct hw_device_t**)
1492+{
1493+ return -1;
1494+}
1495+
1496+int mt::FailingHardwareModuleStub::hw_close(struct hw_device_t*)
1497+{
1498+ return 0;
1499 }
1500
1501 mt::HardwareAccessMock::HardwareAccessMock()
1502@@ -67,6 +87,13 @@
1503 .WillByDefault(DoAll(SetArgPointee<1>(mock_gralloc_module.get()), Return(0)));
1504 ON_CALL(*this, hw_get_module(StrEq(HWC_HARDWARE_MODULE_ID),_))
1505 .WillByDefault(DoAll(SetArgPointee<1>(mock_hwc_module.get()), Return(0)));
1506+
1507+ open_count.store(0);
1508+}
1509+
1510+bool mt::HardwareAccessMock::open_count_matches_close()
1511+{
1512+ return (open_count == 0);
1513 }
1514
1515 mt::HardwareAccessMock::~HardwareAccessMock()

Subscribers

People subscribed via source and target branches