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