2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-toolkit/internal/visuals/visual-factory-impl.h>
21 #include <dali/integration-api/debug.h>
22 #include <dali/public-api/images/image.h>
23 #include <dali/public-api/object/property-array.h>
24 #include <dali/public-api/object/type-registry.h>
25 #include <dali/public-api/object/type-registry-helper.h>
26 #include <dali/devel-api/scripting/scripting.h>
29 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
30 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
31 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
32 #include <dali-toolkit/internal/visuals/border/border-visual.h>
33 #include <dali-toolkit/internal/visuals/color/color-visual.h>
34 #include <dali-toolkit/internal/visuals/gradient/gradient-visual.h>
35 #include <dali-toolkit/internal/visuals/image/batch-image-visual.h>
36 #include <dali-toolkit/internal/visuals/image/image-visual.h>
37 #include <dali-toolkit/internal/visuals/mesh/mesh-visual.h>
38 #include <dali-toolkit/internal/visuals/npatch/npatch-visual.h>
39 #include <dali-toolkit/internal/visuals/primitive/primitive-visual.h>
40 #include <dali-toolkit/internal/visuals/svg/svg-visual.h>
41 #include <dali-toolkit/internal/visuals/text/text-visual.h>
42 #include <dali-toolkit/internal/visuals/animated-image/animated-image-visual.h>
43 #include <dali-toolkit/internal/visuals/wireframe/wireframe-visual.h>
44 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
45 #include <dali-toolkit/internal/visuals/visual-factory-resolve-url.h>
46 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
60 const char * const BATCHING_ENABLED( "batchingEnabled" );
63 BaseHandle handle = Toolkit::VisualFactory::Get();
68 DALI_TYPE_REGISTRATION_BEGIN_CREATE( Toolkit::VisualFactory, Dali::BaseHandle, Create, true )
69 DALI_TYPE_REGISTRATION_END()
73 VisualFactory::VisualFactory( bool debugEnabled )
74 :mDebugEnabled( debugEnabled )
78 VisualFactory::~VisualFactory()
82 Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& propertyMap )
84 // Create factory cache if it hasn't already been
87 mFactoryCache = new VisualFactoryCache();
90 Visual::BasePtr visualPtr;
92 Property::Value* typeValue = propertyMap.Find( Toolkit::DevelVisual::Property::TYPE, VISUAL_TYPE );
93 Toolkit::DevelVisual::Type visualType = Toolkit::DevelVisual::IMAGE; // Default to IMAGE type.
96 Scripting::GetEnumerationProperty( *typeValue, VISUAL_TYPE_TABLE, VISUAL_TYPE_TABLE_COUNT, visualType );
101 case Toolkit::Visual::BORDER:
103 visualPtr = BorderVisual::New( *( mFactoryCache.Get() ), propertyMap );
107 case Toolkit::Visual::COLOR:
109 visualPtr = ColorVisual::New( *( mFactoryCache.Get() ), propertyMap );
113 case Toolkit::Visual::GRADIENT:
115 visualPtr = GradientVisual::New( *( mFactoryCache.Get() ), propertyMap );
119 case Toolkit::Visual::IMAGE:
121 Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
122 std::string imageUrl;
123 if( imageURLValue && imageURLValue->Get( imageUrl ) )
125 // first resolve url type to know which visual to create
126 UrlType::Type type = ResolveUrlType( imageUrl );
127 if( UrlType::N_PATCH == type )
129 visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
131 else if( UrlType::SVG == type )
133 visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
135 else if( UrlType::GIF == type )
137 visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
139 else // Regular image
141 bool batchingEnabled( false );
142 Property::Value* batchingEnabledValue = propertyMap.Find( Toolkit::ImageVisual::Property::BATCHING_ENABLED, BATCHING_ENABLED );
143 if( batchingEnabledValue )
145 batchingEnabledValue->Get( batchingEnabled );
148 if( batchingEnabled )
150 visualPtr = BatchImageVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
154 visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
162 case Toolkit::Visual::MESH:
164 visualPtr = MeshVisual::New( *( mFactoryCache.Get() ), propertyMap );
168 case Toolkit::Visual::PRIMITIVE:
170 visualPtr = PrimitiveVisual::New( *( mFactoryCache.Get() ), propertyMap );
174 case Toolkit::Visual::WIREFRAME:
176 visualPtr = WireframeVisual::New( *( mFactoryCache.Get() ), propertyMap );
180 case Toolkit::DevelVisual::TEXT:
182 visualPtr = TextVisual::New( *( mFactoryCache.Get() ), propertyMap );
189 DALI_LOG_ERROR( "Renderer type unknown\n" );
192 if( mDebugEnabled && visualType != Toolkit::DevelVisual::WIREFRAME )
194 //Create a WireframeVisual if we have debug enabled
195 visualPtr = WireframeVisual::New( *( mFactoryCache.Get() ), visualPtr, propertyMap );
198 return Toolkit::Visual::Base( visualPtr.Get() );
201 Toolkit::Visual::Base VisualFactory::CreateVisual( const Image& image )
205 mFactoryCache = new VisualFactoryCache();
208 Visual::BasePtr visualPtr;
210 NinePatchImage npatchImage = NinePatchImage::DownCast( image );
213 visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), npatchImage );
217 visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), image );
222 //Create a WireframeVisual if we have debug enabled
223 visualPtr = WireframeVisual::New( *( mFactoryCache.Get() ), visualPtr );
226 return Toolkit::Visual::Base( visualPtr.Get() );
229 Toolkit::Visual::Base VisualFactory::CreateVisual( const std::string& url, ImageDimensions size )
233 mFactoryCache = new VisualFactoryCache();
236 Visual::BasePtr visualPtr;
238 // first resolve url type to know which visual to create
239 UrlType::Type type = ResolveUrlType( url );
240 if( UrlType::N_PATCH == type )
242 visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), url );
244 else if( UrlType::SVG == type )
246 visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), url );
248 else if( UrlType::GIF == type )
250 visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), url );
252 else // Regular image
254 visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), url, size );
259 //Create a WireframeVisual if we have debug enabled
260 visualPtr = WireframeVisual::New( *( mFactoryCache.Get() ), visualPtr );
263 return Toolkit::Visual::Base( visualPtr.Get() );
266 } // namespace Internal
268 } // namespace Toolkit