2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 #include <dali/internal/update/resources/atlas-request-status.h>
21 #include <dali/integration-api/glyph-set.h>
23 using namespace Dali::Integration;
31 AtlasRequestStatus::AtlasRequestStatus()
35 AtlasRequestStatus::~AtlasRequestStatus()
39 void AtlasRequestStatus::CheckAndSaveTextRequest( ResourceId id, const ResourceTypePath& typePath )
41 if( typePath.type->id == ResourceText )
43 const TextResourceType* textResource = static_cast<const TextResourceType*>(typePath.type);
44 ResourceId atlasId = textResource->mTextureAtlasId;
46 AtlasStatusIter iter = mAtlasStatus.find(atlasId);
47 if( iter == mAtlasStatus.end() )
50 GlyphLoadStatusContainer glyphStatusMap;
51 glyphStatusMap.insert(make_pair(id, RESOURCE_LOADING));
52 mAtlasStatus.insert(make_pair(atlasId, glyphStatusMap));
57 iter->second.insert(make_pair(id, RESOURCE_LOADING));
62 void AtlasRequestStatus::Update( ResourceId id, ResourceId atlasId, LoadStatus loadStatus )
64 AtlasStatusIter iter = mAtlasStatus.find(atlasId);
65 if( iter != mAtlasStatus.end() )
67 GlyphLoadStatusContainer& glyphRequests = iter->second;
68 GlyphLoadStatusIter glyphIter = glyphRequests.find(id);
69 DALI_ASSERT_DEBUG( glyphIter != glyphRequests.end() );
70 if( glyphIter != glyphRequests.end() )
72 glyphIter->second = loadStatus;
77 bool AtlasRequestStatus::IsLoadComplete( ResourceId atlasId )
79 bool complete = false;
80 if( ! mAtlasStatus.empty() )
82 AtlasStatusIter iter = mAtlasStatus.find(atlasId);
83 if( iter != mAtlasStatus.end() )
85 GlyphLoadStatusContainer& glyphRequests = iter->second;
86 if( ! glyphRequests.empty() )
89 for( GlyphLoadStatusIter glyphIter = glyphRequests.begin(), glyphEnd = glyphRequests.end() ;
90 glyphIter != glyphEnd ;
93 if(glyphIter->second != RESOURCE_COMPLETELY_LOADED)
105 LoadStatus AtlasRequestStatus::GetLoadStatus( ResourceId atlasId )
107 // status initially set to loaded
108 // if a partially loaded glyphset is encountered it is set to RESOURCE_PARTIALLY_LOADED
109 // if a loading glyphset is found RESOURCE_LOADING is returned instantly
110 LoadStatus loadStatus = RESOURCE_COMPLETELY_LOADED;
112 if( ! mAtlasStatus.empty() )
114 AtlasStatusIter iter = mAtlasStatus.find(atlasId);
115 if( iter != mAtlasStatus.end() )
117 GlyphLoadStatusContainer& glyphRequests = iter->second;
118 if( ! glyphRequests.empty() )
120 for( GlyphLoadStatusIter glyphIter = glyphRequests.begin(), glyphEnd = glyphRequests.end() ;
121 glyphIter != glyphEnd ;
124 if( glyphIter->second == RESOURCE_LOADING )
126 // return if a glyphset is still being loaded
127 return RESOURCE_LOADING;
129 else if( glyphIter->second == RESOURCE_PARTIALLY_LOADED )
131 loadStatus = RESOURCE_PARTIALLY_LOADED;
141 void AtlasRequestStatus::Remove( ResourceId atlasId )
143 mAtlasStatus.erase(atlasId);