DALi Version 1.9.9
[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) 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 <dali/public-api/object/ref-object.h>
25 #include <dali/public-api/object/base-object.h>
26 #include <dali/public-api/render-tasks/render-task.h>
27 #include <dali/public-api/rendering/texture.h>
28 #include <dali/public-api/rendering/frame-buffer.h>
29
30 // INTERNAL INCLUDES
31 #include <dali/public-api/dali-adaptor-common.h>
32 #include <dali/public-api/capture/capture.h>
33 #include <dali/public-api/adaptor-framework/native-image-source.h>
34 #include <dali/public-api/adaptor-framework/timer.h>
35
36 namespace Dali
37 {
38
39 namespace Internal
40 {
41
42 namespace Adaptor
43 {
44
45 class Capture;
46 typedef IntrusivePtr<Capture> CapturePtr;
47
48 class Capture : public BaseObject, public ConnectionTracker
49 {
50 public:
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& size, const std::string &path, const Dali::Vector4& clearColor );
72
73   /**
74    * @copydoc Dali::Capture::FinishedSignal
75    */
76   Dali::Capture::CaptureFinishedSignalType& FinishedSignal();
77
78 protected:
79
80   /**
81    * @brief A reference counted object may only be deleted by calling Unreference()
82    */
83   virtual ~Capture();
84
85 private:
86   /**
87    * @brief Create native image source.
88    */
89   void CreateNativeImageSource( const Dali::Vector2& size );
90
91   /**
92    * @brief Delete native image source.
93    */
94   void DeleteNativeImageSource();
95
96   /**
97    * @brief Query whether native image source is created or not.
98    *
99    * @return True is native image source is created.
100    */
101   bool IsNativeImageSourceCreated();
102
103   /**
104    * @brief Create frame buffer.
105    */
106   void CreateFrameBuffer();
107
108   /**
109    * @brief Delete frame buffer.
110    */
111   void DeleteFrameBuffer();
112
113   /**
114    * @brief Query whether frame buffer is created or not.
115    *
116    * @return True is frame buffer is created.
117    */
118   bool IsFrameBufferCreated();
119
120   /**
121    * @brief Setup render task.
122    *
123    * @param[in] source is captured.
124    * @param[in] clearColor background color
125    */
126   void SetupRenderTask( Dali::Actor source, const Dali::Vector4& clearColor );
127
128   /**
129    * @brief Unset render task.
130    */
131   void UnsetRenderTask();
132
133   /**
134    * @brief Query whether render task is setup or not.
135    *
136    * @return True is render task is setup.
137    */
138   bool IsRenderTaskSetup();
139
140   /**
141    * @brief Setup resources for capture.
142    *
143    * @param[in] size is surface size.
144    * @param[in] clearColor is clear color of surface.
145    * @param[in] source is captured.
146    */
147   void SetupResources( const Dali::Vector2& size, const Dali::Vector4& clearColor, Dali::Actor source );
148
149   /**
150    * @brief Unset resources for capture.
151    */
152   void UnsetResources();
153
154   /**
155    * @brief Callback when render is finished.
156    *
157    * @param[in] task is used for capture.
158    */
159   void OnRenderFinished( Dali::RenderTask& task );
160
161   /**
162    * @brief Callback when timer is finished.
163    *
164    * @return True is timer start again.
165    */
166   bool OnTimeOut();
167
168   /**
169    * @brief Save framebuffer.
170    *
171    * @return True is success to save, false is fail.
172    */
173   bool Save();
174
175 private:
176
177   // Undefined
178   Capture( const Capture& );
179
180   // Undefined
181   Capture& operator=( const Capture& rhs );
182
183 private:
184   Dali::Texture                               mNativeTexture;
185   Dali::FrameBuffer                           mFrameBuffer;
186   Dali::RenderTask                            mRenderTask;
187   Dali::Actor                                 mParent;
188   Dali::Actor                                 mSource;
189   Dali::CameraActor                           mCameraActor;
190   Dali::Timer                                 mTimer;           ///< For timeout.
191   Dali::Capture::CaptureFinishedSignalType    mFinishedSignal;
192   std::string                                 mPath;
193   Dali::NativeImageSourcePtr                  mNativeImageSourcePtr;  ///< pointer to surface image
194 };
195
196 }  // End of namespace Adaptor
197 }  // End of namespace Internal
198
199 // Helpers for public-api forwarding methods
200
201 inline Internal::Adaptor::Capture& GetImpl( Dali::Capture& captureWorker)
202 {
203   DALI_ASSERT_ALWAYS( captureWorker && "Capture handle is empty" );
204
205   BaseObject& handle = captureWorker.GetBaseObject();
206
207   return static_cast< Internal::Adaptor::Capture& >( handle );
208 }
209
210 inline const Internal::Adaptor::Capture& GetImpl( const Dali::Capture& captureWorker )
211 {
212   DALI_ASSERT_ALWAYS( captureWorker && "Capture handle is empty" );
213
214   const BaseObject& handle = captureWorker.GetBaseObject();
215
216   return static_cast< const Internal::Adaptor::Capture& >( handle );
217 }
218
219 }  // End of namespace Dali
220
221 #endif // DALI_INTERNAL_CAPTURE_H