-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.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://floralicense.org/license/
-//
-// 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.
-//
+/*
+ * 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 "bloom-view-impl.h"
-#include "../gaussian-blur-view/gaussian-blur-view-impl.h"
// EXTERNAL INCLUDES
#include <sstream>
#include <iomanip>
+#include <dali/public-api/animation/constraint.h>
+#include <dali/public-api/animation/constraints.h>
+#include <dali/public-api/common/stage.h>
+#include <dali/public-api/object/type-registry.h>
+#include <dali/devel-api/object/type-registry-helper.h>
+#include <dali/public-api/render-tasks/render-task-list.h>
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/gaussian-blur-view/gaussian-blur-view.h>
-#include <dali-toolkit/public-api/controls/bloom-view/bloom-view.h>
+#include <dali-toolkit/devel-api/controls/bloom-view/bloom-view.h>
+#include "../gaussian-blur-view/gaussian-blur-view-impl.h"
namespace Dali
{
return Toolkit::BloomView::New();
}
-TypeRegistration mType( typeid(Toolkit::BloomView), typeid(Toolkit::Control), Create );
+DALI_TYPE_REGISTRATION_BEGIN( Toolkit::BloomView, Toolkit::Control, Create )
+DALI_TYPE_REGISTRATION_END()
// default parameters
const float BLOOM_THRESHOLD_DEFAULT = 0.25f;
const float ARBITRARY_FIELD_OF_VIEW = Math::PI / 4.0f;
-const std::string BLOOM_BLUR_STRENGTH_PROPERTY_NAME( "BlurStrengthProperty" );
-
-const std::string BLOOM_THRESHOLD_PROPERTY_NAME( "uBloomThreshold" );
-const std::string RECIP_ONE_MINUS_BLOOM_THRESHOLD_PROPERTY_NAME( "uRecipOneMinusBloomThreshold" );
-const std::string BLOOM_INTENSITY_PROPERTY_NAME( "uBloomIntensity" );
-const std::string BLOOM_SATURATION_PROPERTY_NAME( "uBloomSaturation" );
-const std::string IMAGE_INTENSITY_PROPERTY_NAME( "uImageIntensity" );
-const std::string IMAGE_SATURATION_PROPERTY_NAME( "uImageSaturation" );
+const char* const BLOOM_BLUR_STRENGTH_PROPERTY_NAME = "BlurStrengthProperty";
+const char* const BLOOM_THRESHOLD_PROPERTY_NAME = "uBloomThreshold";
+const char* const RECIP_ONE_MINUS_BLOOM_THRESHOLD_PROPERTY_NAME = "uRecipOneMinusBloomThreshold";
+const char* const BLOOM_INTENSITY_PROPERTY_NAME = "uBloomIntensity";
+const char* const BLOOM_SATURATION_PROPERTY_NAME = "uBloomSaturation";
+const char* const IMAGE_INTENSITY_PROPERTY_NAME = "uImageIntensity";
+const char* const IMAGE_SATURATION_PROPERTY_NAME = "uImageSaturation";
///////////////////////////////////////////////////////
//
BloomView::BloomView()
- : ControlImpl( false ) // doesn't require touch events
+ : Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) )
, mBlurNumSamples(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_NUM_SAMPLES)
, mBlurBellCurveWidth(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_BELL_CURVE_WIDTH)
, mPixelFormat(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_RENDER_TARGET_PIXEL_FORMAT)
BloomView::BloomView( const unsigned int blurNumSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat,
const float downsampleWidthScale, const float downsampleHeightScale)
- : ControlImpl( false ) // doesn't require touch events
+ : Control( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) )
, mBlurNumSamples(blurNumSamples)
, mBlurBellCurveWidth(blurBellCurveWidth)
, mPixelFormat(renderTargetPixelFormat)
{
// root actor to parent all user added actors, needed to allow us to set that subtree as exclusive for our child render task
mChildrenRoot.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
- mChildrenRoot.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); // same size as BloomView object
-
//////////////////////////////////////////////////////
// Create shaders
// Create an ImageActor for compositing the result (scene and bloom textures) to output
mCompositeImageActor = ImageActor::New();
mCompositeImageActor.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
- mCompositeImageActor.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); // same size as BloomView object
mCompositeImageActor.SetShaderEffect( mCompositeShader );
mCompositeImageActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
// Create an ImageActor for holding final result, i.e. the blurred image. This will get rendered to screen later, via default / user render task
mTargetImageActor = ImageActor::New();
mTargetImageActor.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION );
- mTargetImageActor.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); // same size as BloomView object
mTargetImageActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
SetupProperties();
}
-/**
- * ZrelativeToYconstraint
- *
- * f(current, property, scale) = Vector3(current.x, current.y, property.y * scale)
- */
-struct ZrelativeToYconstraint
-{
- ZrelativeToYconstraint( float scale )
- : mScale( scale )
- {}
-
- Vector3 operator()(const Vector3& current,
- const PropertyInput& property)
- {
- Vector3 v;
-
- v.x = current.x;
- v.y = current.y;
- v.z = property.GetVector3().y * mScale;
-
- return v;
- }
-
- float mScale;
-};
-
-void BloomView::OnControlSizeSet(const Vector3& targetSize)
+void BloomView::OnSizeSet(const Vector3& targetSize)
{
mTargetSize = Vector2(targetSize);
+ mChildrenRoot.SetSize(targetSize);
+ mCompositeImageActor.SetSize(targetSize);
+ mTargetImageActor.SetSize(targetSize);
+
+ // Children render camera must move when GaussianBlurView object is
+ // resized. This is since we cannot change render target size - so we need
+ // to remap the child actors' rendering accordingly so they still exactly
+ // fill the render target. Note that this means the effective resolution of
+ // the child render changes as the GaussianBlurView object changes size,
+ // this is the trade off for not being able to modify render target size
+ // Change camera z position based on GaussianBlurView actor height
+ float cameraPosConstraintScale = 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f);
+ mRenderFullSizeCamera.SetZ( mTargetSize.height * cameraPosConstraintScale);
// if we are already on stage, need to update render target sizes now to reflect the new size of this actor
if(Self().OnStage())
mRenderDownsampledCamera.SetNearClippingPlane(1.0f);
mRenderDownsampledCamera.SetAspectRatio(mDownsampledWidth / mDownsampledHeight);
mRenderDownsampledCamera.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor
- mRenderDownsampledCamera.SetRotation(Quaternion(M_PI, Vector3::YAXIS)); // Rotate to look at origin
mRenderDownsampledCamera.SetPosition(0.0f, 0.0f, ((mDownsampledHeight * 0.5f) / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f)));
mRenderFullSizeCamera.SetNearClippingPlane(1.0f);
mRenderFullSizeCamera.SetAspectRatio(mTargetSize.width / mTargetSize.height);
mRenderFullSizeCamera.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor
- mRenderFullSizeCamera.SetRotation(Quaternion(M_PI, Vector3::YAXIS)); // Rotate to look at origin
float cameraPosConstraintScale = 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f);
mRenderFullSizeCamera.SetPosition(0.0f, 0.0f, mTargetSize.height * cameraPosConstraintScale);
-
- // Children render camera must move when GaussianBlurView object is
- // resized. This is since we cannot change render target size - so we need
- // to remap the child actors' rendering accordingly so they still exactly
- // fill the render target. Note that this means the effective resolution of
- // the child render changes as the GaussianBlurView object changes size,
- // this is the trade off for not being able to modify render target size
- // Change camera z position based on GaussianBlurView actor height
-
- mRenderFullSizeCamera.RemoveConstraints();
- mRenderFullSizeCamera.ApplyConstraint( Constraint::New<Vector3>( Actor::POSITION, ParentSource( Actor::SIZE ), ZrelativeToYconstraint(cameraPosConstraintScale) ) );
-
-
//////////////////////////////////////////////////////
// Pass size change onto GaussianBlurView, so it matches
mGaussianBlurView.SetSize(mTargetSize);
// Create render targets
// create off screen buffer of new size to render our child actors to
- mRenderTargetForRenderingChildren = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat, Dali::Image::Unused );
- mBloomExtractTarget = FrameBufferImage::New( mDownsampledWidth, mDownsampledHeight, mPixelFormat, Dali::Image::Unused );
- mOutputRenderTarget = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat, Dali::Image::Unused );
+ mRenderTargetForRenderingChildren = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat, Dali::Image::UNUSED );
+ mBloomExtractTarget = FrameBufferImage::New( mDownsampledWidth, mDownsampledHeight, mPixelFormat, Dali::Image::UNUSED );
+ mOutputRenderTarget = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat, Dali::Image::UNUSED);
//////////////////////////////////////////////////////
taskList.RemoveTask(mCompositeTask);
}
-void BloomView::OnStageDisconnection()
-{
- // TODO: can't call this here, since SetImage() calls fails similarly to above
- // Need to fix the stage connection so this callback can be used arbitrarily. At that point we can simplify the API by removing the need for Activate() / Deactivate()
- //Deactivate();
-}
-
-void BloomView::OnControlStageConnection()
-{
- // TODO: can't call this here, since SetImage() calls fail to connect images to stage, since parent chain not fully on stage yet
- // Need to fix the stage connection so this callback can be used arbitrarily. At that point we can simplify the API by removing the need for Activate() / Deactivate()
- //Activate();
-}
-
void BloomView::Activate()
{
// make sure resources are allocated and start the render tasks processing
}
/**
- * EqualToConstraintFloat
- *
- * f(current, property) = property
- */
-struct EqualToConstraintFloat
-{
- EqualToConstraintFloat(){}
-
- float operator()(const float current, const PropertyInput& property) {return property.GetFloat();}
-};
-
-/**
* RecipOneMinusConstraint
*
* f(current, property) = property
{
RecipOneMinusConstraint(){}
- float operator()(const float current, const PropertyInput& property)
+ void operator()( float& current, const PropertyInputContainer& inputs )
{
- return 1.0f / (1.0f - property.GetFloat());
+ current = 1.0f / ( 1.0f - inputs[0]->GetFloat() );
}
};
// Register a property that the user can control to change the bloom threshold
mBloomThresholdPropertyIndex = self.RegisterProperty(BLOOM_THRESHOLD_PROPERTY_NAME, BLOOM_THRESHOLD_DEFAULT);
Property::Index shaderBloomThresholdPropertyIndex = mBloomExtractShader.GetPropertyIndex(BLOOM_THRESHOLD_PROPERTY_NAME);
- Constraint bloomThresholdConstraint = Constraint::New<float>(shaderBloomThresholdPropertyIndex, Source(self, mBloomThresholdPropertyIndex), EqualToConstraintFloat());
- mBloomExtractShader.ApplyConstraint(bloomThresholdConstraint);
+ Constraint bloomThresholdConstraint = Constraint::New<float>( mBloomExtractShader, shaderBloomThresholdPropertyIndex, EqualToConstraint());
+ bloomThresholdConstraint.AddSource( Source(self, mBloomThresholdPropertyIndex) );
+ bloomThresholdConstraint.Apply();
// precalc 1.0 / (1.0 - threshold) on CPU to save shader insns, using constraint to tie to the normal threshold property
Property::Index shaderRecipOneMinusBloomThresholdPropertyIndex = mBloomExtractShader.GetPropertyIndex(RECIP_ONE_MINUS_BLOOM_THRESHOLD_PROPERTY_NAME);
- Constraint thresholdConstraint = Constraint::New<float>( shaderRecipOneMinusBloomThresholdPropertyIndex, LocalSource(shaderBloomThresholdPropertyIndex), RecipOneMinusConstraint());
- mBloomExtractShader.ApplyConstraint(thresholdConstraint);
+ Constraint thresholdConstraint = Constraint::New<float>( mBloomExtractShader, shaderRecipOneMinusBloomThresholdPropertyIndex, RecipOneMinusConstraint());
+ thresholdConstraint.AddSource( LocalSource(shaderBloomThresholdPropertyIndex) );
+ thresholdConstraint.Apply();
////////////////////////////////////////////
// Register a property that the user can control to fade the blur in / out via internal GaussianBlurView object
mBlurStrengthPropertyIndex = self.RegisterProperty(BLOOM_BLUR_STRENGTH_PROPERTY_NAME, BLOOM_BLUR_STRENGTH_DEFAULT);
- Constraint blurStrengthConstraint = Constraint::New<float>( mGaussianBlurView.GetBlurStrengthPropertyIndex(), Source(self, mBlurStrengthPropertyIndex), EqualToConstraintFloat());
- mGaussianBlurView.ApplyConstraint(blurStrengthConstraint);
+ Constraint blurStrengthConstraint = Constraint::New<float>( mGaussianBlurView, mGaussianBlurView.GetBlurStrengthPropertyIndex(), EqualToConstraint());
+ blurStrengthConstraint.AddSource( Source(self, mBlurStrengthPropertyIndex) );
+ blurStrengthConstraint.Apply();
////////////////////////////////////////////
mBloomIntensityPropertyIndex = self.RegisterProperty(BLOOM_INTENSITY_PROPERTY_NAME, BLOOM_INTENSITY_DEFAULT);
mCompositeShader.SetUniform( BLOOM_INTENSITY_PROPERTY_NAME, BLOOM_INTENSITY_DEFAULT );
Property::Index shaderBloomIntensityPropertyIndex = mCompositeShader.GetPropertyIndex(BLOOM_INTENSITY_PROPERTY_NAME);
- Constraint bloomIntensityConstraint = Constraint::New<float>( shaderBloomIntensityPropertyIndex, Source(self, mBloomIntensityPropertyIndex), EqualToConstraintFloat());
- mCompositeShader.ApplyConstraint(bloomIntensityConstraint);
+ Constraint bloomIntensityConstraint = Constraint::New<float>( mCompositeShader, shaderBloomIntensityPropertyIndex, EqualToConstraint());
+ bloomIntensityConstraint.AddSource( Source(self, mBloomIntensityPropertyIndex) );
+ bloomIntensityConstraint.Apply();
////////////////////////////////////////////
mBloomSaturationPropertyIndex = self.RegisterProperty(BLOOM_SATURATION_PROPERTY_NAME, BLOOM_SATURATION_DEFAULT);
mCompositeShader.SetUniform( BLOOM_SATURATION_PROPERTY_NAME, BLOOM_SATURATION_DEFAULT );
Property::Index shaderBloomSaturationPropertyIndex = mCompositeShader.GetPropertyIndex(BLOOM_SATURATION_PROPERTY_NAME);
- Constraint bloomSaturationConstraint = Constraint::New<float>( shaderBloomSaturationPropertyIndex, Source(self, mBloomSaturationPropertyIndex), EqualToConstraintFloat());
- mCompositeShader.ApplyConstraint(bloomSaturationConstraint);
+ Constraint bloomSaturationConstraint = Constraint::New<float>( mCompositeShader, shaderBloomSaturationPropertyIndex, EqualToConstraint());
+ bloomSaturationConstraint.AddSource( Source(self, mBloomSaturationPropertyIndex) );
+ bloomSaturationConstraint.Apply();
////////////////////////////////////////////
mImageIntensityPropertyIndex = self.RegisterProperty(IMAGE_INTENSITY_PROPERTY_NAME, IMAGE_INTENSITY_DEFAULT);
mCompositeShader.SetUniform( IMAGE_INTENSITY_PROPERTY_NAME, IMAGE_INTENSITY_DEFAULT );
Property::Index shaderImageIntensityPropertyIndex = mCompositeShader.GetPropertyIndex(IMAGE_INTENSITY_PROPERTY_NAME);
- Constraint imageIntensityConstraint = Constraint::New<float>( shaderImageIntensityPropertyIndex, Source(self, mImageIntensityPropertyIndex), EqualToConstraintFloat());
- mCompositeShader.ApplyConstraint(imageIntensityConstraint);
+ Constraint imageIntensityConstraint = Constraint::New<float>( mCompositeShader, shaderImageIntensityPropertyIndex, EqualToConstraint());
+ imageIntensityConstraint.AddSource( Source(self, mImageIntensityPropertyIndex) );
+ imageIntensityConstraint.Apply();
////////////////////////////////////////////
mImageSaturationPropertyIndex = self.RegisterProperty(IMAGE_SATURATION_PROPERTY_NAME, IMAGE_SATURATION_DEFAULT);
mCompositeShader.SetUniform( IMAGE_SATURATION_PROPERTY_NAME, IMAGE_SATURATION_DEFAULT );
Property::Index shaderImageSaturationPropertyIndex = mCompositeShader.GetPropertyIndex(IMAGE_SATURATION_PROPERTY_NAME);
- Constraint imageSaturationConstraint = Constraint::New<float>( shaderImageSaturationPropertyIndex, Source(self, mImageSaturationPropertyIndex), EqualToConstraintFloat());
- mCompositeShader.ApplyConstraint(imageSaturationConstraint);
+ Constraint imageSaturationConstraint = Constraint::New<float>( mCompositeShader, shaderImageSaturationPropertyIndex, EqualToConstraint());
+ imageSaturationConstraint.AddSource( Source(self, mImageSaturationPropertyIndex) );
+ imageSaturationConstraint.Apply();
}
} // namespace Internal