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