Merge "Added C# control / property registration to devel API" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / resources / resource-client.cpp
index 784fbce..2a0e2cd 100644 (file)
 
 // INTERNAL INCLUDES
 #include <dali/internal/event/resources/resource-client.h>
-#include <dali/public-api/common/map-wrapper.h>
+#include <dali/devel-api/common/map-wrapper.h>
 
-#include <dali/integration-api/glyph-set.h>
 #include <dali/integration-api/resource-request.h>
 #include <dali/integration-api/debug.h>
 
 #include <dali/internal/event/common/event-thread-services.h>
 #include <dali/internal/event/common/stage-impl.h>
-#include <dali/internal/event/text/resource/glyph-load-observer.h>
 #include <dali/internal/event/images/image-impl.h>
 #include <dali/internal/update/resources/resource-manager.h>
 
@@ -41,32 +39,23 @@ typedef TicketContainer::iterator                    TicketContainerIter;
 typedef TicketContainer::size_type                   TicketContainerSize;
 typedef std::pair<ResourceId, ResourceTicket*>       TicketPair;
 
-typedef std::map<ResourceId, Bitmap*>                BitmapCache;
-typedef BitmapCache::iterator                        BitmapCacheIter;
-
 struct ResourceClient::Impl
 {
-  Impl(ResourcePolicy::DataRetention dataRetentionPolicy)
-  : mNextId(0),
-    mGlyphLoadObserver(NULL),
-    mDataRetentionPolicy( dataRetentionPolicy )
+  Impl()
+  : mNextId(0)
   {
   }
 
   ResourceId       mNextId;
   TicketContainer  mTickets;
-  BitmapCache      mBitmaps;
-  GlyphLoadObserver* mGlyphLoadObserver;
-  ResourcePolicy::DataRetention mDataRetentionPolicy;
 };
 
 ResourceClient::ResourceClient( ResourceManager& resourceManager,
-                                EventThreadServices& eventThreadServices,
-                                ResourcePolicy::DataRetention dataRetentionPolicy)
+                                EventThreadServices& eventThreadServices)
 : mResourceManager(resourceManager),
   mEventThreadServices(eventThreadServices)
 {
-  mImpl = new ResourceClient::Impl(dataRetentionPolicy);
+  mImpl = new ResourceClient::Impl();
   mResourceManager.SetClient(*this);
 }
 
@@ -83,11 +72,6 @@ ResourceClient::~ResourceClient()
   delete mImpl;
 }
 
