1 #ifndef DALI_INTERNAL_CAPTURE_H
2 #define DALI_INTERNAL_CAPTURE_H
5 * Copyright (c) 2021 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.
22 #include <dali/public-api/object/base-object.h>
23 #include <dali/public-api/object/ref-object.h>
24 #include <dali/public-api/render-tasks/render-task.h>
25 #include <dali/public-api/rendering/frame-buffer.h>
26 #include <dali/public-api/rendering/texture.h>
31 #include <dali/public-api/adaptor-framework/native-image-source.h>
32 #include <dali/public-api/adaptor-framework/timer.h>
33 #include <dali/public-api/capture/capture.h>
34 #include <dali/public-api/dali-adaptor-common.h>
43 typedef IntrusivePtr<Capture> CapturePtr;
45 class Capture : public BaseObject, public ConnectionTracker
48 static constexpr uint32_t DEFAULT_QUALITY = 100;
55 Capture(Dali::CameraActor cameraActor);
58 * @copydoc Dali::Capture::New
60 static CapturePtr New();
63 * @copydoc Dali::Capture::New
65 static CapturePtr New(Dali::CameraActor cameraActor);
68 * @copydoc Dali::Capture::Start
70 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);
73 * @copydoc Dali::Capture::Start
75 void Start(Dali::Actor source, const Dali::Vector2& position, const Dali::Vector2& size, const std::string& path, const Dali::Vector4& clearColor);
78 * @copydoc Dali::Capture::SetImageQuality
80 void SetImageQuality(uint32_t quality);
83 * @copydoc Dali::Capture::GetNativeImageSource
85 Dali::NativeImageSourcePtr GetNativeImageSource() const;
88 * @copydoc Dali::Capture::FinishedSignal
90 Dali::Capture::CaptureFinishedSignalType& FinishedSignal();
94 * @brief A reference counted object may only be deleted by calling Unreference()
100 * @brief Create native image source.
102 void CreateNativeImageSource(const Dali::Vector2& size);
105 * @brief Delete native image source.
107 void DeleteNativeImageSource();
110 * @brief Query whether native image source is created or not.
112 * @return True is native image source is created.
114 bool IsNativeImageSourceCreated();
117 * @brief Create frame buffer.
119 void CreateFrameBuffer();
122 * @brief Delete frame buffer.
124 void DeleteFrameBuffer();
127 * @brief Query whether frame buffer is created or not.
129 * @return True is frame buffer is created.
131 bool IsFrameBufferCreated();
134 * @brief Setup render task.
136 * @param[in] position top-left position of area to be captured
137 * this position is defined in the window.
138 * @param[in] size two dimensional size of area to be captured
139 * @param[in] source sub-scene tree to be captured.
140 * @param[in] clearColor background color
142 void SetupRenderTask(const Dali::Vector2& position, const Dali::Vector2& size, Dali::Actor source, const Dali::Vector4& clearColor);
145 * @brief Unset render task.
147 void UnsetRenderTask();
150 * @brief Query whether render task is setup or not.
152 * @return True is render task is setup.
154 bool IsRenderTaskSetup();
157 * @brief Setup resources for capture.
159 * @param[in] position top-left position of area to be captured
160 * this position is defined in the window.
161 * @param[in] size two dimensional size of area to be captured
162 * @param[in] clearColor color to clear background surface.
163 * @param[in] source sub-scene tree to be captured.
165 void SetupResources(const Dali::Vector2& position, const Dali::Vector2& size, const Dali::Vector4& clearColor, Dali::Actor source);
168 * @brief Unset resources for capture.
170 void UnsetResources();
173 * @brief Callback when render is finished.
175 * @param[in] task is used for capture.
177 void OnRenderFinished(Dali::RenderTask& task);
180 * @brief Callback when timer is finished.
182 * @return True is timer start again.
187 * @brief Save framebuffer.
189 * @return True is success to save, false is fail.
195 Capture(const Capture&);
198 Capture& operator=(const Capture& rhs);
202 Dali::Texture mNativeTexture;
203 Dali::FrameBuffer mFrameBuffer;
204 Dali::RenderTask mRenderTask;
206 Dali::CameraActor mCameraActor;
207 Dali::Timer mTimer; ///< For timeout.
208 Dali::Capture::CaptureFinishedSignalType mFinishedSignal;
210 Dali::NativeImageSourcePtr mNativeImageSourcePtr; ///< pointer to surface image
214 } // End of namespace Adaptor
215 } // End of namespace Internal
217 // Helpers for public-api forwarding methods
219 inline Internal::Adaptor::Capture& GetImpl(Dali::Capture& captureWorker)
221 DALI_ASSERT_ALWAYS(captureWorker && "Capture handle is empty");
223 BaseObject& handle = captureWorker.GetBaseObject();
225 return static_cast<Internal::Adaptor::Capture&>(handle);
228 inline const Internal::Adaptor::Capture& GetImpl(const Dali::Capture& captureWorker)
230 DALI_ASSERT_ALWAYS(captureWorker && "Capture handle is empty");
232 const BaseObject& handle = captureWorker.GetBaseObject();
234 return static_cast<const Internal::Adaptor::Capture&>(handle);
237 } // End of namespace Dali
239 #endif // DALI_INTERNAL_CAPTURE_H