[dali_1.4.29] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / filters / image-filter.h
1 #ifndef DALI_TOOLKIT_INTERNAL_IMAGE_FILTER_H
2 #define DALI_TOOLKIT_INTERNAL_IMAGE_FILTER_H
3
4 /*
5  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/actors/camera-actor.h>
23 #include <dali/public-api/rendering/frame-buffer.h>
24 #include <dali/public-api/rendering/texture.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/devel-api/controls/effects-view/effects-view.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Internal
37 {
38
39 /**
40  * An interface class that provides a interface for image filters that perform
41  * a simple shader effect on an input texture, rendering the output to a FrameBuffer.
42  */
43 class ImageFilter
44 {
45 public:
46   typedef std::vector< Vector3 > FilterKernel;
47
48 public:
49
50   /**
51    * Default constructor
52    */
53   ImageFilter();
54
55   /**
56    * Destructor
57    */
58   virtual ~ImageFilter();
59
60   /**
61    * Enable effect, allocates any necessary resources
62    */
63   virtual void Enable() = 0;
64
65   /**
66    * Disable effect, releases any allocated resources
67    */
68   virtual void Disable() = 0;
69
70   /**
71    * Refresh the filter output
72    */
73   virtual void Refresh() = 0;
74
75   /**
76    * @copydoc Dali::Toolkit::EffectsView::SetRefreshOnDemand
77    */
78   void SetRefreshOnDemand( bool onDemand );
79
80   /**
81    * Set the input texture
82    * @param[in] The input/original texture.
83    */
84   void SetInputTexture( Texture texture );
85
86   /**
87    * Set the output frame buffer
88    * @return The output frame buffer.
89    */
90   void SetOutputFrameBuffer( FrameBuffer frameBuffer );
91
92   /**
93    * Set size of ImageFilter. Used to create internal offscreen buffers
94    * @param[in] size  THe size.
95    */
96   virtual void SetSize( const Vector2& size );
97
98   /**
99    * Set the pixel format for internal offscreen buffers
100    * @param[in] pixelFormat The pixel format.
101    */
102   void SetPixelFormat( Pixel::Format pixelFormat );
103
104   /**
105    * Set the filter kernel
106    * @param[in] The filter kernel
107    */
108   void SetKernel( const FilterKernel& kernel );
109
110   /**
111    * Get a const reference to the internal filter kernel
112    * @Return A a const reference to the internal filter kernel
113    */
114   const FilterKernel& GetKernel() const;
115
116   /**
117    * Get the number of steps/elements in the kernel
118    * @return The number of steps/elements in the kernel
119    */
120   size_t GetKernelSize() const;
121
122   /**
123    * Create a kernel from an array of weights
124    * @param[in] weights
125    * @param[in] count
126    */
127   void CreateKernel( const float* weights, size_t count);
128
129   /**
130    * Set the actor which acts as the root actor for all internal actors for connection to stage
131    * @param[in] rootActor   An actor which acts as the root actor for any internal actors that need
132    *                        to be created
133    */
134   void SetRootActor( Actor rootActor );
135
136   /**
137    * Set the background / clear color
138    * @param[in] color The background / clear color
139    */
140   void SetBackgroundColor( const Vector4& color );
141
142 protected:
143
144   /**
145    * Setup position and parameters for camera
146    */
147   void SetupCamera();
148
149 protected:
150   Texture          mInputTexture;
151   FrameBuffer      mOutputFrameBuffer;
152   FilterKernel     mKernel;
153   Actor            mRootActor;
154   CameraActor      mCameraActor;
155   Vector4          mBackgroundColor;
156   Vector2          mTargetSize;
157   Pixel::Format    mPixelFormat;
158   bool             mRefreshOnDemand;
159
160 }; // class Imagefilter
161
162 } // namespace Internal
163
164 } // namespace Toolkit
165
166 } // namespace Dali
167
168 #endif // DALI_TOOLKIT_INTERNAL_IMAGE_FILTER_H
169