Mir

Merge lp:~kdub/mir/connect-fallback-to-hwc-device into lp:mir

Proposed by Kevin DuBois
Status: Merged
Approved by: Kevin DuBois
Approved revision: no longer in the source branch.
Merged at revision: 1623
Proposed branch: lp:~kdub/mir/connect-fallback-to-hwc-device
Merge into: lp:mir
Diff against target: 804 lines (+242/-195)
17 files modified
include/test/mir_test_doubles/mock_display_device.h (+3/-2)
include/test/mir_test_doubles/mock_renderable_list_compositor.h (+41/-0)
include/test/mir_test_doubles/stub_renderable_list_compositor.h (+41/-0)
src/platform/graphics/android/display_buffer.cpp (+2/-2)
src/platform/graphics/android/display_device.h (+3/-3)
src/platform/graphics/android/fb_device.cpp (+5/-7)
src/platform/graphics/android/fb_device.h (+2/-2)
src/platform/graphics/android/hwc_device.cpp (+7/-14)
src/platform/graphics/android/hwc_device.h (+2/-2)
src/platform/graphics/android/hwc_fb_device.cpp (+26/-7)
src/platform/graphics/android/hwc_fb_device.h (+2/-2)
src/platform/graphics/android/overlay_gl_compositor.cpp (+4/-0)
src/platform/graphics/android/overlay_gl_compositor.h (+18/-2)
tests/unit-tests/graphics/android/test_fb_device.cpp (+8/-14)
tests/unit-tests/graphics/android/test_hwc_device.cpp (+67/-127)
tests/unit-tests/graphics/android/test_hwc_display.cpp (+1/-1)
tests/unit-tests/graphics/android/test_hwc_fb_device.cpp (+10/-10)
To merge this branch: bzr merge lp:~kdub/mir/connect-fallback-to-hwc-device
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alan Griffiths Needs Fixing
Alberto Aguirre (community) Approve
Robert Carr (community) Approve
Review via email: mp+217804@code.launchpad.net

Commit message

make the HwcDevice call the render() function on the fallback gl program (l253), instead of calling a std::function that isn't hooked up to anything.

Description of the change

make the HwcDevice call the render() function on the fallback gl program (l253), instead of calling a std::function that isn't hooked up to anything.

note:
In trunk now, the fallback rendering function is just a stub. This MP leaves it stubbed, but will be do something once lp:~kdub/mir/overlay-gl-program lands. The code is currently just used in the overlays demo.

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
Robert Carr (robertcarr) wrote :

LGTM

review: Approve
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

OK.

the OverlayGLProgram and overlay_gl_compositor.h will change names in the other branch https://code.launchpad.net/~kdub/mir/overlay-gl-program

Shouldn't this branch or the other list a pre-requisite?

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

Just nits:

747 +#include "mir_test_doubles/stub_renderable_list_compositor.h"

Unused.

~~~~

773 + EXPECT_CALL(mock_compositor, render(Ref(renderlist),_))
774 + .InSequence(seq)
775 + .WillOnce(Invoke([](mg::RenderableList const&, mga::SwappingGLContext const& cont)
776 + {cont.swap_buffers();}));

The lambda body should be further indented than the surrounding .WillOnce call. (Or on the same line.)

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

Alan's concerns have been addressed, so approving.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> Alan's concerns have been addressed, so approving.

Yep

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

/mir/tests/unit-tests/graphics/android/test_hwc_device.cpp: In member function 'virtual void HwcDevice_resets_composition_type_with_prepare_Test::TestBody()':
/mir/tests/unit-tests/graphics/android/test_hwc_device.cpp:586:12: error: 'class mir::graphics::android::HwcDevice' has no member named 'render_gl_and_overlays'
     device.render_gl_and_overlays(stub_context, updated_list, [](mg::Renderable const&){});
            ^
/mir/tests/unit-tests/graphics/android/test_hwc_device.cpp:587:12: error: 'class mir::graphics::android::HwcDevice' has no member named 'render_gl_and_overlays'
     device.render_gl_and_overlays(stub_context, updated_list, [](mg::Renderable const&){});

Rebase required

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

