Upload Tizen2.0 source
[framework/graphics/cairo.git] / src / cairo-box-inline.h
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 © 2010 Andrea Canciani
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it either under the terms of the GNU Lesser General Public
8  * License version 2.1 as published by the Free Software Foundation
9  * (the "LGPL") or, at your option, under the terms of the Mozilla
10  * Public License Version 1.1 (the "MPL"). If you do not alter this
11  * notice, a recipient may use your version of this file under either
12  * the MPL or the LGPL.
13  *
14  * You should have received a copy of the LGPL along with this library
15  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
17  * You should have received a copy of the MPL along with this library
18  * in the file COPYING-MPL-1.1
19  *
20  * The contents of this file are subject to the Mozilla Public License
21  * Version 1.1 (the "License"); you may not use this file except in
22  * compliance with the License. You may obtain a copy of the License at
23  * http://www.mozilla.org/MPL/
24  *
25  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
26  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
27  * the specific language governing rights and limitations.
28  *
29  * The Original Code is the cairo graphics library.
30  *
31  * Contributor(s):
32  *      Andrea Canciani <ranma42@gmail.com>
33  */
34
35 #ifndef CAIRO_BOX_H
36 #define CAIRO_BOX_H
37
38 #include "cairo-types-private.h"
39 #include "cairo-compiler-private.h"
40 #include "cairo-fixed-private.h"
41
42 static inline void
43 _cairo_box_set (cairo_box_t *box,
44                 const cairo_point_t *p1,
45                 const cairo_point_t *p2)
46 {
47     box->p1 = *p1;
48     box->p2 = *p2;
49 }
50
51 static inline void
52 _cairo_box_from_integers (cairo_box_t *box, int x, int y, int w, int h)
53 {
54     box->p1.x = _cairo_fixed_from_int (x);
55     box->p1.y = _cairo_fixed_from_int (y);
56     box->p2.x = _cairo_fixed_from_int (x + w);
57     box->p2.y = _cairo_fixed_from_int (y + h);
58 }
59
60 /* assumes box->p1 is top-left, p2 bottom-right */
61 static inline void
62 _cairo_box_add_point (cairo_box_t *box,
63                       const cairo_point_t *point)
64 {
65     if (point->x < box->p1.x)
66         box->p1.x = point->x;
67     else if (point->x > box->p2.x)
68         box->p2.x = point->x;
69
70     if (point->y < box->p1.y)
71         box->p1.y = point->y;
72     else if (point->y > box->p2.y)
73         box->p2.y = point->y;
74 }
75
76 static inline void
77 _cairo_box_add_box (cairo_box_t *box,
78                     const cairo_box_t *add)
79 {
80     if (add->p1.x < box->p1.x)
81         box->p1.x = add->p1.x;
82     if (add->p2.x > box->p2.x)
83         box->p2.x = add->p2.x;
84
85     if (add->p1.y < box->p1.y)
86         box->p1.y = add->p1.y;
87     if (add->p2.y > box->p2.y)
88         box->p2.y = add->p2.y;
89 }
90
91 /* assumes box->p1 is top-left, p2 bottom-right */
92 static inline cairo_bool_t
93 _cairo_box_contains_point (const cairo_box_t *box,
94                            const cairo_point_t *point)
95 {
96     return box->p1.x <= point->x  && point->x <= box->p2.x &&
97         box->p1.y <= point->y  && point->y <= box->p2.y;
98 }
99
100 static inline cairo_bool_t
101 _cairo_box_is_pixel_aligned (const cairo_box_t *box)
102 {
103 #if CAIRO_FIXED_FRAC_BITS <= 8 && 0
104     return ((box->p1.x & CAIRO_FIXED_FRAC_MASK) << 24 |
105             (box->p1.y & CAIRO_FIXED_FRAC_MASK) << 16 |
106             (box->p2.x & CAIRO_FIXED_FRAC_MASK) << 8 |
107             (box->p2.y & CAIRO_FIXED_FRAC_MASK) << 0) == 0;
108 #else /* GCC on i7 prefers this variant (bizarrely according to the profiler) */
109     cairo_fixed_t f;
110
111     f = 0;
112     f |= box->p1.x & CAIRO_FIXED_FRAC_MASK;
113     f |= box->p1.y & CAIRO_FIXED_FRAC_MASK;
114     f |= box->p2.x & CAIRO_FIXED_FRAC_MASK;
115     f |= box->p2.y & CAIRO_FIXED_FRAC_MASK;
116
117     return f == 0;
118 #endif
119 }
120
121 #endif /* CAIRO_BOX_H */