X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fpbo_frame_allocator.cpp;fp=nageru%2Fpbo_frame_allocator.cpp;h=70675b1a630dfbdf1c30730f5134e9f014820c41;hb=f4dc4d6d393026a5507be1f04a9149f6b8c2322c;hp=f9b4601ec3653da0e23fd349a54ad2475291d085;hpb=afd3391c734ec861d2be4f543e596ad98d6b557e;p=nageru diff --git a/nageru/pbo_frame_allocator.cpp b/nageru/pbo_frame_allocator.cpp index f9b4601..70675b1 100644 --- a/nageru/pbo_frame_allocator.cpp +++ b/nageru/pbo_frame_allocator.cpp @@ -264,6 +264,14 @@ void PBOFrameAllocator::destroy_frame(Frame *frame) default: assert(false); } + + if (ud->generation != generation) { + auto it = lingering_generations.find(ud->generation); + assert(it != lingering_generations.end()); + if (--it->second.num_frames_left == 0) { + lingering_generations.erase(it); // Deallocates the userdata block. + } + } } //static int sumsum = 0; @@ -429,6 +437,8 @@ void PBOFrameAllocator::reconfigure(bmusb::PixelFormat pixel_format, return; } + size_t old_num_queued_frames = this->num_queued_frames; + this->pixel_format = pixel_format; this->frame_size = frame_size; this->width = width; @@ -441,12 +451,16 @@ void PBOFrameAllocator::reconfigure(bmusb::PixelFormat pixel_format, this->map_bits = map_bits; lock_guard lock(freelist_mutex); + lingering_generations[generation] = LingeringGeneration{ move(userdata), old_num_queued_frames }; + ++generation; + while (!freelist.empty()) { Frame frame = freelist.front(); freelist.pop(); destroy_frame(&frame); } - ++generation; + + userdata.reset(new Userdata[num_queued_frames]); for (size_t i = 0; i < num_queued_frames; ++i) { init_frame(i, frame_size, width, height, permissions, map_bits, generation); }