Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /* cairo - a vector graphics library with display and print output
  2.  *
  3.  * Copyright © 2009 Intel Corporation
  4.  *
  5.  * This library is free software; you can redistribute it and/or
  6.  * modify it either under the terms of the GNU Lesser General Public
  7.  * License version 2.1 as published by the Free Software Foundation
  8.  * (the "LGPL") or, at your option, under the terms of the Mozilla
  9.  * Public License Version 1.1 (the "MPL"). If you do not alter this
  10.  * notice, a recipient may use your version of this file under either
  11.  * the MPL or the LGPL.
  12.  *
  13.  * You should have received a copy of the LGPL along with this library
  14.  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
  15.  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
  16.  * You should have received a copy of the MPL along with this library
  17.  * in the file COPYING-MPL-1.1
  18.  *
  19.  * The contents of this file are subject to the Mozilla Public License
  20.  * Version 1.1 (the "License"); you may not use this file except in
  21.  * compliance with the License. You may obtain a copy of the License at
  22.  * http://www.mozilla.org/MPL/
  23.  *
  24.  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
  25.  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
  26.  * the specific language governing rights and limitations.
  27.  *
  28.  * The Original Code is the cairo graphics library.
  29.  *
  30.  * The Initial Developer of the Original Code is Red Hat, Inc.
  31.  *
  32.  * Contributor(s):
  33.  *      Chris Wilson <chris@chris-wilson.co.uk>
  34.  */
  35.  
  36. #include "cairoint.h"
  37.  
  38. #include "cairo-error-private.h"
  39. #include "cairo-composite-rectangles-private.h"
  40.  
  41. /* A collection of routines to facilitate writing compositors. */
  42.  
  43. static inline cairo_bool_t
  44. _cairo_composite_rectangles_init (cairo_composite_rectangles_t *extents,
  45.                                   int width, int height,
  46.                                   cairo_operator_t op,
  47.                                   const cairo_pattern_t *source,
  48.                                   cairo_clip_t *clip)
  49. {
  50.     extents->unbounded.x = extents->unbounded.y = 0;
  51.     extents->unbounded.width  = width;
  52.     extents->unbounded.height = height;
  53.  
  54.     if (clip != NULL) {
  55.         const cairo_rectangle_int_t *clip_extents;
  56.  
  57.         clip_extents = _cairo_clip_get_extents (clip);
  58.         if (clip_extents == NULL)
  59.             return FALSE;
  60.  
  61.         if (! _cairo_rectangle_intersect (&extents->unbounded, clip_extents))
  62.             return FALSE;
  63.     }
  64.  
  65.     extents->bounded = extents->unbounded;
  66.     extents->is_bounded = _cairo_operator_bounded_by_either (op);
  67.  
  68.     _cairo_pattern_get_extents (source, &extents->source);
  69.     if (extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_SOURCE) {
  70.         if (! _cairo_rectangle_intersect (&extents->bounded, &extents->source))
  71.             return FALSE;
  72.     }
  73.  
  74.     return TRUE;
  75. }
  76.  
  77. cairo_int_status_t
  78. _cairo_composite_rectangles_init_for_paint (cairo_composite_rectangles_t *extents,
  79.                                             int surface_width, int surface_height,
  80.                                             cairo_operator_t             op,
  81.                                             const cairo_pattern_t       *source,
  82.                                             cairo_clip_t                *clip)
  83. {
  84.     if (! _cairo_composite_rectangles_init (extents,
  85.                                             surface_width, surface_height,
  86.                                             op, source, clip))
  87.     {
  88.         return CAIRO_INT_STATUS_NOTHING_TO_DO;
  89.     }
  90.  
  91.     extents->mask = extents->bounded;
  92.     return CAIRO_STATUS_SUCCESS;
  93. }
  94.  
  95. static cairo_int_status_t
  96. _cairo_composite_rectangles_intersect (cairo_composite_rectangles_t *extents)
  97. {
  98.     cairo_bool_t ret;
  99.  
  100.     ret = _cairo_rectangle_intersect (&extents->bounded, &extents->mask);
  101.     if (! ret && extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_MASK)
  102.         return CAIRO_INT_STATUS_NOTHING_TO_DO;
  103.  
  104.     return CAIRO_STATUS_SUCCESS;
  105. }
  106.  
  107. cairo_int_status_t
  108. _cairo_composite_rectangles_init_for_mask (cairo_composite_rectangles_t *extents,
  109.                                            int surface_width, int surface_height,
  110.                                            cairo_operator_t              op,
  111.                                            const cairo_pattern_t        *source,
  112.                                            const cairo_pattern_t        *mask,
  113.                                            cairo_clip_t                 *clip)
  114. {
  115.     if (! _cairo_composite_rectangles_init (extents,
  116.                                             surface_width, surface_height,
  117.                                             op, source, clip))
  118.     {
  119.         return CAIRO_INT_STATUS_NOTHING_TO_DO;
  120.     }
  121.  
  122.     _cairo_pattern_get_extents (mask, &extents->mask);
  123.  
  124.     return _cairo_composite_rectangles_intersect (extents);
  125. }
  126.  
  127. cairo_int_status_t
  128. _cairo_composite_rectangles_init_for_stroke (cairo_composite_rectangles_t *extents,
  129.                                              int surface_width, int surface_height,
  130.                                              cairo_operator_t            op,
  131.                                              const cairo_pattern_t      *source,
  132.                                              cairo_path_fixed_t         *path,
  133.                                              const cairo_stroke_style_t *style,
  134.                                              const cairo_matrix_t       *ctm,
  135.                                              cairo_clip_t               *clip)
  136. {
  137.     if (! _cairo_composite_rectangles_init (extents,
  138.                                             surface_width, surface_height,
  139.                                             op, source, clip))
  140.     {
  141.         return CAIRO_INT_STATUS_NOTHING_TO_DO;
  142.     }
  143.  
  144.     _cairo_path_fixed_approximate_stroke_extents (path, style, ctm, &extents->mask);
  145.  
  146.     return _cairo_composite_rectangles_intersect (extents);
  147. }
  148.  
  149. cairo_int_status_t
  150. _cairo_composite_rectangles_init_for_fill (cairo_composite_rectangles_t *extents,
  151.                                            int surface_width, int surface_height,
  152.                                            cairo_operator_t              op,
  153.                                            const cairo_pattern_t        *source,
  154.                                            cairo_path_fixed_t           *path,
  155.                                            cairo_clip_t                 *clip)
  156. {
  157.     if (! _cairo_composite_rectangles_init (extents,
  158.                                             surface_width, surface_height,
  159.                                             op, source, clip))
  160.     {
  161.         return CAIRO_INT_STATUS_NOTHING_TO_DO;
  162.     }
  163.  
  164.     _cairo_path_fixed_approximate_fill_extents (path, &extents->mask);
  165.  
  166.     return _cairo_composite_rectangles_intersect (extents);
  167. }
  168.  
  169. cairo_int_status_t
  170. _cairo_composite_rectangles_init_for_glyphs (cairo_composite_rectangles_t *extents,
  171.                                              int surface_width, int surface_height,
  172.                                              cairo_operator_t            op,
  173.                                              const cairo_pattern_t      *source,
  174.                                              cairo_scaled_font_t        *scaled_font,
  175.                                              cairo_glyph_t              *glyphs,
  176.                                              int                         num_glyphs,
  177.                                              cairo_clip_t               *clip,
  178.                                              cairo_bool_t               *overlap)
  179. {
  180.     cairo_status_t status;
  181.  
  182.     if (! _cairo_composite_rectangles_init (extents,
  183.                                             surface_width, surface_height,
  184.                                             op, source, clip))
  185.     {
  186.         return CAIRO_INT_STATUS_NOTHING_TO_DO;
  187.     }
  188.  
  189.     status = _cairo_scaled_font_glyph_device_extents (scaled_font,
  190.                                                       glyphs, num_glyphs,
  191.                                                       &extents->mask,
  192.                                                       overlap);
  193.     if (unlikely (status))
  194.         return status;
  195.  
  196.     return _cairo_composite_rectangles_intersect (extents);
  197. }
  198.