(Renderer) Fix memory leak when using blend-color
[platform/core/uifw/dali-core.git] / dali / internal / common / blending-options.h
1 #ifndef DALI_BLENDING_OPTIONS_H
2 #define DALI_BLENDING_OPTIONS_H
3
4 /*
5  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/rendering/renderer.h>
23 #include <dali/public-api/math/vector4.h>
24 #include <dali/internal/common/owner-pointer.h>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 // This is an optimization to avoid storing 6 separate blending values
33 struct BlendingOptions
34 {
35   /**
36    * Create some default blending options.
37    */
38   BlendingOptions();
39
40   /**
41    * Non-virtual destructor.
42    */
43   ~BlendingOptions();
44
45   /**
46    * Set the blending options.
47    * @param[in] A bitmask of blending options.
48    */
49   void SetBitmask( unsigned int bitmask );
50
51   /**
52    * Retrieve the blending options as a bitmask.
53    * @return A bitmask of blending options.
54    */
55   unsigned int GetBitmask() const;
56
57   /**
58    * @copydoc Dali::RenderableActor::SetBlendFunc()
59    */
60   void SetBlendFunc( BlendFactor::Type srcFactorRgb,   BlendFactor::Type destFactorRgb,
61                      BlendFactor::Type srcFactorAlpha, BlendFactor::Type destFactorAlpha );
62
63   /**
64    * @copydoc Dali::RenderableActor::GetBlendFunc()
65    */
66   BlendFactor::Type GetBlendSrcFactorRgb() const;
67
68   /**
69    * @copydoc Dali::RenderableActor::GetBlendFunc()
70    */
71   BlendFactor::Type GetBlendDestFactorRgb() const;
72
73   /**
74    * @copydoc Dali::RenderableActor::GetBlendFunc()
75    */
76   BlendFactor::Type GetBlendSrcFactorAlpha() const;
77
78   /**
79    * @copydoc Dali::RenderableActor::GetBlendFunc()
80    */
81   BlendFactor::Type GetBlendDestFactorAlpha() const;
82
83   /**
84    * @copydoc Dali::RenderableActor::SetBlendEquation()
85    */
86   void SetBlendEquation( BlendEquation::Type equationRgb, BlendEquation::Type equationAlpha );
87
88   /**
89    * @copydoc Dali::RenderableActor::GetBlendEquation()
90    */
91   BlendEquation::Type GetBlendEquationRgb() const;
92
93   /**
94    * @copydoc Dali::RenderableActor::GetBlendEquation()
95    */
96   BlendEquation::Type GetBlendEquationAlpha() const;
97
98   /**
99    * Set the blend color.
100    * @param[in] color The blend color.
101    * @return True if the blend color changed, otherwise it was already the same color.
102    */
103   void SetBlendColor( const Vector4& color );
104
105   /**
106    * Query the blend color.
107    * The blend color, or NULL if no blend color was set.
108    */
109   const Vector4* GetBlendColor() const;
110
111 private:
112
113   // Undefined copy constructor.
114   BlendingOptions(const BlendingOptions& typePath);
115
116   // Undefined copy constructor.
117   BlendingOptions& operator=(const BlendingOptions& rhs);
118
119 private:
120
121   unsigned int mBitmask; ///< A bitmask of blending options
122
123   OwnerPointer< Vector4> mBlendColor; ///< A heap-allocated color (owned)
124
125 };
126
127 } // namespace Internal
128
129 } // namespace Dali
130
131 #endif // DALI_BLENDING_OPTIONS_H