Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
  2. /* cairo - a vector graphics library with display and print output
  3.  *
  4.  * Copyright © 2002 University of Southern California
  5.  * Copyright © 2005 Red Hat, Inc.
  6.  * Copyright © 2011 Intel Corporation
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it either under the terms of the GNU Lesser General Public
  10.  * License version 2.1 as published by the Free Software Foundation
  11.  * (the "LGPL") or, at your option, under the terms of the Mozilla
  12.  * Public License Version 1.1 (the "MPL"). If you do not alter this
  13.  * notice, a recipient may use your version of this file under either
  14.  * the MPL or the LGPL.
  15.  *
  16.  * You should have received a copy of the LGPL along with this library
  17.  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
  18.  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
  19.  * You should have received a copy of the MPL along with this library
  20.  * in the file COPYING-MPL-1.1
  21.  *
  22.  * The contents of this file are subject to the Mozilla Public License
  23.  * Version 1.1 (the "License"); you may not use this file except in
  24.  * compliance with the License. You may obtain a copy of the License at
  25.  * http://www.mozilla.org/MPL/
  26.  *
  27.  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
  28.  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
  29.  * the specific language governing rights and limitations.
  30.  *
  31.  * The Original Code is the cairo graphics library.
  32.  *
  33.  * The Initial Developer of the Original Code is University of Southern
  34.  * California.
  35.  *
  36.  * Contributor(s):
  37.  *      Carl D. Worth <cworth@cworth.org>
  38.  *      Behdad Esfahbod <behdad@behdad.org>
  39.  *      Chris Wilson <chris@chris-wilson.co.uk>
  40.  *      Karl Tomlinson <karlt+@karlt.net>, Mozilla Corporation
  41.  */
  42.  
  43. #include "cairoint.h"
  44.  
  45. #if !CAIRO_HAS_XLIB_XCB_FUNCTIONS
  46.  
  47. #include "cairo-xlib-private.h"
  48.  
  49. #include "cairo-compositor-private.h"
  50. #include "cairo-image-surface-private.h"
  51. #include "cairo-surface-offset-private.h"
  52.  
  53. static const cairo_compositor_t *
  54. _get_compositor (cairo_surface_t *surface)
  55. {
  56.     return ((cairo_image_surface_t *)surface)->compositor;
  57. }
  58.  
  59. static cairo_bool_t
  60. unclipped (cairo_xlib_surface_t *xlib, cairo_clip_t *clip)
  61. {
  62.     cairo_rectangle_int_t r;
  63.  
  64.     r.x = r.y = 0;
  65.     r.width = xlib->width;
  66.     r.height = xlib->height;
  67.     return _cairo_clip_contains_rectangle (clip, &r);
  68. }
  69.  
  70. static cairo_int_status_t
  71. _cairo_xlib_shm_compositor_paint (const cairo_compositor_t      *_compositor,
  72.                                   cairo_composite_rectangles_t  *extents)
  73. {
  74.     cairo_xlib_surface_t *xlib = (cairo_xlib_surface_t *)extents->surface;
  75.     cairo_int_status_t status;
  76.     cairo_surface_t *shm;
  77.     cairo_bool_t overwrite;
  78.  
  79.     TRACE ((stderr, "%s\n", __FUNCTION__));
  80.  
  81.     overwrite =
  82.         extents->op <= CAIRO_OPERATOR_SOURCE && unclipped (xlib, extents->clip);
  83.  
  84.     shm = _cairo_xlib_surface_get_shm (xlib, overwrite);
  85.     if (shm == NULL)
  86.         return CAIRO_INT_STATUS_UNSUPPORTED;
  87.  
  88.     status = _cairo_compositor_paint (_get_compositor (shm), shm,
  89.                                       extents->op,
  90.                                       &extents->source_pattern.base,
  91.                                       extents->clip);
  92.     if (unlikely (status))
  93.         return status;
  94.  
  95.     xlib->base.is_clear =
  96.         extents->op == CAIRO_OPERATOR_CLEAR && unclipped (xlib, extents->clip);
  97.     xlib->base.serial++;
  98.     xlib->fallback++;
  99.     return CAIRO_INT_STATUS_NOTHING_TO_DO;
  100. }
  101.  
  102. static cairo_int_status_t
  103. _cairo_xlib_shm_compositor_mask (const cairo_compositor_t       *_compositor,
  104.                                  cairo_composite_rectangles_t   *extents)
  105. {
  106.     cairo_xlib_surface_t *xlib = (cairo_xlib_surface_t *)extents->surface;
  107.     cairo_int_status_t status;
  108.     cairo_surface_t *shm;
  109.  
  110.     TRACE ((stderr, "%s\n", __FUNCTION__));
  111.  
  112.     shm = _cairo_xlib_surface_get_shm (xlib, FALSE);
  113.     if (shm == NULL)
  114.         return CAIRO_INT_STATUS_UNSUPPORTED;
  115.  
  116.     status = _cairo_compositor_mask (_get_compositor (shm), shm,
  117.                                      extents->op,
  118.                                      &extents->source_pattern.base,
  119.                                      &extents->mask_pattern.base,
  120.                                      extents->clip);
  121.     if (unlikely (status))
  122.         return status;
  123.  
  124.     xlib->base.is_clear = FALSE;
  125.     xlib->base.serial++;
  126.     xlib->fallback++;
  127.     return CAIRO_INT_STATUS_NOTHING_TO_DO;
  128. }
  129.  
  130. static cairo_int_status_t
  131. _cairo_xlib_shm_compositor_stroke (const cairo_compositor_t     *_compositor,
  132.                                    cairo_composite_rectangles_t *extents,
  133.                                    const cairo_path_fixed_t     *path,
  134.                                    const cairo_stroke_style_t   *style,
  135.                                    const cairo_matrix_t         *ctm,
  136.                                    const cairo_matrix_t         *ctm_inverse,
  137.                                    double                        tolerance,
  138.                                    cairo_antialias_t             antialias)
  139. {
  140.     cairo_xlib_surface_t *xlib = (cairo_xlib_surface_t *)extents->surface;
  141.     cairo_int_status_t status;
  142.     cairo_surface_t *shm;
  143.  
  144.     TRACE ((stderr, "%s\n", __FUNCTION__));
  145.  
  146.     shm = _cairo_xlib_surface_get_shm (xlib, FALSE);
  147.     if (shm == NULL)
  148.         return CAIRO_INT_STATUS_UNSUPPORTED;
  149.  
  150.     status = _cairo_compositor_stroke (_get_compositor (shm), shm,
  151.                                        extents->op,
  152.                                        &extents->source_pattern.base,
  153.                                        path, style,
  154.                                        ctm, ctm_inverse,
  155.                                        tolerance,
  156.                                        antialias,
  157.                                        extents->clip);
  158.     if (unlikely (status))
  159.         return status;
  160.  
  161.     xlib->base.is_clear = FALSE;
  162.     xlib->base.serial++;
  163.     xlib->fallback++;
  164.     return CAIRO_INT_STATUS_NOTHING_TO_DO;
  165. }
  166.  
  167. static cairo_int_status_t
  168. _cairo_xlib_shm_compositor_fill (const cairo_compositor_t       *_compositor,
  169.                                  cairo_composite_rectangles_t *extents,
  170.                                  const cairo_path_fixed_t       *path,
  171.                                  cairo_fill_rule_t               fill_rule,
  172.                                  double                          tolerance,
  173.                                  cairo_antialias_t               antialias)
  174. {
  175.     cairo_xlib_surface_t *xlib = (cairo_xlib_surface_t *)extents->surface;
  176.     cairo_int_status_t status;
  177.     cairo_surface_t *shm;
  178.  
  179.     TRACE ((stderr, "%s\n", __FUNCTION__));
  180.  
  181.     shm = _cairo_xlib_surface_get_shm (xlib, FALSE);
  182.     if (shm == NULL)
  183.         return CAIRO_INT_STATUS_UNSUPPORTED;
  184.  
  185.     status = _cairo_compositor_fill (_get_compositor (shm), shm,
  186.                                      extents->op,
  187.                                      &extents->source_pattern.base,
  188.                                      path,
  189.                                      fill_rule, tolerance, antialias,
  190.                                      extents->clip);
  191.     if (unlikely (status))
  192.         return status;
  193.  
  194.     xlib->base.is_clear = FALSE;
  195.     xlib->base.serial++;
  196.     xlib->fallback++;
  197.     return CAIRO_INT_STATUS_NOTHING_TO_DO;
  198. }
  199.  
  200. static cairo_int_status_t
  201. _cairo_xlib_shm_compositor_glyphs (const cairo_compositor_t     *_compositor,
  202.                                    cairo_composite_rectangles_t *extents,
  203.                                    cairo_scaled_font_t          *scaled_font,
  204.                                    cairo_glyph_t                *glyphs,
  205.                                    int                           num_glyphs,
  206.                                    cairo_bool_t                  overlap)
  207. {
  208.     cairo_xlib_surface_t *xlib = (cairo_xlib_surface_t *)extents->surface;
  209.     cairo_int_status_t status;
  210.     cairo_surface_t *shm;
  211.  
  212.     TRACE ((stderr, "%s\n", __FUNCTION__));
  213.  
  214.     shm = _cairo_xlib_surface_get_shm (xlib, FALSE);
  215.     if (shm == NULL)
  216.         return CAIRO_INT_STATUS_UNSUPPORTED;
  217.  
  218.     status = _cairo_compositor_glyphs (_get_compositor (shm), shm,
  219.                                        extents->op,
  220.                                        &extents->source_pattern.base,
  221.                                        glyphs, num_glyphs, scaled_font,
  222.                                        extents->clip);
  223.     if (unlikely (status))
  224.         return status;
  225.  
  226.     xlib->base.is_clear = FALSE;
  227.     xlib->base.serial++;
  228.     xlib->fallback++;
  229.     return CAIRO_INT_STATUS_NOTHING_TO_DO;
  230. }
  231.  
  232. static const cairo_compositor_t _cairo_xlib_shm_compositor = {
  233.      &_cairo_fallback_compositor,
  234.  
  235.      _cairo_xlib_shm_compositor_paint,
  236.      _cairo_xlib_shm_compositor_mask,
  237.      _cairo_xlib_shm_compositor_stroke,
  238.      _cairo_xlib_shm_compositor_fill,
  239.      _cairo_xlib_shm_compositor_glyphs,
  240. };
  241.  
  242. const cairo_compositor_t *
  243. _cairo_xlib_fallback_compositor_get (void)
  244. {
  245.     return &_cairo_xlib_shm_compositor;
  246. }
  247.  
  248. #endif /* !CAIRO_HAS_XLIB_XCB_FUNCTIONS */
  249.