Merge "[ATSPI] Introduce GetMatchesInMatches API" into tizen_7.0
[platform/core/uifw/dali-adaptor.git] / dali / internal / system / common / capture-impl.h
1 #ifndef DALI_INTERNAL_CAPTURE_H
2 #define DALI_INTERNAL_CAPTURE_H
3
4 /*
5  * Copyright (c) 2022 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/object/base-object.h>
23 #include <dali/public-api/object/ref-object.h>
24 #include <dali/public-api/render-tasks/render-task.h>
25 #include <dali/public-api/rendering/frame-buffer.h>
26 #include <dali/public-api/rendering/texture.h>
27 #include <memory>
28 #include <string>
29
30 // INTERNAL INCLUDES
31 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
32 #include <dali/public-api/adaptor-framework/native-image-source.h>
33 #include <dali/public-api/adaptor-framework/timer.h>
34 #include <dali/public-api/capture/capture.h>
35 #include <dali/public-api/dali-adaptor-common.h>
36
37 namespace Dali
38 {
39 namespace Internal
40 {
41 namespace Adaptor
42 {
43 class Capture;
44 typedef IntrusivePtr<Capture> CapturePtr;
45
46 class Capture : public BaseObject, public ConnectionTracker
47 {
48 public:
49   static constexpr uint32_t DEFAULT_QUALITY = 100;
50
51   /**
52    * @brief Constructor.
53    */
54   Capture();
55
56   Capture(Dali::CameraActor cameraActor);
57
58   /**
59    * @copydoc Dali::Capture::New
60    */
61   static CapturePtr New();
62
63   /**
64    * @copydoc Dali::Capture::New
65    */
66   static CapturePtr New(Dali::CameraActor cameraActor);
67
68   /**
69    * @copydoc Dali::Capture::Start
70    */
71   void Start(Dali::Actor source, const Dali::Vector2& position, const Dali::Vector2& size, const std::string& path, const Dali::Vector4& clearColor, const uint32_t quality);
72
73   /**
74    * @copydoc Dali::Capture::Start
75    */
76   void Start(Dali::Actor source, const Dali::Vector2& position, const Dali::Vector2& size, const std::string& path, const Dali::Vector4& clearColor);
77
78   /**
79    * @copydoc Dali::Capture::SetImageQuality
80    */
81   void SetImageQuality(uint32_t quality);
82
83   /**
84    * @copydoc Dali::Capture::GetNativeImageSource
85    */
86   Dali::NativeImageSourcePtr GetNativeImageSource() const;
87
88   /**
89    * @copydoc Dali::Capture::GetCapturedBuffer
90    */
91   Dali::Devel::PixelBuffer GetCapturedBuffer();
92
93   /**
94    * @copydoc Dali::Capture::FinishedSignal
95    */
96   Dali::Capture::CaptureFinishedSignalType& FinishedSignal();
97
98 protected:
99   /**
100    * @brief A reference counted object may only be deleted by calling Unreference()
101    */
102   virtual ~Capture();
103
104 private:
105   /**
106    * @brief Create texture.
107    */
108   void CreateTexture(const Dali::Vector2& size);
109
110   /**
111    * @brief Delete native image source.
112    */
113   void DeleteNativeImageSource();
114
115   /**
116    * @brief Create frame buffer.
117    */
118   void CreateFrameBuffer();
119
120   /**
121    * @brief Delete frame buffer.
122    */
123   void DeleteFrameBuffer();
124
125   /**
126    * @brief Query whether frame buffer is created or not.
127    *
128    * @return True is frame buffer is created.
129    */
130   bool IsFrameBufferCreated();
131
132   /**
133    * @brief Setup render task.
134    *
135    * @param[in] position top-left position of area to be captured
136    *            this position is defined in the window.
137    * @param[in] size two dimensional size of area to be captured
138    * @param[in] source sub-scene tree to be captured.
139    * @param[in] clearColor background color
140    */
141   void SetupRenderTask(const Dali::Vector2& position, const Dali::Vector2& size, Dali::Actor source, const Dali::Vector4& clearColor);
142
143   /**
144    * @brief Unset render task.
145    */
146   void UnsetRenderTask();
147
148   /**
149    * @brief Query whether render task is setup or not.
150    *
151    * @return True is render task is setup.
152    */
153   bool IsRenderTaskSetup();
154
155   /**
156    * @brief Setup resources for capture.
157    *
158    * @param[in] position top-left position of area to be captured
159    *            this position is defined in the window.
160    * @param[in] size two dimensional size of area to be captured
161    * @param[in] clearColor color to clear background surface.
162    * @param[in] source sub-scene tree to be captured.
163    */
164   void SetupResources(const Dali::Vector2& position, const Dali::Vector2& size, const Dali::Vector4& clearColor, Dali::Actor source);
165
166   /**
167    * @brief Unset resources for capture.
168    */
169   void UnsetResources();
170
171   /**
172    * @brief Callback when render is finished.
173    *
174    * @param[in] task is used for capture.
175    */
176   void OnRenderFinished(Dali::RenderTask& task);
177
178   /**
179    * @brief Callback when timer is finished.
180    *
181    * @return True is timer start again.
182    */
183   bool OnTimeOut();
184
185   /**
186    * @brief Save framebuffer.
187    *
188    * @return True is success to save, false is fail.
189    */
190   bool SaveFile();
191
192 private:
193   // Undefined
194   Capture(const Capture&);
195
196   // Undefined
197   Capture& operator=(const Capture& rhs);
198
199 private:
200   uint32_t                                 mQuality;
201   Dali::Texture                            mTexture;
202   Dali::FrameBuffer                        mFrameBuffer;
203   Dali::RenderTask                         mRenderTask;
204   Dali::Actor                              mSource;
205   Dali::CameraActor                        mCameraActor;
206   Dali::Timer                              mTimer; ///< For timeout.
207   Dali::Capture::CaptureFinishedSignalType mFinishedSignal;
208   std::string                              mPath;
209   Dali::NativeImageSourcePtr               mNativeImageSourcePtr; ///< pointer to surface image
210   Dali::Devel::PixelBuffer                 mPixelBuffer;
211   bool                                     mFileSave;
212   bool                                     mUseDefaultCamera;                   // Whether we use default generated camera, or use inputed camera.
213   bool                                     mSceneOffCameraAfterCaptureFinished; // Whether we need to scene-off after capture finished.
214 };
215
216 } // End of namespace Adaptor
217 } // End of namespace Internal
218
219 // Helpers for public-api forwarding methods
220
221 inline Internal::Adaptor::Capture& GetImpl(Dali::Capture& captureWorker)
222 {
223   DALI_ASSERT_ALWAYS(captureWorker && "Capture handle is empty");
224
225   BaseObject& handle = captureWorker.GetBaseObject();
226
227   return static_cast<Internal::Adaptor::Capture&>(handle);
228 }
229
230 inline const Internal::Adaptor::Capture& GetImpl(const Dali::Capture& captureWorker)
231 {
232   DALI_ASSERT_ALWAYS(captureWorker && "Capture handle is empty");
233
234   const BaseObject& handle = captureWorker.GetBaseObject();
235
236   return static_cast<const Internal::Adaptor::Capture&>(handle);
237 }
238
239 } // End of namespace Dali
240
241 #endif // DALI_INTERNAL_CAPTURE_H