-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
// INTERNAL INCLUDES
#include <dali/internal/event/resources/resource-client.h>
-#include <dali/public-api/common/map-wrapper.h>
+#include <dali/devel-api/common/map-wrapper.h>
-#include <dali/integration-api/glyph-set.h>
#include <dali/integration-api/resource-request.h>
#include <dali/integration-api/debug.h>
+#include <dali/internal/event/common/event-thread-services.h>
#include <dali/internal/event/common/stage-impl.h>
-#include <dali/internal/event/text/resource/glyph-load-observer.h>
#include <dali/internal/event/images/image-impl.h>
#include <dali/internal/update/resources/resource-manager.h>
-#include <dali/internal/update/manager/update-manager.h>
namespace Dali
typedef TicketContainer::size_type TicketContainerSize;
typedef std::pair<ResourceId, ResourceTicket*> TicketPair;
-typedef std::map<ResourceId, Bitmap*> BitmapCache;
-typedef BitmapCache::iterator BitmapCacheIter;
-
struct ResourceClient::Impl
{
Impl()
- : mNextId(0),
- mGlyphLoadObserver( NULL)
+ : mNextId(0)
{
}
ResourceId mNextId;
TicketContainer mTickets;
- BitmapCache mBitmaps;
- GlyphLoadObserver* mGlyphLoadObserver;
};
ResourceClient::ResourceClient( ResourceManager& resourceManager,
- SceneGraph::UpdateManager& updateManager )
+ EventThreadServices& eventThreadServices)
: mResourceManager(resourceManager),
- mUpdateManager(updateManager)
+ mEventThreadServices(eventThreadServices)
{
mImpl = new ResourceClient::Impl();
mResourceManager.SetClient(*this);
const BitmapResourceType& bitmapResource = static_cast <const BitmapResourceType&> (type);
// image tickets will cache the requested parameters, which are updated on successful loading
ImageTicket* imageTicket = new ImageTicket(*this, newId, typePath);
- imageTicket->mAttributes = bitmapResource.imageAttributes;
+ imageTicket->mAttributes.Reset( bitmapResource.size, bitmapResource.scalingMode, bitmapResource.samplingMode, bitmapResource.orientationCorrection );
newTicket = imageTicket;
break;
}
const NativeImageResourceType& nativeResource = static_cast <const NativeImageResourceType&> (type);
// image tickets will cache the requested parameters, which are updated on successful loading
ImageTicket* imageTicket = new ImageTicket(*this, newId, typePath);
- imageTicket->mAttributes = nativeResource.imageAttributes;
+ imageTicket->mAttributes.SetSize( nativeResource.imageDimensions.GetWidth(), nativeResource.imageDimensions.GetHeight() );
newTicket = imageTicket;
break;
}
- case ResourceModel: // FALLTHROUGH
case ResourceTargetImage:
- case ResourceShader:
- case ResourceMesh:
- case ResourceText:
{
newTicket = new ResourceTicket(*this, newId, typePath);
break;
DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: RequestResource(path:%s type.id:%d) newId:%u\n", path.c_str(), type.id, newId);
- RequestLoadResourceMessage( mUpdateManager.GetEventToUpdate(), mResourceManager, newId, typePath, priority );
+ RequestLoadResourceMessage( mEventThreadServices, mResourceManager, newId, typePath, priority );
return newTicket;
}
const BitmapResourceType& bitmapResource = static_cast <const BitmapResourceType&> ( type );
// Image tickets will cache the requested parameters, which are updated on successful loading
ImageTicket* imageTicket = new ImageTicket( *this, newId, typePath );
- imageTicket->mAttributes = bitmapResource.imageAttributes;
+ imageTicket->mAttributes.Reset( bitmapResource.size, bitmapResource.scalingMode, bitmapResource.samplingMode, bitmapResource.orientationCorrection );
newTicket = imageTicket;
break;
}
// FALLTHROUGH:
case ResourceNativeImage:
- case ResourceModel:
case ResourceTargetImage:
- case ResourceShader:
- case ResourceMesh:
- case ResourceText:
{
- DALI_LOG_ERROR( "Unsupported resource type passed for decoding from a memory buffer." );
+ DALI_LOG_ERROR( "Unsupported resource type passed for decoding from a memory buffer.\n" );
}
}
mImpl->mTickets.insert(TicketPair(newId, newTicket.Get()));
DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: DecodeResource( type.id:%d ) newId:%u\n", type.id, newId);
- RequestDecodeResourceMessage( mUpdateManager.GetEventToUpdate(), mResourceManager, newId, typePath, buffer, priority );
+ RequestDecodeResourceMessage( mEventThreadServices, mResourceManager, newId, typePath, buffer, priority );
}
}
return newTicket;
}
-ResourceTicketPtr ResourceClient::LoadShader( ShaderResourceType& type,
- const std::string& path )
-{
- ResourceTicketPtr newTicket;
-
- const ResourceId newId = ++(mImpl->mNextId);
-
- ResourceTypePath typePath(type, path);
- newTicket = new ResourceTicket(*this, newId, typePath);
-
- mImpl->mTickets.insert(TicketPair(newId, newTicket.Get()));
-
- DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: LoadShader(path:%s) newId:%u\n", path.c_str(), newId);
-
- RequestLoadShaderMessage( mUpdateManager.GetEventToUpdate(), mResourceManager, newId, typePath );
- return newTicket;
-}
-
-bool ResourceClient::ReloadResource( ResourceId id, LoadResourcePriority priority )
+bool ResourceClient::ReloadResource( ResourceId id, bool resetFinishedStatus, LoadResourcePriority priority )
{
DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: ReloadResource(Id: %u)\n", id);
DALI_ASSERT_DEBUG(ticket && "Null ticket for tracked resource request." );
const ResourceTypePath * const typePathPtr = &ticket->GetTypePath();
DALI_ASSERT_DEBUG( typePathPtr );
- RequestReloadResourceMessage( mUpdateManager.GetEventToUpdate(), mResourceManager, id, *typePathPtr, priority );
+ RequestReloadResourceMessage( mEventThreadServices, mResourceManager, id, *typePathPtr, priority, resetFinishedStatus );
}
else
{
return resourceExists;
}
-void ResourceClient::SaveResource( ResourceTicketPtr ticket, const std::string& url )
-{
- DALI_ASSERT_DEBUG( ticket );
-
- DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: SaveResource(Id: %u, path:%s)\n", ticket->GetId(), url.c_str());
-
- const ResourceTypePath * const typePathPtr = &ticket->GetTypePath();
- if( typePathPtr )
- {
- if( 0 != url.length() )
- {
- ResourceTypePath typePath( *(typePathPtr->type), url );
- RequestSaveResourceMessage( mUpdateManager.GetEventToUpdate(), mResourceManager, ticket->GetId(), typePath );
- }
- else
- {
- ResourceTypePath typePath( *typePathPtr );
- RequestSaveResourceMessage( mUpdateManager.GetEventToUpdate(), mResourceManager, ticket->GetId(), typePath );
- }
- }
-}
-
ResourceTicketPtr ResourceClient::RequestResourceTicket( ResourceId id )
{
DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: RequestResourceTicket(Id: %u)\n", id);
return ticket;
}
-ImageTicketPtr ResourceClient::AllocateBitmapImage ( unsigned int width,
- unsigned int height,
- unsigned int bufferWidth,
- unsigned int bufferHeight,
- Pixel::Format pixelformat )
-{
- Bitmap * const bitmap = Bitmap::New(Bitmap::BITMAP_2D_PACKED_PIXELS, true); ///< Not exception safe.
- Bitmap::PackedPixelsProfile * const packedBitmap = bitmap->GetPackedPixelsProfile();
- DALI_ASSERT_DEBUG(packedBitmap);
-
- packedBitmap->ReserveBuffer(pixelformat, width, height, bufferWidth, bufferHeight);
- DALI_ASSERT_DEBUG(bitmap->GetBuffer() != 0);
- DALI_ASSERT_DEBUG(bitmap->GetBufferSize() >= width * height);
-
- ImageTicketPtr ticket = AddBitmapImage(bitmap);
-
- DALI_ASSERT_DEBUG(bitmap->GetBuffer() != 0);
- DALI_ASSERT_DEBUG(bitmap->GetBufferSize() >= width * height);
- return ticket;
-}
-
ImageTicketPtr ResourceClient::AddBitmapImage(Bitmap* bitmap)
{
DALI_ASSERT_DEBUG( bitmap != NULL );
const ResourceId newId = ++(mImpl->mNextId);
- Dali::ImageAttributes imageAttributes = Dali::ImageAttributes::New(bitmap->GetImageWidth(), bitmap->GetImageHeight(), bitmap->GetPixelFormat());
- BitmapResourceType bitmapResourceType(imageAttributes); // construct first as no copy ctor (needed to bind ref to object)
+ ImageAttributes imageAttributes = ImageAttributes::New(bitmap->GetImageWidth(), bitmap->GetImageHeight());
+ BitmapResourceType bitmapResourceType( ImageDimensions::FromFloatVec2( imageAttributes.GetSize() ) ); // construct first as no copy ctor (needed to bind ref to object)
ResourceTypePath typePath(bitmapResourceType, "");
newTicket = new ImageTicket(*this, newId, typePath);
newTicket->mAttributes = imageAttributes;
mImpl->mTickets.insert(TicketPair(newId, newTicket.Get()));
- // Store bitmap for immediate access.
- mImpl->mBitmaps[newId] = bitmap;
-
DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: AddBitmapImage() New id = %u\n", newId);
- RequestAddBitmapImageMessage( mUpdateManager.GetEventToUpdate(), mResourceManager, newId, bitmap );
+ RequestAddBitmapImageMessage( mEventThreadServices, mResourceManager, newId, bitmap );
return newTicket;
}
-ResourceTicketPtr ResourceClient::AddNativeImage ( NativeImage& resourceData )
+ResourceTicketPtr ResourceClient::AddNativeImage ( NativeImageInterface& resourceData )
{
ImageTicketPtr newTicket;
ResourceTypePath typePath(nativeImageResourceType, "");
newTicket = new ImageTicket(*this, newId, typePath);
newTicket->mAttributes = ImageAttributes::New(resourceData.GetWidth(),
- resourceData.GetHeight(),
- resourceData.GetPixelFormat());
+ resourceData.GetHeight());
newTicket->LoadingSucceeded();
mImpl->mTickets.insert(TicketPair(newId, newTicket.Get()));
DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: AddNativeImage() New id = %u\n", newId);
- RequestAddNativeImageMessage( mUpdateManager.GetEventToUpdate(), mResourceManager, newId, &resourceData );
+ RequestAddNativeImageMessage( mEventThreadServices, mResourceManager, newId, &resourceData );
return newTicket;
}
-ImageTicketPtr ResourceClient::AddFrameBufferImage ( unsigned int width, unsigned int height, Pixel::Format pixelFormat )
+ImageTicketPtr ResourceClient::AddFrameBufferImage ( unsigned int width, unsigned int height, Pixel::Format pixelFormat, RenderBuffer::Format bufferFormat )
{
ImageTicketPtr newTicket;
const ResourceId newId = ++(mImpl->mNextId);
- Dali::ImageAttributes imageAttributes = Dali::ImageAttributes::New(width, height, pixelFormat );
- RenderTargetResourceType renderTargetResourceType(imageAttributes) ; // construct first as no copy ctor (needed to bind ref to object)
+ ImageAttributes imageAttributes = ImageAttributes::New(width, height);
+ RenderTargetResourceType renderTargetResourceType( ImageDimensions( width, height ) ); // construct first as no copy ctor (needed to bind ref to object)
ResourceTypePath typePath(renderTargetResourceType, "");
newTicket = new ImageTicket(*this, newId, typePath);
newTicket->mAttributes = imageAttributes;
mImpl->mTickets.insert(TicketPair(newId, newTicket.Get()));
DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: AddFrameBufferImage() New id = %u\n", newId);
- RequestAddFrameBufferImageMessage( mUpdateManager.GetEventToUpdate(), mResourceManager, newId, width, height, pixelFormat );
+ RequestAddFrameBufferImageMessage( mEventThreadServices, mResourceManager, newId, width, height, pixelFormat, bufferFormat );
return newTicket;
}
-ImageTicketPtr ResourceClient::AddFrameBufferImage ( NativeImage& nativeImage )
+ImageTicketPtr ResourceClient::AddFrameBufferImage ( NativeImageInterface& nativeImage )
{
ImageTicketPtr newTicket;
const ResourceId newId = ++(mImpl->mNextId);
- Dali::ImageAttributes imageAttributes = Dali::ImageAttributes::New(nativeImage.GetWidth(), nativeImage.GetHeight(), nativeImage.GetPixelFormat() );
- RenderTargetResourceType renderTargetResourceType(imageAttributes); // construct first as no copy ctor (needed to bind ref to object)
+ ImageAttributes imageAttributes = ImageAttributes::New( nativeImage.GetWidth(), nativeImage.GetHeight() );
+ RenderTargetResourceType renderTargetResourceType( ImageDimensions( nativeImage.GetWidth(), nativeImage.GetHeight() ) ); // construct first as no copy ctor (needed to bind ref to object)
ResourceTypePath typePath(renderTargetResourceType, "");
newTicket = new ImageTicket(*this, newId, typePath);
newTicket->mAttributes = imageAttributes;
mImpl->mTickets.insert(TicketPair(newId, newTicket.Get()));
DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: AddFrameBufferImage() New id = %u\n", newId);
- RequestAddFrameBufferImageMessage( mUpdateManager.GetEventToUpdate(), mResourceManager, newId, &nativeImage );
+ RequestAddFrameBufferImageMessage( mEventThreadServices, mResourceManager, newId, &nativeImage );
return newTicket;
}
ImageTicketPtr newTicket;
const ResourceId newId = ++(mImpl->mNextId);
- Dali::ImageAttributes imageAttributes = Dali::ImageAttributes::New( width, height, pixelformat);
- BitmapResourceType bitmapResourceType(imageAttributes); // construct first as no copy ctor (needed to bind ref to object)
+ ImageAttributes imageAttributes = ImageAttributes::New( width, height);
+ BitmapResourceType bitmapResourceType( ImageDimensions( width, height ) ); // construct first as no copy ctor (needed to bind ref to object)
ResourceTypePath typePath(bitmapResourceType, "");
newTicket = new ImageTicket(*this, newId, typePath);
DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: AllocateTexture() New id = %u\n", newId);
- RequestAllocateTextureMessage( mUpdateManager.GetEventToUpdate(), mResourceManager, newId, width, height, pixelformat );
-
- return newTicket;
-}
-
-void ResourceClient::UpdateTexture( ResourceId id,
- BitmapUploadArray uploadArray )
-{
- RequestUpdateTextureMessage( mUpdateManager.GetEventToUpdate(), mResourceManager, id, uploadArray );
-}
-
-ResourceTicketPtr ResourceClient::AllocateMesh( OwnerPointer<MeshData>& meshData )
-{
- ResourceTicketPtr newTicket;
- const ResourceId newId = ++(mImpl->mNextId);
- MeshResourceType meshResourceType; // construct first as no copy ctor (needed to bind ref to object)
- ResourceTypePath typePath(meshResourceType, "");
- newTicket = new ResourceTicket(*this, newId, typePath);
- mImpl->mTickets.insert(TicketPair(newId, newTicket.Get()));
-
- DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: AllocateMesh() New id = %u\n", newId);
- RequestAllocateMeshMessage( mUpdateManager.GetEventToUpdate(), mResourceManager, newId, meshData );
+ RequestAllocateTextureMessage( mEventThreadServices, mResourceManager, newId, width, height, pixelformat );
return newTicket;
}
{
DALI_ASSERT_DEBUG( ticket );
- RequestUpdateBitmapAreaMessage( mUpdateManager.GetEventToUpdate(), mResourceManager, ticket->GetId(), updateArea );
+ RequestUpdateBitmapAreaMessage( mEventThreadServices, mResourceManager, ticket->GetId(), updateArea );
}
-void ResourceClient::UpdateMesh( ResourceTicketPtr ticket, const Dali::MeshData& meshData )
+void ResourceClient::UploadBitmap( ResourceId destId, ResourceId srcId, std::size_t xOffset, std::size_t yOffset )
{
- DALI_ASSERT_DEBUG( ticket );
-
- RequestUpdateMeshMessage( mUpdateManager.GetEventToUpdate(),
- mResourceManager,
- ticket->GetId(),
- meshData );
+ RequestUploadBitmapMessage( mEventThreadServices,
+ mResourceManager,
+ destId,
+ srcId,
+ xOffset,
+ yOffset );
}
-Bitmap* ResourceClient::GetBitmap(ResourceTicketPtr ticket)
-{
- DALI_ASSERT_DEBUG( ticket );
-
- Bitmap* bitmap = NULL;
- BitmapCacheIter iter = mImpl->mBitmaps.find(ticket->GetId());
- if( iter != mImpl->mBitmaps.end() )
- {
- bitmap = iter->second;
- }
- return bitmap;
+void ResourceClient::UploadBitmap( ResourceId destId,Integration::BitmapPtr bitmap, std::size_t xOffset, std::size_t yOffset)
+{
+ RequestUploadBitmapMessage( mEventThreadServices,
+ mResourceManager,
+ destId,
+ bitmap,
+ xOffset,
+ yOffset );
}
-void ResourceClient::SetGlyphLoadObserver( GlyphLoadObserver* glyphLoadedInterface )
+void ResourceClient::UploadBitmap( ResourceId destId, PixelDataPtr pixelData, std::size_t xOffset, std::size_t yOffset)
{
- mImpl->mGlyphLoadObserver = glyphLoadedInterface;
+ RequestUploadBitmapMessage( mEventThreadServices,
+ mResourceManager,
+ destId,
+ pixelData,
+ xOffset,
+ yOffset );
}
-void ResourceClient::UpdateAtlasStatus( ResourceId id, ResourceId atlasId, Integration::LoadStatus loadStatus )
+void ResourceClient::CreateGlTexture( ResourceId id )
{
- RequestAtlasUpdateMessage( mUpdateManager.GetEventToUpdate(), mResourceManager, id, atlasId, loadStatus );
+ RequestCreateGlTextureMessage( mEventThreadServices, mResourceManager, id );
}
+
/********************************************************************************
******************** ResourceTicketLifetimeObserver methods ****************
********************************************************************************/
const ResourceId deadId = ticket.GetId();
const ResourceTypePath& typePath = ticket.GetTypePath();
- // Ensure associated event owned resources are also removed
- mImpl->mBitmaps.erase(ticket.GetId());
-
// The ticket object is dead, remove from tickets container
TicketContainerSize erased = mImpl->mTickets.erase(deadId);
DALI_ASSERT_DEBUG(erased != 0);
(void)erased; // Avoid "unused variable erased" in release builds
DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: ResourceTicketDiscarded() deadId = %u\n", deadId);
- RequestDiscardResourceMessage( mUpdateManager.GetEventToUpdate(), mResourceManager, deadId, typePath.type->id );
+ RequestDiscardResourceMessage( mEventThreadServices, mResourceManager, deadId, typePath.type->id );
}
/********************************************************************************
}
}
-void ResourceClient::NotifySaveRequested( ResourceId id )
-{
- DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: NotifySaveRequested(id:%u)\n", id);
-
- TicketContainerIter ticketIter = mImpl->mTickets.find(id);
- if(ticketIter != mImpl->mTickets.end())
- {
- ResourceTicket* ticket = ticketIter->second;
- SaveResource( ticket, "" );
- }
-}
-
-
void ResourceClient::NotifyLoading( ResourceId id )
{
DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: NotifyLoading(id:%u)\n", id);
}
}
-void ResourceClient::NotifySavingSucceeded( ResourceId id )
-{
- DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: NotifySavingSucceeded(id:%u)\n", id);
-
- TicketContainerIter ticketIter = mImpl->mTickets.find(id);
- if(ticketIter != mImpl->mTickets.end())
- {
- ResourceTicket* ticket = ticketIter->second;
- ticket->SavingSucceeded();
- }
-}
-
-void ResourceClient::NotifySavingFailed( ResourceId id )
-{
- DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: NotifySavingFailed(id:%u)\n", id);
-
- TicketContainerIter ticketIter = mImpl->mTickets.find(id);
- if(ticketIter != mImpl->mTickets.end())
- {
- ResourceTicket* ticket = ticketIter->second;
- ticket->SavingFailed();
- }
-}
-
-void ResourceClient::NotifyGlyphSetLoaded( ResourceId id, const GlyphSet& glyphSet, LoadStatus loadStatus )
-{
- if( mImpl->mGlyphLoadObserver == NULL)
- {
- // should not happen.
- DALI_ASSERT_DEBUG( !"GlyphLoadObserver == NULL ");
- return;
- }
-
- DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: NotifyGlyphSetLoaded(hash:%u)\n", glyphSet.mFontHash);
-
- mImpl->mGlyphLoadObserver->GlyphsLoaded( id, glyphSet, loadStatus );
-}
-
-void ResourceClient::UpdateImageTicket( ResourceId id, const Dali::ImageAttributes& imageAttributes ) ///!< Issue #AHC01
+void ResourceClient::UpdateImageTicket( ResourceId id, const ImageAttributes& imageAttributes ) ///!< Issue #AHC01
{
DALI_LOG_INFO(Debug::Filter::gResource, Debug::General, "ResourceClient: UpdateImageTicket(id:%u)\n", id);