2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/update/resources/atlas-request-status.h>
22 #include <dali/integration-api/glyph-set.h>
24 using namespace Dali::Integration;
32 AtlasRequestStatus::AtlasRequestStatus()
36 AtlasRequestStatus::~AtlasRequestStatus()
40 void AtlasRequestStatus::CheckAndSaveTextRequest( ResourceId id, const ResourceTypePath& typePath )
42 if( typePath.type->id == ResourceText )
44 const TextResourceType* textResource = static_cast<const TextResourceType*>(typePath.type);
45 ResourceId atlasId = textResource->mTextureAtlasId;
47 AtlasStatusIter iter = mAtlasStatus.find(atlasId);
48 if( iter == mAtlasStatus.end() )
51 GlyphLoadStatusContainer glyphStatusMap;
52 glyphStatusMap.insert(make_pair(id, RESOURCE_LOADING));
53 mAtlasStatus.insert(make_pair(atlasId, glyphStatusMap));
58 iter->second.insert(make_pair(id, RESOURCE_LOADING));
63 void AtlasRequestStatus::Update( ResourceId id, ResourceId atlasId, LoadStatus loadStatus )
65 AtlasStatusIter iter = mAtlasStatus.find(atlasId);
66 if( iter != mAtlasStatus.end() )
68 GlyphLoadStatusContainer& glyphRequests = iter->second;
69 GlyphLoadStatusIter glyphIter = glyphRequests.find(id);
70 DALI_ASSERT_DEBUG( glyphIter != glyphRequests.end() );
71 if( glyphIter != glyphRequests.end() )
73 glyphIter->second = loadStatus;
78 bool AtlasRequestStatus::IsLoadComplete( ResourceId atlasId )
80 bool complete = false;
81 if( ! mAtlasStatus.empty() )
83 AtlasStatusIter iter = mAtlasStatus.find(atlasId);
84 if( iter != mAtlasStatus.end() )
86 GlyphLoadStatusContainer& glyphRequests = iter->second;
87 if( ! glyphRequests.empty() )
90 for( GlyphLoadStatusIter glyphIter = glyphRequests.begin(), glyphEnd = glyphRequests.end() ;
91 glyphIter != glyphEnd ;
94 if(glyphIter->second != RESOURCE_COMPLETELY_LOADED)
106 LoadStatus AtlasRequestStatus::GetLoadStatus( ResourceId atlasId )
108 // status initially set to loaded
109 // if a partially loaded glyphset is encountered it is set to RESOURCE_PARTIALLY_LOADED
110 // if a loading glyphset is found RESOURCE_LOADING is returned instantly
111 LoadStatus loadStatus = RESOURCE_COMPLETELY_LOADED;
113 if( ! mAtlasStatus.empty() )
115 AtlasStatusIter iter = mAtlasStatus.find(atlasId);
116 if( iter != mAtlasStatus.end() )
118 GlyphLoadStatusContainer& glyphRequests = iter->second;
119 if( ! glyphRequests.empty() )
121 for( GlyphLoadStatusIter glyphIter = glyphRequests.begin(), glyphEnd = glyphRequests.end() ;
122 glyphIter != glyphEnd ;
125 if( glyphIter->second == RESOURCE_LOADING )
127 // return if a glyphset is still being loaded
128 return RESOURCE_LOADING;
130 else if( glyphIter->second == RESOURCE_PARTIALLY_LOADED )
132 loadStatus = RESOURCE_PARTIALLY_LOADED;
142 void AtlasRequestStatus::Remove( ResourceId atlasId )
144 mAtlasStatus.erase(atlasId);