[Tizen] Enable masking for Scene3D::SceneView 43/300443/2
authorseungho baek <sbsh.baek@samsung.com>
Wed, 25 Oct 2023 05:45:17 +0000 (14:45 +0900)
committerhuiyu.eun <huiyu.eun@samsung.com>
Wed, 25 Oct 2023 07:47:20 +0000 (16:47 +0900)
Change-Id: Ia725f8a19a96d6020e1247cc49b9568a5f562215
Signed-off-by: seungho baek <sbsh.baek@samsung.com>
dali-scene3d/internal/controls/scene-view/scene-view-impl.cpp
dali-scene3d/internal/controls/scene-view/scene-view-impl.h
dali-scene3d/public-api/controls/scene-view/scene-view.h

index ba8156d..73c7712 100644 (file)
@@ -60,6 +60,10 @@ BaseHandle Create()
 
 // Setup properties, signals and actions using the type-registry.
 DALI_TYPE_REGISTRATION_BEGIN(Scene3D::SceneView, Toolkit::Control, Create);
+
+DALI_PROPERTY_REGISTRATION(Scene3D, SceneView, "AlphaMaskUrl", STRING, ALPHA_MASK_URL)
+DALI_PROPERTY_REGISTRATION(Scene3D, SceneView, "MaskContentScale", FLOAT, MASK_CONTENT_SCALE)
+DALI_PROPERTY_REGISTRATION(Scene3D, SceneView, "CropToMask", BOOLEAN, CROP_TO_MASK)
 DALI_TYPE_REGISTRATION_END()
 
 Property::Index    RENDERING_BUFFER        = Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1;
@@ -791,6 +795,113 @@ void SceneView::UpdateShadowUniform(Scene3D::Light light)
   mShaderManager->UpdateShadowUniform(light);
 }
 
+void SceneView::SetAlphaMaskUrl(std::string& alphaMaskUrl)
+{
+  if(mAlphaMaskUrl != alphaMaskUrl)
+  {
+    mAlphaMaskUrl = alphaMaskUrl;
+    mMaskingPropertyChanged = true;
+    UpdateRenderTask();
+  }
+}
+
+std::string SceneView::GetAlphaMaskUrl()
+{
+  return mAlphaMaskUrl;
+}
+
+void SceneView::SetMaskContentScaleFactor(float maskContentScaleFactor)
+{
+  if(mMaskContentScaleFactor != maskContentScaleFactor)
+  {
+    mMaskContentScaleFactor = maskContentScaleFactor;
+    mMaskingPropertyChanged = true;
+    UpdateRenderTask();
+  }
+}
+
+float SceneView::GetMaskContentScaleFactor()
+{
+  return mMaskContentScaleFactor;
+}
+
+void SceneView::EnableCropToMask(bool enableCropToMask)
+{
+  if(mCropToMask != enableCropToMask)
+  {
+    mCropToMask = enableCropToMask;
+    mMaskingPropertyChanged = true;
+    UpdateRenderTask();
+  }
+}
+
+bool SceneView::IsEnabledCropToMask()
+{
+  return mCropToMask;
+}
+
+void SceneView::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
+{
+  Scene3D::SceneView sceneView = Scene3D::SceneView::DownCast(Dali::BaseHandle(object));
+
+  if(sceneView)
+  {
+    SceneView& sceneViewImpl(GetImpl(sceneView));
+
+    switch(index)
+    {
+      case Scene3D::SceneView::Property::ALPHA_MASK_URL:
+      {
+        std::string alphaMaskUrl = value.Get<std::string>();
+        sceneViewImpl.SetAlphaMaskUrl(alphaMaskUrl);
+        break;
+      }
+      case Scene3D::SceneView::Property::MASK_CONTENT_SCALE:
+      {
+        sceneViewImpl.SetMaskContentScaleFactor(value.Get<float>());
+        break;
+      }
+      case Scene3D::SceneView::Property::CROP_TO_MASK:
+      {
+        sceneViewImpl.EnableCropToMask(value.Get<bool>());
+        break;
+      }
+    }
+  }
+}
+
+Property::Value SceneView::GetProperty(BaseObject* object, Property::Index index)
+{
+  Property::Value value;
+
+  Scene3D::SceneView sceneView = Scene3D::SceneView::DownCast(Dali::BaseHandle(object));
+
+  if(sceneView)
+  {
+    SceneView& sceneViewImpl(GetImpl(sceneView));
+
+    switch(index)
+    {
+      case Scene3D::SceneView::Property::ALPHA_MASK_URL:
+      {
+        value = sceneViewImpl.GetAlphaMaskUrl();
+        break;
+      }
+      case Scene3D::SceneView::Property::MASK_CONTENT_SCALE:
+      {
+        value = sceneViewImpl.GetMaskContentScaleFactor();
+        break;
+      }
+      case Scene3D::SceneView::Property::CROP_TO_MASK:
+      {
+        value = sceneViewImpl.IsEnabledCropToMask();
+        break;
+      }
+    }
+  }
+  return value;
+}
+
 ///////////////////////////////////////////////////////////
 //
 // Private methods
