Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_OverlayRegionImpl.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_OverlayRegionImpl.cpp
20  * @brief               This is the implementation file for _OverlayRegionImpl class.
21  *
22  */
23
24 #include <new>
25 #include <unique_ptr.h>
26 #include <Ecore_Evas.h>
27 #include <Elementary.h>
28 #include <FSysSystemInfo.h>
29 #include <FIoFile.h>
30 #include <FBaseInteger.h>
31 #include <FBaseSysLog.h>
32
33 #include <FGrp_BufferInfoImpl.h>
34 #include <FSys_EnvironmentImpl.h>
35 #include <FIo_RegistryImpl.h>
36
37 #include "FUi_CoordinateSystemUtils.h"
38 #include "FUiCtrl_FormImpl.h"
39 #include "FUiCtrl_OverlayAgent.h"
40 #include "FUiCtrl_OverlayRegionImpl.h"
41
42 using namespace Tizen::Base;
43 using namespace Tizen::Base::Collection;
44 using namespace Tizen::Graphics;
45 using namespace Tizen::Io;
46 using namespace Tizen::Media;
47 using namespace Tizen::System;
48 using namespace Tizen::Ui;
49 using namespace Tizen::Ui::Controls;
50
51 namespace Tizen { namespace Ui { namespace Controls
52 {
53 const int _ROTATION_COUNT = 4;
54 int _OverlayRegionImpl::__primaryCameraRotation = -1;
55 int _OverlayRegionImpl::__secondaryCameraRotation = -1;
56 bool _OverlayRegionImpl::__overlayRegionPixelFomatList[]= {false,};
57
58 OverlayRegionRotate
59 _ConvertCamToOverlayRegionRotation(OverlayRegionType overlayRegionType, int cameraRotation, int formOrientation)
60 {
61         OverlayRegionRotate rotation = OVERLAYREGION_ROTATE_NONE;
62         int tempCameraRotation = 0;
63         int tempFormRotation = 0;
64
65         switch (cameraRotation)
66         {
67         case 1://CAMERA_ROTATION_NONE:
68                 tempCameraRotation = 0;
69                 break;
70         case 2://CAMERA_ROTATION_90:
71                 tempCameraRotation = 1;
72                 break;
73         case 3://CAMERA_ROTATION_180:
74                 tempCameraRotation = 2;
75                 break;
76         case 4://CAMERA_ROTATION_270:
77                 tempCameraRotation = 3;
78                 break;
79         default:
80                 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "[E_INVALID_ARG] The current rotation of camera[%d] is invalid", cameraRotation);
81                 return rotation;
82         }
83
84         switch (static_cast<OrientationStatus>(formOrientation))
85         {
86         case ORIENTATION_STATUS_PORTRAIT:
87                 tempFormRotation = 0;
88                 break;
89         case ORIENTATION_STATUS_LANDSCAPE:
90                 tempFormRotation = 1;
91                 break;
92         case ORIENTATION_STATUS_PORTRAIT_REVERSE:
93                 tempFormRotation = 2;
94                 break;
95         case ORIENTATION_STATUS_LANDSCAPE_REVERSE:
96                 tempFormRotation = 3;
97                 break;
98         default:
99                 SysLogException(NID_UI_CTRL, E_INVALID_ARG, "[E_INVALID_ARG] The current rotation of form[%d] is invalid", formOrientation);
100                 return rotation;
101         }
102
103         switch (overlayRegionType)
104         {
105         case OVERLAY_REGION_TYPE_NORMAL:
106                 rotation = OVERLAYREGION_ROTATE_0;
107                 break;
108         case OVERLAY_REGION_TYPE_PRIMARY_CAMERA:
109                 rotation = static_cast<OverlayRegionRotate>((_ROTATION_COUNT - (tempFormRotation - tempCameraRotation)) % _ROTATION_COUNT);
110                 break;
111         case OVERLAY_REGION_TYPE_SECONDARY_CAMERA:
112                 rotation = static_cast<OverlayRegionRotate>((tempFormRotation + tempCameraRotation) % _ROTATION_COUNT);
113                 break;
114         default:
115                 break;
116         }
117         SysSecureLog(NID_UI_CTRL, "The current OverlayRegion's type is [%d], rotation is [%d]", overlayRegionType, rotation);
118
119         return rotation;
120 }
121
122 _OverlayRegionImpl::_OverlayRegionImpl(void)
123         : __pParentForm(null)
124         , __pOverlayRegion(null)
125         , __overlayRegionType(OVERLAY_REGION_TYPE_MIN)
126         , __pOverlayAgent(null)
127         , __destRect(0.0f, 0.0f, 0.0f, 0.0f)
128         , __overlayRegionIndex(-1)
129         , __showState(true)
130         , __cameraRotation(1)
131 {
132 }
133
134 _OverlayRegionImpl::~_OverlayRegionImpl(void)
135 {
136         if (__pParentForm)
137         {
138                 if (__overlayRegionIndex != -1)
139                 {
140                         __pParentForm->__pOverlayerRegionImplArray[__overlayRegionIndex] = null;
141                 }
142
143                 __pParentForm->__overlayRegionCount--;
144         }
145         SysSecureLog(NID_UI_CTRL, "The [%d]th OverlayRegion in form[%x] is deleted.", __overlayRegionIndex, __pParentForm);
146
147         if (__pOverlayAgent)
148         {
149                 delete __pOverlayAgent;
150         }
151 }
152
153 Tizen::Graphics::FloatRectangle
154 _OverlayRegionImpl::GetBounds(void) const
155 {
156         return __destRect;
157 }
158
159 void
160 _OverlayRegionImpl::GetBounds(float& x, float& y, float& width, float& height) const
161 {
162         x = __destRect.x;
163         y = __destRect.y;
164         width = __destRect.width;
165         height = __destRect.height;
166 }
167
168 result
169 _OverlayRegionImpl::SetInputBuffer(const Tizen::Base::ByteBuffer& srcBuffer, const Tizen::Graphics::Dimension& srcDim, OverlayRegionBufferPixelFormat srcFormat)
170 {
171         SysTryReturnResult(NID_UI_CTRL, __pOverlayAgent != null, E_INVALID_STATE, "The current value of OverlayAgent is null.");
172         SysTryReturnResult(NID_UI_CTRL, __showState, E_SYSTEM, "The current Overlay Region is on back ground. Not yet draw.");
173
174         SysTryReturnResult(NID_UI_CTRL, srcDim.width > 0 && srcDim.height > 0, E_INVALID_ARG, " The current value of source dimension[%d, %d] is invalid", srcDim.width, srcDim.height);
175         SysTryReturnResult(NID_UI_CTRL, srcDim.width % OverlayRegion::GetWidthUnit() == 0 && srcDim.height % OverlayRegion::GetHeightUnit()== 0, E_INVALID_ARG,
176                 "The current value of source dimension[%d, %d] is invalid. It should be multiple of OverlayRegion::GetWidthUnit() & GetHeightUnit()", srcDim.width, srcDim.height);
177
178         if (!__overlayRegionPixelFomatList[0])
179         {
180                 result r = _OverlayRegionImpl::SetPixelFormatList();
181                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
182         }
183
184         _OverlayAgentBufferPixelFormat format = _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_ARGB8888;
185
186         switch (srcFormat)
187         {
188         case OVERLAY_REGION_BUFFER_PIXEL_FORMAT_ARGB8888:
189                 format = _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_ARGB8888;
190                 break;
191         case OVERLAY_REGION_BUFFER_PIXEL_FORMAT_RGB565:
192                 format = _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_RGB565;
193                 break;
194         case OVERLAY_REGION_BUFFER_PIXEL_FORMAT_YCbCr420_PLANAR:
195                 format = _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_YCbCr420_PLANAR;
196                 break;
197         case OVERLAY_REGION_BUFFER_PIXEL_FORMAT_NV12:
198                 format = _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_NV12;
199                 break;
200         case OVERLAY_REGION_BUFFER_PIXEL_FORMAT_UYVY:
201                 format = _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_UYVY;
202                 break;
203         default:
204                 SysLogException(NID_UI_CTRL, E_UNSUPPORTED_FORMAT, "[E_UNSUPPORTED_FORMAT] The input value of srcFormat[%d] is unsupported.", srcFormat);
205                 return E_UNSUPPORTED_FORMAT;
206         }
207
208         if (!__overlayRegionPixelFomatList[srcFormat])
209         {
210                 SysLogException(NID_UI_CTRL, E_UNSUPPORTED_FORMAT, "[E_UNSUPPORTED_FORMAT] The input value of srcFormat[%d] is unsupported.", srcFormat);
211                 return E_UNSUPPORTED_FORMAT;
212         }
213
214         int size = srcBuffer.GetCapacity();
215         SysTryReturnResult(NID_UI_CTRL, size > 0, E_INVALID_ARG, "The current size of source[%d] is invalid.", size);
216
217         result r = __pOverlayAgent->SetInputBuffer(srcBuffer, srcDim, format);
218         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
219
220         r = __pOverlayAgent->Draw();
221         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
222
223         return E_SUCCESS;
224 }
225
226 result
227 _OverlayRegionImpl::GetBackgroundBufferInfo(Tizen::Graphics::BufferInfo& info) const
228 {
229         SysTryReturnResult(NID_UI_CTRL, __pOverlayAgent != null, E_INVALID_STATE, "The current value of OverlayAgent is null.");
230
231         result r = __pOverlayAgent->GetBufferInfo(info);
232         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
233
234         _BufferInfoImpl* pBufferInfoImpl = _BufferInfoImpl::GetInstance(info);
235         SysTryReturnResult(NID_UI_CTRL, pBufferInfoImpl != null , E_SYSTEM, "The current value of BufferInfo is null.");
236
237         _FormImpl* pFormImpl = static_cast<_FormImpl*>(__pParentForm->GetUserData());
238         SysTryReturnResult(NID_UI_CTRL, pFormImpl != null, E_SYSTEM, "The current value of parent form is null.");
239
240         OrientationStatus formOrientationStatus = pFormImpl->GetOrientationStatus();
241         switch (formOrientationStatus)
242         {
243         case ORIENTATION_STATUS_NONE:
244                 //fall through
245         case ORIENTATION_STATUS_PORTRAIT:
246                 pBufferInfoImpl->SetOrientation(_BufferInfoImpl::ORIENTATION_PORTRAIT);
247                 break;
248         case ORIENTATION_STATUS_LANDSCAPE :
249                 pBufferInfoImpl->SetOrientation(_BufferInfoImpl::ORIENTATION_LANDSCAPE);
250                 break;
251         case ORIENTATION_STATUS_PORTRAIT_REVERSE:
252                 pBufferInfoImpl->SetOrientation(_BufferInfoImpl::ORIENTATION_PORTRAIT_REVERSE);
253                 break;
254         case ORIENTATION_STATUS_LANDSCAPE_REVERSE:
255                 pBufferInfoImpl->SetOrientation(_BufferInfoImpl::ORIENTATION_LANDSCAPE_REVERSE);
256                 break;
257         }
258
259         switch (__cameraRotation)
260         {
261         case 1: //CAMERA_ROTATION_NONE
262                 pBufferInfoImpl->SetRotation(_BufferInfoImpl::ROTATION_0);
263                 break;
264         case 2: //CAMERA_ROTATION_90:
265                 pBufferInfoImpl->SetRotation(_BufferInfoImpl::ROTATION_90);
266                 break;
267         case 3: //CAMERA_ROTATION_180:
268                 pBufferInfoImpl->SetRotation(_BufferInfoImpl::ROTATION_180);
269                 break;
270         case 4: //CAMERA_ROTATION_270:
271                 pBufferInfoImpl->SetRotation(_BufferInfoImpl::ROTATION_270);
272                 break;
273         }
274
275         return E_SUCCESS;
276 }
277
278 result
279 _OverlayRegionImpl::Construct(_Form* pParentForm, OverlayRegionType overlayRegionType, const FloatRectangle& userDestRect, const FloatRectangle& overlayLogRect, const Rectangle& finalPhyRect)
280 {
281         SysTryReturnResult(NID_UI_CTRL, pParentForm != null, E_SYSTEM, "The current value of Parent Form is null.");
282
283         _FormImpl* pFormImpl = static_cast<_FormImpl*>(pParentForm->GetUserData());
284         SysTryReturnResult(NID_UI_CTRL, pFormImpl != null, E_SYSTEM, "The Impl of Parent Form is null.");
285
286         _OverlayAgentStyle overlayAgentType = _OVERLAY_AGENT_STYLE_REGION_SW;
287         {
288                 String preferredEngineConfig(elm_config_preferred_engine_get());
289                 if(preferredEngineConfig.Equals("opengl_x11", true))
290                 {
291                         overlayAgentType = _OVERLAY_AGENT_STYLE_REGION_GL;
292                         SysLog(NID_UI_CTRL, "The current value of HwAcceleration is On");
293                 }
294                 else if(preferredEngineConfig.Equals("software_x11", true))
295                 {
296                         overlayAgentType = _OVERLAY_AGENT_STYLE_REGION_SW;
297                         SysLog(NID_UI_CTRL, "The current value of HwAcceleration is Off");
298                 }
299                 else
300                 {
301                         String engineConfig(elm_config_engine_get());
302                         if(engineConfig.Equals("opengl_x11", true))
303                         {
304                                 overlayAgentType = _OVERLAY_AGENT_STYLE_REGION_GL;
305                                 SysLog(NID_UI_CTRL,"The current value of HwAcceleration is On (System Default)");
306                         }
307                         else
308                         {
309                                 SysLog(NID_UI_CTRL,"The current value of HwAcceleration is Off (System Default)");
310                         }
311                 }
312         }
313
314         std::unique_ptr<_OverlayAgent> pOverlayAgent(_OverlayAgent::CreateInstanceN(overlayAgentType, *pParentForm, overlayLogRect, finalPhyRect));
315         SysTryReturnResult(NID_UI_CTRL, pOverlayAgent != null, E_SYSTEM, "The current value of OverlayAgent is null.");
316
317         result r = GetLastResult();
318         SysTryReturnResult(NID_UI_CTRL,r == E_SUCCESS, r, "Propagating.");
319
320         //Set Rotation of OverlayRegion
321         if (__primaryCameraRotation == -1 || __secondaryCameraRotation == -1)
322         {
323                 _OverlayRegionMediaCapability capability;
324                 r = capability.Construct();
325                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
326
327                 __primaryCameraRotation = capability.cameraPrimaryRotation;
328                 __secondaryCameraRotation = capability.cameraSecondaryRotation;
329         }
330
331         switch (overlayRegionType)
332         {
333         case OVERLAY_REGION_TYPE_NORMAL:
334                 __cameraRotation = 1; //CAMERA_ROTATION_NONE
335                 break;
336         case OVERLAY_REGION_TYPE_PRIMARY_CAMERA:
337                 __cameraRotation = __primaryCameraRotation;
338                 break;
339         case OVERLAY_REGION_TYPE_SECONDARY_CAMERA:
340                 __cameraRotation = __secondaryCameraRotation;
341                 break;
342         default:
343                 SysLogException(NID_UI_CTRL, E_UNSUPPORTED_FORMAT, "[E_UNSUPPORTED_FORMAT] The current type of OverlayRegion[%d] is unsupported", overlayRegionType);
344                 return E_UNSUPPORTED_FORMAT;
345         }
346
347         OverlayRegionRotate rotation = _ConvertCamToOverlayRegionRotation(overlayRegionType, __cameraRotation, pFormImpl->GetOrientationStatus());
348         SysTryReturnResult(NID_UI_CTRL, rotation != OVERLAYREGION_ROTATE_NONE, E_SYSTEM, "The current camera rotation is invalid.");
349
350         switch(rotation)
351         {
352         case OVERLAYREGION_ROTATE_0:
353                 r = pOverlayAgent->SetRotation(_OVERLAY_AGENT_ROTATION_NONE);
354                 break;
355         case OVERLAYREGION_ROTATE_90:
356                 r = pOverlayAgent->SetRotation(_OVERLAY_AGENT_ROTATION_90);
357                 break;
358         case OVERLAYREGION_ROTATE_180:
359                 r = pOverlayAgent->SetRotation(_OVERLAY_AGENT_ROTATION_180);
360                 break;
361         case OVERLAYREGION_ROTATE_270:
362                 r = pOverlayAgent->SetRotation(_OVERLAY_AGENT_ROTATION_270);
363                 break;
364         default:
365                 r = E_SYSTEM;
366                 break;
367         }
368         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
369
370         __pParentForm = pParentForm;
371         __overlayRegionType = overlayRegionType;
372         __destRect = userDestRect;
373         __pOverlayAgent = pOverlayAgent.release();
374
375         if(overlayAgentType == _OVERLAY_AGENT_STYLE_REGION_GL)
376         {
377                 r = __pOverlayAgent->CreatePixmap(finalPhyRect);
378                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
379         }
380         else if (overlayAgentType == _OVERLAY_AGENT_STYLE_REGION_SW)
381         {
382                 int size = (finalPhyRect.width * 2) * (finalPhyRect.height * 2);
383                 std::unique_ptr<byte[]> pBuffer(new (std::nothrow) byte[size]);
384                 SysTryReturnResult(NID_UI_CTRL, pBuffer != null, E_OUT_OF_MEMORY, "Failed to create a buffer for OverlayRegion.");
385
386                 unsigned long* pPos = (unsigned long*)pBuffer.get();
387                 for(int i = 0; i < finalPhyRect.height; i++)
388                 {
389                         for(int j = 0; j < finalPhyRect.width; j++)
390                         {
391                                 *pPos = 0xFF000000;
392                                 pPos++;
393                         }
394                 }
395
396                 ByteBuffer buffer;
397                 r = buffer.Construct(size);
398                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
399
400                 buffer.SetArray(pBuffer.get(), 0, size);
401                 r = SetInputBuffer(buffer, Dimension(finalPhyRect.width, finalPhyRect.height), OVERLAY_REGION_BUFFER_PIXEL_FORMAT_ARGB8888);
402                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
403         }
404         else
405         {
406                 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] The current type of OverlayAgen[%d] is invalid.", overlayRegionType);
407                 return E_SYSTEM;
408         }
409
410         return r;
411 }
412
413 OverlayRegion*
414 _OverlayRegionImpl::CreateOverlayRegionN(void)
415 {
416         OverlayRegion* pOverlayRegion = new (std::nothrow) OverlayRegion();
417         SysTryReturn(NID_UI_CTRL, pOverlayRegion != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The current value of OverlayRegion is null.");
418
419         __pOverlayRegion = pOverlayRegion;
420         __pOverlayRegion->__pOverlayRegionImpl = this;
421
422         return pOverlayRegion;
423 }
424
425 void
426 _OverlayRegionImpl::SetFormArrayIndex(int index)
427 {
428         __overlayRegionIndex = index;
429 }
430
431 OverlayRegion*
432 _OverlayRegionImpl::GetOverlayRegion(void) const
433 {
434         return __pOverlayRegion;
435 }
436
437 void
438 _OverlayRegionImpl::GoForeground(void)
439 {
440         ClearLastResult();
441         SysTryReturnVoidResult(NID_UI_CTRL, __pOverlayAgent != null, E_SYSTEM, "[E_SYSTEM] The current value of OverlayAgent is null.");
442
443         __showState = true;
444         SysSecureLog(NID_UI_CTRL, "The current pixmap[%d] of OverlayRegion is on foreground.", __pOverlayAgent->GetPixmap());
445 }
446
447 void
448 _OverlayRegionImpl::GoBackground(void)
449 {
450         ClearLastResult();
451         SysTryReturnVoidResult(NID_UI_CTRL, __pOverlayAgent != null, E_SYSTEM, "[E_SYSTEM] The current value of OverlayAgent is null.");
452
453         __showState = false;
454         __pOverlayAgent->UngrabXvPort();
455         SysSecureLog(NID_UI_CTRL, "The current pixmap[%d] of OverlayRegion is on background.", __pOverlayAgent->GetPixmap());
456 }
457
458 result
459 _OverlayRegionImpl::IsValidBounds(const Rectangle& physicalBounds)
460 {
461         int minWidth = _OverlayAgent::GetDstRectMinWidth();
462         int minHeight = _OverlayAgent::GetDstRectMinHeight();
463         SysTryReturnResult(NID_UI_CTRL, physicalBounds.width >= minWidth && physicalBounds.height >= minHeight, E_INVALID_ARG,
464                 "The current size of OverlayRegoin[%d, %d] is under minimum size[%d, %d].", physicalBounds.width, physicalBounds.height, minWidth, minHeight);
465
466         return E_SUCCESS;
467 }
468
469 result
470 _OverlayRegionImpl::SetPixelFormatList(void)
471 {
472         if (__overlayRegionPixelFomatList[0])
473         {
474                 return E_SUCCESS;
475         }
476
477         std::unique_ptr< IListT<bool> > pFormatList(_OverlayAgent::GetPixelFormatListN());
478         SysTryReturn(NID_UI_CTRL, pFormatList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to create a list instance");
479
480         bool set = false;
481         for (int formatIndex = 0; formatIndex < pFormatList->GetCount(); formatIndex++)
482         {
483                 bool value = false;
484                 pFormatList->GetAt(formatIndex, value);
485
486                 if (value)
487                 {
488                         __overlayRegionPixelFomatList[formatIndex + 1] = true;
489                         set = true;
490                 }
491         }
492
493         SysAssertf(set, "The list of supported pixel formats is an invalid.");
494
495         __overlayRegionPixelFomatList[0] = set;
496
497         return E_SUCCESS;
498 }
499
500 IListT<OverlayRegionBufferPixelFormat>*
501 _OverlayRegionImpl::GetSupportedBufferPixelFormatListN(void)
502 {
503         result r = E_SUCCESS;
504
505         if (!_OverlayRegionImpl::__overlayRegionPixelFomatList[0])
506         {
507                 r = _OverlayRegionImpl::SetPixelFormatList();
508                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
509         }
510
511         std::unique_ptr< ArrayListT<OverlayRegionBufferPixelFormat> > pFormatList( new (std::nothrow) ArrayListT<OverlayRegionBufferPixelFormat>());
512         SysTryReturn(NID_UI_CTRL, pFormatList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] failed to create a list instance");
513
514         r = pFormatList->Construct();
515         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
516
517         for (int index = _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_ARGB8888; index <= _OVERLAY_AGENT_BUFFER_PIXEL_FORMAT_UYVY; index++)
518         {
519                 if (_OverlayRegionImpl::__overlayRegionPixelFomatList[index])
520                 {
521                         r = pFormatList->Add(static_cast<OverlayRegionBufferPixelFormat>(index));
522                 }
523         }
524         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
525
526         return pFormatList.release();
527 }
528
529 _OverlayRegionImpl*
530 _OverlayRegionImpl::GetInstance(OverlayRegion& overlayRegion)
531 {
532         return (&overlayRegion != null) ? overlayRegion.__pOverlayRegionImpl : null;
533 }
534
535 const _OverlayRegionImpl*
536 _OverlayRegionImpl::GetInstance(const OverlayRegion& overlayRegion)
537 {
538         return (&overlayRegion != null) ? overlayRegion.__pOverlayRegionImpl : null;
539 }
540
541 } } } // Tizen::Ui::Controls
542
543
544
545 namespace
546 {
547 const char* _MEDIA_CAPABILITY_FILE_PATH = "/usr/etc/media-capability.xml";
548 const char* _CAM_PRIMARY_DIRECTION = "Camera.Primary.Direction";
549 const char* _CAM_PRIMARY_ROTATION = "Camera.Primary.Rotation";
550 const char* _CAM_SECONDARY_DIRECTION = "Camera.Secondary.Direction";
551 const char* _CAM_SECONDARY_ROTATION = "Camera.Secondary.Rotation";
552
553 _OverlayRegionMediaCapability::_OverlayRegionMediaCapability(void)
554         : cameraPrimaryDirection(0)
555         , cameraPrimaryRotation(0)
556         , cameraSecondaryDirection(0)
557         , cameraSecondaryRotation(0)
558 {
559 }
560
561 _OverlayRegionMediaCapability::~_OverlayRegionMediaCapability(void)
562 {
563 }
564
565 result
566 _OverlayRegionMediaCapability::Construct(void)
567 {
568         String fileName = _MEDIA_CAPABILITY_FILE_PATH;
569
570         FileAttributes attributes;
571         result r = File::GetAttributes(fileName, attributes);
572         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Propagating.");
573
574         long long length = attributes.GetFileSize();
575         SysTryReturnResult(NID_UI_CTRL, length > 0, E_SYSTEM, "The size of file(%s) is zero.", fileName.GetPointer());
576
577         std::unique_ptr<char[]> pXmlBuffer(new (std::nothrow) char[length]);
578         SysTryReturnResult(NID_UI_CTRL, pXmlBuffer != null, E_OUT_OF_MEMORY, "The Buffer of Xml is null");
579
580         File fileObj;
581         r = fileObj.Construct(fileName, L"r");
582         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Propagating.");
583
584         //Read the capability xml file content as parse the capability
585         int readLen = fileObj.Read(pXmlBuffer.get(), length);
586         SysTryReturnResult(NID_UI_CTRL, readLen == length, E_SYSTEM, "Failed to read xml file. (length is %d and readLen is %d)", length, readLen);
587
588         //Parse the capability file buffer all the parse key value pair shall be added in __pMap object
589         r = ParseCapability(pXmlBuffer.get(), readLen);
590         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Propagating.");
591
592         return r;
593 }
594
595 void
596 _OverlayRegionMediaCapability::ParseSection(xmlNodePtr pRoot, const String& section)
597 {
598         xmlNode* pNode = null;
599
600         for (pNode = pRoot->children; pNode; pNode = pNode->next)
601         {
602                 String name((char*)pNode->name);
603                 String key(section);
604
605                 key += "." + name;
606
607                 if (pNode->type == XML_ELEMENT_NODE && pNode->children)
608                 {
609                         if (key.Equals(String(_CAM_PRIMARY_DIRECTION)))
610                         {
611                                 String direction((char*)pNode->children->content);
612                                 if (direction.Equals(String("Back")))
613                                 {
614                                         cameraPrimaryDirection = 2; //CAMERA_DIRECTION_BACK;
615                                 }
616                                 else
617                                 {
618                                         cameraPrimaryDirection = 1; //CAMERA_DIRECTION_FRONT;
619                                 }
620                         }
621                         else if (key.Equals(String(_CAM_PRIMARY_ROTATION)))
622                         {
623                                 String rot((char*)pNode->children->content);
624                                 int ret = 0 ;
625                                 Integer::Decode(rot, ret);
626                                 cameraPrimaryRotation = (ret / 90) + 1;
627                         }
628                         else if (key.Equals(String(_CAM_SECONDARY_DIRECTION)))
629                         {
630                                 String direction((char*)pNode->children->content);
631                                 if (direction.Equals(String("Back")))
632                                 {
633                                         cameraSecondaryDirection = 2; //CAMERA_DIRECTION_BACK;
634                                 }
635                                 else
636                                 {
637                                         cameraSecondaryDirection = 1; //CAMERA_DIRECTION_FRONT;
638                                 }
639                         }
640                         else if (key.Equals(String(_CAM_SECONDARY_ROTATION)))
641                         {
642                                 String rot((char*)pNode->children->content);
643                                 int ret = 0 ;
644                                 Integer::Decode(rot, ret);
645                                 cameraSecondaryRotation = (ret / 90) + 1;
646                         }
647                 }
648
649                 ParseSection(pNode, key);
650         }
651 }
652
653 result
654 _OverlayRegionMediaCapability::ParseCapability(const char* xmlBuffer, int length)
655 {
656         std::unique_ptr<xmlDoc, xmlParserDeleter> pDoc(xmlParseMemory(xmlBuffer, length));
657         SysTryReturnResult(NID_UI_CTRL, pDoc != null, E_SYSTEM, "xmlParseMemory failed %s %d", xmlBuffer, length);
658
659         xmlNode* pRoot = xmlDocGetRootElement(pDoc.get());
660         SysTryReturnResult(NID_UI_CTRL, pRoot != null, E_SYSTEM, "[E_SYSTEM] xmlDocGetRootElement failed");
661
662         String name = (const char*) (pRoot->name);
663         SysSecureTryReturnResult(NID_UI_CTRL, name.Equals("MediaCapability", true), E_SYSTEM, "[E_SYSTEM]  Invalid Root Name %ls", name.GetPointer());
664
665         xmlNode* pNode = null;
666         for (pNode = pRoot->children; pNode; pNode = pNode->next)
667         {
668                 if (pNode->type == XML_ELEMENT_NODE)
669                 {
670                         String nodeName((char*)pNode->name);
671                         ParseSection(pNode, nodeName);
672                 }
673         }
674
675         return E_SUCCESS;
676 }
677
678 }