Set pre multiplied property
[platform/core/uifw/widget-viewer-dali.git] / internal / widget_view / widget_view_impl.cpp
index 068ee35..7927adc 100644 (file)
@@ -36,7 +36,6 @@
 #include <widget_instance.h>
 #include <tzplatform_config.h>
 #include <wayland-extension/tizen-extension-client-protocol.h>
-#include <aul_rsm_viewer.h>
 
 namespace Dali
 {
@@ -89,7 +88,8 @@ DALI_ACTION_REGISTRATION( Dali::WidgetView, WidgetView, "activateFaultedWidget",
 
 DALI_TYPE_REGISTRATION_END()
 
-static void OnSurfaceUpdate( struct tizen_remote_surface* surface, wl_buffer* buffer, uint32_t time, void* data )
+static void OnBufferChanged( struct tizen_remote_surface *surface, uint32_t type, struct wl_buffer *buffer,
+                              int32_t img_file_fd, uint32_t img_file_size, uint32_t time, struct wl_array *keys, void *data)
 {
   Dali::WidgetView::Internal::WidgetView* widgetView = static_cast< Dali::WidgetView::Internal::WidgetView* >( data );
 
@@ -109,16 +109,35 @@ static void OnSurfaceUpdate( struct tizen_remote_surface* surface, wl_buffer* bu
   }
 }
 
-static void OnSurfaceMissing( struct tizen_remote_surface* surface, void* data )
+static void OnBufferUpdated( struct tizen_remote_surface* surface, wl_buffer* buffer, uint32_t time, void* data )
 {
-  //ToDo: WidgetDeletedSignal
+  Dali::WidgetView::Internal::WidgetView* widgetView = static_cast< Dali::WidgetView::Internal::WidgetView* >( data );
+
+  if( widgetView )
+  {
+    if( !widgetView->IsWidgetImageView() )
+    {
+      tizen_remote_surface_transfer_visibility( surface, TIZEN_REMOTE_SURFACE_VISIBILITY_TYPE_VISIBLE);
+
+      widgetView->CreateWidgetImageView();
+      widgetView->ConnectSignal( surface );
+    }
+
+    //get tbm surface from buffer
+    tbm_surface_h tbmSurface = static_cast< tbm_surface_h >( wl_buffer_get_user_data( buffer ) );
+    widgetView->UpdateImageSource( tbmSurface );
+  }
 }
 
+static void OnSurfaceMissing( struct tizen_remote_surface* surface, void* data )
+{
+  Dali::WidgetView::Internal::WidgetView* widgetView = static_cast< Dali::WidgetView::Internal::WidgetView* >( data );
 
-static struct aul_rsm_handler_s remoteSurfaceHandler = {
-  OnSurfaceUpdate,
-  OnSurfaceMissing,
-};
+  if( widgetView )
+  {
+    widgetView->CloseRemoteSurface();
+  }
+}
 
 } // unnamed namespace
 
@@ -143,14 +162,14 @@ WidgetView::WidgetView()
   mInstanceId(),
   mContentInfo(),
   mTitle(),
-  mBundle( NULL ),
   mWidth( 0 ),
   mHeight( 0 ),
   mPid( 0 ),
   mUpdatePeriod( 0.0 ),
   mPreviewVisible( true ),
   mStateTextVisible( true ),
-  mPermanentDelete( true ),
+  mPermanentDelete( false ),
+  mWatcherHandle( NULL ),
   mRemoteSurface( NULL )
 {
 }
@@ -161,14 +180,14 @@ WidgetView::WidgetView( const std::string& widgetId, const std::string& contentI
   mInstanceId(),
   mContentInfo( contentInfo ),
   mTitle(),
-  mBundle( NULL ),
   mWidth( width ),
   mHeight( height ),
   mPid( 0 ),
   mUpdatePeriod( updatePeriod ),
   mPreviewVisible( true ),
   mStateTextVisible( true ),
-  mPermanentDelete( true ),
+  mPermanentDelete( false ),
+  mWatcherHandle( NULL ),
   mRemoteSurface( NULL )
 {
 }
@@ -184,11 +203,6 @@ WidgetView::~WidgetView()
       widget_instance_destroy( mInstanceId.c_str() );
     }
   }
-
-  if( mBundle )
-  {
-    bundle_free( mBundle );
-  }
 }
 
 bool WidgetView::PauseWidget()
@@ -378,6 +392,9 @@ void WidgetView::CreateWidgetImageView()
 
   Self().Add( mWidgetImageView );
 
+  //EFL app should be pre multiplied image.
+  mWidgetImageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
+
   // Disable preview and text
   if( mPreviewVisible )
   {
@@ -666,6 +683,7 @@ void WidgetView::OnInitialize()
   char* previewPath = NULL;
   std::string previewImage;
   widget_size_type_e sizeType;
+  screen_connector_watcher_ops ops;
 
   int ret = widget_instance_create( mWidgetId.c_str(), &instanceId );
   if( ret < 0 || !instanceId )
@@ -706,7 +724,9 @@ void WidgetView::OnInitialize()
     mPreviewImage.SetSize( mWidth, mHeight );
   }
 
-  Self().SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
+  Self().SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
+  Self().SetSize( mWidth, mHeight );
+
   Self().Add( mPreviewImage );
 
   // State text
@@ -733,8 +753,10 @@ void WidgetView::OnInitialize()
     return;
   }
 
-  aul_rsm_viewer_set_surface_handler( mInstanceId.c_str(), &remoteSurfaceHandler, this );
-
+  ops.change_cb = OnBufferChanged;
+  ops.missing_cb = OnSurfaceMissing;
+  ops.update_cb = OnBufferUpdated;
+  mWatcherHandle = screen_connector_watcher_add(&ops, (char *)mWidgetId.c_str(), this);
   DALI_LOG_INFO( gWidgetViewLogging, Debug::Verbose, "WidgetView::OnInitialize: widget_instance_launch is called. [%s, mPid = %d]\n", mWidgetId.c_str(), mPid );
 
 }
@@ -770,7 +792,7 @@ void WidgetView::UpdateImageSource( tbm_surface_h source )
 
 void WidgetView::ConnectSignal( tizen_remote_surface* surface )
 {
-  if( mWidgetImageView )
+  if( mWidgetImageView && surface )
   {
     mRemoteSurface = surface;
 
@@ -784,7 +806,7 @@ bool WidgetView::OnTouch( Dali::Actor actor, const Dali::TouchData& event )
 {
   tizen_remote_surface_event_type type = TIZEN_REMOTE_SURFACE_EVENT_TYPE_NONE;
 
-  if( event.GetPointCount() == 0 )
+  if( event.GetPointCount() == 0 || mRemoteSurface == NULL )
   {
     return false;
   }
@@ -841,6 +863,10 @@ bool WidgetView::OnTouch( Dali::Actor actor, const Dali::TouchData& event )
 
 bool WidgetView::OnWheelEvent( Dali::Actor actor, const Dali::WheelEvent& event )
 {
+  if( mRemoteSurface == NULL )
+  {
+    return false;
+  }
   //ToDo: We should check TIZEN_INPUT_DEVICE_CLAS_MOUSE
   tizen_remote_surface_transfer_mouse_wheel( mRemoteSurface,
                                              event.direction,
@@ -894,6 +920,12 @@ float WidgetView::GetWidthForHeight( float height )
   }
 }
 
+void WidgetView::CloseRemoteSurface()
+{
+  screen_connector_watcher_remove( mWatcherHandle );
+  mRemoteSurface = NULL;
+}
+
 } // namespace Internal
 
 } // namespace WidgetView