2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0/
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 FUi_DimmingManager.cpp
19 * @brief This is the implementation file for the _DimmingManager class.
22 #include <FBaseSysLog.h>
23 #include "FUi_Window.h"
24 #include "FUi_DimmingManager.h"
26 using namespace Tizen::Ui;
28 namespace Tizen { namespace Ui {
30 _DimmingManager* _DimmingManager::__pInstance = null;
33 _DimmingManager::GetInstance(void)
35 if (__pInstance == null)
43 _DimmingManager::Initialize(void)
45 static pthread_once_t once_block = PTHREAD_ONCE_INIT;
49 pthread_once(&once_block, InitializeInstance);
54 _DimmingManager::InitializeInstance(void)
58 if (__pInstance == null)
60 __pInstance = new (std::nothrow) _DimmingManager;
61 SysTryReturnVoidResult(NID_UI, __pInstance != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
66 _DimmingManager::ReleaseInstance(void)
75 _DimmingManager::_DimmingManager(void)
79 __pWindowList = new (std::nothrow) WindowList;
80 SysTryReturnVoidResult(NID_UI, __pWindowList, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
82 r = __pWindowList->Construct();
83 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
86 _DimmingManager::~_DimmingManager(void)
92 _DimmingManager::RegisterWindow(_Window* pWindow)
96 int count = __pWindowList->GetCount();
99 _Window* pOldWindow = null;
100 r = __pWindowList->GetAt(count - 1, pOldWindow);
101 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
102 DeleteDimmingLayer(pOldWindow);
105 r = CreateDimmingLayer(pWindow);
106 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
107 r = __pWindowList->Add(pWindow);
108 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
114 _DimmingManager::UnRegisterWindow(_Window* pWindow)
116 result r = E_SUCCESS;
118 DeleteDimmingLayer(pWindow);
119 int count = __pWindowList->GetCount();
122 r = __pWindowList->Remove(pWindow);
125 count = __pWindowList->GetCount();
128 _Window* pOldWindow = null;
129 r = __pWindowList->GetAt(count - 1, pOldWindow);
130 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
131 CreateDimmingLayer(pOldWindow);
138 _DimmingManager::CreateDimmingLayer(_Window* pWindow)
140 result r = E_SUCCESS;
142 _DimmingLayer* pDimmingLayer = new (std::nothrow) _DimmingLayer();
143 SysTryReturn(NID_UI, pDimmingLayer != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
145 r = pDimmingLayer->Construct(*pWindow);
146 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
147 pWindow->SetDimmingLayer(pDimmingLayer);
152 delete pDimmingLayer;
157 _DimmingManager::DeleteDimmingLayer(_Window* pWindow)
161 _DimmingLayer* pLayer = pWindow->GetDimmingLayer();
164 pLayer->SetDimmingEnabled(false);
167 pWindow->SetDimmingLayer(null);
172 _DimmingManager::ShowDimmingLayer(_Window* pWindow)
174 result r = E_SUCCESS;
176 _DimmingLayer* pDimmingLayer = pWindow->GetDimmingLayer();
179 if (pWindow->GetVisibleState())
181 if (pDimmingLayer->IsDimmingEnabled() == false)
183 r = pDimmingLayer->SetDimmingEnabled(true);
184 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
189 r = pDimmingLayer->SetDimmingEnabled(false);
190 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));