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>
45 typedef IntrusivePtr<Capture> CapturePtr;
47 class Capture : public BaseObject, public ConnectionTracker
51 static constexpr uint32_t DEFAULT_QUALITY = 100;
58 Capture( Dali::CameraActor cameraActor );
61 * @copydoc Dali::Capture::New
63 static CapturePtr New();
66 * @copydoc Dali::Capture::New
68 static CapturePtr New( Dali::CameraActor cameraActor );
71 * @copydoc Dali::Capture::Start
73 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 );
76 * @copydoc Dali::Capture::Start
78 void Start( Dali::Actor source, const Dali::Vector2& position, const Dali::Vector2& size, const std::string &path, const Dali::Vector4& clearColor );
81 * @copydoc Dali::Capture::SetImageQuality
83 void SetImageQuality( uint32_t quality );
86 * @copydoc Dali::Capture::GetNativeImageSource
88 Dali::NativeImageSourcePtr GetNativeImageSource() const;
91 * @copydoc Dali::Capture::GetTexture
93 Dali::Texture GetTexture();
96 * @copydoc Dali::Capture::FinishedSignal
98 Dali::Capture::CaptureFinishedSignalType& FinishedSignal();
103 * @brief A reference counted object may only be deleted by calling Unreference()
109 * @brief Create native image source.
111 void CreateTexture( const Dali::Vector2& size );
114 * @brief Delete native image source.
116 void DeleteNativeImageSource();
119 * @brief Create frame buffer.
121 void CreateFrameBuffer();
124 * @brief Delete frame buffer.
126 void DeleteFrameBuffer();
129 * @brief Query whether frame buffer is created or not.
131 * @return True is frame buffer is created.
133 bool IsFrameBufferCreated();
136 * @brief Setup render task.
138 * @param[in] position top-left position of area to be captured
139 * this position is defined in the window.
140 * @param[in] size two dimensional size of area to be captured
141 * @param[in] source sub-scene tree to be captured.
142 * @param[in] clearColor background color
144 void SetupRenderTask( const Dali::Vector2& position, const Dali::Vector2& size, Dali::Actor source, const Dali::Vector4& clearColor );
147 * @brief Unset render task.
149 void UnsetRenderTask();
152 * @brief Query whether render task is setup or not.
154 * @return True is render task is setup.
156 bool IsRenderTaskSetup();
159 * @brief Setup resources for capture.
161 * @param[in] position top-left position of area to be captured
162 * this position is defined in the window.
163 * @param[in] size two dimensional size of area to be captured
164 * @param[in] clearColor color to clear background surface.
165 * @param[in] source sub-scene tree to be captured.
167 void SetupResources( const Dali::Vector2& position, const Dali::Vector2& size, const Dali::Vector4& clearColor, Dali::Actor source );
170 * @brief Unset resources for capture.
172 void UnsetResources();
175 * @brief Callback when render is finished.
177 * @param[in] task is used for capture.
179 void OnRenderFinished( Dali::RenderTask& task );
182 * @brief Callback when timer is finished.
184 * @return True is timer start again.
189 * @brief Save framebuffer.
191 * @return True is success to save, false is fail.
198 Capture( const Capture& );
201 Capture& operator=( const Capture& rhs );
205 Dali::Texture mTexture;
206 Dali::FrameBuffer mFrameBuffer;
207 Dali::RenderTask mRenderTask;
209 Dali::CameraActor mCameraActor;
210 Dali::Timer mTimer; ///< For timeout.
211 Dali::Capture::CaptureFinishedSignalType mFinishedSignal;
213 Dali::NativeImageSourcePtr mNativeImageSourcePtr; ///< pointer to surface image
215 bool mIsNativeImageSourcePossible;
218 } // End of namespace Adaptor
219 } // End of namespace Internal
221 // Helpers for public-api forwarding methods
223 inline Internal::Adaptor::Capture& GetImpl( Dali::Capture& captureWorker)
225 DALI_ASSERT_ALWAYS( captureWorker && "Capture handle is empty" );
227 BaseObject& handle = captureWorker.GetBaseObject();
229 return static_cast< Internal::Adaptor::Capture& >( handle );
232 inline const Internal::Adaptor::Capture& GetImpl( const Dali::Capture& captureWorker )
234 DALI_ASSERT_ALWAYS( captureWorker && "Capture handle is empty" );
236 const BaseObject& handle = captureWorker.GetBaseObject();
238 return static_cast< const Internal::Adaptor::Capture& >( handle );
241 } // End of namespace Dali
243 #endif // DALI_INTERNAL_CAPTURE_H