X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fsystem%2Fcommon%2Fcapture-impl.cpp;h=dfd48e2027718d1c4dcc420e164b49ac527afc67;hb=93f89efc39d006b4e6c6480e85a7c11057c5ef64;hp=2724dd2d5a85ac44685795a778f87360c340c13c;hpb=22d7415fdc44f6d26e0ab1c39f9f8f376436f362;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/dali/internal/system/common/capture-impl.cpp b/dali/internal/system/common/capture-impl.cpp index 2724dd2..dfd48e2 100644 --- a/dali/internal/system/common/capture-impl.cpp +++ b/dali/internal/system/common/capture-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * 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. @@ -19,16 +19,16 @@ #include // EXTERNAL INCLUDES -#include -#include -#include +#include #include #include -#include +#include +#include // INTERNAL INCLUDES -#include #include +#include +#include namespace { @@ -37,29 +37,26 @@ unsigned int TIME_OUT_DURATION = 1000; namespace Dali { - namespace Internal { - namespace Adaptor { - Capture::Capture() -: mQuality( DEFAULT_QUALITY ), +: mQuality(DEFAULT_QUALITY), mTimer(), mPath(), - mNativeImageSourcePtr( NULL ), - mFileSave( false ) + mNativeImageSourcePtr(NULL), + mFileSave(false) { } -Capture::Capture( Dali::CameraActor cameraActor ) -: mQuality( DEFAULT_QUALITY ), - mCameraActor( cameraActor ), +Capture::Capture(Dali::CameraActor cameraActor) +: mQuality(DEFAULT_QUALITY), + mCameraActor(cameraActor), mTimer(), mPath(), - mNativeImageSourcePtr( NULL ), - mFileSave( false ) + mNativeImageSourcePtr(NULL), + mFileSave(false) { } @@ -75,28 +72,26 @@ CapturePtr Capture::New() return pWorker; } -CapturePtr Capture::New( Dali::CameraActor cameraActor ) +CapturePtr Capture::New(Dali::CameraActor cameraActor) { - CapturePtr pWorker = new Capture( cameraActor ); + CapturePtr pWorker = new Capture(cameraActor); return pWorker; } -void Capture::Start( Dali::Actor source, const Dali::Vector2& size, const std::string &path, const Dali::Vector4& clearColor, const uint32_t quality ) +void Capture::Start(Dali::Actor source, const Dali::Vector2& position, const Dali::Vector2& size, const std::string& path, const Dali::Vector4& clearColor, const uint32_t quality) { mQuality = quality; - Start( source, size, path, clearColor ); + Start(source, position, size, path, clearColor); } -void Capture::Start( Dali::Actor source, const Dali::Vector2& size, const std::string &path, const Dali::Vector4& clearColor ) +void Capture::Start(Dali::Actor source, const Dali::Vector2& position, const Dali::Vector2& size, const std::string& path, const Dali::Vector4& clearColor) { - DALI_ASSERT_ALWAYS(path.size() > 4 && "Path is invalid."); - // Increase the reference count focely to avoid application mistake. Reference(); mPath = path; - if( mPath.size() > 0 ) + if(!mPath.empty()) { mFileSave = true; } @@ -104,13 +99,16 @@ void Capture::Start( Dali::Actor source, const Dali::Vector2& size, const std::s DALI_ASSERT_ALWAYS(source && "Source is NULL."); UnsetResources(); - SetupResources( size, clearColor, source ); + SetupResources(position, size, clearColor, source); } -Dali::NativeImageSourcePtr Capture::GetNativeImageSource() const +void Capture::SetImageQuality(uint32_t quality) { - DALI_ASSERT_ALWAYS( mNativeImageSourcePtr && "mNativeImageSourcePtr is NULL."); + mQuality = quality; +} +Dali::NativeImageSourcePtr Capture::GetNativeImageSource() const +{ return mNativeImageSourcePtr; } @@ -119,7 +117,7 @@ Dali::Capture::CaptureFinishedSignalType& Capture::FinishedSignal() return mFinishedSignal; } -void Capture::CreateNativeImageSource( const Vector2& size ) +void Capture::CreateNativeImageSource(const Vector2& size) { Dali::Adaptor& adaptor = Dali::Adaptor::Get(); @@ -128,13 +126,11 @@ void Capture::CreateNativeImageSource( const Vector2& size ) 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 ); + mNativeImageSourcePtr = Dali::NativeImageSource::New(size.width, size.height, Dali::NativeImageSource::COLOR_DEPTH_DEFAULT); } void Capture::DeleteNativeImageSource() { - DALI_ASSERT_ALWAYS(mNativeImageSourcePtr && "mNativeImageSource is NULL."); - mNativeImageSourcePtr.Reset(); } @@ -149,12 +145,12 @@ void Capture::CreateFrameBuffer() DALI_ASSERT_ALWAYS(!mFrameBuffer && "FrameBuffer is already created."); - mNativeTexture = Dali::Texture::New( *mNativeImageSourcePtr ); + mNativeTexture = Dali::Texture::New(*mNativeImageSourcePtr); // Create a FrameBuffer object with depth attachments. - mFrameBuffer = Dali::FrameBuffer::New( mNativeTexture.GetWidth(), mNativeTexture.GetHeight(), Dali::FrameBuffer::Attachment::DEPTH ); + mFrameBuffer = Dali::FrameBuffer::New(mNativeTexture.GetWidth(), mNativeTexture.GetHeight(), Dali::FrameBuffer::Attachment::DEPTH); // Add a color attachment to the FrameBuffer object. - mFrameBuffer.AttachColorTexture( mNativeTexture ); + mFrameBuffer.AttachColorTexture(mNativeTexture); } void Capture::DeleteFrameBuffer() @@ -170,49 +166,52 @@ bool Capture::IsFrameBufferCreated() return mFrameBuffer; } -void Capture::SetupRenderTask( Dali::Actor source, const Dali::Vector4& clearColor ) +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."); - mSource = source; - - // Check the original parent about source. - mParent = mSource.GetParent(); - - Dali::Stage stage = Dali::Stage::GetCurrent(); - Dali::Size stageSize = stage.GetSize(); + Dali::Window window = DevelWindow::Get(source); + if(!window) + { + DALI_LOG_ERROR("The source is not added on the window\n"); + return; + } - // Add to stage for rendering the source. If source isn't on the stage then it never be rendered. - stage.Add( mSource ); + mSource = source; - if( !mCameraActor ) + if(!mCameraActor) { - mCameraActor = Dali::CameraActor::New( stageSize ); - mCameraActor.SetParentOrigin( ParentOrigin::CENTER ); - mCameraActor.SetAnchorPoint( AnchorPoint::CENTER ); + 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(Dali::Actor::Property::POSITION_Z); + Vector2 positionTransition = position + size / 2; + mCameraActor.SetProperty(Dali::Actor::Property::POSITION, Vector3(positionTransition.x, positionTransition.y, cameraDefaultZPosition)); + mCameraActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + mCameraActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); } - stage.Add( mCameraActor ); + window.Add(mCameraActor); DALI_ASSERT_ALWAYS(mFrameBuffer && "Framebuffer is NULL."); DALI_ASSERT_ALWAYS(!mRenderTask && "RenderTask is already created."); - Dali::RenderTaskList taskList = stage.GetRenderTaskList(); - mRenderTask = taskList.CreateTask(); - mRenderTask.SetRefreshRate( Dali::RenderTask::REFRESH_ONCE ); - mRenderTask.SetSourceActor( source ); - mRenderTask.SetCameraActor( mCameraActor ); - mRenderTask.SetScreenToFrameBufferFunction( Dali::RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION ); - mRenderTask.SetFrameBuffer( mFrameBuffer ); - mRenderTask.SetClearColor( clearColor ); - mRenderTask.SetClearEnabled( true ); - mRenderTask.SetProperty( Dali::RenderTask::Property::REQUIRES_SYNC, true ); - mRenderTask.FinishedSignal().Connect( this, &Capture::OnRenderFinished ); - mRenderTask.GetCameraActor().SetInvertYAxis( true ); - - mTimer = Dali::Timer::New( TIME_OUT_DURATION ); - mTimer.TickSignal().Connect( this, &Capture::OnTimeOut ); + Dali::RenderTaskList taskList = window.GetRenderTaskList(); + mRenderTask = taskList.CreateTask(); + mRenderTask.SetRefreshRate(Dali::RenderTask::REFRESH_ONCE); + mRenderTask.SetSourceActor(source); + mRenderTask.SetCameraActor(mCameraActor); + mRenderTask.SetScreenToFrameBufferFunction(Dali::RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION); + mRenderTask.SetFrameBuffer(mFrameBuffer); + mRenderTask.SetClearColor(clearColor); + mRenderTask.SetClearEnabled(true); + mRenderTask.SetProperty(Dali::RenderTask::Property::REQUIRES_SYNC, true); + mRenderTask.FinishedSignal().Connect(this, &Capture::OnRenderFinished); + mRenderTask.GetCameraActor().SetInvertYAxis(true); + + mTimer = Dali::Timer::New(TIME_OUT_DURATION); + mTimer.TickSignal().Connect(this, &Capture::OnTimeOut); mTimer.Start(); } @@ -220,29 +219,18 @@ void Capture::UnsetRenderTask() { DALI_ASSERT_ALWAYS(mCameraActor && "CameraActor is NULL."); - if( mParent ) - { - // Restore the parent of source. - mParent.Add( mSource ); - mParent.Reset(); - } - else - { - mSource.Unparent(); - } - - mSource.Reset(); - mTimer.Reset(); mCameraActor.Unparent(); mCameraActor.Reset(); - DALI_ASSERT_ALWAYS( mRenderTask && "RenderTask is NULL." ); + DALI_ASSERT_ALWAYS(mRenderTask && "RenderTask is NULL."); - Dali::RenderTaskList taskList = Dali::Stage::GetCurrent().GetRenderTaskList(); - taskList.RemoveTask( mRenderTask ); + Dali::Window window = DevelWindow::Get(mSource); + Dali::RenderTaskList taskList = window.GetRenderTaskList(); + taskList.RemoveTask(mRenderTask); mRenderTask.Reset(); + mSource.Reset(); } bool Capture::IsRenderTaskSetup() @@ -250,45 +238,45 @@ bool Capture::IsRenderTaskSetup() return mCameraActor && mRenderTask; } -void Capture::SetupResources( const Dali::Vector2& size, const Dali::Vector4& clearColor, Dali::Actor source ) +void Capture::SetupResources(const Dali::Vector2& position, const Dali::Vector2& size, const Dali::Vector4& clearColor, Dali::Actor source) { - CreateNativeImageSource( size ); + CreateNativeImageSource(size); CreateFrameBuffer(); - SetupRenderTask( source, clearColor ); + SetupRenderTask(position, size, source, clearColor); } void Capture::UnsetResources() { - if( IsRenderTaskSetup() ) + if(IsRenderTaskSetup()) { UnsetRenderTask(); } - if( IsFrameBufferCreated() ) + if(IsFrameBufferCreated()) { DeleteFrameBuffer(); } } -void Capture::OnRenderFinished( Dali::RenderTask& task ) +void Capture::OnRenderFinished(Dali::RenderTask& task) { Dali::Capture::FinishState state = Dali::Capture::FinishState::SUCCEEDED; mTimer.Stop(); - if( mFileSave ) + if(mFileSave) { - if( !SaveFile() ) + if(!SaveFile()) { state = Dali::Capture::FinishState::FAILED; - DALI_LOG_ERROR( "Fail to Capture Path[%s]", mPath.c_str() ); + DALI_LOG_ERROR("Fail to Capture Path[%s]", mPath.c_str()); } } - Dali::Capture handle( this ); - mFinishedSignal.Emit( handle, state ); + Dali::Capture handle(this); + mFinishedSignal.Emit(handle, state); UnsetResources(); @@ -300,8 +288,8 @@ bool Capture::OnTimeOut() { Dali::Capture::FinishState state = Dali::Capture::FinishState::FAILED; - Dali::Capture handle( this ); - mFinishedSignal.Emit( handle, state ); + Dali::Capture handle(this); + mFinishedSignal.Emit(handle, state); UnsetResources(); @@ -315,11 +303,11 @@ bool Capture::SaveFile() { DALI_ASSERT_ALWAYS(mNativeImageSourcePtr && "mNativeImageSourcePtr is NULL"); - return Dali::DevelNativeImageSource::EncodeToFile( *mNativeImageSourcePtr, mPath, mQuality ); + return Dali::DevelNativeImageSource::EncodeToFile(*mNativeImageSourcePtr, mPath, mQuality); } -} // End of namespace Adaptor +} // End of namespace Adaptor -} // End of namespace Internal +} // End of namespace Internal -} // End of namespace Dali +} // End of namespace Dali