diff options
author | Daehyeon Jung <darrenh.jung@samsung.com> | 2020-04-23 19:14:51 +0900 |
---|---|---|
committer | Daehyeon Jung <darrenh.jung@samsung.com> | 2020-04-24 19:45:06 +0900 |
commit | 4286fe0e59dd139ac466b860175464ad710799ab (patch) | |
tree | 2ba9060b8691edf6bae332375b167d4ecc97d3ea /screen_connector_remote_surface_evas | |
parent | ccfb97303abc31ab3bcf0e7f71bc664b4129922a (diff) | |
download | screen-connector-4286fe0e59dd139ac466b860175464ad710799ab.tar.gz screen-connector-4286fe0e59dd139ac466b860175464ad710799ab.tar.bz2 screen-connector-4286fe0e59dd139ac466b860175464ad710799ab.zip |
Release tbm surface on block state
Change-Id: I9ac996016fbc7dc69029c4e88fbdff40e807b7c0
Signed-off-by: Daehyeon Jung <darrenh.jung@samsung.com>
Diffstat (limited to 'screen_connector_remote_surface_evas')
6 files changed, 98 insertions, 1 deletions
diff --git a/screen_connector_remote_surface_evas/remote_surface_mixed.cc b/screen_connector_remote_surface_evas/remote_surface_mixed.cc index 37642c8..7e04373 100644 --- a/screen_connector_remote_surface_evas/remote_surface_mixed.cc +++ b/screen_connector_remote_surface_evas/remote_surface_mixed.cc @@ -95,6 +95,7 @@ void RemoteSurfaceMixed::OnBufferChanged(int type, } void RemoteSurfaceMixed::ForceToUpdateWatcher() { + LOGD("ForceToUpdate %s:%s", GetAppId().c_str(), GetInstId().c_str()); if (!is_file_) { if (img_tbm_.get() == nullptr) { LOGE("tbm surface is not ready"); @@ -110,6 +111,14 @@ void RemoteSurfaceMixed::ForceToUpdateWatcher() { } } +void RemoteSurfaceMixed::ReleaseBuffer() { + if (img_tbm_.get() != nullptr) { + LOGD("tbm surface release buffer %s:%s", GetAppId().c_str(), + GetInstId().c_str()); + img_tbm_->ReleaseWlBuffer(); + } +} + void RemoteSurfaceMixed::SetChangedEventFilter( RemoteSurface::ChangedEventFilter filter) { RemoteSurface::SetChangedEventFilter(filter); diff --git a/screen_connector_remote_surface_evas/remote_surface_mixed_internal.h b/screen_connector_remote_surface_evas/remote_surface_mixed_internal.h index d8edad3..de1f2f9 100644 --- a/screen_connector_remote_surface_evas/remote_surface_mixed_internal.h +++ b/screen_connector_remote_surface_evas/remote_surface_mixed_internal.h @@ -45,6 +45,7 @@ class RemoteSurfaceMixed : public RemoteSurface { void OnBufferChanged(int type, std::shared_ptr<WlBuffer> tbm, int fd, uint32_t size, uint32_t time) override; void ForceToUpdateWatcher(); + void ReleaseBuffer(); private: IWatcherEvent* listener_; diff --git a/screen_connector_remote_surface_evas/remote_surface_watcher.cc b/screen_connector_remote_surface_evas/remote_surface_watcher.cc index 5ed7355..194def5 100644 --- a/screen_connector_remote_surface_evas/remote_surface_watcher.cc +++ b/screen_connector_remote_surface_evas/remote_surface_watcher.cc @@ -103,6 +103,16 @@ void RemoteSurfaceWatcher::Impl::UpdateFocusedSurface() { } } +void RemoteSurfaceWatcher::Impl::ReleaseFocusedSurfaceBuffer() { + if (focused_only_) { + for (auto& i : surfaces_) { + if (i->GetInstId() == focused_inst_id_) { + i->ReleaseBuffer(); + } + } + } +} + void RemoteSurfaceWatcher::Impl::OnAppFocused(const std::string& app_id, const std::string& inst_id, const int pid, @@ -152,6 +162,8 @@ void RemoteSurfaceWatcher::SetChangedEventFilter( for (auto& i : impl_->surfaces_) { i->SetChangedEventFilter(filter); } + + } int RemoteSurfaceWatcher::SetRemoteRender() { @@ -164,6 +176,9 @@ int RemoteSurfaceWatcher::SetRemoteRender() { int RemoteSurfaceWatcher::SetBlock(bool enable) { impl_->block_update_ = enable; impl_->UpdateFocusedSurface(); + if (enable) + impl_->ReleaseFocusedSurfaceBuffer(); + return 0; } diff --git a/screen_connector_remote_surface_evas/remote_surface_watcher_implementation.h b/screen_connector_remote_surface_evas/remote_surface_watcher_implementation.h index f271f5a..e68fe87 100644 --- a/screen_connector_remote_surface_evas/remote_surface_watcher_implementation.h +++ b/screen_connector_remote_surface_evas/remote_surface_watcher_implementation.h @@ -49,6 +49,7 @@ class RemoteSurfaceWatcher::Impl : AulHandle::IEventListener { std::shared_ptr<EvasObject> viewer_win, bool focused_only, bool mock = false); void UpdateFocusedSurface(); + void ReleaseFocusedSurfaceBuffer(); private: friend class RemoteSurfaceWatcher; diff --git a/screen_connector_remote_surface_evas/watcher_image.cc b/screen_connector_remote_surface_evas/watcher_image.cc index 9193593..866d56b 100644 --- a/screen_connector_remote_surface_evas/watcher_image.cc +++ b/screen_connector_remote_surface_evas/watcher_image.cc @@ -16,6 +16,11 @@ #include "screen_connector_remote_surface_evas/watcher_image_internal.h" +#include <dlog.h> + +#undef LOG_TAG +#define LOG_TAG "SC_RS_WI" + #define SC_TOOLKIT_HANDLE_TAG "SC_TOOLKIT_HANDLE_TAG" namespace screen_connector { @@ -54,7 +59,71 @@ void WatcherImage::UpdateTbm(std::shared_ptr<WlBuffer> tbm) { void WatcherImage::ClearTbm() { /* set null to previous object for the tbm type */ evas_object_image_native_surface_set(GetRaw(), NULL); - prev_buf_.reset(); + if (prev_buf_.get() != nullptr) { + prev_buf_.reset(); + } else { + prev_surf_.reset(); + } +} + +void WatcherImage::ReleaseWlBuffer() { + if (prev_buf_.get() == nullptr) + return; + + LOGD("ReleaseWlBuffer() start"); + + Evas_Native_Surface* ns; + tbm_surface_h surface; + int ret; + tbm_surface_info_s info = {0, }; + tbm_surface_info_s info2; + void* source_data; + + ns = evas_object_image_native_surface_get(GetRaw()); + if (ns == nullptr) // image_ is file + return; + + surface = (tbm_surface_h)ns->data.tbm.buffer; + if (surface == nullptr) + return; + + ret = tbm_surface_map(surface, TBM_SURF_OPTION_READ, &info); + if (ret != TBM_SURFACE_ERROR_NONE) + return; + + source_data = info.planes[0].ptr; + if (source_data == nullptr) { + tbm_surface_unmap(surface); + return; + } + + prev_surf_.reset(new TbmSurface(tbm_surface_create(info.width, info.height, info.format), true)); + if (prev_surf_.get() == nullptr) { + tbm_surface_unmap(surface); + return; + } + + ret = tbm_surface_map(prev_surf_.get()->GetRaw(), TBM_SURF_OPTION_WRITE, &info2); + if (ret != TBM_SURFACE_ERROR_NONE) { + tbm_surface_unmap(surface); + return; + } + + memset(info2.planes[0].ptr, 0, info2.planes[0].size); + memcpy(info2.planes[0].ptr, source_data, info.planes[0].size); + + Evas_Native_Surface ns2; + memset(&ns2, 0, sizeof(Evas_Native_Surface)); + ns2.version = EVAS_NATIVE_SURFACE_VERSION; + ns2.type = EVAS_NATIVE_SURFACE_TBM; + ns2.data.tbm.buffer = prev_surf_.get()->GetRaw(); + evas_object_image_native_surface_set(GetRaw(), &ns2); + + tbm_surface_unmap(surface); + tbm_surface_unmap(prev_surf_.get()->GetRaw()); + prev_buf_.reset(); + + LOGD("ReleaseWlBuffer() end"); } void WatcherImage::UpdateFile(int fd, uint32_t size) { diff --git a/screen_connector_remote_surface_evas/watcher_image_internal.h b/screen_connector_remote_surface_evas/watcher_image_internal.h index 31fb4f3..a1d8bf0 100644 --- a/screen_connector_remote_surface_evas/watcher_image_internal.h +++ b/screen_connector_remote_surface_evas/watcher_image_internal.h @@ -33,10 +33,12 @@ class WatcherImage : public EvasObject { void UpdateTbm(std::shared_ptr<WlBuffer> tbm); void ClearTbm(); + void ReleaseWlBuffer(); void UpdateFile(int fd, uint32_t size); private: std::shared_ptr<WlBuffer> prev_buf_; + std::unique_ptr<TbmSurface> prev_surf_; }; } // namespace screen_connector |