X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Frendering%2Ftexture-impl.cpp;h=3c3bbbdc99b613623c840e4ac54c5ee7f93ba5d3;hb=14502a507909174b52e486a0ee7516cb26e6ad45;hp=1fe7657e20c7b1b10068b09a7ad084d2bf1db540;hpb=e317f59daa2ce5577e08c07f515d607a2dbc34e1;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/rendering/texture-impl.cpp b/dali/internal/event/rendering/texture-impl.cpp index 1fe7657..3c3bbbd 100644 --- a/dali/internal/event/rendering/texture-impl.cpp +++ b/dali/internal/event/rendering/texture-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,68 +21,73 @@ // INTERNAL INCLUDES #include #include +#include namespace Dali { namespace Internal { -NewTexturePtr NewTexture::New(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height ) +TexturePtr Texture::New(TextureType::Type type, Pixel::Format format, unsigned int width, unsigned int height ) { - NewTexturePtr texture( new NewTexture( 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; } -NewTexturePtr NewTexture::New( NativeImageInterface& nativeImageInterface ) +TexturePtr Texture::New( NativeImageInterface& nativeImageInterface ) { - NewTexturePtr texture( new NewTexture( &nativeImageInterface ) ); + TexturePtr texture( new Texture( &nativeImageInterface ) ); texture->Initialize(); return texture; } -Render::NewTexture* NewTexture::GetRenderObject() const +Render::Texture* Texture::GetRenderObject() const { return mRenderObject; } -NewTexture::NewTexture(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 ) { } -NewTexture::NewTexture( NativeImageInterfacePtr nativeImageInterface ) +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 ) { } -void NewTexture::Initialize() +void Texture::Initialize() { - if( mNativeImage ) + if( EventThreadServices::IsCoreRunning() ) { - mRenderObject = new Render::NewTexture( mNativeImage ); + if( mNativeImage ) + { + mRenderObject = new Render::Texture( mNativeImage ); + } + else + { + mRenderObject = new Render::Texture( mType, mFormat, mSize ); + } + + OwnerPointer< Render::Texture > transferOwnership( mRenderObject ); + AddTexture( mEventThreadServices.GetUpdateManager(), transferOwnership ); } - else - { - mRenderObject = new Render::NewTexture( mType, mFormat, mWidth, mHeight ); - } - - AddTexture( mEventThreadServices.GetUpdateManager(), *mRenderObject ); } -NewTexture::~NewTexture() +Texture::~Texture() { if( EventThreadServices::IsCoreRunning() && mRenderObject ) { @@ -90,64 +95,98 @@ NewTexture::~NewTexture() } } -bool NewTexture::CheckUploadParametres( const Vector& buffer, const UploadParams& parameters ) const +bool Texture::Upload( PixelDataPtr pixelData ) { - if( mNativeImage ) - { - DALI_LOG_ERROR( "Error: Uploading data to a native texture"); - return false; - } - else if( buffer.Size() < GetBytesPerPixel( mFormat ) * parameters.width * parameters.height ) - { - DALI_LOG_ERROR( "Error: Buffer of an incorrect size when trying to update texture"); - return false; - } - else if( ( parameters.xOffset + parameters.width > static_cast( mWidth/(1< static_cast( mHeight/(1<GetWidth(), pixelData->GetHeight() ); } -void NewTexture::Upload( Vector& buffer, - unsigned int layer, unsigned int mipmap, - unsigned int xOffset, unsigned int yOffset, - unsigned int width, unsigned int height ) +bool Texture::Upload( PixelDataPtr pixelData, + unsigned int layer, unsigned int mipmap, + unsigned int xOffset, unsigned int yOffset, + unsigned int width, unsigned int height ) { - UploadParams params = { layer, mipmap, xOffset, yOffset, width, height }; - if( CheckUploadParametres( buffer, params ) ) + 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 ) { - UploadTextureMessage(mEventThreadServices.GetUpdateManager(), *mRenderObject, buffer, params ); + if( mNativeImage ) + { + DALI_LOG_ERROR( "OpenGL ES does not support uploading data to native texture\n"); + } + else + { + unsigned int pixelDataSize = pixelData->GetWidth()*pixelData->GetHeight(); + if( pixelData->GetBuffer() == NULL || pixelDataSize == 0 ) + { + DALI_LOG_ERROR( "PixelData is empty\n"); + } + else + { + Pixel::Format pixelDataFormat = pixelData->GetPixelFormat(); + if( ( pixelDataFormat == mFormat ) || ( (pixelDataFormat == Pixel::RGB888 ) && ( mFormat == Pixel::RGBA8888 ) ) ) + { + if( pixelDataSize < width * height ) + { + DALI_LOG_ERROR( "PixelData of an incorrect size when trying to update texture\n"); + } + 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 = { 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 ); + + // Request event processing and update forcely + mEventThreadServices.GetRenderController().RequestProcessEventsOnIdle( true ); + mEventThreadServices.ForceNextUpdate(); + + result = true; + } + } + else + { + DALI_LOG_ERROR( "Bad format\n"); + } + } + } } + + return result; } -void NewTexture::Upload( Vector& buffer ) +void Texture::GenerateMipmaps() { - UploadParams params = {0u,0u,0u,0u,mWidth,mHeight}; - if( CheckUploadParametres( buffer, params ) ) + if( EventThreadServices::IsCoreRunning() && mRenderObject ) { - UploadTextureMessage(mEventThreadServices.GetUpdateManager(), *mRenderObject, buffer, params ); + GenerateMipmapsMessage(mEventThreadServices.GetUpdateManager(), *mRenderObject ); } } -void NewTexture::GenerateMipmaps() -{ - GenerateMipmapsMessage(mEventThreadServices.GetUpdateManager(), *mRenderObject ); -} - -unsigned int NewTexture::GetWidth() const +unsigned int Texture::GetWidth() const { - return mWidth; + return mSize.GetWidth(); } -unsigned int NewTexture::GetHeight() const +unsigned int Texture::GetHeight() const { - return mHeight; + return mSize.GetHeight(); } } // namespace Internal