Merge "Fixed SVACE errors in Test Graphics & EglGraphicsController" into devel/master
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 27 May 2021 11:47:46 +0000 (11:47 +0000)
committerGerrit Code Review <gerrit@review>
Thu, 27 May 2021 11:47:46 +0000 (11:47 +0000)
dali/devel-api/adaptor-framework/capture-devel.cpp [new file with mode: 0644]
dali/devel-api/adaptor-framework/capture-devel.h [new file with mode: 0644]
dali/devel-api/file.list
dali/internal/system/common/capture-impl.cpp
dali/internal/system/common/capture-impl.h

diff --git a/dali/devel-api/adaptor-framework/capture-devel.cpp b/dali/devel-api/adaptor-framework/capture-devel.cpp
new file mode 100644 (file)
index 0000000..2d675f3
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2021 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/capture-devel.h>
+#include <dali/internal/system/common/capture-impl.h>
+
+
+namespace Dali
+{
+namespace DevelCapture
+{
+
+Dali::Devel::PixelBuffer GetCapturedBuffer(Dali::Capture capture)
+{
+  return GetImpl(capture).GetCapturedBuffer();
+}
+
+} // namespace DevelWindow
+
+} // namespace Dali
diff --git a/dali/devel-api/adaptor-framework/capture-devel.h b/dali/devel-api/adaptor-framework/capture-devel.h
new file mode 100644 (file)
index 0000000..d69f4fb
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef DALI_CAPTURE_DEVEL_H
+#define DALI_CAPTURE_DEVEL_H
+
+/*
+ * Copyright (c) 2021 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali/public-api/capture/capture.h>
+#include <dali/devel-api/adaptor-framework/pixel-buffer.h>
+
+namespace Dali
+{
+
+namespace DevelCapture
+{
+
+/**
+ * @brief Get PixelBuffer of captured image.
+ *
+ * @return PixelBuffer Captured result
+ */
+DALI_ADAPTOR_API Dali::Devel::PixelBuffer GetCapturedBuffer(Dali::Capture capture);
+
+} // namespace DevelCapture
+
+} // namespace Dali
+
+#endif // DALI_CAPTURE_DEVEL_H
index 9564cc7..8dbb425 100755 (executable)
@@ -9,6 +9,7 @@ SET( devel_api_src_files
   ${adaptor_devel_api_dir}/adaptor-framework/canvas-renderer.cpp
   ${adaptor_devel_api_dir}/adaptor-framework/canvas-renderer-drawable.cpp
   ${adaptor_devel_api_dir}/adaptor-framework/canvas-renderer-shape.cpp
+  ${adaptor_devel_api_dir}/adaptor-framework/capture-devel.cpp
   ${adaptor_devel_api_dir}/adaptor-framework/clipboard.cpp
   ${adaptor_devel_api_dir}/adaptor-framework/clipboard-event-notifier.cpp
   ${adaptor_devel_api_dir}/adaptor-framework/color-controller.cpp
@@ -56,6 +57,7 @@ SET( devel_api_adaptor_framework_header_files
   ${adaptor_devel_api_dir}/adaptor-framework/canvas-renderer.h
   ${adaptor_devel_api_dir}/adaptor-framework/canvas-renderer-drawable.h
   ${adaptor_devel_api_dir}/adaptor-framework/canvas-renderer-shape.h
+  ${adaptor_devel_api_dir}/adaptor-framework/capture-devel.h
   ${adaptor_devel_api_dir}/adaptor-framework/clipboard-event-notifier.h
   ${adaptor_devel_api_dir}/adaptor-framework/clipboard.h
   ${adaptor_devel_api_dir}/adaptor-framework/color-controller-plugin.h
index dfd48e2..1445ebb 100644 (file)
 #include <fstream>
 
 // INTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/bitmap-saver.h>
 #include <dali/devel-api/adaptor-framework/native-image-source-devel.h>
 #include <dali/devel-api/adaptor-framework/window-devel.h>
 #include <dali/integration-api/adaptor-framework/adaptor.h>
-
-namespace
-{
-unsigned int TIME_OUT_DURATION = 1000;
-}
+#include <dali/internal/adaptor/common/adaptor-impl.h>
+#include <dali/internal/graphics/gles/egl-graphics.h>
 
 namespace Dali
 {
@@ -41,6 +39,12 @@ namespace Internal
 {
 namespace Adaptor
 {
+namespace
+{
+constexpr int32_t  GL_VERSION_NATIVE_IMAGE_SOURCE_AVAILABLE = 30;
+constexpr uint32_t TIME_OUT_DURATION                        = 1000;
+} // namespace
+
 Capture::Capture()
 : mQuality(DEFAULT_QUALITY),
   mTimer(),
@@ -63,6 +67,7 @@ Capture::Capture(Dali::CameraActor cameraActor)
 Capture::~Capture()
 {
   DeleteNativeImageSource();
+  mTexture.Reset();
 }
 
 CapturePtr Capture::New()
@@ -87,6 +92,11 @@ void Capture::Start(Dali::Actor source, const Dali::Vector2& position, const Dal
 
 void Capture::Start(Dali::Actor source, const Dali::Vector2& position, const Dali::Vector2& size, const std::string& path, const Dali::Vector4& clearColor)
 {
+  if(!source)
+  {
+    return;
+  }
+
   // Increase the reference count focely to avoid application mistake.
   Reference();
 
@@ -96,8 +106,6 @@ void Capture::Start(Dali::Actor source, const Dali::Vector2& position, const Dal
     mFileSave = true;
   }
 
-  DALI_ASSERT_ALWAYS(source && "Source is NULL.");
-
   UnsetResources();
   SetupResources(position, size, clearColor, source);
 }
@@ -112,53 +120,62 @@ Dali::NativeImageSourcePtr Capture::GetNativeImageSource() const
   return mNativeImageSourcePtr;
 }
 
-Dali::Capture::CaptureFinishedSignalType& Capture::FinishedSignal()
+Dali::Devel::PixelBuffer Capture::GetCapturedBuffer()
 {
-  return mFinishedSignal;
+  if(!mPixelBuffer || (mPixelBuffer && !mPixelBuffer.GetBuffer()))
+  {
+    std::vector<uint8_t> buffer;
+    uint32_t             width, height;
+    Dali::Pixel::Format  pixelFormat;
+    if(!mNativeImageSourcePtr->GetPixels(buffer, width, height, pixelFormat))
+    {
+      return Dali::Devel::PixelBuffer();
+    }
+    mPixelBuffer = Dali::Devel::PixelBuffer::New(width, height, pixelFormat);
+    memcpy(mPixelBuffer.GetBuffer(), &buffer[0], width * height * Dali::Pixel::GetBytesPerPixel(pixelFormat));
+  }
+  return mPixelBuffer;
 }
 
-void Capture::CreateNativeImageSource(const Vector2& size)
+Dali::Capture::CaptureFinishedSignalType& Capture::FinishedSignal()
 {
-  Dali::Adaptor& adaptor = Dali::Adaptor::Get();
-
-  DALI_ASSERT_ALWAYS(adaptor.IsAvailable() && "Dali::Adaptor is not available.");
-
-  DALI_ASSERT_ALWAYS(!mNativeImageSourcePtr && "NativeImageSource is already created.");
-
-  // create the NativeImageSource object with our surface
-  mNativeImageSourcePtr = Dali::NativeImageSource::New(size.width, size.height, Dali::NativeImageSource::COLOR_DEPTH_DEFAULT);
+  return mFinishedSignal;
 }
 
-void Capture::DeleteNativeImageSource()
+void Capture::CreateTexture(const Vector2& size)
 {
-  mNativeImageSourcePtr.Reset();
+  if(!mNativeImageSourcePtr)
+  {
+    mNativeImageSourcePtr = Dali::NativeImageSource::New(size.width, size.height, Dali::NativeImageSource::COLOR_DEPTH_DEFAULT);
+    mTexture              = Dali::Texture::New(*mNativeImageSourcePtr);
+  }
 }
 
-bool Capture::IsNativeImageSourceCreated()
+void Capture::DeleteNativeImageSource()
 {
-  return mNativeImageSourcePtr;
+  if(mNativeImageSourcePtr)
+  {
+    mNativeImageSourcePtr.Reset();
+  }
 }
 
 void Capture::CreateFrameBuffer()
 {
-  DALI_ASSERT_ALWAYS(mNativeImageSourcePtr && "NativeImageSource is NULL.");
-
-  DALI_ASSERT_ALWAYS(!mFrameBuffer && "FrameBuffer is already created.");
-
-  mNativeTexture = Dali::Texture::New(*mNativeImageSourcePtr);
-
-  // Create a FrameBuffer object with depth attachments.
-  mFrameBuffer = Dali::FrameBuffer::New(mNativeTexture.GetWidth(), mNativeTexture.GetHeight(), Dali::FrameBuffer::Attachment::DEPTH);
-  // Add a color attachment to the FrameBuffer object.
-  mFrameBuffer.AttachColorTexture(mNativeTexture);
+  if(!mFrameBuffer)
+  {
+    // Create a FrameBuffer object with depth attachments.
+    mFrameBuffer = Dali::FrameBuffer::New(mTexture.GetWidth(), mTexture.GetHeight(), Dali::FrameBuffer::Attachment::DEPTH);
+    // Add a color attachment to the FrameBuffer object.
+    mFrameBuffer.AttachColorTexture(mTexture);
+  }
 }
 
 void Capture::DeleteFrameBuffer()
 {
-  DALI_ASSERT_ALWAYS(mFrameBuffer && "FrameBuffer is NULL.");
-
-  mFrameBuffer.Reset();
-  mNativeTexture.Reset();
+  if(mFrameBuffer)
+  {
+    mFrameBuffer.Reset();
+  }
 }
 
 bool Capture::IsFrameBufferCreated()
@@ -168,12 +185,16 @@ bool Capture::IsFrameBufferCreated()
 
 void Capture::SetupRenderTask(const Dali::Vector2& position, const Dali::Vector2& size, Dali::Actor source, const Dali::Vector4& clearColor)
 {
-  DALI_ASSERT_ALWAYS(source && "Source is empty.");
+  if(!source)
+  {
+    DALI_LOG_ERROR("Source is empty\n");
+    return;
+  }
 
   Dali::Window window = DevelWindow::Get(source);
   if(!window)
   {
-    DALI_LOG_ERROR("The source is not added on the window\n");
+    DALI_LOG_ERROR("The source is not added on the scene\n");
     return;
   }
 
@@ -193,9 +214,11 @@ void Capture::SetupRenderTask(const Dali::Vector2& position, const Dali::Vector2
 
   window.Add(mCameraActor);
 
-  DALI_ASSERT_ALWAYS(mFrameBuffer && "Framebuffer is NULL.");
-
-  DALI_ASSERT_ALWAYS(!mRenderTask && "RenderTask is already created.");
+  if(!mFrameBuffer)
+  {
+    DALI_LOG_ERROR("Frame buffer is not created.\n");
+    return;
+  }
 
   Dali::RenderTaskList taskList = window.GetRenderTaskList();
   mRenderTask                   = taskList.CreateTask();
@@ -217,19 +240,21 @@ void Capture::SetupRenderTask(const Dali::Vector2& position, const Dali::Vector2
 
 void Capture::UnsetRenderTask()
 {
-  DALI_ASSERT_ALWAYS(mCameraActor && "CameraActor is NULL.");
-
   mTimer.Reset();
 
-  mCameraActor.Unparent();
-  mCameraActor.Reset();
-
-  DALI_ASSERT_ALWAYS(mRenderTask && "RenderTask is NULL.");
+  if(mCameraActor)
+  {
+    mCameraActor.Unparent();
+    mCameraActor.Reset();
+  }
 
-  Dali::Window         window   = DevelWindow::Get(mSource);
-  Dali::RenderTaskList taskList = window.GetRenderTaskList();
-  taskList.RemoveTask(mRenderTask);
-  mRenderTask.Reset();
+  if(mRenderTask)
+  {
+    Dali::Window         window   = DevelWindow::Get(mSource);
+    Dali::RenderTaskList taskList = window.GetRenderTaskList();
+    taskList.RemoveTask(mRenderTask);
+    mRenderTask.Reset();
+  }
   mSource.Reset();
 }
 
@@ -240,7 +265,7 @@ bool Capture::IsRenderTaskSetup()
 
 void Capture::SetupResources(const Dali::Vector2& position, const Dali::Vector2& size, const Dali::Vector4& clearColor, Dali::Actor source)
 {
-  CreateNativeImageSource(size);
+  CreateTexture(size);
 
   CreateFrameBuffer();
 
@@ -270,8 +295,8 @@ void Capture::OnRenderFinished(Dali::RenderTask& task)
   {
     if(!SaveFile())
     {
+      DALI_LOG_ERROR("Fail to Capture Path[%s]\n", mPath.c_str());
       state = Dali::Capture::FinishState::FAILED;
-      DALI_LOG_ERROR("Fail to Capture Path[%s]", mPath.c_str());
     }
   }
 
@@ -301,9 +326,11 @@ bool Capture::OnTimeOut()
 
 bool Capture::SaveFile()
 {
-  DALI_ASSERT_ALWAYS(mNativeImageSourcePtr && "mNativeImageSourcePtr is NULL");
-
-  return Dali::DevelNativeImageSource::EncodeToFile(*mNativeImageSourcePtr, mPath, mQuality);
+  if(mNativeImageSourcePtr)
+  {
+    return Dali::DevelNativeImageSource::EncodeToFile(*mNativeImageSourcePtr, mPath, mQuality);
+  }
+  return false;
 }
 
 } // End of namespace Adaptor
index c8595c4..6de3a90 100644 (file)
@@ -32,6 +32,7 @@
 #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
 {
@@ -85,6 +86,11 @@ public:
   Dali::NativeImageSourcePtr GetNativeImageSource() const;
 
   /**
+   * @copydoc Dali::Capture::GetCapturedBuffer
+   */
+  Dali::Devel::PixelBuffer GetCapturedBuffer();
+
+  /**
    * @copydoc Dali::Capture::FinishedSignal
    */
   Dali::Capture::CaptureFinishedSignalType& FinishedSignal();
@@ -97,9 +103,9 @@ protected:
 
 private:
   /**
-   * @brief Create native image source.
+   * @brief Create texture.
    */
-  void CreateNativeImageSource(const Dali::Vector2& size);
+  void CreateTexture(const Dali::Vector2& size);
 
   /**
    * @brief Delete native image source.
@@ -107,13 +113,6 @@ private:
   void DeleteNativeImageSource();
 
   /**
-   * @brief Query whether native image source is created or not.
-   *
-   * @return True is native image source is created.
-   */
-  bool IsNativeImageSourceCreated();
-
-  /**
    * @brief Create frame buffer.
    */
   void CreateFrameBuffer();
@@ -199,7 +198,7 @@ private:
 
 private:
   uint32_t                                 mQuality;
-  Dali::Texture                            mNativeTexture;
+  Dali::Texture                            mTexture;
   Dali::FrameBuffer                        mFrameBuffer;
   Dali::RenderTask                         mRenderTask;
   Dali::Actor                              mSource;
@@ -208,6 +207,7 @@ private:
   Dali::Capture::CaptureFinishedSignalType mFinishedSignal;
   std::string                              mPath;
   Dali::NativeImageSourcePtr               mNativeImageSourcePtr; ///< pointer to surface image
+  Dali::Devel::PixelBuffer                 mPixelBuffer;
   bool                                     mFileSave;
 };