[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / visual-factory / visual-factory.cpp
1 /*
2  * Copyright (c) 2023 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 "visual-factory.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/adaptor-framework/environment-variable.h>
23 #include <dali/devel-api/common/singleton-service.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/visuals/visual-factory-impl.h>
27
28 namespace Dali
29 {
30 namespace Toolkit
31 {
32 namespace
33 {
34 const char* const DALI_DEBUG_RENDERING("DALI_DEBUG_RENDERING");
35 }
36
37 VisualFactory VisualFactory::Get()
38 {
39   VisualFactory factory;
40
41   // Check whether the VisualFactory is already created
42   SingletonService singletonService(SingletonService::Get());
43   if(singletonService)
44   {
45     BaseHandle handle = singletonService.GetSingleton(typeid(VisualFactory));
46     if(handle)
47     {
48       //If so, downcast the handle of singleton to VisualFactory
49       factory = VisualFactory(dynamic_cast<Internal::VisualFactory*>(handle.GetObjectPtr()));
50     }
51
52     if(!factory) // If not, create the VisualFactory and register it as a singleton
53     {
54       // Check whether debug rendering is required
55       if(EnvironmentVariable::GetEnvironmentVariable(DALI_DEBUG_RENDERING))
56       {
57         factory = VisualFactory(new Internal::VisualFactory(true));
58       }
59       else
60       {
61         factory = VisualFactory(new Internal::VisualFactory(false));
62       }
63       singletonService.Register(typeid(VisualFactory), factory);
64     }
65   }
66
67   return factory;
68 }
69
70 VisualFactory::VisualFactory()
71 {
72 }
73
74 VisualFactory::~VisualFactory()
75 {
76 }
77
78 VisualFactory::VisualFactory(const VisualFactory& handle)
79 : BaseHandle(handle)
80 {
81 }
82
83 VisualFactory& VisualFactory::operator=(const VisualFactory& handle)
84 {
85   BaseHandle::operator=(handle);
86   return *this;
87 }
88
89 VisualFactory::VisualFactory(Internal::VisualFactory* impl)
90 : BaseHandle(impl)
91 {
92 }
93
94 Visual::Base VisualFactory::CreateVisual(const Property::Map& propertyMap)
95 {
96   return GetImplementation(*this).CreateVisual(propertyMap);
97 }
98
99 Visual::Base VisualFactory::CreateVisual(const std::string& url, ImageDimensions size)
100 {
101   return GetImplementation(*this).CreateVisual(url, size);
102 }
103
104 void VisualFactory::SetPreMultiplyOnLoad(bool preMultiply)
105 {
106   GetImplementation(*this).SetPreMultiplyOnLoad(preMultiply);
107 }
108
109 bool VisualFactory::GetPreMultiplyOnLoad() const
110 {
111   return GetImplementation(*this).GetPreMultiplyOnLoad();
112 }
113
114 void VisualFactory::DiscardVisual(Visual::Base visual)
115 {
116   GetImplementation(*this).DiscardVisual(visual);
117 }
118
119 void VisualFactory::UsePreCompiledShader()
120 {
121   GetImplementation(*this).UsePreCompiledShader();
122 }
123
124 } // namespace Toolkit
125
126 } // namespace Dali