Mir

Merge lp:~alan-griffiths/mir/client-side-buffer-age into lp:~raof/mir/client-side-buffer-age

Proposed by Alan Griffiths
Status: Merged
Merged at revision: 468
Proposed branch: lp:~alan-griffiths/mir/client-side-buffer-age
Merge into: lp:~raof/mir/client-side-buffer-age
Diff against target: 96 lines (+37/-32)
2 files modified
src/client/gbm/gbm_client_buffer_depository.cpp (+34/-30)
src/client/gbm/gbm_client_buffer_depository.h (+3/-2)
To merge this branch: bzr merge lp:~alan-griffiths/mir/client-side-buffer-age
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Chris Halse Rogers Pending
Review via email: mp+152392@code.launchpad.net

Commit message

client: Suggestion to make code easier to follow

Description of the change

client: Suggestion to make code easier to follow

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:470
http://jenkins.qa.ubuntu.com/job/mir-ci/27/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/mir-quantal-amd64-ci/27//console

Click here to trigger a rebuild:
http://jenkins.qa.ubuntu.com/job/mir-ci/27//rebuild/?

review: Approve (continuous-integration)
Revision history for this message
Chris Halse Rogers (raof) wrote :

I didn't write it this way originally because we're unnecessarily iterating through the buffer list twice in a once-pre-frame function.

That said, this *is* much clearer¹, we should only have at most 3 buffers in the BufferMap, and if we need to speed things up we can always come back and revisit the performance/obviousness trade.

¹: Except for the "auto current = next++;" - I know what it does, but I need to *think* about what it does. ☺

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/client/gbm/gbm_client_buffer_depository.cpp'
2--- src/client/gbm/gbm_client_buffer_depository.cpp 2013-03-08 01:29:56 +0000
3+++ src/client/gbm/gbm_client_buffer_depository.cpp 2013-03-08 15:01:20 +0000
4@@ -28,43 +28,47 @@
5
6 mclg::GBMClientBufferDepository::GBMClientBufferDepository(
7 std::shared_ptr<DRMFDHandler> const& drm_fd_handler)
8- : drm_fd_handler{drm_fd_handler}
9+ : current_buffer(buffers.end()), drm_fd_handler{drm_fd_handler}
10 {
11 }
12
13 void mclg::GBMClientBufferDepository::deposit_package(std::shared_ptr<mir_toolkit::MirBufferPackage>&& package, int id, geometry::Size size, geometry::PixelFormat pf)
14 {
15- auto buffer_it = buffers.begin();
16- while (buffer_it != buffers.end())
17- {
18- // C++ guarantees that buffers.erase() will only invalidate the iterator
19- // we erase. Move to the next buffer before we potentially invalidate our
20- // iterator.
21- auto current = buffer_it;
22- ++buffer_it;
23-
24- if (current->first == current_buffer)
25- {
26- current->second->mark_as_submitted();
27- }
28- else
29- {
30- if (current->second->age() >= 2 && (current->first != static_cast<uint32_t>(id)))
31- {
32- buffers.erase(current);
33- }
34- else
35- {
36- current->second->increment_age();
37- }
38- }
39- }
40- if (buffers.count(id) == 0)
41- buffers[id] = std::make_shared<mclg::GBMClientBuffer>(drm_fd_handler, std::move(package), size, pf);
42- current_buffer = id;
43+ for (auto next = buffers.begin(); next != buffers.end();)
44+ {
45+ // C++ guarantees that buffers.erase() will only invalidate the iterator we
46+ // erase. Move to the next buffer before we potentially invalidate our iterator.
47+ auto current = next++;
48+
49+ if (current != current_buffer &&
50+ current->first != id &&
51+ current->second->age() >= 2)
52+ {
53+ buffers.erase(current);
54+ }
55+ }
56+
57+ for (auto& current : buffers)
58+ {
59+ current.second->increment_age();
60+ }
61+
62+ if (current_buffer != buffers.end())
63+ {
64+ current_buffer->second->mark_as_submitted();
65+ }
66+
67+ current_buffer = buffers.find(id);
68+
69+ if (current_buffer == buffers.end())
70+ {
71+ auto new_buffer = std::make_shared<mclg::GBMClientBuffer>(drm_fd_handler, std::move(package), size, pf);
72+
73+ current_buffer = buffers.insert(current_buffer, std::make_pair(id, new_buffer));
74+ }
75 }
76
77 std::shared_ptr<mcl::ClientBuffer> mclg::GBMClientBufferDepository::access_current_buffer()
78 {
79- return buffers[current_buffer];
80+ return current_buffer->second;
81 }
82
83=== modified file 'src/client/gbm/gbm_client_buffer_depository.h'
84--- src/client/gbm/gbm_client_buffer_depository.h 2013-03-08 01:29:56 +0000
85+++ src/client/gbm/gbm_client_buffer_depository.h 2013-03-08 15:01:20 +0000
86@@ -46,8 +46,9 @@
87
88 std::shared_ptr<ClientBuffer> access_current_buffer();
89 private:
90- std::map<uint32_t, std::shared_ptr<GBMClientBuffer>> buffers;
91- uint32_t current_buffer;
92+ typedef std::map<int, std::shared_ptr<GBMClientBuffer>> BufferMap;
93+ BufferMap buffers;
94+ BufferMap::iterator current_buffer;
95 std::shared_ptr<DRMFDHandler> drm_fd_handler;
96 };
97

Subscribers

People subscribed via source and target branches