X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fshadow-view%2Fshadow-view-impl.cpp;h=3a865887df41660421924edcca57b574d8ba5a68;hp=b64ce97fd61cc9ec471f0e67c83d54bf755b9395;hb=67c2962f7cb1a545a6ad10b8147c8558cc6f45ca;hpb=84e05cec3039abe8ecaaa950d4f93dd4f94282fe diff --git a/dali-toolkit/internal/controls/shadow-view/shadow-view-impl.cpp b/dali-toolkit/internal/controls/shadow-view/shadow-view-impl.cpp index b64ce97..3a86588 100644 --- a/dali-toolkit/internal/controls/shadow-view/shadow-view-impl.cpp +++ b/dali-toolkit/internal/controls/shadow-view/shadow-view-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -31,8 +31,11 @@ // INTERNAL INCLUDES #include +#include +#include #include #include +#include // TODO: // pixel format / size - set from JSON @@ -86,38 +89,6 @@ const char* const SHADER_SHADOW_COLOR_PROPERTY_NAME = "uShadowColor"; const char* const BLUR_STRENGTH_PROPERTY_NAME = "BlurStrengthProperty"; const char* const SHADOW_COLOR_PROPERTY_NAME = "ShadowColorProperty"; -const char* const RENDER_SHADOW_VERTEX_SOURCE = - - " attribute mediump vec2 aPosition;\n" - " uniform mediump mat4 uMvpMatrix;\n" - " uniform mediump mat4 uModelMatrix;\n" - " uniform vec3 uSize;\n" - " varying vec2 vTexCoord;\n" - - " uniform mediump mat4 uLightCameraProjectionMatrix;\n" - " uniform mediump mat4 uLightCameraViewMatrix;\n" - "\n" - "void main()\n" - "{\n" - " mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n" - " vertexPosition.xyz *= uSize;\n" - " gl_Position = uMvpMatrix * vertexPosition;\n" - " vec4 textureCoords = uLightCameraProjectionMatrix * uLightCameraViewMatrix * uModelMatrix * vertexPosition;\n" - " vTexCoord = 0.5 + 0.5 * (textureCoords.xy/textureCoords.w);\n" - "}\n"; - -const char* const RENDER_SHADOW_FRAGMENT_SOURCE = - "varying mediump vec2 vTexCoord;\n" - "uniform lowp vec4 uShadowColor;\n" - "uniform sampler2D sTexture;\n" - - "void main()\n" - "{\n" - " lowp float alpha;\n" - " alpha = texture2D(sTexture, vec2(vTexCoord.x, vTexCoord.y)).a;\n" - " gl_FragColor = vec4(uShadowColor.rgb, uShadowColor.a * alpha);\n" - "}\n"; - } // namespace ShadowView::ShadowView( float downsampleWidthScale, float downsampleHeightScale ) @@ -153,19 +124,24 @@ void ShadowView::SetShadowPlaneBackground(Actor shadowPlaneBackground) { mShadowPlaneBg = shadowPlaneBackground; - mShadowPlane = Toolkit::ImageView::New( mOutputImage ); - mShadowPlane.SetName( "SHADOW_PLANE" ); - mShadowPlane.SetParentOrigin(ParentOrigin::CENTER); - mShadowPlane.SetAnchorPoint(AnchorPoint::CENTER); + mShadowPlane = Actor::New(); + mShadowPlane.SetProperty( Actor::Property::NAME, "SHADOW_PLANE" ); + mShadowPlane.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mShadowPlane.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER ); + Renderer shadowRenderer = CreateRenderer( SHADER_SHADOW_VIEW_RENDER_SHADER_VERT, SHADER_SHADOW_VIEW_RENDER_SHADER_FRAG, + Shader::Hint::OUTPUT_IS_TRANSPARENT, + Uint16Pair(20,20) ); + TextureSet textureSet = shadowRenderer.GetTextures(); + textureSet.SetTexture( 0u, mOutputFrameBuffer.GetColorTexture() ); + mShadowPlane.AddRenderer( shadowRenderer ); - mShadowPlane.SetProperty( Toolkit::ImageView::Property::IMAGE, mShadowVisualMap ); SetShaderConstants(); // Rather than parent the shadow plane drawable and have constraints to move it to the same // position, instead parent the shadow plane drawable on the shadow plane passed in. - mShadowPlaneBg.Add(mShadowPlane); - mShadowPlane.SetParentOrigin(ParentOrigin::CENTER); - mShadowPlane.SetZ(1.0f); + mShadowPlaneBg.Add( mShadowPlane ); + mShadowPlane.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mShadowPlane.SetProperty( Actor::Property::POSITION_Z, 1.0f ); ConstrainCamera(); @@ -205,7 +181,7 @@ void ShadowView::SetShadowColor(Vector4 color) void ShadowView::Activate() { - DALI_ASSERT_ALWAYS( Self().OnStage() && "ShadowView should be on stage before calling Activate()\n" ); + DALI_ASSERT_ALWAYS( Self().GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) && "ShadowView should be on stage before calling Activate()\n" ); // make sure resources are allocated and start the render tasks processing CreateRenderTasks(); @@ -213,7 +189,7 @@ void ShadowView::Activate() void ShadowView::Deactivate() { - DALI_ASSERT_ALWAYS( Self().OnStage() && "ShadowView should be on stage before calling Deactivate()\n" ) + DALI_ASSERT_ALWAYS( Self().GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) && "ShadowView should be on stage before calling Deactivate()\n" ) // stop render tasks processing // Note: render target resources are automatically freed since we set the Image::Unused flag @@ -228,36 +204,28 @@ void ShadowView::Deactivate() void ShadowView::OnInitialize() { // root actor to parent all user added actors. Used as source actor for shadow render task. - mChildrenRoot.SetParentOrigin( ParentOrigin::CENTER ); + mChildrenRoot.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); mChildrenRoot.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); Vector2 stageSize = Stage::GetCurrent().GetSize(); mCameraActor = CameraActor::New(stageSize); - mCameraActor.SetParentOrigin( ParentOrigin::CENTER ); + mCameraActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); // Target is constrained to point at the shadow plane origin mCameraActor.SetNearClippingPlane( 1.0f ); mCameraActor.SetType( Dali::Camera::FREE_LOOK ); // Camera orientation constrained to point at shadow plane world position - mCameraActor.SetOrientation(Radian(Degree(180)), Vector3::YAXIS); - mCameraActor.SetPosition(DEFAULT_LIGHT_POSITION); - - - Property::Map customShader; - customShader[ Toolkit::Visual::Shader::Property::VERTEX_SHADER ] = RENDER_SHADOW_VERTEX_SOURCE; - customShader[ Toolkit::Visual::Shader::Property::FRAGMENT_SHADER ] = RENDER_SHADOW_FRAGMENT_SOURCE; - - customShader[ Toolkit::Visual::Shader::Property::SUBDIVIDE_GRID_X ] = 20; - customShader[ Toolkit::Visual::Shader::Property::SUBDIVIDE_GRID_Y ] = 20; - - customShader[ Toolkit::Visual::Shader::Property::HINTS ] = Shader::Hint::OUTPUT_IS_TRANSPARENT; - - mShadowVisualMap[ Toolkit::Visual::Property::SHADER ] = customShader; + mCameraActor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Radian(Degree(180)), Vector3::YAXIS) ); + mCameraActor.SetProperty( Actor::Property::POSITION, DEFAULT_LIGHT_POSITION ); // Create render targets needed for rendering from light's point of view - mSceneFromLightRenderTarget = FrameBufferImage::New( stageSize.width, stageSize.height, Pixel::RGBA8888 ); + mSceneFromLightRenderTarget = FrameBuffer::New( stageSize.width, stageSize.height, FrameBuffer::Attachment::NONE ); + Texture textureFromLight = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, unsigned(stageSize.width), unsigned(stageSize.height) ); + mSceneFromLightRenderTarget.AttachColorTexture( textureFromLight ); - mOutputImage = FrameBufferImage::New( stageSize.width * 0.5f, stageSize.height * 0.5f, Pixel::RGBA8888 ); + mOutputFrameBuffer = FrameBuffer::New( stageSize.width * 0.5f, stageSize.height * 0.5f, FrameBuffer::Attachment::NONE ); + Texture outputTexture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, unsigned(stageSize.width * 0.5f), unsigned(stageSize.height * 0.5f) ); + mOutputFrameBuffer.AttachColorTexture( outputTexture ); ////////////////////////////////////////////////////// // Connect to actor tree @@ -265,23 +233,23 @@ void ShadowView::OnInitialize() Self().Add( mChildrenRoot ); Stage::GetCurrent().Add( mCameraActor ); - mBlurFilter.SetRefreshOnDemand(false); - mBlurFilter.SetInputImage(mSceneFromLightRenderTarget); - mBlurFilter.SetOutputImage(mOutputImage); - mBlurFilter.SetSize(stageSize * 0.5f); - mBlurFilter.SetPixelFormat(Pixel::RGBA8888); + mBlurFilter.SetRefreshOnDemand( false ); + mBlurFilter.SetInputTexture( mSceneFromLightRenderTarget.GetColorTexture() ); + mBlurFilter.SetOutputFrameBuffer( mOutputFrameBuffer ); + mBlurFilter.SetSize( stageSize * 0.5f ); + mBlurFilter.SetPixelFormat( Pixel::RGBA8888 ); mBlurRootActor = Actor::New(); - mBlurRootActor.SetName( "BLUR_ROOT_ACTOR" ); + mBlurRootActor.SetProperty( Actor::Property::NAME, "BLUR_ROOT_ACTOR" ); // Turn off inheritance to ensure filter renders properly - mBlurRootActor.SetParentOrigin( ParentOrigin::CENTER ); - mBlurRootActor.SetInheritPosition(false); - mBlurRootActor.SetInheritOrientation(false); - mBlurRootActor.SetInheritScale(false); - mBlurRootActor.SetColorMode(USE_OWN_COLOR); + mBlurRootActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mBlurRootActor.SetProperty( Actor::Property::INHERIT_POSITION, false ); + mBlurRootActor.SetProperty( Actor::Property::INHERIT_ORIENTATION, false ); + mBlurRootActor.SetProperty( Actor::Property::INHERIT_SCALE, false ); + mBlurRootActor.SetProperty( Actor::Property::COLOR_MODE, USE_OWN_COLOR ); - Self().Add(mBlurRootActor); + Self().Add( mBlurRootActor ); mBlurFilter.SetRootActor(mBlurRootActor); mBlurFilter.SetBackgroundColor(Vector4::ZERO); @@ -293,16 +261,21 @@ void ShadowView::OnInitialize() Constraint blurStrengthConstraint = Constraint::New( mBlurFilter.GetHandleForAnimateBlurStrength(), mBlurFilter.GetBlurStrengthPropertyIndex(), EqualToConstraint() ); blurStrengthConstraint.AddSource( Source( self, mBlurStrengthPropertyIndex) ); blurStrengthConstraint.Apply(); + + DevelControl::SetAccessibilityConstructor( Self(), []( Dali::Actor actor ) { + return std::unique_ptr< Dali::Accessibility::Accessible >( + new Control::Impl::AccessibleImpl( actor, Dali::Accessibility::Role::FILLER ) ); + } ); } void ShadowView::OnChildAdd( Actor& child ) { - Control::OnChildAdd( child ); - if( child != mChildrenRoot && child != mBlurRootActor) { mChildrenRoot.Add( child ); } + + Control::OnChildAdd( child ); } void ShadowView::OnChildRemove( Actor& child ) @@ -340,7 +313,7 @@ void ShadowView::CreateRenderTasks() mRenderSceneTask.SetCameraActor( mCameraActor ); mRenderSceneTask.SetSourceActor( mChildrenRoot ); - mRenderSceneTask.SetTargetFrameBuffer( mSceneFromLightRenderTarget ); + mRenderSceneTask.SetFrameBuffer( mSceneFromLightRenderTarget ); mRenderSceneTask.SetInputEnabled( false ); mRenderSceneTask.SetClearEnabled( true );