Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-core.git] / dali / internal / event / resources / resource-type-path.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/event/resources/resource-type-path.h>
20
21 using namespace Dali::Integration;
22
23 namespace Dali
24 {
25
26 namespace Internal
27 {
28
29 namespace
30 {
31
32 /**
33  * Compare two resource types.
34  * @return zero if the types are equal,
35  *         less than zero if lhs < rhs or
36  *         greater than zero if lhs > rhs
37  */
38 int ResourceTypeCompare(const ResourceType& lhs, const ResourceType& rhs)
39 {
40   int result = 0;
41
42   if (lhs.id != rhs.id)
43   {
44     result = lhs.id > rhs.id ? 1 : -1;
45   }
46   else // lhs.id == rhs.id
47   {
48     // Cast to a derived resource type and compare...
49
50     switch (lhs.id)
51     {
52       case ResourceBitmap:
53       {
54         // compare bitmap widths & heights
55         const BitmapResourceType& lhsBitmap = static_cast<const BitmapResourceType&>(lhs);
56         const BitmapResourceType& rhsBitmap = static_cast<const BitmapResourceType&>(rhs);
57
58         if (lhsBitmap.imageAttributes != rhsBitmap.imageAttributes)
59         {
60           result = lhsBitmap.imageAttributes < rhsBitmap.imageAttributes ? -1 : 1;
61         }
62         // else result = 0
63         break;
64       }
65
66       case ResourceNativeImage:
67       {
68         // compare native image widths & heights
69
70         const NativeImageResourceType& lhsNativeImage = static_cast<const NativeImageResourceType&>(lhs);
71         const NativeImageResourceType& rhsNativeImage = static_cast<const NativeImageResourceType&>(rhs);
72
73         if (lhsNativeImage.imageAttributes != rhsNativeImage.imageAttributes)
74         {
75           result = lhsNativeImage.imageAttributes < rhsNativeImage.imageAttributes ? -1 : 1;
76         }
77         // else result = 0
78         break;
79       }
80
81       case ResourceTargetImage:
82       {
83         // compare bitmap widths & heights
84         const RenderTargetResourceType& lhsImage = static_cast<const RenderTargetResourceType&>(lhs);
85         const RenderTargetResourceType& rhsImage = static_cast<const RenderTargetResourceType&>(rhs);
86
87         if (lhsImage.imageAttributes != rhsImage.imageAttributes)
88         {
89           result = lhsImage.imageAttributes < rhsImage.imageAttributes ? -1 : 1;
90         }
91         // else result = 0
92         break;
93       }
94
95       case ResourceShader:
96       {
97         // compare shader source hashes
98         const ShaderResourceType& lhsShader = static_cast<const ShaderResourceType&>(lhs);
99         const ShaderResourceType& rhsShader = static_cast<const ShaderResourceType&>(rhs);
100
101         if (lhsShader.hash != rhsShader.hash)
102         {
103           result = lhsShader.hash < rhsShader.hash ? -1 : 1;
104         }
105         // else result = 0
106         break;
107       }
108
109       case ResourceModel:
110       {
111         break; // result = 0
112       }
113
114       case ResourceMesh:
115       {
116         break; // result = 0
117       }
118
119     }
120   }
121   return result;
122 }
123 }
124
125 bool ResourceTypePath::operator<(const ResourceTypePath& rhs) const
126 {
127   int typeComparison = ResourceTypeCompare(*type, *(rhs.type));
128
129   if (typeComparison != 0)
130   {
131     return (typeComparison < 0);
132   }
133   else
134   {
135     return path < rhs.path;
136   }
137 }
138
139 } // namespace Internal
140
141 } // namespace Dali