Removing rendering backend
[platform/core/uifw/dali-core.git] / dali / internal / update / rendering / scene-graph-sampler.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_SAMPLER_H
2 #define DALI_INTERNAL_SCENE_GRAPH_SAMPLER_H
3
4 /*
5  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <dali/public-api/actors/sampling.h>
21 #include <dali/public-api/rendering/sampler.h>
22 #include <dali/internal/common/message.h>
23 #include <dali/internal/event/common/event-thread-services.h>
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29 namespace SceneGraph
30 {
31
32 struct Sampler
33 {
34
35   typedef Dali::FilterMode::Type FilterMode;
36   typedef Dali::WrapMode::Type   WrapMode;
37
38   /**
39    * Constructor
40    */
41   Sampler()
42   :mMinificationFilter(FilterMode::DEFAULT),
43    mMagnificationFilter(FilterMode::DEFAULT),
44    mSWrapMode(WrapMode::DEFAULT),
45    mTWrapMode(WrapMode::DEFAULT),
46    mRWrapMode(WrapMode::DEFAULT)
47   {}
48
49   /**
50    * Destructor
51    */
52   ~Sampler()
53   {}
54
55
56   /**
57    * Sets the filter modes for an existing sampler
58    * @param[in] sampler The sampler
59    * @param[in] minFilterMode The filter to use under minification
60    * @param[in] magFilterMode The filter to use under magnification
61    */
62   void SetFilterMode( unsigned int minFilterMode, unsigned int magFilterMode )
63   {
64     mMinificationFilter = static_cast<Dali::FilterMode::Type>(minFilterMode);
65     mMagnificationFilter = static_cast<Dali::FilterMode::Type>(magFilterMode );
66   }
67
68   /**
69    * Sets the wrap mode for an existing sampler
70    * @param[in] sampler The sampler
71    * @param[in] rWrapMode Wrapping mode in z direction
72    * @param[in] sWrapMode Wrapping mode in x direction
73    * @param[in] tWrapMode Wrapping mode in y direction
74    */
75   void SetWrapMode( unsigned int rWrapMode, unsigned int sWrapMode, unsigned int tWrapMode )
76   {
77     mRWrapMode = static_cast<Dali::WrapMode::Type>(rWrapMode);
78     mSWrapMode = static_cast<Dali::WrapMode::Type>(sWrapMode);
79     mTWrapMode = static_cast<Dali::WrapMode::Type>(tWrapMode);
80   }
81
82   bool operator==(const Sampler& rhs) const
83   {
84     return ( ( mMinificationFilter == rhs.mMinificationFilter ) &&
85              ( mMagnificationFilter == rhs.mMagnificationFilter ) &&
86              ( mSWrapMode == rhs.mSWrapMode ) &&
87              ( mTWrapMode == rhs.mTWrapMode ) &&
88              ( mRWrapMode == rhs.mRWrapMode ) );
89   }
90
91   bool operator!=(const Sampler& rhs) const
92   {
93     return !(*this == rhs);
94   }
95
96   FilterMode  mMinificationFilter   : 4;    ///< The minify filter
97   FilterMode  mMagnificationFilter  : 4;    ///< The magnify filter
98   WrapMode    mSWrapMode            : 4;    ///< The horizontal wrap mode
99   WrapMode    mTWrapMode            : 4;    ///< The vertical wrap mode
100   WrapMode    mRWrapMode            : 4;    ///< The vertical wrap mode
101 };
102
103
104 inline void SetFilterModeMessage( EventThreadServices& eventThreadServices, SceneGraph::Sampler& sampler, unsigned int minFilterMode, unsigned int magFilterMode )
105 {
106   typedef MessageValue2< SceneGraph::Sampler, unsigned int, unsigned int > LocalType;
107
108   // Reserve some memory inside the message queue
109   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ), false );
110
111   // Construct message in the message queue memory; note that delete should not be called on the return value
112   new (slot) LocalType( &sampler, &Sampler::SetFilterMode, minFilterMode, magFilterMode );
113 }
114
115 inline void SetWrapModeMessage( EventThreadServices& eventThreadServices, SceneGraph::Sampler& sampler, unsigned int rWrapMode, unsigned int sWrapMode, unsigned int tWrapMode )
116 {
117   typedef MessageValue3< SceneGraph::Sampler, unsigned int, unsigned int, unsigned int > LocalType;
118
119   // Reserve some memory inside the message queue
120   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ), false );
121
122   // Construct message in the message queue memory; note that delete should not be called on the return value
123   new (slot) LocalType( &sampler, &Sampler::SetWrapMode, rWrapMode, sWrapMode, tWrapMode );
124 }
125
126 } // namespace SceneGraph
127
128 } // namespace Internal
129
130 } // namespace Dali
131
132
133 #endif //  DALI_INTERNAL_SCENE_GRAPH_SAMPLER_H