FastUIDraw
stroked_path.hpp
Go to the documentation of this file.
1 /*!
2  * \file stroked_path.hpp
3  * \brief file stroked_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_STROKED_PATH_HPP
21 #define FASTUIDRAW_STROKED_PATH_HPP
22 
24 #include <fastuidraw/util/vecN.hpp>
28 #include <fastuidraw/path.hpp>
31 
32 namespace fastuidraw {
33 
34 /*!\addtogroup PainterAttribute
35  * @{
36  */
37 
38 /*!
39  * \brief
40  * A StrokedPath represents the data needed to draw a path stroked.
41  * It contains -all- the data needed to stroke a path regardless of
42  * stroking style. In particular, for a given TessellatedPath,
43  * one only needs to construct a StrokedPath <i>once</i> regardless
44  * of how one strokes the original path for drawing.
45  */
47  public reference_counted<StrokedPath>::non_concurrent
48 {
49 public:
50  /*!
51  * \brief
52  * A Subset represents a handle to a portion of a StrokedPath.
53  * The handle is invalid once the StrokedPath from which it
54  * comes goes out of scope. Do not save these handle values
55  * without also saving a handle of the StrokedPath from which
56  * they come. The region of a \ref Subset is the exact same
57  * region as a \ref PartitionedTessellatedPath::Subset object.
58  * Also, the \ref ID() value for a Subset is the same value as
59  * \ref PartitionedTessellatedPath::Subset::ID() as well.
60  */
61  class Subset
62  {
63  private:
64  typedef bool (Subset::*unspecified_bool_type)(void) const;
65 
66  public:
67  /*!
68  * Ctor to initialize value to "null" handle.
69  */
70  Subset(void):
71  m_d(nullptr)
72  {}
73 
74  /*!
75  * Allows one to legally write to test if Subset
76  * is a null-handle:
77  * \code
78  * Subset p;
79  *
80  * if (p)
81  * {
82  * // p does refers to data
83  * }
84  *
85  * if (!p)
86  * {
87  * // p does not referr to any data
88  * }
89  * \endcode
90  */
91  operator unspecified_bool_type() const
92  {
93  return m_d ? &Subset::has_children : 0;
94  }
95 
96  /*!
97  * Returns the segments that are within this
98  * \ref Subset
99  */
101  segment_chains(void) const;
102 
103  /*!
104  * Returns the joins within this \ref Subset
105  */
107  joins(void) const;
108 
109  /*!
110  * Returns the caps within this \ref Subset
111  */
113  caps(void) const;
114 
115  /*!
116  * Returns the PainterAttributeData to draw the triangles
117  * for the portion of the StrokedPath the Subset represents.
118  * Note: the data is packed with ArcStrokedPoint::pack()
119  * if StrokedPath::has_arcs() returns true, otherwise the
120  * data is packed with StrokedPoint::pack(). There is only
121  * one chunk of the returned object, chunk 0.
122  */
123  const PainterAttributeData&
124  painter_data(void) const;
125 
126  /*!
127  * Return the join chunk to feed the \ref PainterAttributeData
128  * returned by \ref bevel_joins(), \ref miter_clip_joins() \ref
129  * miter_bevel_joins(), \ref miter_joins(), \ref rounded_joins()
130  * or \ref arc_rounded_joins() to get the attribute and index
131  * data representing the joins within this subset. A return value
132  * of -1 indicates that there are no joins within this Subset.
133  */
134  int
135  join_chunk(void) const;
136 
137  /*!
138  * Return the join chunk to feed the \ref PainterAttributeData
139  * returned by \ref adjustable_caps(), \ref square_caps() \ref
140  * rounded_caps(), \ref flat_caps(), \ref arc_rounded_caps() to
141  * get the attribute and index data representing the caps
142  * within this subset. A return value of -1 indicates that there
143  * are no caps within this Subset.
144  */
145  int
146  cap_chunk(void) const;
147 
148  /*!
149  * Returns the bounding box.
150  */
151  const Rect&
152  bounding_box(void) const;
153 
154  /*!
155  * Returns the bounding box realized as a \ref Path.
156  */
157  const Path&
158  bounding_path(void) const;
159 
160  /*!
161  * Returns the ID of this Subset, i.e. the value to
162  * feed to \ref StrokedPath::subset() to get this
163  * \ref Subset.
164  */
165  unsigned int
166  ID(void) const;
167 
168  /*!
169  * Returns true if this Subset has child Subset
170  */
171  bool
172  has_children(void) const;
173 
174  /*!
175  * Returns the children of this Subset. It is an
176  * error to call this if \ref has_children() returns
177  * false.
178  */
180  children(void) const;
181 
182  private:
183  friend class StrokedPath;
184 
185  explicit
186  Subset(void *d);
187 
188  void *m_d;
189  };
190 
191  /*!
192  * A SubsetSelection represents what \ref Subset
193  * objects intersect a clipped region.
194  */
196  {
197  public:
198  /*!
199  * Ctor.
200  */
201  SubsetSelection();
202  ~SubsetSelection();
203 
204  /*!
205  * The ID's of what Subset objects are selected.
206  */
208  subset_ids(void) const;
209 
210  /*!
211  * ID's of what Subset objects are selected for joins.
212  * This value is different from \ref subset_ids() only
213  * when Stroked::select_subset_ids() was specified to
214  * enlarge the join footprints for miter-join stroking.
215  */
217  join_subset_ids(void) const;
218 
219  /*!
220  * Returns the source for the data.
221  */
223  source(void) const;
224 
225  /*!
226  * Clears the SubsetSelection to be empty.
227  * \param src value for \ref source() to return
228  */
229  void
232 
233  private:
234  friend class StrokedPath;
235 
236  void *m_d;
237  };
238 
239  ~StrokedPath();
240 
241  /*!
242  * Returns true if the \ref StrokedPath has arc.
243  * If the stroked path has arcs, ALL of the attribute
244  * data is packed \ref ArcStrokedPoint data,
245  * if it has no arcs then ALL of the data is
246  * packed \ref StrokedPoint data.
247  */
248  bool
249  has_arcs(void) const;
250 
251  /*!
252  * Returns the source \ref PartitionedTessellatedPath of this
253  * \ref StrokedPath.
254  */
256  partitioned_path(void) const;
257 
258  /*!
259  * Returns the number of Subset objects of the StrokedPath.
260  */
261  unsigned int
262  number_subsets(void) const;
263 
264  /*!
265  * Return the named Subset object of the StrokedPath.
266  */
267  Subset
268  subset(unsigned int I) const;
269 
270  /*!
271  * Returns the root-subset of the StrokedPath, this
272  * is the \ref Subset that includes the entire
273  * StrokedPath.
274  */
275  Subset
276  root_subset(void) const;
277 
278  /*!
279  * Returns the data to draw the square caps of a stroked path.
280  * The attribute data is packed \ref StrokedPoint data.
281  */
282  const PainterAttributeData&
283  square_caps(void) const;
284 
285  /*!
286  * Returns the data to draw the flat caps of a stroked path.
287  * The attribute data is packed \ref StrokedPoint data.
288  */
289  const PainterAttributeData&
290  flat_caps(void) const;
291 
292  /*!
293  * Returns the data to draw the caps of a stroked path used
294  * when stroking with a dash pattern. The attribute data is
295  * packed \ref StrokedPoint data.
296  */
297  const PainterAttributeData&
298  adjustable_caps(void) const;
299 
300  /*!
301  * Returns the data to draw the bevel joins of a stroked path.
302  * The attribute data is packed \ref StrokedPoint data.
303  */
304  const PainterAttributeData&
305  bevel_joins(void) const;
306 
307  /*!
308  * Returns the data to draw the miter joins of a stroked path,
309  * if the miter-limit is exceeded on stroking, the miter-join
310  * is clipped to the miter-limit. The attribute data is
311  * packed \ref StrokedPoint data.
312  */
313  const PainterAttributeData&
314  miter_clip_joins(void) const;
315 
316  /*!
317  * Returns the data to draw the miter joins of a stroked path,
318  * if the miter-limit is exceeded on stroking, the miter-join
319  * is to be drawn as a bevel join. The attribute data is
320  * packed \ref StrokedPoint data.
321  */
322  const PainterAttributeData&
323  miter_bevel_joins(void) const;
324 
325  /*!
326  * Returns the data to draw the miter joins of a stroked path,
327  * if the miter-limit is exceeded on stroking, the miter-join
328  * end point is clamped to the miter-distance. The attribute
329  * data is packed \ref StrokedPoint data.
330  */
331  const PainterAttributeData&
332  miter_joins(void) const;
333 
334  /*!
335  * Returns the data to draw rounded joins of a stroked path.
336  * The attribute data is packed \ref StrokedPoint data.
337  * \param thresh will return rounded joins so that the distance
338  * between the approximation of the round and the
339  * actual round is no more than thresh when the
340  * path is stroked with a stroking radius of one.
341  */
342  const PainterAttributeData&
343  rounded_joins(float thresh) const;
344 
345  /*!
346  * Returns the data to draw rounded caps of a stroked path.
347  * The attribute data is packed \ref StrokedPoint data.
348  * \param thresh will return rounded caps so that the distance
349  * between the approximation of the round and the
350  * actual round is no more than thresh when the
351  * path is stroked with a stroking radius of one.
352  */
353  const PainterAttributeData&
354  rounded_caps(float thresh) const;
355 
356  /*!
357  * Returns the data to draw rounded joins of a stroked path
358  * using the fragment shader to provide per-pixel coverage
359  * computation. The attribute data is packed \ref
360  * ArcStrokedPoint data.
361  */
362  const PainterAttributeData&
363  arc_rounded_joins(void) const;
364 
365  /*!
366  * Returns the data to draw rounded caps of a stroked path
367  * using the fragment shader to provide per-pixel coverage
368  * computation. The attribute data is packed \ref
369  * ArcStrokedPoint data.
370  */
371  const PainterAttributeData&
372  arc_rounded_caps(void) const;
373 
374  /*!
375  * Given a set of clip equations in clip coordinates
376  * and a tranformation from local coordiante to clip
377  * coordinates, compute what Subset are not completely
378  * culled by the clip equations.
379  * \param clip_equations array of clip equations
380  * \param clip_matrix_local 3x3 transformation from local (x, y, 1)
381  * coordinates to clip coordinates.
382  * \param one_pixel_width holds the size of a single pixel in
383  * normalized device coordinates
384  * \param geometry_inflation amount path geometry is inflated, array
385  * is indexed by the enumeration \ref
386  * PathEnums::path_geometry_inflation_index_t
387  * \param max_attribute_cnt only allow those chunks for which have no more
388  * than max_attribute_cnt attributes
389  * \param max_index_cnt only allow those chunks for which have no more
390  * than max_index_cnt indices
391  * \param select_miter_joins if true, when selecting what joins are in
392  * the area, enlarge the join footprint for if
393  * the joins are stroked as a type of miter join.
394  * \param[out] dst location to which to write the subset-selection.
395  */
396  void
397  select_subsets(c_array<const vec3> clip_equations,
398  const float3x3 &clip_matrix_local,
399  const vec2 &one_pixel_width,
400  c_array<const float> geometry_inflation,
401  unsigned int max_attribute_cnt,
402  unsigned int max_index_cnt,
403  bool select_miter_joins,
404  SubsetSelection &dst) const;
405 
406  /*!
407  * In contrast to select_subsets() which performs hierarchical
408  * culling against a set of clip equations, this routine performs
409  * no culling and returns the subsets needed to draw all of the
410  * StrokedPath.
411  * \param max_attribute_cnt only allow those chunks for which have no more
412  * than max_attribute_cnt attributes
413  * \param max_index_cnt only allow those chunks for which have no more
414  * than max_index_cnt indices
415  * \param[out] dst location to which to write the \ref Subset ID values
416  */
417  void
418  select_subsets_no_culling(unsigned int max_attribute_cnt,
419  unsigned int max_index_cnt,
420  SubsetSelection &dst) const;
421 
422 private:
423  friend class TessellatedPath;
424 
425  // only a TessellatedPath can construct a StrokedPath
426  explicit
427  StrokedPath(const TessellatedPath &P);
428 
429  void *m_d;
430 };
431 
432 /*! @} */
433 
434 }
435 
436 #endif
An TessellatedPath represents the tessellation of a Path into line segments and arcs.
A StrokedPath represents the data needed to draw a path stroked. It contains -all- the data needed to...
c_array< const TessellatedPath::join > joins(void) const
file fastuidraw_memory.hpp
file matrix.hpp
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
const PainterAttributeData & bevel_joins(void) const
c_array< const TessellatedPath::cap > caps(void) const
unsigned int ID(void) const
Subset root_subset(void) const
A wrapper over a pointer to implement reference counting.
vecN is a simple static array class with no virtual functions and no memory overhead. Supports runtim array index checking and STL style iterators via pointer iterators.
Definition: vecN.hpp:42
PainterAttributeData represents the attribute and index data ready to be consumed by a Painter...
const PainterAttributeData & miter_bevel_joins(void) const
const PainterAttributeData & miter_joins(void) const
const PainterAttributeData & rounded_caps(float thresh) const
A Subset represents a handle to a portion of a StrokedPath. The handle is invalid once the StrokedPat...
vecN< Subset, 2 > children(void) const
void select_subsets_no_culling(unsigned int max_attribute_cnt, unsigned int max_index_cnt, SubsetSelection &dst) const
file c_array.hpp
file path.hpp
void select_subsets(c_array< const vec3 > clip_equations, const float3x3 &clip_matrix_local, const vec2 &one_pixel_width, c_array< const float > geometry_inflation, unsigned int max_attribute_cnt, unsigned int max_index_cnt, bool select_miter_joins, SubsetSelection &dst) const
const Path & bounding_path(void) const
const PainterAttributeData & arc_rounded_caps(void) const
const PainterAttributeData & miter_clip_joins(void) const
c_array< const TessellatedPath::segment_chain > segment_chains(void) const
Subset subset(unsigned int I) const
file painter_attribute_data.hpp
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
unsigned int number_subsets(void) const
bool has_arcs(void) const
const PartitionedTessellatedPath & partitioned_path(void) const
const PainterAttributeData & flat_caps(void) const
file vecN.hpp
const PainterAttributeData & rounded_joins(float thresh) const
Defines default reference counting base classes.
A PartitionedTessellatedPath represents partitioning a TessellatedPath for quick computation of what ...
const Rect & bounding_box(void) const
A Path represents a collection of PathContour objects.
Definition: path.hpp:668
const PainterAttributeData & adjustable_caps(void) const
const PainterAttributeData & arc_rounded_joins(void) const
Class for which copy ctor and assignment operator are private functions.
Definition: util.hpp:505
file partitioned_tessellated_path.hpp
const PainterAttributeData & square_caps(void) const
const PainterAttributeData & painter_data(void) const
file reference_counted.hpp