refactor AlphaFunction class to reduce size 11/247211/1
authorSubhransu Mohanty <sub.mohanty@samsung.com>
Mon, 9 Nov 2020 02:33:12 +0000 (11:33 +0900)
committerSubhransu Mohanty <sub.mohanty@samsung.com>
Mon, 9 Nov 2020 02:40:32 +0000 (11:40 +0900)
Change-Id: I4ed9ad6e4367a97ac97f64cb5b82140fc969d99f

dali/public-api/animation/alpha-function.cpp
dali/public-api/animation/alpha-function.h

index 8952092..0e8ea04 100644 (file)
 
 namespace Dali
 {
-namespace
-{
-constexpr uint32_t BitMaskOfN(uint32_t bits)
-{
-  return (1 << bits) - 1;
-}
-
-} // unnamed namespace
-
 AlphaFunction::AlphaFunction()
-: mBezierControlPoints(Vector4::ZERO),
-  mCustom(nullptr),
-  mBuiltin(DEFAULT),
-  mMode(BUILTIN_FUNCTION)
+: mMode(BUILTIN_FUNCTION),
+  mBuiltin(DEFAULT)
 {
 }
 
 AlphaFunction::AlphaFunction(BuiltinFunction function)
-: mBezierControlPoints(Vector4::ZERO),
-  mCustom(nullptr),
-  mBuiltin(function),
-  mMode(BUILTIN_FUNCTION)
+: mMode(BUILTIN_FUNCTION),
+  mBuiltin(function)
 {
 }
 
 AlphaFunction::AlphaFunction(AlphaFunctionPrototype function)
-: mBezierControlPoints(Vector4::ZERO),
-  mCustom(function),
-  mBuiltin(DEFAULT),
-  mMode(CUSTOM_FUNCTION)
+: mMode(CUSTOM_FUNCTION),
+  mCustom(function)
 {
 }
 
 AlphaFunction::AlphaFunction(const Vector2& controlPoint0, const Vector2& controlPoint1)
-: mBezierControlPoints(
+: mMode(BEZIER),
+  mBuiltin(DEFAULT),
+  mBezierControlPoints(
     Vector4(Clamp(controlPoint0.x, 0.0f, 1.0f),
             controlPoint0.y,
             Clamp(controlPoint1.x, 0.0f, 1.0f),
-            controlPoint1.y)),
-  mCustom(nullptr),
-  mBuiltin(DEFAULT),
-  mMode(BEZIER)
+            controlPoint1.y))
 {
 }
 
 Vector4 AlphaFunction::GetBezierControlPoints() const
 {
-  return mBezierControlPoints;
+  return (mMode == BEZIER) ? mBezierControlPoints : Vector4::ZERO;
 }
 
 AlphaFunctionPrototype AlphaFunction::GetCustomFunction() const
 {
-  return mCustom;
+  return (mMode == CUSTOM_FUNCTION) ? mCustom : nullptr;
 }
 
 AlphaFunction::BuiltinFunction AlphaFunction::GetBuiltinFunction() const
 {
-  return static_cast<AlphaFunction::BuiltinFunction>(mBuiltin & BitMaskOfN(Log<COUNT>::value + 1));
+  return mBuiltin;
 }
 
 AlphaFunction::Mode AlphaFunction::GetMode() const
 {
-  return static_cast<AlphaFunction::Mode>(mMode & BitMaskOfN(2));
+  return mMode;
 }
 
 } // namespace Dali
index 48c32b0..3e006dc 100644 (file)
@@ -18,6 +18,9 @@
  *
  */
 
+// EXTERNAL INCLUDES
+#include <cstdint> // uint8_t
+
 // INTERNAL INCLUDES
 #include <dali/public-api/common/constants.h>
 #include <dali/public-api/common/dali-common.h>
@@ -49,7 +52,7 @@ public:
    * @brief Enumeration for built-in alpha functions.
    * @SINCE_1_0.0
    */
-  enum BuiltinFunction
+  enum BuiltinFunction : uint8_t
   {
     DEFAULT,          ///< Linear @SINCE_1_0.0
     LINEAR,           ///< No transformation @SINCE_1_0.0
@@ -72,7 +75,7 @@ public:
    * @brief Enumeration for all possible functioning modes for the alpha function.
    * @SINCE_1_0.0
    */
-  enum Mode
+  enum Mode : uint8_t
   {
     BUILTIN_FUNCTION, ///< The user has specified a built-in function @SINCE_1_0.0
     CUSTOM_FUNCTION,  ///< The user has provided a custom function @SINCE_1_0.0
@@ -148,10 +151,14 @@ public:
   Mode GetMode() const;
 
 private:
-  Vector4                mBezierControlPoints;             //< Control points for the bezier alpha function
-  AlphaFunctionPrototype mCustom;                          //< Pointer to an alpha function
-  BuiltinFunction        mBuiltin : Log<COUNT>::value + 1; //< Enum indicating the built-in alpha function
-  Mode                   mMode : 2;                        //< Enum indicating the functioning mode of the AlphaFunction
+  Mode            mMode;    //< Enum indicating the functioning mode of the AlphaFunction
+  BuiltinFunction mBuiltin; //< Enum indicating the built-in alpha function
+
+  union
+  {
+    Vector4                mBezierControlPoints; //< Control points for the bezier alpha function
+    AlphaFunctionPrototype mCustom;              //< Pointer to an alpha function
+  };
 };
 
 /**