(Capture) Don't scene-off camera when we use inputed camera 49/280749/7
authorEunki, Hong <eunkiki.hong@samsung.com>
Fri, 2 Sep 2022 14:06:17 +0000 (23:06 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Fri, 16 Sep 2022 13:03:37 +0000 (22:03 +0900)
If we create capture with our own camera, App can add/remove this
camera actor.

But current capture API automatically dettach the camera.

If we use DALi's default camera, than this default camera dettached
from the window, and the rendering broken.

This patch protect some kind of this scenario.
We will dettach the camera from window only if we use
capture-impl generated camera, and don't dettach if we use
inputed camera.

Change-Id: I902fbe3a4d933165de87cff7d420438e66c2fdd2
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali/internal/system/common/capture-impl.cpp
dali/internal/system/common/capture-impl.h

index 21169fe..fc947fd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -50,7 +50,9 @@ Capture::Capture()
   mTimer(),
   mPath(),
   mNativeImageSourcePtr(NULL),
-  mFileSave(false)
+  mFileSave(false),
+  mUseDefaultCamera(true),
+  mSceneOffCameraAfterCaptureFinished(false)
 {
 }
 
@@ -60,7 +62,9 @@ Capture::Capture(Dali::CameraActor cameraActor)
   mTimer(),
   mPath(),
   mNativeImageSourcePtr(NULL),
-  mFileSave(false)
+  mFileSave(false),
+  mUseDefaultCamera(!cameraActor),
+  mSceneOffCameraAfterCaptureFinished(false)
 {
 }
 
@@ -202,7 +206,8 @@ void Capture::SetupRenderTask(const Dali::Vector2& position, const Dali::Vector2
 
   if(!mCameraActor)
   {
-    mCameraActor = Dali::CameraActor::New(size);
+    mUseDefaultCamera = true;
+    mCameraActor      = Dali::CameraActor::New(size);
     // Because input position and size are for 2 dimentional area,
     // default z-directional position of the camera is required to be used for the new camera position.
     float   cameraDefaultZPosition = mCameraActor.GetProperty<float>(Dali::Actor::Property::POSITION_Z);
@@ -212,7 +217,16 @@ void Capture::SetupRenderTask(const Dali::Vector2& position, const Dali::Vector2
     mCameraActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
   }
 
-  window.Add(mCameraActor);
+  // Camera must be scene on. Add camera to window.
+  if(!mCameraActor.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE))
+  {
+    if(!mUseDefaultCamera)
+    {
+      DALI_LOG_ERROR("Camera must be on scene. Camera is connected to window now.\n");
+    }
+    window.Add(mCameraActor);
+    mSceneOffCameraAfterCaptureFinished = true;
+  }
 
   if(!mFrameBuffer)
   {
@@ -242,8 +256,13 @@ void Capture::UnsetRenderTask()
 {
   mTimer.Reset();
 
-  if(mCameraActor)
+  if(mSceneOffCameraAfterCaptureFinished && mCameraActor)
   {
+    if(!mUseDefaultCamera)
+    {
+      DALI_LOG_ERROR("Camera is disconnected from window now.\n");
+    }
+    mSceneOffCameraAfterCaptureFinished = false;
     mCameraActor.Unparent();
     mCameraActor.Reset();
   }
index 6de3a90..5f6e594 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_CAPTURE_H
 
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include <string>
 
 // INTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/pixel-buffer.h>
 #include <dali/public-api/adaptor-framework/native-image-source.h>
 #include <dali/public-api/adaptor-framework/timer.h>
 #include <dali/public-api/capture/capture.h>
 #include <dali/public-api/dali-adaptor-common.h>
-#include <dali/devel-api/adaptor-framework/pixel-buffer.h>
 
 namespace Dali
 {
@@ -209,6 +209,8 @@ private:
   Dali::NativeImageSourcePtr               mNativeImageSourcePtr; ///< pointer to surface image
   Dali::Devel::PixelBuffer                 mPixelBuffer;
   bool                                     mFileSave;
+  bool                                     mUseDefaultCamera;                   // Whether we use default generated camera, or use inputed camera.
+  bool                                     mSceneOffCameraAfterCaptureFinished; // Whether we need to scene-off after capture finished.
 };
 
 } // End of namespace Adaptor