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.
19 * @file FUiCtrlOverlayRegion.cpp
20 * @brief This is the implementation file for OverlayRegion class.
23 #include <FUiCtrlOverlayRegion.h>
25 #include <FSys_SystemInfoImpl.h>
27 #include "FUi_Control.h"
28 #include "FUi_ResourceManager.h"
29 #include "FUi_CoordinateSystemUtils.h"
30 #include "FUiCtrl_OverlayRegionImpl.h"
31 #include "FUiCtrl_OverlayAgent.h"
33 #include "FUi_EcoreEvasMgr.h"
34 #include "FUi_EcoreEvas.h"
36 using namespace Tizen::Ui;
37 using namespace Tizen::Ui::Controls;
38 using namespace Tizen::Base::Collection;
39 using namespace Tizen::Graphics;
41 namespace Tizen { namespace Ui { namespace Controls
44 OverlayRegion::OverlayRegion(void)
45 : __pOverlayRegionImpl(null)
50 OverlayRegion::~OverlayRegion(void)
52 delete __pOverlayRegionImpl;
53 __pOverlayRegionImpl = null;
56 Tizen::Graphics::Rectangle
57 OverlayRegion::GetBounds(void) const
59 if (__pOverlayRegionImpl == null)
61 SysAssertf(__pOverlayRegionImpl != null, "Not yet constructed. Construct() should be called before use.");
62 return Tizen::Graphics::Rectangle();
65 return __pOverlayRegionImpl->GetBounds();
69 OverlayRegion::GetBounds(int& x, int& y, int& width, int& height) const
71 SysAssertf(__pOverlayRegionImpl != null, "Not yet constructed. Construct() should be called before use.");
73 __pOverlayRegionImpl->GetBounds(x, y, width, height);
79 OverlayRegion::SetInputBuffer(const Tizen::Base::ByteBuffer& srcBuffer, const Tizen::Graphics::Dimension& sourceDim, Tizen::Ui::Controls::OverlayRegionBufferPixelFormat srcFormat)
81 SysAssertf(__pOverlayRegionImpl != null, "Not yet constructed. Construct() should be called before use.");
83 result r = __pOverlayRegionImpl->SetInputBuffer(srcBuffer, sourceDim, srcFormat, true);
84 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
90 OverlayRegion::GetBackgroundBufferInfo(Tizen::Graphics::BufferInfo& info) const
92 SysAssertf(__pOverlayRegionImpl != null, "Not yet constructed. Construct() should be called before use.");
94 result r = __pOverlayRegionImpl->GetBackgroundBufferInfo(info);
95 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
101 OverlayRegion::Show(void)
103 SysAssertf(__pOverlayRegionImpl != null, "Not yet constructed. Construct() should be called before use.");
105 result r = __pOverlayRegionImpl->Show();
106 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
112 OverlayRegion::EvaluateBounds(OverlayRegionEvaluationOption option, Tizen::Graphics::Rectangle& rect, bool& modified)
116 if (rect.width <= 0 || rect.height <= 0)
118 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "[E_INVALID_ARG] input rect size is invalid.");
122 Tizen::Graphics::Rectangle physicalRect(_CoordinateSystemUtils::Transform(rect));
123 SysLog(NID_UI_CTRL, "org user rect width : %d Height : %d , org physicalRect[%d, %d]!", rect.width, rect.height, physicalRect.width, physicalRect.height);
125 int deviceLcdWidth = 0;
126 int deviceLcdHeight = 0;
128 SysTryReturn(NID_UI_CTRL, Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/screen.width", deviceLcdWidth) == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] failed to get the value of ScreenWidth from SystemInfo.");
129 SysTryReturn(NID_UI_CTRL, Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/screen.height", deviceLcdHeight) == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] failed to get the value of ScreenHeight from SystemInfo.");
131 const int widthUnit = GetWidthUnit();
132 const int heightUnit = GetHeightUnit();
134 if (widthUnit == -1 || heightUnit == -1)
136 SetLastResult(E_SYSTEM);
140 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
141 int rotation = ecore_evas_rotation_get(pEcoreEvas->GetEcoreEvas());
143 if (rotation == 90 || rotation == 270)
145 int temp = deviceLcdWidth;
146 deviceLcdWidth = deviceLcdHeight;
147 deviceLcdHeight = temp;
149 SysLog(NID_UI_CTRL, "rotate[%d] : deviceLcdWidth[%d], deviceLcdHeight[%d] is swapped", rotation, deviceLcdWidth, deviceLcdHeight);
152 int maxW = deviceLcdWidth - (deviceLcdWidth % widthUnit);
153 int maxH = deviceLcdHeight - (deviceLcdHeight % heightUnit);
155 int logicalMaxW = _CoordinateSystemUtils::InverseHorizontalTransform(maxW);
156 int logicalMaxH = _CoordinateSystemUtils::InverseVerticalTransform(maxH);
158 SysLog(NID_UI_CTRL, "logicalMax[%d, %d], physicalMax[%d, %d]!", logicalMaxW, logicalMaxH, maxW, maxH);
160 int dstMinWidth = _OverlayAgent::GetDstRectMinWidth();
161 int dstMinHeight = _OverlayAgent::GetDstRectMinHeight();
163 SysLog(NID_UI_CTRL, "dstMinDimention[%d, %d]", dstMinWidth, dstMinHeight);
165 int widthReminder = physicalRect.width % widthUnit;
166 int heightReminder = physicalRect.height % heightUnit;
170 case OVERLAY_REGION_EVALUATION_OPTION_GREATER_THAN:
172 if (physicalRect.width > maxW || physicalRect.height > maxH)
175 SysLogException(NID_UI_CTRL, E_UNSUPPORTED_OPTION, "[E_UNSUPPORTED_OPTION] the input rect size is already over physical maximun size.");
179 if (rect.width > logicalMaxW || rect.height > logicalMaxH)
182 SysLogException(NID_UI_CTRL, E_UNSUPPORTED_OPTION, "[E_UNSUPPORTED_OPTION] the input rect size is already over logical maximun size.");
186 if (widthReminder != 0)
188 widthReminder -= widthUnit;
191 if (heightReminder != 0)
193 heightReminder -= heightUnit;
196 physicalRect.width -= widthReminder;
197 physicalRect.height -= heightReminder;
199 if (physicalRect.width < dstMinWidth)
201 physicalRect.width = dstMinWidth;
204 if (physicalRect.height < dstMinHeight)
206 physicalRect.height = dstMinHeight;
210 case OVERLAY_REGION_EVALUATION_OPTION_LESS_THAN:
212 if (physicalRect.width < dstMinWidth || physicalRect.height < dstMinHeight)
215 SysLogException(NID_UI_CTRL, E_UNSUPPORTED_OPTION, "[E_UNSUPPORTED_OPTION] the input rect size doesn't meet the minimun size.");
219 if (physicalRect.width > maxW)
221 physicalRect.width = maxW + widthReminder;
222 SysLog(NID_UI_CTRL, "adjusted width [%d] [%d + %d = %d]!", physicalRect.width, maxW, widthReminder, maxW + widthReminder);
225 if (physicalRect.height > maxH)
227 physicalRect.height = maxH + heightReminder;
228 SysLog(NID_UI_CTRL, "adjusted height [%d] [%d + %d = %d]!", physicalRect.height, maxH, heightReminder, maxH+ heightReminder);
231 physicalRect.width -= widthReminder;
232 physicalRect.height -= heightReminder;
237 SysLogException(NID_UI_CTRL, E_UNSUPPORTED_OPTION, "[E_UNSUPPORTED_OPTION] option is invalid.");
241 Rectangle orgRrect(rect);
243 rect = _CoordinateSystemUtils::InverseTransform(physicalRect);
245 if (rect != orgRrect)
247 SysLog(NID_UI_CTRL, "org logical rect [%d, %d, %d, %d] changed to rect [%d, %d, %d, %d]",
248 orgRrect.x, orgRrect.y, orgRrect.width, orgRrect.height, rect.x, rect.y, rect.width, rect.height);
252 SysLog(NID_UI_CTRL, "adjusted PhysicalRect [W %d, H %d]!", physicalRect.width, physicalRect.height);
254 SetLastResult(E_SUCCESS);
259 OverlayRegion::GetWidthUnit(void)
261 int widthUnit = _OverlayRegionImpl::GetWidthUnit();
262 SysTryReturn(NID_UI_CTRL, widthUnit != -1, -1, E_SYSTEM, "[E_SYSTEM] can't get the width Unit");
268 OverlayRegion::GetHeightUnit(void)
270 int heightUnit = _OverlayRegionImpl::GetHeightUnit();
271 SysTryReturn(NID_UI_CTRL, heightUnit != -1, -1, E_SYSTEM, "[E_SYSTEM] can't get the height Unit");
277 OverlayRegion::GetMaxCount(void)
279 int maxCount = _OverlayRegionImpl::GetMaxCount();
280 SysTryReturn(NID_UI_CTRL, maxCount != -1, -1, E_SYSTEM, "[E_SYSTEM] can't get the maximum count value");
285 IListT< Tizen::Ui::Controls::OverlayRegionBufferPixelFormat >*
286 OverlayRegion::GetSupportedBufferPixelFormatListN(void)
288 if (!_OverlayRegionImpl::overlayRegionPixelFomatList[0])
290 result r = _OverlayRegionImpl::SetPixelFormatList();
291 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
294 Tizen::Base::Collection::ArrayListT<OverlayRegionBufferPixelFormat>* pFormatList = null;
296 pFormatList = new (std::nothrow) ArrayListT<OverlayRegionBufferPixelFormat>();
297 SysTryReturn(NID_UI_CTRL, pFormatList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] failed to create a list instance");
298 if (pFormatList->Construct() != E_SUCCESS)
300 SysLogException(NID_UI_CTRL, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
305 for (int i = 1; i < OVERLAY_REGION_BUFFER_PIXEL_FORMAT_MAX; i++)
307 if (_OverlayRegionImpl::overlayRegionPixelFomatList[i])
309 pFormatList->Add(static_cast<OverlayRegionBufferPixelFormat>(i));
313 SysLog(NID_UI_CTRL, "format list count : %d", pFormatList->GetCount());
315 SetLastResult(E_SUCCESS);
319 } } } // Tizen::Ui::Controls