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/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/devel-api/adaptor-framework/pixel-buffer.h>
32 #include <dali/public-api/adaptor-framework/native-image-source.h>
33 #include <dali/public-api/adaptor-framework/timer.h>
34 #include <dali/public-api/capture/capture.h>
35 #include <dali/public-api/dali-adaptor-common.h>
44 typedef IntrusivePtr<Capture> CapturePtr;
46 class Capture : public BaseObject, public ConnectionTracker
49 static constexpr uint32_t DEFAULT_QUALITY = 100;
56 Capture(Dali::CameraActor cameraActor);
59 * @copydoc Dali::Capture::New
61 static CapturePtr New();
64 * @copydoc Dali::Capture::New
66 static CapturePtr New(Dali::CameraActor cameraActor);
69 * @copydoc Dali::Capture::Start
71 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);
74 * @copydoc Dali::Capture::Start
76 void Start(Dali::Actor source, const Dali::Vector2& position, const Dali::Vector2& size, const std::string& path, const Dali::Vector4& clearColor);
79 * @copydoc Dali::Capture::SetImageQuality
81 void SetImageQuality(uint32_t quality);
84 * @copydoc Dali::Capture::GetNativeImageSource
86 Dali::NativeImageSourcePtr GetNativeImageSource() const;
89 * @copydoc Dali::Capture::GetCapturedBuffer
91 Dali::Devel::PixelBuffer GetCapturedBuffer();
94 * @copydoc Dali::Capture::FinishedSignal
96 Dali::Capture::CaptureFinishedSignalType& FinishedSignal();
100 * @brief A reference counted object may only be deleted by calling Unreference()
106 * @brief Create texture.
108 void CreateTexture(const Dali::Vector2& size);
111 * @brief Delete native image source.
113 void DeleteNativeImageSource();
116 * @brief Create frame buffer.
118 void CreateFrameBuffer();
121 * @brief Delete frame buffer.
123 void DeleteFrameBuffer();
126 * @brief Query whether frame buffer is created or not.
128 * @return True is frame buffer is created.
130 bool IsFrameBufferCreated();
133 * @brief Setup render task.
135 * @param[in] position top-left position of area to be captured
136 * this position is defined in the window.
137 * @param[in] size two dimensional size of area to be captured
138 * @param[in] source sub-scene tree to be captured.
139 * @param[in] clearColor background color
141 void SetupRenderTask(const Dali::Vector2& position, const Dali::Vector2& size, Dali::Actor source, const Dali::Vector4& clearColor);
144 * @brief Unset render task.
146 void UnsetRenderTask();
149 * @brief Query whether render task is setup or not.
151 * @return True is render task is setup.
153 bool IsRenderTaskSetup();
156 * @brief Setup resources for capture.
158 * @param[in] position top-left position of area to be captured
159 * this position is defined in the window.
160 * @param[in] size two dimensional size of area to be captured
161 * @param[in] clearColor color to clear background surface.
162 * @param[in] source sub-scene tree to be captured.
164 void SetupResources(const Dali::Vector2& position, const Dali::Vector2& size, const Dali::Vector4& clearColor, Dali::Actor source);
167 * @brief Unset resources for capture.
169 void UnsetResources();
172 * @brief Callback when render is finished.
174 * @param[in] task is used for capture.
176 void OnRenderFinished(Dali::RenderTask& task);
179 * @brief Callback when timer is finished.
181 * @return True is timer start again.
186 * @brief Save framebuffer.
188 * @return True is success to save, false is fail.
194 Capture(const Capture&);
197 Capture& operator=(const Capture& rhs);
201 Dali::Texture mTexture;
202 Dali::FrameBuffer mFrameBuffer;
203 Dali::RenderTask mRenderTask;
205 Dali::CameraActor mCameraActor;
206 Dali::Timer mTimer; ///< For timeout.
207 Dali::Capture::CaptureFinishedSignalType mFinishedSignal;
209 Dali::NativeImageSourcePtr mNativeImageSourcePtr; ///< pointer to surface image
210 Dali::Devel::PixelBuffer mPixelBuffer;
212 bool mUseDefaultCamera; // Whether we use default generated camera, or use inputed camera.
213 bool mSceneOffCameraAfterCaptureFinished; // Whether we need to scene-off after capture finished.
216 } // End of namespace Adaptor
217 } // End of namespace Internal
219 // Helpers for public-api forwarding methods
221 inline Internal::Adaptor::Capture& GetImpl(Dali::Capture& captureWorker)
223 DALI_ASSERT_ALWAYS(captureWorker && "Capture handle is empty");
225 BaseObject& handle = captureWorker.GetBaseObject();
227 return static_cast<Internal::Adaptor::Capture&>(handle);
230 inline const Internal::Adaptor::Capture& GetImpl(const Dali::Capture& captureWorker)
232 DALI_ASSERT_ALWAYS(captureWorker && "Capture handle is empty");
234 const BaseObject& handle = captureWorker.GetBaseObject();
236 return static_cast<const Internal::Adaptor::Capture&>(handle);
239 } // End of namespace Dali
241 #endif // DALI_INTERNAL_CAPTURE_H