2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FUiCtrl_OverlayAgent.cpp
20 * @brief This file contains implementation of _OverlayAgent class
25 #include <unique_ptr.h>
26 #include <Ecore_Evas.h>
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"
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))
50 using namespace Tizen::Base;
51 using namespace Tizen::Base::Collection;
52 using namespace Tizen::Graphics;
53 using namespace Tizen::Io;
54 using namespace Tizen::Media;
55 using namespace Tizen::System;
56 using namespace Tizen::Ui::Controls;
57 using namespace Tizen::Ui::Animations;
62 CheckXvExtension(Display* pDisplay, int* pFirstPort, int* pCountPort)
64 unsigned int version = 0;
65 unsigned int release = 0;
66 unsigned int requestBase = 0;
67 unsigned int eventBase = 0;
68 unsigned int errorBase = 0;
70 // Query and print Xvideo properties
71 int returnValue = XvQueryExtension(pDisplay, &version, &release, &requestBase, &eventBase, &errorBase);
72 if (returnValue != Success)
74 if (returnValue == XvBadExtension)
76 SysSecureLog(NID_UI_CTRL, "XvBadExtension returned at XvQueryExtension!");
78 else if (returnValue == XvBadAlloc)
80 SysSecureLog(NID_UI_CTRL, "XvBadAlloc returned at XvQueryExtension!");
84 SysSecureLog(NID_UI_CTRL, "Other error happened at XvQueryExtension!");
90 unsigned int adaptors = 0;
91 XvAdaptorInfo* pAdaptorInfo = null;
92 returnValue = XvQueryAdaptors(pDisplay, DefaultRootWindow(pDisplay), &adaptors, &pAdaptorInfo);
93 if (returnValue != Success)
95 if (returnValue == XvBadExtension)
97 SysSecureLog(NID_UI_CTRL, "XvBadExtension returned at XvQueryExtension.");
99 else if (returnValue == XvBadAlloc)
101 SysSecureLog(NID_UI_CTRL, "XvBadAlloc returned at XvQueryExtension.");
105 SysSecureLog(NID_UI_CTRL, "Other error happaned at XvQueryAdaptors.");
108 if (pAdaptorInfo != null)
110 XvFreeAdaptorInfo(pAdaptorInfo);
117 if (adaptors > 0 && pAdaptorInfo != null)
119 for (unsigned int i = 0; i < adaptors; i++)
121 for (unsigned int j = 0; j < pAdaptorInfo[i].num_formats; j++)
123 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);
127 port = pAdaptorInfo[0].base_id;
130 *pCountPort = pAdaptorInfo[0].num_ports;
131 SysSecureLog(NID_UI_CTRL, "The current value of port is %d", port);
134 if (pAdaptorInfo != null)
136 XvFreeAdaptorInfo(pAdaptorInfo);
148 OnPixmapDamaged(void* pData, int type, void* pEvent)
150 Ecore_X_Event_Damage* pDamageEvent = (Ecore_X_Event_Damage*)pEvent;
151 SysTryReturn(NID_UI_CTRL, pDamageEvent != null, ECORE_CALLBACK_PASS_ON, E_INVALID_DATA, "[E_INVALID_DATA] The current value of DamageEvent is invalid.");
153 Tizen::Ui::Controls::_OverlayAgent* pOverlayAgent = static_cast<Tizen::Ui::Controls::_OverlayAgent*>(pData);
154 SysTryReturn(NID_UI_CTRL, pOverlayAgent != null, ECORE_CALLBACK_PASS_ON, E_INVALID_DATA, "[E_INVALID_DATA] Failed to get OverlayAgent from DamagedEvent.");
156 if (pDamageEvent->drawable != pOverlayAgent->GetPixmap())
158 return ECORE_CALLBACK_PASS_ON;
161 pOverlayAgent->SetRendererFlushNeeded();
163 return ECORE_CALLBACK_DONE;
167 OnEvasImageDamaged(void* pData, Evas_Object* pImageObject)
169 Tizen::Ui::Controls::_OverlayAgent* pOverlayAgent = static_cast<Tizen::Ui::Controls::_OverlayAgent*>(pData);
170 SysTryReturnVoidResult(NID_UI_CTRL, pOverlayAgent != null, E_INVALID_DATA, "[E_INVALID_DATA] Failed to get OverlayAgent from DamagedEvent.");
172 Evas_Object* pRendererImageObject = pOverlayAgent->GetRendererImageObject();
173 SysTryReturnVoidResult(NID_UI_CTRL, pRendererImageObject != null, E_INVALID_DATA, "[E_INVALID_DATA] Failed to get Renderer ImageObject of OverlayAgent.");
175 if (pRendererImageObject != pImageObject)
180 Dimension newImageSize(0,0);
181 evas_object_image_size_get(pImageObject, &newImageSize.width, &newImageSize.height);
183 Dimension rendererImageSize(0,0);
184 evas_object_image_size_get(pRendererImageObject, &rendererImageSize.width, &rendererImageSize.height);
186 if (!newImageSize.Equals(rendererImageSize))
188 SysSecureLog(NID_UI_CTRL,"newImageSize [%d, %d] rendererImageSize [%d, %d]", newImageSize.width, newImageSize.height, rendererImageSize.width, rendererImageSize.height);
189 pOverlayAgent->SetDestination(FloatDimension(static_cast<float>(newImageSize.width), static_cast<float>(newImageSize.height)));
194 namespace Tizen { namespace Ui { namespace Controls
197 int _OverlayAgent::__baseXvPort = 0;
198 bool _OverlayAgent::__isPortGrabbed[]={false,};
200 int _OverlayAgent::__overlayAgentCount = 0;
201 int _OverlayAgent::__dstRectMinWidth = -1;
202 int _OverlayAgent::__dstRectMinHegith = -1;
203 int _OverlayAgent::__srcRectMinWidth = -1;
204 int _OverlayAgent::__srcRectMinHegith = -1;
205 int _OverlayAgent::__overlayWidthUnit = -1;
206 int _OverlayAgent::__overlayHeightUnit = -1;
207 int _OverlayAgent::__overlayMaxCount = -1;
208 bool _OverlayAgent::__OverlayAgentBufferPixelFormat[] = {false, };
210 struct visualElementDeleter
212 void operator()(_VisualElement* pVisualElement)
214 pVisualElement->Destroy();
219 _OverlayAgent::CreateInstanceN(_OverlayAgentStyle style, const _Control& parentControl, const FloatRectangle& logicalBounds, const Rectangle& physicalBounds)
221 unique_ptr<_OverlayAgent> pOverlayAgent(new (std::nothrow) _OverlayAgent(style, parentControl, logicalBounds, physicalBounds));
222 SysTryReturn(NID_UI_CTRL, pOverlayAgent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
224 result r = GetLastResult();
225 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
227 return pOverlayAgent.release();
230 _OverlayAgent::_OverlayAgent(_OverlayAgentStyle style, const _Control& parentControl, const FloatRectangle& logicalBounds, const Rectangle& physicalBounds)
232 , __pRendererVE(null)
233 , __pImageObject(null)
235 , __currentRotation(_OVERLAY_AGENT_ROTATION_NONE)
236 , __savedColorFormat(FOURCC('R','G','B','4'))
237 , __currentColorFormat(_OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_ARGB8888)
238 , __currentSourceBufferSize(0,0)
239 , __standardRendererBounds(0.0f, 0.0f, 0.0f, 0.0f)
240 , __standardParentBounds(0.0f, 0.0f, 0.0f, 0.0f)
241 , __needToRellaocImage(false)
242 , __pCurrentSourceBuffer(null)
243 , __pConvertedSourceBuffer(null)
244 , __pixmapDamageHandle(0)
245 , __pPixmapEventHandler(null)
251 result r = CreateRendererVisualElement(parentControl, logicalBounds, physicalBounds);
253 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
254 SysTryReturnVoidResult(NID_UI_CTRL, __pRendererVE != null, E_SYSTEM, "[E_SYSTEM] The Renderer VisualElement is null.");
255 SysTryReturnVoidResult(NID_UI_CTRL, __pImageObject!= null, E_SYSTEM, "[E_SYSTEM] The Renderder ImageObject is null.");
257 __overlayAgentCount++;
258 SysLog(NID_UI_CTRL, "The current count of OverlayAgent is %d", __overlayAgentCount);
261 _OverlayAgent::~_OverlayAgent(void)
263 SysLog(NID_UI_CTRL, "The %dth OverlayAgent is deleted.", __overlayAgentCount);
264 __overlayAgentCount--;
268 if (__pPixmapEventHandler)
270 ecore_event_handler_del(__pPixmapEventHandler);
271 __pPixmapEventHandler = null;
274 if (__pixmapDamageHandle)
276 ecore_x_damage_free(__pixmapDamageHandle);
277 __pixmapDamageHandle = 0;
282 XFreePixmap((Display*)ecore_x_display_get(), __pixmap);
288 XShmDetach((Display*)ecore_x_display_get(), __pShmInfo);
289 shmdt(__pShmInfo->shmaddr);
290 shmctl(__pShmInfo->shmid, IPC_RMID, NULL);
300 if (__pConvertedSourceBuffer)
302 delete __pConvertedSourceBuffer;
303 __pConvertedSourceBuffer = null;
306 if (__pCurrentSourceBuffer)
308 delete __pCurrentSourceBuffer;
309 __pCurrentSourceBuffer = null;
312 if (__pRendererVE != null)
314 __pRendererVE->SetSurface(null);
315 __pRendererVE->Destroy();
316 __pRendererVE = null;
321 evas_object_del(__pImageObject);
322 __pImageObject = null;
327 _OverlayAgent::GetBufferInfo(BufferInfo& bufferInfo) const
329 SysTryReturnResult(NID_UI_CTRL, __pImageObject != null, E_SYSTEM, "The Renderer ImageObject is null.");
330 SysTryReturnResult(NID_UI_CTRL, __pRendererVE != null, E_SYSTEM, "The Renderer Visual Element is null.");
334 evas_object_geometry_get(__pImageObject, NULL, NULL, &width, &height);
336 bufferInfo.width = width;
337 bufferInfo.pitch = width;
338 bufferInfo.height = height;
339 bufferInfo.bitsPerPixel = 32;
340 bufferInfo.pixelFormat = PIXEL_FORMAT_ARGB8888;
342 _BufferInfoImpl* pBufferInfoImpl = _BufferInfoImpl::GetInstance(bufferInfo);
343 SysTryReturnResult(NID_UI_CTRL, pBufferInfoImpl != null, E_SYSTEM, "Failed to get instance of buffer info.");
345 result r = E_SUCCESS;
347 if(__style == _OVERLAY_AGENT_STYLE_REGION_SW || __style == _OVERLAY_AGENT_STYLE_PANEL_SW)
349 pBufferInfoImpl->SetHandle(_BufferInfoImpl::HANDLE_TYPE_VE_SURFACE, reinterpret_cast<Handle>(__pImageObject));
350 SysSecureLog(NID_UI_CTRL,"The returned handle of BufferInfo is a evas image object (HANDLE_TYPE_VE_SURFACE)");
354 pBufferInfoImpl->SetHandle(_BufferInfoImpl::HANDLE_TYPE_OVERLAY_REGION, __pixmap);
355 SysSecureLog(NID_UI_CTRL,"The returned handle of BufferInfo is a pixmap (HANDLE_TYPE_OVERLAY_REGION)");
358 pBufferInfoImpl->SetBounds(Rectangle(0, 0, width, height));
364 _OverlayAgent::SetInputBuffer(const ByteBuffer& srcBuffer, const Dimension& srcDim, _OverlayAgentBufferPixelFormat srcFormat)
366 SysTryReturnResult(NID_UI_CTRL, srcBuffer.GetPointer() != null, E_INVALID_ARG, "The current value of input source buffer is invalid.");
367 SysTryReturnResult(NID_UI_CTRL, srcBuffer.GetCapacity() > 0, E_INVALID_ARG, "The current size of input source buffer is invalid.");
368 SysTryReturnResult(NID_UI_CTRL, srcDim.width >= GetSrcRectMinWidth(), E_INVALID_ARG, "The width of dimension [%d] is under the minimum size.", srcDim.width);
369 SysTryReturnResult(NID_UI_CTRL, srcDim.height >= GetSrcRectMinHeight(), E_INVALID_ARG, "The height of dimension [%d] is under the minimum size.", srcDim.height);
371 if (__currentColorFormat != srcFormat)
373 unsigned int colorFormat = 0;
377 case _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_ARGB8888:
378 colorFormat = FOURCC('R','G','B','4');
380 case _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_RGB565:
381 colorFormat = FOURCC('R','G','B','P');
383 case _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_YCbCr420_PLANAR:
384 colorFormat = FOURCC('I','4','2','0');
386 case _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_NV12:
387 colorFormat = FOURCC('N','V','1','2');
389 case _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_UYVY:
390 colorFormat = FOURCC('U','Y','V','Y');
393 SysLogException(NID_UI_CTRL, E_UNSUPPORTED_FORMAT, "The specified pixel format is not supported.");
394 return E_UNSUPPORTED_FORMAT;
397 __savedColorFormat = colorFormat;
398 __currentColorFormat = srcFormat;
399 __needToRellaocImage = true;
402 if (!srcDim.Equals(__currentSourceBufferSize))
404 __currentSourceBufferSize.width = srcDim.width;
405 __currentSourceBufferSize.height = srcDim.height;
406 __needToRellaocImage = true;
409 __pCurrentSourceBuffer = &srcBuffer;
411 if (__needToRellaocImage)
413 SysSecureLog(NID_UI_CTRL,"The current buffer pointer is %x, size is %d, color format is %d",
414 __pCurrentSourceBuffer->GetPointer(), __pCurrentSourceBuffer->GetCapacity(), __savedColorFormat);
421 _OverlayAgent::Draw(void)
423 SysTryReturnResult(NID_UI_CTRL, __pCurrentSourceBuffer->GetPointer() != null, E_SYSTEM, "The current input user buffer is null. (nothing to draw)");
425 result r = E_SUCCESS;
427 if(__style == _OVERLAY_AGENT_STYLE_REGION_SW || __style == _OVERLAY_AGENT_STYLE_PANEL_SW)
436 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Propagating.");
443 _OverlayAgent::GrabXvPort(void)
445 Display* pDisplay = (Display*)ecore_x_display_get();
446 SysTryReturnResult(NID_UI_CTRL, pDisplay != null, E_SYSTEM, "The current value of Display is null");
450 if (!CheckXvExtension(pDisplay, &baseXvPort, &portCount))
452 SysTryReturnResult(NID_UI_CTRL, false, E_SYSTEM, "Failed to check XvExtension");
455 SysTryReturnResult(NID_UI_CTRL, baseXvPort != -1, E_SYSTEM, "The current value of base XvPort is invalid.");
456 SysTryReturnResult(NID_UI_CTRL, portCount >= 1 && portCount <= _OVERLAYAGENT_XV_PORT, E_SYSTEM, "The current count of available XvPort[%d] is invalid.", portCount);
458 _OverlayAgent::__baseXvPort = baseXvPort;
460 for (int index = 0; index < portCount; index++)
462 if(!__isPortGrabbed[index])
464 int tempPort = __baseXvPort + index;
465 if (XvGrabPort(pDisplay, tempPort, 0) != Success)
467 SysSecureLog(NID_UI_CTRL, "The current XvPort[%d] has been alreadly used by another process", tempPort);
472 __isPortGrabbed[index] = true;
478 SysTryReturnResult(NID_UI_CTRL, __xvPort != -1, E_SYSTEM, "Failed to grab pixmap[%d]", __pixmap);
479 SysSecureLog(NID_UI_CTRL, "The current value of grabbed XvPort is [%d] and pixmap is [%d]", __xvPort, __pixmap);
485 _OverlayAgent::UngrabXvPort(void)
489 if (__isPortGrabbed[__xvPort - __baseXvPort])
491 Display* pDisplay = (Display*) ecore_x_display_get();
492 Atom atom = XInternAtom(pDisplay, "_USER_WM_PORT_ATTRIBUTE_STREAM_OFF", False);
493 XvSetPortAttribute(pDisplay, __xvPort, atom, 1);
494 XvUngrabPort(pDisplay, __xvPort, 0);
496 SysSecureLog(NID_UI_CTRL, "The current value of ungrabbed XvPort is %d, and pixmap is %d", __xvPort, __pixmap);
498 __isPortGrabbed[__xvPort - __baseXvPort] = false;
504 _OverlayAgent::PutXvImage(void)
506 SysTryReturnResult(NID_UI_CTRL, __pixmap != 0, E_SYSTEM, "The current value of pixmap is null");
508 Display* pDisplay = (Display*)ecore_x_display_get();
509 SysTryReturnResult(NID_UI_CTRL, pDisplay != null, E_SYSTEM, "The current value of Display is null");
511 if (__pXvImage == null || __needToRellaocImage)
512 //||(__pXvImage && __pXvImage->data_size != currentSourceBufferSize->GetCapacity()) )
519 if (__pXvImage != null)
523 XShmDetach(pDisplay, __pShmInfo);
524 shmdt(__pShmInfo->shmaddr);
525 shmctl(__pShmInfo->shmid, IPC_RMID, NULL);
540 result r = GrabXvPort();
541 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Propagating.");
544 if (__needToRellaocImage)
546 XShmSegmentInfo* pShmInfo = new (std::nothrow) XShmSegmentInfo();
547 SysTryReturnResult(NID_UI_CTRL, pShmInfo != null, E_SYSTEM, "Failed to create XShmSegmentInfo");
549 XvImage* pXvImage = XvShmCreateImage(pDisplay, __xvPort, __savedColorFormat, 0, __currentSourceBufferSize.width, __currentSourceBufferSize.height, pShmInfo);
550 SysTryReturnResult(NID_UI_CTRL, pXvImage != null, E_SYSTEM, "Failed to create XvImage");
552 pShmInfo->shmid = shmget(IPC_PRIVATE, pXvImage->data_size, IPC_CREAT | 0777);
553 pShmInfo->shmaddr = pXvImage->data = (char*)shmat(pShmInfo->shmid, 0, 0);
554 pShmInfo->readOnly = False;
556 if (!XShmAttach(pDisplay, pShmInfo))
559 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Failed to XShmAttach.");
563 __pXvImage = pXvImage;
564 __pShmInfo = pShmInfo;
567 if (__pXvImage == null)
569 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] Failed to get XvImage");
573 memcpy(__pXvImage->data, __pCurrentSourceBuffer->GetPointer(), __pXvImage->data_size);
574 __pCurrentSourceBuffer = null;
578 evas_object_image_size_get(__pImageObject, &imageWidth, &imageHeight);
580 GC gc= DefaultGCOfScreen(DefaultScreenOfDisplay(pDisplay));
581 XvShmPutImage(pDisplay, __xvPort, __pixmap, gc, __pXvImage, 0, 0, __currentSourceBufferSize.width, __currentSourceBufferSize.height, 0, 0, imageWidth, imageHeight, False);
584 if (__needToRellaocImage)
586 SysSecureLog(NID_UI_CTRL, "The current value of source buffer size is [%d,%d]", __currentSourceBufferSize.width, __currentSourceBufferSize.height);
587 SysSecureLog(NID_UI_CTRL, "The current value of destination XvImage size is [%d,%d]", imageWidth, imageHeight);
588 __needToRellaocImage = false;
591 result r = __pRendererVE->SetFlushNeeded();
592 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r,"[%s] Propagating.", GetErrorMessage(r));
598 _OverlayAgent::PutEvasImage(void)
600 SysTryReturnResult(NID_UI_CTRL, __pImageObject != null, E_SYSTEM, "The current value of Renderer ImageObject is null");
601 SysTryReturnResult(NID_UI_CTRL, __pCurrentSourceBuffer->GetPointer() != null, E_SYSTEM, "The current value of Renderer byte buffer is null");
603 result r = E_SUCCESS;
605 // Create new buffer to convert pixel format
606 if (__needToRellaocImage || __pConvertedSourceBuffer == null ||
607 !(__pConvertedSourceBuffer && (__pConvertedSourceBuffer->GetCapacity() == __pCurrentSourceBuffer->GetCapacity())))
609 if (__pConvertedSourceBuffer != null)
611 __pConvertedSourceBuffer->SetPosition(0);
612 delete __pConvertedSourceBuffer;
613 __pConvertedSourceBuffer = null;
616 __pConvertedSourceBuffer = new (std::nothrow) ByteBuffer;
617 SysTryReturnResult(NID_UI_CTRL, __pConvertedSourceBuffer != null, E_OUT_OF_MEMORY, "Failed to create a ByteBuffer for Evas Image Object.");
619 r = __pConvertedSourceBuffer->Construct(__currentSourceBufferSize.width * __currentSourceBufferSize.height * 4);
622 delete __pConvertedSourceBuffer;
623 __pConvertedSourceBuffer = null;
624 SysLogException(NID_UI_CTRL, r, "[%s] Failed to construct a byte buffer for EvasImageObject.", GetErrorMessage(r));
630 __pConvertedSourceBuffer->SetPosition(0);
632 switch (__currentColorFormat)
634 case _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_ARGB8888:
635 r = __pConvertedSourceBuffer->SetArray(__pCurrentSourceBuffer->GetPointer(), 0, __pConvertedSourceBuffer->GetCapacity());
637 case _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_RGB565:
638 r = _ImageUtil::ConvertPixelFormat(*__pCurrentSourceBuffer, MEDIA_PIXEL_FORMAT_RGB565LE, __currentSourceBufferSize.width, __currentSourceBufferSize.height, *__pConvertedSourceBuffer, MEDIA_PIXEL_FORMAT_BGRA8888);
640 case _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_YCbCr420_PLANAR:
641 r = _ImageUtil::ConvertPixelFormat(*__pCurrentSourceBuffer, MEDIA_PIXEL_FORMAT_YUV420P, __currentSourceBufferSize.width, __currentSourceBufferSize.height, *__pConvertedSourceBuffer, MEDIA_PIXEL_FORMAT_BGRA8888);
643 case _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_NV12:
644 r = _ImageUtil::ConvertPixelFormat(*__pCurrentSourceBuffer, MEDIA_PIXEL_FORMAT_NV12, __currentSourceBufferSize.width, __currentSourceBufferSize.height, *__pConvertedSourceBuffer, MEDIA_PIXEL_FORMAT_BGRA8888);
646 case _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_UYVY:
647 r = _ImageUtil::ConvertPixelFormat(*__pCurrentSourceBuffer, MEDIA_PIXEL_FORMAT_UYVY422, __currentSourceBufferSize.width, __currentSourceBufferSize.height, *__pConvertedSourceBuffer, MEDIA_PIXEL_FORMAT_BGRA8888);
650 SysLogException(NID_UI_CTRL, E_UNSUPPORTED_FORMAT, "[E_UNSUPPORTED_FORMAT] The specified pixel format is not supported.");
651 return E_UNSUPPORTED_FORMAT;
654 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r,"Propagating.");
656 __pCurrentSourceBuffer = null;
657 void* pImageData = (void*)(__pConvertedSourceBuffer->GetPointer());
658 SysTryReturnResult(NID_UI_CTRL, pImageData != null, E_SYSTEM, "The converted image data for Overlay Renderer VisualElement is invalid.");
660 evas_object_image_size_set(__pImageObject, __currentSourceBufferSize.width, __currentSourceBufferSize.height);
661 evas_object_image_data_set(__pImageObject, pImageData);
662 evas_object_image_data_update_add(__pImageObject, 0, 0, __currentSourceBufferSize.width, __currentSourceBufferSize.height);
663 evas_object_show(__pImageObject);
665 if (__needToRellaocImage)
667 SysSecureLog(NID_UI_CTRL, "The current value of source buffer bounds is [%d,%d,%d, %d]", 0, 0, __currentSourceBufferSize.width, __currentSourceBufferSize.height);
668 __needToRellaocImage = false;
671 r = __pRendererVE->SetFlushNeeded();
672 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r,"[%s] Propagating.", GetErrorMessage(r));
678 _OverlayAgent::SetRendererFlushNeeded(void)
680 return __pRendererVE->SetFlushNeeded();
684 _OverlayAgent::SetRotation(_OverlayAgentRotation rotation)
686 SysTryReturnResult(NID_UI_CTRL, __pRendererVE != null, E_SYSTEM, "The Renderer Visual Element is null");
687 SysTryReturnResult(NID_UI_CTRL, rotation < _OVERLAY_AGENT_ROTATION_MAX, E_INVALID_ARG, "The value of input rotation [%d] is invalid.", rotation);
689 if (rotation == __currentRotation)
694 float initialZAngle = __pRendererVE->GetProperty(L"transform.rotation.z").ToFloat();
695 float rotatedZAngle = initialZAngle;
699 case _OVERLAY_AGENT_ROTATION_NONE: // fall through
700 case _OVERLAY_AGENT_ROTATION_NONE_LR: // fall through
701 case _OVERLAY_AGENT_ROTATION_NONE_UD:
702 rotatedZAngle = 0.0f;
705 case _OVERLAY_AGENT_ROTATION_90: // fall through
706 case _OVERLAY_AGENT_ROTATION_90_LR: // fall through
707 case _OVERLAY_AGENT_ROTATION_90_UD:
708 rotatedZAngle = 90.0f;
711 case _OVERLAY_AGENT_ROTATION_180: // fall through
712 case _OVERLAY_AGENT_ROTATION_180_LR: // fall through
713 case _OVERLAY_AGENT_ROTATION_180_UD:
714 rotatedZAngle = 180.0f;
717 case _OVERLAY_AGENT_ROTATION_270: // fall through
718 case _OVERLAY_AGENT_ROTATION_270_LR: // fall through
719 case _OVERLAY_AGENT_ROTATION_270_UD:
720 rotatedZAngle = 270.0f;
727 //Set bounds of rotated renderer
728 FloatRectangle rendererBounds = __standardRendererBounds;
729 if (rotatedZAngle == 90.0f || rotatedZAngle == 270.0f )
731 rendererBounds.x = __standardRendererBounds.x - ((__standardRendererBounds.height - __standardRendererBounds.width) / 2.0f);
732 rendererBounds.y = __standardRendererBounds.y + ((__standardRendererBounds.height - __standardRendererBounds.width) / 2.0f);
733 std::swap(rendererBounds.height, rendererBounds.width);
736 result r = __pRendererVE->SetBounds(rendererBounds);
737 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
739 r = __pRendererVE->SetProperty(L"transform.rotation.z", rotatedZAngle);
740 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
741 SysLog(NID_UI_CTRL, "The current Overlay Renderer is rotated (%d -> %d)", static_cast<int>(initialZAngle), static_cast<int>(rotatedZAngle));
745 case _OVERLAY_AGENT_ROTATION_NONE: // fall through
746 case _OVERLAY_AGENT_ROTATION_90: // fall through
747 case _OVERLAY_AGENT_ROTATION_180: // fall through
748 case _OVERLAY_AGENT_ROTATION_270:
749 r = __pRendererVE->SetProperty(L"transform.rotation.x", 0.0f);
750 r = __pRendererVE->SetProperty(L"transform.rotation.y", 0.0f);
753 case _OVERLAY_AGENT_ROTATION_NONE_UD: // fall through
754 case _OVERLAY_AGENT_ROTATION_180_UD: // fall through
755 case _OVERLAY_AGENT_ROTATION_90_LR: // fall through
756 case _OVERLAY_AGENT_ROTATION_270_LR:
757 r = __pRendererVE->SetProperty(L"transform.rotation.x", 180.0f);
758 r = __pRendererVE->SetProperty(L"transform.rotation.y", 0.0f);
759 SysLog(NID_UI_CTRL, "The current Overlay Renderer is flipped over up side down.");
762 case _OVERLAY_AGENT_ROTATION_NONE_LR: // fall through
763 case _OVERLAY_AGENT_ROTATION_180_LR: // fall through
764 case _OVERLAY_AGENT_ROTATION_90_UD: // fall through
765 case _OVERLAY_AGENT_ROTATION_270_UD:
766 r = __pRendererVE->SetProperty(L"transform.rotation.x", 0.0f);
767 r = __pRendererVE->SetProperty(L"transform.rotation.y", 180.0f);
768 SysLog(NID_UI_CTRL, "The current Overlay Renderer is flipped over left side right.");
774 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
776 __currentRotation = rotation;
778 r = __pRendererVE->SetFlushNeeded();
779 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
785 _OverlayAgent::SetDestination(const FloatDimension& dimension)
787 SysTryReturnResult(NID_UI_CTRL, __pParentVE != null, E_SYSTEM, "The Renderer Visual Element is null");
788 SysTryReturnResult(NID_UI_CTRL, __pRendererVE != null, E_SYSTEM, "The Renderer Visual Element is null");
789 if (__standardRendererBounds.width == dimension.width && __standardRendererBounds.height == dimension.height &&
790 __standardParentBounds.width == __pParentVE->GetBounds().width && __standardParentBounds.height == __pParentVE->GetBounds().height)
795 //Set bounds of saved renderer
796 FloatRectangle parentBounds= __pParentVE->GetBounds();
798 if (parentBounds.width >= dimension.width)
800 __standardRendererBounds.x = (parentBounds.width - dimension.width) / 2.0f;
801 __standardRendererBounds.width = dimension.width;
805 __standardRendererBounds.x = 0.0f;
806 __standardRendererBounds.width = parentBounds.width;
809 if (parentBounds.height >= dimension.height)
811 __standardRendererBounds.y = (parentBounds.height - dimension.height) / 2.0f;
812 __standardRendererBounds.height = dimension.height;
816 __standardRendererBounds.y = 0.0f;
817 __standardRendererBounds.height = parentBounds.height;
820 //Set bounds of resizing renderer
821 float parentWidth = parentBounds.width;
822 float parentHeight = parentBounds.height;
823 FloatDimension inputDimension(dimension.width, dimension.height);
825 Variant rotationAngle = __pRendererVE->GetProperty(L"transform.rotation.z");
826 if(rotationAngle.ToFloat() == 90.0f || rotationAngle.ToFloat() == 270.0f)
828 std::swap(parentWidth, parentHeight);
829 std::swap(inputDimension.width, inputDimension.height);
832 FloatRectangle rendererBounds = __standardRendererBounds;
834 if (parentWidth >= inputDimension.width)
836 rendererBounds.x = (parentBounds.width - inputDimension.width) / 2.0f;
837 rendererBounds.width = inputDimension.width;
841 rendererBounds.x = 0.0f;
842 rendererBounds.width = parentBounds.width;
845 if (parentHeight >= inputDimension.height)
847 rendererBounds.y = (parentBounds.height - inputDimension.height) / 2.0f;
848 rendererBounds.height = inputDimension.height;
852 rendererBounds.y = 0.0f;
853 rendererBounds.height = parentBounds.height;
855 SysLog(NID_UI_CTRL, "The current bounds of resized renderer is [%.3f, %.3f, %.3f, %.3f]",
856 __standardRendererBounds.x, __standardRendererBounds.y, __standardRendererBounds.width, __standardRendererBounds.height);
858 result r = __pRendererVE->SetBounds(rendererBounds);
859 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
861 r = __pRendererVE->SetFlushNeeded();
862 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
864 __standardParentBounds = __pParentVE->GetBounds();
870 _OverlayAgent::SetAspectRatio(bool enable)
876 _OverlayAgent::GetBounds(void) const
878 SysTryReturn(NID_UI_CTRL, __pRendererVE != null, FloatRectangle(0.0f, 0.0f, 0.1f, 0.1f), E_SYSTEM, "The Renderer Visual Element is null");
879 return __standardRendererBounds;
883 _OverlayAgent::CreateRendererVisualElement(const _Control& parentControl, const FloatRectangle& logicalBounds, const Rectangle& physicalBounds)
885 //Create new VisualElement and insert it to Parent's VisualElement
886 unique_ptr<_VisualElement, visualElementDeleter> pRendererVE(new (std::nothrow) _VisualElement());
887 SysTryReturnResult(NID_UI_CTRL, pRendererVE != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient");
889 result r = pRendererVE->Construct();
890 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
892 pRendererVE->SetName("OverlayRenderer");
893 pRendererVE->SetShowState(true);
894 //pRendererVE->SetImplicitAnimationEnabled(true);
895 pRendererVE->SetImplicitAnimationEnabled(false);
896 pRendererVE->SetZOrderGroup(_CONTROL_LAYER_OVERLAY);
898 FloatPoint logicalPoint(0.0f, 0.0f);
899 if(__style == _OVERLAY_AGENT_STYLE_REGION_SW || __style == _OVERLAY_AGENT_STYLE_REGION_GL)
901 logicalPoint.x = logicalBounds.x;
902 logicalPoint.y = logicalBounds.y;
904 pRendererVE->SetBounds(FloatRectangle(logicalPoint.x, logicalPoint.y, logicalBounds.width, logicalBounds.height));
907 __pParentVE = parentControl.GetVisualElement();
908 SysTryReturnResult(NID_UI_CTRL, __pParentVE != null, E_SYSTEM, "[E_SYSTEM] The current value of OverlayPanel's VisualElement is null.");
910 __pParentVE->SetName("OverlayPanel");
911 r = __pParentVE->InsertChild(pRendererVE.get(), null, true);
912 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
914 r = __pParentVE->SetSurfaceOpaque(true);
915 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
918 // Get and Set ImageObject of Renderer VisualElement
919 _EflNode* pEflNode = dynamic_cast<_EflNode*>(pRendererVE->GetNativeNode());
920 SysTryReturnResult(NID_UI_CTRL, pEflNode != null, E_SYSTEM, "Failed to get EflNode from Renderer VisualElement.");
922 Evas_Object* pSmartObject = (Evas_Object*) pEflNode->GetGroupContainer();
923 SysTryReturnResult(NID_UI_CTRL, pSmartObject != null, E_SYSTEM, "Failed to get Group Container of Renderer VisualElement.");
925 Evas* pEvas = evas_object_evas_get(pSmartObject);
926 SysTryReturnResult(NID_UI_CTRL, pEvas != null, E_SYSTEM, "Failed to get Evas of Renderer VisualElement.");
928 Ecore_Evas* pEcoreEvas = ecore_evas_ecore_evas_get(pEvas);
929 SysTryReturnResult(NID_UI_CTRL, pEcoreEvas != null, E_SYSTEM, "Failed to get Ecore Evas of Renderer VisualElement.");
931 __pImageObject = evas_object_image_add(pEvas);
932 SysTryReturnResult(NID_UI_CTRL, __pImageObject != null, E_SYSTEM, "Failed to get Renderer Image Object.");
934 evas_object_name_set(__pImageObject, "OverlayRenderer");
935 evas_object_image_size_set(__pImageObject, physicalBounds.width, physicalBounds.height);
936 evas_object_image_alpha_set(__pImageObject, false);
937 evas_object_image_filled_set(__pImageObject, EINA_TRUE);
938 evas_object_resize(__pImageObject, physicalBounds.width, physicalBounds.height);
939 evas_object_move(__pImageObject, physicalBounds.x, physicalBounds.y);
940 evas_object_show(__pImageObject);
942 DisplayContext* pDisplayContext = parentControl.GetRootWindow()->GetDisplayContext();
943 SysTryReturnResult(NID_UI_CTRL, pDisplayContext != null, E_SYSTEM, "[E_SYSTEM] The current value of RootWindow's DisplayContext is null.");
945 unique_ptr<VisualElementSurface> pRendererSurface(_VisualElementSurfaceImpl::CreateSurfaceUsingExistingObjectN(*pDisplayContext, (Handle)__pImageObject, Dimension(physicalBounds.width, physicalBounds.height)));
946 SysTryReturnResult(NID_UI_CTRL, pRendererSurface != null, E_SYSTEM, "[E_SYSTEM] The current value of RootWindow's DisplayContext is null.");
948 r = pRendererVE->SetSurface(pRendererSurface.release());
949 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
951 r = pRendererVE->SetFlushNeeded();
952 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
954 pRendererVE->SetAnchor(FloatPoint(0.5f, 0.5f));
955 __pRendererVE = pRendererVE.release();
956 __standardRendererBounds = __pRendererVE->GetBounds();
958 if (__style == _OVERLAY_AGENT_STYLE_REGION_SW || __style == _OVERLAY_AGENT_STYLE_PANEL_SW)
960 evas_object_image_pixels_get_callback_set(__pImageObject, OnEvasImageDamaged,(void*)this);
967 _OverlayAgent::CreatePixmap(const Rectangle& physicalBounds)
970 Dimension pixmapSize(physicalBounds.width, physicalBounds.height);
971 SysTryReturnResult(NID_UI_CTRL, (pixmapSize.width >= GetDstRectMinWidth()) && (pixmapSize.height >= GetDstRectMinHeight()),
972 E_SYSTEM, "input size (%d, %d) is too small to create a pixmap",pixmapSize.width, pixmapSize.height);
975 Display *pDisplay = (Display*)ecore_x_display_get();
976 SysTryReturnResult(NID_UI_CTRL, pDisplay != null, E_SYSTEM, "The current value of Display is null");
978 __pixmap = XCreatePixmap(pDisplay, DefaultRootWindow(pDisplay), pixmapSize.width, pixmapSize.height, DefaultDepth(pDisplay, DefaultScreen(pDisplay)));
979 SysTryReturnResult(NID_UI_CTRL, __pixmap != 0, E_SYSTEM, "Failed to create a pixmap of Overlay Agent");
981 GC gc = XCreateGC(pDisplay, __pixmap, 0,0);
982 SysTryReturnResult(NID_UI_CTRL, gc > 0, E_SYSTEM, "Failed to create Graphic Contexts");
985 XSetForeground(pDisplay, gc, (long unsigned int)(Color(0xff000000).GetRGB32()));
986 XFillRectangle(pDisplay, __pixmap, gc, 0, 0, pixmapSize.width, pixmapSize.height);
988 XFreeGC(pDisplay, gc);
990 //Set evas native surface
991 Evas_Native_Surface evasNativeSuface = {0,};
993 evasNativeSuface.version = EVAS_NATIVE_SURFACE_VERSION;
994 evasNativeSuface.type = EVAS_NATIVE_SURFACE_X11;
995 evasNativeSuface.data.x11.visual = ecore_x_default_visual_get(ecore_x_display_get(), ecore_x_default_screen_get());
996 evasNativeSuface.data.x11.pixmap = __pixmap;
998 evas_object_lower(__pImageObject);
999 evas_object_image_native_surface_set(__pImageObject, &evasNativeSuface);
1001 __pixmapDamageHandle = ecore_x_damage_new(__pixmap, ECORE_X_DAMAGE_REPORT_RAW_RECTANGLES);
1002 SysTryCatch(NID_UI_CTRL, __pixmapDamageHandle != 0, , E_SYSTEM, "[E_SYSTEM] Failed to create a damage object");
1004 __pPixmapEventHandler = ecore_event_handler_add(ECORE_X_EVENT_DAMAGE_NOTIFY, OnPixmapDamaged, (void*)this);
1005 SysTryCatch(NID_UI_CTRL, __pPixmapEventHandler != null, , E_SYSTEM, "[E_SYSTEM] Failed to add a pixmap damage event handle");
1010 if (__pPixmapEventHandler)
1012 ecore_event_handler_del(__pPixmapEventHandler);
1013 __pPixmapEventHandler = null;
1016 if (__pixmapDamageHandle)
1018 ecore_x_damage_free(__pixmapDamageHandle);
1019 __pixmapDamageHandle = 0;
1024 XFreePixmap((Display*)ecore_x_display_get(), __pixmap);
1032 _OverlayAgent::GetPixmap(void) const
1038 _OverlayAgent::GetRendererImageObject(void) const
1040 return __pImageObject;
1044 _OverlayAgent::IsValidDestinationDimension(const FloatDimension& dimension) const
1046 FloatDimension physicalDimensionF = _CoordinateSystemUtils::Transform(dimension);
1047 Dimension physicalDimension = _CoordinateSystemUtils::ConvertToInteger(physicalDimensionF);
1048 SysTryReturn(NID_UI_CTRL, (physicalDimension.width >= GetDstRectMinWidth() && physicalDimension.height >= GetDstRectMinHeight()), false, E_INVALID_ARG,
1049 "[E_INVALID_ARG] The size of input dimension (logical size : [%.3f, %.3f], physical size : [%d,%d]) is under minimun size."
1050 ,dimension.width, dimension.height, physicalDimension.width, physicalDimension.height);
1052 FloatRectangle parentBounds = __pParentVE->GetBounds();
1053 SysTryReturn(NID_UI_CTRL, (dimension.width <= parentBounds.width || dimension.height <= parentBounds.height), false, E_INVALID_ARG,
1054 "[E_INVALID_ARG] The size of input dimension[%.3f, %.3f] is over maximum size[%.3f,%.3f]."
1055 ,dimension.width, dimension.height, parentBounds.width, parentBounds.height);
1061 _OverlayAgent::GetOverlayAgentCount(void)
1063 return __overlayAgentCount;
1067 _OverlayAgent::GetPixelFormatListN(void)
1069 if (!__OverlayAgentBufferPixelFormat[0])
1071 const wchar_t* _UI_REGISTRY_PATH = L"/usr/etc/system-info.ini";
1072 const wchar_t* _UI_INFO_SESSION = L"UiControlInfo";
1074 _RegistryImpl registry;
1075 result r = registry.Construct(_UI_REGISTRY_PATH, REG_OPEN_READ_ONLY, null);
1076 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1078 String pixelFormatList(null);
1079 r = registry.GetValue(_UI_INFO_SESSION, L"OverlayRegionBufferPixelFormat", pixelFormatList);
1080 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1083 if (pixelFormatList.Contains(L"ARGB8888"))
1085 __OverlayAgentBufferPixelFormat[_OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_ARGB8888] = true;
1089 if (pixelFormatList.Contains(L"RGB565"))
1091 __OverlayAgentBufferPixelFormat[_OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_RGB565] = true;
1095 if (pixelFormatList.Contains(L"YCbCr420P"))
1097 __OverlayAgentBufferPixelFormat[_OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_YCbCr420_PLANAR] = true;
1101 if (pixelFormatList.Contains(L"NV12"))
1103 __OverlayAgentBufferPixelFormat[_OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_NV12] = true;
1107 if (pixelFormatList.Contains(L"UYVY"))
1109 __OverlayAgentBufferPixelFormat[_OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_UYVY] = true;
1113 SysAssertf(set, "The registry file is an invalid.");
1115 __OverlayAgentBufferPixelFormat[0] = set;
1118 std::unique_ptr< ArrayListT<bool> > pFormatList( new (std::nothrow) ArrayListT<bool>());
1119 SysTryReturn(NID_UI_CTRL, pFormatList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] failed to create a list instance");
1121 result r = pFormatList->Construct();
1122 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1124 for (int index = _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_ARGB8888; index <= _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_UYVY; index++)
1126 r = pFormatList->Add(__OverlayAgentBufferPixelFormat[index]);
1128 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1130 return pFormatList.release();
1134 _OverlayAgent::EvaluateBounds(OverlayAgentEvaluationOption option, FloatRectangle& rect, bool& modified)
1137 SysTryReturnResult(NID_UI_CTRL, rect.width > 0.0f && rect.height > 0.0f,
1138 E_INVALID_ARG, "The size of input rectangle(%.3f, %.3f) is invalid.", rect.width, rect.height);
1140 Rectangle logicalEvaluatingBounds = _CoordinateSystemUtils::ConvertToInteger(rect);
1141 SysTryReturnResult(NID_UI_CTRL, logicalEvaluatingBounds.width > 0 && logicalEvaluatingBounds.height > 0,
1142 E_INVALID_ARG, "The size of logical rectangle(%d, %d) is invalid.", logicalEvaluatingBounds.width, logicalEvaluatingBounds.height);
1144 Rectangle physicalRect(_CoordinateSystemUtils::Transform(logicalEvaluatingBounds));
1145 SysTryReturnResult(NID_UI_CTRL, physicalRect.width > 0 && physicalRect.height > 0,
1146 E_INVALID_ARG, "The size of physical rectangle(%d, %d) is invalid.", physicalRect.width, physicalRect.height);
1148 int physicalMinWidth = GetDstRectMinWidth();
1149 int physicalMinHeight = GetDstRectMinHeight();
1150 SysTryReturnResult(NID_UI_CTRL, physicalMinWidth > 0 && physicalMinHeight > 0, E_SYSTEM, "The value of overlay control's Min width and Min height are invalid.");
1152 const int widthUnit = GetWidthUnit();
1153 const int heightUnit = GetHeightUnit();
1154 SysTryReturnResult(NID_UI_CTRL, widthUnit > 0 && heightUnit > 0, E_SYSTEM, "The value of overlay control's width Unit and height Unit are invalid.");
1156 int screenWidth = _Screen::GetWidth();
1157 int screenHeight = _Screen::GetHeight();
1158 SysTryReturnResult(NID_UI_CTRL, screenWidth > 0 && screenHeight > 0, E_SYSTEM, "The value of screen size is invalid.");
1160 //If orientation status of screen is landscape mode, swap width and height.
1162 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
1163 int orientation = ecore_evas_rotation_get(pEcoreEvas->GetEcoreEvas());
1165 if (orientation == 90 || orientation == 270)
1167 int temp = screenWidth;
1168 screenWidth = screenHeight;
1169 screenHeight = temp;
1170 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);
1174 int physicalMaxWidth= screenWidth - (screenWidth % widthUnit);
1175 int physicalMaxHeight = screenHeight - (screenHeight % heightUnit);
1176 int logicalMaxWidth = _CoordinateSystemUtils::InverseHorizontalTransform(physicalMaxWidth);
1177 int logicalMaxHeight = _CoordinateSystemUtils::InverseVerticalTransform(physicalMaxHeight);
1179 int widthReminder = physicalRect.width % widthUnit;
1180 int heightReminder = physicalRect.height % heightUnit;
1182 //Fix one pixel error when coordinate system transform
1183 if (widthReminder == 1)
1185 physicalRect.width -= 1;
1186 widthReminder = physicalRect.width % widthUnit;
1189 if (heightReminder == 1)
1191 physicalRect.height -= 1;
1192 heightReminder = physicalRect.height % heightUnit;
1197 case OVERLAY_AGENT_EVALUATION_OPTION_GREATER_THAN:
1199 if (logicalEvaluatingBounds.width > logicalMaxWidth || logicalEvaluatingBounds.height > logicalMaxHeight)
1201 SysLogException(NID_UI_CTRL, E_UNSUPPORTED_OPTION, "[E_UNSUPPORTED_OPTION] The size of input rect exceeds logical maximun size.");
1202 return E_UNSUPPORTED_OPTION;
1205 if (physicalRect.width > physicalMaxWidth || physicalRect.height > physicalMaxHeight)
1207 SysLogException(NID_UI_CTRL, E_UNSUPPORTED_OPTION, "[E_UNSUPPORTED_OPTION] The size of input rect exceeds physical maximun size.");
1208 return E_UNSUPPORTED_OPTION;
1211 if (widthReminder != 0)
1213 widthReminder -= widthUnit;
1216 if (heightReminder != 0)
1218 heightReminder -= heightUnit;
1221 physicalRect.width -= widthReminder;
1222 physicalRect.height -= heightReminder;
1224 if (physicalRect.width < physicalMinWidth)
1226 physicalRect.width = physicalMinWidth;
1229 if (physicalRect.height < physicalMinHeight)
1231 physicalRect.height = physicalMinHeight;
1235 case OVERLAY_AGENT_EVALUATION_OPTION_LESS_THAN:
1237 if (physicalRect.width < physicalMinWidth || physicalRect.height < physicalMinHeight)
1239 SysLogException(NID_UI_CTRL, E_UNSUPPORTED_OPTION, "[E_UNSUPPORTED_OPTION] The size of input rect is under minimun size.");
1241 return E_UNSUPPORTED_OPTION;
1244 if (physicalRect.width > physicalMaxWidth)
1246 physicalRect.width = physicalMaxWidth + widthReminder;
1249 if (physicalRect.height > physicalMaxHeight)
1251 physicalRect.height = physicalMaxHeight + heightReminder;
1254 physicalRect.width -= widthReminder;
1255 physicalRect.height -= heightReminder;
1260 SysLogException(NID_UI_CTRL, E_UNSUPPORTED_OPTION, "[E_UNSUPPORTED_OPTION] The input option is an invalid.");
1262 return E_UNSUPPORTED_OPTION;
1266 FloatRectangle originalInputRect(rect);
1267 rect = _CoordinateSystemUtils::ConvertToFloat(_CoordinateSystemUtils::InverseTransform(physicalRect));
1269 if (rect != originalInputRect)
1272 SysLog(NID_UI_CTRL, "The input bounds [%.3f, %.3f, %.3f, %.3f] is modified to [%.3f, %.3f, %.3f, %.3f]",
1273 originalInputRect.x, originalInputRect.y, originalInputRect.width, originalInputRect.height,
1274 rect.x, rect.y, rect.width, rect.height);
1278 SysLog(NID_UI_CTRL, "The evaluated bounds [%.3f, %.3f, %.3f, %.3f] is valid.",
1279 rect.x, rect.y, rect.width, rect.height);
1282 result r = GetLastResult();
1283 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1289 _OverlayAgent::GetValueFromRegistry(const String& key)
1291 const wchar_t* _UI_REGISTRY_PATH = L"/usr/etc/system-info.ini";
1292 const wchar_t* _UI_INFO_SESSION = L"UiControlInfo";
1294 _RegistryImpl registry;
1295 result r = registry.Construct(_UI_REGISTRY_PATH, REG_OPEN_READ_ONLY, null);
1296 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));
1298 String strValue(null);
1299 r = registry.GetValue(_UI_INFO_SESSION, key, strValue);
1300 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));
1303 r = Integer::Parse(strValue, value);
1304 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));
1310 _OverlayAgent::GetDstRectMinWidth(void)
1312 if (__dstRectMinWidth < 0)
1314 int value = GetValueFromRegistry(L"OverlayDstMinWidth");
1315 SysTryReturn(NID_UI_CTRL, value > 0, -1, E_SYSTEM, "[E_SYSTEM] Failed to get Overlay info from registry");
1317 __dstRectMinWidth = value;
1318 SysLog(NID_UI_CTRL, "The overlay control's minimum width of destination is [%d]", __dstRectMinWidth);
1321 SetLastResult(E_SUCCESS);
1323 return __dstRectMinWidth;
1327 _OverlayAgent::GetDstRectMinHeight(void)
1329 if (__dstRectMinHegith < 0)
1331 int value = GetValueFromRegistry(L"OverlayDstMinHeight");
1332 SysTryReturn(NID_UI_CTRL, value > 0, -1, E_SYSTEM, "[E_SYSTEM] Failed to get Overlay info from registry");
1334 __dstRectMinHegith = value;
1335 SysLog(NID_UI_CTRL, "The overlay control's minimum height of destination is [%d]", __dstRectMinHegith);
1338 SetLastResult(E_SUCCESS);
1340 return __dstRectMinHegith;
1344 _OverlayAgent::GetSrcRectMinWidth(void)
1346 if (__srcRectMinWidth < 0)
1348 int value = GetValueFromRegistry(L"OverlaySrcMinWidth");
1349 SysTryReturn(NID_UI_CTRL, value > 0, -1, E_SYSTEM, "[E_SYSTEM] Failed to get Overlay info from registry");
1351 __srcRectMinWidth = value;
1352 SysLog(NID_UI_CTRL, "The overlay control's minimum width of source buffer is [%d]", __srcRectMinWidth);
1355 SetLastResult(E_SUCCESS);
1357 return __srcRectMinWidth;
1361 _OverlayAgent::GetSrcRectMinHeight(void)
1363 if (__srcRectMinHegith < 0)
1365 int value = GetValueFromRegistry(L"OverlaySrcMinHeight");
1366 SysTryReturn(NID_UI_CTRL, value > 0, -1, E_SYSTEM, "[E_SYSTEM] Failed to get Overlay info from registry");
1368 __srcRectMinHegith = value;
1369 SysLog(NID_UI_CTRL, "The overlay control's minimum height of source buffer is [%d]", __srcRectMinHegith);
1372 SetLastResult(E_SUCCESS);
1374 return __srcRectMinHegith;
1378 _OverlayAgent::GetWidthUnit(void)
1380 if (__overlayWidthUnit < 0)
1382 int value = GetValueFromRegistry(L"OverlayRegionWidthUnit");
1383 SysTryReturn(NID_UI_CTRL, value > 0, -1, E_SYSTEM, "[E_SYSTEM] Failed to get Overlay info from registry");
1385 __overlayWidthUnit = value;
1386 SysLog(NID_UI_CTRL, "The overlay control's unit width is [%d]", __overlayWidthUnit);
1389 SetLastResult(E_SUCCESS);
1391 return __overlayWidthUnit;
1395 _OverlayAgent::GetHeightUnit(void)
1397 if (__overlayHeightUnit < 0)
1399 int value = GetValueFromRegistry(L"OverlayRegionHeightUnit");
1400 SysTryReturn(NID_UI_CTRL, value > 0, -1, E_SYSTEM, "[E_SYSTEM] Failed to get Overlay info from registry");
1402 __overlayHeightUnit = value;
1403 SysLog(NID_UI_CTRL, "The overlay control's unit height is [%d]", __overlayHeightUnit);
1406 SetLastResult(E_SUCCESS);
1408 return __overlayHeightUnit;
1412 _OverlayAgent::GetMaxCount(void)
1414 if (__overlayMaxCount < 0)
1416 int value = GetValueFromRegistry(L"MaxOverlayRegionCount");
1417 SysTryReturn(NID_UI_CTRL, value > 0, -1, E_SYSTEM, "[E_SYSTEM] Failed to get Overlay info from registry");
1419 __overlayMaxCount = value;
1420 SysLog(NID_UI_CTRL, "The overlay control's maximum count is [%d]", __overlayMaxCount);
1423 SetLastResult(E_SUCCESS);
1425 return __overlayMaxCount;