FastUIDraw
painter_data_value.hpp
Go to the documentation of this file.
1 /*!
2  * \file painter_data_value.hpp
3  * \brief file painter_data_value.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 #ifndef FASTUIDRAW_PAINTER_DATA_VALUE_HPP
20 #define FASTUIDRAW_PAINTER_DATA_VALUE_HPP
21 
23 
24 namespace fastuidraw
25 {
26  class PainterPackedValuePool;
27 
28 /*!\addtogroup PainterShaderData
29  * @{
30  */
31 
32  /*!
33  * \brief
34  * Element of \ref PainterData to hold shader data either
35  * reference directly to unpacked data or to reuseable
36  * packed data.
37  *
38  * Holds both a PainterPackedValue and a pointer to a value.
39  * If \ref m_packed_value is valid, then its value is used. If
40  * it is nullptr then the value pointed to by \ref m_value is used.
41  */
42  template<typename T>
44  {
45  public:
46  /*!
47  * Ctor from a value.
48  * \param p value with which to initialize, the object pointed
49  * to by p must stay in scope until either make_packed()
50  * is called or the dtor of this \ref PainterDataValue
51  * object is called.
52  */
53  PainterDataValue(const T *p = nullptr):
54  m_value(p)
55  {}
56 
57  /*!
58  * Ctor from a packed value.
59  * \param p value with which to initialize \ref m_packed_value
60  */
62  m_value(nullptr),
64  {}
65 
66  /*!
67  * Only makes sense for \ref PainterBrushShaderData,
68  * see \ref PainterBrushShaderData::bind_images().
69  */
71  bind_images(void) const
72  {
73  return (m_value) ?
74  m_value->bind_images() :
75  m_packed_value.bind_images();
76  }
77 
78  /*!
79  * If \ref m_packed_value is null, then sets it
80  * to a packed value created by the passed \ref
81  * PainterPackedValuePool. In addition, sets
82  * \ref m_value to nullptr.
83  * \param pool \ref PainterPackedValuePool from
84  * which to create the packed value
85  */
86  void
88 
89  /*!
90  * Provided as a conveniance, equivalent to
91  * \code
92  * m_packed_value
93  * \endcode
94  */
95  bool
96  packed(void) const
97  {
98  return m_packed_value;
99  }
100 
101  /*!
102  * Pointer to value.
103  */
104  const T *m_value;
105 
106  /*!
107  * Value pre-packed and ready for reuse.
108  */
110  };
111 /*! @} */
112 }
113 
114 #endif
A PainterPackedValue represents a handle to an object that stores packed state data and tracks if tha...
A PainterPackedValuePool can be used to create PainterPackedValue objects.
c_array< const reference_counted_ptr< const Image > > bind_images(void) const
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
PainterDataValue(const PainterPackedValue< T > &p)
void make_packed(PainterPackedValuePool &pool)
file painter_packed_value.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
PainterPackedValue< T > m_packed_value
Element of PainterData to hold shader data either reference directly to unpacked data or to reuseable...
PainterDataValue(const T *p=nullptr)