Disable texture atlas in svg visual
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / svg / svg-visual.h
1 #ifndef DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_SVG_VISUAL_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 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/intrusive-ptr.h>
23 #include <dali/public-api/object/weak-handle.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
27 #include <dali-toolkit/internal/visuals/visual-url.h>
28
29 struct NSVGimage;
30
31 namespace Dali
32 {
33
34 namespace Toolkit
35 {
36
37 namespace Internal
38 {
39
40 class SvgVisual;
41 typedef IntrusivePtr< SvgVisual > SvgVisualPtr;
42
43 /**
44  * The visual which renders a svg image
45  *
46  * The following property is essential
47  *
48  * | %Property Name           | Type             |
49  * |--------------------------|------------------|
50  * | url                      | STRING           |
51  *
52  */
53 class SvgVisual: public Visual::Base
54 {
55 public:
56
57   /**
58    * @brief Create the SVG Visual using the image URL.
59    *
60    * The visual will parse the SVG image once it is set.
61    * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage
62    *
63    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
64    * @param[in] imageUrl The URL to svg resource to use
65    * @param[in] properties A Property::Map containing settings for this visual
66    * @return A smart-pointer to the newly allocated visual.
67    */
68   static SvgVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties );
69
70   /**
71    * @brief Create the SVG Visual using the image URL.
72    *
73    * The visual will parse the SVG image once it is set.
74    * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage
75    *
76    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
77    * @param[in] imageUrl The URL to svg resource to use
78    * @return A smart-pointer to the newly allocated visual.
79    */
80   static SvgVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl );
81
82 public:  // from Visual
83
84   /**
85    * @copydoc Visual::Base::GetNaturalSize
86    */
87   virtual void GetNaturalSize( Vector2& naturalSize );
88
89   /**
90    * @copydoc Visual::Base::CreatePropertyMap
91    */
92   virtual void DoCreatePropertyMap( Property::Map& map ) const;
93
94   /**
95    * @copydoc Visual::Base::CreateInstancePropertyMap
96    */
97   virtual void DoCreateInstancePropertyMap( Property::Map& map ) const;
98
99 protected:
100
101   /**
102    * @brief Constructor.
103    *
104    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
105    */
106   SvgVisual( VisualFactoryCache& factoryCache );
107
108   /**
109    * @brief A reference counted object may only be deleted by calling Unreference().
110    */
111   virtual ~SvgVisual();
112
113   /**
114    * @copydoc Visual::Base::DoSetProperties
115    */
116   virtual void DoSetProperties( const Property::Map& propertyMap );
117
118   /**
119    * @copydoc Visual::Base::DoSetOnStage
120    */
121   virtual void DoSetOnStage( Actor& actor );
122
123   /**
124    * @copydoc Visual::Base::DoSetOffStage
125    */
126   virtual void DoSetOffStage( Actor& actor );
127
128   /**
129    * @copydoc Visual::Base::OnSetTransform
130    */
131   virtual void OnSetTransform();
132
133 public:
134
135   /**
136    * @bried Apply the rasterized image to the visual.
137    *
138    * @param[in] rasterizedPixelData The pixel buffer with the rasterized pixels
139    */
140   void ApplyRasterizedImage( PixelData rasterizedPixelData );
141
142 private:
143
144   /**
145    * @brief Parses the SVG Image from the set URL.
146    *
147    * @param[in] imageUrl The URL of the image to parse the SVG from.
148    */
149   void ParseFromUrl( const VisualUrl& imageUrl );
150
151   /**
152    * @bried Rasterize the svg with the given size, and add it to the visual.
153    *
154    * @param[in] size The target size of the SVG rasterization.
155    */
156   void AddRasterizationTask( const Vector2& size );
157
158   /**
159    * Helper method to set individual values by index key.
160    * @param[in] index The index key of the value
161    * @param[in] value The value
162    */
163   void DoSetProperty( Property::Index index, const Property::Value& value );
164
165
166   // Undefined
167   SvgVisual( const SvgVisual& svgRenderer );
168
169   // Undefined
170   SvgVisual& operator=( const SvgVisual& svgRenderer );
171
172 private:
173   Vector4              mAtlasRect;
174   VisualUrl            mImageUrl;
175   NSVGimage*           mParsedImage;
176   WeakHandle<Actor>    mPlacementActor;
177   Vector2              mVisualSize;
178   bool                 mAttemptAtlasing;  ///< If true will attempt atlasing, otherwise create unique texture
179 };
180
181 } // namespace Internal
182
183 } // namespace Toolkit
184
185 } // namespace Dali
186
187 #endif /* DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H */