1 #ifndef DALI_INTERNAL_CAPTURE_H
2 #define DALI_INTERNAL_CAPTURE_H
5 * Copyright (c) 2017 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/common/dali-common.h>
28 #include <dali/public-api/render-tasks/render-task.h>
29 #include <dali/public-api/rendering/texture.h>
30 #include <dali/public-api/rendering/frame-buffer.h>
33 #include <native-image-source.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 Second-phase constructor. Must be called immediately after creating a new Capture;
87 * @brief A reference counted object may only be deleted by calling Unreference()
93 * @brief Create surface.
95 * @param[in] size of surface.
97 void CreateSurface( const Dali::Vector2& size );
100 * @brief Delete surface.
102 void DeleteSurface();
105 * @brief Clear surface with color.
107 * @param[in] size of clear aread.
109 void ClearSurface( const Dali::Vector2& size );
112 * @brief Query whether surface is created or not.
114 * @return True is surface is created.
116 bool IsSurfaceCreated();
119 * @brief Create native image source.
121 void CreateNativeImageSource();
124 * @brief Delete native image source.
126 void DeleteNativeImageSource();
129 * @brief Query whether native image source is created or not.
131 * @return True is native image source is created.
133 bool IsNativeImageSourceCreated();
136 * @brief Create frame buffer.
138 void CreateFrameBuffer();
141 * @brief Delete frame buffer.
143 void DeleteFrameBuffer();
146 * @brief Query whether frame buffer is created or not.
148 * @return True is frame buffer is created.
150 bool IsFrameBufferCreated();
153 * @brief Setup render task.
155 * @param[in] source is captured.
156 * @param[in] clearColor background color
158 void SetupRenderTask( Dali::Actor source, const Dali::Vector4& clearColor );
161 * @brief Unset render task.
163 void UnsetRenderTask();
166 * @brief Query whether render task is setup or not.
168 * @return True is render task is setup.
170 bool IsRenderTaskSetup();
173 * @brief Setup resources for capture.
175 * @param[in] size is surface size.
176 * @param[in] clearColor is clear color of surface.
177 * @param[in] source is captured.
179 void SetupResources( const Dali::Vector2& size, const Dali::Vector4& clearColor, Dali::Actor source );
182 * @brief Unset resources for capture.
184 void UnsetResources();
187 * @brief Callback when render is finished.
189 * @param[in] task is used for capture.
191 void OnRenderFinished( Dali::RenderTask& task );
194 * @brief Callback when timer is finished.
196 * @return True is timer start again.
201 * @brief Save framebuffer.
203 * @return True is success to save, false is fail.
210 Capture( const Capture& );
213 Capture& operator=( const Capture& rhs );
216 Dali::Texture mNativeTexture;
217 Dali::FrameBuffer mFrameBuffer;
218 Dali::RenderTask mRenderTask;
221 Dali::CameraActor mCameraActor;
222 Dali::Timer mTimer; ///< For timeout.
223 Dali::Capture::CaptureFinishedSignalType mFinishedSignal;
225 Dali::NativeImageSourcePtr mNativeImageSourcePtr; ///< pointer to surface image
226 tbm_surface_h mTbmSurface;
229 } // End of namespace Adaptor
230 } // End of namespace Internal
232 // Helpers for public-api forwarding methods
234 inline Internal::Adaptor::Capture& GetImpl( Dali::Capture& captureWorker)
236 DALI_ASSERT_ALWAYS( captureWorker && "Capture handle is empty" );
238 BaseObject& handle = captureWorker.GetBaseObject();
240 return static_cast< Internal::Adaptor::Capture& >( handle );
243 inline const Internal::Adaptor::Capture& GetImpl( const Dali::Capture& captureWorker )
245 DALI_ASSERT_ALWAYS( captureWorker && "Capture handle is empty" );
247 const BaseObject& handle = captureWorker.GetBaseObject();
249 return static_cast< const Internal::Adaptor::Capture& >( handle );
252 } // End of namespace Dali
254 #endif // DALI_INTERNAL_CAPTURE_H