[AT-SPI] Require ControlAccessible for Control
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / bloom-view / bloom-view-impl.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include "bloom-view-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/common/stage.h>
23 #include <dali/public-api/animation/constraint.h>
24 #include <dali/public-api/animation/constraints.h>
25 #include <dali/public-api/object/property-map.h>
26 #include <dali/public-api/object/type-registry-helper.h>
27 #include <dali/public-api/object/type-registry.h>
28 #include <dali/public-api/render-tasks/render-task-list.h>
29 #include <dali/public-api/rendering/renderer.h>
30 #include <iomanip>
31 #include <sstream>
32
33 // INTERNAL INCLUDES
34 #include <dali-toolkit/devel-api/controls/bloom-view/bloom-view.h>
35 #include <dali-toolkit/devel-api/controls/control-devel.h>
36 #include <dali-toolkit/devel-api/controls/gaussian-blur-view/gaussian-blur-view.h>
37 #include <dali-toolkit/internal/controls/control/control-renderers.h>
38 #include <dali-toolkit/internal/controls/gaussian-blur-view/gaussian-blur-view-impl.h>
39 #include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
40
41 namespace Dali
42 {
43 namespace Toolkit
44 {
45 namespace Internal
46 {
47 namespace
48 {
49 using namespace Dali;
50
51 BaseHandle Create()
52 {
53   return Toolkit::BloomView::New();
54 }
55
56 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::BloomView, Toolkit::Control, Create)
57 DALI_TYPE_REGISTRATION_END()
58
59 // default parameters
60 const float BLOOM_THRESHOLD_DEFAULT     = 0.25f;
61 const float BLOOM_BLUR_STRENGTH_DEFAULT = 1.0f;
62 const float BLOOM_INTENSITY_DEFAULT     = 1.0f;
63 const float IMAGE_INTENSITY_DEFAULT     = 1.0f;
64 const float BLOOM_SATURATION_DEFAULT    = 1.0f;
65 const float IMAGE_SATURATION_DEFAULT    = 1.0f;
66
67 // gaussian blur
68 const unsigned int  BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_NUM_SAMPLES                = 5;
69 const float         BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_BELL_CURVE_WIDTH      = 1.5f;
70 const Pixel::Format BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_RENDER_TARGET_PIXEL_FORMAT = Pixel::RGBA8888;
71 const float         BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_FADE_IN               = 1.0f; // default, fully blurred
72 const float         BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_WIDTH_SCALE     = 0.5f;
73 const float         BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_HEIGHT_SCALE    = 0.5f;
74
75 const float ARBITRARY_FIELD_OF_VIEW = Math::PI / 4.0f;
76
77 const char* const BLOOM_BLUR_STRENGTH_PROPERTY_NAME             = "BlurStrengthProperty";
78 const char* const BLOOM_THRESHOLD_PROPERTY_NAME                 = "uBloomThreshold";
79 const char* const RECIP_ONE_MINUS_BLOOM_THRESHOLD_PROPERTY_NAME = "uRecipOneMinusBloomThreshold";
80 const char* const BLOOM_INTENSITY_PROPERTY_NAME                 = "uBloomIntensity";
81 const char* const BLOOM_SATURATION_PROPERTY_NAME                = "uBloomSaturation";
82 const char* const IMAGE_INTENSITY_PROPERTY_NAME                 = "uImageIntensity";
83 const char* const IMAGE_SATURATION_PROPERTY_NAME                = "uImageSaturation";
84
85 } // namespace
86
87 BloomView::BloomView()
88 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
89   mBlurNumSamples(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_NUM_SAMPLES),
90   mBlurBellCurveWidth(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_BELL_CURVE_WIDTH),
91   mPixelFormat(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_RENDER_TARGET_PIXEL_FORMAT),
92   mDownsampleWidthScale(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_WIDTH_SCALE),
93   mDownsampleHeightScale(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_HEIGHT_SCALE),
94   mDownsampledWidth(0.0f),
95   mDownsampledHeight(0.0f),
96   mTargetSize(Vector2::ZERO),
97   mLastSize(Vector2::ZERO),
98   mChildrenRoot(Actor::New()),
99   mInternalRoot(Actor::New()),
100   mBloomThresholdPropertyIndex(Property::INVALID_INDEX),
101   mBlurStrengthPropertyIndex(Property::INVALID_INDEX),
102   mBloomIntensityPropertyIndex(Property::INVALID_INDEX),
103   mBloomSaturationPropertyIndex(Property::INVALID_INDEX),
104   mImageIntensityPropertyIndex(Property::INVALID_INDEX),
105   mImageSaturationPropertyIndex(Property::INVALID_INDEX),
106   mActivated(false)
107 {
108 }
109
110 BloomView::BloomView(const unsigned int blurNumSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat, const float downsampleWidthScale, const float downsampleHeightScale)
111 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
112   mBlurNumSamples(blurNumSamples),
113   mBlurBellCurveWidth(blurBellCurveWidth),
114   mPixelFormat(renderTargetPixelFormat),
115   mDownsampleWidthScale(downsampleWidthScale),
116   mDownsampleHeightScale(downsampleHeightScale),
117   mDownsampledWidth(0.0f),
118   mDownsampledHeight(0.0f),
119   mTargetSize(Vector2::ZERO),
120   mLastSize(Vector2::ZERO),
121   mChildrenRoot(Actor::New()),
122   mInternalRoot(Actor::New()),
123   mBloomThresholdPropertyIndex(Property::INVALID_INDEX),
124   mBlurStrengthPropertyIndex(Property::INVALID_INDEX),
125   mBloomIntensityPropertyIndex(Property::INVALID_INDEX),
126   mBloomSaturationPropertyIndex(Property::INVALID_INDEX),
127   mImageIntensityPropertyIndex(Property::INVALID_INDEX),
128   mImageSaturationPropertyIndex(Property::INVALID_INDEX),
129   mActivated(false)
130 {
131 }
132
133 BloomView::~BloomView()
134 {
135 }
136
137 Toolkit::BloomView BloomView::New()
138 {
139   BloomView* impl = new BloomView();
140
141   Dali::Toolkit::BloomView handle = Dali::Toolkit::BloomView(*impl);
142
143   // Second-phase init of the implementation
144   // This can only be done after the CustomActor connection has been made...
145   impl->Initialize();
146
147   return handle;
148 }
149
150 Toolkit::BloomView BloomView::New(const unsigned int blurNumSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat, const float downsampleWidthScale, const float downsampleHeightScale)
151 {
152   BloomView* impl = new BloomView(blurNumSamples, blurBellCurveWidth, renderTargetPixelFormat, downsampleWidthScale, downsampleHeightScale);
153
154   Dali::Toolkit::BloomView handle = Dali::Toolkit::BloomView(*impl);
155
156   // Second-phase init of the implementation
157   // This can only be done after the CustomActor connection has been made...
158   impl->Initialize();
159
160   return handle;
161 }
162
163 ///////////////////////////////////////////////////////////
164 //
165 // Private methods
166 //
167
168 void BloomView::OnInitialize()
169 {
170   // root actor to parent all user added actors, needed to allow us to set that subtree as exclusive for our child render task
171   mChildrenRoot.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
172   mInternalRoot.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
173
174   //////////////////////////////////////////////////////
175   // Create actors
176
177   // Create an image view for rendering from the scene texture to the bloom texture
178   mBloomExtractActor = Actor::New();
179   mBloomExtractActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
180
181   // Create an image view for compositing the result (scene and bloom textures) to output
182   mCompositeActor = Actor::New();
183   mCompositeActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
184
185   // Create an image view for holding final result, i.e. the blurred image. This will get rendered to screen later, via default / user render task
186   mTargetActor = Actor::New();
187   mTargetActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
188
189   // Create the Gaussian Blur object + render tasks
190   // Note that we use mBloomExtractTarget as the source image and also re-use this as the gaussian blur final render target. This saves the gaussian blur code from creating it
191   // render targets etc internally, so we make better use of resources
192   // Note, this also internally creates the render tasks used by the Gaussian blur, this must occur after the bloom extraction and before the compositing
193   mGaussianBlurView = Dali::Toolkit::GaussianBlurView::New(mBlurNumSamples, mBlurBellCurveWidth, mPixelFormat, mDownsampleWidthScale, mDownsampleHeightScale, true);
194   mGaussianBlurView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
195
196   //////////////////////////////////////////////////////
197   // Create cameras for the renders corresponding to the (potentially downsampled) render targets' size
198   mRenderDownsampledCamera = CameraActor::New();
199   mRenderDownsampledCamera.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
200   mRenderDownsampledCamera.SetInvertYAxis(true);
201
202   mRenderFullSizeCamera = CameraActor::New();
203   mRenderFullSizeCamera.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
204   mRenderFullSizeCamera.SetInvertYAxis(true);
205
206   ////////////////////////////////
207   // Connect to actor tree
208   Self().Add(mChildrenRoot);
209   Self().Add(mInternalRoot);
210   mInternalRoot.Add(mBloomExtractActor);
211   mInternalRoot.Add(mGaussianBlurView);
212   mInternalRoot.Add(mCompositeActor);
213   mInternalRoot.Add(mTargetActor);
214   mInternalRoot.Add(mRenderDownsampledCamera);
215   mInternalRoot.Add(mRenderFullSizeCamera);
216
217   // bind properties for / set shader constants to defaults
218   SetupProperties();
219
220   DevelControl::SetAccessibilityConstructor(Self(), [](Dali::Actor actor) {
221     return std::make_unique<DevelControl::ControlAccessible>(actor, Dali::Accessibility::Role::ANIMATION);
222   });
223 }
224
225 void BloomView::OnSizeSet(const Vector3& targetSize)
226 {
227   mTargetSize = Vector2(targetSize);
228   mChildrenRoot.SetProperty(Actor::Property::SIZE, targetSize);
229   mCompositeActor.SetProperty(Actor::Property::SIZE, targetSize);
230   mTargetActor.SetProperty(Actor::Property::SIZE, targetSize);
231
232   // Children render camera must move when GaussianBlurView object is
233   // resized. This is since we cannot change render target size - so we need
234   // to remap the child actors' rendering accordingly so they still exactly
235   // fill the render target. Note that this means the effective resolution of
236   // the child render changes as the GaussianBlurView object changes size,
237   // this is the trade off for not being able to modify render target size
238   // Change camera z position based on GaussianBlurView actor height
239   float cameraPosConstraintScale = 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f);
240   mRenderFullSizeCamera.SetProperty(Actor::Property::POSITION_Z, mTargetSize.height * cameraPosConstraintScale);
241
242   // if we have already activated the blur, need to update render target sizes now to reflect the new size of this actor
243   if(mActivated)
244   {
245     Deactivate();
246     Activate();
247   }
248
249   Control::OnSizeSet(targetSize);
250 }
251
252 void BloomView::OnChildAdd(Actor& child)
253 {
254   if(child != mChildrenRoot && child != mInternalRoot)
255   {
256     mChildrenRoot.Add(child);
257   }
258
259   Control::OnChildAdd(child);
260 }
261
262 void BloomView::OnChildRemove(Actor& child)
263 {
264   mChildrenRoot.Remove(child);
265
266   Control::OnChildRemove(child);
267 }
268
269 void BloomView::AllocateResources()
270 {
271   // size of render targets etc is based on the size of this actor, ignoring z
272   if(mTargetSize != mLastSize || !mActivated)
273   {
274     mLastSize = mTargetSize;
275
276     // get size of downsampled render targets
277     mDownsampledWidth  = mTargetSize.width * mDownsampleWidthScale;
278     mDownsampledHeight = mTargetSize.height * mDownsampleHeightScale;
279
280     //////////////////////////////////////////////////////
281     // Create cameras
282
283     // Create and place a camera for the renders corresponding to the (potentially downsampled) render targets' size
284     mRenderDownsampledCamera.SetFieldOfView(ARBITRARY_FIELD_OF_VIEW);
285     mRenderDownsampledCamera.SetNearClippingPlane(1.0f);
286     mRenderDownsampledCamera.SetAspectRatio(mDownsampledWidth / mDownsampledHeight);
287     mRenderDownsampledCamera.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor
288
289     mRenderDownsampledCamera.SetProperty(Actor::Property::POSITION, Vector3(0.0f, 0.0f, ((mDownsampledHeight * 0.5f) / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f))));
290
291     // Create and place a camera for the children render, corresponding to its render target size
292     mRenderFullSizeCamera.SetFieldOfView(ARBITRARY_FIELD_OF_VIEW);
293     mRenderFullSizeCamera.SetNearClippingPlane(1.0f);
294     mRenderFullSizeCamera.SetAspectRatio(mTargetSize.width / mTargetSize.height);
295     mRenderFullSizeCamera.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor
296
297     float cameraPosConstraintScale = 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f);
298     mRenderFullSizeCamera.SetProperty(Actor::Property::POSITION, Vector3(0.0f, 0.0f, mTargetSize.height * cameraPosConstraintScale));
299
300     //////////////////////////////////////////////////////
301     // Pass size change onto GaussianBlurView, so it matches
302     mGaussianBlurView.SetProperty(Actor::Property::SIZE, mTargetSize);
303     GetImpl(mGaussianBlurView).AllocateResources();
304
305     mGaussianBlurView.SetProperty(Actor::Property::VISIBLE, true);
306
307     //////////////////////////////////////////////////////
308     // Create render targets
309
310     // create off screen buffer of new size to render our child actors to
311     mRenderTargetForRenderingChildren = FrameBuffer::New(mTargetSize.width, mTargetSize.height, FrameBuffer::Attachment::NONE);
312     Texture textureForChildren        = Texture::New(TextureType::TEXTURE_2D, mPixelFormat, unsigned(mTargetSize.width), unsigned(mTargetSize.height));
313     mRenderTargetForRenderingChildren.AttachColorTexture(textureForChildren);
314
315     mBloomExtractTarget = FrameBuffer::New(mDownsampledWidth, mDownsampledHeight, FrameBuffer::Attachment::NONE);
316     Texture texture     = Texture::New(TextureType::TEXTURE_2D, mPixelFormat, unsigned(mDownsampledWidth), unsigned(mDownsampledHeight));
317     mBloomExtractTarget.AttachColorTexture(texture);
318
319     FrameBuffer blurExtractTarget = FrameBuffer::New(mDownsampledWidth, mDownsampledHeight, FrameBuffer::Attachment::NONE);
320     texture                       = Texture::New(TextureType::TEXTURE_2D, mPixelFormat, unsigned(mDownsampledWidth), unsigned(mDownsampledHeight));
321     blurExtractTarget.AttachColorTexture(texture);
322
323     mOutputRenderTarget   = FrameBuffer::New(mTargetSize.width, mTargetSize.height, FrameBuffer::Attachment::NONE);
324     Texture outputTexture = Texture::New(TextureType::TEXTURE_2D, mPixelFormat, unsigned(mTargetSize.width), unsigned(mTargetSize.height));
325     mOutputRenderTarget.AttachColorTexture(outputTexture);
326
327     //////////////////////////////////////////////////////
328     // Point actors and render tasks at new render targets
329
330     Renderer bloomRenderer = CreateRenderer(BASIC_VERTEX_SOURCE, SHADER_BLOOM_VIEW_EXTRACT_SHADER_FRAG);
331     SetRendererTexture(bloomRenderer, mRenderTargetForRenderingChildren);
332     mBloomExtractActor.AddRenderer(bloomRenderer);
333     mBloomExtractActor.SetProperty(Actor::Property::SIZE, Vector2(mDownsampledWidth, mDownsampledHeight)); // size needs to match render target
334
335     // set GaussianBlurView to blur our extracted bloom
336     mGaussianBlurView.SetUserImageAndOutputRenderTarget(mBloomExtractTarget.GetColorTexture(), blurExtractTarget);
337
338     // use the completed blur in the first buffer and composite with the original child actors render
339     Renderer compositeRenderer = CreateRenderer(BASIC_VERTEX_SOURCE, SHADER_BLOOM_VIEW_COMPOSITE_SHADER_FRAG);
340     SetRendererTexture(compositeRenderer, mRenderTargetForRenderingChildren);
341     TextureSet textureSet = compositeRenderer.GetTextures();
342     textureSet.SetTexture(0u, mRenderTargetForRenderingChildren.GetColorTexture());
343     textureSet.SetTexture(1u, blurExtractTarget.GetColorTexture());
344     mCompositeActor.AddRenderer(compositeRenderer);
345
346     // set up target actor for rendering result, i.e. the blurred image
347     Renderer targetRenderer = CreateRenderer(BASIC_VERTEX_SOURCE, BASIC_FRAGMENT_SOURCE);
348     SetRendererTexture(targetRenderer, mOutputRenderTarget);
349     mTargetActor.AddRenderer(targetRenderer);
350   }
351 }
352
353 void BloomView::CreateRenderTasks()
354 {
355   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
356
357   // create render task to render our child actors to offscreen buffer
358   mRenderChildrenTask = taskList.CreateTask();
359   mRenderChildrenTask.SetSourceActor(mChildrenRoot);
360   mRenderChildrenTask.SetExclusive(true);
361   mRenderChildrenTask.SetInputEnabled(false);
362   mRenderChildrenTask.SetClearEnabled(true);
363   mRenderChildrenTask.SetCameraActor(mRenderFullSizeCamera); // use camera that covers render target exactly
364   mRenderChildrenTask.SetFrameBuffer(mRenderTargetForRenderingChildren);
365
366   // Extract the bright part of the image and render to a new buffer. Downsampling also occurs at this stage to save pixel fill, if it is set up.
367   mBloomExtractTask = taskList.CreateTask();
368   mBloomExtractTask.SetSourceActor(mBloomExtractActor);
369   mBloomExtractTask.SetExclusive(true);
370   mBloomExtractTask.SetInputEnabled(false);
371   mBloomExtractTask.SetClearEnabled(true);
372   mBloomExtractTask.SetCameraActor(mRenderDownsampledCamera);
373   mBloomExtractTask.SetFrameBuffer(mBloomExtractTarget);
374
375   // GaussianBlurView tasks must be created here, so they are executed in the correct order with respect to BloomView tasks
376   GetImpl(mGaussianBlurView).CreateRenderTasks();
377
378   // Use an image view displaying the children render and composite it with the blurred bloom buffer, targeting the output
379   mCompositeTask = taskList.CreateTask();
380   mCompositeTask.SetSourceActor(mCompositeActor);
381   mCompositeTask.SetExclusive(true);
382   mCompositeTask.SetInputEnabled(false);
383   mCompositeTask.SetClearEnabled(true);
384   mCompositeTask.SetCameraActor(mRenderFullSizeCamera);
385   mCompositeTask.SetFrameBuffer(mOutputRenderTarget);
386 }
387
388 void BloomView::RemoveRenderTasks()
389 {
390   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
391
392   taskList.RemoveTask(mRenderChildrenTask);
393   taskList.RemoveTask(mBloomExtractTask);
394
395   GetImpl(mGaussianBlurView).RemoveRenderTasks();
396
397   taskList.RemoveTask(mCompositeTask);
398 }
399
400 void BloomView::Activate()
401 {
402   // make sure resources are allocated and start the render tasks processing
403   AllocateResources();
404   CreateRenderTasks();
405   mActivated = true;
406 }
407
408 void BloomView::Deactivate()
409 {
410   // stop render tasks processing
411   // Note: render target resources are automatically freed since we set the Image::Unused flag
412   RemoveRenderTasks();
413
414   mRenderTargetForRenderingChildren.Reset();
415   mBloomExtractTarget.Reset();
416   mOutputRenderTarget.Reset();
417
418   // Reset children
419   mBloomExtractActor.RemoveRenderer(0u);
420   mTargetActor.RemoveRenderer(0u);
421   mCompositeActor.RemoveRenderer(0u);
422
423   mGaussianBlurView.SetProperty(Actor::Property::VISIBLE, false);
424
425   mActivated = false;
426 }
427
428 /**
429  * RecipOneMinusConstraint
430  *
431  * f(current, property) = property
432  */
433 struct RecipOneMinusConstraint
434 {
435   RecipOneMinusConstraint()
436   {
437   }
438
439   void operator()(float& current, const PropertyInputContainer& inputs)
440   {
441     current = 1.0f / (1.0f - inputs[0]->GetFloat());
442   }
443 };
444
445 // create properties and constraints to tie internal shader etc settings to BloomView object. User can therefore animate / set them via BloomView object without knowing about
446 // internal implementation classes
447 void BloomView::SetupProperties()
448 {
449   CustomActor self = Self();
450
451   ///////////////////////////////////////////
452   // bloom threshold
453
454   // set defaults, makes sure properties are registered with shader
455   mBloomExtractActor.RegisterProperty(BLOOM_THRESHOLD_PROPERTY_NAME, BLOOM_THRESHOLD_DEFAULT);
456   mBloomExtractActor.RegisterProperty(RECIP_ONE_MINUS_BLOOM_THRESHOLD_PROPERTY_NAME, 1.0f / (1.0f - BLOOM_THRESHOLD_DEFAULT));
457
458   // Register a property that the user can control to change the bloom threshold
459   mBloomThresholdPropertyIndex                      = self.RegisterProperty(BLOOM_THRESHOLD_PROPERTY_NAME, BLOOM_THRESHOLD_DEFAULT);
460   Property::Index shaderBloomThresholdPropertyIndex = mBloomExtractActor.GetPropertyIndex(BLOOM_THRESHOLD_PROPERTY_NAME);
461   Constraint      bloomThresholdConstraint          = Constraint::New<float>(mBloomExtractActor, shaderBloomThresholdPropertyIndex, EqualToConstraint());
462   bloomThresholdConstraint.AddSource(Source(self, mBloomThresholdPropertyIndex));
463   bloomThresholdConstraint.Apply();
464
465   // precalc 1.0 / (1.0 - threshold) on CPU to save shader insns, using constraint to tie to the normal threshold property
466   Property::Index shaderRecipOneMinusBloomThresholdPropertyIndex = mBloomExtractActor.GetPropertyIndex(RECIP_ONE_MINUS_BLOOM_THRESHOLD_PROPERTY_NAME);
467   Constraint      thresholdConstraint                            = Constraint::New<float>(mBloomExtractActor, shaderRecipOneMinusBloomThresholdPropertyIndex, RecipOneMinusConstraint());
468   thresholdConstraint.AddSource(LocalSource(shaderBloomThresholdPropertyIndex));
469   thresholdConstraint.Apply();
470
471   ////////////////////////////////////////////
472   // bloom strength
473
474   // Register a property that the user can control to fade the blur in / out via internal GaussianBlurView object
475   mBlurStrengthPropertyIndex        = self.RegisterProperty(BLOOM_BLUR_STRENGTH_PROPERTY_NAME, BLOOM_BLUR_STRENGTH_DEFAULT);
476   Constraint blurStrengthConstraint = Constraint::New<float>(mGaussianBlurView, mGaussianBlurView.GetBlurStrengthPropertyIndex(), EqualToConstraint());
477   blurStrengthConstraint.AddSource(Source(self, mBlurStrengthPropertyIndex));
478   blurStrengthConstraint.Apply();
479
480   ////////////////////////////////////////////
481   // bloom intensity
482
483   // Register a property that the user can control to fade the bloom intensity via internally hidden shader
484   mBloomIntensityPropertyIndex = self.RegisterProperty(BLOOM_INTENSITY_PROPERTY_NAME, BLOOM_INTENSITY_DEFAULT);
485   mCompositeActor.RegisterProperty(BLOOM_INTENSITY_PROPERTY_NAME, BLOOM_INTENSITY_DEFAULT);
486   Property::Index shaderBloomIntensityPropertyIndex = mCompositeActor.GetPropertyIndex(BLOOM_INTENSITY_PROPERTY_NAME);
487   Constraint      bloomIntensityConstraint          = Constraint::New<float>(mCompositeActor, shaderBloomIntensityPropertyIndex, EqualToConstraint());
488   bloomIntensityConstraint.AddSource(Source(self, mBloomIntensityPropertyIndex));
489   bloomIntensityConstraint.Apply();
490
491   ////////////////////////////////////////////
492   // bloom saturation
493
494   // Register a property that the user can control to fade the bloom saturation via internally hidden shader
495   mBloomSaturationPropertyIndex = self.RegisterProperty(BLOOM_SATURATION_PROPERTY_NAME, BLOOM_SATURATION_DEFAULT);
496   mCompositeActor.RegisterProperty(BLOOM_SATURATION_PROPERTY_NAME, BLOOM_SATURATION_DEFAULT);
497   Property::Index shaderBloomSaturationPropertyIndex = mCompositeActor.GetPropertyIndex(BLOOM_SATURATION_PROPERTY_NAME);
498   Constraint      bloomSaturationConstraint          = Constraint::New<float>(mCompositeActor, shaderBloomSaturationPropertyIndex, EqualToConstraint());
499   bloomSaturationConstraint.AddSource(Source(self, mBloomSaturationPropertyIndex));
500   bloomSaturationConstraint.Apply();
501
502   ////////////////////////////////////////////
503   // image intensity
504
505   // Register a property that the user can control to fade the image intensity via internally hidden shader
506   mImageIntensityPropertyIndex = self.RegisterProperty(IMAGE_INTENSITY_PROPERTY_NAME, IMAGE_INTENSITY_DEFAULT);
507   mCompositeActor.RegisterProperty(IMAGE_INTENSITY_PROPERTY_NAME, IMAGE_INTENSITY_DEFAULT);
508   Property::Index shaderImageIntensityPropertyIndex = mCompositeActor.GetPropertyIndex(IMAGE_INTENSITY_PROPERTY_NAME);
509   Constraint      imageIntensityConstraint          = Constraint::New<float>(mCompositeActor, shaderImageIntensityPropertyIndex, EqualToConstraint());
510   imageIntensityConstraint.AddSource(Source(self, mImageIntensityPropertyIndex));
511   imageIntensityConstraint.Apply();
512
513   ////////////////////////////////////////////
514   // image saturation
515
516   // Register a property that the user can control to fade the image saturation via internally hidden shader
517   mImageSaturationPropertyIndex = self.RegisterProperty(IMAGE_SATURATION_PROPERTY_NAME, IMAGE_SATURATION_DEFAULT);
518   mCompositeActor.RegisterProperty(IMAGE_SATURATION_PROPERTY_NAME, IMAGE_SATURATION_DEFAULT);
519   Property::Index shaderImageSaturationPropertyIndex = mCompositeActor.GetPropertyIndex(IMAGE_SATURATION_PROPERTY_NAME);
520   Constraint      imageSaturationConstraint          = Constraint::New<float>(mCompositeActor, shaderImageSaturationPropertyIndex, EqualToConstraint());
521   imageSaturationConstraint.AddSource(Source(self, mImageSaturationPropertyIndex));
522   imageSaturationConstraint.Apply();
523 }
524
525 } // namespace Internal
526
527 } // namespace Toolkit
528
529 } // namespace Dali