From a78a4cb1bbc20af6ddea94a875efbc0272572a66 Mon Sep 17 00:00:00 2001 From: taeyoon Date: Tue, 19 Jul 2016 21:48:52 +0900 Subject: [PATCH] [3.0] Add native source render surface for wayland Support offscreen rendering by tbm_surface Change-Id: Ic4756126405af266f06a6a055cdd351986aa02de --- adaptors/base/display-connection.cpp | 8 + adaptors/base/display-connection.h | 8 + adaptors/base/render-helper.cpp | 9 +- .../devel-api/adaptor-framework/render-surface.h | 9 + .../wayland/display-connection-impl-ecore-wl.cpp | 27 +- adaptors/ecore/wayland/display-connection-impl.h | 9 +- adaptors/ecore/wayland/render-surface-ecore-wl.cpp | 5 + adaptors/integration-api/file.list | 9 +- .../native-source-render-surface-factory.h | 47 ++++ .../trigger-event-factory-interface.h | 4 + adaptors/integration-api/trigger-event-factory.h | 6 +- .../wayland/ecore-wl-render-surface.h | 5 + .../wayland/native-source-render-surface.h | 160 ++++++++++++ .../integration-api/x11/ecore-x-render-surface.h | 5 + .../integration-api/x11/pixmap-render-surface.h | 2 + adaptors/mobile/file.list | 7 +- .../native-source-render-surface-factory.cpp | 32 +++ adaptors/tizen/display-connection-impl-tizen.cpp | 55 ++++ adaptors/tizen/file.list | 2 + .../tizen/native-source-render-surface-tizen.cpp | 277 +++++++++++++++++++++ adaptors/wayland/display-connection-impl-wl.cpp | 4 + adaptors/wayland/display-connection-impl.h | 6 + .../wayland/render-surface/render-surface-wl.cpp | 5 +- .../wayland/render-surface/render-surface-wl.h | 5 + adaptors/x11/display-connection-impl-x.cpp | 11 +- adaptors/x11/display-connection-impl.h | 2 + adaptors/x11/ecore-x-render-surface.cpp | 5 + build/tizen/adaptor/Makefile.am | 6 +- 28 files changed, 711 insertions(+), 19 deletions(-) create mode 100644 adaptors/integration-api/native-source-render-surface-factory.h create mode 100644 adaptors/integration-api/wayland/native-source-render-surface.h create mode 100644 adaptors/mobile/native-source-render-surface-factory.cpp create mode 100644 adaptors/tizen/display-connection-impl-tizen.cpp create mode 100644 adaptors/tizen/native-source-render-surface-tizen.cpp diff --git a/adaptors/base/display-connection.cpp b/adaptors/base/display-connection.cpp index 1dc44e9..d34a14f 100644 --- a/adaptors/base/display-connection.cpp +++ b/adaptors/base/display-connection.cpp @@ -34,6 +34,14 @@ DisplayConnection* DisplayConnection::New() return new DisplayConnection(internal); } +DisplayConnection* DisplayConnection::New( RenderSurface::Type type ) +{ + Internal::Adaptor::DisplayConnection* internal(Internal::Adaptor::DisplayConnection::New()); + internal->SetSurfaceType( type ); + + return new DisplayConnection(internal); +} + DisplayConnection::DisplayConnection() : mImpl( NULL ) { diff --git a/adaptors/base/display-connection.h b/adaptors/base/display-connection.h index e38cc78..dc50bbb 100644 --- a/adaptors/base/display-connection.h +++ b/adaptors/base/display-connection.h @@ -22,6 +22,7 @@ #include // INTERNAL INCLUDES +#include namespace Dali @@ -49,6 +50,13 @@ public: static DisplayConnection* New(); /** + * @brief Create an initialized DisplayConnection. + * + * @return A handle to a newly allocated DisplayConnection resource. + */ + static DisplayConnection* New( RenderSurface::Type type ); + + /** * @brief Create a DisplayConnection handle; this can be initialised with DisplayConnection::New(). * * Calling member functions with an uninitialised handle is not allowed. diff --git a/adaptors/base/render-helper.cpp b/adaptors/base/render-helper.cpp index d3a771a..b4ee999 100644 --- a/adaptors/base/render-helper.cpp +++ b/adaptors/base/render-helper.cpp @@ -43,7 +43,14 @@ RenderHelper::RenderHelper( AdaptorInternalServices& adaptorInterfaces ) // set the initial values before render thread starts mSurface = adaptorInterfaces.GetRenderSurfaceInterface(); - mDisplayConnection = Dali::DisplayConnection::New(); + if( mSurface ) + { + mDisplayConnection = Dali::DisplayConnection::New( mSurface->GetSurfaceType() ); + } + else + { + mDisplayConnection = Dali::DisplayConnection::New(); + } } RenderHelper::~RenderHelper() diff --git a/adaptors/devel-api/adaptor-framework/render-surface.h b/adaptors/devel-api/adaptor-framework/render-surface.h index 2844105..dd152f4 100644 --- a/adaptors/devel-api/adaptor-framework/render-surface.h +++ b/adaptors/devel-api/adaptor-framework/render-surface.h @@ -62,6 +62,13 @@ class RenderSurface { public: + enum Type + { + ECORE_RENDER_SURFACE, + WAYLAND_RENDER_SURFACE, + NATIVE_SOURCE_RENDER_SURFACE + }; + /** * @brief Constructor * Inlined as this is a pure abstract interface @@ -157,6 +164,8 @@ public: */ virtual void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ) = 0; + virtual RenderSurface::Type GetSurfaceType() = 0; + private: /** diff --git a/adaptors/ecore/wayland/display-connection-impl-ecore-wl.cpp b/adaptors/ecore/wayland/display-connection-impl-ecore-wl.cpp index e708842..4f60977 100644 --- a/adaptors/ecore/wayland/display-connection-impl-ecore-wl.cpp +++ b/adaptors/ecore/wayland/display-connection-impl-ecore-wl.cpp @@ -23,7 +23,7 @@ #include // INTERNAL HEADERS -#include +#include namespace Dali { @@ -42,19 +42,20 @@ DisplayConnection* DisplayConnection::New() } DisplayConnection::DisplayConnection() -: mDisplay(NULL) { - mDisplay = ecore_wl_display_get(); } DisplayConnection::~DisplayConnection() { - //FIXME + if( mSurfaceType == RenderSurface::NATIVE_SOURCE_RENDER_SURFACE ) + { + ReleaseNativeSourceDisplay(); + } } Any DisplayConnection::GetDisplay() { - return Any(mDisplay); + return Any( mDisplay ); } void DisplayConnection::ConsumeEvents() @@ -65,7 +66,7 @@ bool DisplayConnection::InitializeEgl(EglInterface& egl) { EglImplementation& eglImpl = static_cast(egl); - if (!eglImpl.InitializeGles(reinterpret_cast(mDisplay))) + if( !eglImpl.InitializeGles( mDisplay ) ) { DALI_LOG_ERROR("Failed to initialize GLES."); return false; @@ -74,6 +75,20 @@ bool DisplayConnection::InitializeEgl(EglInterface& egl) return true; } +void DisplayConnection::SetSurfaceType( RenderSurface::Type type ) +{ + mSurfaceType = type; + + if( mSurfaceType == RenderSurface::NATIVE_SOURCE_RENDER_SURFACE ) + { + mDisplay = GetNativeSourceDisplay(); + } + else + { + mDisplay = reinterpret_cast< EGLNativeDisplayType >( ecore_wl_display_get() ); + } +} + void DisplayConnection::GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical) { // calculate DPI diff --git a/adaptors/ecore/wayland/display-connection-impl.h b/adaptors/ecore/wayland/display-connection-impl.h index b9134d1..bc301ae 100644 --- a/adaptors/ecore/wayland/display-connection-impl.h +++ b/adaptors/ecore/wayland/display-connection-impl.h @@ -81,6 +81,8 @@ public: */ bool InitializeEgl(EglInterface& egl); + void SetSurfaceType( RenderSurface::Type type ); + public: /** @@ -90,6 +92,10 @@ public: protected: + EGLNativeDisplayType GetNativeSourceDisplay(); + + void ReleaseNativeSourceDisplay(); + // Undefined DisplayConnection(const DisplayConnection&); @@ -97,7 +103,8 @@ protected: DisplayConnection& operator=(const DisplayConnection& rhs); private: - WlDisplay* mDisplay; ///< Wayland-display for rendering + EGLNativeDisplayType mDisplay; ///< Wayland-display for rendering + RenderSurface::Type mSurfaceType; }; } // namespace Adaptor diff --git a/adaptors/ecore/wayland/render-surface-ecore-wl.cpp b/adaptors/ecore/wayland/render-surface-ecore-wl.cpp index dbb495a..8ef5cc0 100644 --- a/adaptors/ecore/wayland/render-surface-ecore-wl.cpp +++ b/adaptors/ecore/wayland/render-surface-ecore-wl.cpp @@ -126,6 +126,11 @@ unsigned int EcoreWlRenderSurface::GetSurfaceId( Any surface ) const return surfaceId; } +RenderSurface::Type EcoreWlRenderSurface::GetSurfaceType() +{ + return RenderSurface::ECORE_RENDER_SURFACE; +} + } // namespace ECore } // namespace Dali diff --git a/adaptors/integration-api/file.list b/adaptors/integration-api/file.list index 45fcc77..bbf18ab 100644 --- a/adaptors/integration-api/file.list +++ b/adaptors/integration-api/file.list @@ -4,16 +4,17 @@ adaptor_integration_api_header_files = \ $(adaptor_integration_api_dir)/thread-synchronization-interface.h \ $(adaptor_integration_api_dir)/trigger-event-interface.h \ $(adaptor_integration_api_dir)/trigger-event-factory-interface.h \ - $(adaptor_integration_api_dir)/trigger-event-factory.h \ - $(adaptor_integration_api_dir)/pixmap-render-surface-factory.h + $(adaptor_integration_api_dir)/trigger-event-factory.h adaptor_integration_wayland_api_header_files = \ $(adaptor_integration_api_dir)/wayland/wl-types.h \ $(adaptor_integration_api_dir)/wayland/ecore-wl-render-surface.h \ - $(adaptor_integration_api_dir)/wayland/pixmap-render-surface.h + $(adaptor_integration_api_dir)/wayland/native-source-render-surface.h \ + $(adaptor_integration_api_dir)/native-source-render-surface-factory.h adaptor_integration_x11_api_header_files = \ $(adaptor_integration_api_dir)/x11/ecore-x-types.h \ $(adaptor_integration_api_dir)/x11/ecore-x-render-surface.h \ $(adaptor_integration_api_dir)/x11/pixmap-render-surface.h \ - $(adaptor_integration_api_dir)/x11/imf-manager-impl.h + $(adaptor_integration_api_dir)/x11/imf-manager-impl.h \ + $(adaptor_integration_api_dir)/pixmap-render-surface-factory.h diff --git a/adaptors/integration-api/native-source-render-surface-factory.h b/adaptors/integration-api/native-source-render-surface-factory.h new file mode 100644 index 0000000..91599ee --- /dev/null +++ b/adaptors/integration-api/native-source-render-surface-factory.h @@ -0,0 +1,47 @@ +#ifndef __DALI_INTEGRATION_NATIVE_SOURCE_RENDER_SURFACE_FACTORY_H__ +#define __DALI_INTEGRATION_NATIVE_SOURCE_RENDER_SURFACE_FACTORY_H__ + +/* + * Copyright (c) 2014 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. + * + */ + +// EXTERNAL INCLUDES +#include +#include +#include + +// INTERNAL INCLUDES + +namespace Dali +{ + +class NativeSourceRenderSurface; + +/** + * Surface factory function for native source + * A native source surface is created. + * + * @param [in] positionSize the position and size of the surface to create + * @param [in] name Name of surface passed in + * @param [in] isTransparent Whether the surface has an alpha channel + */ +NativeSourceRenderSurface* CreateNativeSourceSurface( PositionSize positionSize, + const std::string& name, + bool isTransparent ); + +} // namespace Dali + +#endif // __DALI_INTEGRATION_NATIVE_SOURCE_RENDER_SURFACE_FACTORY_H__ diff --git a/adaptors/integration-api/trigger-event-factory-interface.h b/adaptors/integration-api/trigger-event-factory-interface.h index 947f812..ebf5c0d 100644 --- a/adaptors/integration-api/trigger-event-factory-interface.h +++ b/adaptors/integration-api/trigger-event-factory-interface.h @@ -22,7 +22,11 @@ #include // INTERNAL INCLUDES +#ifdef DALI_ADAPTOR_COMPILATION #include +#else +#include +#endif namespace Dali { diff --git a/adaptors/integration-api/trigger-event-factory.h b/adaptors/integration-api/trigger-event-factory.h index 1633a0d..a90890a 100644 --- a/adaptors/integration-api/trigger-event-factory.h +++ b/adaptors/integration-api/trigger-event-factory.h @@ -19,8 +19,12 @@ */ // INTERNAL INCLUDES -#include #include +#ifdef DALI_ADAPTOR_COMPILATION +#include +#else +#include +#endif namespace Dali { diff --git a/adaptors/integration-api/wayland/ecore-wl-render-surface.h b/adaptors/integration-api/wayland/ecore-wl-render-surface.h index 99ceb45..88cd7c8 100644 --- a/adaptors/integration-api/wayland/ecore-wl-render-surface.h +++ b/adaptors/integration-api/wayland/ecore-wl-render-surface.h @@ -146,6 +146,11 @@ public: // from Dali::RenderSurface */ virtual void ReleaseLock() = 0; + /** + * @copydoc Dali::RenderSurface::GetSurfaceType() + */ + virtual RenderSurface::Type GetSurfaceType(); + private: /** diff --git a/adaptors/integration-api/wayland/native-source-render-surface.h b/adaptors/integration-api/wayland/native-source-render-surface.h new file mode 100644 index 0000000..881125e --- /dev/null +++ b/adaptors/integration-api/wayland/native-source-render-surface.h @@ -0,0 +1,160 @@ +#ifndef __DALI_TIZEN_BUFFER_RENDER_SURFACE_H__ +#define __DALI_TIZEN_BUFFER_RENDER_SURFACE_H__ + +/* + * Copyright (c) 2014 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. + * + */ + +// EXTERNAL INCLUDES +#include +#include + +// INTERNAL INCLUDES +#ifdef DALI_ADAPTOR_COMPILATION +#include +#include +#else +#include +#include +#endif + +namespace Dali +{ + +class TriggerEventInterface; + +/** + * Ecore X11 implementation of render surface. + */ +class DALI_IMPORT_API NativeSourceRenderSurface : public Dali::RenderSurface +{ +public: + + /** + * Uses an Wayland surface to render to. + * @param [in] positionSize the position and size of the surface + * @param [in] name optional name of surface passed in + * @param [in] isTransparent if it is true, surface has 32 bit color depth, otherwise, 24 bit + */ + NativeSourceRenderSurface( Dali::PositionSize positionSize, + const std::string& name, + bool isTransparent = false ); + + /** + * @copydoc Dali::RenderSurface::~RenderSurface + */ + virtual ~NativeSourceRenderSurface(); + +public: // API + + /** + * @brief Sets the render notification trigger to call when render thread is completed a frame + * + * @param renderNotification to use + */ + void SetRenderNotification( TriggerEventInterface* renderNotification ); + + /** + */ + virtual tbm_surface_h GetDrawable(); + + /** + * @brief GetSurface + * + * @return pixmap + */ + virtual Any GetSurface(); + + virtual void ReleaseNativeSource(); + +public: // from Dali::RenderSurface + + /** + * @copydoc Dali::RenderSurface::InitializeEgl() + */ + virtual void InitializeEgl( EglInterface& egl ); + + /** + * @copydoc Dali::RenderSurface::CreateEglSurface() + */ + virtual void CreateEglSurface( EglInterface& egl ); + + /** + * @copydoc Dali::RenderSurface::DestroyEglSurface() + */ + virtual void DestroyEglSurface( EglInterface& egl ); + + /** + * @copydoc Dali::RenderSurface::ReplaceEGLSurface() + */ + virtual bool ReplaceEGLSurface( EglInterface& egl ); + + /** + * @copydoc Dali::RenderSurface::StartRender() + */ + virtual void StartRender(); + + /** + * @copydoc Dali::RenderSurface::PreRender() + */ + virtual bool PreRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction ); + + /** + * @copydoc Dali::RenderSurface::PostRender() + */ + virtual void PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, DisplayConnection* displayConnection, bool replacingSurface ); + + /** + * @copydoc Dali::RenderSurface::StopRender() + */ + virtual void StopRender(); + + /** + * @copydoc Dali::RenderSurface::SetThreadSynchronization + */ + virtual void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ); + + virtual RenderSurface::Type GetSurfaceType(); + + virtual PositionSize GetPositionSize() const; + + virtual void MoveResize( Dali::PositionSize positionSize ); + + virtual void SetViewMode( ViewMode viewMode ); + +private: + + /** + * Release any locks. + */ + void ReleaseLock(); + + /** + * Create XPixmap + */ + virtual void CreateWlRenderable(); + +private: // Data + + struct Impl; + + Impl* mImpl; + +}; + +} // namespace Dali + +#endif // __DALI_TIZEN_BUFFER_RENDER_SURFACE_H__ diff --git a/adaptors/integration-api/x11/ecore-x-render-surface.h b/adaptors/integration-api/x11/ecore-x-render-surface.h index 1eaa823..3f9b97c 100644 --- a/adaptors/integration-api/x11/ecore-x-render-surface.h +++ b/adaptors/integration-api/x11/ecore-x-render-surface.h @@ -154,6 +154,11 @@ public: // from Dali::RenderSurface */ virtual void ReleaseLock() = 0; + /** + * @copydoc Dali::RenderSurface::GetSurfaceType() + */ + virtual RenderSurface::Type GetSurfaceType(); + private: /** diff --git a/adaptors/integration-api/x11/pixmap-render-surface.h b/adaptors/integration-api/x11/pixmap-render-surface.h index 471462f..f31a0c7 100644 --- a/adaptors/integration-api/x11/pixmap-render-surface.h +++ b/adaptors/integration-api/x11/pixmap-render-surface.h @@ -112,6 +112,8 @@ public: // from Dali::RenderSurface */ virtual void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ); + virtual RenderSurface::Type GetSurfaceType(); + private: /** diff --git a/adaptors/mobile/file.list b/adaptors/mobile/file.list index abe484d..55e99b0 100644 --- a/adaptors/mobile/file.list +++ b/adaptors/mobile/file.list @@ -1,6 +1,11 @@ # mobile profile internal files adaptor_common_internal_mobile_profile_src_files = \ $(adaptor_mobile_dir)/accessibility-adaptor-impl-mobile.cpp \ - $(adaptor_mobile_dir)/pixmap-render-surface-factory.cpp \ $(adaptor_mobile_dir)/mobile-system-settings.cpp \ $(adaptor_mobile_dir)/mobile-color-controller-impl.cpp + +adaptor_common_internal_wayland_mobile_profile_src_files = \ + $(adaptor_mobile_dir)/native-source-render-surface-factory.cpp + +adaptor_common_internal_x_mobile_profile_src_files = \ + $(adaptor_mobile_dir)/pixmap-render-surface-factory.cpp diff --git a/adaptors/mobile/native-source-render-surface-factory.cpp b/adaptors/mobile/native-source-render-surface-factory.cpp new file mode 100644 index 0000000..8ca4910 --- /dev/null +++ b/adaptors/mobile/native-source-render-surface-factory.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2016 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 + +namespace Dali +{ + +DALI_EXPORT_API NativeSourceRenderSurface* CreateNativeSourceSurface( + PositionSize positionSize, + const std::string& name, + bool isTransparent) +{ + return new NativeSourceRenderSurface( positionSize, name, isTransparent ); +} + +} // namespace Dali diff --git a/adaptors/tizen/display-connection-impl-tizen.cpp b/adaptors/tizen/display-connection-impl-tizen.cpp new file mode 100644 index 0000000..f69b398 --- /dev/null +++ b/adaptors/tizen/display-connection-impl-tizen.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2016 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. + * + */ + +// CLASS HEADER +#include + +// EXTERNAL_HEADERS +#include +#include + +// INTERNAL HEADERS +#include +#include + +namespace Dali +{ + +namespace Internal +{ + +namespace Adaptor +{ + +EGLNativeDisplayType DisplayConnection::GetNativeSourceDisplay() +{ + return (EGLNativeDisplayType)tbm_bufmgr_init( -1 ); +} + +void DisplayConnection::ReleaseNativeSourceDisplay() +{ + if( mDisplay ) + { + tbm_bufmgr_deinit( (tbm_bufmgr)mDisplay ); + } +} + +} // namespace Adaptor + +} // namespace Internal + +} // namespace Dali diff --git a/adaptors/tizen/file.list b/adaptors/tizen/file.list index 12cd87e..3038938 100644 --- a/adaptors/tizen/file.list +++ b/adaptors/tizen/file.list @@ -16,6 +16,8 @@ adaptor_tizen_internal_egl_extension_src_files = \ $(adaptor_tizen_dir)/gl/egl-image-extensions-tizen.cpp adaptor_tizen_internal_native_image_src_files = \ + $(adaptor_tizen_dir)/display-connection-impl-tizen.cpp \ + $(adaptor_tizen_dir)/native-source-render-surface-tizen.cpp \ $(adaptor_tizen_dir)/native-image-source-impl-tizen.cpp public_api_adaptor_tizen_header_files = \ diff --git a/adaptors/tizen/native-source-render-surface-tizen.cpp b/adaptors/tizen/native-source-render-surface-tizen.cpp new file mode 100644 index 0000000..4d8f54f --- /dev/null +++ b/adaptors/tizen/native-source-render-surface-tizen.cpp @@ -0,0 +1,277 @@ +/* + * Copyright (c) 2016 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. + * + */ + +// CLASS HEADER +#include + +// EXTERNAL INCLUDES +#include +#include +#include + +#include +#include +#include + +// INTERNAL INCLUDES +#include +#include +#include +#include + +namespace Dali +{ + +#if defined(DEBUG_ENABLED) +extern Debug::Filter* gRenderSurfaceLogFilter; +#endif + +struct NativeSourceRenderSurface::Impl +{ + Impl( Dali::PositionSize positionSize, const std::string& name, bool isTransparent ) + : mPosition( positionSize ), + mTitle( name ), + mRenderNotification( NULL ), + mColorDepth( isTransparent ? COLOR_DEPTH_32 : COLOR_DEPTH_24 ), + mTbmFormat( isTransparent ? TBM_FORMAT_ARGB8888 : TBM_FORMAT_RGB888 ), + mOwnSurface( false ), + mConsumeSurface( NULL ), + mThreadSynchronization( NULL ) + { + } + + PositionSize mPosition; + std::string mTitle; + TriggerEventInterface* mRenderNotification; + ColorDepth mColorDepth; + tbm_format mTbmFormat; + bool mOwnSurface; + + tbm_surface_queue_h mTbmQueue; + tbm_surface_h mConsumeSurface; + ThreadSynchronizationInterface* mThreadSynchronization; ///< A pointer to the thread-synchronization + ConditionalWait mTbmSurfaceCondition; +}; + +NativeSourceRenderSurface::NativeSourceRenderSurface(Dali::PositionSize positionSize, + const std::string& name, + bool isTransparent) +: mImpl( new Impl( positionSize, name, isTransparent ) ) +{ + ecore_wl_init(NULL); + CreateWlRenderable(); +} + +NativeSourceRenderSurface::~NativeSourceRenderSurface() +{ + // release the surface if we own one + if( mImpl->mOwnSurface ) + { + + if( mImpl->mConsumeSurface ) + { + tbm_surface_queue_release( mImpl->mTbmQueue, mImpl->mConsumeSurface ); + mImpl->mConsumeSurface = NULL; + } + + if( mImpl->mTbmQueue ) + { + tbm_surface_queue_destroy( mImpl->mTbmQueue ); + } + + delete mImpl; + + DALI_LOG_INFO( gRenderSurfaceLogFilter, Debug::General, "Own tbm surface queue destroy\n" ); + } +} + +void NativeSourceRenderSurface::SetRenderNotification( TriggerEventInterface* renderNotification ) +{ + mImpl->mRenderNotification = renderNotification; +} + +tbm_surface_h NativeSourceRenderSurface::GetDrawable() +{ + ConditionalWait::ScopedLock lock( mImpl->mTbmSurfaceCondition ); + + return mImpl->mConsumeSurface; +} + +Any NativeSourceRenderSurface::GetSurface() +{ + return Any( NULL ); +} + +void NativeSourceRenderSurface::InitializeEgl( EglInterface& egl ) +{ + DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter ); + + Internal::Adaptor::EglImplementation& eglImpl = static_cast( egl ); + + eglImpl.ChooseConfig( true, mImpl->mColorDepth ); +} + +void NativeSourceRenderSurface::CreateEglSurface( EglInterface& egl ) +{ + DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter ); + + Internal::Adaptor::EglImplementation& eglImpl = static_cast( egl ); + + eglImpl.CreateSurfaceWindow( (EGLNativeWindowType)mImpl->mTbmQueue, mImpl->mColorDepth ); +} + +void NativeSourceRenderSurface::DestroyEglSurface( EglInterface& egl ) +{ + DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter ); + + Internal::Adaptor::EglImplementation& eglImpl = static_cast( egl ); + eglImpl.DestroySurface(); +} + +bool NativeSourceRenderSurface::ReplaceEGLSurface( EglInterface& egl ) +{ + DALI_LOG_TRACE_METHOD( gRenderSurfaceLogFilter ); + + if( mImpl->mConsumeSurface ) + { + tbm_surface_queue_release( mImpl->mTbmQueue, mImpl->mConsumeSurface ); + mImpl->mConsumeSurface = NULL; + } + + if( mImpl->mTbmQueue ) + { + tbm_surface_queue_destroy( mImpl->mTbmQueue ); + } + + CreateWlRenderable(); + + if( !mImpl->mTbmQueue ) + { + return false; + } + + Internal::Adaptor::EglImplementation& eglImpl = static_cast( egl ); + + return eglImpl.ReplaceSurfaceWindow( (EGLNativeWindowType)mImpl->mTbmQueue ); // reinterpret_cast does not compile +} + +void NativeSourceRenderSurface::StartRender() +{ +} + +bool NativeSourceRenderSurface::PreRender( EglInterface&, Integration::GlAbstraction& ) +{ + // nothing to do for pixmaps + return true; +} + +void NativeSourceRenderSurface::PostRender( EglInterface& egl, Integration::GlAbstraction& glAbstraction, DisplayConnection* displayConnection, bool replacingSurface ) +{ + Internal::Adaptor::EglImplementation& eglImpl = static_cast( egl ); + eglImpl.SwapBuffers(); + + // flush gl instruction queue + glAbstraction.Flush(); + + { + if( tbm_surface_queue_can_acquire( mImpl->mTbmQueue, 1 ) ) + { + if( tbm_surface_queue_acquire( mImpl->mTbmQueue, &mImpl->mConsumeSurface ) != TBM_SURFACE_QUEUE_ERROR_NONE ) + { + DALI_LOG_ERROR( "Failed aquire consume tbm_surface\n" ); + return; + } + } + } + + // create damage for client applications which wish to know the update timing + if( mImpl->mRenderNotification ) + { + // use notification trigger + // Tell the event-thread to render the pixmap + mImpl->mRenderNotification->Trigger(); + } + else + { + // FIXME + } + +} + +void NativeSourceRenderSurface::StopRender() +{ + ReleaseLock(); +} + +PositionSize NativeSourceRenderSurface::GetPositionSize() const +{ + return mImpl->mPosition; +} + +void NativeSourceRenderSurface::MoveResize( Dali::PositionSize positionSize ) +{ +} + +void NativeSourceRenderSurface::SetViewMode( ViewMode viewMode ) +{ +} + +void NativeSourceRenderSurface::SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ) +{ + mImpl->mThreadSynchronization = &threadSynchronization; +} + +RenderSurface::Type NativeSourceRenderSurface::GetSurfaceType() +{ + return RenderSurface::NATIVE_SOURCE_RENDER_SURFACE; +} + +void NativeSourceRenderSurface::CreateWlRenderable() +{ + // check we're creating one with a valid size + DALI_ASSERT_ALWAYS( mImpl->mPosition.width > 0 && mImpl->mPosition.height > 0 && "Pixmap size is invalid" ); + + mImpl->mTbmQueue = tbm_surface_queue_create( 3, mImpl->mPosition.width, mImpl->mPosition.height, mImpl->mTbmFormat, TBM_BO_DEFAULT ); + + if( mImpl->mTbmQueue ) + { + mImpl->mOwnSurface = true; + } + else + { + mImpl->mOwnSurface = false; + } +} + +void NativeSourceRenderSurface::ReleaseNativeSource() +{ + if( mImpl->mConsumeSurface ) + { + tbm_surface_queue_release( mImpl->mTbmQueue, mImpl->mConsumeSurface ); + mImpl->mConsumeSurface = NULL; + } +} + +void NativeSourceRenderSurface::ReleaseLock() +{ + if( mImpl->mThreadSynchronization ) + { + mImpl->mThreadSynchronization->PostRenderComplete(); + } +} + +} // namespace Dali diff --git a/adaptors/wayland/display-connection-impl-wl.cpp b/adaptors/wayland/display-connection-impl-wl.cpp index 3b87519..c08e055 100644 --- a/adaptors/wayland/display-connection-impl-wl.cpp +++ b/adaptors/wayland/display-connection-impl-wl.cpp @@ -60,6 +60,10 @@ bool DisplayConnection::InitializeEgl(EglInterface& egl) return true; } +void DisplayConnection::SetSurfaceType( RenderSurface::Type type ) +{ +} + void DisplayConnection::GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical) { CompositorOutput::GetDpi( dpiHorizontal, dpiVertical); diff --git a/adaptors/wayland/display-connection-impl.h b/adaptors/wayland/display-connection-impl.h index f531628..9da53c5 100644 --- a/adaptors/wayland/display-connection-impl.h +++ b/adaptors/wayland/display-connection-impl.h @@ -80,6 +80,8 @@ public: */ bool InitializeEgl(EglInterface& egl); + void SetSurfaceType( RenderSurface::Type type ); + public: /** @@ -89,6 +91,10 @@ public: protected: + EGLNativeDisplayType GetNativeSourceDisplay(); + + void ReleaseNativeSourceDisplay(); + // Undefined DisplayConnection(const DisplayConnection&); diff --git a/adaptors/wayland/render-surface/render-surface-wl.cpp b/adaptors/wayland/render-surface/render-surface-wl.cpp index 00906cf..6df8678 100644 --- a/adaptors/wayland/render-surface/render-surface-wl.cpp +++ b/adaptors/wayland/render-surface/render-surface-wl.cpp @@ -149,7 +149,10 @@ void RenderSurface::SetThreadSynchronization( ThreadSynchronizationInterface& th { } - +RenderSurface::Type RenderSurface::GetSurfaceType() +{ + return RenderSurface::WAYLAND_RENDER_SURFACE; +} } // namespace Wayland diff --git a/adaptors/wayland/render-surface/render-surface-wl.h b/adaptors/wayland/render-surface/render-surface-wl.h index b54c304..bbbf4d2 100644 --- a/adaptors/wayland/render-surface/render-surface-wl.h +++ b/adaptors/wayland/render-surface/render-surface-wl.h @@ -161,6 +161,11 @@ public: // from Dali::RenderSurface */ virtual void SetThreadSynchronization( ThreadSynchronizationInterface& threadSynchronization ); + /** + * @copydoc Dali::RenderSurface::GetSurfaceType() + */ + virtual RenderSurface::Type GetSurfaceType(); + protected: // Data Window mWindow; diff --git a/adaptors/x11/display-connection-impl-x.cpp b/adaptors/x11/display-connection-impl-x.cpp index 02deebb..6ca9f9e 100644 --- a/adaptors/x11/display-connection-impl-x.cpp +++ b/adaptors/x11/display-connection-impl-x.cpp @@ -44,8 +44,6 @@ DisplayConnection* DisplayConnection::New() DisplayConnection::DisplayConnection() : mDisplay(NULL) { - // Because of DDK issue, we need to use separated x display instead of ecore default display - mDisplay = XOpenDisplay(0); } DisplayConnection::~DisplayConnection() @@ -95,6 +93,15 @@ bool DisplayConnection::InitializeEgl(EglInterface& egl) return true; } +void DisplayConnection::SetSurfaceType( RenderSurface::Type type ) +{ + if( type == RenderSurface::ECORE_RENDER_SURFACE ) + { + // Because of DDK issue, we need to use separated x display instead of ecore default display + mDisplay = XOpenDisplay(0); + } +} + void DisplayConnection::GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical) { // calculate DPI diff --git a/adaptors/x11/display-connection-impl.h b/adaptors/x11/display-connection-impl.h index c5b7a70..2c0eabd 100644 --- a/adaptors/x11/display-connection-impl.h +++ b/adaptors/x11/display-connection-impl.h @@ -80,6 +80,8 @@ public: */ bool InitializeEgl(EglInterface& egl); + void SetSurfaceType( RenderSurface::Type type ); + public: /** diff --git a/adaptors/x11/ecore-x-render-surface.cpp b/adaptors/x11/ecore-x-render-surface.cpp index 6c0401e..70b4694 100644 --- a/adaptors/x11/ecore-x-render-surface.cpp +++ b/adaptors/x11/ecore-x-render-surface.cpp @@ -139,6 +139,11 @@ unsigned int EcoreXRenderSurface::GetSurfaceId( Any surface ) const return surfaceId; } +RenderSurface::Type EcoreXRenderSurface::GetSurfaceType() +{ + return RenderSurface::ECORE_RENDER_SURFACE; +} + } // namespace ECore } // namespace Dali diff --git a/build/tizen/adaptor/Makefile.am b/build/tizen/adaptor/Makefile.am index d2fcfbc..9c90180 100644 --- a/build/tizen/adaptor/Makefile.am +++ b/build/tizen/adaptor/Makefile.am @@ -189,10 +189,12 @@ adaptor_internal_src_files += $(adaptor_wayland_tizen_internal_src_files) endif # USE_ECORE_WAYLAND adaptor_internal_src_files += $(adaptor_tizen_internal_egl_extension_src_files) \ - $(adaptor_tizen_internal_native_image_src_files) + $(adaptor_tizen_internal_native_image_src_files) \ + $(adaptor_common_internal_wayland_mobile_profile_src_files) else adaptor_internal_src_files += $(adaptor_x11_tizen_internal_src_files) \ - $(adaptor_common_internal_egl_extension_src_files) + $(adaptor_common_internal_egl_extension_src_files) \ + $(adaptor_common_internal_x_mobile_profile_src_files) endif # WAYLAND endif # MOBILE_PROFILE -- 2.7.4