fbclip.h revision 428d7b3d
1/* 2 * Copyright © 2012 Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 * SOFTWARE. 22 * 23 * Authors: 24 * Chris Wilson <chris@chris-wilson.co.uk> 25 * 26 */ 27 28#ifndef FBCLIP_H 29#define FBCLIP_H 30 31extern const BoxRec * 32fbClipBoxes(const RegionRec *region, const BoxRec *box, const BoxRec **end); 33 34inline static bool 35box_intersect(BoxPtr a, const BoxRec *b) 36{ 37 if (a->x1 < b->x1) 38 a->x1 = b->x1; 39 if (a->x2 > b->x2) 40 a->x2 = b->x2; 41 if (a->x1 >= a->x2) 42 return false; 43 44 if (a->y1 < b->y1) 45 a->y1 = b->y1; 46 if (a->y2 > b->y2) 47 a->y2 = b->y2; 48 if (a->y1 >= a->y2) 49 return false; 50 51 return true; 52} 53 54#define run_box(b, c) \ 55 DBG(("%s: box=(%d, %d), (%d, %d), clip=(%d, %d), (%d, %d)\n", \ 56 __FUNCTION__, (b)->x1, (b)->y1, (b)->x2, (b)->y2, (c)->x1, (c)->y1, (c)->x2, (c)->y2)); \ 57 if ((b)->y2 <= (c)->y1) break; \ 58 if ((b)->x1 >= (c)->x2) continue; \ 59 if ((b)->x2 <= (c)->x1) { if ((b)->y2 <= (c)->y2) break; continue; } 60 61static inline void 62fbDrawableRun(DrawablePtr d, GCPtr gc, const BoxRec *box, 63 void (*func)(DrawablePtr, GCPtr, const BoxRec *b, void *data), 64 void *data) 65{ 66 const BoxRec *c, *end; 67 for (c = fbClipBoxes(gc->pCompositeClip, box, &end); c != end; c++) { 68 BoxRec b; 69 70 run_box(box, c); 71 72 b = *box; 73 if (box_intersect(&b, c)) 74 func(d, gc, &b, data); 75 } 76} 77 78static inline void 79fbDrawableRunUnclipped(DrawablePtr d, GCPtr gc, const BoxRec *box, 80 void (*func)(DrawablePtr, GCPtr, const BoxRec *b, void *data), 81 void *data) 82{ 83 const BoxRec *c, *end; 84 for (c = fbClipBoxes(gc->pCompositeClip, box, &end); c != end; c++) { 85 run_box(box, c); 86 func(d, gc, c, data); 87 } 88} 89 90#endif /* FBCLIP_H */ 91