tizen 2.3.1 release
[framework/graphics/cairo.git] / src / cairo-gl-source.c
1 /* cairo - a vector graphics library with display and print output
2  *
3  * Copyright © 2011 Intel Corporation
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it either under the terms of the GNU Lesser General Public
7  * License version 2.1 as published by the Free Software Foundation
8  * (the "LGPL") or, at your option, under the terms of the Mozilla
9  * Public License Version 1.1 (the "MPL"). If you do not alter this
10  * notice, a recipient may use your version of this file under either
11  * the MPL or the LGPL.
12  *
13  * You should have received a copy of the LGPL along with this library
14  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
16  * You should have received a copy of the MPL along with this library
17  * in the file COPYING-MPL-1.1
18  *
19  * The contents of this file are subject to the Mozilla Public License
20  * Version 1.1 (the "License"); you may not use this file except in
21  * compliance with the License. You may obtain a copy of the License at
22  * http://www.mozilla.org/MPL/
23  *
24  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
25  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
26  * the specific language governing rights and limitations.
27  *
28  * The Original Code is the cairo graphics library.
29  *
30  * The Initial Developer of the Original Code is Red Hat, Inc.
31  *
32  * Contributor(s):
33  *      Chris Wilson <chris@chris-wilson.co.uk>
34  */
35
36 #include "cairoint.h"
37
38 #include "cairo-gl-private.h"
39
40 #include "cairo-surface-backend-private.h"
41
42 static cairo_status_t
43 _cairo_gl_source_finish (void *abstract_surface)
44 {
45     cairo_gl_source_t *source = abstract_surface;
46
47     _cairo_gl_operand_destroy (&source->operand);
48     return CAIRO_STATUS_SUCCESS;
49 }
50
51 static const cairo_surface_backend_t cairo_gl_source_backend = {
52     CAIRO_SURFACE_TYPE_GL,
53     _cairo_gl_source_finish,
54     NULL, /* read-only wrapper */
55 };
56
57 cairo_surface_t *
58 _cairo_gl_pattern_to_source (cairo_surface_t *dst,
59                              const cairo_pattern_t *pattern,
60                              cairo_bool_t is_mask,
61                              const cairo_rectangle_int_t *extents,
62                              const cairo_rectangle_int_t *sample,
63                              int *src_x, int *src_y)
64 {
65     cairo_gl_source_t *source;
66     cairo_int_status_t status;
67
68     TRACE ((stderr, "%s\n", __FUNCTION__));
69     if (pattern == NULL)
70         return _cairo_gl_white_source ();
71
72     source = malloc (sizeof (*source));
73     if (unlikely (source == NULL))
74         return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
75
76     _cairo_surface_init (&source->base,
77                          &cairo_gl_source_backend,
78                          NULL, /* device */
79                          CAIRO_CONTENT_COLOR_ALPHA);
80
81     *src_x = *src_y = 0;
82     status = _cairo_gl_operand_init (&source->operand, pattern,
83                                      (cairo_gl_surface_t *)dst,
84                                      sample, extents,
85                                      FALSE, FALSE);
86     if (unlikely (status)) {
87         cairo_surface_destroy (&source->base);
88         return _cairo_surface_create_in_error (status);
89     }
90
91     return &source->base;
92 }
93
94 cairo_surface_t *
95 _cairo_gl_white_source (void)
96 {
97     cairo_gl_source_t *source;
98
99     source = malloc (sizeof (*source));
100     if (unlikely (source == NULL))
101         return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
102
103     _cairo_surface_init (&source->base,
104                          &cairo_gl_source_backend,
105                          NULL, /* device */
106                          CAIRO_CONTENT_COLOR_ALPHA);
107
108     _cairo_gl_solid_operand_init (&source->operand, CAIRO_COLOR_WHITE);
109
110     return &source->base;
111 }