License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-core.git] / dali / internal / update / resources / atlas-request-status.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/update/resources/atlas-request-status.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/integration-api/glyph-set.h>
23
24 using namespace Dali::Integration;
25 using std::make_pair;
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31
32 AtlasRequestStatus::AtlasRequestStatus()
33 {
34 }
35
36 AtlasRequestStatus::~AtlasRequestStatus()
37 {
38 }
39
40 void AtlasRequestStatus::CheckAndSaveTextRequest( ResourceId id, const ResourceTypePath& typePath )
41 {
42   if( typePath.type->id == ResourceText )
43   {
44     const TextResourceType* textResource = static_cast<const TextResourceType*>(typePath.type);
45     ResourceId atlasId = textResource->mTextureAtlasId;
46
47     AtlasStatusIter iter = mAtlasStatus.find(atlasId);
48     if( iter == mAtlasStatus.end() )
49     {
50       // Create new one
51       GlyphLoadStatusContainer glyphStatusMap;
52       glyphStatusMap.insert(make_pair(id, RESOURCE_LOADING));
53       mAtlasStatus.insert(make_pair(atlasId, glyphStatusMap));
54     }
55     else
56     {
57       // append
58       iter->second.insert(make_pair(id, RESOURCE_LOADING));
59     }
60   }
61 }
62
63 void AtlasRequestStatus::Update( ResourceId id, ResourceId atlasId, LoadStatus loadStatus )
64 {
65   AtlasStatusIter iter = mAtlasStatus.find(atlasId);
66   if( iter != mAtlasStatus.end() )
67   {
68     GlyphLoadStatusContainer& glyphRequests = iter->second;
69     GlyphLoadStatusIter glyphIter = glyphRequests.find(id);
70     DALI_ASSERT_DEBUG( glyphIter != glyphRequests.end() );
71     if( glyphIter != glyphRequests.end() )
72     {
73       glyphIter->second = loadStatus;
74     }
75   }
76 }
77
78 bool AtlasRequestStatus::IsLoadComplete( ResourceId atlasId )
79 {
80   bool complete = false;
81   if( ! mAtlasStatus.empty() )
82   {
83     AtlasStatusIter iter = mAtlasStatus.find(atlasId);
84     if( iter != mAtlasStatus.end() )
85     {
86       GlyphLoadStatusContainer& glyphRequests = iter->second;
87       if( ! glyphRequests.empty() )
88       {
89         complete = true;
90         for( GlyphLoadStatusIter glyphIter = glyphRequests.begin(), glyphEnd = glyphRequests.end() ;
91              glyphIter != glyphEnd ;
92              glyphIter++)
93         {
94           if(glyphIter->second != RESOURCE_COMPLETELY_LOADED)
95           {
96             complete = false;
97             break;
98           }
99         }
100       }
101     }
102   }
103   return complete;
104 }
105
106 LoadStatus AtlasRequestStatus::GetLoadStatus( ResourceId atlasId )
107 {
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;
112
113   if( ! mAtlasStatus.empty() )
114   {
115     AtlasStatusIter iter = mAtlasStatus.find(atlasId);
116     if( iter != mAtlasStatus.end() )
117     {
118       GlyphLoadStatusContainer& glyphRequests = iter->second;
119       if( ! glyphRequests.empty() )
120       {
121         for( GlyphLoadStatusIter glyphIter = glyphRequests.begin(), glyphEnd = glyphRequests.end() ;
122                      glyphIter != glyphEnd ;
123                      glyphIter++)
124         {
125           if( glyphIter->second == RESOURCE_LOADING )
126           {
127             // return if a glyphset is still being loaded
128             return RESOURCE_LOADING;
129           }
130           else if( glyphIter->second == RESOURCE_PARTIALLY_LOADED )
131           {
132             loadStatus = RESOURCE_PARTIALLY_LOADED;
133           }
134         }
135       }
136     }
137   }
138   return loadStatus;
139 }
140
141
142 void AtlasRequestStatus::Remove( ResourceId atlasId )
143 {
144   mAtlasStatus.erase(atlasId);
145 }
146
147 } // Internal
148 } // Dali