Changed Atlas manager to use Dali::Texture instead of Dali::Atlas 05/78905/4
authorFerran Sole <ferran.sole@samsung.com>
Thu, 7 Jul 2016 09:33:12 +0000 (10:33 +0100)
committerFerran Sole <ferran.sole@samsung.com>
Fri, 8 Jul 2016 13:00:22 +0000 (06:00 -0700)
Change-Id: I284d67c3ec3aa198bfe6565dc8dd838022ade19b

automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-text-abstraction.cpp
dali-toolkit/internal/text/multi-language-support-impl.cpp
dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.cpp
dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.h
dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.cpp
dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h
dali-toolkit/internal/text/rendering/atlas/atlas-manager-impl.cpp
dali-toolkit/internal/text/rendering/atlas/atlas-manager-impl.h
dali-toolkit/internal/text/rendering/atlas/atlas-manager.cpp
dali-toolkit/internal/text/rendering/atlas/atlas-manager.h
dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp

index 63c89d3..33a8744 100644 (file)
@@ -152,7 +152,7 @@ public:
   void GetFontMetrics( FontId fontId, FontMetrics& metrics ){}
   GlyphIndex GetGlyphIndex( FontId fontId, Character charcode ){return 0;}
   bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal ){return true;}
-  BufferImage CreateBitmap( FontId fontId, GlyphIndex glyphIndex ){return BufferImage();}
+  PixelData CreateBitmap( FontId fontId, GlyphIndex glyphIndex ){return PixelData();}
   void CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob,
                          unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight )
   {
@@ -462,7 +462,7 @@ bool FontClient::GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType typ
   return GetImplementation(*this).GetGlyphMetrics( array, size, horizontal );
 }
 
-BufferImage FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex )
+PixelData FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex )
 {
   return GetImplementation(*this).CreateBitmap( fontId, glyphIndex );
 }
