From patchwork Wed Aug 17 14:17:13 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: 3486 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 26CE323F70 for ; Wed, 17 Aug 2011 14:17:17 +0000 (UTC) Received: from mail-ey0-f170.google.com (mail-ey0-f170.google.com [209.85.215.170]) by fiordland.canonical.com (Postfix) with ESMTP id 3D71AA1829E for ; Wed, 17 Aug 2011 14:17:16 +0000 (UTC) Received: by eyd10 with SMTP id 10so794525eyd.29 for ; Wed, 17 Aug 2011 07:17:16 -0700 (PDT) Received: by 10.213.29.147 with SMTP id q19mr1260147ebc.132.1313590635089; Wed, 17 Aug 2011 07:17:15 -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.213.102.5 with SMTP id e5cs20611ebo; Wed, 17 Aug 2011 07:17:14 -0700 (PDT) Received: from mr.google.com ([10.216.121.15]) by 10.216.121.15 with SMTP id q15mr6262545weh.104.1313590634833 (num_hops = 1); Wed, 17 Aug 2011 07:17:14 -0700 (PDT) Received: by 10.216.121.15 with SMTP id q15mr4212851weh.104.1313590634284; Wed, 17 Aug 2011 07:17:14 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com [91.189.90.7]) by mx.google.com with ESMTPS id w55si19539wec.26.2011.08.17.07.17.14 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 17 Aug 2011 07:17:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1Qtgvh-0005NZ-IL for ; Wed, 17 Aug 2011 14:17:13 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 7A8DBE0108 for ; Wed, 17 Aug 2011 14:17:13 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: glcompbench X-Launchpad-Branch: ~glcompbench-dev/glcompbench/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 57 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glcompbench-dev/glcompbench/trunk] Rev 57: Add double buffering support to the Xrender canvas. Message-Id: <20110817141713.8884.33791.launchpad@ackee.canonical.com> Date: Wed, 17 Aug 2011 14:17:13 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13697"; Instance="initZopeless config overlay" X-Launchpad-Hash: 92e5267a1224f4acdb454bdf39c9f6d0eb9366de ------------------------------------------------------------ revno: 57 committer: Alexandros Frantzis branch nick: trunk timestamp: Wed 2011-08-17 17:15:49 +0300 message: Add double buffering support to the Xrender canvas. modified: src/composite-canvas-xrender.cc src/composite-canvas-xrender.h --- lp:glcompbench https://code.launchpad.net/~glcompbench-dev/glcompbench/trunk You are subscribed to branch lp:glcompbench. To unsubscribe from this branch go to https://code.launchpad.net/~glcompbench-dev/glcompbench/trunk/+edit-subscription === modified file 'src/composite-canvas-xrender.cc' --- src/composite-canvas-xrender.cc 2011-08-03 17:13:02 +0000 +++ src/composite-canvas-xrender.cc 2011-08-17 14:15:49 +0000 @@ -30,8 +30,6 @@ #include "options.h" #include "log.h" -#include - CompositeCanvasXRender::~CompositeCanvasXRender() { release_resources(); @@ -56,14 +54,92 @@ } bool +CompositeCanvasXRender::have_xdbe() +{ + int major, minor; + bool have_xdbe = false; + + /* Check for the Xdbe extension */ + if (XdbeQueryExtension(xdpy_, &major, &minor)) { + Log::debug("Xdbe extension version %d.%d\n", major, minor); + have_xdbe = true; + } + else { + Log::info("** Xdbe extension not supported. You may experience flickering.\n"); + } + + return have_xdbe; +} + +bool +CompositeCanvasXRender::ensure_xdbe_back_buffer() +{ + XdbeScreenVisualInfo *xdbe_screen_vis_info; + XWindowAttributes canvas_attr; + int num_screens = 1; + bool dbe_visual_found = false; + + if (xdbe_back_buffer_) + return true; + + if (!have_xdbe()) + return false; + + /* Check if the canvas visual supports double-buffering */ + if (!XGetWindowAttributes(xdpy_, canvas_, &canvas_attr)) { + Log::error("XGetWindowAttributes failed!\n"); + return false; + } + + xdbe_screen_vis_info = XdbeGetVisualInfo(xdpy_, &canvas_, &num_screens); + if (!xdbe_screen_vis_info || num_screens == 0) { + Log::error("XdbeGetVisualInfo failed!\n"); + return false; + } + + for (int i = 0; i < xdbe_screen_vis_info[0].count; i++) { + XdbeVisualInfo *vis_info = &xdbe_screen_vis_info[0].visinfo[i]; + if (vis_info->visual == XVisualIDFromVisual(canvas_attr.visual)) { + dbe_visual_found = true; + break; + } + } + + XdbeFreeVisualInfo(xdbe_screen_vis_info); + + if (!dbe_visual_found) { + Log::info("** The window visual does not support double buffering." + " You may experience flickering!\n"); + return false; + } + + /* Allocate the back buffer */ + xdbe_back_buffer_ = XdbeAllocateBackBufferName(xdpy_, canvas_, + XdbeBackground); + if (!xdbe_back_buffer_) { + Log::error("XdbeAllocateBufferName failed!\n"); + return false; + } + + return true; +} + +bool CompositeCanvasXRender::ensure_xrender_picture() { + Drawable drawable; + if (xrender_picture_) return true; if (!have_xrender()) return false; + if (!ensure_xdbe_back_buffer()) + drawable = canvas_; + else + drawable = xdbe_back_buffer_; + XWindowAttributes canvas_attr; if (!XGetWindowAttributes(xdpy_, canvas_, &canvas_attr)) { @@ -81,7 +157,7 @@ return false; } - xrender_picture_ = XRenderCreatePicture(xdpy_, canvas_, pict_format, + xrender_picture_ = XRenderCreatePicture(xdpy_, drawable, pict_format, 0, NULL); if (!xrender_picture_) { Log::error("XRenderCreatePicture failed!\n"); @@ -132,7 +208,11 @@ if (xrender_picture_) XRenderFreePicture(xdpy_, xrender_picture_); + if (xdbe_back_buffer_) + XdbeDeallocateBackBufferName(xdpy_, xdbe_back_buffer_); + xrender_picture_ = 0; + xdbe_back_buffer_ = 0; } CompositeWindow * @@ -144,6 +224,10 @@ void CompositeCanvasXRender::update_screen() { + if (xdbe_back_buffer_) { + XdbeSwapInfo swap_info = {canvas_, XdbeBackground}; + XdbeSwapBuffers(xdpy_, &swap_info, 1); + } } std::string === modified file 'src/composite-canvas-xrender.h' --- src/composite-canvas-xrender.h 2011-08-03 17:13:02 +0000 +++ src/composite-canvas-xrender.h 2011-08-17 14:15:49 +0000 @@ -29,12 +29,14 @@ #include #include #include +#include class CompositeCanvasXRender: public CompositeCanvas { public: CompositeCanvasXRender() : - CompositeCanvas("xrender"), xrender_picture_(0) {} + CompositeCanvas("xrender"), xrender_picture_(0), xdbe_back_buffer_(0) + {} virtual ~CompositeCanvasXRender(); @@ -50,10 +52,13 @@ void reshape(int width, int height); private: + bool have_xdbe(); + bool have_xrender(); + bool ensure_xdbe_back_buffer(); bool ensure_xrender_picture(); - bool have_xrender(); Picture xrender_picture_; + XdbeBackBuffer xdbe_back_buffer_; }; #endif /* COMPOSITE_CANVAS_XRENDER_H_ */