X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fvisual-factory-cache.h;h=418b10ec9ac7f2905b4a33c6b75a9a79cd0b6d83;hb=3c6245ad032678461d6df519db63240016f43ed7;hp=46920c563fab29fb986e80f06d6a70cbd3f11e3c;hpb=257a9991486e4e05335212b21ecc1f5a0aacbc63;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/visuals/visual-factory-cache.h b/dali-toolkit/internal/visuals/visual-factory-cache.h index 46920c5..418b10e 100644 --- a/dali-toolkit/internal/visuals/visual-factory-cache.h +++ b/dali-toolkit/internal/visuals/visual-factory-cache.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_VISUAL_FACTORY_CACHE_H /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 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. @@ -17,51 +17,85 @@ * limitations under the License. */ -// INTERNAL INCLUDES -#include "svg/svg-rasterize-thread.h" - // EXTERNAL INCLUDES +#include #include #include #include -#include #include -#include -#include +// INTERNAL INCLUDES +#include +#include +#include namespace Dali { +class Texture; namespace Toolkit { - namespace Internal { +class ImageAtlasManager; +class NPatchLoader; +class TextureManager; +class VectorAnimationManager; + +typedef IntrusivePtr ImageAtlasManagerPtr; /** * Caches shaders and geometries. Owned by VisualFactory. */ -class VisualFactoryCache : public RefObject +class VisualFactoryCache { public: - /** * Type of shader for caching. */ enum ShaderType { COLOR_SHADER, + COLOR_SHADER_ROUNDED_CORNER, + COLOR_SHADER_BLUR_EDGE, BORDER_SHADER, BORDER_SHADER_ANTI_ALIASING, GRADIENT_SHADER_LINEAR_USER_SPACE, GRADIENT_SHADER_LINEAR_BOUNDING_BOX, GRADIENT_SHADER_RADIAL_USER_SPACE, GRADIENT_SHADER_RADIAL_BOUNDING_BOX, + GRADIENT_SHADER_LINEAR_USER_SPACE_ROUNDED_CORNER, + GRADIENT_SHADER_LINEAR_BOUNDING_BOX_ROUNDED_CORNER, + GRADIENT_SHADER_RADIAL_USER_SPACE_ROUNDED_CORNER, + GRADIENT_SHADER_RADIAL_BOUNDING_BOX_ROUNDED_CORNER, IMAGE_SHADER, + IMAGE_SHADER_ATLAS_DEFAULT_WRAP, + IMAGE_SHADER_ATLAS_CUSTOM_WRAP, + IMAGE_SHADER_ROUNDED_CORNER, NINE_PATCH_SHADER, - SVG_SHADER, - SHADER_TYPE_MAX = SVG_SHADER + NINE_PATCH_MASK_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, + ARC_BUTT_CAP_SHADER, + ARC_ROUND_CAP_SHADER, + SHADER_TYPE_MAX = ARC_ROUND_CAP_SHADER }; /** @@ -73,41 +107,48 @@ public: 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. * @return The geometry of the required type if it exist in the cache. Otherwise, an empty handle is returned. */ - Geometry GetGeometry( GeometryType type ); + Geometry GetGeometry(GeometryType type); /** * Cache the geometry of the give type. * @param[in] type The geometry type. * @param[in] geometry The geometry for caching. */ - void SaveGeometry( GeometryType type, Geometry geometry); + void SaveGeometry(GeometryType type, Geometry geometry); /** * Request shader of the given type. * @return The shader of the required type if it exist in the cache. Otherwise, an empty handle is returned. */ - Shader GetShader( ShaderType type ); + Shader GetShader(ShaderType type); /** * Cache the geometry of the give type. * @param[in] type The geometry type. * @param[in] geometry The geometry for caching. */ - void SaveShader( ShaderType type, Shader shader ); + void SaveShader(ShaderType type, Shader shader); /* * Greate the quad geometry. @@ -120,67 +161,62 @@ public: * @param[in] gridSize The size of the grid. * @return The created grid geometry. */ - static Geometry CreateGridGeometry( Uint16Pair gridSize ); - -public: + static Geometry CreateGridGeometry(Uint16Pair gridSize); /** - * @brief Request renderer from the url - * - * @return The cached renderer if exist in the cache. Otherwise an empty handle is returned. + * @brief Returns a new Texture to use when a visual has failed to correctly render + * @return The broken image texture. */ - Renderer GetRenderer( const std::string& key ) const; + Texture GetBrokenVisualImage(); /** - * @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::SetPreMultiplyOnLoad() */ - void SaveRenderer( const std::string& key, Renderer& renderer ); + void SetPreMultiplyOnLoad(bool preMultiply); /** - * @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 + * @copydoc Toolkit::VisualFactory::GetPreMultiplyOnLoad() */ - bool CleanRendererCache( const std::string& key ); + bool GetPreMultiplyOnLoad(); /** - * @brief Cache the debug renderer + * @brief Set an image to be used when a visual has failed to correctly render + * @param[in] brokenImageUrl The broken image url. */ - void CacheDebugVisual( Renderer& renderer ); + void SetBrokenImageUrl(const std::string& brokenImageUrl); +public: /** - * @brief Request the debug renderer; + * Get the image atlas manager. + * @return A pointer to the atlas manager */ - Renderer GetDebugVisual(); + ImageAtlasManagerPtr GetAtlasManager(); /** - * Get the SVG rasterization thread. - * @return A pointer pointing to the SVG rasterization thread. + * Get the texture manager + * @return A reference to the texture manager */ - SvgRasterizeThread* GetSVGRasterizationThread(); - -private: // for svg rasterization thread + TextureManager& GetTextureManager(); /** - * Applies the rasterized image to material + * Get the N-Patch texture cache. + * @return A reference to the N patch loader */ - void ApplyRasterizedSVGToSampler(); + NPatchLoader& GetNPatchLoader(); -protected: + /** + * Get the SVG rasterization thread. + * @return A raw pointer pointing to the SVG rasterization thread. + */ + SvgRasterizeThread* GetSVGRasterizationThread(); /** - * A reference counted object may only be deleted by calling Unreference() + * Get the vector animation manager. + * @return A reference to the vector animation manager. */ - virtual ~VisualFactoryCache(); + VectorAnimationManager& GetVectorAnimationManager(); +protected: /** * Undefined copy constructor. */ @@ -192,37 +228,17 @@ protected: 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 mDebugVisual; - - SvgRasterizeThread* mSvgRasterizeThread; + Geometry mGeometry[GEOMETRY_TYPE_MAX + 1]; + Shader mShader[SHADER_TYPE_MAX + 1]; + + ImageAtlasManagerPtr mAtlasManager; + TextureManager mTextureManager; + NPatchLoader mNPatchLoader; + Texture mBrokenImageTexture; + SvgRasterizeThread* mSvgRasterizeThread; + std::unique_ptr mVectorAnimationManager; + std::string mBrokenImageUrl; + bool mPreMultiplyOnLoad; }; } // namespace Internal