Coverage Report

Created: 2025-07-07 10:01

/work/workdir/UnpackedTarball/cairo/src/cairo-clip-region.c
Line
Count
Source (jump to first uncovered line)
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 © 2002 University of Southern California
5
 * Copyright © 2005 Red Hat, Inc.
6
 * Copyright © 2009 Chris Wilson
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
 *  Kristian Høgsberg <krh@redhat.com>
39
 *  Chris Wilson <chris@chris-wilson.co.uk>
40
 */
41
42
#include "cairoint.h"
43
#include "cairo-clip-private.h"
44
#include "cairo-error-private.h"
45
#include "cairo-freed-pool-private.h"
46
#include "cairo-gstate-private.h"
47
#include "cairo-path-fixed-private.h"
48
#include "cairo-pattern-private.h"
49
#include "cairo-composite-rectangles-private.h"
50
#include "cairo-region-private.h"
51
52
static void
53
_cairo_clip_extract_region (cairo_clip_t *clip)
54
17.7k
{
55
17.7k
    cairo_rectangle_int_t stack_rects[CAIRO_STACK_ARRAY_LENGTH (cairo_rectangle_int_t)];
56
17.7k
    cairo_rectangle_int_t *r = stack_rects;
57
17.7k
    cairo_bool_t is_region;
58
17.7k
    int i;
59
60
17.7k
    if (clip->num_boxes == 0)
61
0
  return;
62
63
17.7k
    if (clip->num_boxes > ARRAY_LENGTH (stack_rects)) {
64
0
  r = _cairo_malloc_ab (clip->num_boxes, sizeof (cairo_rectangle_int_t));
65
0
  if (r == NULL){
66
0
      _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
67
0
      return;
68
0
  }
69
0
    }
70
71
17.7k
    is_region = clip->path == NULL;
72
35.4k
    for (i = 0; i < clip->num_boxes; i++) {
73
17.7k
  cairo_box_t *b = &clip->boxes[i];
74
17.7k
  if (is_region)
75
17.7k
      is_region =
76
17.7k
    _cairo_fixed_is_integer (b->p1.x | b->p1.y |  b->p2.x | b->p2.y);
77
17.7k
  r[i].x = _cairo_fixed_integer_floor (b->p1.x);
78
17.7k
  r[i].y = _cairo_fixed_integer_floor (b->p1.y);
79
17.7k
  r[i].width  = _cairo_fixed_integer_ceil (b->p2.x) - r[i].x;
80
17.7k
  r[i].height = _cairo_fixed_integer_ceil (b->p2.y) - r[i].y;
81
17.7k
    }
82
17.7k
    clip->is_region = is_region;
83
84
17.7k
    clip->region = cairo_region_create_rectangles (r, i);
85
86
17.7k
    if (r != stack_rects)
87
0
  free (r);
88
17.7k
}
89
90
cairo_region_t *
91
_cairo_clip_get_region (const cairo_clip_t *clip)
92
17.7k
{
93
17.7k
    if (clip == NULL)
94
0
  return NULL;
95
96
17.7k
    if (clip->region == NULL)
97
17.7k
  _cairo_clip_extract_region ((cairo_clip_t *) clip);
98
99
17.7k
    return clip->region;
100
17.7k
}
101
102
cairo_bool_t
103
_cairo_clip_is_region (const cairo_clip_t *clip)
104
17.7k
{
105
17.7k
    if (clip == NULL)
106
0
  return TRUE;
107
108
17.7k
    if (clip->is_region)
109
17.7k
  return TRUE;
110
111
    /* XXX Geometric reduction? */
112
113
0
    if (clip->path)
114
0
  return FALSE;
115
116
0
    if (clip->num_boxes == 0)
117
0
  return TRUE;
118
119
0
    if (clip->region == NULL)
120
0
  _cairo_clip_extract_region ((cairo_clip_t *) clip);
121
122
0
    return clip->is_region;
123
0
}