oss += "<Animations running> ";
}
- if ( keepUpdatingStatus & Integration::KeepUpdating::LOADING_RESOURCES )
- {
- oss += "<Resources loading> ";
- }
-
if ( keepUpdatingStatus & Integration::KeepUpdating::MONITORING_PERFORMANCE )
{
oss += "<Monitoring performance> ";
}
else
{
- Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
- styleMonitor = Dali::StyleMonitor( new StyleMonitor( adaptorImpl.GetPlatformAbstraction() ) );
+ styleMonitor = Dali::StyleMonitor( new StyleMonitor() );
service.Register( typeid( styleMonitor ), styleMonitor );
}
}
return styleMonitor;
}
-StyleMonitor::StyleMonitor(Integration::PlatformAbstraction& platformAbstraction)
-: mPlatformAbstraction(platformAbstraction),
- mDefaultFontSize(-1)
+StyleMonitor::StyleMonitor()
+: mDefaultFontSize(-1)
{
mFontClient = TextAbstraction::FontClient::Get();
GetSystemDefaultFontFamily( mFontClient, mDefaultFontFamily );
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "StyleMonitor::StyleMonitor::DefaultFontFamily(%s)\n", mDefaultFontFamily.c_str() );
- mDefaultFontSize = mPlatformAbstraction.GetDefaultFontSize();
+ mDefaultFontSize = mFontClient.GetDefaultFontSize();
}
StyleMonitor::~StyleMonitor()
case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
{
- mDefaultFontSize = mPlatformAbstraction.GetDefaultFontSize();
+ mDefaultFontSize = mFontClient.GetDefaultFontSize();
break;
}
// EXTERNAL INCLUDES
#include <dali/public-api/object/ref-object.h>
#include <dali/public-api/object/base-object.h>
-#include <dali/integration-api/platform-abstraction.h>
#include <dali/devel-api/text-abstraction/font-client.h>
// INTERNAL INCLUDES
/**
* Constructor.
- * @param[in] platformAbstraction The platform abstraction.
*/
- StyleMonitor(Integration::PlatformAbstraction& platformAbstraction);
+ StyleMonitor();
/**
* Retrieve the initialized instance of the StyleMonitor.
Dali::StyleMonitor::StyleChangeSignalType mStyleChangeSignal; ///< Emitted when the style changes
- Integration::PlatformAbstraction& mPlatformAbstraction; ///< Reference to the PlatformAbstraction (for retrieving defaults)
-
TextAbstraction::FontClient mFontClient;
std::string mDefaultFontFamily; ///< The system default font family
std::string mDefaultFontStyle; ///< The default font style
TestPlatformAbstraction::TestPlatformAbstraction()
: mTrace(),
mIsLoadingResult( false ),
- mGetDefaultFontSizeResult( 0 ),
- mLoadedResourcesQueue(),
- mFailedLoadQueue(),
- mResourceRequests(),
mSize(),
mClosestSize(),
mLoadFileResult(),
TestPlatformAbstraction::~TestPlatformAbstraction()
{
- DiscardRequest();
-}
-
-void TestPlatformAbstraction::Suspend()
-{
- mTrace.PushCall("Suspend", "");
-}
-
-void TestPlatformAbstraction::Resume()
-{
- mTrace.PushCall("Resume", "");
}
ImageDimensions TestPlatformAbstraction::GetClosestImageSize( const std::string& filename,
return closestSize;
}
-void TestPlatformAbstraction::LoadResource(const Integration::ResourceRequest& request)
-{
- std::ostringstream out;
- out << "Type:" << request.GetType()->id << ", Path: " << request.GetPath() << std::endl ;
-
- mTrace.PushCall("LoadResource", out.str());
-
- mResourceRequests.PushBack( new Integration::ResourceRequest(request) );
-}
-
Integration::ResourcePointer TestPlatformAbstraction::LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath )
{
mTrace.PushCall("LoadResourceSynchronously", "");
return mDecodedBitmap;
}
-void TestPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
-{
- mTrace.PushCall("CancelLoad", "");
-}
-
-void TestPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
-{
- mTrace.PushCall("GetResources", "");
-
- while( !mLoadedResourcesQueue.empty() )
- {
- LoadedResource loaded( *mLoadedResourcesQueue.begin() );
- mLoadedResourcesQueue.erase( mLoadedResourcesQueue.begin() );
- cache.LoadResponse( loaded.id, loaded.type, loaded.resource, Integration::RESOURCE_COMPLETELY_LOADED );
- }
-
- // iterate through the resources which failed to load
- while( !mFailedLoadQueue.empty() )
- {
- FailedLoad failed( *mFailedLoadQueue.begin() );
- mFailedLoadQueue.erase( mFailedLoadQueue.begin() );
- cache.LoadFailed( failed.id, failed.failure );
- }
-}
-
-bool TestPlatformAbstraction::IsLoading()
-{
- mTrace.PushCall("IsLoading", "");
- return mIsLoadingResult;
-}
-
-int TestPlatformAbstraction::GetDefaultFontSize() const
-{
- mTrace.PushCall("GetDefaultFontSize", "");
- return mGetDefaultFontSizeResult;
-}
-
-void TestPlatformAbstraction::SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical)
-{
- mTrace.PushCall("SetDpi", "");
-}
-
-bool TestPlatformAbstraction::LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
-{
- mTrace.PushCall("LoadFile", "");
- if( mLoadFileResult.loadResult )
- {
- buffer = mLoadFileResult.buffer;
- }
-
- return mLoadFileResult.loadResult;
-}
-
bool TestPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
{
mTrace.PushCall("LoadShaderBinaryFile", "");
return mLoadFileResult.loadResult;
}
-bool TestPlatformAbstraction::SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const
-{
- mTrace.PushCall("SaveFile", "");
- return false;
-}
-
-void TestPlatformAbstraction::JoinLoaderThreads()
-{
- mTrace.PushCall("JoinLoaderThreads", "");
-}
/** Call this every test */
void TestPlatformAbstraction::Initialize()
{
mTrace.Reset();
mTrace.Enable(true);
- mLoadedResourcesQueue.clear();
- mFailedLoadQueue.clear();
- mResourceRequests.Clear();
mIsLoadingResult=false;
mSynchronouslyLoadedResource.Reset();
mDecodedBitmap.Reset();
{
switch(func)
{
- case SuspendFunc: return mTrace.FindMethod("Suspend");
- case ResumeFunc: return mTrace.FindMethod("Resume");
- case LoadResourceFunc: return mTrace.FindMethod("LoadResource");
case LoadResourceSynchronouslyFunc: return mTrace.FindMethod("LoadResourceSynchronously");
- case LoadFileFunc: return mTrace.FindMethod("LoadFile");
case LoadShaderBinaryFileFunc: return mTrace.FindMethod("LoadShaderBinaryFile");
case SaveShaderBinaryFileFunc: return mTrace.FindMethod("SaveShaderBinaryFile");
- case SaveFileFunc: return mTrace.FindMethod("SaveFile");
- case CancelLoadFunc: return mTrace.FindMethod("CancelLoad");
- case GetResourcesFunc: return mTrace.FindMethod("GetResources");
- case IsLoadingFunc: return mTrace.FindMethod("IsLoading");
- case SetDpiFunc: return mTrace.FindMethod("SetDpi");
- case JoinLoaderThreadsFunc: return mTrace.FindMethod("JoinLoaderThreads");
}
return false;
}
void TestPlatformAbstraction::ClearReadyResources()
{
- mLoadedResourcesQueue.clear();
- mFailedLoadQueue.clear();
mSynchronouslyLoadedResource.Reset();
mDecodedBitmap.Reset();
}
-void TestPlatformAbstraction::SetResourceLoaded(Integration::ResourceId loadedId,
- Integration::ResourceTypeId loadedType,
- Integration::ResourcePointer loadedResource)
-{
- LoadedResource loadedInfo;
- loadedInfo.id = loadedId;
- loadedInfo.type = loadedType;
- loadedInfo.resource = loadedResource;
- mLoadedResourcesQueue.push_back( loadedInfo );
-}
-
-void TestPlatformAbstraction::SetResourceLoadFailed(Integration::ResourceId id,
- Integration::ResourceFailure failure)
-{
- FailedLoad failedInfo;
- failedInfo.id = id;
- failedInfo.failure = failure;
- mFailedLoadQueue.push_back( failedInfo );
-}
-
-Integration::ResourceRequest* TestPlatformAbstraction::GetRequest()
-{
- Integration::ResourceRequest* request = NULL;
-
- // Return last request
- if( ! mResourceRequests.Empty() )
- {
- request = *( mResourceRequests.End() - 1 );
- }
-
- return request;
-}
-
-const TestPlatformAbstraction::ResourceRequestContainer& TestPlatformAbstraction::GetAllRequests() const
-{
- return mResourceRequests;
-}
-
-void TestPlatformAbstraction::SetAllResourceRequestsAsLoaded()
-{
- for( ResourceRequestContainer::Iterator iter = mResourceRequests.Begin(), endIter = mResourceRequests.End();
- iter != endIter; ++iter )
- {
- Integration::ResourceRequest* request = *iter;
- Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
- Integration::ResourcePointer resource(bitmap);
- bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
- SetResourceLoaded( request->GetId(), request->GetType()->id, resource );
- delete request;
- }
- mResourceRequests.Clear();
-}
-
-void TestPlatformAbstraction::SetAllResourceRequestsAsFailed( Integration::ResourceFailure failure )
-{
- for( ResourceRequestContainer::Iterator iter = mResourceRequests.Begin(), endIter = mResourceRequests.End();
- iter != endIter; ++iter )
- {
- Integration::ResourceRequest* request = *iter;
- SetResourceLoadFailed( (*iter)->GetId(), failure);
- delete request;
- }
- mResourceRequests.Clear();
-}
-
-void TestPlatformAbstraction::DiscardRequest()
-{
- for( ResourceRequestContainer::Iterator iter = mResourceRequests.Begin(), endIter = mResourceRequests.End();
- iter != endIter; ++iter )
- {
- Integration::ResourceRequest* request = *iter;
- delete request;
- }
- mResourceRequests.Clear();
-}
-
void TestPlatformAbstraction::SetClosestImageSize(const Vector2& size)
{
mClosestSize = size;
public:
- typedef Vector< Integration::ResourceRequest* > ResourceRequestContainer;
-
/**
* Constructor
*/
*/
virtual ~TestPlatformAbstraction();
- /**
- * @copydoc PlatformAbstraction::Suspend()
- */
- virtual void Suspend();
-
- /**
- * @copydoc PlatformAbstraction::Resume()
- */
- virtual void Resume();
-
/**
* @copydoc PlatformAbstraction::GetClosestImageSize()
*/
SamplingMode::Type samplingMode,
bool orientationCorrection );
- /**
- * @copydoc PlatformAbstraction::LoadResource()
- */
- virtual void LoadResource(const Integration::ResourceRequest& request);
-
/**
* @copydoc PlatformAbstraction::LoadResourceSynchronously()
*/
*/
virtual Integration::BitmapPtr DecodeBuffer( const Dali::Integration::ResourceType& resourceType, uint8_t * buffer, size_t size );
- /**
- * @copydoc PlatformAbstraction::CancelLoad()
- */
- virtual void CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId);
-
- /**
- * @copydoc PlatformAbstraction::GetResources()
- */
- virtual void GetResources(Integration::ResourceCache& cache);
-
- /**
- * @copydoc PlatformAbstraction::IsLoading()
- */
- virtual bool IsLoading();
-
- /**
- * @copydoc PlatformAbstraction::GetDefaultFontSize()
- */
- virtual int GetDefaultFontSize() const;
-
- /**
- * @copydoc PlatformAbstraction::SetDpi()
- */
- virtual void SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical);
-
- /**
- * @copydoc PlatformAbstraction::LoadFile()
- */
- virtual bool LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
-
/**
* @copydoc PlatformAbstraction::LoadShaderBinaryFile()
*/
virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
/**
- * @copydoc PlatformAbstraction::SaveFile()
+ * @copydoc PlatformAbstraction::SaveShaderBinaryFile()
*/
- virtual bool SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const;
-
- /**
- * @copydoc PlatformAbstraction::SaveShaderBinaryFile()
- */
virtual bool SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const { return true; }
- virtual void JoinLoaderThreads();
public: // TEST FUNCTIONS
// Enumeration of Platform Abstraction methods
typedef enum
{
- SuspendFunc,
- ResumeFunc,
- LoadResourceFunc,
LoadResourceSynchronouslyFunc,
- SaveFileFunc,
- LoadFileFunc,
LoadShaderBinaryFileFunc,
- SaveShaderBinaryFileFunc,
- CancelLoadFunc,
- GetResourcesFunc,
- IsLoadingFunc,
- SetDpiFunc,
- JoinLoaderThreadsFunc,
+ SaveShaderBinaryFileFunc
} TestFuncEnum;
/** Call this every test */
*/
void SetIsLoadingResult(bool result);
- /**
- * @brief Sets the value returned by GetDefaultFontSize
- * @param[in] result The value to return
- */
- void SetGetDefaultFontSizeResult(float result);
-
/**
* @brief Clears all resource queues
*/
void ClearReadyResources();
- /**
- * @brief Sets a particular resource request as loaded.
- * @param[in] loadedId The ResourceID of the resource that has been loaded.
- * @param[in] loadedType The type of resource that has been loaded.
- * @param[in] loadedResource A pointer to the resource that has been loaded.
- */
- void SetResourceLoaded(Integration::ResourceId loadedId,
- Integration::ResourceTypeId loadedType,
- Integration::ResourcePointer loadedResource);
-
- /**
- * @brief Sets a particular resource request as load failure.
- * @param[in] id The ID of the failed resource request.
- * @param[in] failure The type of failure.
- */
- void SetResourceLoadFailed(Integration::ResourceId id,
- Integration::ResourceFailure failure);
-
- /**
- * @brief Retrieves the latest resource request
- * @return A pointer to the latest resource request.
- */
- Integration::ResourceRequest* GetRequest();
-
- /**
- * @brief Retrieves a reference to a container of all the resource requests.
- * @return A reference to a container of all the resource requests.
- */
- const ResourceRequestContainer& GetAllRequests() const;
-
- /**
- * @brief Sets all resource requests as loaded.
- */
- void SetAllResourceRequestsAsLoaded();
-
- /**
- * @brief Sets all resource requests as loaded.
- * @param[in] failure The failure type
- */
- void SetAllResourceRequestsAsFailed( Integration::ResourceFailure failure );
-
- /**
- * @brief Discards all current resource requests.
- */
- void DiscardRequest();
-
/**
* @brief Sets the value returned by GetClosestImageSize.
* @param[in] size The size that should be returned.
private:
- struct LoadedResource
- {
- Integration::ResourceId id;
- Integration::ResourceTypeId type;
- Integration::ResourcePointer resource;
- };
-
- struct FailedLoad
- {
- Integration::ResourceId id;
- Integration::ResourceFailure failure;
- };
-
struct LoadFileResult
{
inline LoadFileResult()
Dali::Vector< unsigned char> buffer;
};
- typedef std::vector< LoadedResource > LoadedResourceContainer;
- typedef std::vector< FailedLoad > FailedLoadContainer;
-
mutable TraceCallStack mTrace;
bool mIsLoadingResult;
- int mGetDefaultFontSizeResult;
- LoadedResourceContainer mLoadedResourcesQueue;
- FailedLoadContainer mFailedLoadQueue;
- ResourceRequestContainer mResourceRequests;
Vector2 mSize;
Vector2 mClosestSize;
SET(TC_SOURCES
utc-image-fitting-modes.cpp
- utc-image-loading-cancel-all-loads.cpp
- utc-image-loading-cancel-some-loads.cpp
- utc-image-loading-load-completion.cpp
)
LIST(APPEND TC_SOURCES
- resource-collector.cpp
../dali-adaptor/dali-test-suite-utils/mesh-builder.cpp
../dali-adaptor/dali-test-suite-utils/dali-test-suite-utils.cpp
../dali-adaptor/dali-test-suite-utils/test-actor-utils.cpp
+++ /dev/null
-/*
- * 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.
- *
- */
-
-#include "resource-collector.h"
-#include "tizen-platform-abstraction.h"
-#include <dali/integration-api/debug.h>
-#include <unistd.h>
-
-namespace Dali
-{
-namespace Internal
-{
-namespace Platform
-{
-using namespace Dali::Integration;
-
-ResourceCollector::ResourceCollector() :
- mGrandTotalCompletions(0),
- mGrandTotalNotifications(0)
-{
-}
-
-ResourceCollector::~ResourceCollector() {}
-
-void ResourceCollector::LoadResponse( Dali::Integration::ResourceId id, Dali::Integration::ResourceTypeId type, Dali::Integration::ResourcePointer resource, Dali::Integration::LoadStatus status )
-{
- ++mGrandTotalNotifications;
- if( status == RESOURCE_COMPLETELY_LOADED )
- {
- DALI_ASSERT_DEBUG( mCompletionCounts.find(id) == mCompletionCounts.end() && "A resource can only complete once." );
- mCompletionStatuses[id] = true;
- ++mCompletionCounts[id];
- ++mSuccessCounts[id];
- mCompletionSequence.push_back( id );
- ++mGrandTotalCompletions;
- }
-}
-
-void ResourceCollector::LoadFailed( Dali::Integration::ResourceId id, Dali::Integration::ResourceFailure failure )
-{
- mCompletionStatuses[id] = false;
- ++mFailureCounts[id];
- mCompletionSequence.push_back( id );
- ++mGrandTotalCompletions;
- ++mGrandTotalNotifications;
-}
-
-void PollForNotification( ResourceCollector& collector, Integration::PlatformAbstraction& abstraction, const unsigned maxPolls )
-{
- // Poll for at least one completed or partially completed load:
- const unsigned outstandingNotifications = collector.mGrandTotalNotifications;
- for( unsigned poll = 0; poll < maxPolls; ++poll )
- {
- abstraction.GetResources( collector );
- if( collector.mGrandTotalNotifications > outstandingNotifications )
- {
- break;
- }
- usleep( 3 ); //< Wait 3 microseconds each time around.
- }
-}
-
-} /* namespace Platform */
-} /* namespace Internal */
-} /* namespace Dali */
+++ /dev/null
-#ifndef __DALI_ADAPTOR_TCT_RESOURCE_COLLECTOR_H_
-#define __DALI_ADAPTOR_TCT_RESOURCE_COLLECTOR_H_
-/*
- * 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.
- *
- */
-#include <dali/dali.h>
-#include <dali/integration-api/resource-cache.h>
-
-#include <map>
-
-namespace Dali
-{
-
-namespace Integration
-{
-class PlatformAbstraction;
-}
-
-namespace Internal
-{
-namespace Platform
-{
- /** Stores true for success and false for a failure for each completed
- * resource id.*/
- typedef std::map<Integration::ResourceId, bool> ResourceStatusMap;
- /** Stores an integer counter for a resource ID, e.g., to count the number of
- * times a load or a fail is reported.*/
- typedef std::map<Integration::ResourceId, unsigned> ResourceCounterMap;
- /** Used to track the order in which a sequence of requests is completed.*/
- typedef std::vector<Integration::ResourceId> ResourceSequence;
-
-/**
- * @brief Used for platform testing to record the result of resource requests
- * initiated by tests.
- */
-class ResourceCollector : public Integration::ResourceCache
-{
-public:
-
- ResourceCollector();
- virtual ~ResourceCollector();
-
- virtual void LoadResponse(Dali::Integration::ResourceId id, Dali::Integration::ResourceTypeId type, Dali::Integration::ResourcePointer resource, Dali::Integration::LoadStatus status);
-
- virtual void LoadFailed(Dali::Integration::ResourceId id, Dali::Integration::ResourceFailure failure);
-
- // Data:
- /** Record of the status of each completed resource. */
- ResourceStatusMap mCompletionStatuses;
- /** Record of how many times each resource completed (every value should be 1,
- * else we are broken). */
- ResourceCounterMap mCompletionCounts;
- /** Record of how many times each resource succeeded (every value should be 0 or
- * 1, else we are broken). */
- ResourceCounterMap mSuccessCounts;
- /** Record of how many times each resource failed (every value should be 0 or 1,
- * else we are broken).
- * Only resource IDs that correspond to deliberately unloadable resources
- * should have counts other than 0. */
- ResourceCounterMap mFailureCounts;
- /** Remember the order of request completions so request priority can be tested. */
- ResourceSequence mCompletionSequence;
- /** Count of all successes and failures.*/
- unsigned mGrandTotalCompletions;
- /** Count of all successes, failures, loading notifications and partially loaded notifications.*/
- unsigned mGrandTotalNotifications;
-
-};
-
-/**
- * Helper to poll the abstraction for notifications assuming loads have been
- * issued to it previously and are in-flight.
- */
-void PollForNotification( ResourceCollector& collector, Integration::PlatformAbstraction& abstraction, const unsigned maxPolls = 100 );
-
-} /* namespace Platform */
-} /* namespace Internal */
-} /* namespace Dali */
-
-#endif /* __DALI_ADAPTOR_TCT_RESOURCE_COLLECTOR_H_ */
#include "platform-abstractions/portable/image-operations.h"
+using Dali::Internal::Platform::ApplyAttributesToBitmap;
+
#define ANSI_BLACK "\x1B[0m"
#define ANSI_RED "\x1B[31m"
#define ANSI_GREEN "\x1B[32m"
+++ /dev/null
-/*
- * 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.
- *
- */
-
-#include "utc-image-loading-common.h"
-
-void utc_image_loading_cancel_all_loads_startup(void)
-{
- utc_dali_loading_startup();
-}
-
-void utc_image_loading_cancel_all_loads_cleanup(void)
-{
- utc_dali_loading_cleanup();
-}
-
-/**
- * @brief Test case for load cancellation.
- *
- * Load lots of images in batches, cancelling all in a batch after a small delay to
- * allow the first of a batch to be launched before cancellation starts.
- * Assert that all loads issued are either completed or cancelled.
- *
- * @note Many loads will succeed despite our cancellations due to the coarse
- * granularity of the waits we introduce after loading each batch. That is
- * expected.
- */
-int UtcDaliCancelAllLoads(void)
-{
- tet_printf( "Running load cancel-all test.\n" );
-
- DALI_ASSERT_ALWAYS( gAbstraction != 0 );
-
- // Start a bunch of loads that should work:
-
- Dali::Integration::LoadResourcePriority priority = LoadPriorityNormal;
- unsigned loadsLaunched = 0;
- Dali::Internal::Platform::ResourceCollector resourceSink;
-
- for( unsigned loadGroup = 0; loadGroup < NUM_CANCELLED_LOAD_GROUPS_TO_ISSUE; ++loadGroup )
- {
- // Issue load requests for a batch of images:
- for( unsigned validImage = 0; validImage < NUM_VALID_IMAGES; ++validImage )
- {
- const ImageParameters & loadParams = gCancelAttributes[ loadsLaunched % gCancelAttributes.size() ];
- const BitmapResourceType bitmapResourceType( loadParams.first, loadParams.second.first, loadParams.second.second.first, loadParams.second.second.second );
- const ResourceId resourceId = loadGroup * NUM_VALID_IMAGES + validImage + 1;
- gAbstraction->LoadResource( ResourceRequest( resourceId, bitmapResourceType, VALID_IMAGES[validImage], priority ) );
- loadsLaunched += 1;
- }
-
- // Poll for at least one completed load so we have a good chance of catching an
- // in-flight load as we run through the cancellations further below:
- PollForNotification( resourceSink, *gAbstraction, 100 );
-
- // Cancel all the launched loads in the batch from oldest to newest:
- for( unsigned validImage = 0; validImage < NUM_VALID_IMAGES; ++validImage )
- {
- const ResourceId resourceId = loadGroup * NUM_VALID_IMAGES + validImage + 1;
- gAbstraction->CancelLoad( resourceId, ResourceBitmap );
- }
- }
-
- // Drain the completed loads:
-
- unsigned lastNotifications = -1;
- for( unsigned i = 0; resourceSink.mGrandTotalCompletions < loadsLaunched && resourceSink.mGrandTotalNotifications != lastNotifications; )
- {
- lastNotifications = resourceSink.mGrandTotalNotifications;
- gAbstraction->GetResources( resourceSink );
-
- ++i;
- if( i < MAX_NUM_RESOURCE_TRIES && resourceSink.mGrandTotalCompletions < loadsLaunched )
- {
- usleep( 1000 * 10 );
- }
- else
- {
- break;
- }
- }
-
- // Check the loads completed as expected:
-
- tet_printf( "Issued Loads: %u, Completed Loads: %u, Successful Loads: %u, Failed Loads: %u \n", loadsLaunched, resourceSink.mGrandTotalCompletions, unsigned(resourceSink.mSuccessCounts.size()), unsigned(resourceSink.mFailureCounts.size()) );
- DALI_TEST_CHECK( loadsLaunched > resourceSink.mGrandTotalCompletions );
- DALI_TEST_CHECK( loadsLaunched > resourceSink.mSuccessCounts.size() );
- DALI_TEST_CHECK( 0 == resourceSink.mFailureCounts.size() );
-
- // Check that each success was reported exactly once:
- for( ResourceCounterMap::const_iterator it = resourceSink.mSuccessCounts.begin(), end = resourceSink.mSuccessCounts.end(); it != end; ++it )
- {
- DALI_TEST_CHECK( it->second == 1u );
- }
-
- END_TEST;
-}
+++ /dev/null
-/*
- * 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.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <set>
-
-// INTERNAL INCLUDES
-#include "utc-image-loading-common.h"
-
-void utc_image_loading_cancel_some_loads_startup(void)
-{
- utc_dali_loading_startup();
-}
-
-void utc_image_loading_cancel_some_loads_cleanup(void)
-{
- utc_dali_loading_cleanup();
-}
-
-/**
- * @brief Test case for load cancellation.
- *
- * Load lots, cancel a subset and be sure the wrong loads are never cancelled
- * and that all loads issued are either completed or cancelled.
- */
-int UtcDaliCancelSomeLoads(void)
-{
- tet_printf( "Running load cancel load subset test.\n" );
-
- DALI_ASSERT_ALWAYS( gAbstraction != 0 );
-
- // Start a bunch of loads that should work:
-
- Dali::Integration::LoadResourcePriority priority = LoadPriorityNormal;
- unsigned loadsLaunched = 0;
-
- std::set<Integration::ResourceId> cancelledLoadSet;
- Dali::Internal::Platform::ResourceCollector resourceSink;
-
- for( unsigned loadGroup = 0; loadGroup < NUM_LOAD_GROUPS_TO_ISSUE; ++loadGroup )
- {
- const unsigned preIterationCompletions = resourceSink.mGrandTotalCompletions;
-
- // Issue load requests for a batch of images:
- for( unsigned validImage = 0; validImage < NUM_VALID_IMAGES; ++validImage )
- {
- const ImageParameters & loadParams = gCancelAttributes[ loadsLaunched % gCancelAttributes.size() ];
- const BitmapResourceType bitmapResourceType( loadParams.first, loadParams.second.first, loadParams.second.second.first, loadParams.second.second.second );
- const ResourceId resourceId = loadGroup * NUM_VALID_IMAGES + validImage + 1;
- gAbstraction->LoadResource( ResourceRequest( resourceId, bitmapResourceType, VALID_IMAGES[validImage], priority ) );
- loadsLaunched += 1;
- }
-
- // Let the first image in the batch start to load so we can try to cancel it in-flight:
- usleep( 1 * 1000 ); //< 1 ms is enough to let an image start to load.
- ///@Note: The log should show cancellations of many in-flight loads in desktop builds with info-level logging enabled (e.g., "INFO: DALI: : CheckForCancellation: Cancelled in-flight resource (21)."). If it doesn't, the above delay may need to be adjusted.
-
- // Cancel just two loads (hopefully one in-flight and one queued):
-
- // Cancel first load, hopefully while it is in-flight:
- const ResourceId cancelledInFlight = loadGroup * NUM_VALID_IMAGES + 1;
- gAbstraction->CancelLoad( cancelledInFlight, ResourceBitmap );
- cancelledLoadSet.insert( cancelledInFlight );
-
- // Cancel second load, that is still queued:
- const ResourceId cancelledFromQueue = loadGroup * NUM_VALID_IMAGES + NUM_VALID_IMAGES;
- gAbstraction->CancelLoad( cancelledFromQueue, ResourceBitmap );
- cancelledLoadSet.insert( cancelledFromQueue );
-
- // Drain a group worth of images so the cancellations hit in-flight loads on the next iteration:
- for( unsigned i = 0; i < NUM_VALID_IMAGES * 1000 * 1000 * 10 / (5 * 1000) && resourceSink.mGrandTotalCompletions < preIterationCompletions + NUM_VALID_IMAGES - 2; ++i )
- {
- gAbstraction->GetResources( resourceSink );
- usleep( 5 * 1000 );
- }
- }
-
- // Drain any spare completed loads until no new loads complete on an iteration:
- unsigned lastNotifications = -1;
- for( unsigned i = 0; i < MAX_NUM_RESOURCE_TRIES && resourceSink.mGrandTotalCompletions < loadsLaunched && resourceSink.mGrandTotalNotifications != lastNotifications; ++i )
- {
- lastNotifications = resourceSink.mGrandTotalNotifications;
- gAbstraction->GetResources( resourceSink );
- usleep( 70 * 1000 ); //< 70 ms should allow at least one medium image to load. You might to increase this to run on a slow device.
- gAbstraction->GetResources( resourceSink );
- usleep( 70 * 1000 );
- gAbstraction->GetResources( resourceSink );
- usleep( 70 * 1000 );
- gAbstraction->GetResources( resourceSink );
- }
-
- // Check the loads completed as expected:
-
- tet_printf( "Issued Loads: %u, Completed Loads: %u, Successful Loads: %u, Failed Loads: %u \n", loadsLaunched, resourceSink.mGrandTotalCompletions, unsigned(resourceSink.mSuccessCounts.size()), unsigned(resourceSink.mFailureCounts.size()) );
- DALI_TEST_CHECK( loadsLaunched >= resourceSink.mGrandTotalCompletions );
- DALI_TEST_CHECK( loadsLaunched >= resourceSink.mSuccessCounts.size() );
- DALI_TEST_CHECK( 0 == resourceSink.mFailureCounts.size() );
-
- // Check that if an image was not loaded, it is one of the ones that was cancelled:
- // This is the main point of this test case.
- std::vector<Integration::ResourceId> missingLoads;
- for( unsigned resourceId = 1; resourceId <= NUM_LOAD_GROUPS_TO_ISSUE * NUM_VALID_IMAGES; ++resourceId )
- {
- // Was the load (not) completed?
- if( resourceSink.mCompletionStatuses.find( resourceId ) == resourceSink.mCompletionStatuses.end() )
- {
- // Was the load (not) cancelled?
- if( cancelledLoadSet.find( resourceId ) == cancelledLoadSet.end() )
- {
- // Whoa, the load was not completed and not cancelled either... so where did it go then?
- missingLoads.push_back( resourceId );
- tet_printf( "Missing load. ResourceId %u was not completed but was also not cancelled.\n", resourceId );
- ///@note If this fires, you are probably not waiting long enough in the draining loop above (usleep( 70 * 1000 );).
- }
- }
- }
- DALI_TEST_CHECK( missingLoads.size() == 0U );
-
- // Check that each success was reported exactly once:
- for(ResourceCounterMap::const_iterator it = resourceSink.mSuccessCounts.begin(), end = resourceSink.mSuccessCounts.end(); it != end; ++it )
- {
- DALI_TEST_CHECK( it->second == 1u );
- }
-
- END_TEST;
-}
#include <dali/dali.h>
#include <dali-test-suite-utils.h>
#include "tizen-platform-abstraction.h"
-#include "resource-collector.h"
using namespace Dali;
using namespace Dali::Integration;
-using namespace Dali::Internal::Platform;
namespace
{
+++ /dev/null
-/*
- * 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.
- *
- */
-
-#include "utc-image-loading-common.h"
-
-void utc_image_loading_load_completion_startup(void)
-{
- utc_dali_loading_startup();
-}
-
-void utc_image_loading_load_completion_cleanup(void)
-{
- utc_dali_loading_cleanup();
-}
-
-// Positive test case for loading. Load lots and be sure it has succeeded.
-int UtcDaliLoadCompletion(void)
-{
- tet_printf("Running load completion test \n");
-
- DALI_ASSERT_ALWAYS( gAbstraction != 0 );
-
- // Start a bunch of loads that should work:
-
- Dali::Integration::BitmapResourceType bitmapResourceType;
- Dali::Integration::LoadResourcePriority priority = Dali::Integration::LoadPriorityNormal;
- unsigned loadsLaunched = 0;
-
- for( unsigned loadGroup = 0; loadGroup < NUM_LOAD_GROUPS_TO_ISSUE; ++loadGroup )
- {
- for( unsigned validImage = 0; validImage < NUM_VALID_IMAGES; ++validImage )
- {
- Dali::Integration::ResourceRequest request( loadGroup * NUM_VALID_IMAGES + validImage + 1, bitmapResourceType, VALID_IMAGES[validImage], priority );
- gAbstraction->LoadResource( request );
- }
- loadsLaunched += NUM_VALID_IMAGES;
- }
-
- // Drain the completed loads:
- Dali::Internal::Platform::ResourceCollector resourceSink;
- gAbstraction->GetResources( resourceSink );
- usleep( 500 * 1000 );
- gAbstraction->GetResources( resourceSink );
-
- const double startDrainTime = GetTimeMilliseconds( *gAbstraction );
- while( resourceSink.mGrandTotalCompletions < loadsLaunched && GetTimeMilliseconds( *gAbstraction ) - startDrainTime < MAX_MILLIS_TO_WAIT_FOR_KNOWN_LOADS )
- {
- usleep( 100 * 40 );
- gAbstraction->GetResources( resourceSink );
- }
-
- // Check the loads completed as expected:
-
- tet_printf( "Issued Loads: %u, Completed Loads: %u, Successful Loads: %u, Failed Loads: %u \n", loadsLaunched, resourceSink.mGrandTotalCompletions, unsigned(resourceSink.mSuccessCounts.size()), unsigned(resourceSink.mFailureCounts.size()) );
- DALI_TEST_CHECK( loadsLaunched == resourceSink.mGrandTotalCompletions );
- DALI_TEST_CHECK( loadsLaunched == resourceSink.mSuccessCounts.size() );
- DALI_TEST_CHECK( 0 == resourceSink.mFailureCounts.size() );
-
- // Check that each success was reported exactly once:
- for( ResourceCounterMap::const_iterator it = resourceSink.mSuccessCounts.begin(), end = resourceSink.mSuccessCounts.end(); it != end; ++it )
- {
- DALI_TEST_CHECK( it->second == 1u );
- }
-
- END_TEST;
-}
// EXTERNAL INCLUDES
#include <dali/integration-api/platform-abstraction.h>
-#include <dali/integration-api/resource-cache.h>
#include <dali/public-api/common/dali-common.h>
// INTERNAL INCLUDES
microSeconds = (static_cast<unsigned int>(current) - seconds*1000.0) * 1000;
}
-void EmscriptenPlatformAbstraction::Suspend()
-{
- DALI_ASSERT_ALWAYS("!Not Implemented");
-}
-
-void EmscriptenPlatformAbstraction::Resume()
-{
- DALI_ASSERT_ALWAYS("!Not Implemented");
-}
-
ImageDimensions EmscriptenPlatformAbstraction::GetClosestImageSize( const std::string& filename,
ImageDimensions size,
FittingMode::Type fittingMode,
ret = bitmapPtr;
}
break;
- case Integration::ResourceNativeImage:
- {
- }
- break;
- case Integration::ResourceTargetImage:
- {
- }
- break;
} // switch(resourceType->id)
return ret;
}
-void EmscriptenPlatformAbstraction::LoadResource(const Integration::ResourceRequest& request)
-{
- std::string path = request.GetPath();
-
- Integration::ResourceType *type = request.GetType();
- Integration::ResourceId resourceId = request.GetId();
- Integration::ResourcePointer resourcePtr = request.GetResource();
-
- if( type )
- {
- switch(type->id)
- {
- case Integration::ResourceBitmap:
- {
- Integration::BitmapPtr bitmapPtr = NULL;
-
- if( NULL == request.GetResource().Get() )
- {
- const Integration::BitmapResourceType& bitmapResource( static_cast<const Integration::BitmapResourceType&>(*type) );
-
- Integration::BitmapPtr bitmapPtr = Dali::Internal::Emscripten::GetImage( bitmapResource.size,
- bitmapResource.scalingMode,
- bitmapResource.samplingMode,
- bitmapResource.orientationCorrection,
- path );
-
-
-
- }
- else
- {
- // 2) load it (usually on worker thread)
- // DALI_LOG_TRACE_METHOD( mLogFilter );
- // DALI_LOG_INFO(mLogFilter, Debug::Verbose, "%s(%s)\n", __FUNCTION__, request.GetPath().c_str());
-
- bitmapPtr = LoadResourceEncodedImage( reinterpret_cast<Dali::RefCountedVector<uint8_t>*>( request.GetResource().Get() ) );
- }
-
- if( bitmapPtr )
- {
- mResourceQueue.push( ResourceIdBitmapPair( resourceId, bitmapPtr ) );
- }
-
- }
- break;
- case Integration::ResourceNativeImage:
- {
- printf("EmscriptenPlatformAbstraction::LoadResource ResourceNativeImage\n");
- }
- break;
- case Integration::ResourceTargetImage:
- {
- printf("EmscriptenPlatformAbstraction::LoadResource ResourceTargetImage\n");
- }
- break;
- } // switch(id)
-
- } // if(type)
-
-}
-
-void EmscriptenPlatformAbstraction::SaveResource(const Integration::ResourceRequest& request)
-{
- DALI_ASSERT_ALWAYS("!Not Implemented");
-}
-
Integration::BitmapPtr EmscriptenPlatformAbstraction::DecodeBuffer( const Integration::ResourceType& resourceType, uint8_t * buffer, size_t bufferSize )
{
return Integration::BitmapPtr();
}
-void EmscriptenPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
-{
- DALI_ASSERT_ALWAYS("!Not Implemented");
-}
-
-void EmscriptenPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
-{
- while( !mResourceQueue.empty() )
- {
- Integration::ResourceId resourceId = mResourceQueue.front().first;
- Integration::BitmapPtr bitmapPtr = mResourceQueue.front().second;
-
- cache.LoadResponse( resourceId,
- Integration::ResourceBitmap,
- bitmapPtr,
- Integration::RESOURCE_COMPLETELY_LOADED );
- mResourceQueue.pop();
- }
-}
-
-bool EmscriptenPlatformAbstraction::IsLoading()
-{
- EM_LOG("EmscriptenPlatformAbstraction::IsLoading");
- return false;
-}
-
-const std::string& EmscriptenPlatformAbstraction::GetDefaultFontFamily() const
-{
- EM_LOG("EmscriptenPlatformAbstraction::GetDefaultFontFamily");
- DALI_ASSERT_ALWAYS("!Not Implemented");
- return mGetDefaultFontFamilyResult;
-}
-
-int EmscriptenPlatformAbstraction::GetDefaultFontSize() const
-{
- EM_LOG("EmscriptenPlatformAbstraction::GetDefaultFontSize");
- return 12;
-}
-
-void EmscriptenPlatformAbstraction::SetDpi (unsigned int /* dpiHorizontal*/, unsigned int /* dpiVertical */)
-{
-
-}
-
-
-bool EmscriptenPlatformAbstraction::LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
-{
- EM_LOG("EmscriptenPlatformAbstraction::LoadFile");
- return false;
-}
-
-bool EmscriptenPlatformAbstraction::SaveFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const
-{
- EM_LOG("EmscriptenPlatformAbstraction::SaveFile");
-
- DALI_ASSERT_ALWAYS("!Unimplemented");
- return false;
-}
bool EmscriptenPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
{
return false;
}
-bool EmscriptenPlatformAbstraction::SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const
-{
- EM_LOG("EmscriptenPlatformAbstraction::SaveShaderBinaryFile");
-
- DALI_ASSERT_ALWAYS("!Unimplemented");
- return false;
-}
-
-void EmscriptenPlatformAbstraction::JoinLoaderThreads()
-{
- DALI_ASSERT_ALWAYS("!Unimplemented");
-}
-
void EmscriptenPlatformAbstraction::UpdateDefaultsFromDevice()
{
DALI_ASSERT_ALWAYS("!Unimplemented");
namespace Dali
{
+namespace Integration
+{
+
+typedef IntrusivePtr<Dali::RefObject> ResourcePointer;
+} // namespace Integration
+
/**
* An Dali Platform abstraction using libSDL for Emscripten.
*
public:
- struct Resources
- {
- bool loaded;
- Integration::ResourceId loadedId;
- Integration::ResourceTypeId loadedType;
- Integration::ResourcePointer loadedResource;
-
- bool loadFailed;
- Integration::ResourceId loadFailedId;
- Integration::ResourceFailure loadFailure;
-
- bool saved;
- Integration::ResourceId savedId;
- Integration::ResourceTypeId savedType;
-
- bool saveFailed;
- Integration::ResourceId saveFailedId;
- Integration::ResourceFailure saveFailure;
- };
-
struct LoadFileResult
{
LoadFileResult()
void IncrementGetTimeResult(size_t milliseconds);
- /**
- * @copydoc PlatformAbstraction::Suspend()
- */
- virtual void Suspend();
-
- /**
- * @copydoc PlatformAbstraction::Resume()
- */
- virtual void Resume();
-
/**
* @copydoc PlatformAbstraction::GetClosestImageSize()
*/
bool orientationCorrection );
/**
- * @copydoc PlatformAbstraction::LoadResource()
+ * @copydoc PlatformAbstraction::LoadResourceSynchronously()
*/
- virtual void LoadResource(const Integration::ResourceRequest& request);
-
virtual Integration::ResourcePointer LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath );
- /**
- * @copydoc PlatformAbstraction::SaveResource()
- */
- virtual void SaveResource(const Integration::ResourceRequest& request);
-
/**
* @copydoc PlatformAbstraction::DecodeBuffer()
*/
virtual Integration::BitmapPtr DecodeBuffer( const Integration::ResourceType& resourceType, uint8_t * buffer, size_t bufferSize );
- /**
- * @copydoc PlatformAbstraction::CancelLoad()
- */
- virtual void CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId);
-
- /**
- * @copydoc PlatformAbstraction::GetResources()
- */
- virtual void GetResources(Integration::ResourceCache& cache);
-
- /**
- * @copydoc PlatformAbstraction::IsLoading()
- */
- virtual bool IsLoading();
-
- /**
- * @copydoc PlatformAbstraction::GetDefaultFontFamily()
- */
- virtual const std::string& GetDefaultFontFamily() const;
-
- /**
- * @copydoc PlatformAbstraction::GetDefaultFontSize()
- */
- virtual int GetDefaultFontSize() const;
-
- /**
- * Sets horizontal and vertical pixels per inch value that is used by the display
- * @param[in] dpiHorizontal horizontal dpi value
- * @param[in] dpiVertical vertical dpi value
- */
- virtual void SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical);
-
- /**
- * @copydoc PlatformAbstraction::LoadFile()
- */
- virtual bool LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
-
- /**
- * @copydoc PlatformAbstraction::SaveFile()
- */
- virtual bool SaveFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const;
-
- /**
- * @copydoc PlatformAbstraction::JoinLoaderThreads()
- */
- virtual void JoinLoaderThreads();
-
/**
* @copydoc PlatformAbstraction::LoadShaderBinaryFile()
*/
private:
std::string mGetDefaultFontFamilyResult;
- Resources mResources;
Vector2 mSize;
LoadFileResult mLoadFileResult;
$(tizen_platform_abstraction_src_dir)/resource-loader/resource-requester-base.cpp \
$(tizen_platform_abstraction_src_dir)/resource-loader/resource-bitmap-requester.cpp \
\
- $(tizen_platform_abstraction_src_dir)/resource-loader/resource-thread-base.cpp \
- $(tizen_platform_abstraction_src_dir)/resource-loader/resource-thread-image.cpp \
- \
$(tizen_platform_abstraction_src_dir)/resource-loader/network/file-download.cpp \
$(tizen_platform_abstraction_src_dir)/resource-loader/network/http-utils.cpp \
\
// EXTERNAL INCLUDES
#include <dali/public-api/images/image-operations.h>
-#include <dali/integration-api/resource-cache.h>
#include <dali/integration-api/resource-types.h>
#include <dali/integration-api/bitmap.h>
namespace Dali
{
+namespace Integration
+{
+typedef IntrusivePtr<Dali::RefObject> ResourcePointer;
+} // Integration
+
namespace TizenPlatform
{
namespace ImageLoader
#if defined(DEBUG_ENABLED)
#include <platform-abstractions/tizen/resource-loader/resource-loader.h>
-#include <dali/integration-api/resource-cache.h>
namespace Dali
#include "resource-bitmap-requester.h"
// EXTERNAL INCLUDES
-#include <dali/integration-api/resource-cache.h>
// INTERNAL INCLUDES
#include "network/file-download.h"
}// unnamed namespace
ResourceBitmapRequester::ResourceBitmapRequester( ResourceLoader& resourceLoader )
-: ResourceRequesterBase( resourceLoader ),
- mThreadImageLocal( NULL ),
- mThreadImageRemote( NULL )
+: ResourceRequesterBase( resourceLoader )
{
}
ResourceBitmapRequester::~ResourceBitmapRequester()
{
- delete mThreadImageLocal;
- delete mThreadImageRemote;
}
-void ResourceBitmapRequester::Pause()
-{
- if( mThreadImageLocal )
- {
- mThreadImageLocal->Pause();
- }
- if( mThreadImageRemote )
- {
- mThreadImageRemote->Pause();
- }
-}
-
-void ResourceBitmapRequester::Resume()
-{
- if( mThreadImageLocal )
- {
- mThreadImageLocal->Resume();
- }
- if( mThreadImageRemote )
- {
- mThreadImageRemote->Resume();
- }
-}
-
-void ResourceBitmapRequester::LoadResource( Integration::ResourceRequest& request )
-{
- DALI_ASSERT_DEBUG( (0 != dynamic_cast<BitmapResourceType*>(request.GetType())) && "Only requsts for bitmap resources can ever be routed to ResourceBitmapRequester.\n");
- BitmapResourceType* resType = static_cast<BitmapResourceType*>(request.GetType());
- if( !resType )
- {
- return;
- }
-
- // Work out what thread to decode / load the image on:
- ResourceScheme scheme( FILE_SYSTEM_RESOURCE );
-
- // Work out if the resource is in memory, a file, or in a remote server:
- ResourceThreadBase::RequestType requestType;
- // if resource exists already, then it just needs decoding
- if( request.GetResource().Get() )
- {
- requestType = ResourceThreadBase::RequestDecode;
- }
- else
- {
- const std::string& resourcePath = request.GetPath();
- if( Network::IsHttpUrl( resourcePath) )
- {
- requestType = ResourceThreadBase::RequestDownload;
- scheme = NETWORK_RESOURCE;
- }
- else
- {
- requestType = ResourceThreadBase::RequestLoad;
- }
- }
-
- // Dispatch the job to the right thread
- // lazily create the thread
- if( scheme == FILE_SYSTEM_RESOURCE )
- {
- if( !mThreadImageLocal )
- {
- mThreadImageLocal = new ResourceThreadImage( mResourceLoader );
- }
- mThreadImageLocal->AddRequest( request, requestType );
- }
- else
- {
- if( !mThreadImageRemote )
- {
- mThreadImageRemote = new ResourceThreadImage( mResourceLoader );
- }
- mThreadImageRemote->AddRequest( request, requestType );
- }
-}
-
-Integration::LoadStatus ResourceBitmapRequester::LoadFurtherResources( Integration::ResourceRequest& request, LoadedResource partialResource )
-{
- // Nothing to do
- return RESOURCE_COMPLETELY_LOADED;
-}
-
-void ResourceBitmapRequester::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
-{
- if( mThreadImageLocal )
- {
- mThreadImageLocal->CancelRequest(id);
- }
- if( mThreadImageRemote )
- {
- mThreadImageRemote->CancelRequest(id);
- }
-}
} // TizenPlatform
} // Dali
*/
#include "resource-requester-base.h"
-#include "resource-thread-image.h"
namespace Dali
{
*/
virtual ~ResourceBitmapRequester();
- /**
- * @copydoc ResourceRequester::Pause()
- */
- virtual void Pause();
-
- /**
- * @copydoc ResourceRequester::Resume()
- */
- virtual void Resume();
-
- /**
- * @copydoc ResourceRequester::LoadResource()
- */
- virtual void LoadResource( Integration::ResourceRequest& request );
-
- /**
- * @copydoc ResourceRequester::LoadFurtherResources()
- */
- virtual Integration::LoadStatus LoadFurtherResources( Integration::ResourceRequest& request, LoadedResource partialResource );
-
- /**
- * @copydoc ResourceRequester::CancelLoad()
- */
- virtual void CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId);
-
private:
- ResourceThreadImage* mThreadImageLocal; ///< Image loader thread object to load images in local machine
- ResourceThreadImage* mThreadImageRemote; ///< Image loader thread object to download images in remote http server
};
} // TizenPlatform
// INTERNAL HEADERS
#include <dali/integration-api/bitmap.h>
#include <dali/integration-api/debug.h>
-#include <dali/integration-api/resource-cache.h>
#include <dali/public-api/common/dali-common.h>
#include <dali/devel-api/common/set-wrapper.h>
#include <dali/public-api/math/vector2.h>
struct ResourceLoader::ResourceLoaderImpl
{
- typedef std::pair<ResourceId, ResourceRequest> RequestStorePair;
- typedef std::map<ResourceId, ResourceRequest> RequestStore;
- typedef RequestStore::iterator RequestStoreIter;
-
typedef std::queue<LoadedResource> LoadedQueue;
typedef std::queue<FailedResource> FailedQueue;
FailedQueue mFailedLoads; ///< Failed load request notifications are stored here until fetched by core
RequestHandlers mRequestHandlers;
- RequestStore mStoredRequests; ///< Used to store load requests until loading is completed
ResourceLoaderImpl( ResourceLoader* loader )
{
}
}
- void Pause()
- {
- // Pause all the request handlers:
- for( RequestHandlersIter it = mRequestHandlers.begin(), end = mRequestHandlers.end(); it != end; ++it )
- {
- ResourceRequesterBase * const requester = it->second;
- if( requester )
- {
- requester->Pause();
- }
- }
- }
-
- void Resume()
- {
- // Wake up all the request handlers:
- for( RequestHandlersIter it = mRequestHandlers.begin(), end = mRequestHandlers.end(); it != end; ++it )
- {
- ResourceRequesterBase * const requester = it->second;
- if( requester )
- {
- requester->Resume();
- }
- }
- }
-
ResourceRequesterBase* GetRequester(ResourceTypeId typeId)
{
ResourceRequesterBase* requestHandler = NULL;
return requestHandler;
}
- void LoadResource(const ResourceRequest& request)
- {
- // Store resource request for partial loaders. Will get cleaned up after load complete has finished
- StoreRequest(request);
-
- ResourceRequesterBase* requester = GetRequester(request.GetType()->id);
- if( requester )
- {
- ResourceRequest* storedRequest = GetRequest(request.GetId());
- if( storedRequest != NULL )
- {
- requester->LoadResource(*storedRequest); // Pass in stored request
- }
- }
- else
- {
- DALI_LOG_ERROR( "Unknown resource type (%u) with path \"%s\" in load request.\n", request.GetType()->id, request.GetPath().c_str() );
- DALI_ASSERT_DEBUG( 0 == "Unknown resource type in load request at " __FILE__ ".\n" );
- }
- }
-
- void CancelLoad(ResourceId id, ResourceTypeId typeId)
- {
- ResourceRequesterBase* requester = GetRequester(typeId);
- if( requester )
- {
- requester->CancelLoad( id, typeId );
- }
- ClearRequest( id );
- }
-
- LoadStatus LoadFurtherResources( LoadedResource partialResource )
- {
- LoadStatus loadStatus = RESOURCE_LOADING;
- RequestStoreIter iter = mStoredRequests.find(partialResource.id);
-
- if( mStoredRequests.end() != iter ) // else cancelled. Ignore response
- {
- ResourceRequest& request = iter->second;
- ResourceRequesterBase* requester = GetRequester(request.GetType()->id);
- if( requester )
- {
- loadStatus = requester->LoadFurtherResources( request, partialResource );
- }
-
- DALI_LOG_INFO(gLoaderFilter, Debug::General, "ResourceLoader::LoadFurtherResources( ID:%u complete: %s)\n", request.GetId(), loadStatus==RESOURCE_LOADING?"Loading":loadStatus==RESOURCE_PARTIALLY_LOADED?"PARTIAL":"COMPLETE" );
- }
-
- if( loadStatus == RESOURCE_COMPLETELY_LOADED )
- {
- ClearRequest( partialResource.id );
- }
-
- return loadStatus;
- }
-
- void GetResources(ResourceCache& cache)
- {
- // Fill the resource cache
-
- Mutex::ScopedLock lock( mQueueMutex );
-
- // iterate through the successfully loaded resources
- while (!mLoadedQueue.empty())
- {
- LoadedResource loaded( mLoadedQueue.front() );
- mLoadedQueue.pop();
- ClearRequest( loaded.id );
- cache.LoadResponse( loaded.id, loaded.type, loaded.resource, RESOURCE_COMPLETELY_LOADED );
- }
-
- // iterate through the resources which failed to load
- while (!mFailedLoads.empty())
- {
- FailedResource failed(mFailedLoads.front());
- mFailedLoads.pop();
- ClearRequest(failed.id);
- cache.LoadFailed(failed.id, failed.failureType);
- }
- }
-
void AddLoadedResource(LoadedResource& resource)
{
// Lock the LoadedQueue to store the loaded resource
mFailedLoads.push(resource);
}
- void StoreRequest( const ResourceRequest& request )
- {
- DALI_LOG_INFO(gLoaderFilter, Debug::Verbose, "ResourceLoader: StoreRequest(id:%u)\n", request.GetId());
- mStoredRequests.insert( RequestStorePair( request.GetId(), request ) ); // copy request as value type
- }
-
- ResourceRequest* GetRequest( ResourceId id )
- {
- ResourceRequest* found(NULL);
- DALI_LOG_INFO(gLoaderFilter, Debug::Verbose, "ResourceLoader: GetRequest(id:%u)\n", id);
- RequestStoreIter iter = mStoredRequests.find( id );
- if( mStoredRequests.end() != iter )
- {
- found = &iter->second;
- }
- return found;
- }
-
- void ClearRequest( ResourceId resourceId )
- {
- DALI_LOG_INFO(gLoaderFilter, Debug::Verbose, "ResourceLoader: ClearRequest(id:%u)\n", resourceId);
- RequestStoreIter iter = mStoredRequests.find( resourceId );
- if( mStoredRequests.end() != iter ) // Can't assert here - cancel load may cross with load failed
- {
- mStoredRequests.erase( iter );
- }
- }
private:
delete mImpl;
}
-void ResourceLoader::Pause()
-{
- mImpl->Pause();
-}
-
-void ResourceLoader::Resume()
-{
- mImpl->Resume();
-}
-
bool ResourceLoader::IsTerminating()
{
return __sync_fetch_and_or( &mTerminateThread, 0 );
}
-void ResourceLoader::GetResources(ResourceCache& cache)
-{
- mImpl->GetResources( cache );
-}
-
/********************************************************************************/
/************************** CALLED FROM LOADER THREADS **********************/
/********************************************************************************/
/********************* CALLED FROM PLATFORM ABSTRACTION **********************/
/********************************************************************************/
-void ResourceLoader::LoadResource(const ResourceRequest& request)
-{
- mImpl->LoadResource(request);
-}
-
-void ResourceLoader::CancelLoad(ResourceId id, ResourceTypeId typeId)
-{
- mImpl->CancelLoad(id, typeId);
-}
bool ResourceLoader::LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const
{
*/
#include <dali/integration-api/platform-abstraction.h>
-#include <dali/integration-api/resource-cache.h>
#include <dali/public-api/common/dali-vector.h>
#include <string>
*/
struct FailedResource
{
- FailedResource(Integration::ResourceId resourceId, Integration::ResourceFailure failure):
- id(resourceId),
- failureType(failure)
- {
- }
-
- /// Copy constructor
- FailedResource(const FailedResource& failed)
- : id(failed.id),
- failureType(failed.failureType)
- {
- }
-
- /// Assignment operator
- FailedResource& operator=(const FailedResource& rhs)
- {
- if( this != &rhs )
- {
- id = rhs.id;
- failureType = rhs.failureType;
- }
- return *this;
- }
-
- Integration::ResourceId id;
- Integration::ResourceFailure failureType;
};
/**
*/
~ResourceLoader();
- /**
- * Pause processing of already-queued resource requests.
- */
- void Pause();
-
- /**
- * Continue processing resource requests.
- */
- void Resume();
-
/**
* Check if the ResourceLoader is terminating
* @return true if terminating else false
// From PlatformAbstraction
- /**
- * @copydoc PlatformAbstraction::LoadResource()
- */
- void LoadResource(const Integration::ResourceRequest& request);
-
- /**
- * @copydoc PlatformAbstraction::CancelLoad()
- */
- void CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId);
-
- /**
- * @copydoc PlatformAbstraction::GetResources()
- */
- void GetResources(Integration::ResourceCache& cache);
-
/**
* @copydoc SlpPlatformAbstraction::LoadFile()
*/
*/
#include <platform-abstractions/tizen/resource-loader/resource-loader.h>
-#include <dali/integration-api/resource-request.h>
-#include <dali/integration-api/resource-cache.h>
namespace Dali
{
-namespace Integration
-{
-class ResourceRequest;
-}
-
namespace TizenPlatform
{
*/
virtual ~ResourceRequesterBase();
- /**
- * Pause starting new work on background threads, but keep that work queued.
- */
- virtual void Pause() = 0;
-
- /**
- * Resume processing tasks on background threads.
- */
- virtual void Resume() = 0;
-
- /**
- * Load a resource.
- * @param[in] request The resource request
- */
- virtual void LoadResource( Integration::ResourceRequest& request ) = 0;
-
- /**
- * Load more resources (for partial loading)
- * @param[in] request The initial load request
- * @param[in] partialResource The resources loaded by the last request
- * @return LOADING or PARTIALLY_LOADED if more resources to come, COMPLETELY_LOADED if complete
- */
- virtual Integration::LoadStatus LoadFurtherResources( Integration::ResourceRequest& request, LoadedResource partialResource ) = 0;
-
- /**
- * Cancal load requests
- * @param[in] id The request id of the loading request
- * @param[in] typeId The resource type id of the loading request
- */
- virtual void CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId) = 0;
protected:
ResourceLoader& mResourceLoader; ///< The resource loader to which to send results
+++ /dev/null
-/*
- * 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.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <memory>
-#include <dali/integration-api/debug.h>
-
-// INTERNAL INCLUDES
-#include "resource-thread-base.h"
-#include "tizen-logging.h"
-#include "atomics.h"
-
-using namespace Dali::Integration;
-
-namespace Dali
-{
-
-// Initial values for the members tracking which resources have been cancelled.
-// They start out with different values so that if the first load executed is
-// synchronous, it won't be erroneously cancelled.
-const Integration::ResourceId NO_REQUEST_IN_FLIGHT = Integration::ResourceId(0) - 1;
-const Integration::ResourceId NO_REQUEST_CANCELLED = Integration::ResourceId(0) - 2;
-
-namespace TizenPlatform
-{
-
-namespace
-{
-const char * const IDLE_PRIORITY_ENVIRONMENT_VARIABLE_NAME = "DALI_RESOURCE_THREAD_IDLE_PRIORITY";
-} // unnamed namespace
-
-/** Thrown by InterruptionPoint() to abort a request early. */
-class CancelRequestException {};
-
-ResourceThreadBase::ResourceThreadBase( ResourceLoader& resourceLoader ) :
- mResourceLoader( resourceLoader ),
- mThread( 0 ),
- mCurrentRequestId( NO_REQUEST_IN_FLIGHT ),
- mCancelRequestId( NO_REQUEST_CANCELLED ),
- mPaused( false )
-{
-#if defined(DEBUG_ENABLED)
- mLogFilter = Debug::Filter::New(Debug::Concise, false, "LOG_RESOURCE_THREAD_BASE");
-#endif
-
- int error = pthread_create( &mThread, NULL, InternalThreadEntryFunc, this );
- DALI_ASSERT_ALWAYS( !error && "Error in pthread_create()" );
-}
-
-ResourceThreadBase::~ResourceThreadBase()
-{
- TerminateThread();
-
-#if defined(DEBUG_ENABLED)
- delete mLogFilter;
-#endif
-}
-
-void ResourceThreadBase::TerminateThread()
-{
- if (mThread)
- {
- // wake thread
- mCondition.Notify();
-
- // wait for thread to exit
- pthread_join( mThread, NULL );
-
- mThread = 0;
- }
-}
-
-void ResourceThreadBase::AddRequest(const ResourceRequest& request, const RequestType type)
-{
- bool wasEmpty = false;
- bool wasPaused = false;
-
- {
- // Lock while adding to the request queue
- ConditionalWait::ScopedLock lock( mCondition );
-
- wasEmpty = mQueue.empty();
- wasPaused = mPaused;
-
- mQueue.push_back( std::make_pair(request, type) );
- }
-
- if( wasEmpty && !wasPaused )
- {
- // Wake-up the thread
- mCondition.Notify();
- }
-}
-
-// Called from outer thread.
-void ResourceThreadBase::CancelRequest( const Integration::ResourceId resourceId )
-{
- bool found = false;
- DALI_LOG_INFO( mLogFilter, Debug::Verbose, "%s: %u.\n", __FUNCTION__, unsigned(resourceId) );
-
- // Eliminate the cancelled request from the request queue if it is in there:
- {
- // Lock while searching and removing from the request queue:
- ConditionalWait::ScopedLock lock( mCondition );
-
- for( RequestQueueIter iterator = mQueue.begin();
- iterator != mQueue.end();
- ++iterator )
- {
- if( ((*iterator).first).GetId() == resourceId )
- {
- iterator = mQueue.erase( iterator );
- found = true;
- break;
- }
- }
- }
-
- // Remember the cancelled id for the worker thread to poll at one of its points
- // of interruption:
- if( !found )
- {
- Dali::Internal::AtomicWriteToCacheableAlignedAddress( &mCancelRequestId, resourceId );
- DALI_LOG_INFO( mLogFilter, Debug::Concise, "%s: Cancelling in-flight resource (%u).\n", __FUNCTION__, unsigned(resourceId) );
- }
-}
-
-// Called from worker thread.
-void ResourceThreadBase::InterruptionPoint() const
-{
- const Integration::ResourceId cancelled = Dali::Internal::AtomicReadFromCacheableAlignedAddress( &mCancelRequestId );
- const Integration::ResourceId current = mCurrentRequestId;
-
- if( current == cancelled )
- {
- DALI_LOG_INFO( mLogFilter, Debug::Concise, "%s: Cancelled in-flight resource (%u).\n", __FUNCTION__, unsigned(cancelled) );
- throw CancelRequestException();
- }
-}
-
-void* ResourceThreadBase::InternalThreadEntryFunc( void* This )
-{
- ( static_cast<ResourceThreadBase*>( This ) )->ThreadLoop();
- return NULL;
-}
-
-void ResourceThreadBase::Pause()
-{
- ConditionalWait::ScopedLock lock( mCondition );
- mPaused = true;
-}
-
-void ResourceThreadBase::Resume()
-{
- // Clear the paused flag and if we weren't running already, also wake up the background thread:
- bool wasPaused = false;
- {
- ConditionalWait::ScopedLock lock( mCondition );
- wasPaused = mPaused;
- mPaused = false;
- }
-
- // If we were paused, wake up the background thread and give it a
- // chance to do some work:
- if( wasPaused )
- {
- mCondition.Notify();
- }
-}
-
-//----------------- Called from separate thread (mThread) -----------------
-
-void ResourceThreadBase::ThreadLoop()
-{
- // TODO: Use Environment Options
- const char* threadPriorityIdleRequired = std::getenv( IDLE_PRIORITY_ENVIRONMENT_VARIABLE_NAME );
- if( threadPriorityIdleRequired )
- {
- // if the parameter exists then set up an idle priority for this thread
- struct sched_param sp;
- sp.sched_priority = 0;
- sched_setscheduler(0, SCHED_IDLE, &sp);
- ///@ToDo: change to the corresponding Pthreads call, not this POSIX.1-2001 one with a Linux-specific argument (SCHED_IDLE): int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param);, as specified in the docs for sched_setscheduler(): http://man7.org/linux/man-pages/man2/sched_setscheduler.2.html
- }
-
- InstallLogging();
-
- while( !mResourceLoader.IsTerminating() )
- {
- try
- {
- WaitForRequests();
-
- if ( !mResourceLoader.IsTerminating() )
- {
- ProcessNextRequest();
- }
- }
-
- catch( CancelRequestException& ex )
- {
- // No problem: a derived class deliberately threw to abort an in-flight request
- // that was cancelled.
- DALI_LOG_INFO( mLogFilter, Debug::Concise, "%s: Caught cancellation exception for resource (%u).\n", __FUNCTION__, unsigned(mCurrentRequestId) );
- CancelRequestException* disableUnusedVarWarning = &ex;
- ex = *disableUnusedVarWarning;
- }
-
- // Catch all exceptions to avoid killing the process, and log the error:
- catch( std::exception& ex )
- {
- const char * const what = ex.what();
- DALI_LOG_ERROR( "std::exception caught in resource thread. Aborting request with id %u because of std::exception with reason, \"%s\".\n", unsigned(mCurrentRequestId), what ? what : "null" );
- }
- catch( Dali::DaliException& ex )
- {
- // Probably a failed assert-always:
- DALI_LOG_ERROR( "DaliException caught in resource thread. Aborting request with id %u. Location: \"%s\". Condition: \"%s\".\n", unsigned(mCurrentRequestId), ex.location, ex.condition );
- }
- catch( ... )
- {
- DALI_LOG_ERROR( "Unknown exception caught in resource thread. Aborting request with id %u.\n", unsigned(mCurrentRequestId) );
- }
- }
-}
-
-void ResourceThreadBase::WaitForRequests()
-{
- ConditionalWait::ScopedLock lock( mCondition );
-
- if( mQueue.empty() || mPaused == true )
- {
- // Waiting for a wake up from resource loader control thread
- // This will be to process a new request or terminate
- mCondition.Wait( lock );
- }
-}
-
-void ResourceThreadBase::ProcessNextRequest()
-{
- ResourceRequest* request(NULL);
- RequestType type(RequestLoad);
-
- {
- // lock the queue and extract the next request
- ConditionalWait::ScopedLock lock( mCondition );
-
- if (!mQueue.empty())
- {
- const RequestInfo & front = mQueue.front();
- request = new ResourceRequest( front.first );
- type = front.second;
- mCurrentRequestId = front.first.GetId();
- mQueue.pop_front();
- }
- } // unlock the queue
-
- // process request outside of lock
- if ( NULL != request )
- {
-#ifdef _CPP11
- std::unique_ptr< ResourceRequest > deleter( request );
-#else
- std::auto_ptr< ResourceRequest > deleter( request );
-#endif
- switch( type )
- {
- case RequestLoad:
- {
- Load(*request);
- }
- break;
-
- case RequestDownload:
- {
- Download(*request);
- }
- break;
-
- case RequestDecode:
- {
- Decode(*request);
- }
- break;
- }
- }
-}
-
-void ResourceThreadBase::InstallLogging()
-{
- // resource loading thread will send its logs to TIZEN Platform's LogMessage handler.
- Dali::Integration::Log::InstallLogFunction(Dali::TizenPlatform::LogMessage);
-}
-
-void ResourceThreadBase::UninstallLogging()
-{
- // uninstall it on resource loading thread.
- Dali::Integration::Log::UninstallLogFunction();
-}
-
-void ResourceThreadBase::Download(const Integration::ResourceRequest& request)
-{
- DALI_LOG_TRACE_METHOD(mLogFilter);
- DALI_LOG_WARNING("Resource Downloading from a remote server not supported for this type.\n");
- ///! If you need this for a subclassed thread, look to ResourceThreadImage::Download() for an example implementation.
-}
-
-void ResourceThreadBase::Decode(const Integration::ResourceRequest& request)
-{
- DALI_LOG_TRACE_METHOD(mLogFilter);
- DALI_LOG_WARNING("Resource Decoding from a memory buffer not supported for this type.\n");
- ///! If you need this for a subclassed thread, look to ResourceThreadImage::Decode() for an example implementation.
-}
-
-} // namespace TizenPlatform
-
-} // namespace Dali
+++ /dev/null
-#ifndef __DALI_TIZEN_PLATFORM_RESOURCE_THREAD_BASE_H__
-#define __DALI_TIZEN_PLATFORM_RESOURCE_THREAD_BASE_H__
-
-/*
- * Copyright (c) 2015 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.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <deque>
-#include <dali/devel-api/threading/conditional-wait.h>
-
-// INTERNAL INCLUDES
-#include "resource-loader.h"
-#include "resource-loading-client.h"
-
-namespace Dali
-{
-
-namespace TizenPlatform
-{
-
-/**
- * Resource loader worker thread
- */
-class ResourceThreadBase : public ResourceLoadingClient
-{
-public:
- // typedefs and enums
-
- /** Client threads send work to resource threads through Requests, for which
- * this type identifies the action to be taken on the resource thread. */
- enum RequestType
- {
- /** Pull a resource out of the platform's file system. */
- RequestLoad,
- /** Pull a resource from the network. */
- RequestDownload,
- /** Pull a resource out of a memory buffer. */
- RequestDecode
- };
-
- typedef std::pair<Integration::ResourceRequest, RequestType> RequestInfo;
- typedef std::deque<RequestInfo> RequestQueue;
- typedef RequestQueue::iterator RequestQueueIter;
-
-public:
- // Constructor
- ResourceThreadBase(ResourceLoader& resourceLoader);
-
- // Destructor
- virtual ~ResourceThreadBase();
-
-protected:
- void TerminateThread();
-
-public:
- /**
- * Add a resource request to the back of the queue
- * @param[in] request The requested resource/file url and attributes
- * @param[in] type Load or save flag
- */
- void AddRequest(const Integration::ResourceRequest& request, const RequestType type);
-
- /**
- * Cancel a resource request. Removes the request from the queue.
- * @param[in] resourceId ID of the resource to be canceled
- */
- void CancelRequest(Integration::ResourceId resourceId);
-
- /**
- * Pause starting new work in the background, but keep that work queued.
- */
- void Pause();
-
- /**
- * Resume processing tasks on background thread.
- */
- void Resume();
-
-
-protected:
- /**
- * Main control loop for the thread.
- * The thread is terminated when this function exits
- */
- void ThreadLoop();
-
- /**
- * Wait for an incoming resource request or termination
- */
- void WaitForRequests();
-
- /**
- * Process the resource request at the head of the queue
- */
- void ProcessNextRequest();
-
- /**
- * Install a logging function in to core for this thread.
- */
- void InstallLogging();
-
- /**
- * Uninstall a logging function.
- */
- void UninstallLogging();
-
- /**
- * Load a resource
- * @param[in] request The requested resource/file url and attributes
- */
- virtual void Load(const Integration::ResourceRequest& request) = 0;
-
- /**
- * Download a resource
- * @param[in] request The requested resource/file url and attributes
- */
- virtual void Download(const Integration::ResourceRequest& request);
-
- /**
- * Decode a resource exactly as if it were being loaded but source its data
- * from a memory buffer attached directly to the request object.
- * @param[in] request The requested resource data and attributes
- */
- virtual void Decode(const Integration::ResourceRequest& request);
-
- /**
- * @brief Cancels current resource request if it matches the one latched to be cancelled.
- *
- * @copydoc ResourceLoadingClient::InterruptionPoint
- */
- virtual void InterruptionPoint() const;
-
-private:
- /**
- * Helper for the thread calling the entry function
- * @param[in] This A pointer to the current UpdateThread object
- */
- static void* InternalThreadEntryFunc( void* This );
-
-protected:
- ResourceLoader& mResourceLoader;
- pthread_t mThread; ///< thread instance
- ConditionalWait mCondition; ///< condition variable
- RequestQueue mQueue; ///< Request queue
-private:
- Integration::ResourceId mCurrentRequestId; ///< Current request, set by worker thread
- volatile Integration::ResourceId mCancelRequestId; ///< Request to be cancelled on thread: written by external thread and read by worker.
- bool mPaused; ///< Whether to process work in mQueue
-
-private:
-
- // Undefined
- ResourceThreadBase( const ResourceThreadBase& resourceThreadBase );
-
- // Undefined
- ResourceThreadBase& operator=( const ResourceThreadBase& resourceThreadBase );
-
-#if defined(DEBUG_ENABLED)
-public:
- Integration::Log::Filter* mLogFilter;
-#endif
-}; // class ResourceThreadBase
-
-} // namespace TizenPlatform
-
-} // namespace Dali
-
-#endif // __DALI_TIZEN_PLATFORM_RESOURCE_THREAD_BASE_H__
+++ /dev/null
-/*
- * Copyright (c) 2015 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.
- *
- */
-
-// CLASS HEADER
-#include "resource-thread-image.h"
-
-// EXTERNAL INCLUDES
-#include <dali/devel-api/common/ref-counted-dali-vector.h>
-#include <dali/integration-api/bitmap.h>
-#include <dali/integration-api/debug.h>
-#include <dali/integration-api/resource-cache.h>
-#include <dali/integration-api/resource-types.h>
-
-// INTERNAL INCLUDES
-#include "portable/file-closer.h"
-#include "image-loaders/image-loader.h"
-#include "network/file-download.h"
-
-using namespace Dali::Integration;
-
-namespace Dali
-{
-
-namespace TizenPlatform
-{
-
-namespace
-{
-
-// limit maximum image down load size to 50 MB
-const size_t MAXIMUM_DOWNLOAD_IMAGE_SIZE = 50 * 1024 * 1024 ;
-}
-
-ResourceThreadImage::ResourceThreadImage(ResourceLoader& resourceLoader)
-: ResourceThreadBase(resourceLoader)
-{
-}
-
-ResourceThreadImage::~ResourceThreadImage()
-{
-}
-
-void ResourceThreadImage::Load(const ResourceRequest& request)
-{
- DALI_LOG_TRACE_METHOD( mLogFilter );
- DALI_LOG_INFO( mLogFilter, Debug::Verbose, "%s(%s)\n", __FUNCTION__, request.GetPath().c_str() );
-
- LoadImageFromLocalFile(request);
-}
-
-void ResourceThreadImage::Download(const ResourceRequest& request)
-{
- bool succeeded;
-
- DALI_LOG_TRACE_METHOD( mLogFilter );
- DALI_LOG_INFO( mLogFilter, Debug::Verbose, "%s(%s)\n", __FUNCTION__, request.GetPath().c_str() );
-
- Dali::Vector<uint8_t> dataBuffer;
- size_t dataSize;
- succeeded = DownloadRemoteImageIntoMemory( request, dataBuffer, dataSize );
- if( succeeded )
- {
- DecodeImageFromMemory(static_cast<void*>(&dataBuffer[0]), dataBuffer.Size(), request);
- }
-}
-
-void ResourceThreadImage::Decode(const ResourceRequest& request)
-{
- DALI_LOG_TRACE_METHOD( mLogFilter );
- DALI_LOG_INFO(mLogFilter, Debug::Verbose, "%s(%s)\n", __FUNCTION__, request.GetPath().c_str());
-
- // Get the blob of binary data that we need to decode:
- DALI_ASSERT_DEBUG( request.GetResource() );
-
- DALI_ASSERT_DEBUG( 0 != dynamic_cast<Dali::RefCountedVector<uint8_t>*>( request.GetResource().Get() ) && "Only blobs of binary data can be decoded." );
- Dali::RefCountedVector<uint8_t>* const encodedBlob = reinterpret_cast<Dali::RefCountedVector<uint8_t>*>( request.GetResource().Get() );
-
- if( 0 != encodedBlob )
- {
- const size_t blobSize = encodedBlob->GetVector().Size();
- uint8_t * const blobBytes = &(encodedBlob->GetVector()[0]);
- DecodeImageFromMemory(blobBytes, blobSize, request);
- }
- else
- {
- FailedResource resource(request.GetId(), FailureUnknown);
- mResourceLoader.AddFailedLoad(resource);
- }
-}
-
-bool ResourceThreadImage::DownloadRemoteImageIntoMemory(const Integration::ResourceRequest& request, Dali::Vector<uint8_t>& dataBuffer, size_t& dataSize)
-{
- bool ok = Network::DownloadRemoteFileIntoMemory( request.GetPath(), dataBuffer, dataSize, MAXIMUM_DOWNLOAD_IMAGE_SIZE );
- if( !ok )
- {
- FailedResource resource(request.GetId(), FailureUnknown);
- mResourceLoader.AddFailedLoad(resource);
- }
- return ok;
-}
-
-void ResourceThreadImage::LoadImageFromLocalFile(const Integration::ResourceRequest& request)
-{
- bool fileNotFound = false;
- BitmapPtr bitmap = 0;
- bool result = false;
-
- Dali::Internal::Platform::FileCloser fileCloser( request.GetPath().c_str(), "rb" );
- FILE * const fp = fileCloser.GetFile();
-
- if( NULL != fp )
- {
- result = ImageLoader::ConvertStreamToBitmap( *request.GetType(), request.GetPath(), fp, *this, bitmap );
- // Last chance to interrupt a cancelled load before it is reported back to clients
- // which have already stopped tracking it:
- InterruptionPoint(); // Note: This can throw an exception.
- if( result && bitmap )
- {
- // Construct LoadedResource and ResourcePointer for image data
- LoadedResource resource( request.GetId(), request.GetType()->id, ResourcePointer( bitmap.Get() ) );
- // Queue the loaded resource
- mResourceLoader.AddLoadedResource( resource );
- }
- else
- {
- DALI_LOG_WARNING( "Unable to decode %s\n", request.GetPath().c_str() );
- }
- }
- else
- {
- DALI_LOG_WARNING( "Failed to open file to load \"%s\"\n", request.GetPath().c_str() );
- fileNotFound = true;
- }
-
- if ( !bitmap )
- {
- if( fileNotFound )
- {
- FailedResource resource(request.GetId(), FailureFileNotFound );
- mResourceLoader.AddFailedLoad(resource);
- }
- else
- {
- FailedResource resource(request.GetId(), FailureUnknown);
- mResourceLoader.AddFailedLoad(resource);
- }
- }
-}
-
-void ResourceThreadImage::DecodeImageFromMemory(void* blobBytes, size_t blobSize, const Integration::ResourceRequest& request)
-{
- BitmapPtr bitmap = 0;
-
- DALI_ASSERT_DEBUG( blobSize > 0U );
- DALI_ASSERT_DEBUG( blobBytes != 0U );
-
- if( blobBytes != 0 && blobSize > 0U )
- {
- // Open a file handle on the memory buffer:
- Dali::Internal::Platform::FileCloser fileCloser( blobBytes, blobSize, "rb" );
- FILE * const fp = fileCloser.GetFile();
- if ( NULL != fp )
- {
- bool result = ImageLoader::ConvertStreamToBitmap( *request.GetType(), request.GetPath(), fp, StubbedResourceLoadingClient(), bitmap );
- if ( result && bitmap )
- {
- // Construct LoadedResource and ResourcePointer for image data
- LoadedResource resource( request.GetId(), request.GetType()->id, ResourcePointer( bitmap.Get() ) );
- // Queue the loaded resource
- mResourceLoader.AddLoadedResource( resource );
- }
- else
- {
- DALI_LOG_WARNING( "Unable to decode bitmap supplied as in-memory blob.\n" );
- }
- }
- }
-
- if (!bitmap)
- {
- FailedResource resource(request.GetId(), FailureUnknown);
- mResourceLoader.AddFailedLoad(resource);
- }
-}
-
-} // namespace TizenPlatform
-
-} // namespace Dali
+++ /dev/null
-#ifndef __DALI_TIZEN_PLATFORM_RESOURCE_THREAD_IMAGE_H__
-#define __DALI_TIZEN_PLATFORM_RESOURCE_THREAD_IMAGE_H__
-
-/*
- * Copyright (c) 2015 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.
- *
- */
-// EXTERNAL INCLUDES
-#include <dali/integration-api/resource-cache.h>
-#include <dali/integration-api/resource-types.h>
-
-// INTERNAL INCLUDES
-#include "resource-thread-base.h"
-
-namespace Dali
-{
-
-namespace TizenPlatform
-{
-
-class ResourceThreadImage : public ResourceThreadBase
-{
-public:
- /**
- * Constructor
- * @param[in] resourceLoader A reference to the ResourceLoader
- */
- ResourceThreadImage( ResourceLoader& resourceLoader );
-
- /**
- * Destructor
- */
- virtual ~ResourceThreadImage();
-
-
-private:
- /**
- * @copydoc ResourceThreadBase::Load
- */
- virtual void Load(const Integration::ResourceRequest& request);
-
- /**
- * @copydoc ResourceThreadBase::Download
- */
- virtual void Download(const Integration::ResourceRequest& request);
-
- /**
- * @copydoc ResourceThreadBase::Decode
- */
- virtual void Decode(const Integration::ResourceRequest& request);
-
- /**
- * Download a requested image into a memory buffer.
- * @param[in] request The requested resource/file url and attributes
- * @param[out] dataBuffer A memory buffer object to be written with downloaded image data.
- * @param[out] dataSize The size of the memory buffer.
- */
- bool DownloadRemoteImageIntoMemory(const Integration::ResourceRequest& request, Dali::Vector<uint8_t>& dataBuffer, size_t& dataSize);
-
- /**
- * Load a requested image from a local file.
- * @param[in] request The requested resource/file url and attributes
- */
- void LoadImageFromLocalFile(const Integration::ResourceRequest& request);
-
- /**
- * Decode a requested image from a memory buffer.
- * @param[in] blobBytes A pointer to the memory buffer containig the requested image data.
- * @param[in] blobSize The size of the memory buffer containing the requested image data.
- * @param[in] request The requested resource/file url and attributes
- */
- void DecodeImageFromMemory(void* blobBytes, size_t blobSize, const Integration::ResourceRequest& request);
-}; // class ResourceThreadImage
-
-} // namespace TizenPlatform
-
-} // namespace Dali
-
-#endif // __DALI_TIZEN_PLATFORM_RESOURCE_THREAD_IMAGE_H__
delete mResourceLoader;
}
-void TizenPlatformAbstraction::Suspend()
-{
- if (mResourceLoader)
- {
- mResourceLoader->Pause();
- }
-}
-
-void TizenPlatformAbstraction::Resume()
-{
- if (mResourceLoader)
- {
- mResourceLoader->Resume();
- }
-}
-
int TizenPlatformAbstraction::GetDefaultFontSize() const
{
int fontSize( -1 );
return ImageLoader::GetClosestImageSize( resourceBuffer, size, fittingMode, samplingMode, orientationCorrection );
}
-void TizenPlatformAbstraction::LoadResource(const Integration::ResourceRequest& request)
-{
- if (mResourceLoader)
- {
- mResourceLoader->LoadResource(request);
- }
-}
-
Integration::ResourcePointer TizenPlatformAbstraction::LoadResourceSynchronously(const Integration::ResourceType& resourceType, const std::string& resourcePath)
{
return ImageLoader::LoadResourceSynchronously( resourceType, resourcePath );
return bitmap;
}
-void TizenPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
-{
- if (mResourceLoader)
- {
- mResourceLoader->CancelLoad(id, typeId);
- }
-}
-
-void TizenPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
-{
- if (mResourceLoader)
- {
- mResourceLoader->GetResources(cache);
- }
-}
-
-bool TizenPlatformAbstraction::LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
-{
- bool result = false;
-
- if( mResourceLoader )
- {
- result = mResourceLoader->LoadFile( filename, buffer );
- }
-
- return result;
-}
-
-std::string TizenPlatformAbstraction::LoadFile( const std::string& filename )
-{
- std::string result;
- if (mResourceLoader)
- {
- result = mResourceLoader->LoadFile(filename);
- }
-
- return result;
-}
-
-void TizenPlatformAbstraction::JoinLoaderThreads()
-{
- delete mResourceLoader;
- mResourceLoader = NULL;
-}
-
bool TizenPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
{
bool result = false;
*/
#include <dali/integration-api/platform-abstraction.h>
-#include <dali/integration-api/resource-cache.h>
#include <dali/public-api/common/dali-common.h>
#include <string>
public: // PlatformAbstraction overrides
- /**
- * @copydoc PlatformAbstraction::Suspend()
- */
- virtual void Suspend();
-
- /**
- * @copydoc PlatformAbstraction::Resume()
- */
- virtual void Resume();
-
/**
* @copydoc PlatformAbstraction::GetClosestImageSize()
*/
SamplingMode::Type samplingMode,
bool orientationCorrection );
- /**
- * @copydoc PlatformAbstraction::LoadResource()
- */
- virtual void LoadResource(const Integration::ResourceRequest& request);
-
/**
* @copydoc PlatformAbstraction::LoadResourceSynchronously()
*/
*/
virtual Integration::BitmapPtr DecodeBuffer( const Integration::ResourceType& resourceType, uint8_t * buffer, size_t size );
- /**
- * @copydoc PlatformAbstraction::CancelLoad()
- */
- virtual void CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId);
-
- /**
- * @copydoc PlatformAbstraction::GetResources()
- */
- virtual void GetResources(Integration::ResourceCache& cache);
-
- /**
- * @copydoc PlatformAbstraction::JoinLoaderThreads()
- */
- virtual void JoinLoaderThreads();
-
/**
* @copydoc PlatformAbstraction::GetDefaultFontSize()
*/
virtual int GetDefaultFontSize() const;
- /**
- * @copydoc PlatformAbstraction::LoadFile()
- */
- virtual bool LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
-
- /**
- * @copydoc PlatformAbstraction::LoadFile()
- */
- virtual std::string LoadFile( const std::string& filename );
-
/**
* @copydoc PlatformAbstraction::LoadShaderBinaryFile()
*/
GetImplementation(*this).GetDpi( horizontalDpi, verticalDpi );
}
+int FontClient::GetDefaultFontSize()
+{
+ return GetImplementation(*this).GetDefaultFontSize();
+}
+
void FontClient::ResetSystemDefaults()
{
GetImplementation(*this).ResetSystemDefaults();
*/
void GetDpi( unsigned int& horizontalDpi, unsigned int& verticalDpi );
+ /**
+ * @brief Called by Dali to retrieve the default font size for the platform.
+ *
+ * This is an accessibility size, which is mapped to a UI Control specific point-size in stylesheets.
+ * For example if zero the smallest size, this could potentially map to TextLabel point-size 8.
+ * @return The default font size.
+ */
+ int GetDefaultFontSize();
+
/**
* @brief Called when the user changes the system defaults.
*
// CLASS HEADER
#include <dali/internal/text-abstraction/font-client-impl.h>
+// EXTERNAL INCLUDES
+#ifndef DALI_PROFILE_UBUNTU
+#include <vconf.h>
+#endif
+
// INTERNAL INCLUDES
#include <singleton-service.h>
#include <dali/internal/text-abstraction/font-client-plugin-impl.h>
verticalDpi = mDpiVertical;
}
+int FontClient::GetDefaultFontSize()
+{
+ int fontSize( -1 );
+
+#ifndef DALI_PROFILE_UBUNTU
+ vconf_get_int( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &fontSize );
+#endif // DALI_PROFILE_UBUNTU
+
+ return fontSize;
+}
+
void FontClient::ResetSystemDefaults()
{
CreatePlugin();
*/
void GetDpi( unsigned int& horizontalDpi, unsigned int& verticalDpi );
+ /**
+ * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFontSize()
+ */
+ int GetDefaultFontSize();
+
/**
* @copydoc Dali::TextAbstraction::FontClient::ResetSystemDefaults()
*/