~mir-team/mir/development-branch

« back to all changes in this revision

Viewing changes to src/server/graphics/software_cursor.cpp

  • Committer: Tarmac
  • Author(s): Kevin DuBois
  • Date: 2015-02-05 15:33:26 UTC
  • mfrom: (2291.1.2 fix-1413211)
  • Revision ID: tarmac-20150205153326-zbck48f3x3p3eg8a
Ensure that mg::Buffer::write won't block when writing the SoftwareCursor by allocating a fresh buffer each time an update is needed.

fixes: LP: #1413211. Fixes: https://bugs.launchpad.net/bugs/1413211.

Approved by Alan Griffiths, Alexandros Frantzis, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
    // Do a lock dance to make this function threadsafe,
128
128
    // while avoiding calling scene methods under lock
129
129
    {
 
130
        geom::Point position{0,0};
130
131
        std::lock_guard<std::mutex> lg{guard};
131
 
        new_renderable = create_renderable_for(cursor_image);
 
132
        if (renderable)
 
133
            position = renderable->screen_position().top_left;
 
134
        new_renderable = create_renderable_for(cursor_image, position);
132
135
    }
133
136
 
134
137
    // Add the new renderable first, then remove the old one to avoid
148
151
}
149
152
 
150
153
std::shared_ptr<mg::detail::CursorRenderable>
151
 
mg::SoftwareCursor::create_renderable_for(CursorImage const& cursor_image)
 
154
mg::SoftwareCursor::create_renderable_for(CursorImage const& cursor_image, geom::Point position)
152
155
{
153
 
    std::shared_ptr<detail::CursorRenderable> new_renderable;
154
 
 
155
 
    // Reuse buffer if possible, to minimize buffer reallocations
156
 
    if (renderable && renderable->buffer()->size() == cursor_image.size())
157
 
    {
158
 
        new_renderable = std::make_shared<detail::CursorRenderable>(
159
 
            renderable->buffer(),
160
 
            renderable->screen_position().top_left + hotspot -
161
 
                cursor_image.hotspot());
162
 
    }
163
 
    else
164
 
    {
165
 
        auto const buffer = allocator->alloc_buffer(
166
 
            {cursor_image.size(), format, mg::BufferUsage::software});
167
 
        new_renderable = std::make_shared<detail::CursorRenderable>(
168
 
            buffer,
169
 
            geom::Point{0,0} - cursor_image.hotspot());
170
 
    }
 
156
    auto new_renderable = std::make_shared<detail::CursorRenderable>(
 
157
        allocator->alloc_buffer({cursor_image.size(), format, mg::BufferUsage::software}),
 
158
        position + hotspot - cursor_image.hotspot());
171
159
 
172
160
    size_t const pixels_size =
173
161
        cursor_image.size().width.as_uint32_t() *