From ebadc2ed0810d9941a2f44586016073fea90115b Mon Sep 17 00:00:00 2001 From: M Joonas Pihlaja Date: Sat, 27 Feb 2010 03:24:55 +0200 Subject: [PATCH] test: Add tests covering more clip fast paths in groups. The clip-group-shapes-* tests check that it doesn't matter whether the clip path is set before or after pushing a group using specific types of clip paths (aligned/unaligned rectangles and general paths.) --- test/Makefile.sources | 1 + ...ip-group-shapes-aligned-rectangles.ref.png | Bin 0 -> 378 bytes test/clip-group-shapes-circles.ref.png | Bin 0 -> 1510 bytes ...-group-shapes-unaligned-rectangles.ref.png | Bin 0 -> 415 bytes test/clip-group-shapes.c | 189 ++++++++++++++++++ 5 files changed, 190 insertions(+) create mode 100644 test/clip-group-shapes-aligned-rectangles.ref.png create mode 100644 test/clip-group-shapes-circles.ref.png create mode 100644 test/clip-group-shapes-unaligned-rectangles.ref.png create mode 100644 test/clip-group-shapes.c diff --git a/test/Makefile.sources b/test/Makefile.sources index 0f524e1da..ef5253b6c 100644 --- a/test/Makefile.sources +++ b/test/Makefile.sources @@ -25,6 +25,7 @@ test_sources = \ clip-fill-rule.c \ clip-fill-rule-pixel-aligned.c \ clip-fill-unbounded.c \ + clip-group-shapes.c \ clip-image.c \ clip-nesting.c \ clip-operator.c \ diff --git a/test/clip-group-shapes-aligned-rectangles.ref.png b/test/clip-group-shapes-aligned-rectangles.ref.png new file mode 100644 index 0000000000000000000000000000000000000000..cba75078a1e5dd79482e18783a75c89b8ada0d94 GIT binary patch literal 378 zcmeAS@N?(olHy`uVBq!ia0vp^CxAGGg9%9bJb4iVq}Y|gW!U_%O^81FzS1{ zIEGZrd3)<1=Me)QhJzMM{!c4)jWKIWd6qAbbn$d{8sCoFJF6M)c}A$TxH=I@Jo@$e zYm|BK#|5$Vf9$tui+8td@ZcC!#F1Gu?;3w_(i7uMoG3sv(J60b%yl^L(#!?Gz+~`r L^>bP0l+XkKGWUuR literal 0 HcmV?d00001 diff --git a/test/clip-group-shapes-circles.ref.png b/test/clip-group-shapes-circles.ref.png new file mode 100644 index 0000000000000000000000000000000000000000..064cc589d06719b11caafb1510599810a39dc45e GIT binary patch literal 1510 zcmcIk`#aMM7#}fWD95BYODeaybR&deb892VWj16pLJub?9+b<8a+$*sZKGUHW>JXc zl-wC#j@*a2#3ailX_jR?QD@E{aDF?_`@HY_yzl#YKJWAS<&)v&>Zl-hL=FT3DL6Z! z+{OKGaR$jsiYtb<>?dwu650_3`mq;(wv^|AK+=z#QMR73g=@36PI*acGV6Q};sUfz zvl^0xq1oX_7>acYk{OMj^#;qshRr+%y57ik(lEu9nx>f?`tvgvh()!gm8U*O|CBot z@2kz?Dkf$8Ae6g`tcNyk3%6^-_#4fH*0-e3v+C=XO5IzAx-Gxqi>h#`ccFbbwWPz! zSOX-Be8maJgzSe?j|Bi{PW*qzE(BYCD<~Y2kf5f~)eZuKPg!SUzzrHto`5tD*yu`u zF2s~RSB#FXsOg#Stf+c0>jOq(C4e?t3zK_6${A9*&O%Y3v<`bR9S32m`S{c(T6K^I zi9;6ym|xGkciz3HfAUhR%XFL}P#BR8JA`blUSp&hrlD`G~J2%l2>8C5ez z9GWrrsR!@$?l)O*iy(64C!;%oc=H`>><{ZB>VmD)qp#y(2??0G_$7a=t16tc91@w1I%TTekU}VN@fgjasMp};+UN{>Gd*2B zYHpQ=E=PFIwWNE!RtP&nX6V3W$m5(;@0v0i2qY!RRyVM}gk=MbF-k>6tP49YBk4kL zraOfa%4A>lYc*(S*DyMS_QjS0jZypa@^a<-nOF0KVEIuh#g7TIY~NTSjmkf($l($t zNVFSpQntzidA?fsSxXAFMh-rVNzQk;Kor8V1y9 z@fa;KO58b+-}IVzz{Q1)?x&l=H!GvQ#Eo&@kLqw917=aOH3YP=An9QpDG9iE!Ve>7 zb56gd!%{pOW4#ZFy0q-I*y{asb2zu2MQC%w_wJsYCWTKW-#=Jyg!3wf^5LAi5F>5r zcm0R!eWbtQ1*&~hnRdRujPv=9aoA?y<4VBK-et2*k-T)F@`mmZnTcCi$o3~he|>gy zu8Um)4PfJn@mZ*pPvG{TXoart1DP^0+IhEBxnX6c3h6=Lr>$%0vF#VxK)EzCA7?0z4(Wi%#6-|qO>4`Btw?<^0E z=))uDC4GEHCYOgKib^fvn@6P!iXAMox&F=Z8Q&9m8-3rFRyp(S5-55)Fg#QBt|pN& zTu52AdaR=(*fa#ogzzh@&m{LcV=zRLB*^aA1KM#F)~jD-)5HhvSQ#IwM+oh^I6u&x k1!lKxT*K=9m*r(3;u{yw*LH%c#l{VCws%E6w<9M1174=uDgXcg literal 0 HcmV?d00001 diff --git a/test/clip-group-shapes-unaligned-rectangles.ref.png b/test/clip-group-shapes-unaligned-rectangles.ref.png new file mode 100644 index 0000000000000000000000000000000000000000..2ad4118247fcdfda4c437ff9489396eaa7cd0365 GIT binary patch literal 415 zcmeAS@N?(olHy`uVBq!ia0vp^CxAGGg9%9bJb4iVq}Y|gW!U_%O^81Fot-# zIEGZrd3*IB=V1c@21oTJ22+<^x-;{WC;PWs0_Xpz${ufu%U;WS?%Td9{cnHgIO-W6Gdsrn-YzG+{qU^M7kIDF{=99&ye-=CikyiP1;hpq@k7SS y_L$jo%jTH0p4<0oFRcT5{WDvmJV_4y!89RD>NvxuyYavfXYh3Ob6Mw<&;$Sg?TYpQ literal 0 HcmV?d00001 diff --git a/test/clip-group-shapes.c b/test/clip-group-shapes.c new file mode 100644 index 000000000..72eff9fff --- /dev/null +++ b/test/clip-group-shapes.c @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2010 M Joonas Pihlaja + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Author: M Joonas Pihlaja + */ +#include "cairo-test.h" + +/* Tests specific clipping fast paths and their interaction with + * groups: It shouldn't matter if the clip is set before or after + * pushing a group. + * + * There's some overlap with the following tests, but they test for + * different things: + * + * group-clip.c (tests preserving paths), clipped-group.c (tests + * clipping the same thing different ways), clip-push-group (tests + * for a specific bug). + */ + +#define MIN(a,b) ((a) < (b) ? (a) : (b)) + +#define GENERATE_REF 0 + +/* For determining whether we establish the clip path before or after + * pushing a group. */ +enum { + CLIP_OUTSIDE_GROUP, + CLIP_INSIDE_GROUP +}; + +typedef void (*clipper_t)(cairo_t *cr, int w, int h); + +static cairo_test_status_t +clip_and_paint (cairo_t *cr, + int w, int h, + clipper_t do_clip, + int clip_where) +{ + cairo_save (cr); { + if (GENERATE_REF) { + do_clip (cr, w, h); + cairo_paint (cr); + } + else { + if (clip_where == CLIP_OUTSIDE_GROUP) + do_clip (cr, w, h); + cairo_push_group (cr); { + if (clip_where == CLIP_INSIDE_GROUP) + do_clip (cr, w, h); + cairo_paint (cr); + } + cairo_pop_group_to_source (cr); + cairo_paint (cr); + } + } + cairo_restore (cr); + return CAIRO_TEST_SUCCESS; +} + +static cairo_test_status_t +run_clip_test (cairo_t *cr, int w, int h, clipper_t do_clip) +{ + cairo_set_source_rgb (cr, 1,1,1); + cairo_paint (cr); + cairo_set_source_rgb (cr, 1,0,0); + + /* Left. */ + clip_and_paint (cr, w/2, h, do_clip, CLIP_OUTSIDE_GROUP); + + /* Right */ + cairo_translate(cr, w/2, 0); + clip_and_paint (cr, w/2, h, do_clip, CLIP_INSIDE_GROUP); + + return CAIRO_TEST_SUCCESS; +} + +static void +clip_aligned_rectangles (cairo_t *cr, int w, int h) +{ + int x1 = 0.2 * w; + int y1 = 0.2 * h; + int x2 = 0.8 * w; + int y2 = 0.8 * h; + + cairo_rectangle (cr, x1, y1, w, h); + cairo_clip (cr); + + cairo_rectangle (cr, x2, y2, -w, -h); + cairo_clip (cr); +} + +static void +clip_unaligned_rectangles (cairo_t *cr, int w, int h) +{ + /* This clip stresses the antialiased edges produced by an + * unaligned rectangular clip. The edges should be produced by + * compositing red on white with alpha = 0.5 on the sides, and with + * alpha = 0.25 in the corners. */ + int x1 = 0.2 * w; + int y1 = 0.2 * h; + int x2 = 0.8 * w; + int y2 = 0.8 * h; + + cairo_rectangle (cr, x1+0.5, y1+0.5, w, h); + cairo_clip (cr); + + cairo_rectangle (cr, x2+0.5, y2+0.5, -w, -h); + w = x2 - x1; + h = y2 - y1; + cairo_rectangle (cr, x2, y1+1, -w+1, h-1); + cairo_clip (cr); +} + +static void +clip_circles (cairo_t *cr, int w, int h) +{ + int x1 = 0.5 * w; + int y1 = 0.5 * h; + int x2 = 0.75 * w; + int y2 = 0.75 * h; + int r = 0.4*MIN(w,h); + + cairo_arc (cr, x1, y1, r, 0, 6.28); + cairo_close_path (cr); + cairo_clip (cr); + + cairo_arc (cr, x2, y2, r, 0, 6.28); + cairo_close_path (cr); + cairo_clip (cr); +} + +static cairo_test_status_t +draw_aligned_rectangles (cairo_t *cr, int width, int height) +{ + return run_clip_test (cr, width, height, clip_aligned_rectangles); +} + +static cairo_test_status_t +draw_unaligned_rectangles (cairo_t *cr, int width, int height) +{ + return run_clip_test (cr, width, height, clip_unaligned_rectangles); +} + +static cairo_test_status_t +draw_circles (cairo_t *cr, int width, int height) +{ + return run_clip_test (cr, width, height, clip_circles); +} + +CAIRO_TEST (clip_group_shapes_aligned_rectangles, + "Test clip and group interaction with aligned rectangle clips", + "clip", /* keywords */ + NULL, /* requirements */ + 200, 100, + NULL, draw_aligned_rectangles) + +CAIRO_TEST (clip_group_shapes_unaligned_rectangles, + "Test clip and group interaction with unaligned rectangle clips", + "clip", /* keywords */ + "target=raster", /* requirements */ + 200, 100, + NULL, draw_unaligned_rectangles) + +CAIRO_TEST (clip_group_shapes_circles, + "Test clip and group interaction with circular clips", + "clip", /* keywords */ + NULL, /* requirements */ + 200, 100, + NULL, draw_circles)