Added devel property PREMULTIPLIED_ALPHA ( "premultipliedAlpha" ). 56/103556/1 accepted/tizen/3.0/common/20161209.161244 accepted/tizen/3.0/ivi/20161209.105551 accepted/tizen/3.0/mobile/20161209.105218 accepted/tizen/3.0/tv/20161209.105411 accepted/tizen/3.0/wearable/20161209.105522 submit/tizen_3.0/20161209.084701
authoradam.b <adam.b@samsung.com>
Thu, 8 Dec 2016 14:58:04 +0000 (14:58 +0000)
committeradam.b <adam.b@samsung.com>
Thu, 8 Dec 2016 15:37:03 +0000 (15:37 +0000)
Control::SetBackground() applies premultipliedAlpha on existing
visual if no new visual instantiated.

The property enables/disables premultiplied alpha on the Visual.

Example:

control.SetProperty( Toolkit::Control::Property::BACKGROUND,
                     Property::Map().
                     Add( "premultipliedAlpha", true ));

Change-Id: Ie28aaceb9e7b9ca4f7a1e4ef0cf424a4a7fe5f00

automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp
dali-toolkit/devel-api/visuals/visual-properties-devel.h [new file with mode: 0644]
dali-toolkit/internal/visuals/visual-base-impl.cpp
dali-toolkit/internal/visuals/visual-string-constants.cpp
dali-toolkit/internal/visuals/visual-string-constants.h
dali-toolkit/public-api/controls/control-impl.cpp

index d82277d..ed906ae 100644 (file)
@@ -1012,3 +1012,61 @@ int UtcDaliVisualWireframeVisual(void)
   END_TEST;
 }
 
