Remove Sampler scene object
[platform/core/uifw/dali-core.git] / dali / internal / common / image-sampler.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/common/image-sampler.h>
20
21 // EXTERNAL INCLUDES
22 #include <iosfwd>
23
24 namespace Dali
25 {
26
27 namespace Internal
28 {
29
30 namespace ImageSampler
31 {
32
33 namespace
34 {
35
36 // @todo MESH_REWORK Remove file after image removal
37
38 // Adjust these shift sizes if the FilterMode enum grows
39 const int MINIFY_BIT_SHIFT  = 0;    // Room for 16
40 const int MAGNIFY_BIT_SHIFT = 4;
41 const int UWRAP_BIT_SHIFT   = 8;
42 const int VWRAP_BIT_SHIFT   = 12;
43
44 const int MASK_MINIFY_FILTER    = 0x0000000F;
45 const int MASK_MAGNIFY_FILTER   = 0x000000F0;
46 const int MASK_UWRAP_MODE       = 0x00000F00;
47 const int MASK_VWRAP_MODE       = 0x0000F000;
48
49 } // namespace
50
51 /**
52  * Utility to store one of the sampling parameters values.
53  * @param[out] options A bitmask used to store the FilterMode values.
54  * @param[in] factor The FilterMode value.
55  * @param[in] bitshift Used to shift to the correct part of options.
56  */
57 void StoreSamplingParameter( unsigned int& options, unsigned int mode, int bitShift )
58 {
59   if( mode != 0 )
60   {
61     options |= ( mode << bitShift );
62   }
63 }
64
65 /**
66  * Utility to retrieve one of the FilterMode values.
67  * @param[in] options A bitmask of filter values.
68  * @param[in] mask The used to mask unwanted values.
69  * @param[in] bitshift Used to shift to the correct part of options.
70  * @return Return the filter mode.
71  */
72 unsigned int RetrieveSamplingParameter( unsigned int options, int mask, int bitShift )
73 {
74   unsigned int index = options & mask;
75
76   index = ( index >> bitShift );    // Zero based index for array
77   return index;
78 }
79
80 unsigned int PackBitfield( FilterMode::Type minify, FilterMode::Type magnify, WrapMode::Type uWrap, WrapMode::Type vWrap )
81 {
82   unsigned int bitfield = 0;
83   StoreSamplingParameter( bitfield, minify, MINIFY_BIT_SHIFT );
84   StoreSamplingParameter( bitfield, magnify, MAGNIFY_BIT_SHIFT );
85   StoreSamplingParameter( bitfield, uWrap, UWRAP_BIT_SHIFT );
86   StoreSamplingParameter( bitfield, vWrap, VWRAP_BIT_SHIFT );
87   return bitfield;
88 }
89
90 FilterMode::Type GetMinifyFilterMode( unsigned int bitfield )
91 {
92   return static_cast<FilterMode::Type>( RetrieveSamplingParameter( bitfield, MASK_MINIFY_FILTER, MINIFY_BIT_SHIFT ) );
93 }
94
95 FilterMode::Type GetMagnifyFilterMode( unsigned int bitfield )
96 {
97   return static_cast<FilterMode::Type>( RetrieveSamplingParameter( bitfield, MASK_MAGNIFY_FILTER, MAGNIFY_BIT_SHIFT ) );
98 }
99
100 WrapMode::Type GetUWrapMode( unsigned int bitfield )
101 {
102   return static_cast<WrapMode::Type>( RetrieveSamplingParameter( bitfield, MASK_UWRAP_MODE, UWRAP_BIT_SHIFT ) );
103 }
104
105 WrapMode::Type GetVWrapMode( unsigned int bitfield )
106 {
107   return static_cast<WrapMode::Type>( RetrieveSamplingParameter( bitfield, MASK_VWRAP_MODE, VWRAP_BIT_SHIFT ) );
108 }
109
110 } // namespace ImageSampler
111
112 } // namespace Internal
113
114 } // namespace Dali