Merge "Fix P130821-00023 issue" into tizen_2.2
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_OverlayAgent.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
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.
16 //
17
18 /**
19  * @file                FUiCtrl_OverlayAgent.cpp
20  * @brief               This file contains implementation of _OverlayAgent class
21  */
22
23 #include <new>
24 #include <sys/shm.h>
25 #include <unique_ptr.h>
26 #include <Ecore_Evas.h>
27
28 #include <FBaseResult.h>
29 #include <FUiIOrientationEventListener.h>
30 #include <FUiAnimDisplayContext.h>
31 #include <FGrp_BufferInfoImpl.h>
32 #include <FGrp_Screen.h>
33 #include <FIo_RegistryImpl.h>
34 #include <FMedia_ImageUtil.h>
35 #include "FUi_Control.h"
36 #include "FUi_CoordinateSystemUtils.h"
37 #include "FUi_EcoreEvas.h"
38 #include "FUi_EcoreEvasMgr.h"
39 #include "FUi_Window.h"
40 #include "FUiAnim_EflNode.h"
41 #include "FUiAnim_ControlVisualElement.h"
42 #include "FUiAnim_VisualElementSurfaceImpl.h"
43 #include "FUiAnim_VisualElementImpl.h"
44 #include "FUiCtrl_OverlayAgent.h"
45
46 #define B(c,s) ((((unsigned int)(c)) & 0xff) << (s))
47 #define FOURCC(a,b,c,d) (B(d,24) | B(c,16) | B(b,8) | B(a,0))
48
49 using namespace std;
50 using namespace Tizen::Base;
51 using namespace Tizen::Base::Collection;
52 using namespace Tizen::Base::Runtime;
53 using namespace Tizen::Graphics;
54 using namespace Tizen::Io;
55 using namespace Tizen::Media;
56 using namespace Tizen::System;
57 using namespace Tizen::Ui::Controls;
58 using namespace Tizen::Ui::Animations;
59
60 namespace
61 {
62 bool
63 CheckXvExtension(Display* pDisplay, int* pFirstPort, int* pCountPort)
64 {
65         unsigned int version = 0;
66         unsigned int release = 0;
67         unsigned int requestBase = 0;
68         unsigned int eventBase = 0;
69         unsigned int errorBase = 0;
70
71         // Query and print Xvideo properties
72         int returnValue = XvQueryExtension(pDisplay, &version, &release, &requestBase, &eventBase, &errorBase);
73         if (returnValue != Success)
74         {
75                 if (returnValue == XvBadExtension)
76                 {
77                         SysSecureLog(NID_UI_CTRL, "XvBadExtension returned at XvQueryExtension!");
78                 }
79                 else if (returnValue == XvBadAlloc)
80                 {
81                         SysSecureLog(NID_UI_CTRL, "XvBadAlloc returned at XvQueryExtension!");
82                 }
83                 else
84                 {
85                         SysSecureLog(NID_UI_CTRL, "Other error happened at XvQueryExtension!");
86                 }
87
88                 return false;
89         }
90
91         unsigned int adaptors = 0;
92         XvAdaptorInfo* pAdaptorInfo = null;
93         returnValue = XvQueryAdaptors(pDisplay, DefaultRootWindow(pDisplay), &adaptors, &pAdaptorInfo);
94         if (returnValue != Success)
95         {
96                 if (returnValue == XvBadExtension)
97                 {
98                         SysSecureLog(NID_UI_CTRL, "XvBadExtension returned at XvQueryExtension.");
99                 }
100                 else if (returnValue == XvBadAlloc)
101                 {
102                         SysSecureLog(NID_UI_CTRL, "XvBadAlloc returned at XvQueryExtension.");
103                 }
104                 else
105                 {
106                         SysSecureLog(NID_UI_CTRL, "Other error happaned at XvQueryAdaptors.");
107                 }
108
109                 if (pAdaptorInfo != null)
110                 {
111                         XvFreeAdaptorInfo(pAdaptorInfo);
112                 }
113
114                 return false;
115         }
116
117         int port = -1;
118         if (adaptors > 0 && pAdaptorInfo != null)
119         {
120                 for (unsigned int i = 0; i < adaptors; i++)
121                 {
122                         for (unsigned int j = 0; j < pAdaptorInfo[i].num_formats; j++)
123                         {
124                                 SysSecureLog(NID_UI_CTRL, "The current value of depth is %d and visual is %ld.", pAdaptorInfo[i].formats[j].depth, pAdaptorInfo[i].formats[j].visual_id);
125                         }
126                 }
127
128                 port = pAdaptorInfo[0].base_id;
129
130                 *pFirstPort = port;
131                 *pCountPort = pAdaptorInfo[0].num_ports;
132                 SysSecureLog(NID_UI_CTRL, "The current value of port is %d", port);
133         }
134
135         if (pAdaptorInfo != null)
136         {
137                 XvFreeAdaptorInfo(pAdaptorInfo);
138         }
139
140         if (port == -1)
141         {
142                 return false;
143         }
144
145         return true;
146 }
147
148 Eina_Bool
149 OnPixmapDamaged(void* pData, int type, void* pEvent)
150 {
151         Ecore_X_Event_Damage* pDamageEvent = (Ecore_X_Event_Damage*)pEvent;
152         SysTryReturn(NID_UI_CTRL, pDamageEvent != null, ECORE_CALLBACK_PASS_ON, E_INVALID_DATA, "[E_INVALID_DATA] The current value of DamageEvent is invalid.");
153
154         Tizen::Ui::Controls::_OverlayAgent* pOverlayAgent = static_cast<Tizen::Ui::Controls::_OverlayAgent*>(pData);
155         SysTryReturn(NID_UI_CTRL, pOverlayAgent != null, ECORE_CALLBACK_PASS_ON, E_INVALID_DATA, "[E_INVALID_DATA] Failed to get OverlayAgent from DamagedEvent.");
156
157         if (pDamageEvent->drawable != pOverlayAgent->GetPixmap())
158         {
159                 return ECORE_CALLBACK_PASS_ON;
160         }
161
162         pOverlayAgent->SetRendererFlushNeeded();
163
164         return ECORE_CALLBACK_DONE;
165 }
166
167 void
168 OnEvasImageDamaged(void* pData, Evas_Object* pImageObject)
169 {
170         Tizen::Ui::Controls::_OverlayAgent* pOverlayAgent = static_cast<Tizen::Ui::Controls::_OverlayAgent*>(pData);
171         SysTryReturnVoidResult(NID_UI_CTRL, pOverlayAgent != null, E_INVALID_DATA, "[E_INVALID_DATA] Failed to get OverlayAgent from DamagedEvent.");
172
173         Evas_Object* pRendererImageObject = pOverlayAgent->GetRendererImageObject();
174         SysTryReturnVoidResult(NID_UI_CTRL, pRendererImageObject != null, E_INVALID_DATA, "[E_INVALID_DATA] Failed to get Renderer ImageObject of OverlayAgent.");
175
176         if (pRendererImageObject != pImageObject)
177         {
178                 return;
179         }
180
181         Dimension newImageSize(0,0);
182         evas_object_image_size_get(pImageObject, &newImageSize.width, &newImageSize.height);
183
184         Dimension rendererImageSize(0,0);
185         evas_object_image_size_get(pRendererImageObject, &rendererImageSize.width, &rendererImageSize.height);
186
187         //pOverlayAgent->SetRendererFlushNeeded();
188
189         if (!newImageSize.Equals(rendererImageSize))
190         {
191                 SysSecureLog(NID_UI_CTRL,"newImageSize [%d, %d] rendererImageSize [%d, %d]", newImageSize.width, newImageSize.height, rendererImageSize.width, rendererImageSize.height);
192                 pOverlayAgent->SetDestination(FloatDimension(static_cast<float>(newImageSize.width), static_cast<float>(newImageSize.height)));
193         }
194 }
195 } // Anonymous
196
197 namespace Tizen { namespace Ui { namespace Controls
198 {
199
200 int _OverlayAgent::__baseXvPort = 0;
201 bool _OverlayAgent::__isPortGrabbed[]={false,};
202
203 int _OverlayAgent::__overlayAgentCount = 0;
204 int _OverlayAgent::__dstRectMinWidth = -1;
205 int _OverlayAgent::__dstRectMinHegith = -1;
206 int _OverlayAgent::__srcRectMinWidth = -1;
207 int _OverlayAgent::__srcRectMinHegith = -1;
208 int _OverlayAgent::__overlayWidthUnit = -1;
209 int _OverlayAgent::__overlayHeightUnit = -1;
210 int _OverlayAgent::__overlayMaxCount = -1;
211 bool _OverlayAgent::__OverlayAgentBufferPixelFormat[] = {false, };
212
213 struct visualElementDeleter
214 {
215         void operator()(_VisualElement* pVisualElement)
216         {
217                 pVisualElement->Destroy();
218         }
219 };
220
221 _OverlayAgent::_OverlayVisualElement::_OverlayVisualElement(void)
222         : __pOverlayTimer(null)
223         , __pImageObject(null)
224         , __showStateChanged(false)
225 {
226 }
227
228 _OverlayAgent::_OverlayVisualElement::_OverlayVisualElement(const _OverlayVisualElement& rhs)
229         : _VisualElement(rhs)
230         , __pOverlayTimer(null)
231         , __pImageObject(rhs.__pImageObject)
232         , __showStateChanged(rhs.__showStateChanged)
233 {
234 }
235
236 _OverlayAgent::_OverlayVisualElement::~_OverlayVisualElement(void)
237 {
238         if (__pOverlayTimer)
239         {
240                 __pOverlayTimer->Cancel();
241                 delete __pOverlayTimer;
242                 __pOverlayTimer = null;
243         }
244
245         if (__pImageObject)
246         {
247                 evas_object_event_callback_del(__pImageObject, EVAS_CALLBACK_SHOW, OnImageObjectShown);
248                 evas_object_event_callback_del(__pImageObject, EVAS_CALLBACK_HIDE, OnImageObjectHidden);
249         }
250 }
251
252 result
253 _OverlayAgent::_OverlayVisualElement::Construct(void)
254 {
255         if (!__pOverlayTimer)
256         {
257                 __pOverlayTimer = new (nothrow) Timer();
258                 __pOverlayTimer->Construct(*this);
259         }
260
261         return _VisualElement::Construct();
262 }
263
264 Evas_Object*
265 _OverlayAgent::_OverlayVisualElement::GetImageObject(void) const
266 {
267         return __pImageObject;
268 }
269
270 void
271 _OverlayAgent::_OverlayVisualElement::SetImageObject(Evas_Object* pImageObject)
272 {
273         if (__pImageObject)
274         {
275                 evas_object_event_callback_del(__pImageObject, EVAS_CALLBACK_SHOW, OnImageObjectShown);
276                 evas_object_event_callback_del(__pImageObject, EVAS_CALLBACK_HIDE, OnImageObjectHidden);
277         }
278
279         __pImageObject = pImageObject;
280
281         if (__pImageObject)
282         {
283                 evas_object_event_callback_add(__pImageObject, EVAS_CALLBACK_SHOW, OnImageObjectShown, this);
284                 evas_object_event_callback_add(__pImageObject, EVAS_CALLBACK_HIDE, OnImageObjectHidden, this);
285         }
286 }
287
288 void
289 _OverlayAgent::_OverlayVisualElement::SetImageObjectShowStateChanged(void)
290 {
291         __showStateChanged = true;
292
293         if (IsFailed(__pOverlayTimer->Start(0)))
294         {
295                 __pOverlayTimer->Cancel();
296                 __pOverlayTimer->Start(0);
297                 SysSecureLog(NID_UI_CTRL, "The timer is restarted.");
298         }
299 }
300
301 void
302 _OverlayAgent::_OverlayVisualElement::OnImageObjectShown(void* pData, Evas *pEvas, Evas_Object *pImageObject, void *event_info)
303 {
304         _OverlayVisualElement* pOverlayVE = reinterpret_cast<_OverlayVisualElement*>(pData);
305         if (pOverlayVE)
306         {
307                 pOverlayVE->SetImageObjectShowStateChanged();
308                 SysSecureLog(NID_UI_CTRL, "The show state of Renderer VisualElement is set to SHOW");
309         }
310 }
311
312 void
313 _OverlayAgent::_OverlayVisualElement::OnImageObjectHidden(void* pData, Evas *pEvas, Evas_Object *pImageObject, void *event_info)
314 {
315         _OverlayVisualElement* pOverlayVE = reinterpret_cast<_OverlayVisualElement*>(pData);
316         if (pOverlayVE)
317         {
318                 pOverlayVE->SetImageObjectShowStateChanged();
319                 SysSecureLog(NID_UI_CTRL, "The show state of Renderer VisualElement is set to HIDE");
320         }
321 }
322
323 VisualElement*
324 _OverlayAgent::_OverlayVisualElement::CloneN(void) const
325 {
326         return new (nothrow) _OverlayVisualElement(*this);
327 }
328
329 void
330 _OverlayAgent::_OverlayVisualElement::OnTimerExpired(Timer& timer)
331 {
332         if (&timer == __pOverlayTimer && __showStateChanged && __pImageObject)
333         {
334                 SetShowState(evas_object_visible_get(__pImageObject));
335                 __showStateChanged = false;
336                 SysSecureLog(NID_UI_CTRL, "Updates show state of Renderer VisualElement");
337         }
338         else
339         {
340                 SysSecureLog(NID_UI_CTRL, "The state of timer is invalid.");
341         }
342 }
343
344 _OverlayAgent*
345 _OverlayAgent::CreateInstanceN(_OverlayAgentStyle style, const _Control& parentControl, const FloatRectangle& logicalBounds, const Rectangle& physicalBounds)
346 {
347         unique_ptr<_OverlayAgent> pOverlayAgent(new (nothrow) _OverlayAgent(style, parentControl, logicalBounds, physicalBounds));
348         SysTryReturn(NID_UI_CTRL, pOverlayAgent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
349
350         result r = GetLastResult();
351         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
352
353         return pOverlayAgent.release();
354 }
355
356 _OverlayAgent::_OverlayAgent(_OverlayAgentStyle style, const _Control& parentControl, const FloatRectangle& logicalBounds, const Rectangle& physicalBounds)
357         : __pRendererVE(null)
358         , __pParentVE(null)
359         , __pImageObject(null)
360         , __style(style)
361         , __currentRotation(_OVERLAY_AGENT_ROTATION_NONE)
362         , __savedColorFormat(FOURCC('R','G','B','4'))
363         , __currentColorFormat(_OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_ARGB8888)
364         , __currentSourceBufferSize(0,0)
365         , __standardRendererBounds(0.0f, 0.0f, 0.0f, 0.0f)
366         , __standardParentBounds(0.0f, 0.0f, 0.0f, 0.0f)
367         , __needToRellaocImage(false)
368         , __pCurrentSourceBuffer(null)
369         , __pConvertedSourceBuffer(null)
370         , __pixmapDamageHandle(0)
371         , __pPixmapEventHandler(null)
372         , __pixmap(0)
373         , __xvPort(-1)
374         , __pXvImage(null)
375         , __pShmInfo(null)
376 {
377         result r = CreateRendererVisualElement(parentControl, logicalBounds, physicalBounds);
378
379         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
380         SysTryReturnVoidResult(NID_UI_CTRL, __pRendererVE != null, E_SYSTEM, "[E_SYSTEM] The Renderer VisualElement is null.");
381         SysTryReturnVoidResult(NID_UI_CTRL, __pImageObject!= null, E_SYSTEM, "[E_SYSTEM] The Renderder ImageObject is null.");
382
383         __overlayAgentCount++;
384         SysLog(NID_UI_CTRL, "The current count of OverlayAgent is %d", __overlayAgentCount);
385 }
386
387 _OverlayAgent::~_OverlayAgent(void)
388 {
389         SysLog(NID_UI_CTRL, "The %dth OverlayAgent is deleted.", __overlayAgentCount);
390         __overlayAgentCount--;
391
392         if (__xvPort > 0)
393         {
394                 UngrabXvPort();
395         }
396
397         if (__pPixmapEventHandler)
398         {
399                 ecore_event_handler_del(__pPixmapEventHandler);
400                 __pPixmapEventHandler = null;
401         }
402
403         if (__pixmapDamageHandle)
404         {
405                 ecore_x_damage_free(__pixmapDamageHandle);
406                 __pixmapDamageHandle = 0;
407         }
408
409         if (__pixmap != 0)
410         {
411                 XFreePixmap((Display*)ecore_x_display_get(), __pixmap);
412                 __pixmap = 0;
413         }
414
415         if (__pShmInfo)
416         {
417                 XShmDetach((Display*)ecore_x_display_get(), __pShmInfo);
418                 shmdt(__pShmInfo->shmaddr);
419                 shmctl(__pShmInfo->shmid, IPC_RMID, NULL);
420                 __pShmInfo = null;
421         }
422
423         if (__pXvImage)
424         {
425                 XFree(__pXvImage);
426                 __pXvImage = null;
427         }
428
429         if (__pConvertedSourceBuffer)
430         {
431                 delete __pConvertedSourceBuffer;
432                 __pConvertedSourceBuffer = null;
433         }
434
435         if (__pCurrentSourceBuffer)
436         {
437                 delete __pCurrentSourceBuffer;
438                 __pCurrentSourceBuffer = null;
439         }
440
441         if (__pRendererVE != null)
442         {
443                 __pRendererVE->SetSurface(null);
444                 __pRendererVE->Destroy();
445                 __pRendererVE = null;
446         }
447
448         if (__pImageObject)
449         {
450                 evas_object_del(__pImageObject);
451                 __pImageObject = null;
452         }
453 }
454
455 result
456 _OverlayAgent::GetBufferInfo(BufferInfo& bufferInfo) const
457 {
458         SysTryReturnResult(NID_UI_CTRL, __pImageObject != null, E_SYSTEM, "The Renderer ImageObject is null.");
459         SysTryReturnResult(NID_UI_CTRL, __pRendererVE != null, E_SYSTEM, "The Renderer Visual Element is null.");
460
461         int width = 0;
462         int height = 0;
463         evas_object_geometry_get(__pImageObject, NULL, NULL, &width, &height);
464
465         bufferInfo.width = width;
466         bufferInfo.pitch = width;
467         bufferInfo.height = height;
468         bufferInfo.bitsPerPixel = 32;
469         bufferInfo.pixelFormat = PIXEL_FORMAT_ARGB8888;
470
471         _BufferInfoImpl* pBufferInfoImpl = _BufferInfoImpl::GetInstance(bufferInfo);
472         SysTryReturnResult(NID_UI_CTRL, pBufferInfoImpl != null, E_SYSTEM, "Failed to get instance of buffer info.");
473
474         result r = E_SUCCESS;
475
476         if(__style == _OVERLAY_AGENT_STYLE_REGION_SW || __style == _OVERLAY_AGENT_STYLE_PANEL_SW)
477         {
478                 pBufferInfoImpl->SetHandle(_BufferInfoImpl::HANDLE_TYPE_VE_SURFACE, reinterpret_cast<Handle>(__pImageObject));
479                 SysSecureLog(NID_UI_CTRL,"The returned handle of BufferInfo is a evas image object (HANDLE_TYPE_VE_SURFACE)");
480         }
481         else
482         {
483                 pBufferInfoImpl->SetHandle(_BufferInfoImpl::HANDLE_TYPE_OVERLAY_REGION, __pixmap);
484                 SysSecureLog(NID_UI_CTRL,"The returned handle of BufferInfo is a pixmap (HANDLE_TYPE_OVERLAY_REGION)");
485         }
486
487         pBufferInfoImpl->SetBounds(Rectangle(0, 0, width, height));
488
489         return r;
490 }
491
492 result
493 _OverlayAgent::SetInputBuffer(const ByteBuffer& srcBuffer, const Dimension& srcDim, _OverlayAgentBufferPixelFormat srcFormat)
494 {
495         SysTryReturnResult(NID_UI_CTRL, srcBuffer.GetPointer() != null, E_INVALID_ARG, "The current value of input source buffer is invalid.");
496         SysTryReturnResult(NID_UI_CTRL, srcBuffer.GetCapacity() > 0, E_INVALID_ARG, "The current size of input source buffer is invalid.");
497         SysTryReturnResult(NID_UI_CTRL, srcDim.width >= GetSrcRectMinWidth(), E_INVALID_ARG, "The width of dimension [%d] is under the minimum size.", srcDim.width);
498         SysTryReturnResult(NID_UI_CTRL, srcDim.height >= GetSrcRectMinHeight(), E_INVALID_ARG, "The height of dimension [%d] is under the minimum size.", srcDim.height);
499
500         if (__currentColorFormat != srcFormat)
501         {
502                 unsigned int colorFormat = 0;
503
504                 switch (srcFormat)
505                 {
506                 case _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_ARGB8888:
507                         colorFormat = FOURCC('R','G','B','4');
508                         break;
509                 case _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_RGB565:
510                         colorFormat = FOURCC('R','G','B','P');
511                         break;
512                 case _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_YCbCr420_PLANAR:
513                         colorFormat = FOURCC('I','4','2','0');
514                         break;
515                 case _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_NV12:
516                         colorFormat = FOURCC('N','V','1','2');
517                         break;
518                 case _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_UYVY:
519                         colorFormat = FOURCC('U','Y','V','Y');
520                         break;
521                 default:
522                         SysLogException(NID_UI_CTRL, E_UNSUPPORTED_FORMAT, "The specified pixel format is not supported.");
523                         return E_UNSUPPORTED_FORMAT;
524                 }
525
526                 __savedColorFormat = colorFormat;
527                 __currentColorFormat = srcFormat;
528                 __needToRellaocImage = true;
529         }
530
531         if (!srcDim.Equals(__currentSourceBufferSize))
532         {
533                 __currentSourceBufferSize.width = srcDim.width;
534                 __currentSourceBufferSize.height = srcDim.height;
535                 __needToRellaocImage = true;
536         }
537
538         __pCurrentSourceBuffer = &srcBuffer;
539
540         if (__needToRellaocImage)
541         {
542                 SysSecureLog(NID_UI_CTRL,"The current buffer pointer is %x, size is %d, color format is %d",
543                         __pCurrentSourceBuffer->GetPointer(), __pCurrentSourceBuffer->GetCapacity(), __savedColorFormat);
544         }
545
546         return E_SUCCESS;
547 }
548
549 result
550 _OverlayAgent::Draw(void)
551 {
552         SysTryReturnResult(NID_UI_CTRL, __pCurrentSourceBuffer->GetPointer() != null, E_SYSTEM, "The current input user buffer is null. (nothing to draw)");
553
554         result r = E_SUCCESS;
555
556         if(__style == _OVERLAY_AGENT_STYLE_REGION_SW || __style == _OVERLAY_AGENT_STYLE_PANEL_SW)
557         {
558                 r = PutEvasImage();
559         }
560         else
561         {
562                 r = PutXvImage();
563         }
564
565         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Propagating.");
566
567         return r;
568 }
569
570
571 result
572 _OverlayAgent::GrabXvPort(void)
573 {
574         Display* pDisplay = (Display*)ecore_x_display_get();
575         SysTryReturnResult(NID_UI_CTRL, pDisplay != null, E_SYSTEM, "The current value of Display is null");
576
577         int baseXvPort = -1;
578         int portCount = -1;
579         if (!CheckXvExtension(pDisplay, &baseXvPort, &portCount))
580         {
581                 SysTryReturnResult(NID_UI_CTRL, false, E_SYSTEM, "Failed to check XvExtension");
582         }
583
584         SysTryReturnResult(NID_UI_CTRL, baseXvPort > 0, E_SYSTEM, "The current value of base XvPort is invalid.");
585         SysTryReturnResult(NID_UI_CTRL, portCount >= 1 && portCount <= _OVERLAYAGENT_XV_PORT, E_SYSTEM, "The current count of available XvPort[%d] is invalid.", portCount);
586
587         _OverlayAgent::__baseXvPort = baseXvPort;
588
589         for (int index = 0; index < portCount; index++)
590         {
591                 if(!__isPortGrabbed[index])
592                 {
593                         int tempPort = __baseXvPort + index;
594                         if (XvGrabPort(pDisplay, tempPort, 0) != Success)
595                         {
596                                 SysSecureLog(NID_UI_CTRL, "The current XvPort[%d] has been alreadly used by another process", tempPort);
597                         }
598                         else
599                         {
600                                 __xvPort = tempPort;
601                                 __isPortGrabbed[index] = true;
602                                 break;
603                         }
604                 }
605         }
606
607         SysTryReturnResult(NID_UI_CTRL, __xvPort > 0, E_SYSTEM, "Failed to grab pixmap[%d]", __pixmap);
608         SysSecureLog(NID_UI_CTRL, "The current value of grabbed XvPort is [%d] and pixmap is [%d]", __xvPort, __pixmap);
609
610         return E_SUCCESS;
611 }
612
613 void
614 _OverlayAgent::UngrabXvPort(void)
615 {
616         ClearLastResult();
617
618         if (__xvPort > 0 && (__xvPort - __baseXvPort) >= 0 && __isPortGrabbed[__xvPort - __baseXvPort])
619         {
620                 Display* pDisplay = (Display*) ecore_x_display_get();
621                 Atom atom = XInternAtom(pDisplay, "_USER_WM_PORT_ATTRIBUTE_STREAM_OFF", False);
622                 XvSetPortAttribute(pDisplay, __xvPort, atom, 1);
623                 XvUngrabPort(pDisplay, __xvPort, 0);
624
625                 SysSecureLog(NID_UI_CTRL, "The current value of ungrabbed XvPort is %d, and pixmap is %d", __xvPort, __pixmap);
626
627                 __isPortGrabbed[__xvPort - __baseXvPort] = false;
628                 __xvPort = -1;
629         }
630 }
631
632 result
633 _OverlayAgent::PutXvImage(void)
634 {
635         SysTryReturnResult(NID_UI_CTRL, __pixmap != 0, E_SYSTEM, "The current value of pixmap is null");
636
637         Display* pDisplay = (Display*)ecore_x_display_get();
638         SysTryReturnResult(NID_UI_CTRL, pDisplay != null, E_SYSTEM, "The current value of Display is null");
639
640         if (__pXvImage == null || __needToRellaocImage)
641                 //||(__pXvImage && __pXvImage->data_size != currentSourceBufferSize->GetCapacity()) )
642         {
643                 if (__xvPort != -1)
644                 {
645                         UngrabXvPort();
646                 }
647
648                 if (__pXvImage != null)
649                 {
650                         if (__pShmInfo)
651                         {
652                                 XShmDetach(pDisplay, __pShmInfo);
653                                 shmdt(__pShmInfo->shmaddr);
654                                 shmctl(__pShmInfo->shmid, IPC_RMID, NULL);
655                                 delete __pShmInfo;
656                                 __pShmInfo = null;
657                         }
658
659                         if (__pXvImage)
660                         {
661                                 XFree(__pXvImage);
662                                 __pXvImage = null;
663                         }
664                 }
665         }
666
667         if (__xvPort == -1)
668         {
669                 result r = GrabXvPort();
670                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Propagating.");
671         }
672
673         if (__needToRellaocImage)
674         {
675                 XShmSegmentInfo* pShmInfo = new (std::nothrow) XShmSegmentInfo();
676                 SysTryReturnResult(NID_UI_CTRL, pShmInfo != null, E_SYSTEM, "Failed to create XShmSegmentInfo");
677
678                 XvImage* pXvImage = XvShmCreateImage(pDisplay, __xvPort, __savedColorFormat, 0, __currentSourceBufferSize.width, __currentSourceBufferSize.height, pShmInfo);
679                 SysTryReturnResult(NID_UI_CTRL, pXvImage != null, E_SYSTEM, "Failed to create XvImage");
680
681                 pShmInfo->shmid = shmget(IPC_PRIVATE, pXvImage->data_size, IPC_CREAT | 0777);
682                 pShmInfo->shmaddr = pXvImage->data = (char*)shmat(pShmInfo->shmid, 0, 0);
683                 pShmInfo->readOnly = False;
684
685                 if (!XShmAttach(pDisplay, pShmInfo))
686                 {
687                         XFree(pXvImage);
688                         SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Failed to XShmAttach.");
689                         return E_SYSTEM;
690                 }
691
692                 __pXvImage = pXvImage;
693                 __pShmInfo = pShmInfo;
694         }
695
696         if (__pXvImage == null)
697         {
698                 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Failed to get XvImage");
699                 return E_SYSTEM;
700         }
701
702         memcpy(__pXvImage->data, __pCurrentSourceBuffer->GetPointer(), __pXvImage->data_size);
703         __pCurrentSourceBuffer = null;
704
705         int imageWidth = 0;
706         int imageHeight = 0;
707         evas_object_image_size_get(__pImageObject, &imageWidth, &imageHeight);
708
709         GC gc= DefaultGCOfScreen(DefaultScreenOfDisplay(pDisplay));
710         XvShmPutImage(pDisplay, __xvPort, __pixmap, gc, __pXvImage, 0, 0, __currentSourceBufferSize.width, __currentSourceBufferSize.height, 0, 0, imageWidth, imageHeight, False);
711         XSync(pDisplay, 0);
712
713         if (__needToRellaocImage)
714         {
715                 SysSecureLog(NID_UI_CTRL, "The current value of source buffer size is [%d,%d]", __currentSourceBufferSize.width, __currentSourceBufferSize.height);
716                 SysSecureLog(NID_UI_CTRL, "The current value of destination XvImage size is [%d,%d]", imageWidth, imageHeight);
717                 __needToRellaocImage = false;
718         }
719
720         result r = __pRendererVE->SetFlushNeeded();
721         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r,"[%s] Propagating.", GetErrorMessage(r));
722
723         return r;
724 }
725
726 result
727 _OverlayAgent::PutEvasImage(void)
728 {
729         SysTryReturnResult(NID_UI_CTRL, __pImageObject != null, E_SYSTEM, "The current value of Renderer ImageObject is null");
730         SysTryReturnResult(NID_UI_CTRL, __pCurrentSourceBuffer->GetPointer() != null, E_SYSTEM, "The current value of Renderer byte buffer is null");
731
732         result r = E_SUCCESS;
733
734         // Create new buffer to convert pixel format
735         if (__needToRellaocImage || __pConvertedSourceBuffer == null ||
736                 !(__pConvertedSourceBuffer && (__pConvertedSourceBuffer->GetCapacity() == __pCurrentSourceBuffer->GetCapacity())))
737         {
738                 if (__pConvertedSourceBuffer != null)
739                 {
740                         __pConvertedSourceBuffer->SetPosition(0);
741                         delete __pConvertedSourceBuffer;
742                         __pConvertedSourceBuffer = null;
743                 }
744
745                 __pConvertedSourceBuffer = new (std::nothrow) ByteBuffer;
746                 SysTryReturnResult(NID_UI_CTRL, __pConvertedSourceBuffer != null, E_OUT_OF_MEMORY, "Failed to create a ByteBuffer for Evas Image Object.");
747
748                 r = __pConvertedSourceBuffer->Construct(__currentSourceBufferSize.width * __currentSourceBufferSize.height * 4);
749                 if (r != E_SUCCESS)
750                 {
751                         delete __pConvertedSourceBuffer;
752                         __pConvertedSourceBuffer = null;
753                         SysLogException(NID_UI_CTRL, r, "[%s] Failed to construct a byte buffer for EvasImageObject.", GetErrorMessage(r));
754
755                         return r;
756                 }
757         }
758
759         __pConvertedSourceBuffer->SetPosition(0);
760
761         switch (__currentColorFormat)
762         {
763         case _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_ARGB8888:
764                 r = __pConvertedSourceBuffer->SetArray(__pCurrentSourceBuffer->GetPointer(), 0, __pConvertedSourceBuffer->GetCapacity());
765                 break;
766         case _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_RGB565:
767                 r = _ImageUtil::ConvertPixelFormat(*__pCurrentSourceBuffer, MEDIA_PIXEL_FORMAT_RGB565LE, __currentSourceBufferSize.width, __currentSourceBufferSize.height, *__pConvertedSourceBuffer, MEDIA_PIXEL_FORMAT_BGRA8888);
768                 break;
769         case _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_YCbCr420_PLANAR:
770                 r = _ImageUtil::ConvertPixelFormat(*__pCurrentSourceBuffer, MEDIA_PIXEL_FORMAT_YUV420P, __currentSourceBufferSize.width, __currentSourceBufferSize.height, *__pConvertedSourceBuffer, MEDIA_PIXEL_FORMAT_BGRA8888);
771                 break;
772         case _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_NV12:
773                 r = _ImageUtil::ConvertPixelFormat(*__pCurrentSourceBuffer, MEDIA_PIXEL_FORMAT_NV12, __currentSourceBufferSize.width, __currentSourceBufferSize.height, *__pConvertedSourceBuffer, MEDIA_PIXEL_FORMAT_BGRA8888);
774                 break;
775         case _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_UYVY:
776                 r = _ImageUtil::ConvertPixelFormat(*__pCurrentSourceBuffer, MEDIA_PIXEL_FORMAT_UYVY422, __currentSourceBufferSize.width, __currentSourceBufferSize.height, *__pConvertedSourceBuffer, MEDIA_PIXEL_FORMAT_BGRA8888);
777                 break;
778         default:
779                 SysLogException(NID_UI_CTRL, E_UNSUPPORTED_FORMAT, "[E_UNSUPPORTED_FORMAT] The specified pixel format is not supported.");
780                 return E_UNSUPPORTED_FORMAT;
781         }
782
783         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r,"Propagating.");
784
785         __pCurrentSourceBuffer = null;
786         void* pImageData = (void*)(__pConvertedSourceBuffer->GetPointer());
787         SysTryReturnResult(NID_UI_CTRL, pImageData != null, E_SYSTEM, "The converted image data for Overlay Renderer VisualElement is invalid.");
788
789         evas_object_image_size_set(__pImageObject, __currentSourceBufferSize.width, __currentSourceBufferSize.height);
790         evas_object_image_data_set(__pImageObject, pImageData);
791         evas_object_image_data_update_add(__pImageObject, 0, 0, __currentSourceBufferSize.width, __currentSourceBufferSize.height);
792         evas_object_show(__pImageObject);
793
794         if (__needToRellaocImage)
795         {
796                 SysSecureLog(NID_UI_CTRL, "The current value of source buffer bounds is [%d,%d,%d, %d]", 0, 0, __currentSourceBufferSize.width, __currentSourceBufferSize.height);
797                 __needToRellaocImage = false;
798         }
799
800         r = __pRendererVE->SetFlushNeeded();
801         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r,"[%s] Propagating.", GetErrorMessage(r));
802
803         return r;
804 }
805
806 result
807 _OverlayAgent::SetRendererFlushNeeded(void)
808 {
809         return __pRendererVE->SetFlushNeeded();
810 }
811
812 result
813 _OverlayAgent::SetRotation(_OverlayAgentRotation rotation)
814 {
815         SysTryReturnResult(NID_UI_CTRL, __pRendererVE != null, E_SYSTEM, "The Renderer Visual Element is null");
816         SysTryReturnResult(NID_UI_CTRL, rotation < _OVERLAY_AGENT_ROTATION_MAX, E_INVALID_ARG, "The value of input rotation [%d] is invalid.", rotation);
817
818         if (rotation == __currentRotation)
819         {
820                 return E_SUCCESS;
821         }
822
823         float initialZAngle = __pRendererVE->GetProperty(L"transform.rotation.z").ToFloat();
824         float rotatedZAngle = initialZAngle;
825
826         switch (rotation)
827         {
828         case _OVERLAY_AGENT_ROTATION_NONE: // fall through
829         case _OVERLAY_AGENT_ROTATION_NONE_LR: // fall through
830         case _OVERLAY_AGENT_ROTATION_NONE_UD:
831                 rotatedZAngle = 0.0f;
832                 break;
833
834         case _OVERLAY_AGENT_ROTATION_90: // fall through
835         case _OVERLAY_AGENT_ROTATION_90_LR: // fall through
836         case _OVERLAY_AGENT_ROTATION_90_UD:
837                 rotatedZAngle = 90.0f;
838                 break;
839
840         case _OVERLAY_AGENT_ROTATION_180: // fall through
841         case _OVERLAY_AGENT_ROTATION_180_LR: // fall through
842         case _OVERLAY_AGENT_ROTATION_180_UD:
843                 rotatedZAngle = 180.0f;
844                 break;
845
846         case _OVERLAY_AGENT_ROTATION_270: // fall through
847         case _OVERLAY_AGENT_ROTATION_270_LR: // fall through
848         case _OVERLAY_AGENT_ROTATION_270_UD:
849                 rotatedZAngle = 270.0f;
850                 break;
851
852         default:
853                 break;
854         }
855
856         //Set bounds of rotated renderer
857         FloatRectangle rendererBounds = __standardRendererBounds;
858         if (rotatedZAngle == 90.0f || rotatedZAngle == 270.0f )
859         {
860                 rendererBounds.x = __standardRendererBounds.x - ((__standardRendererBounds.height - __standardRendererBounds.width) / 2.0f);
861                 rendererBounds.y = __standardRendererBounds.y + ((__standardRendererBounds.height - __standardRendererBounds.width) / 2.0f);
862                 std::swap(rendererBounds.height, rendererBounds.width);
863         }
864
865         result r = __pRendererVE->SetBounds(rendererBounds);
866         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
867
868         r = __pRendererVE->SetProperty(L"transform.rotation.z", rotatedZAngle);
869         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
870         SysLog(NID_UI_CTRL, "The current Overlay Renderer is rotated (%d -> %d)", static_cast<int>(initialZAngle), static_cast<int>(rotatedZAngle));
871
872         switch (rotation)
873         {
874         case _OVERLAY_AGENT_ROTATION_NONE: // fall through
875         case _OVERLAY_AGENT_ROTATION_90: // fall through
876         case _OVERLAY_AGENT_ROTATION_180: // fall through
877         case _OVERLAY_AGENT_ROTATION_270:
878                 r = __pRendererVE->SetProperty(L"transform.rotation.x", 0.0f);
879                 r = __pRendererVE->SetProperty(L"transform.rotation.y", 0.0f);
880                 break;
881
882         case _OVERLAY_AGENT_ROTATION_NONE_UD: // fall through
883         case _OVERLAY_AGENT_ROTATION_180_UD: // fall through
884         case _OVERLAY_AGENT_ROTATION_90_LR: // fall through
885         case _OVERLAY_AGENT_ROTATION_270_LR:
886                 r = __pRendererVE->SetProperty(L"transform.rotation.x", 180.0f);
887                 r = __pRendererVE->SetProperty(L"transform.rotation.y", 0.0f);
888                 SysLog(NID_UI_CTRL, "The current Overlay Renderer is flipped over up side down.");
889                 break;
890
891         case _OVERLAY_AGENT_ROTATION_NONE_LR: // fall through
892         case _OVERLAY_AGENT_ROTATION_180_LR: // fall through
893         case _OVERLAY_AGENT_ROTATION_90_UD: // fall through
894         case _OVERLAY_AGENT_ROTATION_270_UD:
895                 r = __pRendererVE->SetProperty(L"transform.rotation.x", 0.0f);
896                 r = __pRendererVE->SetProperty(L"transform.rotation.y", 180.0f);
897                 SysLog(NID_UI_CTRL, "The current Overlay Renderer is flipped over left side right.");
898                 break;
899
900         default:
901                 break;
902         }
903         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
904
905         __currentRotation = rotation;
906
907         r = __pRendererVE->SetFlushNeeded();
908         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
909
910         return r;
911 }
912
913 result
914 _OverlayAgent::SetDestination(const FloatDimension& dimension)
915 {
916         SysTryReturnResult(NID_UI_CTRL, __pParentVE != null, E_SYSTEM, "The Renderer Visual Element is null");
917         SysTryReturnResult(NID_UI_CTRL, __pRendererVE != null, E_SYSTEM, "The Renderer Visual Element is null");
918         if (__standardRendererBounds.width == dimension.width && __standardRendererBounds.height == dimension.height &&
919                 __standardParentBounds.width == __pParentVE->GetBounds().width && __standardParentBounds.height == __pParentVE->GetBounds().height)
920         {
921                 return E_SUCCESS;
922         }
923
924         //Set bounds of saved renderer
925         FloatRectangle parentBounds= __pParentVE->GetBounds();
926
927         if (parentBounds.width >= dimension.width)
928         {
929                 __standardRendererBounds.x = (parentBounds.width - dimension.width) / 2.0f;
930                 __standardRendererBounds.width = dimension.width;
931         }
932         else
933         {
934                 __standardRendererBounds.x = 0.0f;
935                 __standardRendererBounds.width = parentBounds.width;
936         }
937
938         if (parentBounds.height >= dimension.height)
939         {
940                 __standardRendererBounds.y = (parentBounds.height - dimension.height) / 2.0f;
941                 __standardRendererBounds.height = dimension.height;
942         }
943         else
944         {
945                 __standardRendererBounds.y = 0.0f;
946                 __standardRendererBounds.height = parentBounds.height;
947         }
948
949         //Set bounds of resizing renderer
950         float parentWidth = parentBounds.width;
951         float parentHeight = parentBounds.height;
952         FloatDimension inputDimension(dimension.width, dimension.height);
953
954         Variant rotationAngle = __pRendererVE->GetProperty(L"transform.rotation.z");
955         if(rotationAngle.ToFloat() == 90.0f || rotationAngle.ToFloat() == 270.0f)
956         {
957                 std::swap(parentWidth, parentHeight);
958                 std::swap(inputDimension.width, inputDimension.height);
959         }
960
961         FloatRectangle rendererBounds = __standardRendererBounds;
962
963         if (parentWidth >= inputDimension.width)
964         {
965                 rendererBounds.x = (parentBounds.width - inputDimension.width) / 2.0f;
966                 rendererBounds.width = inputDimension.width;
967         }
968         else
969         {
970                 rendererBounds.x = 0.0f;
971                 rendererBounds.width = parentBounds.width;
972         }
973
974         if (parentHeight >= inputDimension.height)
975         {
976                 rendererBounds.y = (parentBounds.height - inputDimension.height) / 2.0f;
977                 rendererBounds.height = inputDimension.height;
978         }
979         else
980         {
981                 rendererBounds.y = 0.0f;
982                 rendererBounds.height = parentBounds.height;
983         }
984         SysLog(NID_UI_CTRL, "The current bounds of resized renderer is [%.3f, %.3f, %.3f, %.3f]",
985                 __standardRendererBounds.x, __standardRendererBounds.y, __standardRendererBounds.width, __standardRendererBounds.height);
986
987         result r = __pRendererVE->SetBounds(rendererBounds);
988         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
989
990         r = __pRendererVE->SetFlushNeeded();
991         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
992
993         __standardParentBounds = __pParentVE->GetBounds();
994
995         return r;
996 }
997
998 result
999 _OverlayAgent::SetAspectRatio(bool enable)
1000 {
1001         return E_SUCCESS;
1002 }
1003
1004 FloatRectangle
1005 _OverlayAgent::GetBounds(void) const
1006 {
1007         SysTryReturn(NID_UI_CTRL, __pRendererVE != null, FloatRectangle(0.0f, 0.0f, 0.1f, 0.1f), E_SYSTEM, "The Renderer Visual Element is null");
1008         return __standardRendererBounds;
1009 }
1010
1011 result
1012 _OverlayAgent::CreateRendererVisualElement(const _Control& parentControl, const FloatRectangle& logicalBounds, const Rectangle& physicalBounds)
1013 {
1014
1015         //Create new VisualElement and insert it to Parent's VisualElement
1016         unique_ptr<_OverlayVisualElement, visualElementDeleter> pRendererVE(new (std::nothrow) _OverlayVisualElement());
1017         SysTryReturnResult(NID_UI_CTRL, pRendererVE != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1018
1019         result r = pRendererVE->Construct();
1020         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1021
1022         pRendererVE->SetName("OverlayRenderer");
1023         pRendererVE->SetShowState(true);
1024         //pRendererVE->SetImplicitAnimationEnabled(true);
1025         pRendererVE->SetImplicitAnimationEnabled(false);
1026         pRendererVE->SetZOrderGroup(_CONTROL_LAYER_OVERLAY);
1027
1028         FloatPoint logicalPoint(0.0f, 0.0f);
1029         if(__style == _OVERLAY_AGENT_STYLE_REGION_SW || __style == _OVERLAY_AGENT_STYLE_REGION_GL)
1030         {
1031                 logicalPoint.x = logicalBounds.x;
1032                 logicalPoint.y = logicalBounds.y;
1033         }
1034         pRendererVE->SetBounds(FloatRectangle(logicalPoint.x, logicalPoint.y, logicalBounds.width, logicalBounds.height));
1035
1036
1037         __pParentVE = parentControl.GetVisualElement();
1038         SysTryReturnResult(NID_UI_CTRL, __pParentVE != null, E_SYSTEM, "[E_SYSTEM] The current value of OverlayPanel's VisualElement is null.");
1039
1040         __pParentVE->SetName("OverlayPanel");
1041         r = __pParentVE->InsertChild(pRendererVE.get(), null, true);
1042         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1043
1044         r = __pParentVE->SetSurfaceOpaque(true);
1045         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1046
1047
1048         // Get and Set ImageObject of Renderer VisualElement
1049         _EflNode* pEflNode = dynamic_cast<_EflNode*>(pRendererVE->GetNativeNode());
1050         SysTryReturnResult(NID_UI_CTRL, pEflNode != null, E_SYSTEM, "Failed to get EflNode from Renderer VisualElement.");
1051
1052         Evas_Object* pSmartObject = (Evas_Object*) pEflNode->GetGroupContainer();
1053         SysTryReturnResult(NID_UI_CTRL, pSmartObject != null, E_SYSTEM, "Failed to get Group Container of Renderer VisualElement.");
1054
1055         Evas* pEvas = evas_object_evas_get(pSmartObject);
1056         SysTryReturnResult(NID_UI_CTRL, pEvas != null, E_SYSTEM, "Failed to get Evas of Renderer VisualElement.");
1057
1058         Ecore_Evas* pEcoreEvas = ecore_evas_ecore_evas_get(pEvas);
1059         SysTryReturnResult(NID_UI_CTRL, pEcoreEvas != null, E_SYSTEM, "Failed to get Ecore Evas of Renderer VisualElement.");
1060
1061         __pImageObject = evas_object_image_add(pEvas);
1062         SysTryReturnResult(NID_UI_CTRL, __pImageObject != null, E_SYSTEM, "Failed to get Renderer Image Object.");
1063
1064         evas_object_name_set(__pImageObject, "OverlayRenderer");
1065         evas_object_image_size_set(__pImageObject, physicalBounds.width, physicalBounds.height);
1066         evas_object_image_alpha_set(__pImageObject, false);
1067         evas_object_image_filled_set(__pImageObject, EINA_TRUE);
1068         evas_object_resize(__pImageObject, physicalBounds.width, physicalBounds.height);
1069         evas_object_move(__pImageObject, physicalBounds.x, physicalBounds.y);
1070         evas_object_hide(__pImageObject);
1071         pRendererVE->SetImageObject(__pImageObject);
1072
1073
1074         DisplayContext* pDisplayContext = parentControl.GetRootWindow()->GetDisplayContext();
1075         SysTryReturnResult(NID_UI_CTRL, pDisplayContext != null, E_SYSTEM, "[E_SYSTEM] The current value of RootWindow's DisplayContext is null.");
1076
1077         unique_ptr<VisualElementSurface> pRendererSurface(_VisualElementSurfaceImpl::CreateSurfaceUsingExistingObjectN(*pDisplayContext, (Handle)__pImageObject, Dimension(physicalBounds.width, physicalBounds.height)));
1078         SysTryReturnResult(NID_UI_CTRL, pRendererSurface != null, E_SYSTEM, "[E_SYSTEM] The current value of RootWindow's DisplayContext is null.");
1079
1080         r = pRendererVE->SetSurface(pRendererSurface.release());
1081         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1082
1083         r = pRendererVE->SetFlushNeeded();
1084         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1085
1086         pRendererVE->SetAnchor(FloatPoint(0.5f, 0.5f));
1087         __pRendererVE = pRendererVE.release();
1088         __standardRendererBounds = __pRendererVE->GetBounds();
1089
1090         if (__style == _OVERLAY_AGENT_STYLE_REGION_SW || __style == _OVERLAY_AGENT_STYLE_PANEL_SW)
1091         {
1092                 evas_object_image_pixels_get_callback_set(__pImageObject, OnEvasImageDamaged,(void*)this);
1093         }
1094
1095         return r;
1096 }
1097
1098 result
1099 _OverlayAgent::CreatePixmap(const Rectangle& physicalBounds)
1100 {
1101         //Set size of pixmap
1102         Dimension pixmapSize(physicalBounds.width, physicalBounds.height);
1103         SysTryReturnResult(NID_UI_CTRL, (pixmapSize.width >= GetDstRectMinWidth()) && (pixmapSize.height >= GetDstRectMinHeight()),
1104                 E_SYSTEM, "input size (%d, %d) is too small to create a pixmap",pixmapSize.width, pixmapSize.height);
1105
1106         // Create pixmap
1107         Display *pDisplay = (Display*)ecore_x_display_get();
1108         SysTryReturnResult(NID_UI_CTRL, pDisplay != null, E_SYSTEM, "The current value of Display is null");
1109
1110         __pixmap = XCreatePixmap(pDisplay, DefaultRootWindow(pDisplay), pixmapSize.width, pixmapSize.height, DefaultDepth(pDisplay, DefaultScreen(pDisplay)));
1111         SysTryReturnResult(NID_UI_CTRL, __pixmap != 0, E_SYSTEM, "Failed to create a pixmap of Overlay Agent");
1112
1113         GC gc = XCreateGC(pDisplay, __pixmap, 0,0);
1114         SysTryReturnResult(NID_UI_CTRL, gc > 0, E_SYSTEM, "Failed to create Graphic Contexts");
1115
1116         //Set initial color
1117         XSetForeground(pDisplay, gc, (long unsigned int)(Color(0xff000000).GetRGB32()));
1118         XFillRectangle(pDisplay, __pixmap, gc, 0, 0, pixmapSize.width, pixmapSize.height);
1119         XSync(pDisplay, 0);
1120         XFreeGC(pDisplay, gc);
1121
1122         //Set evas native surface
1123         Evas_Native_Surface evasNativeSuface = {0,};
1124
1125         evasNativeSuface.version = EVAS_NATIVE_SURFACE_VERSION;
1126         evasNativeSuface.type = EVAS_NATIVE_SURFACE_X11;
1127         evasNativeSuface.data.x11.visual = ecore_x_default_visual_get(ecore_x_display_get(), ecore_x_default_screen_get());
1128         evasNativeSuface.data.x11.pixmap = __pixmap;
1129
1130         evas_object_lower(__pImageObject);
1131         evas_object_image_native_surface_set(__pImageObject, &evasNativeSuface);
1132
1133         __pixmapDamageHandle = ecore_x_damage_new(__pixmap, ECORE_X_DAMAGE_REPORT_RAW_RECTANGLES);
1134         SysTryCatch(NID_UI_CTRL, __pixmapDamageHandle != 0, , E_SYSTEM, "[E_SYSTEM] Failed to create a damage object");
1135
1136         __pPixmapEventHandler = ecore_event_handler_add(ECORE_X_EVENT_DAMAGE_NOTIFY, OnPixmapDamaged, (void*)this);
1137         SysTryCatch(NID_UI_CTRL, __pPixmapEventHandler != null, , E_SYSTEM, "[E_SYSTEM] Failed to add a pixmap damage event handle");
1138
1139         return E_SUCCESS;
1140
1141 CATCH:
1142         if (__pPixmapEventHandler)
1143         {
1144                 ecore_event_handler_del(__pPixmapEventHandler);
1145                 __pPixmapEventHandler = null;
1146         }
1147
1148         if (__pixmapDamageHandle)
1149         {
1150                 ecore_x_damage_free(__pixmapDamageHandle);
1151                 __pixmapDamageHandle = 0;
1152         }
1153
1154         if (__pixmap)
1155         {
1156                 XFreePixmap((Display*)ecore_x_display_get(), __pixmap);
1157                 __pixmap = 0;
1158         }
1159
1160         return E_SYSTEM;
1161 }
1162
1163 Pixmap
1164 _OverlayAgent::GetPixmap(void) const
1165 {
1166         return __pixmap;
1167 }
1168
1169 Evas_Object*
1170 _OverlayAgent::GetRendererImageObject(void) const
1171 {
1172         return __pImageObject;
1173 }
1174
1175 bool
1176 _OverlayAgent::IsValidDestinationDimension(const FloatDimension& dimension) const
1177 {
1178         FloatDimension physicalDimensionF = _CoordinateSystemUtils::Transform(dimension);
1179         Dimension physicalDimension = _CoordinateSystemUtils::ConvertToInteger(physicalDimensionF);
1180         SysTryReturn(NID_UI_CTRL, (physicalDimension.width >= GetDstRectMinWidth() && physicalDimension.height >= GetDstRectMinHeight()), false, E_INVALID_ARG,
1181                         "[E_INVALID_ARG] The size of input dimension (logical size : [%.3f, %.3f], physical size : [%d,%d]) is under minimun size."
1182                         ,dimension.width, dimension.height, physicalDimension.width, physicalDimension.height);
1183
1184         FloatRectangle parentBounds = __pParentVE->GetBounds();
1185         SysTryReturn(NID_UI_CTRL, (dimension.width <= parentBounds.width || dimension.height <= parentBounds.height), false, E_INVALID_ARG,
1186                         "[E_INVALID_ARG] The size of input dimension[%.3f, %.3f] is over maximum size[%.3f,%.3f]."
1187                         ,dimension.width, dimension.height, parentBounds.width, parentBounds.height);
1188
1189         return true;
1190 }
1191
1192 int
1193 _OverlayAgent::GetOverlayAgentCount(void)
1194 {
1195         return __overlayAgentCount;
1196 }
1197
1198 IListT<bool>*
1199 _OverlayAgent::GetPixelFormatListN(void)
1200 {
1201         if (!__OverlayAgentBufferPixelFormat[0])
1202         {
1203                 const wchar_t* _UI_REGISTRY_PATH = L"/usr/etc/system-info.ini";
1204                 const wchar_t* _UI_INFO_SESSION = L"UiControlInfo";
1205
1206                 _RegistryImpl registry;
1207                 result r = registry.Construct(_UI_REGISTRY_PATH, REG_OPEN_READ_ONLY, null);
1208                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1209
1210                 String pixelFormatList(null);
1211                 r = registry.GetValue(_UI_INFO_SESSION, L"OverlayRegionBufferPixelFormat", pixelFormatList);
1212                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1213
1214                 bool set = false;
1215                 if (pixelFormatList.Contains(L"ARGB8888"))
1216                 {
1217                         __OverlayAgentBufferPixelFormat[_OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_ARGB8888] = true;
1218                         set = true;
1219                 }
1220
1221                 if (pixelFormatList.Contains(L"RGB565"))
1222                 {
1223                         __OverlayAgentBufferPixelFormat[_OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_RGB565] = true;
1224                         set = true;
1225                 }
1226
1227                 if (pixelFormatList.Contains(L"YCbCr420P"))
1228                 {
1229                         __OverlayAgentBufferPixelFormat[_OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_YCbCr420_PLANAR] = true;
1230                         set = true;
1231                 }
1232
1233                 if (pixelFormatList.Contains(L"NV12"))
1234                 {
1235                         __OverlayAgentBufferPixelFormat[_OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_NV12] = true;
1236                         set = true;
1237                 }
1238
1239                 if (pixelFormatList.Contains(L"UYVY"))
1240                 {
1241                         __OverlayAgentBufferPixelFormat[_OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_UYVY] = true;
1242                         set = true;
1243                 }
1244
1245                 SysAssertf(set, "The registry file is an invalid.");
1246
1247                 __OverlayAgentBufferPixelFormat[0] = set;
1248         }
1249
1250         std::unique_ptr< ArrayListT<bool> > pFormatList( new (std::nothrow) ArrayListT<bool>());
1251         SysTryReturn(NID_UI_CTRL, pFormatList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] failed to create a list instance");
1252
1253         result r = pFormatList->Construct();
1254         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1255
1256         for (int index = _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_ARGB8888; index <= _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_UYVY; index++)
1257         {
1258                 r = pFormatList->Add(__OverlayAgentBufferPixelFormat[index]);
1259         }
1260         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1261
1262         return pFormatList.release();
1263 }
1264
1265 result
1266 _OverlayAgent::EvaluateBounds(OverlayAgentEvaluationOption option, FloatRectangle& rect, bool& modified)
1267 {
1268         modified = false;
1269         SysTryReturnResult(NID_UI_CTRL, rect.width > 0.0f && rect.height > 0.0f,
1270                 E_INVALID_ARG, "The size of input rectangle(%.3f, %.3f) is invalid.", rect.width, rect.height);
1271
1272         Rectangle logicalEvaluatingBounds = _CoordinateSystemUtils::ConvertToInteger(rect);
1273         SysTryReturnResult(NID_UI_CTRL, logicalEvaluatingBounds.width > 0 && logicalEvaluatingBounds.height > 0,
1274                 E_INVALID_ARG, "The size of logical rectangle(%d, %d) is invalid.", logicalEvaluatingBounds.width, logicalEvaluatingBounds.height);
1275
1276         Rectangle physicalRect(_CoordinateSystemUtils::Transform(logicalEvaluatingBounds));
1277         SysTryReturnResult(NID_UI_CTRL, physicalRect.width > 0 && physicalRect.height > 0,
1278                 E_INVALID_ARG, "The size of physical rectangle(%d, %d) is invalid.", physicalRect.width, physicalRect.height);
1279
1280         int physicalMinWidth = GetDstRectMinWidth();
1281         int physicalMinHeight = GetDstRectMinHeight();
1282         SysTryReturnResult(NID_UI_CTRL, physicalMinWidth > 0 && physicalMinHeight > 0, E_SYSTEM, "The value of overlay control's Min width and Min height are invalid.");
1283
1284         const int widthUnit = GetWidthUnit();
1285         const int heightUnit = GetHeightUnit();
1286         SysTryReturnResult(NID_UI_CTRL, widthUnit > 0 && heightUnit > 0, E_SYSTEM, "The value of overlay control's width Unit and height Unit are invalid.");
1287
1288         int screenWidth = _Screen::GetWidth();
1289         int screenHeight = _Screen::GetHeight();
1290         SysTryReturnResult(NID_UI_CTRL, screenWidth > 0 && screenHeight > 0, E_SYSTEM, "The value of screen size is invalid.");
1291
1292         //If orientation status of screen is landscape mode, swap width and height.
1293         {
1294                 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
1295                 int orientation = ecore_evas_rotation_get(pEcoreEvas->GetEcoreEvas());
1296
1297                 if (orientation == 90 || orientation == 270)
1298                 {
1299                         int temp = screenWidth;
1300                         screenWidth = screenHeight;
1301                         screenHeight = temp;
1302                         SysSecureLog(NID_UI_CTRL, "The current value of device screen width is %d, device screen height is %d and orientation is %d", screenWidth, screenHeight, orientation);
1303                 }
1304         }
1305
1306         int physicalMaxWidth= screenWidth - (screenWidth % widthUnit);
1307         int physicalMaxHeight = screenHeight - (screenHeight % heightUnit);
1308         int logicalMaxWidth = _CoordinateSystemUtils::InverseHorizontalTransform(physicalMaxWidth);
1309         int logicalMaxHeight = _CoordinateSystemUtils::InverseVerticalTransform(physicalMaxHeight);
1310
1311         int widthReminder = physicalRect.width % widthUnit;
1312         int heightReminder = physicalRect.height % heightUnit;
1313
1314         //Fix one pixel error when coordinate system transform
1315         if (widthReminder == 1)
1316         {
1317                 physicalRect.width -= 1;
1318                 widthReminder = physicalRect.width % widthUnit;
1319         }
1320
1321         if (heightReminder == 1)
1322         {
1323                 physicalRect.height -= 1;
1324                 heightReminder = physicalRect.height % heightUnit;
1325         }
1326
1327         switch (option)
1328         {
1329         case OVERLAY_AGENT_EVALUATION_OPTION_GREATER_THAN:
1330                 {
1331                         if (logicalEvaluatingBounds.width > logicalMaxWidth || logicalEvaluatingBounds.height > logicalMaxHeight)
1332                         {
1333                                 SysLogException(NID_UI_CTRL, E_UNSUPPORTED_OPTION, "[E_UNSUPPORTED_OPTION] The size of input rect exceeds logical maximun size.");
1334                                 return E_UNSUPPORTED_OPTION;
1335                         }
1336
1337                         if (physicalRect.width > physicalMaxWidth || physicalRect.height > physicalMaxHeight)
1338                         {
1339                                 SysLogException(NID_UI_CTRL, E_UNSUPPORTED_OPTION, "[E_UNSUPPORTED_OPTION] The size of input rect exceeds physical maximun size.");
1340                                 return E_UNSUPPORTED_OPTION;
1341                         }
1342
1343                         if (widthReminder != 0)
1344                         {
1345                                 widthReminder -= widthUnit;
1346                         }
1347
1348                         if (heightReminder != 0)
1349                         {
1350                                 heightReminder -= heightUnit;
1351                         }
1352
1353                         physicalRect.width -= widthReminder;
1354                         physicalRect.height -= heightReminder;
1355
1356                         if (physicalRect.width < physicalMinWidth)
1357                         {
1358                                 physicalRect.width = physicalMinWidth;
1359                         }
1360
1361                         if (physicalRect.height < physicalMinHeight)
1362                         {
1363                                 physicalRect.height = physicalMinHeight;
1364                         }
1365                 }
1366                 break;
1367         case OVERLAY_AGENT_EVALUATION_OPTION_LESS_THAN:
1368                 {
1369                         if (physicalRect.width < physicalMinWidth || physicalRect.height < physicalMinHeight)
1370                         {
1371                                 SysLogException(NID_UI_CTRL, E_UNSUPPORTED_OPTION, "[E_UNSUPPORTED_OPTION] The size of input rect is under minimun size.");
1372
1373                                 return E_UNSUPPORTED_OPTION;
1374                         }
1375
1376                         if (physicalRect.width > physicalMaxWidth)
1377                         {
1378                                 physicalRect.width = physicalMaxWidth + widthReminder;
1379                         }
1380
1381                         if (physicalRect.height > physicalMaxHeight)
1382                         {
1383                                 physicalRect.height = physicalMaxHeight + heightReminder;
1384                         }
1385
1386                         physicalRect.width -= widthReminder;
1387                         physicalRect.height -= heightReminder;
1388                 }
1389                 break;
1390         default:
1391                 {
1392                         SysLogException(NID_UI_CTRL, E_UNSUPPORTED_OPTION, "[E_UNSUPPORTED_OPTION] The input option is an invalid.");
1393
1394                         return E_UNSUPPORTED_OPTION;
1395                 }
1396         }
1397
1398         FloatRectangle originalInputRect(rect);
1399         rect = _CoordinateSystemUtils::ConvertToFloat(_CoordinateSystemUtils::InverseTransform(physicalRect));
1400
1401         if (rect != originalInputRect)
1402         {
1403                 modified = true;
1404                 SysLog(NID_UI_CTRL, "The input bounds [%.3f, %.3f, %.3f, %.3f] is modified to [%.3f, %.3f, %.3f, %.3f]",
1405                                 originalInputRect.x, originalInputRect.y, originalInputRect.width, originalInputRect.height,
1406                                 rect.x, rect.y, rect.width, rect.height);
1407         }
1408         else
1409         {
1410                 SysLog(NID_UI_CTRL, "The evaluated bounds [%.3f, %.3f, %.3f, %.3f] is valid.",
1411                         rect.x, rect.y, rect.width, rect.height);
1412         }
1413
1414         result r = GetLastResult();
1415         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1416
1417         return r;
1418 }
1419
1420 int
1421 _OverlayAgent::GetValueFromRegistry(const String& key)
1422 {
1423         const wchar_t* _UI_REGISTRY_PATH = L"/usr/etc/system-info.ini";
1424         const wchar_t* _UI_INFO_SESSION = L"UiControlInfo";
1425
1426         _RegistryImpl registry;
1427         result r = registry.Construct(_UI_REGISTRY_PATH, REG_OPEN_READ_ONLY, null);
1428         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));
1429
1430         String strValue(null);
1431         r = registry.GetValue(_UI_INFO_SESSION, key, strValue);
1432         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));
1433
1434         int value;
1435         r = Integer::Parse(strValue, value);
1436         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));
1437
1438         return value;
1439 }
1440
1441 int
1442 _OverlayAgent::GetDstRectMinWidth(void)
1443 {
1444         if (__dstRectMinWidth < 0)
1445         {
1446                 int value = GetValueFromRegistry(L"OverlayDstMinWidth");
1447                 SysTryReturn(NID_UI_CTRL, value > 0, -1, E_SYSTEM, "[E_SYSTEM] Failed to get Overlay info from registry");
1448
1449                 __dstRectMinWidth = value;
1450                 SysLog(NID_UI_CTRL, "The overlay control's minimum width of destination is [%d]", __dstRectMinWidth);
1451         }
1452
1453         SetLastResult(E_SUCCESS);
1454
1455         return __dstRectMinWidth;
1456 }
1457
1458 int
1459 _OverlayAgent::GetDstRectMinHeight(void)
1460 {
1461         if (__dstRectMinHegith < 0)
1462         {
1463                 int value = GetValueFromRegistry(L"OverlayDstMinHeight");
1464                 SysTryReturn(NID_UI_CTRL, value > 0, -1, E_SYSTEM, "[E_SYSTEM] Failed to get Overlay info from registry");
1465
1466                 __dstRectMinHegith = value;
1467                 SysLog(NID_UI_CTRL, "The overlay control's minimum height of destination is [%d]", __dstRectMinHegith);
1468         }
1469
1470         SetLastResult(E_SUCCESS);
1471
1472         return __dstRectMinHegith;
1473 }
1474
1475 int
1476 _OverlayAgent::GetSrcRectMinWidth(void)
1477 {
1478         if (__srcRectMinWidth < 0)
1479         {
1480                 int value = GetValueFromRegistry(L"OverlaySrcMinWidth");
1481                 SysTryReturn(NID_UI_CTRL,  value > 0, -1, E_SYSTEM, "[E_SYSTEM] Failed to get Overlay info from registry");
1482
1483                 __srcRectMinWidth = value;
1484                 SysLog(NID_UI_CTRL, "The overlay control's minimum width of source buffer is [%d]", __srcRectMinWidth);
1485         }
1486
1487         SetLastResult(E_SUCCESS);
1488
1489         return __srcRectMinWidth;
1490 }
1491
1492 int
1493 _OverlayAgent::GetSrcRectMinHeight(void)
1494 {
1495         if (__srcRectMinHegith < 0)
1496         {
1497                 int value = GetValueFromRegistry(L"OverlaySrcMinHeight");
1498                 SysTryReturn(NID_UI_CTRL,  value > 0, -1, E_SYSTEM, "[E_SYSTEM] Failed to get Overlay info from registry");
1499
1500                 __srcRectMinHegith = value;
1501                 SysLog(NID_UI_CTRL, "The overlay control's minimum height of source buffer is [%d]", __srcRectMinHegith);
1502         }
1503
1504         SetLastResult(E_SUCCESS);
1505
1506         return __srcRectMinHegith;
1507 }
1508
1509 int
1510 _OverlayAgent::GetWidthUnit(void)
1511 {
1512         if (__overlayWidthUnit < 0)
1513         {
1514                 int value = GetValueFromRegistry(L"OverlayRegionWidthUnit");
1515                 SysTryReturn(NID_UI_CTRL,  value > 0, -1, E_SYSTEM, "[E_SYSTEM] Failed to get Overlay info from registry");
1516
1517                 __overlayWidthUnit = value;
1518                 SysLog(NID_UI_CTRL, "The overlay control's unit width is [%d]", __overlayWidthUnit);
1519         }
1520
1521         SetLastResult(E_SUCCESS);
1522
1523         return __overlayWidthUnit;
1524 }
1525
1526 int
1527 _OverlayAgent::GetHeightUnit(void)
1528 {
1529         if (__overlayHeightUnit < 0)
1530         {
1531                 int value = GetValueFromRegistry(L"OverlayRegionHeightUnit");
1532                 SysTryReturn(NID_UI_CTRL,  value > 0, -1, E_SYSTEM, "[E_SYSTEM] Failed to get Overlay info from registry");
1533
1534                 __overlayHeightUnit = value;
1535                 SysLog(NID_UI_CTRL, "The overlay control's unit height is [%d]", __overlayHeightUnit);
1536         }
1537
1538         SetLastResult(E_SUCCESS);
1539
1540         return __overlayHeightUnit;
1541 }
1542
1543 int
1544 _OverlayAgent::GetMaxCount(void)
1545 {
1546         if (__overlayMaxCount < 0)
1547         {
1548                 int value = GetValueFromRegistry(L"MaxOverlayRegionCount");
1549                 SysTryReturn(NID_UI_CTRL,  value > 0, -1, E_SYSTEM, "[E_SYSTEM] Failed to get Overlay info from registry");
1550
1551                 __overlayMaxCount = value;
1552                 SysLog(NID_UI_CTRL, "The overlay control's maximum count is [%d]", __overlayMaxCount);
1553         }
1554
1555         SetLastResult(E_SUCCESS);
1556
1557         return __overlayMaxCount;
1558 }
1559 }}} // Tizen::Ui
1560