=== modified file 'src/canvas-x11.cpp'
--- src/canvas-x11.cpp	2011-06-30 14:01:43 +0000
+++ src/canvas-x11.cpp	2011-08-09 10:51:03 +0000
@@ -76,11 +76,7 @@
     if (!xdpy_)
         return false;
 
-    XVisualInfo *visinfo = get_xvisualinfo();
-
-    xwin_ = create_canvas_x_window(xdpy_, "glmark2 "GLMARK_VERSION, mWidth, mHeight, visinfo);
-
-    XFree(visinfo);
+    resize(mWidth, mHeight);
 
     if (!xwin_)
         return false;
@@ -99,13 +95,8 @@
     glEnable(GL_CULL_FACE);
     glCullFace(GL_BACK);
 
-    glViewport(0, 0, mWidth, mHeight);
-
     clear();
 
-    mProjection = LibMatrix::Mat4::perspective(60.0, mWidth / (float)mHeight,
-                                               1.0, 1024.0);
-
     return true;
 }
 
@@ -193,3 +184,31 @@
 
     return false;
 }
+
+void
+CanvasX11::resize(int width, int height)
+{
+    /* Recreate an existing window only if it has actually been resized */
+    if (xwin_) {
+        if (mWidth != width || mHeight != height) {
+            XDestroyWindow(xdpy_, xwin_);
+            xwin_ = 0;
+        }
+        else {
+            return;
+        }
+    }
+
+    mWidth = width;
+    mHeight = height;
+
+    XVisualInfo *visinfo = get_xvisualinfo();
+
+    xwin_ = create_canvas_x_window(xdpy_, "glmark2 "GLMARK_VERSION, mWidth, mHeight, visinfo);
+
+    XFree(visinfo);
+
+    glViewport(0, 0, mWidth, mHeight);
+    mProjection = LibMatrix::Mat4::perspective(60.0, mWidth / (float)mHeight,
+                                               1.0, 1024.0);
+}

=== modified file 'src/canvas-x11.h'
--- src/canvas-x11.h	2011-06-30 13:13:14 +0000
+++ src/canvas-x11.h	2011-08-09 10:51:03 +0000
@@ -39,9 +39,11 @@
     virtual Pixel read_pixel(int x, int y);
     virtual void write_to_file(std::string &filename);
     virtual bool should_quit();
+    virtual void resize(int width, int height);
 
 protected:
-    CanvasX11(int width, int height) : Canvas(width, height) {}
+    CanvasX11(int width, int height) :
+        Canvas(width, height), xwin_(0), xdpy_(0) {}
 
     virtual XVisualInfo *get_xvisualinfo() = 0;
     virtual bool make_current() = 0;

=== modified file 'src/canvas.h'
--- src/canvas.h	2011-07-05 13:45:41 +0000
+++ src/canvas.h	2011-08-09 10:51:03 +0000
@@ -68,6 +68,7 @@
     }
     virtual void write_to_file(std::string &filename) { (void)filename; }
     virtual bool should_quit() { return false; }
+    virtual void resize(int width, int height) { (void)width; (void)height; }
 
     static Canvas &dummy()
     {

=== modified file 'src/main.cpp'
--- src/main.cpp	2011-08-04 14:21:27 +0000
+++ src/main.cpp	2011-08-09 11:13:43 +0000
@@ -214,9 +214,9 @@
 
     // Create the canvas
 #if USE_GL
-    CanvasX11GLX canvas(800, 600);
+    CanvasX11GLX canvas(Options::size.first, Options::size.second);
 #elif USE_GLESv2
-    CanvasX11EGL canvas(800, 600);
+    CanvasX11EGL canvas(Options::size.first, Options::size.second);
 #endif
 
     // Register the scenes, so they can be looked-up by name

=== modified file 'src/options.cpp'
--- src/options.cpp	2011-06-30 08:38:35 +0000
+++ src/options.cpp	2011-08-09 11:13:43 +0000
@@ -25,12 +25,16 @@
 #include <cstdlib>
 #include <cstdio>
 #include <getopt.h>
+#include <sstream>
 
 #include "options.h"
+#include "util.h"
+#include "log.h"
 
 std::vector<std::string> Options::benchmarks;
 bool Options::validate = false;
 bool Options::swap_buffers = true;
+std::pair<int,int> Options::size(800, 600);
 bool Options::list_scenes = false;
 bool Options::show_debug = false;
 bool Options::show_help = false;
@@ -39,12 +43,41 @@
     {"benchmark", 1, 0, 0},
     {"validate", 0, 0, 0},
     {"no-swap-buffers", 0, 0, 0},
+    {"size", 1, 0, 0},
     {"list-scenes", 0, 0, 0},
     {"debug", 0, 0, 0},
     {"help", 0, 0, 0},
     {0, 0, 0, 0}
 };
 
