Reduce Render::Texture size by 30% and texture upload message size by 50% 94/137994/2
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Mon, 10 Jul 2017 13:11:47 +0000 (14:11 +0100)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Mon, 10 Jul 2017 15:24:00 +0000 (16:24 +0100)
use uint16_t instead of unsigned int, which is unnecessarily large

Change-Id: I52ed1574086c3c35148ac1def09f32f49238adb4

dali/internal/event/rendering/texture-impl.cpp
dali/internal/event/rendering/texture-impl.h
dali/internal/render/renderers/render-texture.cpp
dali/internal/render/renderers/render-texture.h

index 4887adf..5044890 100644 (file)
@@ -29,7 +29,9 @@ namespace Internal
 
 TexturePtr Texture::New(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height )
 {
-  TexturePtr texture( new Texture( type, format, width, height ) );
+  constexpr auto max_value = std::numeric_limits< uint16_t >::max();
+  DALI_ASSERT_ALWAYS( ( width < max_value )&&( height < max_value )&& "Size out of range" );
+  TexturePtr texture( new Texture( type, format, ImageDimensions( width, height) ) );
   texture->Initialize();
   return texture;
 }
@@ -46,14 +48,13 @@ Render::Texture* Texture::GetRenderObject() const
   return mRenderObject;
 }
 
-Texture::Texture(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height )
+Texture::Texture(TextureType::Type type, Pixel::Format format, ImageDimensions size )
 : mEventThreadServices( *Stage::GetCurrent() ),
   mRenderObject( NULL ),
   mNativeImage(),
+  mSize( size ),
   mType( type ),
-  mFormat( format ),
-  mWidth( width ),
-  mHeight( height )
+  mFormat( format )
 {
 }
 
@@ -61,10 +62,9 @@ Texture::Texture( NativeImageInterfacePtr nativeImageInterface )
 : mEventThreadServices( *Stage::GetCurrent() ),
   mRenderObject( NULL ),
   mNativeImage( nativeImageInterface ),
+  mSize( nativeImageInterface->GetWidth(), nativeImageInterface->GetHeight() ),
   mType( TextureType::TEXTURE_2D ),
-  mFormat( Pixel::RGB888 ),
-  mWidth( nativeImageInterface->GetWidth() ),
-  mHeight( nativeImageInterface->GetHeight() )
+  mFormat( Pixel::RGB888 )
 {
 }
 
@@ -78,7 +78,7 @@ void Texture::Initialize()
     }
     else
     {
-      mRenderObject = new Render::Texture( mType, mFormat, mWidth, mHeight );
+      mRenderObject = new Render::Texture( mType, mFormat, mSize );
     }
 
     OwnerPointer< Render::Texture > transferOwnership( mRenderObject );
