summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorAndrzej Hunt <andrzej.hunt@collabora.com>2014-05-25 16:42:17 +0100
committerAndrzej Hunt <andrzej.hunt@collabora.com>2014-06-25 13:04:30 +0100
commit24dfd0a0d65bf72c2c083c28c4d6c6a8b9ebe3cf (patch)
tree5ee9b25d2d31dca966e058819c1c6c1e1df6d411 /desktop
parent67d7bad694928e8a5d7416de21c612822e14dadc (diff)
Upgrade gtktiledviewer to use its own buffer.
Change-Id: I3f567ff19ee0d5b0d54aeef9b163b78567d72946
Diffstat (limited to 'desktop')
-rw-r--r--desktop/qa/gtktiledviewer/gtktiledviewer.cxx42
1 files changed, 29 insertions, 13 deletions
diff --git a/desktop/qa/gtktiledviewer/gtktiledviewer.cxx b/desktop/qa/gtktiledviewer/gtktiledviewer.cxx
index 51d9414198ee..2ffa59907171 100644
--- a/desktop/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/desktop/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -32,6 +32,7 @@ static int help()
}
static GtkWidget* ourCanvas;
+static GdkPixbuf* ourPixBuf = 0;
bool drawCallback(GtkWidget* /* The eventbox */, void* /* cairo_t* cr */, gpointer pData)
{
@@ -46,25 +47,41 @@ bool drawCallback(GtkWidget* /* The eventbox */, void* /* cairo_t* cr */, gpoint
int nRenderWidth = nWidth / 10;
int nRenderHeight = nHeight / 10;
int nRowStride;
- unsigned char* pBuffer = pDocument->paintTile( nRenderWidth, nRenderHeight,
- &nRowStride,
- 0, 0, // origin
- nWidth, nHeight );
+
+ if ( ourPixBuf &&
+ (gdk_pixbuf_get_width( ourPixBuf ) != nRenderWidth ||
+ gdk_pixbuf_get_height( ourPixBuf ) != nRenderHeight ) )
+ {
+ g_object_unref( G_OBJECT( ourPixBuf ) );
+ ourPixBuf = 0;
+
+ }
+ if (!ourPixBuf)
+ {
+ ourPixBuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB,
+ true, 8,
+ nRenderWidth, nRenderHeight);
+ }
+
+ unsigned char* pBuffer = gdk_pixbuf_get_pixels( ourPixBuf );
+
+ pDocument->paintTile( pBuffer,
+ nRenderWidth, nRenderHeight,
+ &nRowStride,
+ 0, 0, // origin
+ nWidth, nHeight );
+ // TODO: double check that the rowstride really matches what we expected,
+ // although presumably we'd already be crashing by now if things were
+ // wrong.
+ (void) nRowStride;
for (int i = 3; i < nRowStride*nRenderHeight; i += 4)
{
pBuffer[i] = 0xFF;
}
- GdkPixbuf* pBixBuf = gdk_pixbuf_new_from_data( pBuffer, GDK_COLORSPACE_RGB,
- true, 8,
- nRenderWidth, nRenderHeight,
- nRowStride,
- 0, 0 );
- pBixBuf = gdk_pixbuf_flip( pBixBuf, false );
- gtk_image_set_from_pixbuf( GTK_IMAGE(ourCanvas), pBixBuf );
+ gtk_image_set_from_pixbuf( GTK_IMAGE( ourCanvas ), ourPixBuf );
- // TODO: we need to keep track of and cleanup these buffers etc.
return true;
}
@@ -108,7 +125,6 @@ int main( int argc, char* argv[] )
ourCanvas = pCanvas;
gtk_container_add( GTK_CONTAINER( pEventBox ), pCanvas );
-
g_signal_connect( G_OBJECT(pEventBox), "button-press-event", G_CALLBACK(drawCallback), pDocument);
gtk_widget_show( pCanvas );