+int UtcDaliVisualPremultipliedAlpha(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline( "UtcDaliVisualPremultipliedAlpha" );
+
+  VisualFactory factory = VisualFactory::Get();
+
+  // image visual, test default value ( false )
+  {
+    Visual::Base imageVisual = factory.CreateVisual(
+          Property::Map()
+          .Add( Visual::Property::TYPE, Visual::IMAGE )
+          .Add( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME ) );
+
+    Dali::Property::Map visualMap;
+    imageVisual.CreatePropertyMap( visualMap );
+    Property::Value* value = visualMap.Find( DevelVisual::Property::PREMULTIPLIED_ALPHA );
+
+    // test values
+    DALI_TEST_CHECK( value );
+    DALI_TEST_EQUALS( value->Get<bool>(), false, TEST_LOCATION );
+  }
+
+  // image visual, override premultiplied
+  {
+    Visual::Base imageVisual = factory.CreateVisual(
+          Property::Map()
+          .Add( Visual::Property::TYPE, Visual::IMAGE )
+          .Add( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME )
+          .Add( DevelVisual::Property::PREMULTIPLIED_ALPHA, true ) );
+
+    Dali::Property::Map visualMap;
+    imageVisual.CreatePropertyMap( visualMap );
+    Property::Value* value = visualMap.Find( DevelVisual::Property::PREMULTIPLIED_ALPHA );
+
+    // test values
+    DALI_TEST_CHECK( value );
+    DALI_TEST_EQUALS( value->Get<bool>(), true, TEST_LOCATION);
+  }
+
+  // svg visual ( premultiplied alpha by default is true )
+  {
+    Visual::Base imageVisual = factory.CreateVisual(
+          Property::Map()
+          .Add( Visual::Property::TYPE, Visual::IMAGE )
+          .Add( ImageVisual::Property::URL, TEST_SVG_FILE_NAME ) );
+
+    Dali::Property::Map visualMap;
+    imageVisual.CreatePropertyMap( visualMap );
+    Property::Value* value = visualMap.Find( DevelVisual::Property::PREMULTIPLIED_ALPHA );
+
+    // test values
+    DALI_TEST_CHECK( value );
+    DALI_TEST_EQUALS( value->Get<bool>(), true, TEST_LOCATION );
+  }
+
+  END_TEST;
+}
diff --git a/dali-toolkit/devel-api/visuals/visual-properties-devel.h b/dali-toolkit/devel-api/visuals/visual-properties-devel.h
new file mode 100644 (file)
index 0000000..8f7248f
--- /dev/null
@@ -0,0 +1,135 @@
+#ifndef DALI_TOOLKIT_DEVEL_API_VISUALS_VISUAL_PROPERTIES_DEVEL_H
+#define DALI_TOOLKIT_DEVEL_API_VISUALS_VISUAL_PROPERTIES_DEVEL_H
+
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace DevelVisual
+{
+
+/**
+ * @brief All the visual types.
+ */
+enum Type
+{
+  BORDER    = Dali::Toolkit::Visual::BORDER,
+  COLOR     = Dali::Toolkit::Visual::COLOR,
+  GRADIENT  = Dali::Toolkit::Visual::GRADIENT,
+  IMAGE     = Dali::Toolkit::Visual::IMAGE,
+  MESH      = Dali::Toolkit::Visual::MESH,
+  PRIMITIVE = Dali::Toolkit::Visual::PRIMITIVE,
+  WIREFRAME = Dali::Toolkit::Visual::WIREFRAME,
+
+  TEXT      = WIREFRAME + 1, ///< Renders text.
+};
+
+namespace Property
+{
+
+enum Type
+{
+  TYPE   = Dali::Toolkit::Visual::Property::TYPE,
+  SHADER = Dali::Toolkit::Visual::Property::SHADER,
+
+  /**
+   * @brief The transform used by the visual.
+   * @details Name "transform", type Property::Map.
+
+   * @note Optional.
+   * @see DevelVisual::Transform::Property
+   */
+  TRANSFORM = SHADER + 1, // Dali::Toolkit::Visual::Property::SHADER + 1
+
+  /**
+   * @brief Enables/disables premultiplied alpha.
+   * The premultiplied alpha is false by default unless this behaviour is modified
+   * by the derived Visual type.
+
+   * @details Name "premultipliedAlpha", type Property::Boolean.
+
+   * @note Optional.
+   */
+  PREMULTIPLIED_ALPHA = SHADER + 2, // Dali::Toolkit::Visual::Property::SHADER + 2
+};
+
+} //namespace Property
+
+namespace Transform
+{
+
+namespace Property
+{
+
+enum Type
+{
+  /**
+   * @brief Offset of the visual. It can be either relative (percentage of the parent)
+   * or absolute (in world units).
+   * @details Name "offset", type Property::VECTOR2
+   */
+  OFFSET,
+
+  /**
+   * @brief Size of the visual. It can be either relative (percentage of the parent)
+   * or absolute (in world units).
+   * @details Name "size", type Property::VECTOR2
+   */
+  SIZE,
+
+  /**
+   * @brief The origin of the visual within its control area.
+   * @details Name "origin", type Align::Type (Property::INTEGER) or Property::STRING.
+   * @see Toolkit::Align
+   */
+  ORIGIN,
+
+  /**
+   * @brief The anchor-point of the visual
+   * @details Name "anchorPoint", type Align::Type (Property::INTEGER) or Property::STRING.
+   * @see Toolkit::Align
+   */
+  ANCHOR_POINT,
+
+  /**
+   * @brief Indicates which components of the offset and size are relative
+   * (percentage of the parent) or absolute (in world units).
+   * 0 indicates the component is relative, and 1 absolute.
+   * @details Name "offsetSizeMode", type Property::VECTOR4
+   */
+  OFFSET_SIZE_MODE
+};
+
+} //namespace Property
+
+} // namespace Transform
+
+} // namespace DevelVisual
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // DALI_TOOLKIT_DEVEL_API_VISUALS_VISUAL_PROPERTIES_DEVEL_H
index 5681016..8010118 100644 (file)
@@ -23,6 +23,7 @@
 #include <dali/integration-api/debug.h>
 
 //INTERNAL HEARDER
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
 #include <dali-toolkit/public-api/visuals/visual-properties.h>
 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
@@ -64,6 +65,7 @@ void Base::SetCustomShader( const Property::Map& shaderMap )
 
 void Base::Initialize( Actor& actor, const Property::Map& propertyMap )
 {
+
   Property::Value* customShaderValue = propertyMap.Find( Toolkit::Visual::Property::SHADER, CUSTOM_SHADER );
   if( customShaderValue )
   {
@@ -74,6 +76,16 @@ void Base::Initialize( Actor& actor, const Property::Map& propertyMap )
     }
   }
 
