Mir

Merge lp:~alan-griffiths/mir/fix-1284597 into lp:mir

Proposed by Alan Griffiths
Status: Merged
Approved by: Daniel van Vugt
Approved revision: no longer in the source branch.
Merged at revision: 1429
Proposed branch: lp:~alan-griffiths/mir/fix-1284597
Merge into: lp:mir
Diff against target: 49 lines (+13/-2)
1 file modified
examples/render_surfaces.cpp (+13/-2)
To merge this branch: bzr merge lp:~alan-griffiths/mir/fix-1284597
Reviewer Review Type Date Requested Status
Alexandros Frantzis (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Daniel van Vugt manual testing Approve
Review via email: mp+208180@code.launchpad.net

Commit message

examples: if we use GL to init each buffer, then we need a GL context

Description of the change

examples: if we use GL to init each buffer, then we need a GL context

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

I can't tell if this will render correctly, or if it's just providing a dummy context to avoid crashing. Obviously it would need to render correctly too, which means making use of "gl_context". Will have to test...

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

Tested and works.

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

Ping Jenkins again. CI problems are now fixed.

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

The proposed solution depends on knowledge of how things work internally (e.g. that buffers are allocated lazily). I think that something in the spirit of http://paste.ubuntu.com/6998792/ is cleaner (for a more robust solution we need to restore the previous context instead of just releasing the current one, or alternatively, not bind a new context at all if there is an active context already).

Note: I have tried it only on desktop, not N4, so there may be further complications.

A weak needs fixing... I prefer this solution over the proposed, and I think it's the Right Way (TM), but I can live with what is proposed (it's certainly more explicit than what we have now).

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

I agree with the first sentence of above. Though I disagree about changing to a significantly more cryptic design as suggested. That's bad for maintenance in the long run. Probably worse than breaking the encapsulation. At least simple code is simple to understand and therefore to maintain.

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

> Though I disagree about changing to a significantly more cryptic design as suggested

Which part of the new design do you find cryptic?

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

mir::raii::paired_calls is cryptic, but then one could argue RAII and C++ itself is equally so by design. So that's just an opinion.

Also, from memory mg::BufferInitializer only exists to support examples/*. Last time I looked into it, that class had no purpose in the rest of Mir. It's probably a bad idea to make extensive use of such classes which are only used in examples/* and will never be used in real servers/clients.

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

> The proposed solution depends on knowledge of how things work internally (e.g.
> that buffers are allocated lazily). I think that something in the spirit of
> http://paste.ubuntu.com/6998792/ is cleaner (for a more robust solution we
> need to restore the previous context instead of just releasing the current
> one, or alternatively, not bind a new context at all if there is an active
> context already).

Applied your patch - it is sufficient for the example.

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

Looks good (what else would I say?) :)

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

I'm assuming the new version still works. :) Land it.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/render_surfaces.cpp'
2--- examples/render_surfaces.cpp 2014-02-21 11:19:46 +0000
3+++ examples/render_surfaces.cpp 2014-02-26 10:14:52 +0000
4@@ -28,10 +28,12 @@
5 #include "mir/graphics/cursor.h"
6 #include "mir/graphics/display.h"
7 #include "mir/graphics/display_buffer.h"
8+#include "mir/graphics/gl_context.h"
9 #include "mir/shell/surface_factory.h"
10 #include "mir/shell/surface.h"
11 #include "mir/run_mir.h"
12 #include "mir/report_exception.h"
13+#include "mir/raii.h"
14
15 #include "mir_image.h"
16 #include "buffer_render_target.h"
17@@ -296,12 +298,17 @@
18 class RenderResourcesBufferInitializer : public mg::BufferInitializer
19 {
20 public:
21- RenderResourcesBufferInitializer()
22+ RenderResourcesBufferInitializer(std::unique_ptr<mg::GLContext> gl_context)
23+ : gl_context{std::move(gl_context)}
24 {
25 }
26
27 void operator()(mg::Buffer& buffer)
28 {
29+ auto using_gl_context = mir::raii::paired_calls(
30+ [this] { gl_context->make_current(); },
31+ [this] { gl_context->release_current(); });
32+
33 mt::ImageRenderer img_renderer{mir_image.pixel_data,
34 geom::Size{mir_image.width, mir_image.height},
35 mir_image.bytes_per_pixel};
36@@ -309,9 +316,13 @@
37 brt.make_current();
38 img_renderer.render();
39 }
40+
41+ private:
42+ std::unique_ptr<mg::GLContext> const gl_context;
43+
44 };
45
46- return std::make_shared<RenderResourcesBufferInitializer>();
47+ return std::make_shared<RenderResourcesBufferInitializer>(the_display()->create_gl_context());
48 }
49 ///\internal [RenderResourcesBufferInitializer_tag]
50

Subscribers

People subscribed via source and target branches