1 #ifndef DALI_INTERNAL_CAPTURE_H
2 #define DALI_INTERNAL_CAPTURE_H
5 * Copyright (c) 2020 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 <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/frame-buffer.h>
30 #include <dali/public-api/dali-adaptor-common.h>
31 #include <dali/public-api/capture/capture.h>
32 #include <dali/public-api/adaptor-framework/native-image-source.h>
33 #include <dali/public-api/adaptor-framework/timer.h>
34 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
46 typedef IntrusivePtr<Capture> CapturePtr;
48 class Capture : public BaseObject, public ConnectionTracker
52 static constexpr uint32_t DEFAULT_QUALITY = 100;
59 Capture( Dali::CameraActor cameraActor );
62 * @copydoc Dali::Capture::New
64 static CapturePtr New();
67 * @copydoc Dali::Capture::New
69 static CapturePtr New( Dali::CameraActor cameraActor );
72 * @copydoc Dali::Capture::Start
74 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 );
77 * @copydoc Dali::Capture::Start
79 void Start( Dali::Actor source, const Dali::Vector2& position, const Dali::Vector2& size, const std::string &path, const Dali::Vector4& clearColor );
82 * @copydoc Dali::Capture::SetImageQuality
84 void SetImageQuality( uint32_t quality );
87 * @copydoc Dali::Capture::GetNativeImageSource
89 Dali::NativeImageSourcePtr GetNativeImageSource() const;
92 * @copydoc Dali::Capture::GetTexture
94 Dali::Texture GetTexture();
97 * @copydoc Dali::Capture::GetCapturedBuffer
99 Dali::Devel::PixelBuffer GetCapturedBuffer();
102 * @copydoc Dali::Capture::FinishedSignal
104 Dali::Capture::CaptureFinishedSignalType& FinishedSignal();
109 * @brief A reference counted object may only be deleted by calling Unreference()
115 * @brief Create native image source.
117 void CreateTexture( const Dali::Vector2& size );
120 * @brief Delete native image source.
122 void DeleteNativeImageSource();
125 * @brief Create frame buffer.
127 void CreateFrameBuffer();
130 * @brief Delete frame buffer.
132 void DeleteFrameBuffer();
135 * @brief Query whether frame buffer is created or not.
137 * @return True is frame buffer is created.
139 bool IsFrameBufferCreated();
142 * @brief Setup render task.
144 * @param[in] position top-left position of area to be captured
145 * this position is defined in the window.
146 * @param[in] size two dimensional size of area to be captured
147 * @param[in] source sub-scene tree to be captured.
148 * @param[in] clearColor background color
150 void SetupRenderTask( const Dali::Vector2& position, const Dali::Vector2& size, Dali::Actor source, const Dali::Vector4& clearColor );
153 * @brief Unset render task.
155 void UnsetRenderTask();
158 * @brief Query whether render task is setup or not.
160 * @return True is render task is setup.
162 bool IsRenderTaskSetup();
165 * @brief Setup resources for capture.
167 * @param[in] position top-left position of area to be captured
168 * this position is defined in the window.
169 * @param[in] size two dimensional size of area to be captured
170 * @param[in] clearColor color to clear background surface.
171 * @param[in] source sub-scene tree to be captured.
173 void SetupResources( const Dali::Vector2& position, const Dali::Vector2& size, const Dali::Vector4& clearColor, Dali::Actor source );
176 * @brief Unset resources for capture.
178 void UnsetResources();
181 * @brief Callback when render is finished.
183 * @param[in] task is used for capture.
185 void OnRenderFinished( Dali::RenderTask& task );
188 * @brief Callback when timer is finished.
190 * @return True is timer start again.
195 * @brief Save framebuffer.
197 * @return True is success to save, false is fail.
204 Capture( const Capture& );
207 Capture& operator=( const Capture& rhs );
211 Dali::Texture mTexture;
212 Dali::FrameBuffer mFrameBuffer;
213 Dali::RenderTask mRenderTask;
215 Dali::CameraActor mCameraActor;
216 Dali::Timer mTimer; ///< For timeout.
217 Dali::Capture::CaptureFinishedSignalType mFinishedSignal;
219 Dali::NativeImageSourcePtr mNativeImageSourcePtr; ///< pointer to surface image
220 Dali::Devel::PixelBuffer mPixelBuffer;
222 bool mIsNativeImageSourcePossible;
225 } // End of namespace Adaptor
226 } // End of namespace Internal
228 // Helpers for public-api forwarding methods
230 inline Internal::Adaptor::Capture& GetImpl( Dali::Capture& captureWorker)
232 DALI_ASSERT_ALWAYS( captureWorker && "Capture handle is empty" );
234 BaseObject& handle = captureWorker.GetBaseObject();
236 return static_cast< Internal::Adaptor::Capture& >( handle );
239 inline const Internal::Adaptor::Capture& GetImpl( const Dali::Capture& captureWorker )
241 DALI_ASSERT_ALWAYS( captureWorker && "Capture handle is empty" );
243 const BaseObject& handle = captureWorker.GetBaseObject();
245 return static_cast< const Internal::Adaptor::Capture& >( handle );
248 } // End of namespace Dali
250 #endif // DALI_INTERNAL_CAPTURE_H