Try to avoid copying the GdkPixbuf when it is tightly packed
authorNeil Roberts <neil@linux.intel.com>
Thu, 15 Jul 2010 10:32:08 +0000 (11:32 +0100)
committerNeil Roberts <neil@linux.intel.com>
Thu, 15 Jul 2010 16:25:36 +0000 (17:25 +0100)
commitb780413e5ae4b4fea2130b85d7590d397aea8cac
treec664ce30763ea3ef3ded4310440cf714f7eb2183
parentfc12c42a83084b9d3acd1ed5a1b3dd34057f54d8
Try to avoid copying the GdkPixbuf when it is tightly packed

The docs for GdkPixbuf say that the last row of the image won't
necessarily be allocated to the size of the full rowstride. The rest
of Cogl and possibly GL assumes that we can copy the bitmap with
memcpy(height*rowstride) so we previously would copy the pixbuf data
to ensure this. However if the rowstride is the same as bpp*width then
there is no way for the last row to be under-allocated so in this case
we can just directly upload from the gdk pixbuf. Now that CoglBitmap
can be created with a destroy function we can make it keep a reference
to the pixbuf and unref it during its destroy callback. GdkPixbuf
seems to always pack the image with no padding between rows even if it
is RGB so this should end up always avoiding the memcpy.

The fallback code for when we do have to copy the pixbuf is now
simplified so that it copies all of the rows in a single loop. We only
copy the useful region of each row so this should be safe. The
rowstride of the CoglBitmap is now always allocated to bpp*width
regardless of the rowstride of the pixbuf.
clutter/cogl/cogl/cogl-bitmap-pixbuf.c