1 #ifndef DALI_INTERNAL_CAPTURE_H
2 #define DALI_INTERNAL_CAPTURE_H
5 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
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>
47 typedef IntrusivePtr<Capture> CapturePtr;
49 class Capture : public BaseObject, public ConnectionTracker
57 Capture( Dali::CameraActor cameraActor );
60 * @copydoc Dali::Capture::New
62 static CapturePtr New();
65 * @copydoc Dali::Capture::New
67 static CapturePtr New( Dali::CameraActor cameraActor );
70 * @copydoc Dali::Capture::Start
72 void Start( Dali::Actor source, const Dali::Vector2& size, const std::string &path, const Dali::Vector4& clearColor );
75 * @copydoc Dali::Capture::FinishedSignal
77 Dali::Capture::CaptureFinishedSignalType& FinishedSignal();
82 * @brief A reference counted object may only be deleted by calling Unreference()
88 * @brief Create surface.
90 * @param[in] size of surface.
92 void CreateSurface( const Dali::Vector2& size );
95 * @brief Delete surface.
100 * @brief Clear surface with color.
102 * @param[in] size of clear aread.
104 void ClearSurface( const Dali::Vector2& size );
107 * @brief Query whether surface is created or not.
109 * @return True is surface is created.
111 bool IsSurfaceCreated();
114 * @brief Create native image source.
116 void CreateNativeImageSource();
119 * @brief Delete native image source.
121 void DeleteNativeImageSource();
124 * @brief Query whether native image source is created or not.
126 * @return True is native image source is created.
128 bool IsNativeImageSourceCreated();
131 * @brief Create frame buffer.
133 void CreateFrameBuffer();
136 * @brief Delete frame buffer.
138 void DeleteFrameBuffer();
141 * @brief Query whether frame buffer is created or not.
143 * @return True is frame buffer is created.
145 bool IsFrameBufferCreated();
148 * @brief Setup render task.
150 * @param[in] source is captured.
151 * @param[in] clearColor background color
153 void SetupRenderTask( Dali::Actor source, const Dali::Vector4& clearColor );
156 * @brief Unset render task.
158 void UnsetRenderTask();
161 * @brief Query whether render task is setup or not.
163 * @return True is render task is setup.
165 bool IsRenderTaskSetup();
168 * @brief Setup resources for capture.
170 * @param[in] size is surface size.
171 * @param[in] clearColor is clear color of surface.
172 * @param[in] source is captured.
174 void SetupResources( const Dali::Vector2& size, const Dali::Vector4& clearColor, Dali::Actor source );
177 * @brief Unset resources for capture.
179 void UnsetResources();
182 * @brief Callback when render is finished.
184 * @param[in] task is used for capture.
186 void OnRenderFinished( Dali::RenderTask& task );
189 * @brief Callback when timer is finished.
191 * @return True is timer start again.
196 * @brief Save framebuffer.
198 * @return True is success to save, false is fail.
205 Capture( const Capture& );
208 Capture& operator=( const Capture& rhs );
211 Dali::Texture mNativeTexture;
212 Dali::FrameBuffer mFrameBuffer;
213 Dali::RenderTask mRenderTask;
216 Dali::CameraActor mCameraActor;
217 Dali::Timer mTimer; ///< For timeout.
218 Dali::Capture::CaptureFinishedSignalType mFinishedSignal;
220 Dali::NativeImageSourcePtr mNativeImageSourcePtr; ///< pointer to surface image
221 tbm_surface_h mTbmSurface;
224 } // End of namespace Adaptor
225 } // End of namespace Internal
227 // Helpers for public-api forwarding methods
229 inline Internal::Adaptor::Capture& GetImpl( Dali::Capture& captureWorker)
231 DALI_ASSERT_ALWAYS( captureWorker && "Capture handle is empty" );
233 BaseObject& handle = captureWorker.GetBaseObject();
235 return static_cast< Internal::Adaptor::Capture& >( handle );
238 inline const Internal::Adaptor::Capture& GetImpl( const Dali::Capture& captureWorker )
240 DALI_ASSERT_ALWAYS( captureWorker && "Capture handle is empty" );
242 const BaseObject& handle = captureWorker.GetBaseObject();
244 return static_cast< const Internal::Adaptor::Capture& >( handle );
247 } // End of namespace Dali
249 #endif // DALI_INTERNAL_CAPTURE_H