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