[Interest] allocate QImage data in QSharedMemory

Konstantin Shegunov kshegunov at gmail.com
Mon Dec 12 22:59:54 CET 2016


Hi,
Why not construct the image object from the shared memory buffer to begin
with? Then lock the sm while drawing.
Look for example this constructor:
http://doc.qt.io/qt-5/qimage.html#QImage-3

On Mon, Dec 12, 2016 at 11:45 PM, Joshua Grauman <jnfo-c at grauman.com> wrote:

> Hello all,
>
> I have been able to generate a screen capture of my program by rendering a
> window into a QImage at 30fps (called from QTimer), and then copying the
> QImage to shared memory (QSharedMemory) where another program grabs the
> frames and outputs them to ffmpeg. It all works great.
>
> However, my cpu is barely keeping up if I do much on my app.
>
> One of the ways I thought of to speed it up is to avoid the memcpy from
> the QImage (img) to QSharedMemory (sharedMemory) by deriving from QImage to
> a new class (QSharedMemoryImage) which allocates its image data in shared
> memory to begin with so that the window->render() function renders the
> window right into shared memory so the copy isn't necessary. QImage was a
> bit too complex for me to figure out how to do this.
>
> For you experts, is this possible? How hard would it be?
>
> Here's the relevant code in the QTimer:
>
>   window->render(&img, QPoint(), QRegion(), QWidget::DrawChildren);
>   sharedMemory.lock();
>   char *to = (char*)sharedMemory.data();
>   const unsigned char *from = img.constBits();
>   memcpy(to, from, sharedMemory.size());
>   sharedMemory.unlock();
>
> Josh
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20161212/9d6f4324/attachment.html>


More information about the Interest mailing list