/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
// INTERNAL INCLUDES
#include <dali/public-api/object/type-registry.h>
#include <dali/internal/event/common/thread-local-storage.h>
-#include <dali/internal/event/images/image-factory.h>
+#include <dali/internal/event/images/bitmap-packed-pixel.h>
#include <dali/internal/event/resources/resource-client.h>
#include <dali/integration-api/bitmap.h>
#include <dali/integration-api/platform-abstraction.h>
{
bool uploadSuccess( false );
- if( Compatible(bufferImage.GetPixelFormat(),
- xOffset + bufferImage.GetWidth(),
- yOffset + bufferImage.GetHeight() ) )
+ if( IsInside( xOffset + bufferImage.GetWidth(), yOffset + bufferImage.GetHeight() ) )
{
AllocateAtlas();
ResourceId destId = GetResourceId();
- ResourceId srcId = bufferImage.GetResourceId();
- if( destId && srcId )
+ if( destId )
{
- mResourceClient.UploadBitmap( destId, srcId, xOffset, yOffset );
+ bufferImage.UploadBitmap( destId, xOffset, yOffset );
uploadSuccess = true;
}
}
Integration::BitmapPtr bitmap = LoadBitmap( url );
- if( bitmap && Compatible(bitmap->GetPixelFormat(), xOffset + bitmap->GetImageWidth(), yOffset + bitmap->GetImageHeight()) )
+ if( bitmap && IsInside( xOffset + bitmap->GetImageWidth(), yOffset + bitmap->GetImageHeight()) )
{
AllocateAtlas();
ResourceId destId = GetResourceId();
return uploadSuccess;
}
+bool Atlas::Upload( PixelDataPtr pixelData,
+ SizeType xOffset,
+ SizeType yOffset )
+{
+ bool uploadSuccess( false );
+ if( IsInside( xOffset + pixelData->GetWidth(), yOffset + pixelData->GetHeight() ) )
+ {
+ AllocateAtlas();
+ ResourceId destId = GetResourceId();
+
+ if( destId )
+ {
+ mResourceClient.UploadBitmap( destId, pixelData, xOffset, yOffset );
+ uploadSuccess = true;
+ }
+ }
+
+ return uploadSuccess;
+}
+
void Atlas::RecoverFromContextLoss()
{
ResourceId destId = GetResourceId();
Pixel::Format pixelFormat,
bool recoverContext )
: mResourceClient( ThreadLocalStorage::Get().GetResourceClient() ),
- mImageFactory( ThreadLocalStorage::Get().GetImageFactory() ),
mClearColor( Vector4::ZERO ),
mPixelFormat( pixelFormat ),
mClear( false ),
{
--mConnectionCount;
- if ( Dali::Image::UNUSED == mReleasePolicy &&
- mConnectionCount == 0 )
- {
- ReleaseAtlas();
- }
+ // Only release the atlas upon destruction
}
}
-bool Atlas::Compatible( Pixel::Format pixelFormat,
- SizeType x,
- SizeType y )
+bool Atlas::IsInside( SizeType x, SizeType y )
{
- bool Compatible(false);
+ bool fit(false);
- if( mPixelFormat != pixelFormat )
+ if( x <= mWidth && y <= mHeight )
{
- DALI_LOG_ERROR( "Pixel format %d does not match Atlas format %d\n", pixelFormat, mPixelFormat );
+ fit = true;
}
else
{
- if( x <= mWidth && y <= mHeight )
- {
- Compatible = true;
- }
- else
- {
- DALI_LOG_ERROR( "image does not fit within the atlas \n" );
- }
+ DALI_LOG_ERROR( "image does not fit within the atlas \n" );
}
- return Compatible;
+ return fit;
}
void Atlas::AllocateAtlas()
if( !mTicket )
{
mTicket = mResourceClient.AllocateTexture( mWidth, mHeight, mPixelFormat );
- mImageFactory.RegisterForContextRecovery( this );
+ mTicket->AddObserver( *this );
}
}
{
mTicket.Reset();
ClearCache();
- mImageFactory.UnregisterFromContextRecovery( this );
}
void Atlas::ClearBackground(const Vector4& color )
}
}
- RectArea area;
- imageData->Update(area);
-
mClearColor = color;
mClear = true;
- mResourceClient.UploadBitmap( destId, imageData->GetResourceId(), 0, 0 );
+
+ imageData->UploadBitmap( destId, 0, 0 );
}
}