Mir

Code review comment for lp:~vanvugt/mir/async-page-flips

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

Alexandros,

You are mistaken and I am indeed aware of the perils of touching the currently-scanning-out-buffer. Learned that the hard way when I did bypass... Fortunately when you do make that mistake it's usually visibly obvious.

What makes this proposal safe is that we hold both the buffer being scheduled and the buffer currently visible ("last_flipped_"), to ensure neither of them ever get modified until they have been retired by a later page flip.

Buffers are only released when they are neither scheduled, nor being scanned out:

// Presently visible is either last_flipped_bufobj (composited), last_flipped_bypass_buf (bypassed) or
// scheduled_bufobj (recently flipped which replaced last_flipped_bufobj).
wait_for_page_flip();

// Now presently visible is either scheduled_bufobj (composited) or last_flipped_bypass_buf (bypassed), so
// those are the ones we need to continue holding references to.

if (scheduled_bufobj) // switched from bypass to now compositing
    last_flipped_bypass_buf = nullptr; // release formerly bypassed buffer

// last_flipped_bufobj is now guaranteed no longer on screen, since wait_for_page_flip
if (last_flipped_bufobj)
    last_flipped_bufobj->release();

// Hold the reference so we don't release/reuse the on-screen buffer until something replaces it
last_flipped_bufobj = scheduled_bufobj;

It's confusing I know. But I believe it is correct.

« Back to merge proposal