1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ 2 /* 3 * Utilities for region manipulation 4 * 5 * Copyright (C) 2010 Red Hat, Inc. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License as 9 * published by the Free Software Foundation; either version 2 of the 10 * License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, but 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #ifndef __META_REGION_UTILS_H__ 22 #define __META_REGION_UTILS_H__ 23 24 #include <cairo.h> 25 #include <glib.h> 26 27 #include "backends/meta-backend-types.h" 28 #include "clutter/clutter.h" 29 #include "core/boxes-private.h" 30 31 /** 32 * MetaRegionIterator: 33 * @region: region being iterated 34 * @rectangle: current rectangle 35 * @line_start: whether the current rectangle starts a horizontal band 36 * @line_end: whether the current rectangle ends a horizontal band 37 * 38 * cairo_region_t is a yx banded region; sometimes its useful to iterate through 39 * such a region treating the start and end of each horizontal band in a distinct 40 * fashion. 41 * 42 * Usage: 43 * 44 * MetaRegionIterator iter; 45 * for (meta_region_iterator_init (&iter, region); 46 * !meta_region_iterator_at_end (&iter); 47 * meta_region_iterator_next (&iter)) 48 * { 49 * [ Use iter.rectangle, iter.line_start, iter.line_end ] 50 * } 51 */ 52 typedef struct _MetaRegionIterator MetaRegionIterator; 53 54 struct _MetaRegionIterator { 55 cairo_region_t *region; 56 cairo_rectangle_int_t rectangle; 57 gboolean line_start; 58 gboolean line_end; 59 int i; 60 61 /*< private >*/ 62 int n_rectangles; 63 cairo_rectangle_int_t next_rectangle; 64 }; 65 66 typedef struct _MetaRegionBuilder MetaRegionBuilder; 67 68 #define META_REGION_BUILDER_MAX_LEVELS 16 69 struct _MetaRegionBuilder { 70 /* To merge regions in binary tree order, we need to keep track of 71 * the regions that we've already merged together at different 72 * levels of the tree. We fill in an array in the pattern: 73 * 74 * |a | 75 * |b |a | 76 * |c | |ab | 77 * |d |c |ab | 78 * |e | | |abcd| 79 */ 80 cairo_region_t *levels[META_REGION_BUILDER_MAX_LEVELS]; 81 int n_levels; 82 }; 83 84 void meta_region_builder_init (MetaRegionBuilder *builder); 85 void meta_region_builder_add_rectangle (MetaRegionBuilder *builder, 86 int x, 87 int y, 88 int width, 89 int height); 90 cairo_region_t * meta_region_builder_finish (MetaRegionBuilder *builder); 91 92 void meta_region_iterator_init (MetaRegionIterator *iter, 93 cairo_region_t *region); 94 gboolean meta_region_iterator_at_end (MetaRegionIterator *iter); 95 void meta_region_iterator_next (MetaRegionIterator *iter); 96 97 cairo_region_t * meta_region_scale (cairo_region_t *region, 98 int scale); 99 100 cairo_region_t * meta_region_scale_double (cairo_region_t *region, 101 double scale, 102 MetaRoundingStrategy rounding_strategy); 103 104 cairo_region_t * meta_make_border_region (cairo_region_t *region, 105 int x_amount, 106 int y_amount, 107 gboolean flip); 108 109 cairo_region_t * meta_region_transform (const cairo_region_t *region, 110 MetaMonitorTransform transform, 111 int width, 112 int height); 113 114 cairo_region_t * meta_region_crop_and_scale (cairo_region_t *region, 115 graphene_rect_t *src_rect, 116 int dst_width, 117 int dst_height); 118 119 #endif /* __META_REGION_UTILS_H__ */ 120