]> git.sesse.net Git - nageru/blobdiff - nageru/pbo_frame_allocator.cpp
Small refactoring in PBOAllocator::init_frame().
[nageru] / nageru / pbo_frame_allocator.cpp
index 709a2bf359e505ab7e089f567fce33b502427834..5910a0237fb6ce725072336666591a3c76f7799d 100644 (file)
@@ -47,7 +47,9 @@ PBOFrameAllocator::PBOFrameAllocator(bmusb::PixelFormat pixel_format, size_t fra
 {
        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);
+               Frame frame;
+               init_frame(frame, &userdata[i], this, pixel_format, frame_size, width, height, permissions, map_bits, buffer, generation);
+               freelist.push(frame);
        }
        glBindBuffer(buffer, 0);
        check_error();
@@ -55,7 +57,7 @@ PBOFrameAllocator::PBOFrameAllocator(bmusb::PixelFormat pixel_format, size_t fra
        check_error();
 }
 
-void PBOFrameAllocator::init_frame(size_t frame_idx, size_t frame_size, GLuint width, GLuint height, GLenum permissions, GLenum map_bits, int generation)
+void PBOFrameAllocator::init_frame(Frame &frame, Userdata *ud, PBOFrameAllocator *owner, bmusb::PixelFormat pixel_format, size_t frame_size, GLuint width, GLuint height, GLenum permissions, GLenum map_bits, GLenum buffer, int generation)
 {
        GLuint pbo;
        glGenBuffers(1, &pbo);
@@ -65,18 +67,16 @@ void PBOFrameAllocator::init_frame(size_t frame_idx, size_t frame_size, GLuint w
        glBufferStorage(buffer, frame_size, nullptr, permissions | GL_MAP_PERSISTENT_BIT);
        check_error();
 
-       Frame frame;
        frame.data = (uint8_t *)glMapBufferRange(buffer, 0, frame_size, permissions | map_bits | GL_MAP_PERSISTENT_BIT);
        frame.data2 = frame.data + frame_size / 2;
        check_error();
        frame.size = frame_size;
-       Userdata *ud = &userdata[frame_idx];
        frame.userdata = ud;
        ud->generation = generation;
        ud->pbo = pbo;
        ud->pixel_format = pixel_format;
        ud->data_copy_malloc = new uint8_t[frame_size];
-       frame.owner = this;
+       frame.owner = owner;
 
        // For 8-bit non-planar Y'CbCr, we ask the driver to split Y' and Cb/Cr
        // into separate textures. For 10-bit, the input format (v210)
@@ -214,8 +214,6 @@ void PBOFrameAllocator::init_frame(size_t frame_idx, size_t frame_size, GLuint w
                        assert(false);
                }
        }
-
-       freelist.push(frame);
 }
 
 PBOFrameAllocator::~PBOFrameAllocator()
@@ -465,7 +463,9 @@ void PBOFrameAllocator::reconfigure(bmusb::PixelFormat pixel_format,
 
        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);
+               Frame frame;
+               init_frame(frame, &userdata[i], this, pixel_format, frame_size, width, height, permissions, map_bits, buffer, generation);
+               freelist.push(frame);
        }
 
        // There may still be frames out with the old configuration