From patchwork Fri Sep 6 19:08:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lespiau, Damien" X-Patchwork-Id: 2854971 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 887AC9F2D6 for ; Fri, 6 Sep 2013 19:15:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1430620319 for ; Fri, 6 Sep 2013 19:15:56 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 16CFC20318 for ; Fri, 6 Sep 2013 19:15:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EF706E768B for ; Fri, 6 Sep 2013 12:15:54 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTP id E46B1E764C for ; Fri, 6 Sep 2013 12:09:06 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP; 06 Sep 2013 12:06:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.90,856,1371106800"; d="scan'208";a="374564963" Received: from unknown (HELO strange.amr.corp.intel.com) ([10.255.14.105]) by orsmga001.jf.intel.com with ESMTP; 06 Sep 2013 12:09:05 -0700 From: Damien Lespiau To: intel-gfx@lists.freedesktop.org Date: Fri, 6 Sep 2013 20:08:40 +0100 Message-Id: <1378494530-3600-3-git-send-email-damien.lespiau@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1378494530-3600-1-git-send-email-damien.lespiau@intel.com> References: <1378494530-3600-1-git-send-email-damien.lespiau@intel.com> Subject: [Intel-gfx] [PATCH i-g-t 02/12] lib: Add a helper to paint a PNG using cairo X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Damien Lespiau --- lib/drmtest.c | 28 ++++++++++++++++++++++++++++ lib/drmtest.h | 2 ++ 2 files changed, 30 insertions(+) diff --git a/lib/drmtest.c b/lib/drmtest.c index eca792c..f760028 100644 --- a/lib/drmtest.c +++ b/lib/drmtest.c @@ -1338,6 +1338,34 @@ void kmstest_paint_test_pattern(cairo_t *cr, int width, int height) assert(!cairo_status(cr)); } +void kmstest_paint_image(cairo_t *cr, const char *filename, + int dst_x, int dst_y, int dst_width, int dst_height) +{ + cairo_surface_t *image; + int img_width, img_height; + double scale_x, scale_y; + + image = cairo_image_surface_create_from_png(filename); + assert(cairo_surface_status(image) == CAIRO_STATUS_SUCCESS); + + img_width = cairo_image_surface_get_width(image); + img_height = cairo_image_surface_get_height(image); + + scale_x = (double)dst_width / img_width; + scale_y = (double)dst_height / img_height; + + cairo_save(cr); + + cairo_translate(cr, dst_x, dst_y); + cairo_scale(cr, scale_x, scale_y); + cairo_set_source_surface(cr, image, 0, 0); + cairo_paint(cr); + + cairo_surface_destroy(image); + + cairo_restore(cr); +} + #define DF(did, cid, _bpp, _depth) \ { DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, _bpp, _depth } static struct format_desc_struct { diff --git a/lib/drmtest.h b/lib/drmtest.h index 2a562f7..6591068 100644 --- a/lib/drmtest.h +++ b/lib/drmtest.h @@ -326,6 +326,8 @@ cairo_t *kmstest_get_cairo_ctx(int fd, struct kmstest_fb *fb); void kmstest_paint_color_gradient(cairo_t *cr, int x, int y, int w, int h, int r, int g, int b); void kmstest_paint_test_pattern(cairo_t *cr, int width, int height); +void kmstest_paint_image(cairo_t *cr, const char *filename, + int dst_x, int dst_y, int dst_width, int dst_height); void kmstest_dump_mode(drmModeModeInfo *mode); int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id); const char *kmstest_format_str(uint32_t drm_format);