index 1a72243..8b491b0 100644 (file)
@@ -593,7 +593,7 @@ void MultilanguageSupport::ValidateFonts( const Vector<Character>& text,
           if( isValidFont &&
               isEmojiScript )
           {
-            const BufferImage bitmap = fontClient.CreateBitmap( fontId, glyphIndex );
+            const PixelData bitmap = fontClient.CreateBitmap( fontId, glyphIndex );
 
             // For color emojis, the font is valid if the bitmap is RGBA.
             isValidFont = bitmap && ( Pixel::BGRA8888 == bitmap.GetPixelFormat() );
index f40b3a4..8532b93 100644 (file)
@@ -89,7 +89,7 @@ AtlasGlyphManager::AtlasGlyphManager()
 }
 
 void AtlasGlyphManager::Add( const Text::GlyphInfo& glyph,
-                             const BufferImage& bitmap,
+                             const PixelData& bitmap,
                              Dali::Toolkit::AtlasManager::AtlasSlot& slot )
 {
   DALI_LOG_INFO( gLogFilter, Debug::General, "Added glyph, font: %d index: %d\n", glyph.fontId, glyph.index );
@@ -97,9 +97,9 @@ void AtlasGlyphManager::Add( const Text::GlyphInfo& glyph,
   if ( mAtlasManager.Add( bitmap, slot ) )
   {
     // A new atlas was created so set the texture set details for the atlas
-    Dali::Atlas atlas = mAtlasManager.GetAtlasContainer( slot.mAtlasId );
+    Dali::Texture atlas = mAtlasManager.GetAtlasContainer( slot.mAtlasId );
     TextureSet textureSet = TextureSet::New();
-    textureSet.SetImage( 0u, atlas );
+    textureSet.SetTexture( 0u, atlas );
     mAtlasManager.SetTextures( slot.mAtlasId, textureSet );
   }
 
index 90210f2..b72b649 100644 (file)
@@ -70,7 +70,7 @@ public:
    * @copydoc Toolkit::AtlasGlyphManager::Add
    */
   void Add( const Text::GlyphInfo& glyph,
-            const BufferImage& bitmap,
+            const PixelData& bitmap,
             Dali::Toolkit::AtlasManager::AtlasSlot& slot );
 
   /**
index abcd391..6858f26 100644 (file)
@@ -69,7 +69,7 @@ AtlasGlyphManager::AtlasGlyphManager(Internal::AtlasGlyphManager *impl)
 }
 
 void AtlasGlyphManager::Add( const Text::GlyphInfo& glyph,
-                             const BufferImage& bitmap,
+                             const PixelData& bitmap,
                              AtlasManager::AtlasSlot& slot )
 {
   GetImplementation(*this).Add( glyph, bitmap, slot );
index 3831589..3ba54de 100644 (file)
@@ -84,7 +84,7 @@ public:
    * @param[out] slot information returned by atlas manager for addition
    */
   void Add( const Text::GlyphInfo& glyph,
-            const BufferImage& bitmap,
+            const PixelData& bitmap,
             AtlasManager::AtlasSlot& slot );
 
   /**
index 8d3ae1b..bc3a70a 100644 (file)
@@ -41,7 +41,6 @@ namespace
   const uint32_t DEFAULT_BLOCK_HEIGHT( 16u );
   const uint32_t SINGLE_PIXEL_PADDING( 1u );
   const uint32_t DOUBLE_PIXEL_PADDING( SINGLE_PIXEL_PADDING << 1 );
-  const uint32_t FILLED_PIXEL( -1 );
   Toolkit::AtlasManager::AtlasSize EMPTY_SIZE;
 }
 
@@ -79,8 +78,7 @@ Toolkit::AtlasManager::AtlasId AtlasManager::CreateAtlas( const Toolkit::AtlasMa
     return 0;
   }
 
-  Dali::Atlas atlas = Dali::Atlas::New( width, height, pixelformat );
-  atlas.Clear( Vector4::ZERO );
+  Dali::Texture atlas = Dali::Texture::New( TextureType::TEXTURE_2D, pixelformat, width, height );
   AtlasDescriptor atlasDescriptor;
   atlasDescriptor.mAtlas = atlas;
   atlasDescriptor.mSize = size;
@@ -88,35 +86,21 @@ Toolkit::AtlasManager::AtlasId AtlasManager::CreateAtlas( const Toolkit::AtlasMa
   atlasDescriptor.mTotalBlocks = ( ( width - 1u ) / blockWidth ) * ( ( height - 1u ) / blockHeight );
   atlasDescriptor.mAvailableBlocks = atlasDescriptor.mTotalBlocks;
 
-  atlasDescriptor.mHorizontalStrip = BufferImage::New( blockWidth, SINGLE_PIXEL_PADDING, pixelformat );
-  atlasDescriptor.mVerticalStrip = BufferImage::New( SINGLE_PIXEL_PADDING, blockHeight - DOUBLE_PIXEL_PADDING, pixelformat );
-
-  PixelBuffer* buffer = atlasDescriptor.mHorizontalStrip.GetBuffer();
-  if( buffer == NULL )
-  {
-    DALI_LOG_ERROR("atlasDescriptor.mHorizontalStrip.GetBuffer() returns NULL\n");
-    return 0;
-  }
-  memset( buffer, 0, atlasDescriptor.mHorizontalStrip.GetBufferSize() );
-
-  buffer = atlasDescriptor.mVerticalStrip.GetBuffer();
-  if( buffer == NULL )
-  {
-    DALI_LOG_ERROR("atlasDescriptor.mVerticalStrip.GetBuffer() returns NULL\n");
-    return 0;
-  }
-  memset( buffer, 0, atlasDescriptor.mVerticalStrip.GetBufferSize() );
-
-  BufferImage filledPixelImage = BufferImage::New( 1u, 1u, pixelformat );
-  buffer = filledPixelImage.GetBuffer();
-  if( buffer == NULL)
-  {
-    DALI_LOG_ERROR("filledPixelImage.GetBuffer() returns NULL\n");
-    return 0;
-  }
-
-  memset( buffer, 0xFF, filledPixelImage.GetBufferSize() );
-  atlas.Upload( filledPixelImage, 0, 0 );
+  unsigned int bufferSize(  blockWidth * SINGLE_PIXEL_PADDING * Dali::Pixel::GetBytesPerPixel(pixelformat) );
+  unsigned char* bufferHorizontalStrip = new unsigned char[bufferSize];
+  memset( bufferHorizontalStrip, 0, bufferSize );
+  atlasDescriptor.mHorizontalStrip = PixelData::New( bufferHorizontalStrip, bufferSize, blockWidth, SINGLE_PIXEL_PADDING, pixelformat, PixelData::DELETE_ARRAY );
+
+  bufferSize = SINGLE_PIXEL_PADDING * (blockHeight - DOUBLE_PIXEL_PADDING) * Dali::Pixel::GetBytesPerPixel(pixelformat);
+  unsigned char* bufferVerticalStrip = new unsigned char[bufferSize];
+  memset( bufferVerticalStrip, 0, bufferSize );
+  atlasDescriptor.mVerticalStrip = PixelData::New( bufferVerticalStrip, bufferSize, SINGLE_PIXEL_PADDING, blockHeight - DOUBLE_PIXEL_PADDING, pixelformat, PixelData::DELETE_ARRAY );
+
+  bufferSize = Dali::Pixel::GetBytesPerPixel(pixelformat);
+  unsigned char* buffer = new unsigned char[bufferSize];
+  memset( buffer, 0xFF, bufferSize );
+  PixelData filledPixelImage = PixelData::New( buffer, bufferSize, 1u, 1u, pixelformat, PixelData::DELETE_ARRAY );
+  atlas.Upload( filledPixelImage, 0u, 0u, 0u, 0u, 1u, 1u );
   mAtlasList.push_back( atlasDescriptor );
   return mAtlasList.size();
 }
@@ -126,7 +110,7 @@ void AtlasManager::SetAddPolicy( Toolkit::AtlasManager::AddFailPolicy policy )
   mAddFailPolicy = policy;
 }
 
-bool AtlasManager::Add( const BufferImage& image,
+bool AtlasManager::Add( const PixelData& image,
                         Toolkit::AtlasManager::AtlasSlot& slot,
                         Toolkit::AtlasManager::AtlasId atlas )
 {
@@ -245,7 +229,7 @@ AtlasManager::SizeType AtlasManager::CheckAtlas( SizeType atlas,
   return result;
 }
 
-void AtlasManager::UploadImage( const BufferImage& image,
+void AtlasManager::UploadImage( const PixelData& image,
                                 const AtlasSlotDescriptor& desc )
 {
   // Get the atlas to upload the image to
@@ -271,25 +255,30 @@ void AtlasManager::UploadImage( const BufferImage& image,
   SizeType height = image.GetHeight();
 
   // Blit image 1 pixel to the right and down into the block to compensate for texture filtering
-  if ( !mAtlasList[ atlas ].mAtlas.Upload( image,
+  if ( !mAtlasList[ atlas ].mAtlas.Upload( image, 0u, 0u,
                                            blockOffsetX + SINGLE_PIXEL_PADDING,
-                                           blockOffsetY + SINGLE_PIXEL_PADDING ) )
+                                           blockOffsetY + SINGLE_PIXEL_PADDING,
+                                           width, height) )
   {
     DALI_LOG_ERROR("Uploading image to Atlas Failed!.\n");
   }
 
   // Blit top strip
-  if ( !mAtlasList[ atlas ].mAtlas.Upload( mAtlasList[ atlas ].mHorizontalStrip,
+  if ( !mAtlasList[ atlas ].mAtlas.Upload( mAtlasList[ atlas ].mHorizontalStrip, 0u, 0u,
                                            blockOffsetX,
-                                           blockOffsetY ) )
+                                           blockOffsetY,
+                                           mAtlasList[ atlas ].mHorizontalStrip.GetWidth(),
+                                           mAtlasList[ atlas ].mHorizontalStrip.GetHeight()) )
   {
     DALI_LOG_ERROR("Uploading top strip to Atlas Failed!\n");
   }
 
   // Blit left strip
-  if ( !mAtlasList[ atlas ].mAtlas.Upload( mAtlasList[ atlas ].mVerticalStrip,
+  if ( !mAtlasList[ atlas ].mAtlas.Upload( mAtlasList[ atlas ].mVerticalStrip, 0u, 0u,
                                            blockOffsetX,
-                                           blockOffsetY + SINGLE_PIXEL_PADDING ) )
+                                           blockOffsetY + SINGLE_PIXEL_PADDING,
+                                           mAtlasList[ atlas ].mVerticalStrip.GetWidth(),
+                                           mAtlasList[ atlas ].mVerticalStrip.GetHeight() ) )
   {
     DALI_LOG_ERROR("Uploading left strip to Atlas Failed!\n");
   }
@@ -297,9 +286,11 @@ void AtlasManager::UploadImage( const BufferImage& image,
   // Blit bottom strip
   if ( blockOffsetY + height + DOUBLE_PIXEL_PADDING <= mAtlasList[ atlas ].mSize.mHeight )
   {
-    if ( !mAtlasList[ atlas ].mAtlas.Upload( mAtlasList[ atlas ].mHorizontalStrip,
+    if ( !mAtlasList[ atlas ].mAtlas.Upload( mAtlasList[ atlas ].mHorizontalStrip, 0u, 0u,
                                              blockOffsetX,
-                                             blockOffsetY + height + SINGLE_PIXEL_PADDING ) )
+                                             blockOffsetY + height + SINGLE_PIXEL_PADDING,
+                                             mAtlasList[ atlas ].mHorizontalStrip.GetWidth(),
+                                             mAtlasList[ atlas ].mHorizontalStrip.GetHeight() ) )
     {
       DALI_LOG_ERROR("Uploading bottom strip to Atlas Failed!.\n");
     }
@@ -308,9 +299,11 @@ void AtlasManager::UploadImage( const BufferImage& image,
   // Blit right strip
   if ( blockOffsetX + width + DOUBLE_PIXEL_PADDING <= mAtlasList[ atlas ].mSize.mWidth )
   {
-    if ( !mAtlasList[ atlas ].mAtlas.Upload( mAtlasList[ atlas ].mVerticalStrip,
+    if ( !mAtlasList[ atlas ].mAtlas.Upload( mAtlasList[ atlas ].mVerticalStrip, 0u, 0u,
                                              blockOffsetX + width + SINGLE_PIXEL_PADDING,
-                                             blockOffsetY + SINGLE_PIXEL_PADDING ) )
+                                             blockOffsetY + SINGLE_PIXEL_PADDING,
+                                             mAtlasList[ atlas ].mVerticalStrip.GetWidth(),
+                                             mAtlasList[ atlas ].mVerticalStrip.GetHeight() ) )
     {
       DALI_LOG_ERROR("Uploading right strip to Atlas Failed!.\n");
     }
@@ -349,10 +342,10 @@ void AtlasManager::GenerateMeshData( ImageId id,
   }
 }
 
-Dali::Atlas AtlasManager::GetAtlasContainer( AtlasId atlas ) const
+Dali::Texture AtlasManager::GetAtlasContainer( AtlasId atlas ) const
 {
   DALI_ASSERT_DEBUG( atlas && atlas <= mAtlasList.size() );
-  Dali::Atlas atlasContainer;
+  Dali::Texture atlasContainer;
   if ( atlas && atlas-- <= mAtlasList.size() )
   {
     atlasContainer = mAtlasList[ atlas ].mAtlas;
index e86bda1..863bba9 100644 (file)
@@ -59,11 +59,11 @@ public:
    */
   struct AtlasDescriptor
   {
-    Dali::Atlas mAtlas;                                                 // atlas image
+    Dali::Texture mAtlas;                                                 // atlas image
     Toolkit::AtlasManager::AtlasSize mSize;                             // size of atlas
     Pixel::Format mPixelFormat;                                         // pixel format used by atlas
-    BufferImage mHorizontalStrip;                                       // Image used to pad upload
-    BufferImage mVerticalStrip;                                         // Image used to pad upload
+    PixelData mHorizontalStrip;                                       // Image used to pad upload
+    PixelData mVerticalStrip;                                         // Image used to pad upload
     TextureSet mTextureSet;                                             // Texture set used for atlas texture
     SizeType mTotalBlocks;                                              // total number of blocks in atlas
     SizeType mAvailableBlocks;                                          // number of blocks available in atlas
@@ -101,7 +101,7 @@ public:
   /**
    * @copydoc Toolkit::AtlasManager::Add
    */
-  bool Add( const BufferImage& image,
+  bool Add( const PixelData& image,
             Toolkit::AtlasManager::AtlasSlot& slot,
             Toolkit::AtlasManager::AtlasId atlas );
 
@@ -121,7 +121,7 @@ public:
   /**
    * @copydoc Toolkit::AtlasManager::GetAtlasContainer
    */
-  Dali::Atlas GetAtlasContainer( AtlasId atlas ) const;
+  Dali::Texture GetAtlasContainer( AtlasId atlas ) const;
 
   /**
    * @copydoc Toolkit::AtlasManager::GetAtlas
@@ -185,7 +185,7 @@ private:
                        SizeType height,
                        Pixel::Format pixelFormat );
 
-  void UploadImage( const BufferImage& image,
+  void UploadImage( const PixelData& image,
                     const AtlasSlotDescriptor& desc );
 
 };
index d28b586..510da05 100644 (file)
@@ -55,7 +55,7 @@ void AtlasManager::SetAddPolicy( AddFailPolicy policy )
   GetImplementation(*this).SetAddPolicy( policy );
 }
 
-bool AtlasManager::Add( const BufferImage& image,
+bool AtlasManager::Add( const PixelData& image,
                         AtlasManager::AtlasSlot& slot,
                         AtlasManager::AtlasId atlas )
 {
@@ -78,7 +78,7 @@ void AtlasManager::GenerateMeshData( ImageId id,
                                              addReference );
 }
 
-Dali::Atlas AtlasManager::GetAtlasContainer( AtlasId atlas ) const
+Dali::Texture AtlasManager::GetAtlasContainer( AtlasId atlas ) const
 {
   return GetImplementation(*this).GetAtlasContainer( atlas );
 }
index df86ac1..5542dd0 100644 (file)
@@ -157,13 +157,13 @@ public:
    *          If an add is made before an atlas is created under this policy,
    *          then a default size atlas will be created
    *
-   * @param[in] image reference to a bitmapimage
+   * @param[in] image PixelData object containing the image data
    * @param[out] slot result of add operation
    * @param[in] atlas optional preferred atlas
    *
    * @return true if a new atlas was created
    */
-  bool Add( const BufferImage& image,
+  bool Add( const PixelData& image,
             AtlasSlot& slot,
             AtlasId atlas = 0 );
 
@@ -196,7 +196,7 @@ public:
    *
    * @return Atlas Handle
    */
-  Dali::Atlas GetAtlasContainer( AtlasId atlas ) const;
+  Dali::Texture GetAtlasContainer( AtlasId atlas ) const;
 
   /**
    * @brief Get the Id of the atlas containing an image
index f2e5596..3ee577f 100644 (file)
@@ -289,7 +289,7 @@ struct AtlasRenderer::Impl
           }
 
           // Create a new image for the glyph
-          BufferImage bitmap = mFontClient.CreateBitmap( glyph.fontId, glyph.index );
+          PixelData bitmap = mFontClient.CreateBitmap( glyph.fontId, glyph.index );
           if( bitmap )
           {
             MaxBlockSize& blockSize = mBlockSizes[currentBlockSize];