From cffc864eb25bea9efe810681cd5d50ae3dda9596 Mon Sep 17 00:00:00 2001 From: Kimmo Hoikka Date: Mon, 10 Jul 2017 14:11:47 +0100 Subject: [PATCH] Reduce Render::Texture size by 30% and texture upload message size by 50% use uint16_t instead of unsigned int, which is unnecessarily large Change-Id: I52ed1574086c3c35148ac1def09f32f49238adb4 --- dali/internal/event/rendering/texture-impl.cpp | 48 +++++++++++++------- dali/internal/event/rendering/texture-impl.h | 26 +++++------ dali/internal/render/renderers/render-texture.cpp | 54 +++++++++++------------ dali/internal/render/renderers/render-texture.h | 40 +++++------------ 4 files changed, 82 insertions(+), 86 deletions(-) diff --git a/dali/internal/event/rendering/texture-impl.cpp b/dali/internal/event/rendering/texture-impl.cpp index 4887adf..5044890 100644 --- a/dali/internal/event/rendering/texture-impl.cpp +++ b/dali/internal/event/rendering/texture-impl.cpp @@ -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< ( mHeight / (1< ( 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 diff --git a/dali/internal/event/rendering/texture-impl.h b/dali/internal/event/rendering/texture-impl.h index 213961e..4464dcb 100644 --- a/dali/internal/event/rendering/texture-impl.h +++ b/dali/internal/event/rendering/texture-impl.h @@ -23,6 +23,7 @@ #include // Dali::IntrusivePtr #include #include +#include // Dali::ImageDimensions #include // Dali::Internal::Render::Texture #include #include @@ -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; ///( 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 ) { } diff --git a/dali/internal/render/renderers/render-texture.h b/dali/internal/render/renderers/render-texture.h index 8497b83..f96ca9d 100644 --- a/dali/internal/render/renderers/render-texture.h +++ b/dali/internal/render/renderers/render-texture.h @@ -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 + }; -- 2.7.4