+  Property::Value* premultipliedAlphaValue = propertyMap.Find( Toolkit::DevelVisual::Property::PREMULTIPLIED_ALPHA, PREMULTIPLIED_ALPHA );
+  if( premultipliedAlphaValue )
+  {
+    bool premultipliedAlpha( false );
+    if( premultipliedAlphaValue->Get( premultipliedAlpha ) )
+    {
+      EnablePreMultipliedAlpha( premultipliedAlpha );
+    }
+  }
+
   DoInitialize( actor, propertyMap );
 }
 
@@ -138,7 +150,7 @@ void Base::SetOffStage( Actor& actor )
 
 void Base::EnablePreMultipliedAlpha( bool preMultipled )
 {
-  if(preMultipled)
+  if( preMultipled )
   {
     mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
   }
@@ -172,6 +184,9 @@ void Base::CreatePropertyMap( Property::Map& map ) const
   {
     mImpl->mCustomShader->CreatePropertyMap( map );
   }
+
+  bool premultipliedAlpha( IsPreMultipliedAlphaEnabled() );
+  map.Insert( DevelVisual::Property::PREMULTIPLIED_ALPHA, premultipliedAlpha );
 }
 
 bool Base::GetIsOnStage() const
index a224124..07831a0 100644 (file)
@@ -35,6 +35,9 @@ const char * const CUSTOM_SUBDIVIDE_GRID_X( "subdivideGridX" );
 const char * const CUSTOM_SUBDIVIDE_GRID_Y( "subdivideGridY" );
 const char * const CUSTOM_SHADER_HINTS( "hints" );
 
+// Premultipled alpha
+extern const char * const PREMULTIPLIED_ALPHA( "premultipliedAlpha" );
+
 // Image visual
 const char * const IMAGE_URL_NAME("url");
 const char * const ATLAS_RECT_UNIFORM_NAME ( "uAtlasRect" );
index efb0354..aacfa87 100644 (file)
@@ -35,6 +35,9 @@ extern const char * const CUSTOM_SUBDIVIDE_GRID_X;
 extern const char * const CUSTOM_SUBDIVIDE_GRID_Y;
 extern const char * const CUSTOM_SHADER_HINTS;
 
+// Premultiplied alpha
+extern const char * const PREMULTIPLIED_ALPHA;
+
 // Image visual
 extern const char * const IMAGE_URL_NAME;
 extern const char * const ATLAS_RECT_UNIFORM_NAME;
index b6ea20b..e4321cb 100644 (file)
 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
 #include <dali-toolkit/internal/styling/style-manager-impl.h>
 #include <dali-toolkit/internal/visuals/color/color-visual.h>
+#include <dali-toolkit/internal/visuals/visual-string-constants.h>
+#include <dali-toolkit/internal/visuals/visual-base-impl.h>
 
 namespace Dali
 {
@@ -457,11 +460,25 @@ Vector4 Control::GetBackgroundColor() const
 void Control::SetBackground( const Property::Map& map )
 {
   Actor self( Self() );
-  InitializeVisual( self, mImpl->mBackgroundVisual, map );
-  if( mImpl->mBackgroundVisual )
+  Toolkit::Visual::Base backgroundVisual;
+  InitializeVisual( self, backgroundVisual, map );
+
+  // if new visual created, replace existing one
+  if( backgroundVisual )
   {
+    mImpl->mBackgroundVisual = backgroundVisual;
     mImpl->mBackgroundVisual.SetDepthIndex( DepthIndex::BACKGROUND );
   }
+  // ...otherwise process map and apply it to the existing visual
+  else if( mImpl->mBackgroundVisual )
+  {
+    Property::Value* premultipliedAlpha = map.Find( Toolkit::DevelVisual::Property::PREMULTIPLIED_ALPHA, Toolkit::Internal::PREMULTIPLIED_ALPHA );
+    if( premultipliedAlpha )
+    {
+      bool value( premultipliedAlpha->Get<bool>() );
+      Toolkit::GetImplementation( mImpl->mBackgroundVisual ).EnablePreMultipliedAlpha( value );
+    }
+  }
 }
 
 void Control::SetBackgroundImage( Image image )