Subversion Repositories Kolibri OS

Rev

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

  1. /* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */
  2. /* cairo - a vector graphics library with display and print output
  3.  *
  4.  * Copyright (c) 2008  M Joonas Pihlaja
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person
  7.  * obtaining a copy of this software and associated documentation
  8.  * files (the "Software"), to deal in the Software without
  9.  * restriction, including without limitation the rights to use,
  10.  * copy, modify, merge, publish, distribute, sublicense, and/or sell
  11.  * copies of the Software, and to permit persons to whom the
  12.  * Software is furnished to do so, subject to the following
  13.  * conditions:
  14.  *
  15.  * The above copyright notice and this permission notice shall be
  16.  * included in all copies or substantial portions of the Software.
  17.  *
  18.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19.  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  20.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21.  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  22.  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  23.  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  24.  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  25.  * OTHER DEALINGS IN THE SOFTWARE.
  26.  */
  27. #ifndef CAIRO_SPANS_PRIVATE_H
  28. #define CAIRO_SPANS_PRIVATE_H
  29. #include "cairo-types-private.h"
  30. #include "cairo-compiler-private.h"
  31.  
  32. /* Number of bits of precision used for alpha. */
  33. #define CAIRO_SPANS_UNIT_COVERAGE_BITS 8
  34. #define CAIRO_SPANS_UNIT_COVERAGE ((1 << CAIRO_SPANS_UNIT_COVERAGE_BITS)-1)
  35.  
  36. /* A structure representing an open-ended horizontal span of constant
  37.  * pixel coverage. */
  38. typedef struct _cairo_half_open_span {
  39.     /* The inclusive x-coordinate of the start of the span. */
  40.     int x;
  41.  
  42.     /* The pixel coverage for the pixels to the right. */
  43.     int coverage;
  44. } cairo_half_open_span_t;
  45.  
  46. /* Span renderer interface. Instances of renderers are provided by
  47.  * surfaces if they want to composite spans instead of trapezoids. */
  48. typedef struct _cairo_span_renderer cairo_span_renderer_t;
  49. struct _cairo_span_renderer {
  50.     /* Private status variable. */
  51.     cairo_status_t status;
  52.  
  53.     /* Called to destroy the renderer. */
  54.     cairo_destroy_func_t        destroy;
  55.  
  56.     /* Render the spans on row y of the destination by whatever compositing
  57.      * method is required. */
  58.     cairo_warn cairo_status_t
  59.     (*render_rows) (void *abstract_renderer,
  60.                     int y, int height,
  61.                     const cairo_half_open_span_t        *coverages,
  62.                     unsigned num_coverages);
  63.  
  64.     /* Called after all rows have been rendered to perform whatever
  65.      * final rendering step is required.  This function is called just
  66.      * once before the renderer is destroyed. */
  67.     cairo_status_t (*finish) (void *abstract_renderer);
  68. };
  69.  
  70. /* Scan converter interface. */
  71. typedef struct _cairo_scan_converter cairo_scan_converter_t;
  72. struct _cairo_scan_converter {
  73.     /* Destroy this scan converter. */
  74.     cairo_destroy_func_t        destroy;
  75.  
  76.     /* Add a single edge to the converter. */
  77.     cairo_status_t (*add_edge) (void                *abstract_converter,
  78.                                 const cairo_point_t *p1,
  79.                                 const cairo_point_t *p2,
  80.                                 int top, int bottom,
  81.                                 int dir);
  82.  
  83.     /* Add a polygon (set of edges) to the converter. */
  84.     cairo_status_t (*add_polygon) (void             *abstract_converter,
  85.                                    const cairo_polygon_t  *polygon);
  86.  
  87.     /* Generates coverage spans for rows for the added edges and calls
  88.      * the renderer function for each row. After generating spans the
  89.      * only valid thing to do with the converter is to destroy it. */
  90.     cairo_status_t (*generate) (void                    *abstract_converter,
  91.                                 cairo_span_renderer_t   *renderer);
  92.  
  93.     /* Private status. Read with _cairo_scan_converter_status(). */
  94.     cairo_status_t status;
  95. };
  96.  
  97. /* Scan converter constructors. */
  98.  
  99. cairo_private cairo_scan_converter_t *
  100. _cairo_tor_scan_converter_create (int                   xmin,
  101.                                   int                   ymin,
  102.                                   int                   xmax,
  103.                                   int                   ymax,
  104.                                   cairo_fill_rule_t     fill_rule);
  105.  
  106. typedef struct _cairo_rectangular_scan_converter {
  107.     cairo_scan_converter_t base;
  108.  
  109.     int xmin, xmax;
  110.     int ymin, ymax;
  111.  
  112.     struct _cairo_rectangular_scan_converter_chunk {
  113.         struct _cairo_rectangular_scan_converter_chunk *next;
  114.         void *base;
  115.         int count;
  116.         int size;
  117.     } chunks, *tail;
  118.     char buf[CAIRO_STACK_BUFFER_SIZE];
  119.     int num_rectangles;
  120. } cairo_rectangular_scan_converter_t;
  121.  
  122. cairo_private void
  123. _cairo_rectangular_scan_converter_init (cairo_rectangular_scan_converter_t *self,
  124.                                         const cairo_rectangle_int_t *extents);
  125.  
  126. cairo_private cairo_status_t
  127. _cairo_rectangular_scan_converter_add_box (cairo_rectangular_scan_converter_t *self,
  128.                                            const cairo_box_t *box,
  129.                                            int dir);
  130.  
  131. typedef struct _cairo_botor_scan_converter {
  132.     cairo_scan_converter_t base;
  133.  
  134.     cairo_box_t extents;
  135.     cairo_fill_rule_t fill_rule;
  136.  
  137.     int xmin, xmax;
  138.  
  139.     struct _cairo_botor_scan_converter_chunk {
  140.         struct _cairo_botor_scan_converter_chunk *next;
  141.         void *base;
  142.         int count;
  143.         int size;
  144.     } chunks, *tail;
  145.     char buf[CAIRO_STACK_BUFFER_SIZE];
  146.     int num_edges;
  147. } cairo_botor_scan_converter_t;
  148.  
  149. cairo_private void
  150. _cairo_botor_scan_converter_init (cairo_botor_scan_converter_t *self,
  151.                                   const cairo_box_t *extents,
  152.                                   cairo_fill_rule_t fill_rule);
  153.  
  154. /* cairo-spans.c: */
  155.  
  156. cairo_private cairo_scan_converter_t *
  157. _cairo_scan_converter_create_in_error (cairo_status_t error);
  158.  
  159. cairo_private cairo_status_t
  160. _cairo_scan_converter_status (void *abstract_converter);
  161.  
  162. cairo_private cairo_status_t
  163. _cairo_scan_converter_set_error (void *abstract_converter,
  164.                                  cairo_status_t error);
  165.  
  166. cairo_private cairo_span_renderer_t *
  167. _cairo_span_renderer_create_in_error (cairo_status_t error);
  168.  
  169. cairo_private cairo_status_t
  170. _cairo_span_renderer_status (void *abstract_renderer);
  171.  
  172. /* Set the renderer into an error state.  This sets all the method
  173.  * pointers except ->destroy() of the renderer to no-op
  174.  * implementations that just return the error status. */
  175. cairo_private cairo_status_t
  176. _cairo_span_renderer_set_error (void *abstract_renderer,
  177.                                 cairo_status_t error);
  178.  
  179. cairo_private cairo_status_t
  180. _cairo_surface_composite_polygon (cairo_surface_t       *surface,
  181.                                   cairo_operator_t       op,
  182.                                   const cairo_pattern_t *pattern,
  183.                                   cairo_fill_rule_t     fill_rule,
  184.                                   cairo_antialias_t     antialias,
  185.                                   const cairo_composite_rectangles_t *rects,
  186.                                   cairo_polygon_t       *polygon,
  187.                                   cairo_region_t        *clip_region);
  188.  
  189. #endif /* CAIRO_SPANS_PRIVATE_H */
  190.