Merge branch 'devel/master (1.2.0)' into tizen
[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  * @brief Compare two sets of image loading parameters for equality.
34  */
35 inline bool AttributesEqual( ImageDimensions aDims, FittingMode::Type aScaling, SamplingMode::Type aSampling, bool aOrient, ImageDimensions bDims, FittingMode::Type bScaling, SamplingMode::Type bSampling, bool bOrient )
36 {
37   return aDims     == bDims &&
38          aScaling  == bScaling &&
39          aSampling == bSampling &&
40          aOrient   == bOrient;
41 }
42
43 /**
44  * @brief Compare two sets of image loading parameters
45  * @pre The two sets are not identical.
46  */
47 inline bool AttributesLessAssumingNotEqual( ImageDimensions aDims, FittingMode::Type aScaling, SamplingMode::Type aSampling, bool aOrient, ImageDimensions bDims, FittingMode::Type bScaling, SamplingMode::Type bSampling, bool bOrient )
48 {
49   return aDims     < bDims &&
50          aScaling  < bScaling &&
51          aSampling < bSampling &&
52          aOrient   < bOrient;
53 }
54
55 /**
56  * Compare two resource types.
57  * @return zero if the types are equal,
58  *         less than zero if lhs < rhs or
59  *         greater than zero if lhs > rhs
60  */
61 int ResourceTypeCompare(const ResourceType& lhs, const ResourceType& rhs)
62 {
63   int result = 0;
64
65   if (lhs.id != rhs.id)
66   {
67     result = lhs.id > rhs.id ? 1 : -1;
68   }
69   else // lhs.id == rhs.id
70   {
71     // Cast to a derived resource type and compare...
72
73     switch (lhs.id)
74     {
75       case ResourceBitmap:
76       {
77         // compare bitmap widths & heights
78         const BitmapResourceType& lhsBitmap = static_cast<const BitmapResourceType&>(lhs);
79         const BitmapResourceType& rhsBitmap = static_cast<const BitmapResourceType&>(rhs);
80
81         if( ! AttributesEqual( lhsBitmap.size, lhsBitmap.scalingMode, lhsBitmap.samplingMode, lhsBitmap.orientationCorrection,
82                                rhsBitmap.size, rhsBitmap.scalingMode, rhsBitmap.samplingMode, rhsBitmap.orientationCorrection ) )
83         {
84           result = AttributesLessAssumingNotEqual( lhsBitmap.size, lhsBitmap.scalingMode, lhsBitmap.samplingMode, lhsBitmap.orientationCorrection,
85                                                    rhsBitmap.size, rhsBitmap.scalingMode, rhsBitmap.samplingMode, rhsBitmap.orientationCorrection );
86         }
87         // else result = 0
88         break;
89       }
90
91       case ResourceNativeImage:
92       {
93         // compare native image widths & heights
94
95         const NativeImageResourceType& lhsNativeImage = static_cast<const NativeImageResourceType&>(lhs);
96         const NativeImageResourceType& rhsNativeImage = static_cast<const NativeImageResourceType&>(rhs);
97
98         if (lhsNativeImage.imageDimensions != rhsNativeImage.imageDimensions)
99         {
100           result = lhsNativeImage.imageDimensions < rhsNativeImage.imageDimensions ? -1 : 1;
101         }
102         // else result = 0
103         break;
104       }
105
106       case ResourceTargetImage:
107       {
108         // compare bitmap widths & heights
109         const RenderTargetResourceType& lhsImage = static_cast<const RenderTargetResourceType&>(lhs);
110         const RenderTargetResourceType& rhsImage = static_cast<const RenderTargetResourceType&>(rhs);
111
112         if (lhsImage.imageDimensions != rhsImage.imageDimensions)
113         {
114           result = lhsImage.imageDimensions < rhsImage.imageDimensions ? -1 : 1;
115         }
116         // else result = 0
117         break;
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