@@ -100,10 +100,19 @@ bool Texture::Upload( PixelDataPtr pixelData )
 }
 
 bool Texture::Upload( PixelDataPtr pixelData,
-                         unsigned int layer, unsigned int mipmap,
-                         unsigned int xOffset, unsigned int yOffset,
-                         unsigned int width, unsigned int height )
+                      unsigned int layer, unsigned int mipmap,
+                      unsigned int xOffset, unsigned int yOffset,
+                      unsigned int width, unsigned int height )
 {
+  constexpr auto max_value = std::numeric_limits< uint16_t >::max();
+  DALI_ASSERT_ALWAYS( layer < max_value &&
+                      mipmap < max_value &&
+                      xOffset < max_value &&
+                      yOffset < max_value &&
+                      width < max_value &&
+                      height < max_value &&
+                      "Parameter value out of range" );
+
   bool result(false);
   if( EventThreadServices::IsCoreRunning() && mRenderObject )
   {
@@ -127,15 +136,20 @@ bool Texture::Upload( PixelDataPtr pixelData,
           {
             DALI_LOG_ERROR( "PixelData of an incorrect size when trying to update texture\n");
           }
-          else if( ( xOffset + width  > ( mWidth  / (1<<mipmap) ) ) ||
-              ( yOffset + height > ( mHeight / (1<<mipmap) ) ) )
+          else if( ( xOffset + width  > ( mSize.GetWidth()  / (1u << mipmap) ) ) ||
+              ( yOffset + height > ( mSize.GetHeight() / (1u << mipmap) ) ) )
           {
             DALI_LOG_ERROR( "Texture update area out of bounds\n");
           }
           else
           {
             //Parameters are correct. Send message to upload data to the texture
-            UploadParams params = { layer, mipmap, xOffset, yOffset, width, height };
+            UploadParams params = { static_cast< uint16_t >( layer ),
+                                    static_cast< uint16_t >( mipmap ),
+                                    static_cast< uint16_t >( xOffset ),
+                                    static_cast< uint16_t >( yOffset ),
+                                    static_cast< uint16_t >( width ),
+                                    static_cast< uint16_t >( height ) };
             UploadTextureMessage( mEventThreadServices.GetUpdateManager(), *mRenderObject, pixelData, params );
             result = true;
           }
@@ -161,12 +175,12 @@ void Texture::GenerateMipmaps()
 
 unsigned int Texture::GetWidth() const
 {
-  return mWidth;
+  return mSize.GetWidth();
 }
 
 unsigned int Texture::GetHeight() const
 {
-  return mHeight;
+  return mSize.GetHeight();
 }
 
 } // namespace Internal
index 213961e..4464dcb 100644 (file)
@@ -23,6 +23,7 @@
 #include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
 #include <dali/public-api/object/base-object.h>
 #include <dali/public-api/images/pixel.h>
+#include <dali/public-api/images/image-operations.h> // Dali::ImageDimensions
 #include <dali/public-api/rendering/texture.h> // Dali::Internal::Render::Texture
 #include <dali/internal/event/common/event-thread-services.h>
 #include <dali/internal/event/images/pixel-data-impl.h>
@@ -48,12 +49,12 @@ public:
    */
   struct UploadParams
   {
-    unsigned int layer;    ///< Specifies the layer of a cube map or array texture
-    unsigned int mipmap;   ///< Specifies the level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.
-    unsigned int xOffset;  ///< Specifies a texel offset in the x direction within the texture array.
-    unsigned int yOffset;  ///< Specifies a texel offset in the y direction within the texture array.
-    unsigned int width;    ///< Specifies the width of the texture subimage
-    unsigned int height;   ///< Specifies the height of the texture subimage.
+    uint16_t layer;    ///< Specifies the layer of a cube map or array texture
+    uint16_t mipmap;   ///< Specifies the level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image.
+    uint16_t xOffset;  ///< Specifies a texel offset in the x direction within the texture array.
+    uint16_t yOffset;  ///< Specifies a texel offset in the y direction within the texture array.
+    uint16_t width;    ///< Specifies the width of the texture subimage
+    uint16_t height;   ///< Specifies the height of the texture subimage.
   };
 
   /**
@@ -115,10 +116,9 @@ private: // implementation
    * Constructor
    * @param[in] type The type of the texture
    * @param[in] format The format of the pixel data
-   * @param[in] width The width of the texture
-   * @param[in] height The height of the texture
+   * @param[in] size The size of the texture
    */
-  Texture(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height );
+  Texture(TextureType::Type type, Pixel::Format format, ImageDimensions size );
 
   /**
    * Constructor from native image
@@ -148,10 +148,10 @@ private: // data
   Internal::Render::Texture* mRenderObject;            ///<The Render::Texture associated to this texture
 
   NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
-  Dali::TextureType::Type mType;      ///< Texture type (cached)
-  Pixel::Format mFormat;              ///< Pixel format
-  unsigned int mWidth;                ///< Width of the texture
-  unsigned int mHeight;               ///< Height of the texture
+  ImageDimensions mSize;                ///< Size of the texture
+  Dali::TextureType::Type mType;        ///< Texture type (cached)
+  Pixel::Format mFormat;                ///< Pixel format
+
 };
 
 } // namespace Internal
index 8ae6829..b4646d5 100644 (file)
@@ -623,20 +623,20 @@ bool IsCompressedFormat(Pixel::Format pixelFormat)
 } //Unnamed namespace
 
 
-Texture::Texture( Type type, Pixel::Format format, unsigned int width, unsigned int height )
-:mId( 0 ),
mTarget( ( type == TextureType::TEXTURE_2D ) ? GL_TEXTURE_2D : GL_TEXTURE_CUBE_MAP ),
mType( type ),
mSampler(),
mNativeImage(),
- mGlFormat( GL_RGB ),
mGlInternalFormat( GL_RGB ),
mPixelDataType( GL_UNSIGNED_BYTE ),
mWidth( width ),
mHeight( height ),
mMaxMipMapLevel( 0 ),
- mHasAlpha( HasAlpha( format ) ),
- mIsCompressed( IsCompressedFormat( format ) )
+Texture::Texture( Type type, Pixel::Format format, ImageDimensions size )
+: mNativeImage(),
 mSampler(),
 mId( 0 ),
 mTarget( ( type == TextureType::TEXTURE_2D ) ? GL_TEXTURE_2D : GL_TEXTURE_CUBE_MAP ),
 mGlInternalFormat( GL_RGB ),
 mGlFormat( GL_RGB ),
 mPixelDataType( GL_UNSIGNED_BYTE ),
 mWidth( size.GetWidth() ),
 mHeight( size.GetHeight() ),
 mMaxMipMapLevel( 0 ),
 mType( type ),
 mHasAlpha( HasAlpha( format ) ),
 mIsCompressed( IsCompressedFormat( format ) )
 {
   PixelFormatToGl( static_cast<DevelPixel::Format>( format ),
                    mGlFormat,
@@ -645,19 +645,19 @@ Texture::Texture( Type type, Pixel::Format format, unsigned int width, unsigned
 }
 
 Texture::Texture( NativeImageInterfacePtr nativeImageInterface )
-:mId( 0 ),
mTarget( GL_TEXTURE_2D ),
mType( TextureType::TEXTURE_2D ),
mSampler(),
mNativeImage( nativeImageInterface ),
- mGlFormat( GL_RGB ),
mGlInternalFormat( GL_RGB ),
mPixelDataType( GL_UNSIGNED_BYTE ),
mWidth( nativeImageInterface->GetWidth() ),
mHeight( nativeImageInterface->GetHeight() ),
mMaxMipMapLevel( 0 ),
- mHasAlpha( nativeImageInterface->RequiresBlending() ),
- mIsCompressed( false )
+: mNativeImage( nativeImageInterface ),
 mSampler(),
 mId( 0 ),
 mTarget( GL_TEXTURE_2D ),
 mGlInternalFormat( GL_RGB ),
 mGlFormat( GL_RGB ),
 mPixelDataType( GL_UNSIGNED_BYTE ),
 mWidth( nativeImageInterface->GetWidth() ),
 mHeight( nativeImageInterface->GetHeight() ),
 mMaxMipMapLevel( 0 ),
 mType( TextureType::TEXTURE_2D ),
 mHasAlpha( nativeImageInterface->RequiresBlending() ),
 mIsCompressed( false )
 {
 }
 
index 8497b83..f96ca9d 100644 (file)
@@ -46,10 +46,9 @@ public:
    * Constructor
    * @param[in] type The type of the texture
    * @param[in] format The format of the pixel data
-   * @param[in] width The width of the texture
-   * @param[in] height The height of the texture
+   * @param[in] size The size of the texture
    */
-  Texture( Type type, Pixel::Format format, unsigned int width, unsigned int height );
+  Texture( Type type, Pixel::Format format, ImageDimensions size );
 
   /**
    * Constructor from native image
@@ -67,7 +66,7 @@ public:
    * Creates the texture and reserves memory for the first mipmap level
    * @param[in] context The GL context
    */
-  void Initialize(Context& context);
+  void Initialize( Context& context );
 
   /**
    * Deletes the texture from the GPU
@@ -119,24 +118,6 @@ public:
   }
 
   /**
-   * Get the width of the texture
-   * @return Width of the texture
-   */
-  unsigned int GetWidth() const
-  {
-    return mWidth;
-  }
-
-  /**
-   * Get the height of the texture
-   * @return Height of the texture
-   */
-  unsigned int GetHeight() const
-  {
-    return mHeight;
-  }
-
-  /**
    * Get the type of the texture
    * @return Type of the texture
    */
@@ -163,19 +144,20 @@ private:
    */
   void ApplySampler( Context& context, Render::Sampler* sampler );
 
+  NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
+  Render::Sampler mSampler;             ///< The current sampler state
   GLuint mId;                           ///< Id of the texture
   GLuint mTarget;                       ///< Specifies the target to which the texture is bound.
-  Type mType;                           ///< Type of the texture
-  Render::Sampler mSampler;             ///< The current sampler state
-  NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
-  GLenum mGlFormat;                     ///< The gl format of the pixel data
   GLint mGlInternalFormat;              ///< The gl internal format of the pixel data
+  GLenum mGlFormat;                     ///< The gl format of the pixel data
   GLenum mPixelDataType;                ///< The data type of the pixel data
-  unsigned int mWidth;                  ///< Width of the texture
-  unsigned int mHeight;                 ///< Height of the texture
-  unsigned int mMaxMipMapLevel;         ///< Maximum mipmap level
+  uint16_t mWidth;                      ///< Width of the texture
+  uint16_t mHeight;                     ///< Height of the texture
+  uint16_t mMaxMipMapLevel;             ///< Maximum mipmap level
+  Type mType:2;                         ///< Type of the texture
   bool mHasAlpha : 1;                   ///< Whether the format has an alpha channel
   bool mIsCompressed : 1;               ///< Whether the format is compressed
+
 };