Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-core.git] / dali / internal / update / nodes / scene-graph-layer.cpp
1 /*
2  * Copyright (c) 2021 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/actors/layer-impl.h>
20 #include <dali/internal/update/nodes/scene-graph-layer.h>
21
22 // INTERNAL INCLUDES
23 #include <dali/public-api/common/dali-common.h>
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29 namespace SceneGraph
30 {
31 SceneGraph::Layer* Layer::New()
32 {
33   // Layers are currently heap allocated, unlike Nodes which are in a memory pool
34   // However Node::Delete( layer ) will correctly delete a layer / node depending on type
35   return new Layer();
36 }
37
38 Layer::Layer()
39 : Node(),
40   mSortFunction(Internal::Layer::ZValue),
41   mClippingBox(0, 0, 0, 0),
42   mLastCamera(nullptr),
43   mBehavior(Dali::Layer::LAYER_UI),
44   mIsClipping(false),
45   mDepthTestDisabled(true),
46   mIsDefaultSortFunction(true)
47 {
48   // set a flag the node to say this is a layer
49   mIsLayer = true;
50
51   // layer starts off dirty
52   mAllChildTransformsClean[0] = false;
53   mAllChildTransformsClean[1] = false;
54 }
55
56 Layer::~Layer() = default;
57
58 void Layer::SetSortFunction(Dali::Layer::SortFunctionType function)
59 {
60   if(mSortFunction != function)
61   {
62     // is a custom sort function used
63     if(function != Internal::Layer::ZValue)
64     {
65       mIsDefaultSortFunction = false;
66     }
67     else
68     {
69       mIsDefaultSortFunction = true;
70     }
71
72     // changing the sort function makes the layer dirty
73     mAllChildTransformsClean[0] = false;
74     mAllChildTransformsClean[1] = false;
75     mSortFunction               = function;
76   }
77 }
78
79 void Layer::SetClipping(bool enabled)
80 {
81   mIsClipping = enabled;
82 }
83
84 void Layer::SetClippingBox(const Dali::ClippingBox& box)
85 {
86   mClippingBox.Set(box.x, box.y, box.width, box.height);
87 }
88
89 void Layer::SetBehavior(Dali::Layer::Behavior behavior)
90 {
91   mBehavior = behavior;
92 }
93
94 void Layer::SetDepthTestDisabled(bool disable)
95 {
96   mDepthTestDisabled = disable;
97 }
98
99 bool Layer::IsDepthTestDisabled() const
100 {
101   return mDepthTestDisabled;
102 }
103
104 void Layer::ClearRenderables()
105 {
106   colorRenderables.Clear();
107   overlayRenderables.Clear();
108 }
109
110 } // namespace SceneGraph
111
112 } // namespace Internal
113
114 } // namespace Dali