SvgVisual: Using VectorImageRenderer
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / svg / svg-visual.h
index 0bce4b0..0f1dc95 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H
 
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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.
@@ -26,7 +26,9 @@
 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
 #include <dali-toolkit/internal/visuals/visual-url.h>
 
+#ifdef NO_THORVG
 struct NSVGimage;
+#endif /* NO_THORVG */
 
 namespace Dali
 {
@@ -37,6 +39,7 @@ namespace Toolkit
 namespace Internal
 {
 
+class ImageVisualShaderFactory;
 class SvgVisual;
 typedef IntrusivePtr< SvgVisual > SvgVisualPtr;
 
@@ -61,11 +64,12 @@ public:
    * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage
    *
    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
+   * @param[in] shaderFactory The ImageVisualShaderFactory object
    * @param[in] imageUrl The URL to svg resource to use
    * @param[in] properties A Property::Map containing settings for this visual
    * @return A smart-pointer to the newly allocated visual.
    */
-  static SvgVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties );
+  static SvgVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties );
 
   /**
    * @brief Create the SVG Visual using the image URL.
@@ -74,27 +78,28 @@ public:
    * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage
    *
    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
+   * @param[in] shaderFactory The ImageVisualShaderFactory object
    * @param[in] imageUrl The URL to svg resource to use
    * @return A smart-pointer to the newly allocated visual.
    */
-  static SvgVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl );
+  static SvgVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl );
 
 public:  // from Visual
 
   /**
    * @copydoc Visual::Base::GetNaturalSize
    */
-  virtual void GetNaturalSize( Vector2& naturalSize );
+  void GetNaturalSize( Vector2& naturalSize ) override;
 
   /**
    * @copydoc Visual::Base::CreatePropertyMap
    */
-  virtual void DoCreatePropertyMap( Property::Map& map ) const;
+  void DoCreatePropertyMap( Property::Map& map ) const override;
 
   /**
    * @copydoc Visual::Base::CreateInstancePropertyMap
    */
-  virtual void DoCreateInstancePropertyMap( Property::Map& map ) const;
+  void DoCreateInstancePropertyMap( Property::Map& map ) const override;
 
 protected:
 
@@ -102,8 +107,10 @@ protected:
    * @brief Constructor.
    *
    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
+   * @param[in] shaderFactory The ImageVisualShaderFactory object
+   * @param[in] imageUrl The URL to svg resource to use
    */
-  SvgVisual( VisualFactoryCache& factoryCache );
+  SvgVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl );
 
   /**
    * @brief A reference counted object may only be deleted by calling Unreference().
@@ -113,40 +120,63 @@ protected:
   /**
    * @copydoc Visual::Base::DoSetProperties
    */
-  virtual void DoSetProperties( const Property::Map& propertyMap );
+  void DoSetProperties( const Property::Map& propertyMap ) override;
 
   /**
-   * @copydoc Visual::Base::DoSetOnStage
+   * @copydoc Visual::Base::DoSetOnScene
    */
-  virtual void DoSetOnStage( Actor& actor );
+  void DoSetOnScene( Actor& actor ) override;
 
   /**
-   * @copydoc Visual::Base::DoSetOffStage
+   * @copydoc Visual::Base::DoSetOffScene
    */
-  virtual void DoSetOffStage( Actor& actor );
+  void DoSetOffScene( Actor& actor ) override;
 
   /**
    * @copydoc Visual::Base::OnSetTransform
    */
-  virtual void OnSetTransform();
+  void OnSetTransform() override;
+
+  /**
+   * @copydoc Visual::Base::IsResourceReady
+   */
+  bool IsResourceReady() const override;
 
 public:
 
+#ifdef NO_THORVG
   /**
    * @bried Apply the rasterized image to the visual.
    *
+   * @param[in] parsedSvg The data of parsed image.
    * @param[in] rasterizedPixelData The pixel buffer with the rasterized pixels
    */
-  void ApplyRasterizedImage( PixelData rasterizedPixelData );
-
-private:
-
+  void ApplyRasterizedImage( NSVGimage* parsedSvg, PixelData rasterizedPixelData );
+#else /* NO_THORVG */
   /**
-   * @brief Parses the SVG Image from the set URL.
+   * @bried Apply the rasterized image to the visual.
    *
-   * @param[in] imageUrl The URL of the image to parse the SVG from.
+   * @param[in] vectorImage The data of vector image.
+   * @param[in] rasterizedPixelData The pixel buffer with the rasterized pixels
+   * @param[in] bool Whether the resource is loaded
    */
-  void ParseFromUrl( const VisualUrl& imageUrl );
+  void ApplyRasterizedImage( VectorImageRenderer vectorImage, PixelData rasterizedPixelData, bool isLoaded );
+#endif /* NO_THORVG */
+
+private:
+#ifdef NO_THORVG
+  /**
+    * @brief Parses the SVG Image from the set URL.
+    *
+    * @param[in] imageUrl The URL of the image to parse the SVG from.
+    */
+   void ParseFromUrl( const VisualUrl& imageUrl );
+#else /* NO_THORVG */
+  /**
+    * @brief Load the SVG Image from the set URL.
+    */
+   void Load();
+#endif /* NO_THORVG */
 
   /**
    * @bried Rasterize the svg with the given size, and add it to the visual.
@@ -155,6 +185,12 @@ private:
    */
   void AddRasterizationTask( const Vector2& size );
 
+  /**
+   * Helper method to set individual values by index key.
+   * @param[in] index The index key of the value
+   * @param[in] value The value
+   */
+  void DoSetProperty( Property::Index index, const Property::Value& value );
 
   // Undefined
   SvgVisual( const SvgVisual& svgRenderer );
@@ -163,11 +199,21 @@ private:
   SvgVisual& operator=( const SvgVisual& svgRenderer );
 
 private:
-  Vector4              mAtlasRect;
-  VisualUrl            mImageUrl;
-  NSVGimage*           mParsedImage;
-  WeakHandle<Actor>    mPlacementActor;
-  Vector2              mVisualSize;
+  ImageVisualShaderFactory& mImageVisualShaderFactory;
+  Vector4                   mAtlasRect;
+  VisualUrl                 mImageUrl;
+#ifdef NO_THORVG
+  NSVGimage*                mParsedImage;
+#else /* NO_THORVG */
+  VectorImageRenderer       mVectorRenderer;
+  uint32_t                  mDefaultWidth;
+  uint32_t                  mDefaultHeight;
+  bool                      mLoaded;
+  bool                      mLocalResource;
+#endif /* NO_THORVG */
+  WeakHandle<Actor>         mPlacementActor;
+  Vector2                   mVisualSize;
+  bool                      mAttemptAtlasing;  ///< If true will attempt atlasing, otherwise create unique texture
 };
 
 } // namespace Internal