1 /* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
2 /* cairo - a vector graphics library with display and print output
4 * Copyright 2002 University of Southern California
5 * Copyright 2005 Red Hat, Inc.
6 * Copyright 2007 Emmanuel Pacaud
7 * Copyright 2008 Benjamin Otte
8 * Copyright 2008 Chris Wilson
10 * This library is free software; you can redistribute it and/or
11 * modify it either under the terms of the GNU Lesser General Public
12 * License version 2.1 as published by the Free Software Foundation
13 * (the "LGPL") or, at your option, under the terms of the Mozilla
14 * Public License Version 1.1 (the "MPL"). If you do not alter this
15 * notice, a recipient may use your version of this file under either
16 * the MPL or the LGPL.
18 * You should have received a copy of the LGPL along with this library
19 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
21 * You should have received a copy of the MPL along with this library
22 * in the file COPYING-MPL-1.1
24 * The contents of this file are subject to the Mozilla Public License
25 * Version 1.1 (the "License"); you may not use this file except in
26 * compliance with the License. You may obtain a copy of the License at
27 * http://www.mozilla.org/MPL/
29 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
30 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
31 * the specific language governing rights and limitations.
33 * The Original Code is the cairo graphics library.
35 * The Initial Developer of the Original Code is University of Southern
39 * Owen Taylor <otaylor@redhat.com>
40 * Kristian Høgsberg <krh@redhat.com>
41 * Emmanuel Pacaud <emmanuel.pacaud@lapp.in2p3.fr>
42 * Chris Wilson <chris@chris-wilson.co.uk>
43 * Andrea Canciani <ranma42@gmail.com>
46 #include "cairo-test.h"
49 #define START_OPERATOR CAIRO_OPERATOR_CLEAR
50 #define STOP_OPERATOR CAIRO_OPERATOR_HSL_LUMINOSITY
54 #define FULL_WIDTH ((STEPS + 1) * COUNT - 1)
55 #define FULL_HEIGHT ((COUNT + STOP_OPERATOR - START_OPERATOR) / COUNT) * (STEPS + 1)
58 create_patterns (cairo_t *bg, cairo_t *fg)
62 for (x = 0; x < STEPS; x++) {
63 double i = (double) x / (STEPS - 1);
64 cairo_set_source_rgba (bg, 0, 0, 0, i);
65 cairo_rectangle (bg, x, 0, 1, STEPS);
68 cairo_set_source_rgba (fg, 0, 0, 0, i);
69 cairo_rectangle (fg, 0, x, STEPS, 1);
74 /* expects a STEP*STEP pixel rectangle */
76 do_composite (cairo_t *cr, cairo_operator_t op, cairo_surface_t *bg, cairo_surface_t *fg)
78 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
79 cairo_set_source_surface (cr, bg, 0, 0);
82 cairo_set_operator (cr, op);
83 cairo_set_source_surface (cr, fg, 0, 0);
88 subdraw (cairo_t *cr, int width, int height)
93 cairo_surface_t *bg, *fg;
95 bg = cairo_surface_create_similar (cairo_get_target (cr),
96 CAIRO_CONTENT_ALPHA, SIZE * STEPS, SIZE * STEPS);
97 fg = cairo_surface_create_similar (cairo_get_target (cr),
98 CAIRO_CONTENT_ALPHA, SIZE * STEPS, SIZE * STEPS);
99 bgcr = cairo_create (bg);
100 fgcr = cairo_create (fg);
101 cairo_scale (bgcr, SIZE, SIZE);
102 cairo_scale (fgcr, SIZE, SIZE);
103 create_patterns (bgcr, fgcr);
104 cairo_destroy (bgcr);
105 cairo_destroy (fgcr);
107 for (op = START_OPERATOR; op <= STOP_OPERATOR; op++, i++) {
110 SIZE * (STEPS + 1) * (i % COUNT),
111 SIZE * (STEPS + 1) * (i / COUNT));
112 cairo_rectangle (cr, 0, 0, SIZE * (STEPS + 1), SIZE * (STEPS+1));
114 do_composite (cr, op, bg, fg);
118 cairo_surface_destroy (fg);
119 cairo_surface_destroy (bg);
123 static cairo_surface_t *
124 create_source (cairo_surface_t *target, int width, int height)
126 cairo_surface_t *similar;
129 similar = cairo_surface_create_similar (target,
132 cr = cairo_create (similar);
133 cairo_surface_destroy (similar);
135 subdraw (cr, width, height);
137 similar = cairo_surface_reference (cairo_get_target (cr));
143 static cairo_test_status_t
144 draw (cairo_t *cr, int width, int height)
146 cairo_surface_t *source;
148 cairo_set_source_rgb (cr, 1, 1, 1);
151 source = create_source (cairo_get_target (cr), width, height);
152 cairo_set_source_surface (cr, source, 0, 0);
153 cairo_surface_destroy (source);
157 return CAIRO_TEST_SUCCESS;
160 CAIRO_TEST (operator_alpha_alpha,
161 "Tests result of compositing pure-alpha surfaces"
162 "\nCompositing of pure-alpha sources is inconsistent across backends.",
163 "alpha, similar, operator", /* keywords */
164 NULL, /* requirements */
165 FULL_WIDTH * SIZE, FULL_HEIGHT * SIZE,