2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 * @file FUiEffects_EffectManagerImpl.cpp
19 * @brief This is the source file for the _EffectManagerImpl class
22 #include <FUiEffects_EffectManagerImpl.h>
28 #include <FBaseColIList.h>
29 #include <FBaseSysLog.h>
30 #include <FBaseErrors.h>
31 #include <FUiTouchEventInfo.h>
33 #include <FUiEffectsEffect.h>
34 #include <FUiEffectsEffectManager.h>
35 #include <FUiEffectsEffectTouchInfo.h>
36 #include <FUiEffectsIEffectEventListener.h>
37 #include <FUiEffectsIEffectResourceProvider.h>
39 #include <FUi_CoordinateSystemUtils.h>
40 #include "FUiEffects_EffectImpl.h"
41 #include "FUiEffects_EffectManagerImpl.h"
42 #include <FUiEffects_LoggingProfiler.h>
43 #include <FUiEffects_RuntimeIEffectModelListener.h>
44 #include <FUiEffects_ParserEffectParser.h>
45 #include "FUiEffects_EffectErrorMessages.h"
47 using namespace Tizen::Ui::Controls;
48 using namespace Tizen::Base::Runtime;
49 using namespace Tizen::Ui;
50 using namespace Tizen::Base;
51 using namespace Tizen::Graphics;
52 using namespace Tizen::Base::Collection;
54 using namespace Tizen::Ui::Effects::_Runtime;
55 using namespace Tizen::Ui::Effects::_Renderer;
56 using namespace Tizen::Ui::Effects::_Parser;
57 using namespace Tizen::Ui::Effects;
58 using namespace Tizen::Ui::Effects::_Utils;
61 using namespace Tizen::Ui::Effects::_Parser;
63 namespace Tizen { namespace Ui { namespace Effects
66 _EffectManagerImpl* pEffectManagerImpl = null;
67 EffectManager* pEffectManager = null;
68 pthread_once_t once_block = PTHREAD_ONCE_INIT;
70 const char* _EffectManagerImpl::__pPathToEffectFile = null;
73 _EffectManagerImpl::CreateEffect(const Tizen::Base::String& filePath)
75 SetLastResult(E_SUCCESS);
77 bool fileExists = false;
80 std::wstring tempWStr(filePath.GetPointer());
81 std::string filePathStr(tempWStr.begin(), tempWStr.end());
82 fin.open(filePathStr.c_str(), std::ios::in);
83 fileExists = fin.is_open();
86 SysTryReturn(NID_UI_EFFECT, fileExists, null, E_FILE_NOT_FOUND, _UiEffectError::NO_EFFECT_FILE, filePathStr.c_str());
88 __pPathToEffectFile = filePathStr.c_str();
90 Effect* pEffect = new (std::nothrow) Effect();
91 SysTryReturn(NID_UI_EFFECT, pEffect != null, null, E_OUT_OF_MEMORY, _UiEffectError::OUT_OF_MEMORY);
93 result r = GetLastResult();
94 SysTryCatch(NID_UI_EFFECT, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
96 SysLog(NID_UI_EFFECT, "Effect from file '%ls' is loaded successfully", filePath.GetPointer());
105 _EffectManagerImpl::DestroyEffect(Effect& effect)
107 SetLastResult(E_SUCCESS);
109 if (_EffectImpl::__effects.find(&effect) != _EffectImpl::__effects.end())
111 SysLog(NID_UI_EFFECT, "The effect [%ls] is destroying now", effect.GetName().GetPointer());
113 SysLog(NID_UI_EFFECT, "The effect is destroyed successfully");
117 SysLog(NID_UI_EFFECT, "The effect was destroyed before");
123 _EffectManagerImpl::_EffectManagerImpl(void)
125 if (EffectRenderer::InitOpenGL())
127 SysLog(NID_UI_EFFECT, "Effects. OpenGL initialization is successful!");
131 SysLogException(NID_UI_EFFECT, E_OPERATION_FAILED, "[E_OPERATION_FAILED] OpenGL initialization failed");
135 _EffectManagerImpl::~_EffectManagerImpl(void)
137 // destroy all effects
138 // operator while is here because in Effect class destuctor we erase element from container __effects
141 if (_EffectImpl::__effects.empty())
145 delete *(_EffectImpl::__effects.begin());
148 _EffectImpl::__renderControls.clear();
149 _EffectImpl::__controlsSetPerforming.clear();
151 EffectRenderer::CloseOpenGL();
155 _EffectManagerImpl::InitSingleton(void)
157 SysAssertf(pEffectManagerImpl == null, _UiEffectError::INTERNAL_ERROR);
158 SysAssertf(pEffectManager == null, _UiEffectError::INTERNAL_ERROR);
160 std::unique_ptr<_EffectManagerImpl> pEffectManagerImplTemp(new (std::nothrow) _EffectManagerImpl());
161 SysTryReturnVoidResult(NID_UI_EFFECT, pEffectManagerImplTemp.get() != null, E_OUT_OF_MEMORY, _UiEffectError::OUT_OF_MEMORY);
163 pEffectManager = new (std::nothrow) EffectManager();
164 SysTryReturnVoidResult(NID_UI_EFFECT, pEffectManager != null, E_OUT_OF_MEMORY, _UiEffectError::OUT_OF_MEMORY);
166 pEffectManagerImpl = pEffectManagerImplTemp.release();
169 _EffectManagerImpl::ManagerAndImplPair
170 _EffectManagerImpl::GetInstance(void)
172 SetLastResult(E_SUCCESS);
174 if (pEffectManagerImpl == null)
176 SysAssertf(pEffectManager == null, _UiEffectError::INTERNAL_ERROR);
177 pthread_once(&once_block, InitSingleton);
178 result res = GetLastResult();
179 SysTryReturn(NID_UI_EFFECT, res == E_SUCCESS, std::make_pair(static_cast<EffectManager*>(null), static_cast<_EffectManagerImpl*>(null)), res, "[%s] Propagating.", GetErrorMessage(res));
182 return std::make_pair(pEffectManager, pEffectManagerImpl);
186 _EffectManagerImpl::DestroyInstance(void)
188 SetLastResult(E_SUCCESS);
189 if (pEffectManagerImpl != null)
191 SysAssertf(pEffectManager != null, _UiEffectError::INTERNAL_ERROR);
192 delete pEffectManagerImpl;
193 delete pEffectManager;
194 pEffectManagerImpl = null;
195 pEffectManager = null;
196 once_block = PTHREAD_ONCE_INIT;
201 } } } //Tizen::Ui::Effects