[Tizen] support capture in gles 2.0
[platform/core/uifw/dali-adaptor.git] / dali / public-api / capture / capture.h
1 #ifndef DALI_CAPTURE_H
2 #define DALI_CAPTURE_H
3
4 /*
5  * Copyright (c) 2020 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 HEADERS
22 #include <dali/public-api/actors/actor.h>
23 #include <dali/public-api/actors/camera-actor.h>
24 #include <dali/public-api/rendering/texture.h>
25 #include <dali/public-api/signals/dali-signal.h>
26
27 // INTERNAL INCLUDES
28 #include <dali/public-api/adaptor-framework/native-image-source.h>
29 #include <dali/public-api/dali-adaptor-common.h>
30
31 namespace Dali
32 {
33 /**
34  * @addtogroup dali_adaptor_framework
35  * @{
36  */
37
38 namespace Internal DALI_INTERNAL
39 {
40 namespace Adaptor
41 {
42 class Capture;
43 }
44 } // namespace DALI_INTERNAL
45
46 /**
47  * @brief Capture snapshots the current scene and save as a file.
48  *
49  * @SINCE_1_3.4
50  *
51  * Applications should follow the example below to create capture :
52  *
53  * @code
54  * Capture capture = Capture::New();
55  * @endcode
56  *
57  * If required, you can also connect class member function to a signal :
58  *
59  * @code
60  * capture.FinishedSignal().Connect(this, &CaptureSceneExample::OnCaptureFinished);
61  * @endcode
62  *
63  * At the connected class member function, you can know whether capture finish state.
64  *
65  * @code
66  * void CaptureSceneExample::OnCaptureFinished( Capture capture, Capture::FinishState state )
67  * {
68  *   if ( state == Capture::FinishState::SUCCEEDED )
69  *   {
70  *     // Do something
71  *   }
72  *   else
73  *   {
74  *     // Do something
75  *   }
76  * }
77  * @endcode
78  */
79 class DALI_ADAPTOR_API Capture : public BaseHandle
80 {
81 public:
82   /**
83    * @brief The enumerations used for checking capture success
84    * @SINCE_1_3_4
85    */
86   enum class FinishState
87   {
88     SUCCEEDED, ///< Succeeded in saving the result after capture
89     FAILED     ///< Failed to capture by time out or to save the result
90   };
91
92   /**
93    * @brief Typedef for finished signals sent by this class.
94    *
95    * @SINCE_1_3_4
96    */
97   typedef Signal<void(Capture, Capture::FinishState)> CaptureFinishedSignalType;
98
99   /**
100    * @brief Create an uninitialized Capture; this can be initialized with Actor::New().
101    *
102    * @SINCE_1_3_4
103    *
104    * Calling member functions with an uninitialized Dali::Object is not allowed.
105    */
106   Capture();
107
108   /**
109    * @brief Create an initialized Capture.
110    *
111    * @SINCE_1_3_4
112    *
113    * @return A handle to a newly allocated Dali resource.
114    * @note Projection mode of default cameraActor is Dali::Camera::PERSPECTIVE_PROJECTION
115    */
116   static Capture New();
117
118   /**
119    * @brief Create an initialized Capture.
120    *
121    * @SINCE_1_3_4
122    *
123    * @param[in] cameraActor An initialized CameraActor.
124    * @return A handle to a newly allocated Dali resource.
125    */
126   static Capture New(Dali::CameraActor cameraActor);
127
128   /**
129    * @brief Downcast an Object handle to Capture handle.
130    *
131    * @SINCE_1_3_4
132    *
133    * If handle points to a Capture object the downcast produces valid
134    * handle. If not the returned handle is left uninitialized.
135    *
136    * @param[in] handle to An object.
137    * @return handle to a Capture object or an uninitialized handle.
138    */
139   static Capture DownCast(BaseHandle handle);
140
141   /**
142    * @brief Dali::Actor is intended as a base class.
143    *
144    * @SINCE_1_3_4
145    *
146    * This is non-virtual since derived Handle types must not contain data or virtual methods.
147    */
148   ~Capture();
149
150   /**
151    * @brief This copy constructor is required for (smart) pointer semantics.
152    *
153    * @SINCE_1_3_4
154    *
155    * @param[in] copy A reference to the copied handle.
156    */
157   Capture(const Capture& copy);
158
159   /**
160    * @brief This assignment operator is required for (smart) pointer semantics.
161    *
162    * @SINCE_1_3_4
163    *
164    * @param[in] rhs  A reference to the copied handle.
165    * @return A reference to this.
166    */
167   Capture& operator=(const Capture& rhs);
168
169   /**
170    * @brief Move constructor.
171    *
172    * @SINCE_1_9.24
173    * @param[in] rhs A reference to the moved handle
174    */
175   Capture(Capture&& rhs);
176
177   /**
178    * @brief Move assignment operator.
179    *
180    * @SINCE_1_9.24
181    * @param[in] rhs A reference to the moved handle
182    * @return A reference to this handle
183    */
184   Capture& operator=(Capture&& rhs);
185
186   /**
187    * @brief Start capture and save the image as a file.
188    *
189    * @SINCE_1_9.27
190    * @param[in] source source actor to be used for capture.
191    *            This source must be added on the window in advance.
192    * @param[in] position top-left position of area to be captured
193    *            this position is defined in the window.
194    * @param[in] size captured size.
195    * @param[in] path image file path to be saved as a file.
196    *            If path is empty string, the captured result is not be saved as a file.
197    * @param[in] clearColor background color of captured scene
198    * @note suppose that we want to capture actor 'A'. And, the actor 'A' is overlapped by another actor 'B' that is not a child of 'A'.
199    *       in this case, if source is root of scene, the captured image includes a part of actor 'B' on the 'A'.
200    *       however, if source is just actor 'A', the result includes only 'A'.
201    */
202   void Start(Actor source, const Vector2& position, const Vector2& size, const std::string& path, const Vector4& clearColor);
203
204   /**
205    * @brief Start capture and save the image as a file.
206    *
207    * @SINCE_1_9.12
208    *
209    * @param[in] source source actor to be used for capture.
210    *            This source must be added on the window in advance.
211    * @param[in] size captured size.
212    * @param[in] path image file path to be saved as a file.
213    *            If path is empty string, the captured result is not be saved as a file.
214    * @param[in] clearColor background color of captured scene
215    * @param[in] quality The value to control image quality for jpeg file format in the range [1, 100]
216    */
217   void Start(Actor source, const Vector2& size, const std::string& path, const Vector4& clearColor, const uint32_t quality);
218
219   /**
220    * @brief Start capture and save the image as a file.
221    *
222    * @SINCE_1_3_4
223    *
224    * @param[in] source source actor to be used for capture.
225    *            This source must be added on the window in advance.
226    * @param[in] size captured size.
227    * @param[in] path image file path to be saved as a file.
228    *            If path is empty string, the captured result is not be saved as a file.
229    * @param[in] clearColor background color of captured scene
230    */
231   void Start(Actor source, const Vector2& size, const std::string& path, const Vector4& clearColor);
232
233   /**
234    * @brief Start capture and save the image as a file.
235    *
236    * @SINCE_1_3_4
237    *
238    * @param[in] source source actor to be used for capture.
239    *            This source must be added on the window in advance.
240    * @param[in] size captured size.
241    * @param[in] path image file path to be saved as a file.
242    *            If path is empty string, the captured result is not be saved as a file.
243    * @note Clear color is transparent.
244    */
245   void Start(Actor source, const Vector2& size, const std::string& path);
246
247   /**
248    * @brief Set result image quality in case of jpeg
249    *
250    * @param[in] quality The value to control image quality for jpeg file format in the range [1, 100]
251    */
252   void SetImageQuality(uint32_t quality);
253
254   /**
255    * @brief Get NativeImageSourcePtr that is saved captured image.
256    *
257    * @SINCE_1_9.10
258    *
259    * @return NativeImageSourcePtr Captured result that can be rendered with DALi
260    */
261   Dali::NativeImageSourcePtr GetNativeImageSource() const;
262
263   /**
264    * @brief Get Texture of captured image.
265    *
266    * @return Texture Captured result
267    */
268   Dali::Texture GetTexture();
269
270   /**
271    * @brief Get finished signal.
272    *
273    * @SINCE_1_3_4
274    *
275    * @return finished signal instance.
276    */
277   CaptureFinishedSignalType& FinishedSignal();
278
279 public: // Not intended for application developers
280   /// @cond internal
281   /**
282    * @brief This constructor is used by New() methods.
283    *
284    * @SINCE_1_3_4
285    *
286    * @param[in] internal A pointer to a newly allocated Dali resource.
287    */
288   explicit DALI_INTERNAL Capture(Internal::Adaptor::Capture* internal);
289   /// @endcond
290 };
291
292 /**
293  * @}
294  */
295
296 } // namespace Dali
297
298 #endif // DALI_CAPTURE_H