@@ -980,7 +1091,8 @@ void SceneView::UpdateRenderTask()
       Dali::FrameBuffer currentFrameBuffer = mRenderTask.GetFrameBuffer();
       if(!currentFrameBuffer ||
          !Dali::Equals(currentFrameBuffer.GetColorTexture().GetWidth(), size.width) ||
-         !Dali::Equals(currentFrameBuffer.GetColorTexture().GetHeight(), size.height))
+         !Dali::Equals(currentFrameBuffer.GetColorTexture().GetHeight(), size.height) ||
+         mMaskingPropertyChanged)
       {
         mRootLayer.SetProperty(Dali::Actor::Property::COLOR_MODE, ColorMode::USE_OWN_COLOR);
         mRenderTask.ResetViewportGuideActor();
@@ -998,6 +1110,14 @@ void SceneView::UpdateRenderTask()
         imagePropertyMap.Insert(Toolkit::ImageVisual::Property::URL, imageUrl.GetUrl());
         // To flip rendered scene without CameraActor::SetInvertYAxis() to avoid backface culling.
         imagePropertyMap.Insert(Toolkit::ImageVisual::Property::PIXEL_AREA, Vector4(0.0f, 1.0f, 1.0f, -1.0f));
+        imagePropertyMap.Insert(Toolkit::ImageVisual::Property::ALPHA_MASK_URL, mAlphaMaskUrl);
+        if(!mAlphaMaskUrl.empty())
+        {
+          imagePropertyMap.Insert(Toolkit::ImageVisual::Property::MASK_CONTENT_SCALE, mMaskContentScaleFactor);
+          imagePropertyMap.Insert(Toolkit::ImageVisual::Property::CROP_TO_MASK, mCropToMask);
+          imagePropertyMap.Insert(Toolkit::DevelImageVisual::Property::MASKING_TYPE, Toolkit::DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
+        }
+        mMaskingPropertyChanged = false;
         mVisual = Toolkit::VisualFactory::Get().CreateVisual(imagePropertyMap);
 
         Toolkit::DevelControl::RegisterVisual(*this, RENDERING_BUFFER, mVisual);
index 594615a..b3fc14d 100644 (file)
@@ -227,11 +227,65 @@ public:
   Dali::Scene3D::Loader::ShaderManagerPtr GetShaderManager() const;
 
   /**
-   * @brief Update shader uniforms about shadow.
+   * @brief Updates shader uniforms about shadow.
    * @param[in] light Light that makes shadow.
    */
   void UpdateShadowUniform(Scene3D::Light light);
 
+  /**
+   * @brief Sets alpha mask url
+   * @param[in] alphaMaskUrl Url for alpha mask.
+   */
+  void SetAlphaMaskUrl(std::string& alphaMaskUrl);
+
+  /**
+   * @brief Retrieves alpha mask url
+   * @return Alpha mask url.
+   */
+  std::string GetAlphaMaskUrl();
+
+  /**
+   * @brief Sets mask content scale factor
+   * @param[in] maskContentScaleFactor Scale factor for mask content.
+   */
+  void SetMaskContentScaleFactor(float maskContentScaleFactor);
+
+  /**
+   * @brief Retrieves mask content scale factor
+   * @return Scale factor for mask content.
+   */
+  float GetMaskContentScaleFactor();
+
+  /**
+   * @brief Sets whether the rendered result will be crop to mask or not.
+   * @param[in] enableCropToMask True for crop rendered result to mask.
+   */
+  void EnableCropToMask(bool enableCropToMask);
+
+  /**
+   * @brief Retrieves whether the crop to mask is enabled or not.
+   * @return True when rendered result is cropped to mask.
+   */
+  bool IsEnabledCropToMask();
+
+  // Properties
+
+  /**
+   * Called when a property of an object of this type is set.
+   * @param[in] object The object whose property is set.
+   * @param[in] index The property index.
+   * @param[in] value The new property value.
+   */
+  static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
+
+  /**
+   * Called to retrieve a property of an object of this type.
+   * @param[in] object The object whose property is to be retrieved.
+   * @param[in] index The property index.
+   * @return The current value of the property.
+   */
+  static Property::Value GetProperty(BaseObject* object, Property::Index index);
+
 protected:
   /**
    * @brief Constructs a new SceneView.
@@ -371,6 +425,12 @@ private:
   float                                                    mSkyboxIntensity{1.0f};
   uint8_t                                                  mFrameBufferMultiSamplingLevel{4u};
 
+  // Masking
+  std::string mAlphaMaskUrl;
+  float       mMaskContentScaleFactor{1.0f};
+  bool        mCropToMask{true};
+  bool        mMaskingPropertyChanged{false};
+
   // Shader Factory
   Dali::Scene3D::Loader::ShaderManagerPtr mShaderManager;
 
index 4d5857a..1e9e7fa 100644 (file)
@@ -105,6 +105,50 @@ class DALI_SCENE3D_API SceneView : public Dali::Toolkit::Control
 {
 public:
   /**
+   * @brief The start and end property ranges for this control.
+   * @SINCE_1_1.4
+   */
+  enum PropertyRange
+  {
+    PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
+    PROPERTY_END_INDEX   = PROPERTY_START_INDEX + 1000
+  };
+
+  struct Property
+  {
+    enum
+    {
+      /**
+       * @brief URL of a masking image
+       * @details Name "alphaMaskUrl", type Property::STRING, URL of image to apply as
+       * a mask after SceneView is drawn.
+       * @note Alpha masking is only available when framebuffer is used.
+       * @note Optional.
+       */
+      ALPHA_MASK_URL = PROPERTY_START_INDEX,
+
+      /**
+       * @brief The scale factor to apply to the content image before masking
+       * @details Name "maskContentScale", type Property::FLOAT, The scale factor
+       * to apply to the content before masking. Note, scaled result is cropped to
+       * the same size as the alpha mask.
+       * @note Optional.
+       */
+      MASK_CONTENT_SCALE,
+
+      /**
+       * @brief Whether to crop rendered result to mask or scale mask to fit result
+       * @details Name "cropToMask", type Property::BOOLEAN, True if the rendered result should
+       * be cropped to match the mask size, or false if the result should remain the same size.
+       * @note Optional, Default true
+       * @note If this is false, then the mask is scaled to fit the rendered result before being applied.
+       */
+      CROP_TO_MASK,
+    };
+  };
+
+public:
+  /**
    * @brief Create an initialized SceneView.
    *
    * @SINCE_2_1.38