From patchwork Wed Aug 10 13:58:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexandros.frantzis@linaro.org X-Patchwork-Id: 3373 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 078F423F46 for ; Wed, 10 Aug 2011 13:58:24 +0000 (UTC) Received: from mail-qw0-f52.google.com (mail-qw0-f52.google.com [209.85.216.52]) by fiordland.canonical.com (Postfix) with ESMTP id AD7EEA18261 for ; Wed, 10 Aug 2011 13:58:23 +0000 (UTC) Received: by qwb8 with SMTP id 8so813305qwb.11 for ; Wed, 10 Aug 2011 06:58:23 -0700 (PDT) Received: by 10.229.159.194 with SMTP id k2mr3021153qcx.83.1312984703026; Wed, 10 Aug 2011 06:58:23 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.190.71 with SMTP id dh7cs81759qcb; Wed, 10 Aug 2011 06:58:22 -0700 (PDT) Received: from mr.google.com ([10.227.174.73]) by 10.227.174.73 with SMTP id s9mr9441555wbz.75.1312984702604 (num_hops = 1); Wed, 10 Aug 2011 06:58:22 -0700 (PDT) Received: by 10.227.174.73 with SMTP id s9mr6879669wbz.75.1312984701644; Wed, 10 Aug 2011 06:58:21 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id p2si2510775wbh.34.2011.08.10.06.58.21; Wed, 10 Aug 2011 06:58:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) client-ip=91.189.90.139; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) smtp.mail=bounces@canonical.com Received: from loganberry.canonical.com ([91.189.90.37]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1Qr9Ia-0004nf-Uh for ; Wed, 10 Aug 2011 13:58:20 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id E6B1B2E8005 for ; Wed, 10 Aug 2011 13:58:20 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: glmark2 X-Launchpad-Branch: ~glmark2-dev/glmark2/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 119 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glmark2-dev/glmark2/trunk] Rev 119: Add support for setting the size of the drawing area. Message-Id: <20110810135820.1453.25239.launchpad@loganberry.canonical.com> Date: Wed, 10 Aug 2011 13:58:20 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13636"; Instance="initZopeless config overlay" X-Launchpad-Hash: 17379dab3cf5ba7f97393d4f8297bf49697efc21 Merge authors: Alexandros Frantzis (afrantzis) ------------------------------------------------------------ revno: 119 [merge] committer: Alexandros Frantzis branch nick: trunk timestamp: Tue 2011-08-09 16:13:04 +0300 message: Add support for setting the size of the drawing area. modified: src/canvas-x11.cpp src/canvas-x11.h src/canvas.h src/main.cpp src/options.cpp src/options.h src/scene-effect-2d.cpp --- lp:glmark2 https://code.launchpad.net/~glmark2-dev/glmark2/trunk You are subscribed to branch lp:glmark2. To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription === 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 #include #include +#include #include "options.h" +#include "util.h" +#include "log.h" std::vector Options::benchmarks; bool Options::validate = false; bool Options::swap_buffers = true; +std::pair 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 &size) +{ + std::vector 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 benchmarks; static bool validate; static bool swap_buffers; + static std::pair 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 &array, +create_convolution_fragment_shader(Canvas &canvas, std::vector &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));