From 69c3adda75c264d2b0aa452d30fdccaa47bd3034 Mon Sep 17 00:00:00 2001 From: Chu Hoang Date: Wed, 11 Nov 2015 15:36:24 +0000 Subject: [PATCH] Changed ImageActor and to use new renderers and removed ImageAttachement. Added Material::GetTextureSampler and Material::GetTexture methods. Removed DerivedType::RENDERABLE and changed Actor::IsRenderable() method to check the mRenderers instead since ImageActor was the last Actor type to use RENDERABLE. Change-Id: I0cbfe8d47592a77d06ebf720851fe26d2496eb01 --- .../src/dali-devel/utc-Dali-HitTestAlgorithm.cpp | 2 +- automated-tests/src/dali/utc-Dali-ImageActor.cpp | 24 +- automated-tests/src/dali/utc-Dali-ShaderEffect.cpp | 9 +- dali/devel-api/rendering/material.cpp | 16 +- dali/devel-api/rendering/material.h | 24 +- dali/integration-api/profiling.cpp | 4 - .../actor-attachments/image-attachment-impl.cpp | 346 ------------ .../actor-attachments/image-attachment-impl.h | 297 ---------- dali/internal/event/actors/actor-impl.cpp | 1 - dali/internal/event/actors/actor-impl.h | 7 +- dali/internal/event/actors/image-actor-impl.cpp | 618 ++++++++++++++++----- dali/internal/event/actors/image-actor-impl.h | 82 +-- dali/internal/event/effects/shader-effect-impl.cpp | 233 ++++---- dali/internal/event/effects/shader-effect-impl.h | 84 ++- dali/internal/event/effects/shader-factory.cpp | 2 - .../event/events/hit-test-algorithm-impl.cpp | 7 +- dali/internal/event/rendering/material-impl.cpp | 26 +- dali/internal/event/rendering/material-impl.h | 16 +- dali/internal/file.list | 2 - dali/internal/update/manager/update-manager.cpp | 7 - .../scene-graph-image-attachment-debug.h | 49 -- .../scene-graph-image-attachment.cpp | 498 ----------------- .../scene-graph-image-attachment.h | 407 -------------- dali/public-api/actors/image-actor.cpp | 10 +- dali/public-api/actors/image-actor.h | 60 +- dali/public-api/shader-effects/shader-effect.h | 4 +- 26 files changed, 790 insertions(+), 2045 deletions(-) delete mode 100644 dali/internal/event/actor-attachments/image-attachment-impl.cpp delete mode 100644 dali/internal/event/actor-attachments/image-attachment-impl.h delete mode 100644 dali/internal/update/node-attachments/scene-graph-image-attachment-debug.h delete mode 100644 dali/internal/update/node-attachments/scene-graph-image-attachment.cpp delete mode 100644 dali/internal/update/node-attachments/scene-graph-image-attachment.h diff --git a/automated-tests/src/dali-devel/utc-Dali-HitTestAlgorithm.cpp b/automated-tests/src/dali-devel/utc-Dali-HitTestAlgorithm.cpp index ae04a17..633533e 100644 --- a/automated-tests/src/dali-devel/utc-Dali-HitTestAlgorithm.cpp +++ b/automated-tests/src/dali-devel/utc-Dali-HitTestAlgorithm.cpp @@ -387,7 +387,7 @@ int UtcDaliHitTestAlgorithmStencil(void) layer.Add( stencil ); // Create a renderable actor and add that to the layer - Actor layerHitActor = ImageActor::New(); + Actor layerHitActor = ImageActor::New( Dali::BufferImage::WHITE() ); layerHitActor.SetSize( 100.0f, 100.0f ); layerHitActor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); layerHitActor.SetParentOrigin( ParentOrigin::TOP_LEFT ); diff --git a/automated-tests/src/dali/utc-Dali-ImageActor.cpp b/automated-tests/src/dali/utc-Dali-ImageActor.cpp index 2325e19..0bb708c 100644 --- a/automated-tests/src/dali/utc-Dali-ImageActor.cpp +++ b/automated-tests/src/dali/utc-Dali-ImageActor.cpp @@ -151,13 +151,16 @@ int UtcDaliImageActor9Patch(void) ImageActor actor = ImageActor::New(image); actor.SetStyle(ImageActor::STYLE_NINE_PATCH); + DALI_TEST_EQUALS( ImageActor::STYLE_QUAD, actor.GetStyle(), TEST_LOCATION ); //nine patch is deprecated + Vector4 border(0.1,0.2,0.3,0.4); actor.SetNinePatchBorder(border); - DALI_TEST_EQUALS( 0.1f, actor.GetNinePatchBorder().x, TEST_LOCATION ); - DALI_TEST_EQUALS( 0.2f, actor.GetNinePatchBorder().y, TEST_LOCATION ); - DALI_TEST_EQUALS( 0.3f, actor.GetNinePatchBorder().z, TEST_LOCATION ); - DALI_TEST_EQUALS( 0.4f, actor.GetNinePatchBorder().w, TEST_LOCATION ); + //nine patch is deprecated + DALI_TEST_EQUALS( 0.0f, actor.GetNinePatchBorder().x, TEST_LOCATION ); + DALI_TEST_EQUALS( 0.0f, actor.GetNinePatchBorder().y, TEST_LOCATION ); + DALI_TEST_EQUALS( 0.0f, actor.GetNinePatchBorder().z, TEST_LOCATION ); + DALI_TEST_EQUALS( 0.0f, actor.GetNinePatchBorder().w, TEST_LOCATION ); END_TEST; } @@ -792,7 +795,7 @@ int UtcDaliImageGetStyle(void) application.SendNotification(); application.Render(); - DALI_TEST_EQUALS( ImageActor::STYLE_NINE_PATCH, actor.GetStyle(), TEST_LOCATION ); + DALI_TEST_EQUALS( ImageActor::STYLE_QUAD, actor.GetStyle(), TEST_LOCATION ); //nine patch is deprecated END_TEST; } @@ -804,12 +807,15 @@ int UtcDaliImageSetNinePatchBorder(void) ImageActor actor = ImageActor::New(image); actor.SetStyle(ImageActor::STYLE_NINE_PATCH); + DALI_TEST_EQUALS( ImageActor::STYLE_QUAD, actor.GetStyle(), TEST_LOCATION ); //nine patch is deprecated + actor.SetNinePatchBorder(Vector4( 1.0f, 2.0f, 3.0f, 4.0f)); - DALI_TEST_EQUALS( 1.0f, actor.GetNinePatchBorder().x, TEST_LOCATION ); - DALI_TEST_EQUALS( 2.0f, actor.GetNinePatchBorder().y, TEST_LOCATION ); - DALI_TEST_EQUALS( 3.0f, actor.GetNinePatchBorder().z, TEST_LOCATION ); - DALI_TEST_EQUALS( 4.0f, actor.GetNinePatchBorder().w, TEST_LOCATION ); + //nine patch is deprecated + DALI_TEST_EQUALS( 0.0f, actor.GetNinePatchBorder().x, TEST_LOCATION ); + DALI_TEST_EQUALS( 0.0f, actor.GetNinePatchBorder().y, TEST_LOCATION ); + DALI_TEST_EQUALS( 0.0f, actor.GetNinePatchBorder().z, TEST_LOCATION ); + DALI_TEST_EQUALS( 0.0f, actor.GetNinePatchBorder().w, TEST_LOCATION ); END_TEST; } diff --git a/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp b/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp index 47433ad..0f4a088 100644 --- a/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp +++ b/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp @@ -378,11 +378,8 @@ int UtcDaliShaderEffectMethodSetUniformViewport(void) application.SendNotification(); application.Render(); - const Vector2& stageSize(Stage::GetCurrent().GetSize()); - - DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uVec2", Vector2( stageSize.x/2, -stageSize.y/2 ) ) ); - - DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uVec2Dir", Vector2( -1.0f, 2.0f ) ) ); + DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uVec2", Vector2( 0.0f, 0.0f ) ) ); //ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION deprecated + DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uVec2Dir", Vector2( 1.0f, 2.0f ) ) ); //ShaderEffect::COORDINATE_TYPE_VIEWPORT_DIRECTION deprecated // change coordinate types effect.SetUniform( "uVec2", Vector2( 0.1f, 0.2f ), ShaderEffect::COORDINATE_TYPE_DEFAULT ); @@ -397,7 +394,7 @@ int UtcDaliShaderEffectMethodSetUniformViewport(void) DALI_TEST_EQUALS( outValue, Vector2( 0.1f, 0.2f ), TEST_LOCATION ); application.GetGlAbstraction().GetUniformValue( "uVec2Dir", outValue ); - DALI_TEST_EQUALS( outValue, Vector2( stageSize.x *.5f - 1.f, -stageSize.y * .5f + 2.f), TEST_LOCATION ); + DALI_TEST_EQUALS( outValue, Vector2( 1.0f, 2.0f ), TEST_LOCATION ); //ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION deprecated END_TEST; } diff --git a/dali/devel-api/rendering/material.cpp b/dali/devel-api/rendering/material.cpp index 1af8446..7695082 100644 --- a/dali/devel-api/rendering/material.cpp +++ b/dali/devel-api/rendering/material.cpp @@ -118,22 +118,34 @@ void Material::SetTextureSampler( size_t index, Sampler sampler ) GetImplementation(*this).SetTextureSampler( index, samplerPtr ); } +Sampler Material::GetTextureSampler( size_t index ) const +{ + Internal::Sampler* samplerPtr( GetImplementation(*this).GetTextureSampler( index ) ); + return Dali::Sampler( samplerPtr ); +} + void Material::SetTextureUniformName( size_t index, const std::string& uniformName ) { GetImplementation(*this).SetTextureUniformName( index, uniformName ); } -int Material::GetTextureIndex( const std::string& uniformName ) +int Material::GetTextureIndex( const std::string& uniformName ) const { return GetImplementation(*this).GetTextureIndex( uniformName ); } -Image Material::GetTexture( const std::string& uniformName ) +Image Material::GetTexture( const std::string& uniformName ) const { Internal::Image* imagePtr( GetImplementation(*this).GetTexture( uniformName ) ); return Dali::Image( imagePtr ); } +Image Material::GetTexture( size_t index ) const +{ + Internal::Image* imagePtr( GetImplementation(*this).GetTexture( index ) ); + return Dali::Image( imagePtr ); +} + std::size_t Material::GetNumberOfTextures() const { return GetImplementation(*this).GetNumberOfTextures(); diff --git a/dali/devel-api/rendering/material.h b/dali/devel-api/rendering/material.h index f53fcbc..48b5d6c 100644 --- a/dali/devel-api/rendering/material.h +++ b/dali/devel-api/rendering/material.h @@ -163,6 +163,14 @@ public: void SetTextureSampler( size_t index, Sampler sampler ); /** + * @brief Retrieve the sampler of a texture given its texture index + * + * @param[in] index The index of the texture in the array of textures + * @return Returns the sampler of a texture given its texture index + */ + Sampler GetTextureSampler( size_t index ) const; + + /** * @brief Set the uniform name of a given texture * * @param[in] index The index of the texture in the array of textures @@ -170,21 +178,29 @@ public: */ void SetTextureUniformName( size_t index, const std::string& uniformName ); - /* + /** * @brief Retrive the index of a texture given its uniform name * * @param[in] uniformName the uniform name * @returns The index in the array of textures or -1 if the texture is not found */ - int GetTextureIndex( const std::string& uniformName ); + int GetTextureIndex( const std::string& uniformName ) const; - /* + /** * @brief Retrive the texture given its uniform name * * @param[in] uniformName the uniform name * @returns The image in the array of textures corresponding to the uniformName or an empty handle if the texture is not found */ - Image GetTexture( const std::string& uniformName ); + Image GetTexture( const std::string& uniformName ) const; + + /** + * @brief Retrive the texture given its index + * + * @param[in] index The index in the array of textures + * @returns The image in the array of textures corresponding to the index or an empty handle if the texture is not found + */ + Image GetTexture( size_t index ) const; /** * @brief Retrieve the number of textures used by the material diff --git a/dali/integration-api/profiling.cpp b/dali/integration-api/profiling.cpp index d01d274..b86a841 100644 --- a/dali/integration-api/profiling.cpp +++ b/dali/integration-api/profiling.cpp @@ -31,7 +31,6 @@ #include #include -#include #include #include @@ -52,7 +51,6 @@ #include #include -#include #include #include @@ -115,9 +113,7 @@ const int CAMERA_ACTOR_MEMORY_SIZE( sizeof( Internal::SceneGraph::CameraAttachment ) ); const int IMAGE_ACTOR_MEMORY_SIZE( sizeof( Internal::ImageActor ) + - sizeof( Internal::ImageAttachment ) + sizeof( Internal::SceneGraph::Node ) + - sizeof( Internal::SceneGraph::ImageAttachment ) + sizeof( Internal::Render::ImageRenderer )); const int LAYER_MEMORY_SIZE( sizeof( Internal::Layer ) + diff --git a/dali/internal/event/actor-attachments/image-attachment-impl.cpp b/dali/internal/event/actor-attachments/image-attachment-impl.cpp deleted file mode 100644 index 4ebe539..0000000 --- a/dali/internal/event/actor-attachments/image-attachment-impl.cpp +++ /dev/null @@ -1,346 +0,0 @@ -/* - * Copyright (c) 2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// CLASS HEADER -#include - -// INTERNAL INCLUDES -#include -#include -#include -#include -#include -#include - -namespace Dali -{ - -namespace Internal -{ - -ImageAttachmentPtr ImageAttachment::New( EventThreadServices& eventThreadServices, const SceneGraph::Node& parentNode ) -{ - ImageAttachmentPtr attachment( new ImageAttachment( eventThreadServices ) ); - - // Transfer object ownership of scene-object to message - SceneGraph::ImageAttachment* sceneObject = CreateSceneObject(); - AttachToNodeMessage( eventThreadServices.GetUpdateManager(), parentNode, sceneObject ); - - // Keep raw pointer for message passing - attachment->mSceneObject = sceneObject; - - return attachment; -} - -ImageAttachment::ImageAttachment( EventThreadServices& eventThreadServices ) -: RenderableAttachment(eventThreadServices), - mSceneObject(NULL), - mPixelArea(0,0,0,0), - mStyle(Dali::ImageActor::STYLE_QUAD), - mBorder(0.45,0.45,0.1,0.1), - mIsPixelAreaSet(false), - mBorderInPixels(false), - - - mBlendingOptions(), - mSamplerBitfield( ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) ), - mSortModifier( 0.0f ), - mCullFaceMode( CullNone ), - mBlendingMode( BlendingMode::AUTO ), - mShaderEffect() -{ - mImageConnectable.Set( NULL, false ); -} - -ImageAttachment::~ImageAttachment() -{ -} - -void ImageAttachment::SetImage( ImagePtr& image ) -{ - bool onStage = OnStage(); - // keep a reference to Image object - mImageConnectable.Set( image, onStage ); - - // Wait until the scene-graph attachment is connected, before providing resource ID - if ( OnStage() ) - { - unsigned int resourceId = (image) ? image->GetResourceId() : 0u; - - // sceneObject is being used in a separate thread; queue a message to set - SetTextureIdMessage( GetEventThreadServices(), *mSceneObject, resourceId ); - } -} - -ImagePtr ImageAttachment::GetImage() -{ - return mImageConnectable.Get(); -} - -void ImageAttachment::SetPixelArea(const PixelArea& pixelArea) -{ - // check to see if pixel area is actually different, using rect::operator== - if( pixelArea != mPixelArea ) - { - // Cache for public getters - mPixelArea = pixelArea; - mIsPixelAreaSet = true; - - // sceneObject is being used in a separate thread; queue a message to set - SetPixelAreaMessage( GetEventThreadServices(), *mSceneObject, mPixelArea ); - } -} - -void ImageAttachment::ClearPixelArea() -{ - // Cache for public getters - mIsPixelAreaSet = false; - - // sceneObject is being used in a separate thread; queue a message to set - ClearPixelAreaMessage( GetEventThreadServices(), *mSceneObject ); -} - -void ImageAttachment::SetStyle(Style style) -{ - // Cache for public getters - mStyle = style; - - // sceneObject is being used in a separate thread; queue a message to set - SetStyleMessage( GetEventThreadServices(), *mSceneObject, style ); -} - -void ImageAttachment::SetNinePatchBorder(const Vector4& border, bool inPixels) -{ - // Cache for public getters - mBorder = border; - mBorderInPixels = inPixels; - - // sceneObject is being used in a separate thread; queue a message to set - SetNinePatchBorderMessage( GetEventThreadServices(), *mSceneObject, border, inPixels ); -} - -SceneGraph::ImageAttachment* ImageAttachment::CreateSceneObject() -{ - return SceneGraph::ImageAttachment::New( 0u ); -} - -const SceneGraph::ImageAttachment& ImageAttachment::GetSceneObject() const -{ - DALI_ASSERT_DEBUG( mSceneObject != NULL ); - return *mSceneObject; -} - -void ImageAttachment::SetSortModifier(float modifier) -{ - // Cache for actor-side getters - mSortModifier = modifier; - - // attachment is being used in a separate thread; queue a message to set the value & base value - SetSortModifierMessage( GetEventThreadServices(), GetSceneObject(), modifier ); -} - -float ImageAttachment::GetSortModifier() const -{ - // mSortModifier is not animatable; this is the most up-to-date value. - return mSortModifier; -} - -void ImageAttachment::SetCullFace( CullFaceMode mode ) -{ - // Cache for actor-side getters - mCullFaceMode = mode; - - // attachment is being used in a separate thread; queue a message to set the value - SetCullFaceMessage( GetEventThreadServices(), GetSceneObject(), mode ); -} - -CullFaceMode ImageAttachment::GetCullFace() const -{ - // mCullFaceMode is not animatable; this is the most up-to-date value. - return mCullFaceMode; -} - -void ImageAttachment::SetBlendMode( BlendingMode::Type mode ) -{ - mBlendingMode = mode; - - // attachment is being used in a separate thread; queue a message to set the value - SetBlendingModeMessage( GetEventThreadServices(), GetSceneObject(), mode ); -} - -BlendingMode::Type ImageAttachment::GetBlendMode() const -{ - return mBlendingMode; -} - -void ImageAttachment::SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb, - BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha ) -{ - // Cache for actor-side getters - mBlendingOptions.SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha ); - - // attachment is being used in a separate thread; queue a message to set the value - SetBlendingOptionsMessage( GetEventThreadServices(), GetSceneObject(), mBlendingOptions.GetBitmask() ); -} - -void ImageAttachment::GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb, - BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const -{ - // These are not animatable, the cached values are up-to-date. - srcFactorRgb = mBlendingOptions.GetBlendSrcFactorRgb(); - destFactorRgb = mBlendingOptions.GetBlendDestFactorRgb(); - srcFactorAlpha = mBlendingOptions.GetBlendSrcFactorAlpha(); - destFactorAlpha = mBlendingOptions.GetBlendDestFactorAlpha(); -} - -void ImageAttachment::SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha ) -{ - mBlendingOptions.SetBlendEquation( equationRgb, equationAlpha ); - - // attachment is being used in a separate thread; queue a message to set the value - SetBlendingOptionsMessage( GetEventThreadServices(), GetSceneObject(), mBlendingOptions.GetBitmask() ); -} - -void ImageAttachment::GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const -{ - // These are not animatable, the cached values are up-to-date. - equationRgb = mBlendingOptions.GetBlendEquationRgb(); - equationAlpha = mBlendingOptions.GetBlendEquationAlpha(); -} - -void ImageAttachment::SetBlendColor( const Vector4& color ) -{ - if( mBlendingOptions.SetBlendColor( color ) ) - { - // attachment is being used in a separate thread; queue a message to set the value - SetBlendColorMessage( GetEventThreadServices(), GetSceneObject(), color ); - } -} - -const Vector4& ImageAttachment::GetBlendColor() const -{ - const Vector4* optionalColor = mBlendingOptions.GetBlendColor(); - if( optionalColor ) - { - return *optionalColor; - } - - return Vector4::ZERO; -} - -void ImageAttachment::SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter ) -{ - mSamplerBitfield = ImageSampler::PackBitfield( minFilter, magFilter ); - - SetSamplerMessage( GetEventThreadServices(), GetSceneObject(), mSamplerBitfield ); -} - -void ImageAttachment::GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const -{ - minFilter = ImageSampler::GetMinifyFilterMode( mSamplerBitfield ); - magFilter = ImageSampler::GetMagnifyFilterMode( mSamplerBitfield ); -} - - -void ImageAttachment::SetShaderEffect(ShaderEffect& effect) -{ - if ( OnStage() ) - { - if ( mShaderEffect ) - { - mShaderEffect->Disconnect(); - } - - mShaderEffect.Reset( &effect ); - - const SceneGraph::Shader& shader = dynamic_cast( *mShaderEffect->GetSceneObject() ); - - ApplyShaderMessage( GetEventThreadServices(), GetSceneObject(), shader ); - - mShaderEffect->Connect(); - } - else - { - mShaderEffect = ShaderEffectPtr(&effect); - } - // Effects can only be applied when the Node is connected to scene-graph -} - -ShaderEffectPtr ImageAttachment::GetShaderEffect() const -{ - return mShaderEffect; -} - -void ImageAttachment::RemoveShaderEffect() -{ - if ( OnStage() ) - { - RemoveShaderMessage( GetEventThreadServices(), GetSceneObject() ); - - // Notify shader effect - if (mShaderEffect) - { - mShaderEffect->Disconnect(); - } - } - - mShaderEffect.Reset(); -} - - -void ImageAttachment::OnStageConnection2() -{ - if ( mShaderEffect ) - { - const SceneGraph::Shader& shader = dynamic_cast( *mShaderEffect->GetSceneObject() ); - - ApplyShaderMessage( GetEventThreadServices(), GetSceneObject(), shader ); - - // Notify shader effect - mShaderEffect->Connect(); - } - - mImageConnectable.OnStageConnect(); - - // Provide resource ID when scene-graph attachment is connected - ImagePtr image = mImageConnectable.Get(); - unsigned int resourceId = (image) ? image->GetResourceId() : 0u; - if ( 0u != resourceId ) - { - SetTextureIdMessage( GetEventThreadServices(), *mSceneObject, resourceId ); - } -} - -void ImageAttachment::OnStageDisconnection2() -{ - // Notify shader effect - if ( mShaderEffect ) - { - mShaderEffect->Disconnect(); - } - - // Remove resource ID when scene-graph attachment is disconnected - SetTextureIdMessage( GetEventThreadServices(), *mSceneObject, 0u ); - - mImageConnectable.OnStageDisconnect(); -} - - - -} // namespace Internal - -} // namespace Dali diff --git a/dali/internal/event/actor-attachments/image-attachment-impl.h b/dali/internal/event/actor-attachments/image-attachment-impl.h deleted file mode 100644 index 0d7a7a0..0000000 --- a/dali/internal/event/actor-attachments/image-attachment-impl.h +++ /dev/null @@ -1,297 +0,0 @@ -#ifndef __DALI_INTERNAL_IMAGE_ATTACHMENT_H__ -#define __DALI_INTERNAL_IMAGE_ATTACHMENT_H__ - -/* - * Copyright (c) 2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// INTERNAL INCLUDES -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Dali -{ - -namespace Internal -{ - -namespace SceneGraph -{ -class ImageAttachment; -class Node; -} - -/** - * An attachment for rendering images in various ways. - */ -class ImageAttachment : public RenderableAttachment -{ -public: - - typedef Dali::ImageActor::Style Style; - typedef Dali::ImageActor::PixelArea PixelArea; - - /** - * Create a new ImageAttachment. - * @param[in] eventThreadServices to use - * @param[in] parentNode The node to attach a scene-object to. - * @return A smart-pointer to the newly allocated ImageAttachment. - */ - static ImageAttachmentPtr New( EventThreadServices& eventThreadServices, const SceneGraph::Node& parentNode ); - - /** - * Sets image rendered by the attachment. - * @param [in] image A pointer to the image to display or NULL to clear. Reference to avoid unnecessary increment/decrement reference count. - */ - void SetImage( ImagePtr& image ); - - /** - * Retrieve the image rendered by the attachment. - * @return The image or an uninitialized image in case the ImageActor was cleared. - */ - ImagePtr GetImage(); - - /** - * Set a region of the image to display, in pixels. - * @param [in] pixelArea The area of the image to display. - * This in pixels, relative to the top-left (0,0) of the image. - */ - void SetPixelArea(const PixelArea& pixelArea); - - /** - * Retrieve the region of the image to display, in pixels. - * @return The pixel area, or a default-constructed area if none was set. - */ - const PixelArea& GetPixelArea() const - { - // This is not animatable; the cached value is up-to-date. - return mPixelArea; - } - - /** - * Query whether a pixel area has been set. - * @return True if a pixel area has been set. - */ - bool IsPixelAreaSet() const - { - // This is not animatable; the cached value is up-to-date. - return mIsPixelAreaSet; - } - - /** - * Remove any pixel areas specified with SetPixelArea; the entire image will be displayed. - * @pre image must be initialized. - */ - void ClearPixelArea(); - - /** - * Set how the ImageAttachment is rendered; the default is STYLE_QUAD. - * @param [in] style The new style. - */ - void SetStyle(Style style); - - /** - * Query how the image is rendered. - * @return The rendering style. - */ - Style GetStyle() - { - // This is not animatable; the cached value is up-to-date. - return mStyle; - } - - /** - * @copydoc Dali::ImageActor::SetNinePatchBorder - */ - void SetNinePatchBorder(const Vector4& border, bool inPixels); - - /** - * @copydoc Dali::ImageActor::GetNinePatchBorder - */ - Vector4 GetNinePatchBorder() - { - // This is not animatable; the cached value is up-to-date. - return mBorder; - } - - - /** - * Set the depth-sort modifier for the renderable. - * This modifies the back-to-front distance calculation, when rendering with transparency. - * This is useful for ordering transparent objects that are positioned close to each other. - * @param[in] modifier The depth-sort modifier. - */ - void SetSortModifier(float modifier); - - /** - * From Renderable; Retrieve the depth-sort modifier for the renderable. - * @return The depth-sort modifier. - */ - float GetSortModifier() const; - - /** - * Set the face-culling mode for this attachment. - * @param[in] mode The culling mode. - */ - void SetCullFace(CullFaceMode mode); - - /** - * Retrieve the face-culling mode for this attachment. - * @return mode The culling mode. - */ - CullFaceMode GetCullFace() const; - - /** - * @copydoc Dali::RenderableActor::SetBlendMode() - */ - void SetBlendMode( BlendingMode::Type mode ); - - /** - * @copydoc Dali::RenderableActor::GetBlendMode() - */ - BlendingMode::Type GetBlendMode() const; - - /** - * @copydoc Dali::RenderableActor::SetBlendFunc() - */ - void SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb, - BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha ); - - /** - * @copydoc Dali::RenderableActor::GetBlendFunc() - */ - void GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb, - BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const; - - /** - * @copydoc Dali::RenderableActor::SetBlendEquation() - */ - void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha ); - - /** - * @copydoc Dali::RenderableActor::GetBlendEquation() - */ - void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const; - - /** - * @copydoc Dali::RenderableActor::SetBlendColor() - */ - void SetBlendColor( const Vector4& color ); - - /** - * @copydoc Dali::RenderableActor::GetBlendColor() - */ - const Vector4& GetBlendColor() const; - - /** - * @copydoc Dali::RenderableActor::SetFilterMode() - */ - void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter ); - - /** - * @copydoc Dali::RenderableActor::GetFilterMode() - */ - void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const; - - /** - * @copydoc Dali::RenderableActor::SetShaderEffect - */ - void SetShaderEffect(ShaderEffect& effect); - - /** - * @copydoc Dali::RenderableActor::GetShaderEffect - */ - ShaderEffectPtr GetShaderEffect() const; - - /** - * @copydoc Dali::RenderableActor::RemoveShaderEffect - */ - void RemoveShaderEffect(); - -private: - - /** - * First stage construction of a ImageAttachment. - * @param[in] eventThreadServices Used for messaging to and reading from scene-graph. - */ - ImageAttachment( EventThreadServices& eventThreadServices ); - - /** - * Creates the corresponding scene-graph ImageAttachment. - * @return A newly allocated scene object. - */ - static SceneGraph::ImageAttachment* CreateSceneObject(); - - /** - * @copydoc Dali::Internal::RenderableAttachment::OnStageConnection2() - */ - virtual void OnStageConnection2(); - - /** - * @copydoc Dali::Internal::RenderableAttachment::OnStageDisconnection2() - */ - virtual void OnStageDisconnection2(); - - /** - * @copydoc Dali::Internal::RenderableAttachment::GetSceneObject() - */ - const SceneGraph::ImageAttachment& GetSceneObject() const; - -protected: - - /** - * A reference counted object may only be deleted by calling Unreference() - */ - virtual ~ImageAttachment(); - -private: - - const SceneGraph::ImageAttachment* mSceneObject; ///< Not owned - - ImageConnector mImageConnectable; ///< Manages the image displayed by the attachment - - // Cached for public getters - - PixelArea mPixelArea; - - Style mStyle; - Vector4 mBorder; - - bool mIsPixelAreaSet : 1; - bool mBorderInPixels : 1; - - BlendingOptions mBlendingOptions; - unsigned int mSamplerBitfield; - float mSortModifier; - CullFaceMode mCullFaceMode:3; ///< cullface mode, 3 bits enough for 4 values - BlendingMode::Type mBlendingMode:2; ///< blending mode, 2 bits enough for 3 values - - ShaderEffectPtr mShaderEffect; ///< Optional referenced shader effect -}; - -} // namespace Internal - -} // namespace Dali - -#endif // __DALI_INTERNAL_IMAGE_ATTACHMENT_H__ diff --git a/dali/internal/event/actors/actor-impl.cpp b/dali/internal/event/actors/actor-impl.cpp index 475702e..e44c3f2 100644 --- a/dali/internal/event/actors/actor-impl.cpp +++ b/dali/internal/event/actors/actor-impl.cpp @@ -1879,7 +1879,6 @@ Actor::Actor( DerivedType derivedType ) mId( ++mActorCounter ), // actor ID is initialised to start from 1, and 0 is reserved mDepth( 0u ), mIsRoot( ROOT_LAYER == derivedType ), - mIsRenderable( RENDERABLE == derivedType ), mIsLayer( LAYER == derivedType || ROOT_LAYER == derivedType ), mIsOnStage( false ), mSensitive( true ), diff --git a/dali/internal/event/actors/actor-impl.h b/dali/internal/event/actors/actor-impl.h index be4e6fb..7f2ae5b 100644 --- a/dali/internal/event/actors/actor-impl.h +++ b/dali/internal/event/actors/actor-impl.h @@ -165,13 +165,13 @@ public: bool OnStage() const; /** - * Query whether the actor is a RenderableActor derived type. + * Query whether the actor has any renderers. * @return True if the actor is renderable. */ bool IsRenderable() const { // inlined as this is called a lot in hit testing - return mIsRenderable; + return mRenderers && !mRenderers->empty(); } /** @@ -1473,7 +1473,7 @@ protected: enum DerivedType { - BASIC, RENDERABLE, LAYER, ROOT_LAYER + BASIC, LAYER, ROOT_LAYER }; /** @@ -1797,7 +1797,6 @@ protected: unsigned short mDepth :12; ///< Cached: The depth in the hierarchy of the actor. Only 4096 levels of depth are supported const bool mIsRoot : 1; ///< Flag to identify the root actor - const bool mIsRenderable : 1; ///< Flag to identify that this is a renderable actor const bool mIsLayer : 1; ///< Flag to identify that this is a layer bool mIsOnStage : 1; ///< Flag to identify whether the actor is on-stage bool mSensitive : 1; ///< Whether the actor emits touch event signals diff --git a/dali/internal/event/actors/image-actor-impl.cpp b/dali/internal/event/actors/image-actor-impl.cpp index cf7b7d4..3588a40 100644 --- a/dali/internal/event/actors/image-actor-impl.cpp +++ b/dali/internal/event/actors/image-actor-impl.cpp @@ -22,8 +22,10 @@ #include // for strcmp // INTERNAL INCLUDES +#include // for EqualToConstraint #include #include +#include #include #include #include @@ -55,37 +57,163 @@ BaseHandle Create() TypeRegistration mType( typeid( Dali::ImageActor ), typeid( Dali::Actor ), Create ); -ImageActor::Style StyleEnum(const std::string &s) +struct GridVertex { - if(s == "STYLE_NINE_PATCH") - { - return Dali::ImageActor::STYLE_NINE_PATCH; - } - else if(s == "STYLE_NINE_PATCH_NO_CENTER") - { - return Dali::ImageActor::STYLE_NINE_PATCH_NO_CENTER; - } - else // if(s == "QUAD") + Vector3 mPosition; + Vector2 mTextureCoord; +}; + +GeometryPtr CreateQuadGeometry( const Vector2& size, int imageWidth, int imageHeight, const Dali::ImageActor::PixelArea& pixelArea ) +{ + const float halfWidth = size.width * 0.5f; + const float halfHeight = size.height * 0.5f; + GridVertex quadVertexData[4] = { - return Dali::ImageActor::STYLE_QUAD; - } + { Vector3( -halfWidth, -halfHeight, 0.f ), Vector2( ( pixelArea.x ) / (float)imageWidth, ( pixelArea.y ) / (float)imageHeight ) }, + { Vector3( -halfWidth, halfHeight, 0.f ), Vector2( ( pixelArea.x ) / (float)imageWidth, ( pixelArea.y + pixelArea.height ) / (float)imageHeight ) }, + { Vector3( halfWidth, -halfHeight, 0.f ), Vector2( ( pixelArea.x + pixelArea.width ) / (float)imageWidth, ( pixelArea.y ) / (float)imageHeight ) }, + { Vector3( halfWidth, halfHeight, 0.f ), Vector2( ( pixelArea.x + pixelArea.width ) / (float)imageWidth, ( pixelArea.y + pixelArea.height ) / (float)imageHeight ) } + }; + + Property::Map quadVertexFormat; + quadVertexFormat["aPosition"] = Property::VECTOR3; + quadVertexFormat["aTexCoord"] = Property::VECTOR2; + PropertyBufferPtr quadVertices = PropertyBuffer::New(); + quadVertices->SetFormat( quadVertexFormat ); + quadVertices->SetSize( 4 ); + quadVertices->SetData(quadVertexData); + + // Create the geometry object + GeometryPtr geometry = Geometry::New(); + geometry->AddVertexBuffer( *quadVertices ); + geometry->SetGeometryType( Dali::Geometry::TRIANGLE_STRIP ); + + return geometry; } -std::string StyleString(const ImageActor::Style style) +GeometryPtr CreateGridGeometry( const Vector2& size, unsigned int gridWidth, unsigned int gridHeight, int imageWidth, int imageHeight, const Dali::ImageActor::PixelArea& pixelArea ) { - if(style == Dali::ImageActor::STYLE_NINE_PATCH) + // Create vertices + std::vector< GridVertex > vertices; + vertices.reserve( ( gridWidth + 1 ) * ( gridHeight + 1 ) ); + + for( unsigned int y = 0u; y < gridHeight + 1; ++y ) { - return "STYLE_NINE_PATCH"; + float yPos = (float)y / gridHeight; + for( unsigned int x = 0u; x < gridWidth + 1; ++x ) + { + float xPos = (float)x / gridWidth; + GridVertex vertex = { + Vector3( size.width * ( xPos - 0.5f ), size.height * ( yPos - 0.5f ), 0.0f ), + Vector2( ( pixelArea.x + pixelArea.width * xPos ) / (float)imageWidth, + ( pixelArea.y + pixelArea.height * yPos ) / (float)imageHeight ) + }; + vertices.push_back( vertex ); + } } - else if(style == Dali::ImageActor::STYLE_NINE_PATCH_NO_CENTER) + + // Create indices + Vector< unsigned int > indices; + indices.Reserve( ( gridWidth + 2 ) * gridHeight * 2 - 2); + + for( unsigned int row = 0u; row < gridHeight; ++row ) { - return "STYLE_NINE_PATCH_NO_CENTER"; + unsigned int rowStartIndex = row*(gridWidth+1u); + unsigned int nextRowStartIndex = rowStartIndex + gridWidth +1u; + + if( row != 0u ) // degenerate index on non-first row + { + indices.PushBack( rowStartIndex ); + } + + for( unsigned int column = 0u; column < gridWidth+1u; column++) // main strip + { + indices.PushBack( rowStartIndex + column); + indices.PushBack( nextRowStartIndex + column); + } + + if( row != gridHeight-1u ) // degenerate index on non-last row + { + indices.PushBack( nextRowStartIndex + gridWidth ); + } } - else // if(s == "QUAD") + + + Property::Map vertexFormat; + vertexFormat[ "aPosition" ] = Property::VECTOR3; + vertexFormat[ "aTexCoord" ] = Property::VECTOR2; + PropertyBufferPtr vertexPropertyBuffer = PropertyBuffer::New(); + vertexPropertyBuffer->SetFormat( vertexFormat ); + vertexPropertyBuffer->SetSize( vertices.size() ); + if( vertices.size() > 0 ) { - return "STYLE_QUAD"; + vertexPropertyBuffer->SetData( &vertices[ 0 ] ); } + + Property::Map indexFormat; + indexFormat[ "indices" ] = Property::INTEGER; + PropertyBufferPtr indexPropertyBuffer = PropertyBuffer::New(); + indexPropertyBuffer->SetFormat( indexFormat ); + indexPropertyBuffer->SetSize( indices.Size() ); + if( indices.Size() > 0 ) + { + indexPropertyBuffer->SetData( &indices[ 0 ] ); + } + + // Create the geometry object + GeometryPtr geometry = Geometry::New(); + geometry->AddVertexBuffer( *vertexPropertyBuffer ); + geometry->SetIndexBuffer( *indexPropertyBuffer ); + geometry->SetGeometryType( Dali::Geometry::TRIANGLE_STRIP ); + + return geometry; + } + + +template< typename T> +ConstraintBase* CreateEqualConstraint(Object& target, Property::Index index, Internal::SourceContainer& sources ) +{ + typedef typename Dali::Internal::PropertyConstraintPtr< T >::Type PropertyConstraintPtrType; + + CallbackBase* callback = new Dali::Constraint::Function< T >( EqualToConstraint() ); + PropertyConstraintPtrType funcPtr( new Internal::PropertyConstraint< T >( reinterpret_cast< Dali::Constraint::Function< T >* >( callback ) ) ); + + return Internal::Constraint< T >::New( target, index, sources, funcPtr ); +} + +const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( + attribute mediump vec3 aPosition;\n + attribute mediump vec2 aTexCoord;\n + varying mediump vec2 vTexCoord;\n + uniform mediump mat4 uMvpMatrix;\n + uniform mediump vec3 uSize;\n + uniform mediump vec4 uTextureRect;\n + \n + void main()\n + {\n + mediump vec4 vertexPosition = vec4(aPosition, 1.0);\n + vertexPosition = uMvpMatrix * vertexPosition;\n + \n + vTexCoord = aTexCoord;\n + gl_Position = vertexPosition;\n + }\n +); + +const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( + varying mediump vec2 vTexCoord;\n + uniform sampler2D sTexture;\n + uniform lowp vec4 uColor;\n + \n + void main()\n + {\n + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n + }\n +); + +const size_t INVALID_TEXTURE_ID = (size_t)-1; +const int INVALID_RENDERER_ID = -1; +const unsigned int MAXIMUM_GRID_SIZE = 2048; } ImageActorPtr ImageActor::New() @@ -95,9 +223,16 @@ ImageActorPtr ImageActor::New() // Second-phase construction of base class actor->Initialize(); - // Create the attachment - actor->mImageAttachment = ImageAttachment::New( actor->GetEventThreadServices(), *actor->mNode ); - actor->Attach( *actor->mImageAttachment ); + //Create the renderer + actor->mRenderer = Renderer::New(); + + GeometryPtr quad = CreateQuadGeometry( Vector2::ONE, 1, 1, PixelArea() ); + actor->mRenderer->SetGeometry( *quad ); + + ShaderPtr shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER, Dali::Shader::HINT_NONE ); + MaterialPtr material = Material::New(); + material->SetShader( *shader ); + actor->mRenderer->SetMaterial( *material ); return actor; } @@ -110,109 +245,84 @@ void ImageActor::OnInitialize() void ImageActor::SetImage( ImagePtr& image ) { - ImagePtr currentImage = mImageAttachment->GetImage(); - // early exit if it's the same image as we already have - if ( currentImage == image ) + if( !image ) { - return; + if( mRendererIndex != INVALID_RENDERER_ID ) + { + RemoveRenderer( mRendererIndex ); + mRendererIndex = INVALID_RENDERER_ID; + } } - - // NOTE! image might be pointing to NULL, which is fine as in that case app wants to just remove the image - ImagePtr newImage( image ); - // if image is not NULL, check for 9 patch - if( newImage ) + else { - // Automatically convert nine-patch images to cropped bitmap - NinePatchImage* ninePatchImage = NinePatchImage::DownCast( image.Get() ); - if( ninePatchImage ) - { - newImage = ninePatchImage->CreateCroppedBufferImage(); - SetStyle( Dali::ImageActor::STYLE_NINE_PATCH ); + SamplerPtr sampler = Sampler::New(); + sampler->SetFilterMode( mMinFilter, mMagFilter ); - const NinePatchImage::StretchRanges& stretchPixelsX = ninePatchImage->GetStretchPixelsX(); - const NinePatchImage::StretchRanges& stretchPixelsY = ninePatchImage->GetStretchPixelsY(); + mTextureIndex = mRenderer->GetMaterial()->AddTexture( image, "sTexture", sampler ); - if( stretchPixelsX.Size() > 0 && stretchPixelsY.Size() > 0 ) - { - Vector4 border; - //The NinePatchImage stretch pixels are in the cropped image space, inset by 1 to get it to uncropped image space - border.x = stretchPixelsX[ 0 ].GetX() + 1; - border.y = stretchPixelsY[ 0 ].GetX() + 1; - border.z = image->GetWidth() - stretchPixelsX[ 0 ].GetY() - 1; - border.w = image->GetHeight() - stretchPixelsY[ 0 ].GetY() - 1; - - SetNinePatchBorder( border, true ); - } + if( mRendererIndex == INVALID_RENDERER_ID ) + { + mRendererIndex = AddRenderer( *mRenderer ); } - } - // set the actual image (normal or 9 patch) and natural size based on that - mImageAttachment->SetImage( newImage ); - RelayoutRequest(); + if( !mIsPixelAreaSet ) + { + mPixelArea = PixelArea( 0, 0, image->GetWidth(), image->GetHeight() ); + } + + RelayoutRequest(); + } } -ImagePtr ImageActor::GetImage() +ImagePtr ImageActor::GetImage() const { - return mImageAttachment->GetImage(); + return mRenderer->GetMaterial()->GetTexture( mTextureIndex ); } void ImageActor::SetPixelArea( const PixelArea& pixelArea ) { - mImageAttachment->SetPixelArea( pixelArea ); + mPixelArea = pixelArea; + mIsPixelAreaSet = true; RelayoutRequest(); } const ImageActor::PixelArea& ImageActor::GetPixelArea() const { - return mImageAttachment->GetPixelArea(); + return mPixelArea; } bool ImageActor::IsPixelAreaSet() const { - return mImageAttachment->IsPixelAreaSet(); + return mIsPixelAreaSet; } void ImageActor::ClearPixelArea() { - mImageAttachment->ClearPixelArea(); - - RelayoutRequest(); -} - -void ImageActor::SetStyle( Style style ) -{ - mImageAttachment->SetStyle( style ); -} + mIsPixelAreaSet = false; -ImageActor::Style ImageActor::GetStyle() const -{ - return mImageAttachment->GetStyle(); -} - -void ImageActor::SetNinePatchBorder( const Vector4& border, bool inPixels ) -{ - mImageAttachment->SetNinePatchBorder( border, inPixels ); -} - -Vector4 ImageActor::GetNinePatchBorder() const -{ - return mImageAttachment->GetNinePatchBorder(); -} + int imageWidth = 0; + int imageHeight = 0; + ImagePtr image = GetImage(); + if( image ) + { + imageWidth = image->GetWidth(); + imageHeight = image->GetHeight(); + } -ImageAttachment& ImageActor::GetImageAttachment() -{ - return *mImageAttachment; -} + mPixelArea = PixelArea( 0, 0, imageWidth, imageHeight ); -RenderableAttachment& ImageActor::GetRenderableAttachment() const -{ - DALI_ASSERT_DEBUG( mImageAttachment && "ImageAttachment missing from ImageActor" ); - return *mImageAttachment; + RelayoutRequest(); } ImageActor::ImageActor() -: Actor( Actor::RENDERABLE ) +: Actor( Actor::BASIC ), + mRendererIndex( INVALID_RENDERER_ID ), + mTextureIndex( INVALID_TEXTURE_ID ), + mEffectTextureIndex( INVALID_TEXTURE_ID ), + mMinFilter( FilterMode::DEFAULT ), + mMagFilter( FilterMode::DEFAULT ), + mIsPixelAreaSet( false ) { } @@ -231,7 +341,7 @@ Vector2 ImageActor::CalculateNaturalSize() const // if no image then natural size is 0 Vector2 size( 0.0f, 0.0f ); - ImagePtr image = mImageAttachment->GetImage(); + ImagePtr image = GetImage(); if( image ) { if( IsPixelAreaSet() ) @@ -249,12 +359,84 @@ Vector2 ImageActor::CalculateNaturalSize() const return size; } -void ImageActor::OnStageConnectionInternal() +void ImageActor::OnRelayout( const Vector2& size, RelayoutContainer& container ) { -} + int imageWidth = 1; + int imageHeight = 1; -void ImageActor::OnStageDisconnectionInternal() -{ + ImagePtr image = GetImage(); + + if( image ) + { + imageWidth = image->GetWidth(); + imageHeight = image->GetHeight(); + } + + unsigned int gridWidth = 1; + unsigned int gridHeight = 1; + if( mShaderEffect ) + { + Dali::ShaderEffect::GeometryHints hints = mShaderEffect->GetGeometryHints(); + Property::Value gridDensityValue = mShaderEffect->GetDefaultProperty( Dali::ShaderEffect::Property::GRID_DENSITY ); + int gridDensity = Dali::ShaderEffect::DEFAULT_GRID_DENSITY; + gridDensityValue.Get( gridDensity ); + + if( ( hints & Dali::ShaderEffect::HINT_GRID_X ) ) + { + gridWidth = size.width / gridDensity; + } + if( ( hints & Dali::ShaderEffect::HINT_GRID_Y ) ) + { + gridHeight = size.height / gridDensity; + } + + //limit the grid size + gridWidth = std::min( MAXIMUM_GRID_SIZE, gridWidth ); + gridHeight = std::min( MAXIMUM_GRID_SIZE, gridHeight ); + } + + GeometryPtr quad = gridWidth <= 1 && gridHeight <= 1 ? + CreateQuadGeometry( size, imageWidth, imageHeight, mPixelArea ) : + CreateGridGeometry( size, gridWidth, gridHeight, imageWidth, imageHeight, mPixelArea ); + + mRenderer->SetGeometry( *quad ); + + Vector4 textureRect( 0.f, 0.f, 1.f, 1.f ); + if( mIsPixelAreaSet ) + { + ImagePtr image = GetImage(); + if( image ) + { + int imageWidth = image->GetWidth(); + int imageHeight = image->GetHeight();; + + const float uScale = 1.0f / float(imageWidth); + const float vScale = 1.0f / float(imageHeight); + const float x = uScale * float(mPixelArea.x); + const float y = vScale * float(mPixelArea.y); + const float width = uScale * float(mPixelArea.width); + const float height = vScale * float(mPixelArea.height); + + // bottom left + textureRect.x = x; + textureRect.y = y; + + // top right + textureRect.z = x + width; + textureRect.w = y + height; + } + } + + Material* material = mRenderer->GetMaterial(); + Property::Index index = material->GetPropertyIndex( "sTextureRect" ); + if( index != Property::INVALID_INDEX ) + { + material->SetProperty( index, textureRect ); + } + else + { + material->RegisterProperty( "sTextureRect", textureRect ); + } } unsigned int ImageActor::GetDefaultPropertyCount() const @@ -397,12 +579,12 @@ void ImageActor::SetDefaultProperty( Property::Index index, const Property::Valu } case Dali::ImageActor::Property::STYLE: { - SetStyle( StyleEnum( propertyValue.Get() ) ); + //not supported break; } case Dali::ImageActor::Property::BORDER: { - SetNinePatchBorder( propertyValue.Get(), true /*in pixels*/ ); + //not supported break; } case Dali::ImageActor::Property::IMAGE: @@ -448,18 +630,18 @@ Property::Value ImageActor::GetDefaultProperty( Property::Index index ) const } case Dali::ImageActor::Property::STYLE: { - ret = StyleString( GetStyle() ); + //not supported break; } case Dali::ImageActor::Property::BORDER: { - ret = GetNinePatchBorder(); + //not supported break; } case Dali::ImageActor::Property::IMAGE: { Property::Map map; - Scripting::CreatePropertyMap( Dali::Image( mImageAttachment->GetImage().Get() ), map ); + Scripting::CreatePropertyMap( Dali::Image( GetImage().Get() ), map ); ret = Property::Value( map ); break; } @@ -474,114 +656,284 @@ Property::Value ImageActor::GetDefaultProperty( Property::Index index ) const return ret; } - void ImageActor::SetSortModifier(float modifier) { - mImageAttachment->SetSortModifier( modifier ); + mRenderer->SetDepthIndex( modifier ); } float ImageActor::GetSortModifier() const { - return mImageAttachment->GetSortModifier(); -} - -void ImageActor::SetDepthIndex( int depthIndex ) -{ - mImageAttachment->SetSortModifier( depthIndex ); -} - -int ImageActor::GetDepthIndex() const -{ - return static_cast< int >( mImageAttachment->GetSortModifier() ); + return mRenderer->GetDepthIndex(); } void ImageActor::SetCullFace(CullFaceMode mode) { - mImageAttachment->SetCullFace( mode ); + mRenderer->GetMaterial()->SetFaceCullingMode( static_cast< Dali::Material::FaceCullingMode >( mode ) ); } CullFaceMode ImageActor::GetCullFace() const { - return mImageAttachment->GetCullFace(); + return static_cast< CullFaceMode >( mRenderer->GetMaterial()->GetFaceCullingMode() ); } void ImageActor::SetBlendMode( BlendingMode::Type mode ) { - mImageAttachment->SetBlendMode( mode ); + mRenderer->GetMaterial()->SetBlendMode( mode ); } BlendingMode::Type ImageActor::GetBlendMode() const { - return mImageAttachment->GetBlendMode(); + return mRenderer->GetMaterial()->GetBlendMode(); } void ImageActor::SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba ) { - mImageAttachment->SetBlendFunc( srcFactorRgba, destFactorRgba, srcFactorRgba, destFactorRgba ); + mRenderer->GetMaterial()->SetBlendFunc( srcFactorRgba, destFactorRgba, srcFactorRgba, destFactorRgba ); } void ImageActor::SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb, BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha ) { - mImageAttachment->SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha ); + mRenderer->GetMaterial()->SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha ); } void ImageActor::GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb, - BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const + BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const { - mImageAttachment->GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha ); + mRenderer->GetMaterial()->GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha ); } void ImageActor::SetBlendEquation( BlendingEquation::Type equationRgba ) { - mImageAttachment->SetBlendEquation( equationRgba, equationRgba ); + mRenderer->GetMaterial()->SetBlendEquation( equationRgba, equationRgba ); } void ImageActor::SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha ) { - mImageAttachment->SetBlendEquation( equationRgb, equationAlpha ); + mRenderer->GetMaterial()->SetBlendEquation( equationRgb, equationAlpha ); } void ImageActor::GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const { - mImageAttachment->GetBlendEquation( equationRgb, equationAlpha ); + mRenderer->GetMaterial()->GetBlendEquation( equationRgb, equationAlpha ); } void ImageActor::SetBlendColor( const Vector4& color ) { - mImageAttachment->SetBlendColor( color ); + mBlendColor = color; + mRenderer->GetMaterial()->SetBlendColor( mBlendColor ); } const Vector4& ImageActor::GetBlendColor() const { - return mImageAttachment->GetBlendColor(); + return mBlendColor; } void ImageActor::SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter ) { - mImageAttachment->SetFilterMode( minFilter, magFilter ); + mMinFilter = minFilter; + mMagFilter = magFilter; + + if( mTextureIndex != INVALID_TEXTURE_ID ) + { + SamplerPtr sampler = Sampler::New(); + sampler->SetFilterMode( minFilter, magFilter ); + + mRenderer->GetMaterial()->SetTextureSampler( mTextureIndex, sampler.Get() ); + } } void ImageActor::GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const { - return mImageAttachment->GetFilterMode( minFilter, magFilter ); + minFilter = mMinFilter; + magFilter = mMagFilter; } -void ImageActor::SetShaderEffect(ShaderEffect& effect) +void ImageActor::SetShaderEffect( ShaderEffect& effect ) { - mImageAttachment->SetShaderEffect( effect ); + if( mShaderEffect ) + { + mShaderEffect->Disconnect( this ); + } + + mShaderEffect = ShaderEffectPtr( &effect ); + effect.Connect( this ); + + Dali::ShaderEffect::GeometryHints hints = effect.GetGeometryHints(); + + int shaderHints = Dali::Shader::HINT_NONE; + + if( hints & Dali::ShaderEffect::HINT_DEPTH_BUFFER ) + { + shaderHints |= Dali::Shader::HINT_REQUIRES_SELF_DEPTH_TEST; + } + if( hints & Dali::ShaderEffect::HINT_BLENDING ) + { + shaderHints |= Dali::Shader::HINT_OUTPUT_IS_TRANSPARENT; + } + if( !(hints & Dali::ShaderEffect::HINT_DOESNT_MODIFY_GEOMETRY) ) + { + shaderHints |= Dali::Shader::HINT_MODIFIES_GEOMETRY; + } + + ShaderPtr shader = Shader::New( effect.GetVertexShader(), effect.GetFragmentShader(), static_cast< Dali::Shader::ShaderHints >( shaderHints ) ); + mRenderer->GetMaterial()->SetShader( *shader ); + + //get the uniforms and apply them to the renderer + const ShaderEffect::UniformArray& uniforms = mShaderEffect->GetUniforms(); + for( ShaderEffect::UniformArray::const_iterator it = uniforms.begin(); it != uniforms.end(); ++it ) + { + const ShaderEffect::Uniform& uniform = *it; + EffectUniformUpdated( uniform ); + } + + if( mShaderEffect->GetEffectImage() ) + { + EffectImageUpdated(); + } +} + +void ImageActor::EffectUniformUpdated( const ShaderEffect::Uniform& uniform ) +{ + if( !mShaderEffect ) + { + return; + } + + Shader* shader = mRenderer->GetMaterial()->GetShader(); + + Property::Index index = shader->GetPropertyIndex( uniform.mName ); + if( index == Property::INVALID_INDEX ) + { + index = shader->RegisterProperty( uniform.mName, uniform.mValue ); + + //Constrain the shader's uniform properties to the ShaderEffect properties + Internal::ConstraintBase* constraint = NULL; + Internal::SourceContainer sources; + + switch( uniform.mValue.GetType() ) + { + case Property::INTEGER: + case Property::FLOAT: + { + constraint = CreateEqualConstraint< float >(*shader, index, sources ); + break; + } + case Property::VECTOR2: + { + constraint = CreateEqualConstraint< Vector2 >(*shader, index, sources ); + break; + } + case Property::VECTOR3: + { + constraint = CreateEqualConstraint< Vector3 >(*shader, index, sources ); + break; + } + case Property::VECTOR4: + { + constraint = CreateEqualConstraint< Vector4 >(*shader, index, sources ); + break; + } + case Property::MATRIX3: + { + constraint = CreateEqualConstraint< Matrix3 >(*shader, index, sources ); + break; + } + case Property::MATRIX: + { + constraint = CreateEqualConstraint< Matrix >(*shader, index, sources ); + break; + } + case Property::BOOLEAN: + case Property::ARRAY: + case Property::ROTATION: + case Property::STRING: + case Property::RECTANGLE: + case Property::MAP: + case Property::NONE: + //not supported + break; + } + + //constrain the renderers property to the ShaderEffect + if( constraint ) + { + Source source; + source.sourceType = OBJECT_PROPERTY; + source.propertyIndex = uniform.mIndex; + source.object = mShaderEffect.Get(); + + constraint->AddSource( source ); + constraint->Apply(); + } + } + else + { + shader->SetProperty( index, uniform.mValue ); + } } ShaderEffectPtr ImageActor::GetShaderEffect() const { - return mImageAttachment->GetShaderEffect(); + return mShaderEffect; } void ImageActor::RemoveShaderEffect() { - return mImageAttachment->RemoveShaderEffect(); + //if we previously had a subdivided grid then we need to reset the geometry as well + if( mShaderEffect ) + { + mShaderEffect->Disconnect( this ); + + Dali::ShaderEffect::GeometryHints hints = mShaderEffect->GetGeometryHints(); + if( ( hints & Dali::ShaderEffect::HINT_GRID_X ) || + ( hints & Dali::ShaderEffect::HINT_GRID_Y ) ) + { + RelayoutRequest(); + } + } + + ShaderPtr shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER, Dali::Shader::HINT_NONE ); + mRenderer->GetMaterial()->SetShader( *shader ); + mShaderEffect.Reset(); } +void ImageActor::EffectImageUpdated() +{ + if( mShaderEffect ) + { + Dali::Image effectImage = mShaderEffect->GetEffectImage(); + if( effectImage ) + { + Image& effectImageImpl = GetImplementation( effectImage ); + + if( mEffectTextureIndex == INVALID_TEXTURE_ID ) + { + mEffectTextureIndex = mRenderer->GetMaterial()->AddTexture( &effectImageImpl, "sEffect", NULL ); + } + else + { + mRenderer->GetMaterial()->SetTextureImage( mEffectTextureIndex, &effectImageImpl ); + } + } + else + { + if( mEffectTextureIndex != INVALID_TEXTURE_ID ) + { + mRenderer->GetMaterial()->RemoveTexture( mEffectTextureIndex ); + } + mEffectTextureIndex = INVALID_TEXTURE_ID; + } + + //ensure that the sEffectRect uniform is set + Shader* shader = mRenderer->GetMaterial()->GetShader(); + Property::Index index = shader->GetPropertyIndex( "sEffectRect" ); + if( index == Property::INVALID_INDEX ) + { + shader->RegisterProperty( "sEffectRect", Vector4( 0.f, 0.f, 1.f, 1.f) ); + } + } +} } // namespace Internal diff --git a/dali/internal/event/actors/image-actor-impl.h b/dali/internal/event/actors/image-actor-impl.h index 785216e..654e7fe 100644 --- a/dali/internal/event/actors/image-actor-impl.h +++ b/dali/internal/event/actors/image-actor-impl.h @@ -24,8 +24,8 @@ #include #include #include -#include #include +#include #include namespace Dali @@ -53,7 +53,6 @@ class ImageActor : public Actor { public: - typedef Dali::ImageActor::Style Style; typedef Dali::ImageActor::PixelArea PixelArea; /** @@ -77,7 +76,7 @@ public: * Retrieve the image rendered by the actor's attachment. * @return smart pointer to the image or an empty one if no image is assigned */ - ImagePtr GetImage(); + ImagePtr GetImage() const; /** * @copydoc Dali::ImageActor::SetPixelArea() @@ -100,33 +99,6 @@ public: void ClearPixelArea(); /** - * @copydoc Dali::ImageActor::SetStyle() - */ - void SetStyle( Style style ); - - /** - * @copydoc Dali::ImageActor::GetStyle() - */ - Style GetStyle() const; - - /** - * @copydoc Dali::ImageActor::SetNinePatchBorder - */ - void SetNinePatchBorder( const Vector4& border, bool inPixels = false ); - - /** - * @copydoc Dali::ImageActor::GetNinePatchBorder - */ - Vector4 GetNinePatchBorder() const; - - /** - * Retrieve the attachment which renders the image. - * @return The attachment. - */ - ImageAttachment& GetImageAttachment(); - - - /** * @copydoc Dali::RenderableActor::SetSortModifier() */ void SetSortModifier(float modifier); @@ -137,16 +109,6 @@ public: float GetSortModifier() const; /** - * @copydoc Dali::RenderableActor::SetDepthIndex() - */ - void SetDepthIndex( int depthIndex ); - - /** - * @copydoc Dali::RenderableActor::GetDepthIndex() - */ - int GetDepthIndex() const; - - /** * @copydoc Dali::RenderableActor::SetCullFace() */ void SetCullFace(CullFaceMode mode); @@ -218,6 +180,18 @@ public: */ void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const; + /** + * @brief Allows this ImageActor to respond to the event that the a shader effect's uniform has updated + * + * @param[in] uniform The shader effect uniform that has been updated + */ + void EffectUniformUpdated( const ShaderEffect::Uniform& uniform ); + + /** + * @brief Allows this ImageActor to respond to the eventa that the shader effect's effect texture has been changed + */ + void EffectImageUpdated(); + public: /** * @copydoc Actor::SetShaderEffect @@ -293,13 +267,6 @@ public: // From Actor */ virtual Vector3 GetNaturalSize() const; -private: // From RenderableActor - - /** - * @copydoc RenderableActor::GetRenderableAttachment - */ - virtual RenderableAttachment& GetRenderableAttachment() const; - protected: /** @@ -322,19 +289,22 @@ private: Vector2 CalculateNaturalSize() const; /** - * From Actor; used to trigger fade-in animations. + * @copydoc Dali::Actor::OnRelayout() */ - virtual void OnStageConnectionInternal(); - - /** - * From Actor; used to notify Image. - */ - virtual void OnStageDisconnectionInternal(); + virtual void OnRelayout( const Vector2& size, RelayoutContainer& container ); private: - ImageAttachmentPtr mImageAttachment; ///< Used to display the image (holds a pointer to currently showed Image) - + ShaderEffectPtr mShaderEffect; ///< Optional referenced shader effect + RendererPtr mRenderer; ///< The renderer used to render the image + PixelArea mPixelArea; ///< The pixel area of the image to render + Vector4 mBlendColor; ///< The blend color for this ImageActor + int mRendererIndex; ///< The index location of mRenderer + size_t mTextureIndex; ///< The texture index for this ImageActor's texture + size_t mEffectTextureIndex; ///< The texture index for this ImageActor's effect texture + FilterMode::Type mMinFilter; ///< The minification filter currently set + FilterMode::Type mMagFilter; ///< The magnification filter currently set + bool mIsPixelAreaSet; ///< Flag indicating if the pixel area has been set }; } // namespace Internal diff --git a/dali/internal/event/effects/shader-effect-impl.cpp b/dali/internal/event/effects/shader-effect-impl.cpp index 2b7fe66..fe1acb7 100644 --- a/dali/internal/event/effects/shader-effect-impl.cpp +++ b/dali/internal/event/effects/shader-effect-impl.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -89,56 +90,47 @@ WrapperStrings customImageShaderWrappers = }; /** - * Helper to wrap the program with our default pre and postfix if needed and then send it to update/render thread - * @param[in] effect of the shader + * Helper to wrap the program with our default pre and postfix if needed * @param[in] vertexPrefix from application - * @param[in] fragmentPrefix from application * @param[in] vertexBody from application - * @param[in] fragmentBody from application - * @param[in] modifiesGeometry based on flags and vertex shader */ -void WrapAndSetProgram( Internal::ShaderEffect& effect, - const std::string& vertexPrefix, const std::string& fragmentPrefix, - const std::string& vertexBody, const std::string& fragmentBody, - bool modifiesGeometry ) +std::string WrapVertexShader( const std::string& vertexPrefix, const std::string& vertexBody ) { - // if there is some real data in the strings - if( ( vertexPrefix.length() > 0 ) || - ( fragmentPrefix.length() > 0 ) || - ( vertexBody.length() > 0 ) || - ( fragmentBody.length() > 0 ) ) - { - std::string vertexSource = vertexPrefix; - std::string fragmentSource = fragmentPrefix; - - // Create complete shader program strings: - - vertexSource += customImageShaderWrappers.vertexShaderPrefix; + std::string vertexSource = vertexPrefix + customImageShaderWrappers.vertexShaderPrefix; - // Append the custom vertex shader code if supplied, otherwise append the default - if ( vertexBody.length() > 0 ) - { - vertexSource.append( vertexBody ); - } - else - { - vertexSource.append( customImageShaderWrappers.vertexShaderPostfix ); - } + // Append the custom vertex shader code if supplied, otherwise append the default + if ( vertexBody.length() > 0 ) + { + vertexSource.append( vertexBody ); + } + else + { + vertexSource.append( customImageShaderWrappers.vertexShaderPostfix ); + } - fragmentSource += customImageShaderWrappers.fragmentShaderPrefix; + return vertexSource; +} - // Append the custom fragment shader code if supplied, otherwise append the default - if ( fragmentBody.length() > 0 ) - { - fragmentSource.append( fragmentBody ); - } - else - { - fragmentSource.append( customImageShaderWrappers.fragmentShaderPostfix ); - } +/** + * Helper to wrap the program with our default pre and postfix if needed + * @param[in] fragmentPrefix from application + * @param[in] fragmentBody from application + */ +std::string WrapFragmentShader( const std::string& fragmentPrefix, const std::string& fragmentBody ) +{ + std::string fragmentSource = fragmentPrefix + customImageShaderWrappers.fragmentShaderPrefix; - effect.SendProgramMessage( vertexSource, fragmentSource, modifiesGeometry ); + // Append the custom fragment shader code if supplied, otherwise append the default + if ( fragmentBody.length() > 0 ) + { + fragmentSource.append( fragmentBody ); } + else + { + fragmentSource.append( customImageShaderWrappers.fragmentShaderPostfix ); + } + + return fragmentSource; } std::string GetShader(const std::string& field, const Property::Value& property) @@ -177,8 +169,8 @@ ShaderEffectPtr ShaderEffect::New( Dali::ShaderEffect::GeometryHints hints ) ShaderEffect::ShaderEffect( EventThreadServices& eventThreadServices, Dali::ShaderEffect::GeometryHints hints ) : mEventThreadServices( eventThreadServices ), - mConnectionCount (0), - mGeometryHints( hints ) + mGeometryHints( hints ), + mGridDensity( Dali::ShaderEffect::DEFAULT_GRID_DENSITY ) { mSceneObject = new SceneGraph::Shader( hints ); DALI_ASSERT_DEBUG( NULL != mSceneObject ); @@ -204,55 +196,56 @@ ShaderEffect::~ShaderEffect() void ShaderEffect::SetEffectImage( Dali::Image image ) { // if images are the same, do nothing - if (mImage == image) + if ( mEffectImage == image ) { return; } - if (mImage && mConnectionCount > 0) + if ( mEffectImage && mConnectedActors.size() > 0 ) { // unset previous image - GetImplementation(mImage).Disconnect(); + GetImplementation( mEffectImage ).Disconnect(); } // in case image is empty this will reset our image handle - mImage = image; + mEffectImage = image; - if (!image) + if( image ) { - // mSceneShader can be in a separate thread; queue a setter message - SetTextureIdMessage( mEventThreadServices, *mSceneObject, 0 ); + // tell image that we're using it + if (mConnectedActors.size() > 0) + { + GetImplementation( mEffectImage ).Connect(); + } } - else + + //inform connected actors the image has been unset + for(std::vector< ActorPtr >::iterator it = mConnectedActors.begin(); it != mConnectedActors.end(); ++it ) { - // tell image that we're using it - if (mConnectionCount > 0) + ImageActor* imageActor = dynamic_cast< ImageActor* >( it->Get() ); + if( imageActor ) { - GetImplementation(mImage).Connect(); + imageActor->EffectImageUpdated(); } - // mSceneShader can be in a separate thread; queue a setter message - SetTextureIdMessage( mEventThreadServices, *mSceneObject, GetImplementation(mImage).GetResourceId() ); } } void ShaderEffect::SetUniform( const std::string& name, Property::Value value, UniformCoordinateType uniformCoordinateType ) { - // Register/Set the property + // Register the property if it does not exist Property::Index index = RegisterProperty( name, value ); - // RegisterProperty guarantees a positive value as index - DALI_ASSERT_DEBUG( static_cast(index) >= CustomPropertyStartIndex() ); - unsigned int metaIndex = index - CustomPropertyStartIndex(); - // check if there's space in cache - if( mCoordinateTypes.Count() < (metaIndex + 1) ) - { - mCoordinateTypes.Resize( metaIndex + 1 ); - } - // only send message if the value is different than current, initial value is COORDINATE_TYPE_DEFAULT (0) - if( uniformCoordinateType != mCoordinateTypes[ metaIndex ] ) + Uniform uniform = { name, index, value }; + mUniforms.push_back( uniform ); + + //inform any connected actors + for(std::vector< ActorPtr >::iterator it = mConnectedActors.begin(); it != mConnectedActors.end(); ++it) { - mCoordinateTypes[ metaIndex ] = uniformCoordinateType; - SetCoordinateTypeMessage( mEventThreadServices, *mSceneObject, metaIndex, uniformCoordinateType ); + ImageActor* imageActor = dynamic_cast< ImageActor* >( (*it).Get() ); + if( imageActor ) + { + imageActor->EffectUniformUpdated( uniform ); + } } } @@ -264,56 +257,42 @@ void ShaderEffect::SetPrograms( const string& vertexSource, const string& fragme void ShaderEffect::SetPrograms( const std::string& vertexPrefix, const std::string& fragmentPrefix, const std::string& vertexSource, const std::string& fragmentSource ) { - bool modifiesGeometry = true; - // check if the vertex shader is empty (means it cannot modify geometry) - if( (vertexPrefix.length() == 0) && (vertexSource.length() == 0) ) - { - modifiesGeometry = false; - } - // check the hint second - if( ( mGeometryHints & Dali::ShaderEffect::HINT_DOESNT_MODIFY_GEOMETRY ) != 0 ) - { - modifiesGeometry = false; - } - - WrapAndSetProgram( *this, vertexPrefix, fragmentPrefix, vertexSource, fragmentSource, modifiesGeometry ); + mVertexSource = WrapVertexShader( vertexPrefix, vertexSource ); + mFragmentSource = WrapFragmentShader( fragmentPrefix, fragmentSource ); } -void ShaderEffect::SendProgramMessage( const string& vertexSource, const string& fragmentSource, - bool modifiesGeometry ) +void ShaderEffect::Connect( ActorPtr actor ) { - ThreadLocalStorage& tls = ThreadLocalStorage::Get(); - ShaderFactory& shaderFactory = tls.GetShaderFactory(); - size_t shaderHash; + if( !actor ) + { + return; + } - Internal::ShaderDataPtr shaderData = shaderFactory.Load( vertexSource, fragmentSource, shaderHash ); - DALI_ASSERT_DEBUG( shaderHash != 0U ); + std::vector< ActorPtr >::const_iterator it = std::find( mConnectedActors.begin(), mConnectedActors.end(), actor ); + if( it == mConnectedActors.end() ) + { + mConnectedActors.push_back( actor ); + } - // Add shader program to scene-object using a message to the UpdateManager - SetShaderProgramMessage( mEventThreadServices.GetUpdateManager(), *mSceneObject, shaderData, modifiesGeometry ); + if( mEffectImage && mConnectedActors.size() == 1 ) + { + GetImplementation( mEffectImage ).Connect(); + } } - -void ShaderEffect::Connect() +void ShaderEffect::Disconnect( ActorPtr actor ) { - ++mConnectionCount; - - if (mImage && mConnectionCount == 1) + if( !actor ) { - GetImplementation(mImage).Connect(); - - // Image may have changed resource due to load/release policy. Ensure correct texture ID is set on scene graph object - SetTextureIdMessage( mEventThreadServices, *mSceneObject, GetImplementation(mImage).GetResourceId() ); + return; } -} -void ShaderEffect::Disconnect() -{ - DALI_ASSERT_DEBUG(mConnectionCount > 0); - --mConnectionCount; + DALI_ASSERT_DEBUG(mConnectedActors.size() > 0); + std::vector< ActorPtr >::iterator match( std::remove( mConnectedActors.begin(), mConnectedActors.end(), actor ) ); + mConnectedActors.erase( match, mConnectedActors.end() ); - if (mImage && mConnectionCount == 0) + if (mEffectImage && mConnectedActors.size() == 0) { - GetImplementation(mImage).Disconnect(); + GetImplementation(mEffectImage).Disconnect(); } } @@ -392,7 +371,16 @@ void ShaderEffect::SetDefaultProperty( Property::Index index, const Property::Va { case Dali::ShaderEffect::Property::GRID_DENSITY: { - SetGridDensityMessage( mEventThreadServices, *mSceneObject, propertyValue.Get() ); + propertyValue.Get( mGridDensity ); + if( ( mGeometryHints & Dali::ShaderEffect::HINT_GRID_X ) || + ( mGeometryHints & Dali::ShaderEffect::HINT_GRID_Y ) ) + { + //inform all the connected actors + for(std::vector< ActorPtr >::iterator it = mConnectedActors.begin(); it != mConnectedActors.end(); ++it ) + { + (*it)->RelayoutRequest(); + } + } break; } @@ -423,43 +411,40 @@ void ShaderEffect::SetDefaultProperty( Property::Index index, const Property::Va case Dali::ShaderEffect::Property::GEOMETRY_HINTS: { - Dali::ShaderEffect::GeometryHints hint = Dali::ShaderEffect::HINT_NONE; + mGeometryHints = Dali::ShaderEffect::HINT_NONE; std::string s = propertyValue.Get(); if(s == "HINT_NONE") { - hint = Dali::ShaderEffect::HINT_NONE; + mGeometryHints = Dali::ShaderEffect::HINT_NONE; } else if(s == "HINT_GRID_X") { - hint = Dali::ShaderEffect::HINT_GRID_X; + mGeometryHints = Dali::ShaderEffect::HINT_GRID_X; } else if(s == "HINT_GRID_Y") { - hint = Dali::ShaderEffect::HINT_GRID_Y; + mGeometryHints = Dali::ShaderEffect::HINT_GRID_Y; } else if(s == "HINT_GRID") { - hint = Dali::ShaderEffect::HINT_GRID; + mGeometryHints = Dali::ShaderEffect::HINT_GRID; } else if(s == "HINT_DEPTH_BUFFER") { - hint = Dali::ShaderEffect::HINT_DEPTH_BUFFER; + mGeometryHints = Dali::ShaderEffect::HINT_DEPTH_BUFFER; } else if(s == "HINT_BLENDING") { - hint = Dali::ShaderEffect::HINT_BLENDING; + mGeometryHints = Dali::ShaderEffect::HINT_BLENDING; } else if(s == "HINT_DOESNT_MODIFY_GEOMETRY") { - hint = Dali::ShaderEffect::HINT_DOESNT_MODIFY_GEOMETRY; + mGeometryHints = Dali::ShaderEffect::HINT_DOESNT_MODIFY_GEOMETRY; } else { DALI_ASSERT_ALWAYS(!"Geometry hint unknown" ); } - - SetHintsMessage( mEventThreadServices, *mSceneObject, hint ); - break; } @@ -477,16 +462,6 @@ Property::Value ShaderEffect::GetDefaultProperty(Property::Index /*index*/) cons return Property::Value(); } -void ShaderEffect::NotifyScenePropertyInstalled( const SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index ) const -{ - // Warning - the property is added to the Shader object in the Update thread and the meta-data is added in the Render thread (through a secondary message) - - // mSceneObject requires metadata for each custom property (uniform) - UniformMeta* meta = UniformMeta::New( name, newProperty, Dali::ShaderEffect::COORDINATE_TYPE_DEFAULT ); - // mSceneObject is being used in a separate thread; queue a message to add the property - InstallUniformMetaMessage( mEventThreadServices, *mSceneObject, *meta ); // Message takes ownership -} - const SceneGraph::PropertyOwner* ShaderEffect::GetSceneObject() const { return mSceneObject; diff --git a/dali/internal/event/effects/shader-effect-impl.h b/dali/internal/event/effects/shader-effect-impl.h index 2ccc768..2443804 100644 --- a/dali/internal/event/effects/shader-effect-impl.h +++ b/dali/internal/event/effects/shader-effect-impl.h @@ -21,6 +21,7 @@ // INTERNAL INCLUDES #include #include +#include #include #include #include @@ -47,12 +48,15 @@ class ShaderEffect : public Object public: typedef Dali::ShaderEffect::UniformCoordinateType UniformCoordinateType; - enum GeometryState + struct Uniform { - DOESNT_MODIFY_GEOMETRY, - MODIFIES_GEOMETRY + std::string mName; + Property::Index mIndex; + Property::Value mValue; }; + typedef std::vector< Uniform > UniformArray; + /** * Create a new ShaderEffect with no programs * @param hints GeometryHints to define the geometry of the rendered object @@ -73,6 +77,20 @@ public: UniformCoordinateType uniformCoordinateType ); /** + * Returns the uniforms set for the shaders + * + * @return Returns and array of uniforms set for the shaders + */ + const UniformArray& GetUniforms() {return mUniforms;} + + /** + * Returns the GeometryHints used + * + * @return Returns the GeometryHints used + */ + Dali::ShaderEffect::GeometryHints GetGeometryHints() const {return mGeometryHints;} + + /** * Add a GeometryType specific default program to this ShaderEffect * @param[in] geometryType The GeometryType rendered by the shader program * @param[in] vertexSource The source code for the vertex shader @@ -93,23 +111,41 @@ public: const std::string& vertexSource, const std::string& fragmentSource ); /** - * Send shader program to scene-graph object. - * @param[in] vertexSource The source code for the vertex shader - * @param[in] fragmentSource The source code for the fragment shader - * @param[in] modifiesGeometry True if the shader modifies geometry + * @brief Notify ShaderEffect that it's being used by an Actor. + * + * @param[in] actor The Actor that is connecting to this ShaderEffect + */ + void Connect( ActorPtr actor ); + + /** + * @brief Notify ShaderEffect that an Actor is no longer using it. + * + * @param[in] actor The Actor that is disconnecting from this ShaderEffect */ - void SendProgramMessage( const std::string& vertexSource, const std::string& fragmentSource, - bool modifiesGeometry ); + void Disconnect( ActorPtr actor ); + +public: + + /** + * Returns the vertex shader for this ShaderEffect + * + * @return Returns the vertex shader for this ShaderEffect + */ + const std::string& GetVertexShader() const {return mVertexSource;} /** - * Notify ShaderEffect that it's being used by an Actor. + * Returns the fragment shader for this ShaderEffect + * + * @return Returns the fragment shader for this ShaderEffect */ - void Connect(); + const std::string& GetFragmentShader() const {return mFragmentSource;} /** - * Notify ShaderEffect that an Actor is no longer using it. + * Returns the fragment shader for this ShaderEffect + * + * @return Returns the fragment shader for this ShaderEffect */ - void Disconnect(); + Dali::Image GetEffectImage() const {return mEffectImage;} public: // Default property extensions from Object @@ -164,11 +200,6 @@ public: // Default property extensions from Object virtual Property::Value GetDefaultProperty( Property::Index index ) const; /** - * @copydoc Dali::Internal::Object::NotifyScenePropertyInstalled() - */ - virtual void NotifyScenePropertyInstalled( const SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index ) const; - - /** * @copydoc Dali::Internal::Object::GetSceneObject() */ virtual const SceneGraph::PropertyOwner* GetSceneObject() const; @@ -204,13 +235,18 @@ private: ShaderEffect& operator=( const ShaderEffect& rhs ); private: // Data - EventThreadServices& mEventThreadServices; ///< Event thread services, for sending messages - SceneGraph::Shader* mSceneObject; ///< pointer to the scene shader, should not be changed on this thread - Dali::Image mImage; ///< Client-side handle for the effect image - unsigned int mConnectionCount; ///< number of on-stage ImageActors using this shader effect - Dali::ShaderEffect::GeometryHints mGeometryHints; ///< shader geometry hints for building the geometry - Dali::Vector< UniformCoordinateType > mCoordinateTypes; ///< cached to avoid sending tons of unnecessary messages + std::vector< ActorPtr > mConnectedActors; ///< The array of actors that are currently connected to this ShaderEffect + UniformArray mUniforms; ///< The array of uniforms set for this ShaderEffect + + std::string mVertexSource; ///< The vertex shader source + std::string mFragmentSource; ///< The fragment shader source + + EventThreadServices& mEventThreadServices; ///< Event thread services, for sending messages + SceneGraph::Shader* mSceneObject; ///< Pointer to the scene shader, should not be changed on this thread + Dali::Image mEffectImage; ///< The Client-side handle to the effect image + Dali::ShaderEffect::GeometryHints mGeometryHints; ///< shader geometry hints for building the geometry + float mGridDensity; ///< The grid denisty }; } // namespace Internal diff --git a/dali/internal/event/effects/shader-factory.cpp b/dali/internal/event/effects/shader-factory.cpp index 64100a0..865bdbd 100644 --- a/dali/internal/event/effects/shader-factory.cpp +++ b/dali/internal/event/effects/shader-factory.cpp @@ -149,8 +149,6 @@ void ShaderFactory::SaveBinary( Internal::ShaderDataPtr shaderData ) void ShaderFactory::LoadDefaultShaders() { mDefaultShader = ShaderEffect::New(); - - mDefaultShader->SendProgramMessage( ImageVertex, ImageFragment, false ); } void ShaderFactory::MemoryCacheInsert( ShaderData& shaderData ) diff --git a/dali/internal/event/events/hit-test-algorithm-impl.cpp b/dali/internal/event/events/hit-test-algorithm-impl.cpp index 4b66841..604f71e 100644 --- a/dali/internal/event/events/hit-test-algorithm-impl.cpp +++ b/dali/internal/event/events/hit-test-algorithm-impl.cpp @@ -218,12 +218,7 @@ HitActor HitTestWithinLayer( Actor& actor, hit.distance = distance; hit.depth = actor.GetHierarchyDepth() * Dali::Layer::TREE_DEPTH_MULTIPLIER; - // Is this actor an Image Actor or contains a renderer? - if ( ImageActor* imageActor = dynamic_cast< ImageActor* >( &actor ) ) - { - hit.depth += imageActor->GetDepthIndex(); - } - else if ( actor.GetRendererCount() > 0 ) + if ( actor.GetRendererCount() > 0 ) { //Get renderer with maximum depth int rendererMaxDepth(actor.GetRendererAt( 0 ).Get()->GetDepthIndex()); diff --git a/dali/internal/event/rendering/material-impl.cpp b/dali/internal/event/rendering/material-impl.cpp index 4e0a86c..6539d08 100644 --- a/dali/internal/event/rendering/material-impl.cpp +++ b/dali/internal/event/rendering/material-impl.cpp @@ -147,6 +147,16 @@ void Material::SetTextureSampler( size_t index, Sampler* sampler ) } } +Sampler* Material::GetTextureSampler( size_t index ) const +{ + if( index < GetNumberOfTextures() ) + { + return mTextures[index].mSampler.Get(); + } + + return NULL; +} + void Material::SetTextureUniformName( size_t index, const std::string& uniformName ) { if( index < GetNumberOfTextures() ) @@ -156,7 +166,7 @@ void Material::SetTextureUniformName( size_t index, const std::string& uniformNa } } -int Material::GetTextureIndex( const std::string& uniformName ) +int Material::GetTextureIndex( const std::string& uniformName ) const { size_t textureCount(GetNumberOfTextures()); for( size_t i(0); i #include #include -#include #include #include #include @@ -424,12 +423,6 @@ void UpdateManager::AttachToNode( Node* node, NodeAttachment* attachment ) // attach node to attachment first so that parent is known by the time attachment is connected node->Attach( *attachment ); // node takes ownership - - // @todo MESH_REWORK Remove after merge of SceneGraph::RenderableAttachment and SceneGraph::RendererAttachment - if( dynamic_cast( attachment ) != NULL ) - { - attachment->Initialize( *mImpl->sceneController, mSceneGraphBuffers.GetUpdateBufferIndex() ); - } } void UpdateManager::AddObject( PropertyOwner* object ) diff --git a/dali/internal/update/node-attachments/scene-graph-image-attachment-debug.h b/dali/internal/update/node-attachments/scene-graph-image-attachment-debug.h deleted file mode 100644 index ef950ed..0000000 --- a/dali/internal/update/node-attachments/scene-graph-image-attachment-debug.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef __DALI_SCENE_GRAPH_IMAGE_ATTACHMENT_DEBUG_H__ -#define __DALI_SCENE_GRAPH_IMAGE_ATTACHMENT_DEBUG_H__ - -/* - * Copyright (c) 2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -namespace Dali -{ -namespace Internal -{ -namespace SceneGraph -{ - -#if defined(DEBUG_ENABLED) -Debug::Filter* gImageAttachmentLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_SCENE_GRAPH_IMAGE_ATTACHMENT"); - -#define ATTACHMENT_LOG(level) \ - DALI_LOG_INFO(gImageAttachmentLogFilter, level, "SceneGraph::ImageAttachment::%s: this:%p\n", __FUNCTION__, this) -#define ATTACHMENT_LOG_FMT(level, format, args...) \ - DALI_LOG_INFO(gImageAttachmentLogFilter, level, "SceneGraph::ImageAttachment::%s: this:%p " format, __FUNCTION__, this, ## args) - -#else - -#define ATTACHMENT_LOG(level) -#define ATTACHMENT_LOG_FMT(level, format, args...) - -#endif - -} // namespace SceneGraph - -} // namespace Internal - -} // namespace Dali - -#endif // __DALI_SCENE_GRAPH_IMAGE_ATTACHMENT_DEBUG_H__ diff --git a/dali/internal/update/node-attachments/scene-graph-image-attachment.cpp b/dali/internal/update/node-attachments/scene-graph-image-attachment.cpp deleted file mode 100644 index 7f62e42..0000000 --- a/dali/internal/update/node-attachments/scene-graph-image-attachment.cpp +++ /dev/null @@ -1,498 +0,0 @@ -/* - * Copyright (c) 2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// CLASS HEADER -#include - -// INTERNAL INCLUDES -#include -#include -#include - -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include - -namespace Dali -{ - -namespace Internal -{ - -// value types used by messages -template <> struct ParameterType< Render::ImageRenderer::MeshType > -: public BasicType< Render::ImageRenderer::MeshType > {}; - -namespace SceneGraph -{ - -ImageAttachment* ImageAttachment::New( unsigned int textureId ) -{ - return new ImageAttachment( textureId ); -} - -ImageAttachment::ImageAttachment( unsigned int textureId ) -: RenderableAttachment( false ), // no scaling - mImageRenderer( NULL ), - mTextureId( textureId ), - mRefreshMeshData( true ), - mIsPixelAreaSet( false ), - mPreviousRefreshHints( 0 ), - mStyle( Dali::ImageActor::STYLE_QUAD ), - mCullFaceMode( CullNone ) -{ -} - -void ImageAttachment::Initialize2( BufferIndex updateBufferIndex ) -{ - DALI_ASSERT_DEBUG( NULL != mSceneController ); - - // Create main renderer, passing ownership to the render-thread - mImageRenderer = Render::ImageRenderer::New(); - - mSceneController->GetRenderMessageDispatcher().AddRenderer( *mImageRenderer ); - - ATTACHMENT_LOG_FMT(Debug::General, " renderer: %p\n", mImageRenderer); - - if( mTextureId != 0 ) - { - typedef MessageValue1< Render::ImageRenderer, ResourceId > DerivedType; - - // Reserve some memory inside the render queue - unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); - - // Construct message in the render queue memory; note that delete should not be called on the return value - new (slot) DerivedType( mImageRenderer, &Render::ImageRenderer::SetTextureId, mTextureId ); - } - - // After derived classes have (potentially) created their renderer - Render::Renderer& renderer = GetRenderer(); - renderer.SetCullFace( static_cast< Dali::Material::FaceCullingMode >( mCullFaceMode ) ); - - // set the default shader here as well - renderer.SetShader( mShader ); -} - -void ImageAttachment::OnDestroy2() -{ - DALI_ASSERT_DEBUG( NULL != mSceneController ); - - // Request deletion in the next Render - mSceneController->GetRenderMessageDispatcher().RemoveRenderer( *mImageRenderer ); - mImageRenderer = NULL; -} - -void ImageAttachment::ConnectedToSceneGraph() -{ - // Do nothing -} - -void ImageAttachment::DisconnectedFromSceneGraph() -{ - // Do nothing -} - -ImageAttachment::~ImageAttachment() -{ -} - -Render::Renderer& ImageAttachment::GetRenderer() -{ - return *mImageRenderer; -} - -const Render::Renderer& ImageAttachment::GetRenderer() const -{ - return *mImageRenderer; -} - -void ImageAttachment::SetTextureId( BufferIndex updateBufferIndex, unsigned int textureId ) -{ - DALI_ASSERT_DEBUG(mSceneController); - ATTACHMENT_LOG_FMT(Debug::General, " textureid: %d)\n", textureId); - - mTextureId = textureId; - - // Loading is essentially finished if we don't have a resource ID - mFinishedResourceAcquisition = ( 0 == mTextureId ); - - if( mImageRenderer ) - { - typedef MessageValue1< Render::ImageRenderer, ResourceId > DerivedType; - - // Reserve some memory inside the render queue - unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); - - // Construct message in the render queue memory; note that delete should not be called on the return value - new (slot) DerivedType( mImageRenderer, &Render::ImageRenderer::SetTextureId, mTextureId ); - } -} - -void ImageAttachment::SetPixelArea( BufferIndex updateBufferIndex, const PixelArea& pixelArea ) -{ - // update the pixel area information - mIsPixelAreaSet = true; - - { - typedef MessageValue1< Render::ImageRenderer, Render::ImageRenderer::PixelArea > DerivedType; - - // Reserve some memory inside the render queue - unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); - - // Construct message in the render queue memory; note that delete should not be called on the return value - new (slot) DerivedType( mImageRenderer, &Render::ImageRenderer::SetPixelArea, pixelArea ); - } - - // we rely on attachment to not call us unless it actually did change - mRefreshMeshData = true; -} - -void ImageAttachment::ClearPixelArea() -{ - mIsPixelAreaSet = false; - mRefreshMeshData = true; -} - -void ImageAttachment::SetStyle( Dali::ImageActor::Style style ) -{ - if (mStyle != style) - { - mStyle = style; - mRefreshMeshData = true; - } -} - -void ImageAttachment::SetBorder( BufferIndex updateBufferIndex, const Vector4& border, bool inPixels ) -{ - // update the 9 patch border information - - typedef MessageValue2< Render::ImageRenderer, Vector4, bool > DerivedType; - - // Reserve some memory inside the render queue - unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); - - // Construct message in the render queue memory; note that delete should not be called on the return value - new (slot) DerivedType( mImageRenderer, &Render::ImageRenderer::SetNinePatchBorder, border, inPixels ); - - if (mStyle != Dali::ImageActor::STYLE_QUAD) - { - mRefreshMeshData = true; - } -} - -void ImageAttachment::SetBlendingOptions( BufferIndex updateBufferIndex, unsigned int options ) -{ - // Blending options are forwarded to renderer in render-thread - typedef MessageValue1< Render::ImageRenderer, unsigned int > DerivedType; - - // Reserve some memory inside the render queue - unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); - - // Construct message in the render queue memory; note that delete should not be called on the return value - new (slot) DerivedType( mImageRenderer, &Render::ImageRenderer::SetBlendingOptions, options ); -} - -void ImageAttachment::SetBlendColor( BufferIndex updateBufferIndex, const Vector4& color ) -{ - // Blend color is forwarded to renderer in render-thread - typedef MessageValue1< Render::ImageRenderer, Vector4 > DerivedType; - - // Reserve some memory inside the render queue - unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); - - // Construct message in the render queue memory; note that delete should not be called on the return value - new (slot) DerivedType( mImageRenderer, &Render::ImageRenderer::SetBlendColor, color ); -} - -void ImageAttachment::SetCullFace( BufferIndex updateBufferIndex, CullFaceMode mode ) -{ - DALI_ASSERT_DEBUG(mSceneController); - DALI_ASSERT_DEBUG(mode >= CullNone && mode <= CullFrontAndBack); - - mCullFaceMode = mode; - - typedef MessageValue1< Render::Renderer, Dali::Material::FaceCullingMode > DerivedType; - - // Reserve some memory inside the render queue - unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); - - // Construct message in the render queue memory; note that delete should not be called on the return value - new (slot) DerivedType( &GetRenderer(), &Render::Renderer::SetCullFace, static_cast< Dali::Material::FaceCullingMode >( mode ) ); -} - -void ImageAttachment::SetSampler( BufferIndex updateBufferIndex, unsigned int samplerBitfield ) -{ - DALI_ASSERT_DEBUG(mSceneController); - - typedef MessageValue1< Render::Renderer, unsigned int > DerivedType; - - // Reserve some memory inside the render queue - unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); - - // Construct message in the render queue memory; note that delete should not be called on the return value - new (slot) DerivedType( &GetRenderer(), &Render::Renderer::SetSampler, samplerBitfield ); -} - -void ImageAttachment::ApplyShader( BufferIndex updateBufferIndex, Shader* shader ) -{ - mShader = shader; - - // send the message to renderer - SendShaderChangeMessage( updateBufferIndex ); - - // tell derived class to do something - ShaderChanged( updateBufferIndex ); -} - -void ImageAttachment::RemoveShader( BufferIndex updateBufferIndex ) -{ - // return to default shader - mShader = NULL; - - // send the message to renderer - SendShaderChangeMessage( updateBufferIndex ); - - // tell derived class to do something - ShaderChanged( updateBufferIndex ); -} - - -void ImageAttachment::ShaderChanged( BufferIndex updateBufferIndex ) -{ - DALI_ASSERT_DEBUG( mSceneController ); - - int hints = 0; // default shader hints are 0 - if( mShader ) - { - hints = mShader->GetGeometryHints(); - } - if ( hints != mPreviousRefreshHints ) - { - mPreviousRefreshHints = hints; - // (may) need to change geometry - mRefreshMeshData = true; - } -} - -void ImageAttachment::SizeChanged( BufferIndex updateBufferIndex ) -{ - // avoid regenerating geometry if the size did not actually change (visibility change can accumulate a false SizeChanged) - const Vector3& actorSize = GetParent().GetSize( updateBufferIndex ); - if( fabsf( actorSize.width - mGeometrySize.width ) > Math::MACHINE_EPSILON_1 || - fabsf( actorSize.height - mGeometrySize.height ) > Math::MACHINE_EPSILON_1 ) - { - mRefreshMeshData = true; - } -} - -bool ImageAttachment::DoPrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager ) -{ - DALI_LOG_TRACE_METHOD_FMT(gImageAttachmentLogFilter, "this:%p", this); - bool ready = false; - - if( 0 != mTextureId ) - { - // The metadata is used by IsFullyOpaque(), below. - mBitmapMetadata = resourceManager.GetBitmapMetadata( mTextureId ); - - CompleteStatusManager& completeStatusManager = mSceneController->GetCompleteStatusManager(); - CompleteStatusManager::CompleteState status = completeStatusManager.GetStatus( mTextureId ); - - switch( status ) - { - case CompleteStatusManager::NOT_READY: - { - ready = false; - - if( mBitmapMetadata.GetIsFramebuffer() ) - { - ready = true; - } - mFinishedResourceAcquisition = false; - FollowTracker( mTextureId ); - } - break; - - case CompleteStatusManager::COMPLETE: - { - ready = true; - mFinishedResourceAcquisition = true; - } - break; - - case CompleteStatusManager::NEVER: - { - ready = false; - mFinishedResourceAcquisition = true; - } - break; - } - } - else - { - // Loading is essentially finished if we don't have a resource ID - mFinishedResourceAcquisition = true; - } - - ATTACHMENT_LOG_FMT(Debug::General, " ObjName:%s finished:%s ready:%s \n", - DALI_LOG_GET_OBJECT_C_STR(mParent), - mFinishedResourceAcquisition?"T":"F", ready?"T":"F"); - - return ready; -} - -void ImageAttachment::DoPrepareRender( BufferIndex updateBufferIndex ) -{ - DALI_ASSERT_DEBUG( mSceneController && mImageRenderer ); - - ATTACHMENT_LOG_FMT(Debug::General, "ObjName:%s textureId:%d\n", - DALI_LOG_GET_OBJECT_C_STR(mParent), - mTextureId); - - // Check whether we need to refresh the vertex buffer. - if ( mRefreshMeshData ) - { - const Vector3& actorSize = GetParent().GetSize( updateBufferIndex ); - mGeometrySize.x = actorSize.x; - mGeometrySize.y = actorSize.y; - - Render::ImageRenderer::MeshType meshType = Render::ImageRenderer::GRID_QUAD; - - if ( !PreviousHintEnabled( Dali::ShaderEffect::HINT_GRID ) ) - { - if ( mStyle == Dali::ImageActor::STYLE_NINE_PATCH ) - { - meshType = Render::ImageRenderer::NINE_PATCH; - } - else if ( mStyle == Dali::ImageActor::STYLE_NINE_PATCH_NO_CENTER ) - { - meshType = Render::ImageRenderer::NINE_PATCH_NO_CENTER; - } - else - { - meshType = Render::ImageRenderer::QUAD; - } - } - else - { - if ( mStyle == Dali::ImageActor::STYLE_NINE_PATCH ) - { - meshType = Render::ImageRenderer::GRID_NINE_PATCH; - } - else if ( mStyle == Dali::ImageActor::STYLE_NINE_PATCH_NO_CENTER ) - { - meshType = Render::ImageRenderer::GRID_NINE_PATCH_NO_CENTER; - } - else - { - meshType = Render::ImageRenderer::GRID_QUAD; - } - } - - // Recalculate the mesh data in the next render - { - typedef MessageValue3< Render::ImageRenderer, Render::ImageRenderer::MeshType, Vector2, bool > DerivedType; - - // Reserve some memory inside the render queue - unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); - - // Construct message in the render queue memory; note that delete should not be called on the return value - new (slot) DerivedType( mImageRenderer, &Render::ImageRenderer::CalculateMeshData, meshType, mGeometrySize, mIsPixelAreaSet ); - } - - mRefreshMeshData = false; - } -} - -void RenderableAttachment::SetBlendingMode( BlendingMode::Type mode ) -{ - mBlendingMode = mode; -} - -BlendingMode::Type RenderableAttachment::GetBlendingMode() const -{ - return mBlendingMode; -} - -bool ImageAttachment::IsFullyOpaque( BufferIndex updateBufferIndex ) -{ - bool fullyOpaque = true; - - switch( mBlendingMode ) - { - case BlendingMode::OFF: - { - fullyOpaque = true; - break; - } - case BlendingMode::ON: - { - // Blending always. - fullyOpaque = false; - break; - } - case BlendingMode::AUTO: - { - /** - * Fully opaque when... - * 1) not using the alpha channel from the image data - * 2) the inherited color is not transparent nor semi-transparent - * 3) the shader doesn't require blending - */ - fullyOpaque = mBitmapMetadata.IsFullyOpaque(); - - if ( fullyOpaque && mParent ) - { - fullyOpaque = ( mParent->GetWorldColor(updateBufferIndex).a >= FULLY_OPAQUE ); - - if ( fullyOpaque && mShader != NULL ) - { - fullyOpaque = !PreviousHintEnabled( Dali::ShaderEffect::HINT_BLENDING ); - } - } - } - } - return fullyOpaque; -} - -void ImageAttachment::SendShaderChangeMessage( BufferIndex updateBufferIndex ) -{ - typedef MessageValue1< Render::Renderer, Shader* > DerivedType; - // Reserve memory inside the render queue - unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); - // Construct message in the mRenderer queue memory; note that delete should not be called on the return value - new (slot) DerivedType( &GetRenderer(), &Render::Renderer::SetShader, mShader ); -} - - - -} // namespace SceneGraph - -} // namespace Internal - -} // namespace Dali diff --git a/dali/internal/update/node-attachments/scene-graph-image-attachment.h b/dali/internal/update/node-attachments/scene-graph-image-attachment.h deleted file mode 100644 index cb05ae9..0000000 --- a/dali/internal/update/node-attachments/scene-graph-image-attachment.h +++ /dev/null @@ -1,407 +0,0 @@ -#ifndef __DALI_INTERNAL_SCENE_GRAPH_IMAGE_ATTACHMENT_H__ -#define __DALI_INTERNAL_SCENE_GRAPH_IMAGE_ATTACHMENT_H__ - -/* - * Copyright (c) 2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// INTERNAL INCLUDES -#include -#include -#include -#include -#include -#include - -namespace Dali -{ - -namespace Internal -{ - -// value types used by messages -template <> struct ParameterType< Dali::ImageActor::Style > -: public BasicType< Dali::ImageActor::Style > {}; - -namespace Render -{ -class ImageRenderer; -} - -namespace SceneGraph -{ -class Shader; -class RenderQueue; - -/** - * An attachment for rendering images in various ways. - */ -class ImageAttachment : public RenderableAttachment -{ -public: - - typedef Dali::ImageActor::Style Style; - typedef Dali::ImageActor::PixelArea PixelArea; - - /** - * Create a new ImageAttachment. - * @param [in] textureId The resource ID of a texture. - * @return The newly allocated ImageAttachment. - */ - static ImageAttachment* New( unsigned int textureId ); - - /** - * Virtual destructor - */ - virtual ~ImageAttachment(); - - /** - * @copydoc RenderableAttachment::GetRenderer(). - */ - virtual Render::Renderer& GetRenderer(); - - /** - * @copydoc RenderableAttachment::GetRenderer(). - */ - virtual const Render::Renderer& GetRenderer() const; - - /** - * Set the ID used to retrieve a texture from ResourceManager. - * @param[in] updateBufferIndex The current update buffer index. - * @param[in] textureId The texture ID. - */ - void SetTextureId( BufferIndex updateBufferIndex, unsigned int textureId ); - - /** - * Set the area of the texture to display. - * @param[in] updateBufferIndex The current update buffer index. - * @param [in] pixelArea The area to display, in pixels relative to the top-left (0,0) of the image. - */ - void SetPixelArea( BufferIndex updateBufferIndex, const PixelArea& pixelArea ); - - /** - * Query whether a pixel area has been set. - * @return True if a pixel area has been set. - */ - bool IsPixelAreaSet() const - { - return mIsPixelAreaSet; - } - - /** - * Remove any pixel areas specified with SetPixelArea; the entire image will be displayed. - * @pre image must be initialized. - */ - void ClearPixelArea(); - - /** - * Set how the attachment is rendered; the default is STYLE_QUAD. - * @param [in] style The new style. - */ - void SetStyle( Style style ); - - /** - * Retrieve how the attachment is rendered. - * @return The style. - */ - Style GetStyle() - { - return mStyle; - } - - /** - * Set the border; this is applied with STYLE_NINE_PATCH. - * @param [in] updateBufferIndex to use. - * @param [in] border The new border setting. - * @param [in] inPixels if the border is in pixels. - */ - void SetBorder( BufferIndex updateBufferIndex, const Vector4& border, bool inPixels ); - - /** - * Set the blending options. This should only be called from the update-thread. - * @param[in] updateBufferIndex The current update buffer index. - * @param[in] options A bitmask of blending options. - */ - void SetBlendingOptions( BufferIndex updateBufferIndex, unsigned int options ); - - /** - * Set the blend-color. This should only be called from the update-thread. - * @param[in] updateBufferIndex The current update buffer index. - * @param[in] color The new blend-color. - */ - void SetBlendColor( BufferIndex updateBufferIndex, const Vector4& color ); - - /** - * Set the face-culling mode. - * @param[in] updateBufferIndex The current update buffer index. - * @param[in] mode The face-culling mode. - */ - void SetCullFace( BufferIndex updateBufferIndex, CullFaceMode mode ); - - /** - * Set the sampler used to render the texture for this renderable. - * @param[in] updateBufferIndex The current update buffer index. - * @param[in] samplerBitfield The image sampler packed options to set. - */ - void SetSampler( BufferIndex updateBufferIndex, unsigned int samplerBitfield ); - - /** - * Apply a shader on the renderable - * @param[in] updateBufferIndex The current update buffer index. - * @param[in] shader to apply. - */ - void ApplyShader( BufferIndex updateBufferIndex, Shader* shader ); - - /** - * Remove the shader from the renderable - * @param[in] updateBufferIndex The current update buffer index. - */ - void RemoveShader( BufferIndex updateBufferIndex ); - - /** - * Called to notify that the shader might have been changed - * The implementation should recalculate geometry and scale based on the - * hints from the new shader - * @param[in] updateBufferIndex The current update buffer index. - * @return Return true if the geometry changed. - */ - virtual void ShaderChanged( BufferIndex updateBufferIndex ); - - /** - * @copydoc RenderableAttachment::SizeChanged() - */ - virtual void SizeChanged( BufferIndex updateBufferIndex ); - - /** - * @copydoc RenderableAttachment::DoPrepareRender() - */ - virtual void DoPrepareRender( BufferIndex updateBufferIndex ); - - /** - * @copydoc RenderableAttachment::IsFullyOpaque() - */ - virtual bool IsFullyOpaque( BufferIndex updateBufferIndex ); - -protected: - - /** - * Protected constructor - */ - ImageAttachment( unsigned int textureId ); - -private: - /** - * Sends the shader to the renderer - * @param updateBufferIndex for the message buffer - */ - void SendShaderChangeMessage( BufferIndex updateBufferIndex ); - - /** - * @copydoc RenderableAttachment::Initialize2(). - */ - virtual void Initialize2( BufferIndex updateBufferIndex ); - - /** - * @copydoc RenderableAttachment::OnDestroy2(). - */ - virtual void OnDestroy2(); - - /** - * @copydoc NodeAttachment::ConnectedToSceneGraph() - */ - virtual void ConnectedToSceneGraph(); - - /** - * @copydoc NodeAttachment::DisconnectedFromSceneGraph() - */ - virtual void DisconnectedFromSceneGraph(); - - /** - * @copydoc RenderableAttachment::DoPrepareResources() - */ - virtual bool DoPrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager ); - - // Helper to check whether a geometry hint was set - bool PreviousHintEnabled( Dali::ShaderEffect::GeometryHints hint ) const - { - return mPreviousRefreshHints & hint; - } - - // Undefined - ImageAttachment(const ImageAttachment&); - - // Undefined - ImageAttachment& operator=(const ImageAttachment& rhs); - -private: // Data - - Render::ImageRenderer* mImageRenderer; ///< Raw-pointers to renderer that is owned by RenderManager - unsigned int mTextureId; ///< The resource ID for a texture - - // bitfields to fit in single byte - bool mRefreshMeshData : 1; ///< Whether the vertex/index buffers needs regenerating - bool mIsPixelAreaSet : 1; ///< Whether pixel area is set, cached for image actor to be able to ask for it - int mPreviousRefreshHints : 4; ///< The shader geometry hints, when the vertex buffer was last refreshed, 4 bits is enough as there's 4 flags - Style mStyle : 2; ///< rendering style, 2 bits is enough as only 2 values in the enum - CullFaceMode mCullFaceMode : 3; ///< Cullface mode, 3 bits is enough for 4 values - - BitmapMetadata mBitmapMetadata;///< The bitmap metadata - Vector2 mGeometrySize; ///< The size of the currently used geometry - -}; - -// Messages for ImageAttachment - -inline void SetTextureIdMessage( EventThreadServices& eventThreadServices, const ImageAttachment& attachment, unsigned int id ) -{ - typedef MessageDoubleBuffered1< ImageAttachment, unsigned int > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); - - // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &attachment, &ImageAttachment::SetTextureId, id ); -} - -inline void SetPixelAreaMessage( EventThreadServices& eventThreadServices, const ImageAttachment& attachment, const Dali::ImageActor::PixelArea& area ) -{ - typedef MessageDoubleBuffered1< ImageAttachment, Dali::ImageActor::PixelArea > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); - - // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &attachment, &ImageAttachment::SetPixelArea, area ); -} - -inline void ClearPixelAreaMessage( EventThreadServices& eventThreadServices, const ImageAttachment& attachment ) -{ - typedef Message< ImageAttachment > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); - - // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &attachment, &ImageAttachment::ClearPixelArea ); -} - -inline void SetStyleMessage( EventThreadServices& eventThreadServices, const ImageAttachment& attachment, Dali::ImageActor::Style style ) -{ - typedef MessageValue1< ImageAttachment, Dali::ImageActor::Style > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); - - // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &attachment, &ImageAttachment::SetStyle, style ); -} - -inline void SetNinePatchBorderMessage( EventThreadServices& eventThreadServices, const ImageAttachment& attachment, const Vector4& border, bool inPixels ) -{ - typedef MessageDoubleBuffered2< ImageAttachment, Vector4, bool > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); - - // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &attachment, &ImageAttachment::SetBorder, border, inPixels ); -} - -inline void SetSortModifierMessage( EventThreadServices& eventThreadServices, const ImageAttachment& attachment, float modifier ) -{ - typedef MessageValue1< ImageAttachment, float > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); - - // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &attachment, &ImageAttachment::SetSortModifier, modifier ); -} - -inline void SetCullFaceMessage( EventThreadServices& eventThreadServices, const ImageAttachment& attachment, CullFaceMode mode ) -{ - typedef MessageDoubleBuffered1< ImageAttachment, CullFaceMode > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); - - // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &attachment, &ImageAttachment::SetCullFace, mode ); -} - -inline void SetBlendingOptionsMessage( EventThreadServices& eventThreadServices, const ImageAttachment& attachment, unsigned int options ) -{ - typedef MessageDoubleBuffered1< ImageAttachment, unsigned int > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); - - new (slot) LocalType( &attachment, &ImageAttachment::SetBlendingOptions, options ); -} - -inline void SetBlendColorMessage( EventThreadServices& eventThreadServices, const ImageAttachment& attachment, const Vector4& color ) -{ - typedef MessageDoubleBuffered1< ImageAttachment, Vector4 > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); - - new (slot) LocalType( &attachment, &ImageAttachment::SetBlendColor, color ); -} - -inline void SetSamplerMessage( EventThreadServices& eventThreadServices, const ImageAttachment& attachment, unsigned int samplerBitfield ) -{ - typedef MessageDoubleBuffered1< ImageAttachment, unsigned int > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); - - // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &attachment, &ImageAttachment::SetSampler, samplerBitfield ); -} - -inline void ApplyShaderMessage( EventThreadServices& eventThreadServices, const ImageAttachment& attachment, const Shader& constShader ) -{ - // Update thread can edit the object - Shader& shader = const_cast< Shader& >( constShader ); - - typedef MessageDoubleBuffered1< ImageAttachment, Shader* > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); - - // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &attachment, &ImageAttachment::ApplyShader, &shader ); -} - -inline void RemoveShaderMessage( EventThreadServices& eventThreadServices, const ImageAttachment& attachment ) -{ - typedef MessageDoubleBuffered0< ImageAttachment > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); - - // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &attachment, &ImageAttachment::RemoveShader ); -} - -} // namespace SceneGraph - -} // namespace Internal - -} // namespace Dali - -#endif // __DALI_INTERNAL_SCENE_GRAPH_IMAGE_ATTACHMENT_H__ diff --git a/dali/public-api/actors/image-actor.cpp b/dali/public-api/actors/image-actor.cpp index d93f0ba..8599880 100644 --- a/dali/public-api/actors/image-actor.cpp +++ b/dali/public-api/actors/image-actor.cpp @@ -104,22 +104,24 @@ ImageActor::PixelArea ImageActor::GetPixelArea() const void ImageActor::SetStyle(Style style) { - GetImplementation(*this).SetStyle(style); + //deprecated - use ImageView instead for nine patch } ImageActor::Style ImageActor::GetStyle() const { - return GetImplementation(*this).GetStyle(); + //deprecated - use ImageView instead for nine patch + return ImageActor::STYLE_QUAD; } void ImageActor::SetNinePatchBorder(const Vector4& border) { - GetImplementation(*this).SetNinePatchBorder(border, true/*in pixels*/); + //deprecated - use ImageView instead for nine patch } Vector4 ImageActor::GetNinePatchBorder() const { - return GetImplementation(*this).GetNinePatchBorder(); + //deprecated - use ImageView instead for nine patch + return Vector4::ZERO; } void ImageActor::SetSortModifier(float modifier) diff --git a/dali/public-api/actors/image-actor.h b/dali/public-api/actors/image-actor.h index c97d724..bc49566 100644 --- a/dali/public-api/actors/image-actor.h +++ b/dali/public-api/actors/image-actor.h @@ -76,16 +76,17 @@ public: enum { PIXEL_AREA = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX, ///< name "pixelArea", type Rect - STYLE, ///< name "style", type std::string - BORDER, ///< name "border", type Vector4 + STYLE, ///< @deprecated Dali 1.1.11 name "style", type std::string + BORDER, ///< @deprecated Dali 1.1.11 name "border", type Vector4 IMAGE, ///< name "image", type Map {"filename":"", "loadPolicy":...} }; }; /** + * @deprecated DALi 1.1.11, only quad style supported, use ImageView instead for nine patch + * * @brief Style determines how the Image is rendered. * - * @code * STYLE_QUAD: * * 0---------2 0-----------------2 @@ -103,53 +104,12 @@ public: * Image is rendered as a textured rectangle. The texture * is scaled uniformly as the quad is resized. * - * STYLE_NINE_PATCH: - * - * |---|---------------|---| |---|-----------------------------|---| - * | 1 | 2 | 3 | | 1 | 2 | 3 | - * |---|---------------|---| |---|-----------------------------|---| - * | | | | | | | | - * | | | | | | | | - * | 4 | 5 | 6 | SCALE | | | | - * | | | | ----> | | | | - * | | | | | 4 | 5 | 6 | - * |-------------------|---| | | | | - * | 7 | 8 | 9 | | | | | - * |---|---------------|---| | | | | - * |---------------------------------|---| - * | 7 | 8 | 9 | - * |---|-----------------------------|---| - * - * Image is rendered as a textured rectangle. The texture - * is scaled differently over each of the 9 sections. - * - * STYLE_NINE_PATCH_NO_CENTER: - * - * Image is rendered in the same way as STYLE_NINE_PATCH, - * but the Center Section (5) is not rendered. - * @endcode - * - * Visualise a Picture Frame: - * - * - Corner sections (1,3,7,9) are not scaled, regardless - * of how big the Image is. - * - Horizontal edge sections (2,8) are scaled only in the - * X axis as the image increases in width. - * - Vertical edge sections (4,6) are scaled only in the - * Y axis as the image increases in height. - * - Center section (5) is scaled in both X and Y axes as - * the image increases in width and/or height. - * - * Note: If GRID hints are enabled (via a Shader that requires it), - * the above geometry will be further subdivided into rectangles of - * approx. 40x40 in size. STYLE_NINE_PATCH_NO_CENTER is not supported - * yet when GRID hints are enabled. */ enum Style { STYLE_QUAD, ///< As a simple quad. - STYLE_NINE_PATCH, ///< As a nine-patch. - STYLE_NINE_PATCH_NO_CENTER ///< As a nine-patch without center section being rendered. + STYLE_NINE_PATCH, ///< @deprecated Dali 1.1.11 As a nine-patch. + STYLE_NINE_PATCH_NO_CENTER ///< @deprecated Dali 1.1.11 As a nine-patch without center section being rendered. }; /** @@ -276,6 +236,8 @@ public: PixelArea GetPixelArea() const; /** + * @deprecated DALi 1.1.11, use ImageView instead + * * @brief Set how the image is rendered; the default is STYLE_QUAD. * * @pre image must be initialized. @@ -284,6 +246,8 @@ public: void SetStyle(Style style); /** + * @deprecated DALi 1.1.11, use ImageView instead + * * @brief Query how the image is rendered. * * @pre image must be initialized. @@ -292,6 +256,8 @@ public: Style GetStyle() const; /** + * @deprecated DALi 1.1.11, use ImageView instead + * * @brief Set the border used with STYLE_NINE_PATCH. * * The values are in pixels from the left, top, right, and bottom of the image respectively. @@ -301,6 +267,8 @@ public: void SetNinePatchBorder(const Vector4& border); /** + * @deprecated DALi 1.1.11, use ImageView instead + * * @brief Retrieve the border used with STYLE_NINE_PATCH. * * @return The nine-patch border. diff --git a/dali/public-api/shader-effects/shader-effect.h b/dali/public-api/shader-effects/shader-effect.h index 856d589..1ab3fc9 100644 --- a/dali/public-api/shader-effects/shader-effect.h +++ b/dali/public-api/shader-effects/shader-effect.h @@ -164,8 +164,8 @@ public: enum UniformCoordinateType { COORDINATE_TYPE_DEFAULT, ///< Default, No transformation to be applied - COORDINATE_TYPE_VIEWPORT_POSITION, ///< The uniform is a position vector in viewport coordinates that needs to be converted to GL view space coordinates. - COORDINATE_TYPE_VIEWPORT_DIRECTION ///< The uniform is a directional vector in viewport coordinates that needs to be converted to GL view space coordinates. + COORDINATE_TYPE_VIEWPORT_POSITION, ///< @deprecated Dali 1.1.11 The uniform is a position vector in viewport coordinates that needs to be converted to GL view space coordinates. + COORDINATE_TYPE_VIEWPORT_DIRECTION ///< @deprecated Dali 1.1.11 The uniform is a directional vector in viewport coordinates that needs to be converted to GL view space coordinates. }; /** -- 2.7.4