X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fnpatch%2Fnpatch-visual.h;h=e89d9e00a08d74868638ace87edd7f72df7edcd4;hp=0a0465fe5101fc6b7645273c87d6fb71a7cbddc7;hb=ab447436de92a2e8bc8cd1393f4807f19ef6b316;hpb=fb545906ceea3a2946c8a451f34ea7da283c4ffe diff --git a/dali-toolkit/internal/visuals/npatch/npatch-visual.h b/dali-toolkit/internal/visuals/npatch/npatch-visual.h index 0a0465f..e89d9e0 100644 --- a/dali-toolkit/internal/visuals/npatch/npatch-visual.h +++ b/dali-toolkit/internal/visuals/npatch/npatch-visual.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_INTERNAL_N_PATCH_VISUAL_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. @@ -20,15 +20,17 @@ // EXTERNAL INCLUDES #include -#include #include -#include #include #include #include +#include // INTERNAL INCLUDES +#include +#include #include +#include namespace Dali { @@ -38,7 +40,7 @@ namespace Toolkit namespace Internal { - +class ImageVisualShaderFactory; class NPatchVisual; typedef IntrusivePtr< NPatchVisual > NPatchVisualPtr; @@ -50,24 +52,26 @@ typedef IntrusivePtr< NPatchVisual > NPatchVisualPtr; * | %Property Name | Type | * |--------------------------|------------------| * | url | STRING | - * | borderOnly | BOOLEAN - * + * | borderOnly | BOOLEAN | + * | border | RECTANGLE | + * | auxiliaryImage | STRING | + * | auxiliaryImageAlpha | FLOAT | */ -class NPatchVisual: public Visual::Base +class NPatchVisual: public Visual::Base, public TextureUploadObserver { public: - /** * @brief Create an N-patch visual using an image URL. * * The visual will load the image synchronously when the associated actor is put on stage, and destroy the image 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 9 patch image resource to use * @param[in] properties A Property::Map containing settings for this visual * @return A smart-pointer to the newly allocated visual. */ - static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl, const Property::Map& properties ); + static NPatchVisualPtr New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties); /** * @brief Create an N-patch visual using an image URL. @@ -75,30 +79,28 @@ public: * The visual will load the image synchronously when the associated actor is put on stage, and destroy the image 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 9 patch image resource to use * @return A smart-pointer to the newly allocated visual. */ - static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl ); - - /** - * @brief Create an N-patch visual with a NinePatchImage resource. - * - * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object - * @param[in] image The NinePatchImage to use - */ - static NPatchVisualPtr New( VisualFactoryCache& factoryCache, NinePatchImage image ); + static NPatchVisualPtr 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 + */ + void DoCreateInstancePropertyMap( Property::Map& map ) const override; protected: @@ -107,7 +109,7 @@ protected: * * @param[in] factoryCache Reference to the VisualFactoryCache object */ - NPatchVisual( VisualFactoryCache& factoryCache ); + NPatchVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory); /** * @brief A reference counted object may only be deleted by calling Unreference(). @@ -115,28 +117,38 @@ protected: virtual ~NPatchVisual(); /** + * @copydoc Visual::Base::OnInitialize + */ + void OnInitialize() override; + + /** * @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; private: /** + * Loads the NPatch image and the Auxiliary image if needed + */ + void LoadImages(); + + /** * @brief Creates a geometry for this renderer's grid size * * @return Returns the created geometry for this renderer's grid size @@ -193,13 +205,41 @@ private: */ Geometry CreateBorderGeometry( Uint16Pair gridSize ); + /** + * @brief Creates a renderer by using loaded resource. + */ + void SetResource(); + private: - NPatchLoader& mLoader; ///< reference to N patch loader for fast access - std::string mImageUrl; ///< The url to the N patch to load - std::size_t mId; ///< id of the N patch (from loader/cache) - bool mBorderOnly; ///< if only border is desired + /** + * @copydoc TextureUploadObserver::UploadCompleted + * + * To avoid rendering garbage pixels, renderer should be added to actor after the resources are ready. + * This callback is the place to add the renderer as it would be called once the loading is finished. + */ + void UploadComplete( bool loadSuccess, int32_t textureId, TextureSet textureSet, bool useAtlasing, const Vector4& atlasRect, bool preMultiplied ) override; + + /** + * @copydoc TextureUploadObserver::LoadComplete + * + * To avoid rendering garbage pixels, renderer should be added to actor after the resources are ready. + * This callback is the place to add the renderer as it would be called once the loading is finished. + */ + void LoadComplete( bool loadSuccess, Devel::PixelBuffer pixelBuffer, const VisualUrl& url, bool preMultiplied ) override; +private: + WeakHandle mPlacementActor; ///< Weakhandle to contain Actor during texture loading + NPatchLoader& mLoader; ///< reference to N patch loader for fast access + ImageVisualShaderFactory& mImageVisualShaderFactory; + VisualUrl mImageUrl; ///< The url to the N patch to load + VisualUrl mAuxiliaryUrl; ///< An auxiliary image that can be displayed on top of the N-Patch + NPatchData::NPatchDataId mId; ///< id of the N patch (from loader/cache) + Devel::PixelBuffer mAuxiliaryPixelBuffer; ///< pixel buffer of the auxiliary mask image + bool mBorderOnly; ///< if only border is desired + Rect mBorder; ///< The size of the border + float mAuxiliaryImageAlpha; ///< The alpha value for the auxiliary image only + Toolkit::ImageVisual::ReleasePolicy::Type mReleasePolicy; ///< The release policy to determine when an image should no longer be cached. }; } // namespace Internal