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