70c87db828351c6173aba8e566936c8bee5dd37d
[framework/graphics/cairo.git] / src / cairo-surface-observer-private.h
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 Intel Corporation.
31  *
32  * Contributor(s):
33  *      Chris Wilson <chris@chris-wilson.co.uk>
34  */
35
36 #ifndef CAIRO_SURFACE_OBSERVER_PRIVATE_H
37 #define CAIRO_SURFACE_OBSERVER_PRIVATE_H
38
39 #include "cairoint.h"
40
41 #include "cairo-device-private.h"
42 #include "cairo-list-private.h"
43 #include "cairo-recording-surface-private.h"
44 #include "cairo-surface-private.h"
45 #include "cairo-surface-backend-private.h"
46 #include "cairo-time-private.h"
47
48 struct stat {
49     double min, max, sum, sum_sq;
50     unsigned count;
51 };
52
53 #define NUM_OPERATORS (CAIRO_OPERATOR_HSL_LUMINOSITY+1)
54 #define NUM_CAPS (CAIRO_LINE_CAP_SQUARE+1)
55 #define NUM_JOINS (CAIRO_LINE_JOIN_BEVEL+1)
56 #define NUM_ANTIALIAS (CAIRO_ANTIALIAS_BEST+1)
57 #define NUM_FILL_RULE (CAIRO_FILL_RULE_EVEN_ODD+1)
58
59 struct extents {
60     struct stat area;
61     unsigned int bounded, unbounded;
62 };
63
64 struct pattern {
65     unsigned int type[7]; /* native/record/other surface/gradients */
66 };
67
68 struct path {
69     unsigned int type[5]; /* empty/pixel/rectilinear/straight/curved */
70 };
71
72 struct clip {
73     unsigned int type[6]; /* none, region, boxes, single path, polygon, general */
74 };
75
76 typedef struct _cairo_observation cairo_observation_t;
77 typedef struct _cairo_observation_record cairo_observation_record_t;
78 typedef struct _cairo_device_observer cairo_device_observer_t;
79
80 struct _cairo_observation_record {
81     cairo_content_t target_content;
82     int target_width;
83     int target_height;
84
85     int index;
86     cairo_operator_t op;
87     int source;
88     int mask;
89     int num_glyphs;
90     int path;
91     int fill_rule;
92     double tolerance;
93     int antialias;
94     int clip;
95     cairo_time_t elapsed;
96 };
97
98 struct _cairo_observation {
99     int num_surfaces;
100     int num_contexts;
101     int num_sources_acquired;
102
103     /* XXX put interesting stats here! */
104
105     struct paint {
106         cairo_time_t elapsed;
107         unsigned int count;
108         struct extents extents;
109         unsigned int operators[NUM_OPERATORS];
110         struct pattern source;
111         struct clip clip;
112         unsigned int noop;
113
114         cairo_observation_record_t slowest;
115     } paint;
116
117     struct mask {
118         cairo_time_t elapsed;
119         unsigned int count;
120         struct extents extents;
121         unsigned int operators[NUM_OPERATORS];
122         struct pattern source;
123         struct pattern mask;
124         struct clip clip;
125         unsigned int noop;
126
127         cairo_observation_record_t slowest;
128     } mask;
129
130     struct fill {
131         cairo_time_t elapsed;
132         unsigned int count;
133         struct extents extents;
134         unsigned int operators[NUM_OPERATORS];
135         struct pattern source;
136         struct path path;
137         unsigned int antialias[NUM_ANTIALIAS];
138         unsigned int fill_rule[NUM_FILL_RULE];
139         struct clip clip;
140         unsigned int noop;
141
142         cairo_observation_record_t slowest;
143     } fill;
144
145     struct stroke {
146         cairo_time_t elapsed;
147         unsigned int count;
148         struct extents extents;
149         unsigned int operators[NUM_OPERATORS];
150         unsigned int caps[NUM_CAPS];
151         unsigned int joins[NUM_CAPS];
152         unsigned int antialias[NUM_ANTIALIAS];
153         struct pattern source;
154         struct path path;
155         struct stat line_width;
156         struct clip clip;
157         unsigned int noop;
158
159         cairo_observation_record_t slowest;
160     } stroke;
161
162     struct glyphs {
163         cairo_time_t elapsed;
164         unsigned int count;
165         struct extents extents;
166         unsigned int operators[NUM_OPERATORS];
167         struct pattern source;
168         struct clip clip;
169         unsigned int noop;
170
171         cairo_observation_record_t slowest;
172     } glyphs;
173
174     cairo_array_t timings;
175     cairo_recording_surface_t *record;
176 };
177
178 struct _cairo_device_observer {
179     cairo_device_t base;
180     cairo_device_t *target;
181
182     cairo_observation_t log;
183 };
184
185 struct callback_list {
186     cairo_list_t link;
187
188     cairo_surface_observer_callback_t func;
189     void *data;
190 };
191
192 struct _cairo_surface_observer {
193     cairo_surface_t base;
194     cairo_surface_t *target;
195
196     cairo_observation_t log;
197
198     cairo_list_t paint_callbacks;
199     cairo_list_t mask_callbacks;
200     cairo_list_t fill_callbacks;
201     cairo_list_t stroke_callbacks;
202     cairo_list_t glyphs_callbacks;
203
204     cairo_list_t flush_callbacks;
205     cairo_list_t finish_callbacks;
206 };
207
208 #endif /* CAIRO_SURFACE_OBSERVER_PRIVATE_H */