+/** 
+ * Parses a size string of the form WxH
+ * 
+ * @param str the string to parse
+ * @param size the parsed size (width, height) 
+ */
+static void
+parse_size(const std::string &str, std::pair<int,int> &size)
+{
+    std::vector<std::string> d;
+    Util::split(str, 'x', d);
+
+    std::stringstream ss(d[0]);
+    ss >> size.first;
+
+    /*
+     * Parse the second element (height). If there is none, use the value
+     * of the first element for the second (width = height)
+     */
+    if (d.size() > 1) {
+        ss.clear();
+        ss.str(d[1]);
+        ss >> size.second;
+    }
+    else 
+        size.second = size.first;
+}
+
 void
 Options::print_help()
 {
@@ -57,6 +90,7 @@
            "                         running the benchmarks\n"
            "      --no-swap-buffers  Don't update the canvas by swapping the front and\n"
            "                         back buffer, use glFinish() instead\n"
+           "  -s, --size WxH         Size of the display (default: 800x600)\n"
            "  -l, --list-scenes      Display information about the available scenes\n"
            "                         and their options\n"
            "  -d, --debug            Display debug messages\n"
@@ -71,7 +105,7 @@
         int c;
         const char *optname = "";
 
-        c = getopt_long(argc, argv, "b:ldh",
+        c = getopt_long(argc, argv, "b:s:ldh",
                         long_options, &option_index);
         if (c == -1)
             break;
@@ -87,6 +121,8 @@
             Options::validate = true;
         else if (!strcmp(optname, "no-swap-buffers"))
             Options::swap_buffers = false;
+        else if (c == 's' || !strcmp(optname, "size"))
+            parse_size(optarg, Options::size);
         else if (c == 'l' || !strcmp(optname, "list-scenes"))
             Options::list_scenes = true;
         else if (c == 'd' || !strcmp(optname, "debug"))

=== modified file 'src/options.h'
--- src/options.h	2011-06-15 11:25:14 +0000
+++ src/options.h	2011-08-09 11:13:43 +0000
@@ -34,6 +34,7 @@
     static std::vector<std::string> benchmarks;
     static bool validate;
     static bool swap_buffers;
+    static std::pair<int,int> size;
     static bool list_scenes;
     static bool show_debug;
     static bool show_help;

=== modified file 'src/scene-effect-2d.cpp'
--- src/scene-effect-2d.cpp	2011-08-09 10:34:49 +0000
+++ src/scene-effect-2d.cpp	2011-08-09 11:21:35 +0000
@@ -82,6 +82,7 @@
  * response). This also means that we don't need to perform the (implicit)
  * rotation of the kernel in our convolution implementation.
  *
+ * @param canvas the destination Canvas for this shader
  * @param array the array holding the filter coefficients in row-major
  *              order
  * @param width the width of the filter
@@ -90,7 +91,7 @@
  * @return a string containing the frament source code
  */
 static std::string
-create_convolution_fragment_shader(std::vector<float> &array,
+create_convolution_fragment_shader(Canvas &canvas, std::vector<float> &array,
                                    unsigned int width, unsigned int height)
 {
     static const std::string frg_shader_filename(GLMARK_DATA_PATH"/shaders/effect-2d-convolution.frag");
@@ -102,8 +103,8 @@
     }
 
     /* Steps are needed to be able to access nearby pixels */
-    source.add_const("TextureStepX", 1.0f/800.0f);
-    source.add_const("TextureStepY", 1.0f/600.0f);
+    source.add_const("TextureStepX", 1.0f/canvas.width());
+    source.add_const("TextureStepY", 1.0f/canvas.height());
 
     std::stringstream ss_def;
     std::stringstream ss_convolution;
@@ -314,7 +315,7 @@
     /* Create and load the shaders */
     ShaderSource vtx_source(vtx_shader_filename);
     ShaderSource frg_source;
-    frg_source.append(create_convolution_fragment_shader(kernel,
+    frg_source.append(create_convolution_fragment_shader(mCanvas, kernel,
                                                          kernel_width,
                                                          kernel_height));
 

