FastUIDraw
filled_path.hpp
Go to the documentation of this file.
1 /*!
2  * \file filled_path.hpp
3  * \brief file filled_path.hpp
4  *
5  * Copyright 2016 by Intel.
6  *
7  * Contact: kevin.rogovin@gmail.com
8  *
9  * This Source Code Form is subject to the
10  * terms of the Mozilla Public License, v. 2.0.
11  * If a copy of the MPL was not distributed with
12  * this file, You can obtain one at
13  * http://mozilla.org/MPL/2.0/.
14  *
15  * \author Kevin Rogovin <kevin.rogovin@gmail.com>
16  *
17  */
18 
19 
20 #ifndef FASTUIDRAW_FILLED_PATH_HPP
21 #define FASTUIDRAW_FILLED_PATH_HPP
22 
24 #include <fastuidraw/util/vecN.hpp>
26 #include <fastuidraw/util/rect.hpp>
33 
34 namespace fastuidraw {
35 
36 ///@cond
37 class PainterAttributeData;
38 class TessellatedPath;
39 class Path;
40 ///@endcond
41 
42 /*!\addtogroup PainterAttribute
43  * @{
44  */
45 
46 /*!
47  * \brief
48  * A FilledPath represents the data needed to draw a path filled.
49  * It contains -all- the data needed to fill a path regardless of
50  * the fill rule.
51  */
52 class FilledPath:
53  public reference_counted<FilledPath>::non_concurrent
54 {
55 public:
56  /*!
57  * \brief
58  * A Subset represents a handle to a portion of a FilledPath.
59  * The handle is invalid once the FilledPath from which it
60  * comes goes out of scope. Do not save these handle values
61  * without also saving a handle of the FilledPath from which
62  * they come.
63  */
64  class Subset
65  {
66  public:
67  /*!
68  * Enumeration to specify type for an attribute of
69  * aa_fuzz_painter_data().
70  */
72  {
73  /*!
74  * Point is a point on the path.
75  */
77 
78  /*!
79  * Point is a point on the boundary of the aa-fuzz
80  */
82 
83  /*!
84  * Point is a point on the boundary of the aa-fuzz
85  * as a miter-join point.
86  */
88  };
89 
90  /*!
91  * Returns the PainterAttributeData to draw the triangles
92  * for the portion of the FilledPath the Subset represents.
93  * The attribute data is packed as follows:
94  * - PainterAttribute::m_attrib0 .xy -> position of point in local coordinate (float)
95  * - PainterAttribute::m_attrib0 .zw -> 0 (free)
96  * - PainterAttribute::m_attrib1 .xyzw -> 0 (free)
97  * - PainterAttribute::m_attrib2 .xyzw -> 0 (free)
98  */
100  painter_data(void) const;
101 
102  /*!
103  * Returns the PainterAttributeData to draw the anti-alias fuzz
104  * for the portion of the FilledPath the Subset represents.
105  * The aa-fuzz is drawn as a quad (of two triangles) per edge
106  * of the boudnary of a filled component.
107  * The attribute data is packed as follows:
108  * - PainterAttribute::m_attrib0 .xy -> position of point in local coordinate (float)
109  * - PainterAttribute::m_attrib0 .z -> (uint) classification, given by \ref aa_fuzz_type_t
110  * - PainterAttribute::m_attrib0 .w -> the z-offset value (uint)
111  * - PainterAttribute::m_attrib1 .xy -> normal vector to edge
112  * - PainterAttribute::m_attrib1 .zw -> normal vector to next edge
113  * - PainterAttribute::m_attrib2 .xyzw -> 0 (free)
114  */
115  const PainterAttributeData&
116  aa_fuzz_painter_data(void) const;
117 
118  /*!
119  * Returns an array listing what winding number values
120  * there are triangle in this Subset. To get the indices
121  * for those triangle with winding number N, use the chunk
122  * computed from chunk_from_winding_number(N). The same attribute
123  * chunk, 0, is used regardless of which index chunk.
124  */
126  winding_numbers(void) const;
127 
128  /*!
129  * Returns the bounding box realized as a \ref Path.
130  */
131  const Path&
132  bounding_path(void) const;
133 
134  /*!
135  * Returns the bounding box of the Subset.
136  */
137  const Rect&
138  bounding_box(void) const;
139 
140  /*!
141  * Returns what chunk to pass PainterAttributeData::index_data_chunk()
142  * called on the \ref PainterAttributeData returned by painter_data()
143  * to get the triangles of a specified winding number. The same
144  * attribute chunk, 0, is used regardless of which winding number.
145  * \param w winding number
146  */
147  static
148  unsigned int
150 
151  /*!
152  * Returns what chunk to pass PainterAttributeData::index_data_chunk()
153  * called on the \ref PainterAttributeData returned by painter_data()
154  * to get the triangles of a specified fill rule.
155  */
156  static
157  unsigned int
159 
160  /*!
161  * Returns the chunk to pass PainterAttributeData::index_data_chunk()
162  * and PainterAttributeData::attribute_data_chunk() on the
163  * \ref PainterAttributeData returned by aa_fuzz_painter_data().
164  * NOTE that this value is NOT the same as returned by
165  * fill_chunk_from_winding_number(int).
166  * \param w winding number
167  */
168  static
169  unsigned int
171 
172  private:
173  friend class FilledPath;
174 
175  explicit
176  Subset(void *d);
177 
178  void *m_d;
179  };
180 
181  /*!
182  * \brief
183  * Opaque object to hold work room needed for functions
184  * of FilledPath that require scratch space.
185  */
187  {
188  public:
189  ScratchSpace(void);
190  ~ScratchSpace();
191  private:
192  friend class FilledPath;
193  void *m_d;
194  };
195 
196  ~FilledPath();
197 
198  /*!
199  * Returns the the bounding box of the \ref FilledPath.
200  */
201  const Rect&
202  bounding_box(void) const;
203 
204  /*!
205  * Returns the number of Subset objects of the FilledPath.
206  */
207  unsigned int
208  number_subsets(void) const;
209 
210  /*!
211  * Return the named \ref Subset object of the FilledPath.
212  */
213  Subset
214  subset(unsigned int I) const;
215 
216  /*!
217  * Returns the root \ref Subset, i.e. the \ref Subset that
218  * encompasses the entire \ref FilledPath.
219  */
220  Subset
221  root_subset(void) const;
222 
223  /*!
224  * Fetch those Subset objects that have triangles that
225  * intersect a region specified by clip equations.
226  * \param scratch_space scratch space for computations.
227  * \param clip_equations array of clip equations
228  * \param clip_matrix_local 3x3 transformation from local (x, y, 1)
229  * coordinates to clip coordinates.
230  * \param max_attribute_cnt only allow those \ref Subset objects for which
231  * Subset::painter_data() have no more than
232  * max_attribute_cnt attributes.
233  * \param max_index_cnt only allow those \ref Subset objects for which
234  * Subset::painter_data() have no more than
235  * max_index_cnt attributes.
236  * \param[out] dst location to which to write the \ref Subset ID values
237  * \returns the number of Subset object ID's written to dst, that
238  * number is guaranteed to be no more than number_subsets().
239  *
240  */
241  unsigned int
242  select_subsets(ScratchSpace &scratch_space,
243  c_array<const vec3> clip_equations,
244  const float3x3 &clip_matrix_local,
245  unsigned int max_attribute_cnt,
246  unsigned int max_index_cnt,
247  c_array<unsigned int> dst) const;
248 
249  /*!
250  * In contrast to select_subsets() which performs hierarchical
251  * culling against a set of clip equations, this routine performs
252  * no culling and returns the subsets needed to draw all of the
253  * FilledPath.
254  * \param max_attribute_cnt only allow those chunks for which have no more
255  * than max_attribute_cnt attributes
256  * \param max_index_cnt only allow those chunks for which have no more
257  * than max_index_cnt indices
258  * \param[out] dst location to which to write the \ref Subset ID values
259  * \returns the number of Subset object ID's written to dst, that
260  * number is guaranteed to be no more than number_subsets().
261  */
262  unsigned int
263  select_subsets_no_culling(unsigned int max_attribute_cnt,
264  unsigned int max_index_cnt,
265  c_array<unsigned int> dst) const;
266 private:
267  friend class TessellatedPath;
268 
269  // only a TessellatedPath can construct a FilledPath
270  explicit
271  FilledPath(const TessellatedPath &P);
272 
273  void *m_d;
274 };
275 
276 /*! @} */
277 
278 } //namespace fastuidraw
279 
280 #endif
An TessellatedPath represents the tessellation of a Path into line segments and arcs.
const PainterAttributeData & painter_data(void) const
file fastuidraw_memory.hpp
A Subset represents a handle to a portion of a FilledPath. The handle is invalid once the FilledPath ...
Definition: filled_path.hpp:64
file matrix.hpp
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
static unsigned int fill_chunk_from_fill_rule(enum PainterEnums::fill_rule_t fill_rule)
const Path & bounding_path(void) const
PainterAttributeData represents the attribute and index data ready to be consumed by a Painter...
const PainterAttributeData & aa_fuzz_painter_data(void) const
Opaque object to hold work room needed for functions of FilledPath that require scratch space...
file c_array.hpp
const Rect & bounding_box(void) const
Subset root_subset(void) const
file painter_attribute_data.hpp
A FilledPath represents the data needed to draw a path filled. It contains -all- the data needed to f...
Definition: filled_path.hpp:52
unsigned int select_subsets_no_culling(unsigned int max_attribute_cnt, unsigned int max_index_cnt, c_array< unsigned int > dst) const
unsigned int select_subsets(ScratchSpace &scratch_space, c_array< const vec3 > clip_equations, const float3x3 &clip_matrix_local, unsigned int max_attribute_cnt, unsigned int max_index_cnt, c_array< unsigned int > dst) const
A c_array is a wrapper over a C pointer with a size parameter to facilitate bounds checking and provi...
Definition: c_array.hpp:43
file painter_enums.hpp
file vecN.hpp
fill_rule_t
Enumerations specifying common fill rules.
Defines default reference counting base classes.
unsigned int number_subsets(void) const
c_array< const int > winding_numbers(void) const
A Path represents a collection of PathContour objects.
Definition: path.hpp:668
Class for which copy ctor and assignment operator are private functions.
Definition: util.hpp:505
file painter_attribute_writer.hpp
static unsigned int fill_chunk_from_winding_number(int w)
Subset subset(unsigned int I) const
file fill_rule.hpp
static unsigned int aa_fuzz_chunk_from_winding_number(int w)
file reference_counted.hpp