-ResourcePolicy::DataRetention ResourceClient::GetResourceDataRetentionPolicy()
-{
-  return mImpl->mDataRetentionPolicy;
-}
-
 ResourceTicketPtr ResourceClient::RequestResource(
   const ResourceType& type,
   const std::string& path,
@@ -108,7 +92,7 @@ ResourceTicketPtr ResourceClient::RequestResource(
       const BitmapResourceType& bitmapResource = static_cast <const BitmapResourceType&> (type);
       // image tickets will cache the requested parameters, which are updated on successful loading
       ImageTicket* imageTicket = new ImageTicket(*this, newId, typePath);
-      imageTicket->mAttributes = bitmapResource.imageAttributes;
+      imageTicket->mAttributes.Reset( bitmapResource.size, bitmapResource.scalingMode, bitmapResource.samplingMode, bitmapResource.orientationCorrection );
       newTicket = imageTicket;
       break;
     }
@@ -118,14 +102,11 @@ ResourceTicketPtr ResourceClient::RequestResource(
       const NativeImageResourceType& nativeResource = static_cast <const NativeImageResourceType&> (type);
       // image tickets will cache the requested parameters, which are updated on successful loading
       ImageTicket* imageTicket = new ImageTicket(*this, newId, typePath);
-      imageTicket->mAttributes = nativeResource.imageAttributes;
+      imageTicket->mAttributes.SetSize( nativeResource.imageDimensions.GetWidth(), nativeResource.imageDimensions.GetHeight() );
       newTicket = imageTicket;
       break;
     }
     case ResourceTargetImage:
-    case ResourceShader:
-    case ResourceMesh:
-    case ResourceText:
     {
       newTicket = new ResourceTicket(*this, newId, typePath);
       break;
@@ -163,7 +144,7 @@ ResourceTicketPtr ResourceClient::DecodeResource(
         const BitmapResourceType& bitmapResource = static_cast <const BitmapResourceType&> ( type );
         // Image tickets will cache the requested parameters, which are updated on successful loading
         ImageTicket* imageTicket = new ImageTicket( *this, newId, typePath );
-        imageTicket->mAttributes = bitmapResource.imageAttributes;
+        imageTicket->mAttributes.Reset( bitmapResource.size, bitmapResource.scalingMode, bitmapResource.samplingMode, bitmapResource.orientationCorrection );
         newTicket = imageTicket;
         break;
       }
@@ -171,11 +152,8 @@ ResourceTicketPtr ResourceClient::DecodeResource(
       // FALLTHROUGH:
       case ResourceNativeImage:
       case ResourceTargetImage:
-      case ResourceShader:
-      case ResourceMesh:
-      case ResourceText:
       {
-        DALI_LOG_ERROR( "Unsupported resource type passed for decoding from a memory buffer." );
+        DALI_LOG_ERROR( "Unsupported resource type passed for decoding from a memory buffer.\n" );
       }
     }
 
@@ -190,24 +168,6 @@ ResourceTicketPtr ResourceClient::DecodeResource(
   return newTicket;
 }
 
-ResourceTicketPtr ResourceClient::LoadShader( ShaderResourceType& type,
-                                              const std::string& path )
-{
-  ResourceTicketPtr newTicket;
-
-  const ResourceId newId = ++(mImpl->mNextId);
-
-  ResourceTypePath typePath(type, path);
-  newTicket = new ResourceTicket(*this, newId, typePath);
-
-  mImpl->mTickets.insert(TicketPair(newId, newTicket.Get()));
-
-  DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: LoadShader(path:%s) newId:%u\n", path.c_str(), newId);
-
-  RequestLoadShaderMessage( mEventThreadServices, mResourceManager, newId, typePath );
-  return newTicket;
-}
-
 bool ResourceClient::ReloadResource( ResourceId id, bool resetFinishedStatus, LoadResourcePriority priority )
 {
   DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: ReloadResource(Id: %u)\n", id);
@@ -233,28 +193,6 @@ bool ResourceClient::ReloadResource( ResourceId id, bool resetFinishedStatus, Lo
   return resourceExists;
 }
 
-void ResourceClient::SaveResource( ResourceTicketPtr ticket, const std::string& url )
-{
-  DALI_ASSERT_DEBUG( ticket );
-
-  DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: SaveResource(Id: %u, path:%s)\n", ticket->GetId(), url.c_str());
-
-  const ResourceTypePath * const typePathPtr = &ticket->GetTypePath();
-  if( typePathPtr )
-  {
-    if( 0 != url.length() )
-    {
-      ResourceTypePath typePath( *(typePathPtr->type), url );
-      RequestSaveResourceMessage( mEventThreadServices, mResourceManager, ticket->GetId(), typePath );
-    }
-    else
-    {
-      ResourceTypePath typePath( *typePathPtr );
-      RequestSaveResourceMessage( mEventThreadServices, mResourceManager, ticket->GetId(), typePath );
-    }
-  }
-}
-
 ResourceTicketPtr ResourceClient::RequestResourceTicket( ResourceId id )
 {
   DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: RequestResourceTicket(Id: %u)\n", id);
@@ -271,28 +209,6 @@ ResourceTicketPtr ResourceClient::RequestResourceTicket( ResourceId id )
   return ticket;
 }
 
-ImageTicketPtr ResourceClient::AllocateBitmapImage( unsigned int width,
-                                                    unsigned int height,
-                                                    unsigned int bufferWidth,
-                                                    unsigned int bufferHeight,
-                                                    Pixel::Format pixelformat )
-{
-  /* buffer is available via public-api, therefore not discardable */
-  Bitmap* const bitmap = Bitmap::New( Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
-  Bitmap::PackedPixelsProfile* const packedBitmap = bitmap->GetPackedPixelsProfile();
-  DALI_ASSERT_DEBUG(packedBitmap);
-
-  packedBitmap->ReserveBuffer(pixelformat, width, height, bufferWidth, bufferHeight);
-  DALI_ASSERT_DEBUG(bitmap->GetBuffer() != 0);
-  DALI_ASSERT_DEBUG(bitmap->GetBufferSize() >= width * height);
-
-  ImageTicketPtr ticket = AddBitmapImage(bitmap);
-
-  DALI_ASSERT_DEBUG(bitmap->GetBuffer() != 0);
-  DALI_ASSERT_DEBUG(bitmap->GetBufferSize() >= width * height);
-  return ticket;
-}
-
 ImageTicketPtr ResourceClient::AddBitmapImage(Bitmap* bitmap)
 {
   DALI_ASSERT_DEBUG( bitmap != NULL );
@@ -301,8 +217,8 @@ ImageTicketPtr ResourceClient::AddBitmapImage(Bitmap* bitmap)
 
   const ResourceId newId = ++(mImpl->mNextId);
 
-  Dali::ImageAttributes imageAttributes = Dali::ImageAttributes::New(bitmap->GetImageWidth(), bitmap->GetImageHeight());
-  BitmapResourceType bitmapResourceType(imageAttributes); // construct first as no copy ctor (needed to bind ref to object)
+  ImageAttributes imageAttributes = ImageAttributes::New(bitmap->GetImageWidth(), bitmap->GetImageHeight());
+  BitmapResourceType bitmapResourceType( ImageDimensions::FromFloatVec2( imageAttributes.GetSize() ) ); // construct first as no copy ctor (needed to bind ref to object)
   ResourceTypePath typePath(bitmapResourceType, "");
   newTicket = new ImageTicket(*this, newId, typePath);
   newTicket->mAttributes = imageAttributes;
@@ -310,9 +226,6 @@ ImageTicketPtr ResourceClient::AddBitmapImage(Bitmap* bitmap)
 
   mImpl->mTickets.insert(TicketPair(newId, newTicket.Get()));
 
-  // Store bitmap for immediate access.
-  mImpl->mBitmaps[newId] = bitmap;
-
   DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: AddBitmapImage() New id = %u\n", newId);
   RequestAddBitmapImageMessage( mEventThreadServices, mResourceManager, newId, bitmap );
 
@@ -340,14 +253,14 @@ ResourceTicketPtr ResourceClient::AddNativeImage ( NativeImageInterface& resourc
   return newTicket;
 }
 
-ImageTicketPtr ResourceClient::AddFrameBufferImage ( unsigned int width, unsigned int height, Pixel::Format pixelFormat )
+ImageTicketPtr ResourceClient::AddFrameBufferImage ( unsigned int width, unsigned int height, Pixel::Format pixelFormat, RenderBuffer::Format bufferFormat )
 {
   ImageTicketPtr newTicket;
 
   const ResourceId newId = ++(mImpl->mNextId);
 
-  Dali::ImageAttributes imageAttributes = Dali::ImageAttributes::New(width, height);
-  RenderTargetResourceType renderTargetResourceType(imageAttributes) ; // construct first as no copy ctor (needed to bind ref to object)
+  ImageAttributes imageAttributes = ImageAttributes::New(width, height);
+  RenderTargetResourceType renderTargetResourceType( ImageDimensions( width, height ) ); // construct first as no copy ctor (needed to bind ref to object)
   ResourceTypePath typePath(renderTargetResourceType, "");
   newTicket = new ImageTicket(*this, newId, typePath);
   newTicket->mAttributes = imageAttributes;
@@ -356,7 +269,7 @@ ImageTicketPtr ResourceClient::AddFrameBufferImage ( unsigned int width, unsigne
   mImpl->mTickets.insert(TicketPair(newId, newTicket.Get()));
 
   DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: AddFrameBufferImage() New id = %u\n", newId);
-  RequestAddFrameBufferImageMessage( mEventThreadServices, mResourceManager, newId, width, height, pixelFormat );
+  RequestAddFrameBufferImageMessage( mEventThreadServices, mResourceManager, newId, width, height, pixelFormat, bufferFormat );
 
   return newTicket;
 }
@@ -367,8 +280,8 @@ ImageTicketPtr ResourceClient::AddFrameBufferImage ( NativeImageInterface& nativ
 
   const ResourceId newId = ++(mImpl->mNextId);
 
-  Dali::ImageAttributes imageAttributes = Dali::ImageAttributes::New(nativeImage.GetWidth(), nativeImage.GetHeight() );
-  RenderTargetResourceType renderTargetResourceType(imageAttributes); // construct first as no copy ctor (needed to bind ref to object)
+  ImageAttributes imageAttributes = ImageAttributes::New( nativeImage.GetWidth(), nativeImage.GetHeight() );
+  RenderTargetResourceType renderTargetResourceType( ImageDimensions( nativeImage.GetWidth(), nativeImage.GetHeight() ) ); // construct first as no copy ctor (needed to bind ref to object)
   ResourceTypePath typePath(renderTargetResourceType, "");
   newTicket = new ImageTicket(*this, newId, typePath);
   newTicket->mAttributes = imageAttributes;
@@ -390,8 +303,8 @@ ResourceTicketPtr ResourceClient::AllocateTexture( unsigned int width,
   ImageTicketPtr newTicket;
   const ResourceId newId = ++(mImpl->mNextId);
 
-  Dali::ImageAttributes imageAttributes = Dali::ImageAttributes::New( width, height);
-  BitmapResourceType bitmapResourceType(imageAttributes); // construct first as no copy ctor (needed to bind ref to object)
+  ImageAttributes imageAttributes = ImageAttributes::New( width, height);
+  BitmapResourceType bitmapResourceType( ImageDimensions( width, height ) ); // construct first as no copy ctor (needed to bind ref to object)
   ResourceTypePath typePath(bitmapResourceType, "");
   newTicket = new ImageTicket(*this, newId, typePath);
 
@@ -406,27 +319,6 @@ ResourceTicketPtr ResourceClient::AllocateTexture( unsigned int width,
   return newTicket;
 }
 
-void ResourceClient::UpdateTexture(  ResourceId id,
-                                     BitmapUploadArray uploadArray )
-{
-  RequestUpdateTextureMessage(  mEventThreadServices, mResourceManager, id, uploadArray );
-}
-
-ResourceTicketPtr ResourceClient::AllocateMesh( OwnerPointer<MeshData>& meshData )
-{
-  ResourceTicketPtr newTicket;
-  const ResourceId newId = ++(mImpl->mNextId);
-  MeshResourceType meshResourceType; // construct first as no copy ctor (needed to bind ref to object)
-  ResourceTypePath typePath(meshResourceType, "");
-  newTicket = new ResourceTicket(*this, newId, typePath);
-  mImpl->mTickets.insert(TicketPair(newId, newTicket.Get()));
-
-  DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: AllocateMesh() New id = %u\n", newId);
-  RequestAllocateMeshMessage( mEventThreadServices, mResourceManager, newId, meshData );
-
-  return newTicket;
-}
-
 void ResourceClient::UpdateBitmapArea( ResourceTicketPtr ticket, RectArea& updateArea )
 {
   DALI_ASSERT_DEBUG( ticket );
@@ -455,46 +347,21 @@ void ResourceClient::UploadBitmap( ResourceId destId,Integration::BitmapPtr bitm
                               yOffset );
 }
 
-void ResourceClient::UpdateMesh( ResourceTicketPtr ticket, const Dali::MeshData& meshData )
+void ResourceClient::UploadBitmap( ResourceId destId, PixelDataPtr pixelData, std::size_t xOffset, std::size_t yOffset)
 {
-  DALI_ASSERT_DEBUG( ticket );
-
-  ResourcePolicy::Discardable discardable = ResourcePolicy::RETAIN;
-  if( mImpl->mDataRetentionPolicy == ResourcePolicy::DALI_DISCARDS_ALL_DATA )
-  {
-    discardable = ResourcePolicy::DISCARD;
-  }
-
-  RequestUpdateMeshMessage( mEventThreadServices,
-                            mResourceManager,
-                            ticket->GetId(),
-                            meshData,
-                            discardable );
-}
-
-Bitmap* ResourceClient::GetBitmap(ResourceTicketPtr ticket)
-{
-  DALI_ASSERT_DEBUG( ticket );
-
-  Bitmap* bitmap = NULL;
-  BitmapCacheIter iter = mImpl->mBitmaps.find(ticket->GetId());
-
-  if( iter != mImpl->mBitmaps.end() )
-  {
-    bitmap = iter->second;
-  }
-  return bitmap;
+  RequestUploadBitmapMessage( mEventThreadServices,
+                              mResourceManager,
+                              destId,
+                              pixelData,
+                              xOffset,
+                              yOffset );
 }
 
-void ResourceClient::SetGlyphLoadObserver( GlyphLoadObserver* glyphLoadedInterface )
+void ResourceClient::CreateGlTexture( ResourceId id )
 {
-  mImpl->mGlyphLoadObserver = glyphLoadedInterface;
+  RequestCreateGlTextureMessage( mEventThreadServices, mResourceManager, id );
 }
 
-void ResourceClient::UpdateAtlasStatus( ResourceId id, ResourceId atlasId, Integration::LoadStatus loadStatus )
-{
-  RequestAtlasUpdateMessage( mEventThreadServices, mResourceManager, id, atlasId, loadStatus );
-}
 
 /********************************************************************************
  ********************   ResourceTicketLifetimeObserver methods   ****************
@@ -505,9 +372,6 @@ void ResourceClient::ResourceTicketDiscarded(const ResourceTicket& ticket)
   const ResourceId deadId = ticket.GetId();
   const ResourceTypePath& typePath = ticket.GetTypePath();
 
-  // Ensure associated event owned resources are also removed
-  mImpl->mBitmaps.erase(ticket.GetId());
-
   // The ticket object is dead, remove from tickets container
   TicketContainerSize erased = mImpl->mTickets.erase(deadId);
   DALI_ASSERT_DEBUG(erased != 0);
@@ -533,19 +397,6 @@ void ResourceClient::NotifyUploaded( ResourceId id )
   }
 }
 
-void ResourceClient::NotifySaveRequested( ResourceId id )
-{
-  DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: NotifySaveRequested(id:%u)\n", id);
-
-  TicketContainerIter ticketIter = mImpl->mTickets.find(id);
-  if(ticketIter != mImpl->mTickets.end())
-  {
-    ResourceTicket* ticket = ticketIter->second;
-    SaveResource( ticket, "" );
-  }
-}
-
-
 void ResourceClient::NotifyLoading( ResourceId id )
 {
   DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: NotifyLoading(id:%u)\n", id);
@@ -582,45 +433,7 @@ void ResourceClient::NotifyLoadingFailed( ResourceId id )
   }
 }
 
-void ResourceClient::NotifySavingSucceeded( ResourceId id )
-{
-  DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: NotifySavingSucceeded(id:%u)\n", id);
-
-  TicketContainerIter ticketIter = mImpl->mTickets.find(id);
-  if(ticketIter != mImpl->mTickets.end())
-  {
-    ResourceTicket* ticket = ticketIter->second;
-    ticket->SavingSucceeded();
-  }
-}
-
-void ResourceClient::NotifySavingFailed( ResourceId id )
-{
-  DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: NotifySavingFailed(id:%u)\n", id);
-
-  TicketContainerIter ticketIter = mImpl->mTickets.find(id);
-  if(ticketIter != mImpl->mTickets.end())
-  {
-    ResourceTicket* ticket = ticketIter->second;
-    ticket->SavingFailed();
-  }
-}
-
-void ResourceClient::NotifyGlyphSetLoaded( ResourceId id, const GlyphSet& glyphSet, LoadStatus loadStatus )
-{
-  if( mImpl->mGlyphLoadObserver == NULL)
-  {
-    // should not happen.
-    DALI_ASSERT_DEBUG( !"GlyphLoadObserver == NULL ");
-    return;
-  }
-
-  DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: NotifyGlyphSetLoaded(hash:%u)\n", glyphSet.mFontHash);
-
-  mImpl->mGlyphLoadObserver->GlyphsLoaded( id, glyphSet, loadStatus );
-}
-
-void ResourceClient::UpdateImageTicket( ResourceId id, const Dali::ImageAttributes& imageAttributes ) ///!< Issue #AHC01
+void ResourceClient::UpdateImageTicket( ResourceId id, const ImageAttributes& imageAttributes ) ///!< Issue #AHC01
 {
   DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: UpdateImageTicket(id:%u)\n", id);