rebase done, re-top-approving

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/test/mir_test_doubles/mock_display_device.h'
--- include/test/mir_test_doubles/mock_display_device.h 2014-03-26 05:48:59 +0000
+++ include/test/mir_test_doubles/mock_display_device.h 2014-05-12 18:27:14 +0000
@@ -22,6 +22,7 @@
22#include "mir/graphics/buffer.h"22#include "mir/graphics/buffer.h"
23#include "src/platform/graphics/android/display_device.h"23#include "src/platform/graphics/android/display_device.h"
24#include "src/platform/graphics/android/gl_context.h"24#include "src/platform/graphics/android/gl_context.h"
25#include "src/platform/graphics/android/overlay_gl_compositor.h"
25#include <gmock/gmock.h>26#include <gmock/gmock.h>
2627
27namespace mir28namespace mir
@@ -36,10 +37,10 @@
36 ~MockDisplayDevice() noexcept {}37 ~MockDisplayDevice() noexcept {}
37 MOCK_METHOD1(mode, void(MirPowerMode));38 MOCK_METHOD1(mode, void(MirPowerMode));
38 MOCK_METHOD1(render_gl, void(graphics::android::SwappingGLContext const&));39 MOCK_METHOD1(render_gl, void(graphics::android::SwappingGLContext const&));
39 MOCK_METHOD3(render_gl_and_overlays, void(40 MOCK_METHOD3(prepare_overlays, void(
40 graphics::android::SwappingGLContext const&,41 graphics::android::SwappingGLContext const&,
41 graphics::RenderableList const&,42 graphics::RenderableList const&,
42 std::function<void(graphics::Renderable const&)> const&));43 graphics::android::RenderableListCompositor const&));
43 MOCK_METHOD1(post, void(graphics::Buffer const&));44 MOCK_METHOD1(post, void(graphics::Buffer const&));
44 MOCK_CONST_METHOD1(apply_orientation, bool(MirOrientation));45 MOCK_CONST_METHOD1(apply_orientation, bool(MirOrientation));
45};46};
4647
=== added file 'include/test/mir_test_doubles/mock_renderable_list_compositor.h'
--- include/test/mir_test_doubles/mock_renderable_list_compositor.h 1970-01-01 00:00:00 +0000
+++ include/test/mir_test_doubles/mock_renderable_list_compositor.h 2014-05-12 18:27:14 +0000
@@ -0,0 +1,41 @@
1/*
2 * Copyright © 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
17 */
18
19#ifndef MIR_TEST_DOUBLES_MOCK_RENDERABLE_LIST_COMPOSITOR_H_
20#define MIR_TEST_DOUBLES_MOCK_RENDERABLE_LIST_COMPOSITOR_H_
21
22#include "src/platform/graphics/android/overlay_gl_compositor.h"
23#include <gmock/gmock.h>
24
25namespace mir
26{
27namespace test
28{
29namespace doubles
30{
31
32struct MockRenderableListCompositor : public graphics::android::RenderableListCompositor
33{
34 MOCK_CONST_METHOD2(render,
35 void(graphics::RenderableList const&, graphics::android::SwappingGLContext const&));
36};
37
38}
39}
40}
41#endif // MIR_TEST_DOUBLES_MOCK_RENDERABLE_LIST_COMPOSITOR_H_
042
=== added file 'include/test/mir_test_doubles/stub_renderable_list_compositor.h'
--- include/test/mir_test_doubles/stub_renderable_list_compositor.h 1970-01-01 00:00:00 +0000
+++ include/test/mir_test_doubles/stub_renderable_list_compositor.h 2014-05-12 18:27:14 +0000
@@ -0,0 +1,41 @@
1/*
2 * Copyright © 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
17 */
18
19#ifndef MIR_TEST_DOUBLES_STUB_RENDERABLE_LIST_COMPOSITOR_H_
20#define MIR_TEST_DOUBLES_STUB_RENDERABLE_LIST_COMPOSITOR_H_
21
22#include "src/platform/graphics/android/overlay_gl_compositor.h"
23
24namespace mir
25{
26namespace test
27{
28namespace doubles
29{
30
31struct StubRenderableListCompositor : public graphics::android::RenderableListCompositor
32{
33 void render(graphics::RenderableList const&, graphics::android::SwappingGLContext const&) const
34 {
35 }
36};
37
38}
39}
40}
41#endif // MIR_TEST_DOUBLES_STUB_RENDERABLE_LIST_COMPOSITOR_H_
042
=== modified file 'src/platform/graphics/android/display_buffer.cpp'
--- src/platform/graphics/android/display_buffer.cpp 2014-05-01 07:13:02 +0000
+++ src/platform/graphics/android/display_buffer.cpp 2014-05-12 18:27:14 +0000
@@ -88,7 +88,7 @@
8888
89void mga::DisplayBuffer::render_and_post_update(89void mga::DisplayBuffer::render_and_post_update(
90 RenderableList const& renderlist,90 RenderableList const& renderlist,
91 std::function<void(Renderable const&)> const& render_fn)91 std::function<void(Renderable const&)> const&)
92{92{
93 if (renderlist.empty())93 if (renderlist.empty())
94 {94 {
@@ -96,7 +96,7 @@
96 }96 }
97 else97 else
98 {98 {
99 display_device->render_gl_and_overlays(gl_context, renderlist, render_fn);99 display_device->prepare_overlays(gl_context, renderlist, overlay_program);
100 }100 }
101101
102 post();102 post();
103103
=== modified file 'src/platform/graphics/android/display_device.h'
--- src/platform/graphics/android/display_device.h 2014-03-26 05:48:59 +0000
+++ src/platform/graphics/android/display_device.h 2014-05-12 18:27:14 +0000
@@ -22,7 +22,6 @@
22#include "mir/graphics/renderable.h"22#include "mir/graphics/renderable.h"
23#include "mir_toolkit/common.h"23#include "mir_toolkit/common.h"
24#include <EGL/egl.h>24#include <EGL/egl.h>
25#include <list>
2625
27namespace mir26namespace mir
28{27{
@@ -33,6 +32,7 @@
3332
34namespace android33namespace android
35{34{
35class RenderableListCompositor;
36class SwappingGLContext;36class SwappingGLContext;
3737
38class DisplayDevice38class DisplayDevice
@@ -42,10 +42,10 @@
4242
43 virtual void mode(MirPowerMode mode) = 0;43 virtual void mode(MirPowerMode mode) = 0;
44 virtual void render_gl(SwappingGLContext const& context) = 0;44 virtual void render_gl(SwappingGLContext const& context) = 0;
45 virtual void render_gl_and_overlays(45 virtual void prepare_overlays(
46 SwappingGLContext const& context,46 SwappingGLContext const& context,
47 RenderableList const& list,47 RenderableList const& list,
48 std::function<void(Renderable const&)> const& render_fn) = 0;48 RenderableListCompositor const& list_compositor) = 0;
49 virtual void post(Buffer const& buffer) = 0;49 virtual void post(Buffer const& buffer) = 0;
50 virtual bool apply_orientation(MirOrientation orientation) const = 0;50 virtual bool apply_orientation(MirOrientation orientation) const = 0;
5151
5252
=== modified file 'src/platform/graphics/android/fb_device.cpp'
--- src/platform/graphics/android/fb_device.cpp 2014-03-26 05:48:59 +0000
+++ src/platform/graphics/android/fb_device.cpp 2014-05-12 18:27:14 +0000
@@ -24,6 +24,7 @@
24#include "fb_device.h"24#include "fb_device.h"
25#include "framebuffer_bundle.h"25#include "framebuffer_bundle.h"
26#include "buffer.h"26#include "buffer.h"
27#include "overlay_gl_compositor.h"
2728
28#include <boost/throw_exception.hpp>29#include <boost/throw_exception.hpp>
29#include <stdexcept>30#include <stdexcept>
@@ -49,15 +50,12 @@
49 context.swap_buffers();50 context.swap_buffers();
50}51}
5152
52void mga::FBDevice::render_gl_and_overlays(53void mga::FBDevice::prepare_overlays(
53 SwappingGLContext const& context,54 SwappingGLContext const& context,
54 RenderableList const& renderables,55 RenderableList const& list,
55 std::function<void(Renderable const&)> const& render_fn) 56 RenderableListCompositor const& compositor)
56{57{
57 for(auto const& renderable : renderables)58 compositor.render(list, context);
58 render_fn(*renderable);
59
60 context.swap_buffers();
61}59}
6260
63void mga::FBDevice::post(mg::Buffer const& buffer)61void mga::FBDevice::post(mg::Buffer const& buffer)
6462
=== modified file 'src/platform/graphics/android/fb_device.h'
--- src/platform/graphics/android/fb_device.h 2014-03-26 05:48:59 +0000
+++ src/platform/graphics/android/fb_device.h 2014-05-12 18:27:14 +0000
@@ -38,10 +38,10 @@
38 bool apply_orientation(MirOrientation orientation) const;38 bool apply_orientation(MirOrientation orientation) const;
39 void mode(MirPowerMode mode);39 void mode(MirPowerMode mode);
40 virtual void render_gl(SwappingGLContext const& context);40 virtual void render_gl(SwappingGLContext const& context);
41 virtual void render_gl_and_overlays(41 virtual void prepare_overlays(
42 SwappingGLContext const& context,42 SwappingGLContext const& context,
43 RenderableList const& list,43 RenderableList const& list,
44 std::function<void(Renderable const&)> const& render_fn);44 RenderableListCompositor const& list_compositor);
45 void post(Buffer const& buffer);45 void post(Buffer const& buffer);
4646
47private:47private:
4848
=== modified file 'src/platform/graphics/android/hwc_device.cpp'
--- src/platform/graphics/android/hwc_device.cpp 2014-03-26 05:48:59 +0000
+++ src/platform/graphics/android/hwc_device.cpp 2014-05-12 18:27:14 +0000
@@ -24,7 +24,7 @@
24#include "hwc_wrapper.h"24#include "hwc_wrapper.h"
25#include "framebuffer_bundle.h"25#include "framebuffer_bundle.h"
26#include "buffer.h"26#include "buffer.h"
27#include "mir/graphics/buffer.h"27#include "overlay_gl_compositor.h"
2828
29namespace mg = mir::graphics;29namespace mg = mir::graphics;
30namespace mga=mir::graphics::android;30namespace mga=mir::graphics::android;
@@ -88,10 +88,10 @@
88 context.swap_buffers();88 context.swap_buffers();
89}89}
9090
91void mga::HwcDevice::render_gl_and_overlays(91void mga::HwcDevice::prepare_overlays(
92 SwappingGLContext const& context,92 SwappingGLContext const& context,
93 RenderableList const& renderables,93 RenderableList const& renderables,
94 std::function<void(Renderable const&)> const& render_fn)94 RenderableListCompositor const& list_compositor)
95{95{
96 if (!(list_needs_commit = hwc_list.update_list_and_check_if_changed(renderables, fbtarget_size)))96 if (!(list_needs_commit = hwc_list.update_list_and_check_if_changed(renderables, fbtarget_size)))
97 return;97 return;
@@ -99,25 +99,18 @@
9999
100 hwc_wrapper->prepare(*hwc_list.native_list().lock());100 hwc_wrapper->prepare(*hwc_list.native_list().lock());
101101
102 //draw layers that the HWC did not accept for overlays here102 mg::RenderableList rejected_renderables;
103 bool needs_swapbuffers = false;103
104 auto layers_it = hwc_list.begin();104 auto layers_it = hwc_list.begin();
105 for(auto const& renderable : renderables)105 for(auto const& renderable : renderables)
106 {106 {
107 //prepare all layers for draw.
108 layers_it->prepare_for_draw();107 layers_it->prepare_for_draw();
109
110 //trigger GL on the layers that are not overlays
111 if (layers_it->needs_gl_render())108 if (layers_it->needs_gl_render())
112 {109 rejected_renderables.push_back(renderable);
113 render_fn(*renderable);
114 needs_swapbuffers = true;
115 }
116 layers_it++;110 layers_it++;
117 }111 }
118112
119 if (needs_swapbuffers)113 list_compositor.render(rejected_renderables, context);
120 context.swap_buffers();
121}114}
122115
123void mga::HwcDevice::post(mg::Buffer const& buffer)116void mga::HwcDevice::post(mg::Buffer const& buffer)
124117
=== modified file 'src/platform/graphics/android/hwc_device.h'
--- src/platform/graphics/android/hwc_device.h 2014-03-26 05:48:59 +0000
+++ src/platform/graphics/android/hwc_device.h 2014-05-12 18:27:14 +0000
@@ -48,10 +48,10 @@
48 std::shared_ptr<SyncFileOps> const& sync_ops);48 std::shared_ptr<SyncFileOps> const& sync_ops);
4949
50 virtual void render_gl(SwappingGLContext const& context);50 virtual void render_gl(SwappingGLContext const& context);
51 virtual void render_gl_and_overlays(51 virtual void prepare_overlays(
52 SwappingGLContext const& context,52 SwappingGLContext const& context,
53 RenderableList const& list,53 RenderableList const& list,
54 std::function<void(Renderable const&)> const& render_fn);54 RenderableListCompositor const& list_compositor);
55 void post(Buffer const& buffer);55 void post(Buffer const& buffer);
5656
57private:57private:
5858
=== modified file 'src/platform/graphics/android/hwc_fb_device.cpp'
--- src/platform/graphics/android/hwc_fb_device.cpp 2014-03-26 05:48:59 +0000
+++ src/platform/graphics/android/hwc_fb_device.cpp 2014-05-12 18:27:14 +0000
@@ -22,8 +22,10 @@
22#include "framebuffer_bundle.h"22#include "framebuffer_bundle.h"
23#include "android_format_conversion-inl.h"23#include "android_format_conversion-inl.h"
24#include "hwc_wrapper.h"24#include "hwc_wrapper.h"
25#include "overlay_gl_compositor.h"
25#include "mir/graphics/buffer.h"26#include "mir/graphics/buffer.h"
26#include "mir/graphics/android/native_buffer.h"27#include "mir/graphics/android/native_buffer.h"
28#include "gl_context.h"
2729
28#include <boost/throw_exception.hpp>30#include <boost/throw_exception.hpp>
29#include <sstream>31#include <sstream>
@@ -33,6 +35,24 @@
33namespace mga = mir::graphics::android;35namespace mga = mir::graphics::android;
34namespace geom = mir::geometry;36namespace geom = mir::geometry;
3537
38namespace
39{
40class HWC10Context : public mga::SwappingGLContext
41{
42public:
43 HWC10Context(std::function<void()> const& swapping_fn)
44 : swapping_fn(std::move(swapping_fn))
45 {
46 }
47 void swap_buffers() const override
48 {
49 swapping_fn();
50 }
51private:
52 std::function<void()> const swapping_fn;
53};
54}
55
36mga::HwcFbDevice::HwcFbDevice(std::shared_ptr<hwc_composer_device_1> const& hwc_device,56mga::HwcFbDevice::HwcFbDevice(std::shared_ptr<hwc_composer_device_1> const& hwc_device,
37 std::shared_ptr<HwcWrapper> const& hwc_wrapper,57 std::shared_ptr<HwcWrapper> const& hwc_wrapper,
38 std::shared_ptr<framebuffer_device_t> const& fb_device,58 std::shared_ptr<framebuffer_device_t> const& fb_device,
@@ -84,16 +104,15 @@
84 gpu_render();104 gpu_render();
85}105}
86106
87void mga::HwcFbDevice::render_gl_and_overlays(107void mga::HwcFbDevice::prepare_overlays(
88 SwappingGLContext const&,108 SwappingGLContext const&,
89 RenderableList const& renderables,109 RenderableList const& list,
90 std::function<void(Renderable const&)> const& render_fn)110 RenderableListCompositor const& compositor)
91{111{
92 prepare();112 prepare();
93 //TODO: filter this list based on the results of the preparation113 //hwc 1.0 is weird in that the driver gets to call eglSwapBuffers.
94 for(auto const& renderable : renderables)114 HWC10Context context(std::bind(&HwcFbDevice::gpu_render, this));
95 render_fn(*renderable);115 compositor.render(list, context);
96 gpu_render();
97}116}
98117
99void mga::HwcFbDevice::post(mg::Buffer const& buffer)118void mga::HwcFbDevice::post(mg::Buffer const& buffer)
100119
=== modified file 'src/platform/graphics/android/hwc_fb_device.h'
--- src/platform/graphics/android/hwc_fb_device.h 2014-03-26 05:48:59 +0000
+++ src/platform/graphics/android/hwc_fb_device.h 2014-05-12 18:27:14 +0000
@@ -41,10 +41,10 @@
41 std::shared_ptr<HWCVsyncCoordinator> const& coordinator);41 std::shared_ptr<HWCVsyncCoordinator> const& coordinator);
4242
43 virtual void render_gl(SwappingGLContext const& context);43 virtual void render_gl(SwappingGLContext const& context);
44 virtual void render_gl_and_overlays(44 virtual void prepare_overlays(
45 SwappingGLContext const& context,45 SwappingGLContext const& context,
46 RenderableList const& list,46 RenderableList const& list,
47 std::function<void(Renderable const&)> const& render_fn);47 RenderableListCompositor const& list_compositor);
48 void post(Buffer const& buffer);48 void post(Buffer const& buffer);
4949
50private:50private:
5151
=== modified file 'src/platform/graphics/android/overlay_gl_compositor.cpp'
--- src/platform/graphics/android/overlay_gl_compositor.cpp 2014-04-17 23:10:31 +0000
+++ src/platform/graphics/android/overlay_gl_compositor.cpp 2014-05-12 18:27:14 +0000
@@ -47,3 +47,7 @@
47 overlay_program = factory.create_gl_program(vertex_shader, fragment_shader);47 overlay_program = factory.create_gl_program(vertex_shader, fragment_shader);
48 context.release_current();48 context.release_current();
49}49}
50
51void mga::OverlayGLProgram::render(RenderableList const&, SwappingGLContext const&) const
52{
53}
5054
=== modified file 'src/platform/graphics/android/overlay_gl_compositor.h'
--- src/platform/graphics/android/overlay_gl_compositor.h 2014-04-17 22:20:59 +0000
+++ src/platform/graphics/android/overlay_gl_compositor.h 2014-05-12 18:27:14 +0000
@@ -20,6 +20,7 @@
20#define MIR_GRAPHICS_ANDROID_OVERLAY_GL_PROGRAM_H_20#define MIR_GRAPHICS_ANDROID_OVERLAY_GL_PROGRAM_H_
2121
22#include "mir/graphics/gl_program.h"22#include "mir/graphics/gl_program.h"
23#include "mir/graphics/renderable.h"
23#include <memory>24#include <memory>
2425
25namespace mir26namespace mir
@@ -31,11 +32,26 @@
3132
32namespace android33namespace android
33{34{
3435class SwappingGLContext;
35class OverlayGLProgram36
37class RenderableListCompositor
38{
39public:
40 virtual ~RenderableListCompositor() = default;
41 virtual void render(RenderableList const&, SwappingGLContext const&) const = 0;
42protected:
43 RenderableListCompositor() = default;
44private:
45 RenderableListCompositor(RenderableListCompositor const&) = delete;
46 RenderableListCompositor& operator=(RenderableListCompositor const&) = delete;
47};
48
49class OverlayGLProgram : public RenderableListCompositor
36{50{
37public:51public:
38 OverlayGLProgram(GLProgramFactory const& program_factory, graphics::GLContext const& gl_context);52 OverlayGLProgram(GLProgramFactory const& program_factory, graphics::GLContext const& gl_context);
53
54 void render(RenderableList const&, SwappingGLContext const&) const;
39private:55private:
40 std::unique_ptr<graphics::GLProgram> overlay_program;56 std::unique_ptr<graphics::GLProgram> overlay_program;
41};57};
4258
=== modified file 'tests/unit-tests/graphics/android/test_fb_device.cpp'
--- tests/unit-tests/graphics/android/test_fb_device.cpp 2014-03-11 13:44:57 +0000
+++ tests/unit-tests/graphics/android/test_fb_device.cpp 2014-05-12 18:27:14 +0000
@@ -19,6 +19,7 @@
19#include "mir_test_doubles/mock_fb_hal_device.h"19#include "mir_test_doubles/mock_fb_hal_device.h"
20#include "mir_test_doubles/mock_buffer.h"20#include "mir_test_doubles/mock_buffer.h"
21#include "src/platform/graphics/android/fb_device.h"21#include "src/platform/graphics/android/fb_device.h"
22#include "src/platform/graphics/android/overlay_gl_compositor.h"
22#include "mir_test_doubles/mock_framebuffer_bundle.h"23#include "mir_test_doubles/mock_framebuffer_bundle.h"
23#include "mir_test_doubles/mock_android_hw.h"24#include "mir_test_doubles/mock_android_hw.h"
24#include "mir_test_doubles/mock_egl.h"25#include "mir_test_doubles/mock_egl.h"
@@ -27,6 +28,8 @@
27#include "mir_test_doubles/mock_android_native_buffer.h"28#include "mir_test_doubles/mock_android_native_buffer.h"
28#include "mir_test_doubles/mock_render_function.h"29#include "mir_test_doubles/mock_render_function.h"
29#include "mir_test_doubles/mock_swapping_gl_context.h"30#include "mir_test_doubles/mock_swapping_gl_context.h"
31#include "mir_test_doubles/stub_renderable_list_compositor.h"
32#include "mir_test_doubles/mock_renderable_list_compositor.h"
3033
31#include <gtest/gtest.h>34#include <gtest/gtest.h>
32#include <stdexcept>35#include <stdexcept>
@@ -63,7 +66,7 @@
63 mtd::MockSwappingGLContext mock_context;66 mtd::MockSwappingGLContext mock_context;
64};67};
6568
66TEST_F(FBDevice, render_overlays_via_gl)69TEST_F(FBDevice, prepares_overlays_by_rendering)
67{70{
68 auto renderable1 = std::make_shared<mtd::StubRenderable>();71 auto renderable1 = std::make_shared<mtd::StubRenderable>();
69 auto renderable2 = std::make_shared<mtd::StubRenderable>();72 auto renderable2 = std::make_shared<mtd::StubRenderable>();
@@ -73,20 +76,11 @@
73 renderable276 renderable2
74 };77 };
7578
76 mtd::MockRenderFunction mock_call_counter;79 mtd::MockRenderableListCompositor mock_compositor;
77 testing::Sequence seq;80 EXPECT_CALL(mock_compositor, render(testing::Ref(renderlist),testing::_))
78 EXPECT_CALL(mock_call_counter, called(testing::Ref(*renderable1)))81 .Times(1);
79 .InSequence(seq);
80 EXPECT_CALL(mock_call_counter, called(testing::Ref(*renderable2)))
81 .InSequence(seq);
82 EXPECT_CALL(mock_context, swap_buffers())
83 .InSequence(seq);
84
85 mga::FBDevice fbdev(fb_hal_mock);82 mga::FBDevice fbdev(fb_hal_mock);
86 fbdev.render_gl_and_overlays(mock_context, renderlist, [&](mg::Renderable const& renderable)83 fbdev.prepare_overlays(mock_context, renderlist, mock_compositor);
87 {
88 mock_call_counter.called(renderable);
89 });
90}84}
9185
92TEST_F(FBDevice, commits_frame_via_post)86TEST_F(FBDevice, commits_frame_via_post)
9387
=== modified file 'tests/unit-tests/graphics/android/test_hwc_device.cpp'
--- tests/unit-tests/graphics/android/test_hwc_device.cpp 2014-05-05 03:36:45 +0000
+++ tests/unit-tests/graphics/android/test_hwc_device.cpp 2014-05-12 18:27:14 +0000
@@ -34,6 +34,8 @@
34#include "mir_test_doubles/mock_render_function.h"34#include "mir_test_doubles/mock_render_function.h"
35#include "mir_test_doubles/mock_swapping_gl_context.h"35#include "mir_test_doubles/mock_swapping_gl_context.h"
36#include "mir_test_doubles/stub_swapping_gl_context.h"36#include "mir_test_doubles/stub_swapping_gl_context.h"
37#include "mir_test_doubles/stub_renderable_list_compositor.h"
38#include "mir_test_doubles/mock_renderable_list_compositor.h"
37#include <gmock/gmock.h>39#include <gmock/gmock.h>
38#include <gtest/gtest.h>40#include <gtest/gtest.h>
39#include <stdexcept>41#include <stdexcept>
@@ -230,6 +232,7 @@
230 testing::NiceMock<mtd::MockBuffer> mock_buffer;232 testing::NiceMock<mtd::MockBuffer> mock_buffer;
231 mtd::MockSwappingGLContext mock_context;233 mtd::MockSwappingGLContext mock_context;
232 mtd::StubSwappingGLContext stub_context;234 mtd::StubSwappingGLContext stub_context;
235 mtd::StubRenderableListCompositor stub_compositor;
233};236};
234237
235238
@@ -249,125 +252,62 @@
249 device.render_gl(stub_context);252 device.render_gl(stub_context);
250}253}
251254
252TEST_F(HwcDevice, calls_render_fn_and_swap_when_all_overlays_are_rejected)255namespace
253{256{
254 using namespace testing;257MATCHER_P(MatchesRenderableList, value, std::string(""))
255 mtd::MockRenderFunction mock_render_fn;258{
256 auto render_fn = [&](mg::Renderable const& renderable)259 if (value.size() != arg.size())
257 {260 return false;
258 mock_render_fn.called(renderable);261
259 };262 bool match{true};
260263 auto it = value.begin();
261 std::list<std::shared_ptr<mg::Renderable>> updated_list({264 for(auto const& a : arg)
262 stub_renderable1,265 {
263 stub_renderable2266 if (a != *it)
264 });267 match = false;
265268 it++;
266 std::list<hwc_layer_1_t*> expected_list269 }
267 {270 return match;
268 &comp_layer,271}
269 &comp_layer,272
270 &target_layer273}
271 };274
272275TEST_F(HwcDevice, calls_render_with_list_of_rejected_overlays)
273 Sequence seq;276{
274 EXPECT_CALL(*mock_hwc_device_wrapper, prepare(MatchesList(expected_list)))277 using namespace testing;
275 .InSequence(seq)278 mtd::MockRenderableListCompositor mock_compositor;
276 .WillOnce(Invoke([&](hwc_display_contents_1_t& contents)279
277 {280 std::list<std::shared_ptr<mg::Renderable>> updated_list({
278 ASSERT_EQ(contents.numHwLayers, 3);281 stub_renderable1,
279 contents.hwLayers[0].compositionType = HWC_FRAMEBUFFER;282 stub_renderable2
280 contents.hwLayers[1].compositionType = HWC_FRAMEBUFFER;283 });
281 contents.hwLayers[2].compositionType = HWC_FRAMEBUFFER_TARGET;284 std::list<std::shared_ptr<mg::Renderable>> expected_renderable_list({
282 }));285 stub_renderable2
283 EXPECT_CALL(mock_render_fn, called(Ref(*stub_renderable1)))286 });
284 .InSequence(seq);287
285 EXPECT_CALL(mock_render_fn, called(Ref(*stub_renderable2)))288 std::list<hwc_layer_1_t*> expected_prepare_list
286 .InSequence(seq);289 {
287 EXPECT_CALL(mock_context, swap_buffers())290 &comp_layer,
288 .InSequence(seq);291 &comp_layer,
289292 &target_layer
290 mga::HwcDevice device(mock_device, mock_hwc_device_wrapper, mock_vsync, mock_file_ops);293 };
291 device.render_gl_and_overlays(mock_context, updated_list, render_fn);294
292}295 Sequence seq;
293296 EXPECT_CALL(*mock_hwc_device_wrapper, prepare(MatchesList(expected_prepare_list)))
294TEST_F(HwcDevice, calls_render_and_swap_when_some_overlays_are_rejected)297 .InSequence(seq)
295{298 .WillOnce(Invoke([&](hwc_display_contents_1_t& contents)
296 using namespace testing;299 {
297 mtd::MockRenderFunction mock_render_fn;300 ASSERT_EQ(contents.numHwLayers, 3);
298 auto render_fn = [&](mg::Renderable const& renderable)301 contents.hwLayers[0].compositionType = HWC_OVERLAY;
299 {302 contents.hwLayers[1].compositionType = HWC_FRAMEBUFFER;
300 mock_render_fn.called(renderable);303 contents.hwLayers[2].compositionType = HWC_FRAMEBUFFER_TARGET;
301 };304 }));
302305
303 std::list<std::shared_ptr<mg::Renderable>> updated_list({306 EXPECT_CALL(mock_compositor, render(MatchesRenderableList(expected_renderable_list),Ref(mock_context)))
304 stub_renderable1,307 .InSequence(seq);
305 stub_renderable2308
306 });309 mga::HwcDevice device(mock_device, mock_hwc_device_wrapper, mock_vsync, mock_file_ops);
307310 device.prepare_overlays(mock_context, updated_list, mock_compositor);
308 std::list<hwc_layer_1_t*> expected_list
309 {
310 &comp_layer,
311 &comp_layer,
312 &target_layer
313 };
314
315 Sequence seq;
316 EXPECT_CALL(*mock_hwc_device_wrapper, prepare(MatchesList(expected_list)))
317 .InSequence(seq)
318 .WillOnce(Invoke([&](hwc_display_contents_1_t& contents)
319 {
320 ASSERT_EQ(contents.numHwLayers, 3);
321 contents.hwLayers[0].compositionType = HWC_OVERLAY;
322 contents.hwLayers[1].compositionType = HWC_FRAMEBUFFER;
323 contents.hwLayers[2].compositionType = HWC_FRAMEBUFFER_TARGET;
324 }));
325 EXPECT_CALL(mock_render_fn, called(Ref(*stub_renderable2)))
326 .InSequence(seq);
327 EXPECT_CALL(mock_context, swap_buffers())
328 .InSequence(seq);
329
330 mga::HwcDevice device(mock_device, mock_hwc_device_wrapper, mock_vsync, mock_file_ops);
331 device.render_gl_and_overlays(mock_context, updated_list, render_fn);
332}
333
334TEST_F(HwcDevice, does_not_call_render_or_swap_when_all_overlays_accepted)
335{
336 using namespace testing;
337 mtd::MockRenderFunction mock_render_fn;
338 auto render_fn = [&](mg::Renderable const& renderable)
339 {
340 mock_render_fn.called(renderable);
341 };
342
343 std::list<std::shared_ptr<mg::Renderable>> updated_list({
344 stub_renderable1,
345 stub_renderable2
346 });
347
348 std::list<hwc_layer_1_t*> expected_list
349 {
350 &comp_layer,
351 &comp_layer,
352 &target_layer
353 };
354
355 EXPECT_CALL(*mock_hwc_device_wrapper, prepare(MatchesList(expected_list)))
356 .Times(1)
357 .WillOnce(Invoke([&](hwc_display_contents_1_t& contents)
358 {
359 ASSERT_EQ(contents.numHwLayers, 3);
360 contents.hwLayers[0].compositionType = HWC_OVERLAY;
361 contents.hwLayers[1].compositionType = HWC_OVERLAY;
362 contents.hwLayers[2].compositionType = HWC_FRAMEBUFFER_TARGET;
363 }));
364 EXPECT_CALL(mock_render_fn, called(_))
365 .Times(0);
366 EXPECT_CALL(mock_context, swap_buffers())
367 .Times(0);
368
369 mga::HwcDevice device(mock_device, mock_hwc_device_wrapper, mock_vsync, mock_file_ops);
370 device.render_gl_and_overlays(mock_context, updated_list, render_fn);
371}311}
372312
373TEST_F(HwcDevice, resets_layers_when_prepare_gl_called)313TEST_F(HwcDevice, resets_layers_when_prepare_gl_called)
@@ -398,7 +338,7 @@
398 stub_renderable2338 stub_renderable2
399 });339 });
400340
401 device.render_gl_and_overlays(stub_context, updated_list, [](mg::Renderable const&){});341 device.prepare_overlays(stub_context, updated_list, stub_compositor);
402 device.render_gl(stub_context);342 device.render_gl(stub_context);
403}343}
404344
@@ -544,7 +484,7 @@
544 EXPECT_CALL(*native_handle_3, update_fence(release_fence3))484 EXPECT_CALL(*native_handle_3, update_fence(release_fence3))
545 .InSequence(seq);485 .InSequence(seq);
546486
547 device.render_gl_and_overlays(stub_context, updated_list, [](mg::Renderable const&){});487 device.prepare_overlays(stub_context, updated_list, stub_compositor);
548 device.post(mock_buffer);488 device.post(mock_buffer);
549}489}
550490
@@ -570,9 +510,9 @@
570 EXPECT_CALL(*mock_hwc_device_wrapper, set(_))510 EXPECT_CALL(*mock_hwc_device_wrapper, set(_))
571 .Times(1);511 .Times(1);
572512
573 device.render_gl_and_overlays(stub_context, updated_list, [](mg::Renderable const&){});513 device.prepare_overlays(stub_context, updated_list, stub_compositor);
574 device.post(mock_buffer);514 device.post(mock_buffer);
575 device.render_gl_and_overlays(stub_context, updated_list, [](mg::Renderable const&){});515 device.prepare_overlays(stub_context, updated_list, stub_compositor);
576 device.post(mock_buffer);516 device.post(mock_buffer);
577}517}
578518
@@ -598,9 +538,9 @@
598 EXPECT_CALL(*mock_hwc_device_wrapper, set(_))538 EXPECT_CALL(*mock_hwc_device_wrapper, set(_))
599 .Times(2);539 .Times(2);
600540
601 device.render_gl_and_overlays(stub_context, updated_list, [](mg::Renderable const&){});541 device.prepare_overlays(stub_context, updated_list, stub_compositor);
602 device.post(mock_buffer);542 device.post(mock_buffer);
603 device.render_gl_and_overlays(stub_context, updated_list, [](mg::Renderable const&){});543 device.prepare_overlays(stub_context, updated_list, stub_compositor);
604 device.post(mock_buffer);544 device.post(mock_buffer);
605}545}
606546
@@ -643,7 +583,7 @@
643 EXPECT_EQ(HWC_FRAMEBUFFER, contents.hwLayers[0].compositionType);583 EXPECT_EQ(HWC_FRAMEBUFFER, contents.hwLayers[0].compositionType);
644 }));584 }));
645585
646 device.render_gl_and_overlays(stub_context, updated_list, [](mg::Renderable const&){});586 device.prepare_overlays(stub_context, updated_list, stub_compositor);
647 device.render_gl_and_overlays(stub_context, updated_list, [](mg::Renderable const&){});587 device.prepare_overlays(stub_context, updated_list, stub_compositor);
648 device.post(mock_buffer);588 device.post(mock_buffer);
649}589}
650590
=== modified file 'tests/unit-tests/graphics/android/test_hwc_display.cpp'
--- tests/unit-tests/graphics/android/test_hwc_display.cpp 2014-05-01 07:13:02 +0000
+++ tests/unit-tests/graphics/android/test_hwc_display.cpp 2014-05-12 18:27:14 +0000
@@ -133,7 +133,7 @@
133 std::function<void(mg::Renderable const&)> render_fn;133 std::function<void(mg::Renderable const&)> render_fn;
134134
135 InSequence seq;135 InSequence seq;
136 EXPECT_CALL(*mock_display_device, render_gl_and_overlays(_, Ref(renderlist), Ref(render_fn)))136 EXPECT_CALL(*mock_display_device, prepare_overlays(_, Ref(renderlist), _))
137 .Times(1);137 .Times(1);
138 EXPECT_CALL(*mock_fb_bundle, last_rendered_buffer())138 EXPECT_CALL(*mock_fb_bundle, last_rendered_buffer())
139 .Times(1)139 .Times(1)
140140
=== modified file 'tests/unit-tests/graphics/android/test_hwc_fb_device.cpp'
--- tests/unit-tests/graphics/android/test_hwc_fb_device.cpp 2014-03-26 05:48:59 +0000
+++ tests/unit-tests/graphics/android/test_hwc_fb_device.cpp 2014-05-12 18:27:14 +0000
@@ -29,6 +29,8 @@
29#include "mir_test_doubles/stub_swapping_gl_context.h"29#include "mir_test_doubles/stub_swapping_gl_context.h"
30#include "mir_test_doubles/mock_egl.h"30#include "mir_test_doubles/mock_egl.h"
31#include "mir_test_doubles/mock_hwc_device_wrapper.h"31#include "mir_test_doubles/mock_hwc_device_wrapper.h"
32#include "mir_test_doubles/mock_renderable_list_compositor.h"
33#include "src/platform/graphics/android/overlay_gl_compositor.h"
32#include "hwc_struct_helpers.h"34#include "hwc_struct_helpers.h"
33#include <gtest/gtest.h>35#include <gtest/gtest.h>
34#include <stdexcept>36#include <stdexcept>
@@ -111,6 +113,7 @@
111TEST_F(HwcFbDevice, hwc10_prepare_with_renderables)113TEST_F(HwcFbDevice, hwc10_prepare_with_renderables)
112{114{
113 using namespace testing;115 using namespace testing;
116 mtd::MockRenderableListCompositor mock_compositor;
114 std::list<hwc_layer_1_t*> expected_list{&skip_layer};117 std::list<hwc_layer_1_t*> expected_list{&skip_layer};
115 auto renderable1 = std::make_shared<mtd::StubRenderable>();118 auto renderable1 = std::make_shared<mtd::StubRenderable>();
116 auto renderable2 = std::make_shared<mtd::StubRenderable>();119 auto renderable2 = std::make_shared<mtd::StubRenderable>();
@@ -120,14 +123,15 @@
120 renderable2123 renderable2
121 };124 };
122125
123 mtd::MockRenderFunction mock_call_counter;
124 testing::Sequence seq;126 testing::Sequence seq;
125 EXPECT_CALL(*mock_hwc_device_wrapper, prepare(MatchesList(expected_list)))127 EXPECT_CALL(*mock_hwc_device_wrapper, prepare(MatchesList(expected_list)))
126 .InSequence(seq);128 .InSequence(seq);
127 EXPECT_CALL(mock_call_counter, called(testing::Ref(*renderable1)))129 EXPECT_CALL(mock_compositor, render(Ref(renderlist),_))
128 .InSequence(seq);130 .InSequence(seq)
129 EXPECT_CALL(mock_call_counter, called(testing::Ref(*renderable2)))131 .WillOnce(Invoke([](mg::RenderableList const&, mga::SwappingGLContext const& cont)
130 .InSequence(seq);132 {
133 cont.swap_buffers();
134 }));
131 EXPECT_CALL(mock_egl, eglGetCurrentDisplay())135 EXPECT_CALL(mock_egl, eglGetCurrentDisplay())
132 .InSequence(seq)136 .InSequence(seq)
133 .WillOnce(Return(dpy));137 .WillOnce(Return(dpy));
@@ -138,11 +142,7 @@
138 .InSequence(seq);142 .InSequence(seq);
139143
140 mga::HwcFbDevice device(mock_hwc_device, mock_hwc_device_wrapper, mock_fb_device, mock_vsync);144 mga::HwcFbDevice device(mock_hwc_device, mock_hwc_device_wrapper, mock_fb_device, mock_vsync);
141145 device.prepare_overlays(stub_context, renderlist, mock_compositor);
142 device.render_gl_and_overlays(stub_context, renderlist, [&](mg::Renderable const& renderable)
143 {
144 mock_call_counter.called(renderable);
145 });
146}146}
147147
148TEST_F(HwcFbDevice, hwc10_post)148TEST_F(HwcFbDevice, hwc10_post)

Subscribers

People subscribed via source and target branches