~vanvugt/mir/frontend-server

« back to all changes in this revision

Viewing changes to src/server/compositor/switching_bundle.cpp

  • Committer: Daniel van Vugt
  • Date: 2014-03-11 04:27:30 UTC
  • mfrom: (1416.1.43 development-branch)
  • Revision ID: daniel.van.vugt@canonical.com-20140311042730-885xmim7i3sm4zga
MergeĀ latestĀ development-branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
182
182
    return ring[slot].buf;
183
183
}
184
184
 
 
185
inline
 
186
bool mc::SwitchingBundle::client_buffers_available(std::unique_lock<std::mutex> const& /*lock*/)
 
187
{
 
188
    /*
 
189
     * Even if there are free buffers available, we might wish to still
 
190
     * wait. This is so we don't touch (hence allocate) a third or higher
 
191
     * buffer until/unless it's absolutely necessary. It becomes necessary
 
192
     * only when framedropping (above) or with overlapping compositors
 
193
     * (like with bypass).
 
194
     * The performance benefit of triple buffering is usually minimal,
 
195
     * but always uses 50% more memory. So try to avoid it when possible.
 
196
     */
 
197
 
 
198
    int min_free =
 
199
#if 0  // FIXME: This memory optimization breaks timing tests
 
200
        (nbuffers > 2 && !overlapping_compositors) ?  nbuffers - 1 : 1;
 
201
#else
 
202
        1;
 
203
#endif
 
204
 
 
205
    return nfree() >= min_free;
 
206
}
 
207
 
185
208
void mc::SwitchingBundle::client_acquire(std::function<void(graphics::Buffer* buffer)> complete)
186
209
{
187
210
    std::unique_lock<std::mutex> lock(guard);
199
222
    }
200
223
    else
201
224
    {
202
 
        /*
203
 
         * Even if there are free buffers available, we might wish to still
204
 
         * wait. This is so we don't touch (hence allocate) a third or higher
205
 
         * buffer until/unless it's absolutely necessary. It becomes necessary
206
 
         * only when framedropping (above) or with overlapping compositors
207
 
         * (like with bypass).
208
 
         * The performance benefit of triple buffering is usually minimal,
209
 
         * but always uses 50% more memory. So try to avoid it when possible.
210
 
         */
211
 
 
212
 
        int min_free =
213
 
#if 0  // FIXME: This memory optimization breaks timing tests
214
 
            (nbuffers > 2 && !overlapping_compositors) ?  nbuffers - 1 : 1;
215
 
#else
216
 
            1;
217
 
#endif
218
 
 
219
 
        if (nfree() < min_free)
 
225
        if (!client_buffers_available(lock))
220
226
            return;
221
227
    }
222
228
 
362
368
            ncompositors--;
363
369
        }
364
370
 
365
 
        if (client_acquire_todo) complete_client_acquire(std::move(lock));
 
371
        if (client_buffers_available(lock) && client_acquire_todo)
 
372
            complete_client_acquire(std::move(lock));
366
373
    }
367
374
}
368
375