~raof/mir/client-side-buffer-age

« back to all changes in this revision

Viewing changes to src/client/gbm/gbm_client_buffer_depository.cpp

  • Committer: Christopher James Halse Rogers
  • Date: 2013-03-10 08:21:20 UTC
  • mfrom: (467.1.3 mir3)
  • Revision ID: raof@ubuntu.com-20130310082120-9sp8xi0xvdx37tno
Merge Alan's simplification of deposit_buffer

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
mclg::GBMClientBufferDepository::GBMClientBufferDepository(
30
30
        std::shared_ptr<DRMFDHandler> const& drm_fd_handler)
31
 
    : drm_fd_handler{drm_fd_handler}
 
31
    : current_buffer(buffers.end()), drm_fd_handler{drm_fd_handler}
32
32
{
33
33
}
34
34
 
35
35
void mclg::GBMClientBufferDepository::deposit_package(std::shared_ptr<mir_toolkit::MirBufferPackage>&& package, int id, geometry::Size size, geometry::PixelFormat pf)
36
36
{
37
 
    auto buffer_it = buffers.begin();
38
 
    while (buffer_it != buffers.end())
39
 
    {
40
 
        // C++ guarantees that buffers.erase() will only invalidate the iterator
41
 
        // we erase. Move to the next buffer before we potentially invalidate our
42
 
        // iterator.
43
 
        auto current = buffer_it;
44
 
        ++buffer_it;
45
 
 
46
 
        if (current->first == current_buffer)
47
 
        {
48
 
            current->second->mark_as_submitted();
49
 
        }
50
 
        else
51
 
        {
52
 
            if (current->second->age() >= 2 && (current->first != static_cast<uint32_t>(id)))
53
 
            {
54
 
                buffers.erase(current);
55
 
            }
56
 
            else
57
 
            {
58
 
                current->second->increment_age();
59
 
            }
60
 
        }
61
 
    }
62
 
    if (buffers.count(id) == 0)
63
 
        buffers[id] = std::make_shared<mclg::GBMClientBuffer>(drm_fd_handler, std::move(package), size, pf);
64
 
    current_buffer = id;
 
37
    for (auto next = buffers.begin(); next != buffers.end();)
 
38
    {
 
39
        // C++ guarantees that buffers.erase() will only invalidate the iterator we
 
40
        // erase. Move to the next buffer before we potentially invalidate our iterator.
 
41
        auto current = next;
 
42
        next++;
 
43
 
 
44
        if (current != current_buffer &&
 
45
            current->first != id &&
 
46
            current->second->age() >= 2)
 
47
        {
 
48
            buffers.erase(current);
 
49
        }
 
50
    }
 
51
 
 
52
    for (auto& current : buffers)
 
53
    {
 
54
        current.second->increment_age();
 
55
    }
 
56
 
 
57
    if (current_buffer != buffers.end())
 
58
    {
 
59
        current_buffer->second->mark_as_submitted();
 
60
    }
 
61
 
 
62
    current_buffer = buffers.find(id);
 
63
 
 
64
    if (current_buffer == buffers.end())
 
65
    {
 
66
        auto new_buffer = std::make_shared<mclg::GBMClientBuffer>(drm_fd_handler, std::move(package), size, pf);
 
67
 
 
68
        current_buffer = buffers.insert(current_buffer, std::make_pair(id, new_buffer));
 
69
    }
65
70
}
66
71
 
67
72
std::shared_ptr<mcl::ClientBuffer> mclg::GBMClientBufferDepository::access_current_buffer()
68
73
{
69
 
    return buffers[current_buffer];
 
74
    return current_buffer->second;
70
75
}