[dali_2.3.20] 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) 2021 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/devel-api/controls/effects-view/effects-view.h>
28 #include <dali-toolkit/public-api/controls/control-impl.h>
29
30 namespace Dali
31 {
32 namespace Toolkit
33 {
34 namespace Internal
35 {
36 /**
37  * An interface class that provides a interface for image filters that perform
38  * a simple shader effect on an input texture, rendering the output to a FrameBuffer.
39  */
40 class ImageFilter
41 {
42 public:
43   typedef std::vector<Vector3> FilterKernel;
44
45 public:
46   /**
47    * Default constructor
48    */
49   ImageFilter();
50
51   /**
52    * Destructor
53    */
54   virtual ~ImageFilter();
55
56   /**
57    * Enable effect, allocates any necessary resources
58    */
59   virtual void Enable() = 0;
60
61   /**
62    * Disable effect, releases any allocated resources
63    */
64   virtual void Disable() = 0;
65
66   /**
67    * Refresh the filter output
68    */
69   virtual void Refresh() = 0;
70
71   /**
72    * @copydoc Dali::Toolkit::EffectsView::SetRefreshOnDemand
73    */
74   void SetRefreshOnDemand(bool onDemand);
75
76   /**
77    * Set the input texture
78    * @param[in] The input/original texture.
79    */
80   void SetInputTexture(Texture texture);
81
82   /**
83    * Set the output frame buffer
84    * @return The output frame buffer.
85    */
86   void SetOutputFrameBuffer(FrameBuffer frameBuffer);
87
88   /**
89    * Set size of ImageFilter. Used to create internal offscreen buffers
90    * @param[in] size  THe size.
91    */
92   virtual void SetSize(const Vector2& size);
93
94   /**
95    * Set the pixel format for internal offscreen buffers
96    * @param[in] pixelFormat The pixel format.
97    */
98   void SetPixelFormat(Pixel::Format pixelFormat);
99
100   /**
101    * Set the filter kernel
102    * @param[in] The filter kernel
103    */
104   void SetKernel(const FilterKernel& kernel);
105
106   /**
107    * Get a const reference to the internal filter kernel
108    * @Return A a const reference to the internal filter kernel
109    */
110   const FilterKernel& GetKernel() const;
111
112   /**
113    * Get the number of steps/elements in the kernel
114    * @return The number of steps/elements in the kernel
115    */
116   size_t GetKernelSize() const;
117
118   /**
119    * Create a kernel from an array of weights
120    * @param[in] weights
121    * @param[in] count
122    */
123   void CreateKernel(const float* weights, size_t count);
124
125   /**
126    * Set the actor which acts as the root actor for all internal actors for connection to stage
127    * @param[in] rootActor   An actor which acts as the root actor for any internal actors that need
128    *                        to be created
129    */
130   void SetRootActor(Actor rootActor);
131
132   /**
133    * Set the background / clear color
134    * @param[in] color The background / clear color
135    */
136   void SetBackgroundColor(const Vector4& color);
137
138 protected:
139   /**
140    * Setup position and parameters for camera
141    */
142   void SetupCamera();
143
144 protected:
145   Texture       mInputTexture;
146   FrameBuffer   mOutputFrameBuffer;
147   FilterKernel  mKernel;
148   Actor         mRootActor;
149   CameraActor   mCameraActor;
150   Vector4       mBackgroundColor;
151   Vector2       mTargetSize;
152   Pixel::Format mPixelFormat;
153   bool          mRefreshOnDemand;
154
155 }; // class Imagefilter
156
157 } // namespace Internal
158
159 } // namespace Toolkit
160
161 } // namespace Dali
162
163 #endif // DALI_TOOLKIT_INTERNAL_IMAGE_FILTER_H