#define DALI_TOOLKIT_VISUAL_FACTORY_CACHE_H
/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
* limitations under the License.
*/
-// INTERNAL INCLUDES
-#include "svg/svg-rasterize-thread.h"
-
// EXTERNAL INCLUDES
#include <dali/public-api/math/uint-16-pair.h>
#include <dali/public-api/object/ref-object.h>
#include <dali/public-api/rendering/geometry.h>
-#include <dali/public-api/rendering/renderer.h>
#include <dali/public-api/rendering/shader.h>
#include <dali/devel-api/common/owner-container.h>
-#include <dali/devel-api/object/weak-handle.h>
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/visuals/npatch-loader.h>
+#include <dali-toolkit/internal/visuals/svg/svg-rasterize-thread.h>
+#include <dali-toolkit/internal/visuals/texture-manager-impl.h>
namespace Dali
{
namespace Internal
{
-
class ImageAtlasManager;
+class NPatchLoader;
+class TextureManager;
+
typedef IntrusivePtr<ImageAtlasManager> ImageAtlasManagerPtr;
+
/**
* Caches shaders and geometries. Owned by VisualFactory.
*/
-class VisualFactoryCache : public RefObject
+class VisualFactoryCache
{
public:
GRADIENT_SHADER_RADIAL_USER_SPACE,
GRADIENT_SHADER_RADIAL_BOUNDING_BOX,
IMAGE_SHADER,
- BATCH_IMAGE_SHADER,
IMAGE_SHADER_ATLAS_DEFAULT_WRAP,
IMAGE_SHADER_ATLAS_CUSTOM_WRAP,
NINE_PATCH_SHADER,
+ NINE_PATCH_MASK_SHADER,
SVG_SHADER,
- SHADER_TYPE_MAX = SVG_SHADER
+ TEXT_SHADER_MULTI_COLOR_TEXT,
+ TEXT_SHADER_MULTI_COLOR_TEXT_WITH_STYLE,
+ TEXT_SHADER_SINGLE_COLOR_TEXT,
+ TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE,
+ TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_EMOJI,
+ TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE_AND_EMOJI,
+ ANIMATED_GRADIENT_SHADER_LINEAR_BOUNDING_REFLECT,
+ ANIMATED_GRADIENT_SHADER_LINEAR_BOUNDING_REPEAT,
+ ANIMATED_GRADIENT_SHADER_LINEAR_BOUNDING_CLAMP,
+ ANIMATED_GRADIENT_SHADER_LINEAR_USER_REFLECT,
+ ANIMATED_GRADIENT_SHADER_LINEAR_USER_REPEAT,
+ ANIMATED_GRADIENT_SHADER_LINEAR_USER_CLAMP,
+ ANIMATED_GRADIENT_SHADER_RADIAL_BOUNDING_REFLECT,
+ ANIMATED_GRADIENT_SHADER_RADIAL_BOUNDING_REPEAT,
+ ANIMATED_GRADIENT_SHADER_RADIAL_BOUNDING_CLAMP,
+ ANIMATED_GRADIENT_SHADER_RADIAL_USER_REFLECT,
+ ANIMATED_GRADIENT_SHADER_RADIAL_USER_REPEAT,
+ ANIMATED_GRADIENT_SHADER_RADIAL_USER_CLAMP,
+ WIREFRAME_SHADER,
+ SHADER_TYPE_MAX = WIREFRAME_SHADER
};
/**
BORDER_GEOMETRY,
NINE_PATCH_GEOMETRY,
NINE_PATCH_BORDER_GEOMETRY,
- GEOMETRY_TYPE_MAX = NINE_PATCH_BORDER_GEOMETRY
+ WIREFRAME_GEOMETRY,
+ GEOMETRY_TYPE_MAX = WIREFRAME_GEOMETRY
};
public:
/**
* @brief Constructor
+ *
+ * @param[in] preMultiplyOnLoad True if image visuals should pre-multiply alpha on image load.
+ */
+ VisualFactoryCache( bool preMultiplyOnLoad );
+
+ /**
+ * @brief Destructor
*/
- VisualFactoryCache();
+ ~VisualFactoryCache();
/**
* Request geometry of the given type.
static Geometry CreateGridGeometry( Uint16Pair gridSize );
/**
- * Create the batchable geometry
- * @param[in] texCoords The texture atlas rect coordinates
- * @return The created batchable geometry
- */
- static Geometry CreateBatchQuadGeometry( Vector4 texCoords );
-
- /**
* @brief Returns an image to be used when a visual has failed to correctly render
* @return The broken image handle.
*/
- static Image GetBrokenVisualImage();
-
-public:
+ Image GetBrokenVisualImage();
/**
- * @brief Request renderer from the url
- *
- * @return The cached renderer if exist in the cache. Otherwise an empty handle is returned.
+ * @copydoc Toolkit::VisualFactory::SetPreMultiplyOnLoad()
*/
- Renderer GetRenderer( const std::string& key ) const;
+ void SetPreMultiplyOnLoad( bool preMultiply );
/**
- * @brief Cache the renderer based on the given key.
- *
- * If the key already exists in the cache, then the cache will save an additional renderer to the cache.
- * RemoveRenderer will then need to be called twice to remove both items from the cache.
- *
- * @param[in] key The key to use for caching
- * @param[in] renderer The Renderer to be cached
+ * @copydoc Toolkit::VisualFactory::GetPreMultiplyOnLoad()
*/
- void SaveRenderer( const std::string& key, Renderer& renderer );
+ bool GetPreMultiplyOnLoad();
/**
- * @brief Cleans the renderer cache by removing the renderer from the cache based on the given key if there are no longer any references to it
- *
- * @param[in] key The key used for caching
- *
- * @return True if the renderer is no longer used anywhere, false otherwise
+ * @brief Set an image to be used when a visual has failed to correctly render
+ * @param[in] brokenImageUrl The broken image url.
*/
- bool CleanRendererCache( const std::string& key );
+ void SetBrokenImageUrl(const std::string& brokenImageUrl);
+public:
/**
- * @brief Cache the debug renderer
+ * Get the image atlas manager.
+ * @return A pointer to the atlas manager
*/
- void CacheDebugRenderer( Renderer& renderer );
+ ImageAtlasManagerPtr GetAtlasManager();
/**
- * @brief Request the debug renderer;
+ * Get the texture manager
+ * @return A reference to the texture manager
*/
- Renderer GetDebugRenderer();
+ TextureManager& GetTextureManager();
/**
- * Get the image atlas manager.
- * @return A pointer pointing to the atlas manager
+ * Get the N-Patch texture cache.
+ * @return A reference to the N patch loader
*/
- ImageAtlasManagerPtr GetAtlasManager();
+ NPatchLoader& GetNPatchLoader();
/**
* Get the SVG rasterization thread.
- * @return A pointer pointing to the SVG rasterization thread.
+ * @return A raw pointer pointing to the SVG rasterization thread.
*/
SvgRasterizeThread* GetSVGRasterizationThread();
protected:
/**
- * A reference counted object may only be deleted by calling Unreference()
- */
- virtual ~VisualFactoryCache();
-
- /**
* Undefined copy constructor.
*/
VisualFactoryCache(const VisualFactoryCache&);
VisualFactoryCache& operator=(const VisualFactoryCache& rhs);
private:
- struct CachedRenderer
- {
- std::string mKey;
- WeakHandle< Renderer > mRenderer;
-
- CachedRenderer( const std::string& key, Renderer& renderer )
- : mKey( key ),
- mRenderer( renderer)
- {}
- };
-
- typedef Dali::Vector< std::size_t > HashVector;
- typedef Dali::OwnerContainer< const CachedRenderer* > CachedRenderers;
-
- /**
- * @brief Finds the first index into the cached visuals from the url
- *
- * @return Returns the first index into the cached renderer from the url if it exists in the cache, otherwise returns -1
- */
- int FindRenderer( const std::string& key ) const;
-
-private:
Geometry mGeometry[GEOMETRY_TYPE_MAX+1];
Shader mShader[SHADER_TYPE_MAX+1];
- HashVector mRendererHashes;
- CachedRenderers mRenderers;
-
- Renderer mDebugRenderer;
-
ImageAtlasManagerPtr mAtlasManager;
+ TextureManager mTextureManager;
+ NPatchLoader mNPatchLoader;
SvgRasterizeThread* mSvgRasterizeThread;
+ std::string mBrokenImageUrl;
+ bool mPreMultiplyOnLoad;
};
} // namespace Internal