1 #ifndef DALI_INTERNAL_CAPTURE_H
2 #define DALI_INTERNAL_CAPTURE_H
5 * Copyright (c) 2022 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/integration-api/processor-interface.h>
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/public-api/object/ref-object.h>
25 #include <dali/public-api/object/weak-handle.h>
26 #include <dali/public-api/render-tasks/render-task.h>
27 #include <dali/public-api/rendering/frame-buffer.h>
28 #include <dali/public-api/rendering/texture.h>
33 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
34 #include <dali/integration-api/adaptor-framework/scene-holder-impl.h>
35 #include <dali/public-api/adaptor-framework/native-image-source.h>
36 #include <dali/public-api/adaptor-framework/timer.h>
37 #include <dali/public-api/capture/capture.h>
38 #include <dali/public-api/dali-adaptor-common.h>
47 typedef IntrusivePtr<Capture> CapturePtr;
49 class Capture : public BaseObject, public ConnectionTracker, public Integration::Processor
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::SetExclusive
89 void SetExclusive(bool exclusive);
92 * @copydoc Dali::Capture::IsExclusive
94 bool IsExclusive() const;
97 * @copydoc Dali::Capture::GetNativeImageSource
99 Dali::NativeImageSourcePtr GetNativeImageSource() const;
102 * @copydoc Dali::Capture::GetCapturedBuffer
104 Dali::Devel::PixelBuffer GetCapturedBuffer();
107 * @copydoc Dali::Capture::GetTexture
109 Dali::Texture GetTexture() const;
112 * @copydoc Dali::Capture::FinishedSignal
114 Dali::Capture::CaptureFinishedSignalType& FinishedSignal();
118 * @brief A reference counted object may only be deleted by calling Unreference()
124 * @brief Create texture.
126 void CreateTexture(const Dali::Vector2& size);
129 * @brief Delete native image source.
131 void DeleteNativeImageSource();
134 * @brief Create frame buffer.
136 void CreateFrameBuffer();
139 * @brief Delete frame buffer.
141 void DeleteFrameBuffer();
144 * @brief Query whether frame buffer is created or not.
146 * @return True is frame buffer is created.
148 bool IsFrameBufferCreated();
151 * @brief Setup render task.
153 * @param[in] position top-left position of area to be captured
154 * this position is defined in the window.
155 * @param[in] size two dimensional size of area to be captured
156 * @param[in] source sub-scene tree to be captured.
157 * @param[in] clearColor background color
159 void SetupRenderTask(const Dali::Vector2& position, const Dali::Vector2& size, Dali::Actor source, const Dali::Vector4& clearColor);
162 * @brief Unset render task.
164 void UnsetRenderTask();
167 * @brief Query whether render task is setup or not.
169 * @return True is render task is setup.
171 bool IsRenderTaskSetup();
174 * @brief Setup resources for capture.
176 * @param[in] position top-left position of area to be captured
177 * this position is defined in the window.
178 * @param[in] size two dimensional size of area to be captured
179 * @param[in] clearColor color to clear background surface.
180 * @param[in] source sub-scene tree to be captured.
182 void SetupResources(const Dali::Vector2& position, const Dali::Vector2& size, const Dali::Vector4& clearColor, Dali::Actor source);
185 * @brief Unset resources for capture.
187 void UnsetResources();
190 * @brief Callback when render is finished.
192 * @param[in] task is used for capture.
194 void OnRenderFinished(Dali::RenderTask& task);
197 * @brief Callback when timer is finished.
199 * @return True is timer start again.
204 * @brief Save framebuffer.
206 * @return True is success to save, false is fail.
212 Capture(const Capture&);
215 Capture& operator=(const Capture& rhs);
217 protected: // Implementation of Processor
219 * @copydoc Dali::Integration::Processor::Process()
221 void Process(bool postProcessor) override;
224 * @copydoc Dali::Integration::Processor::GetProcessorName()
226 std::string_view GetProcessorName() const override
233 Dali::Texture mTexture;
234 Dali::WeakHandle<Dali::Integration::SceneHolder> mSceneHolderHandle;
235 Dali::FrameBuffer mFrameBuffer;
236 Dali::RenderTask mRenderTask;
238 Dali::CameraActor mCameraActor;
239 Dali::Timer mTimer; ///< For timeout.
240 Dali::Capture::CaptureFinishedSignalType mFinishedSignal;
242 Dali::NativeImageSourcePtr mNativeImageSourcePtr; ///< pointer to surface image
243 Dali::Devel::PixelBuffer mPixelBuffer;
244 bool mInCapture{false};
245 bool mIsExclusive{false};
247 bool mUseDefaultCamera; // Whether we use default generated camera, or use inputed camera.
248 bool mSceneOffCameraAfterCaptureFinished; // Whether we need to scene-off after capture finished.
251 } // End of namespace Adaptor
252 } // End of namespace Internal
254 // Helpers for public-api forwarding methods
256 inline Internal::Adaptor::Capture& GetImpl(Dali::Capture& captureWorker)
258 DALI_ASSERT_ALWAYS(captureWorker && "Capture handle is empty");
260 BaseObject& handle = captureWorker.GetBaseObject();
262 return static_cast<Internal::Adaptor::Capture&>(handle);
265 inline const Internal::Adaptor::Capture& GetImpl(const Dali::Capture& captureWorker)
267 DALI_ASSERT_ALWAYS(captureWorker && "Capture handle is empty");
269 const BaseObject& handle = captureWorker.GetBaseObject();
271 return static_cast<const Internal::Adaptor::Capture&>(handle);
274 } // End of namespace Dali
276 #endif // DALI_INTERNAL_CAPTURE_H