Tizen 2.1 base
[framework/osp/uifw.git] / src / graphics / FGrp_CanvasImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
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        FGrp_CanvasImpl.cpp
20  * @brief       This is the implementation file for _CanvasImpl class.
21  *
22  */
23
24 #include <new>
25 #include <memory>
26
27 #include <unique_ptr.h>
28
29 #include <FBaseSysLog.h>
30
31 #include "FGrp_BufferInfoImpl.h"
32 #include "FGrp_Callback.h"
33 #include "FGrp_CanvasImpl.h"
34 #include "FGrp_BitmapUtil.h"
35 #include "FGrp_Bitmap.h"
36 #include "FGrp_CanvasCoordHolder.h"
37 #include "FGrp_Canvas.h"
38 #include "FGrp_CanvasImplPrivate.h"
39 #include "FGrp_FontUtil.h"
40 #include "FGrp_EnrichedTextImpl.h"
41 #include "util/FGrp_Util.h"
42 #include "FGrp_TextTextObject.h"
43
44 using namespace Tizen::Base;
45 using namespace Tizen::Base::Collection;
46
47
48 #define EXTRACT_CANVASEX(pVar, canvas)          Tizen::Graphics::_Canvas * pVar = canvas._pNativeCanvas
49 #define EXTRACT_BITMAPEX(pVar, bitmap)          Tizen::Graphics::_Bitmap * pVar = Tizen::Graphics::GetBitmapEx(bitmap)
50 #define EXTRACT_FONTEX(pVar, font)              Tizen::Graphics::_Font * pVar = Tizen::Graphics::GetFontEx(font)
51 #define EXTRACT_SCALED_BITMAPEX(pVar, bitmap)   Tizen::Graphics::_Bitmap * pVar = Tizen::Graphics::GetScaledBitmapEx(bitmap)
52
53 #define IsSucceeded(X)          (!IsFailed(X))
54
55 #define INSTANCE_IS_VALID       (this && (this->_pNativeCanvas && this->_pNativeCanvas->IsValid()))
56 #define CANVAS_IS_VALID(canvas) (&canvas && (canvas._pNativeCanvas && canvas._pNativeCanvas->IsValid()))
57
58 #define BITMAP_IS_VALID(bitmap) (&bitmap && const_cast<_BitmapImpl*>(&bitmap)->__CheckValidity())
59
60
61 namespace // unnamed
62 {
63
64 // retrieving bounds rectangle which has (0,0,w,h).
65 Tizen::Graphics::Rectangle
66 _GetBoundsRel(const Tizen::Graphics::_CanvasImpl& canvas)
67 {
68         Tizen::Graphics::Rectangle rect = canvas.GetBounds();
69         rect.x = 0;
70         rect.y = 0;
71
72         return rect;
73 }
74
75 template<typename T>
76 void
77 _ExpandClippingAreaForLineWidth(Tizen::Graphics::Rectangle& rtCanvas, T lineWidth)
78 {
79         int lineWidthHalf = (lineWidth + 1) / 2;
80
81         rtCanvas.x -= lineWidthHalf;
82         rtCanvas.y -= lineWidthHalf;
83         rtCanvas.width += lineWidthHalf * 2;
84         rtCanvas.height += lineWidthHalf * 2;
85 }
86
87 }
88
89 namespace Tizen { namespace Graphics { namespace _Util
90 {
91
92 template <>
93 inline Tizen::Graphics::Point Convert<Tizen::Graphics::FloatPoint, Tizen::Graphics::Point>(const Tizen::Graphics::FloatPoint& point)
94 {
95         return Tizen::Graphics::Point(int(point.x), int(point.y));
96 }
97
98 template <>
99 inline Tizen::Graphics::Rectangle Convert<Tizen::Graphics::FloatRectangle, Tizen::Graphics::Rectangle>(const Tizen::Graphics::FloatRectangle& rect)
100 {
101         return Tizen::Graphics::Rectangle(int(rect.x), int(rect.y), int(rect.width), int(rect.height));
102 }
103
104 template <>
105 _Util::Point<double>* Convert<Tizen::Base::Collection::IList, _Util::Point<double>*>(const Tizen::Base::Collection::IList& points)
106 {
107         int count = points.GetCount();
108
109         std::unique_ptr<_Util::Point<double>[]> pPointArray(new (std::nothrow) _Util::Point<double>[count]);
110
111         SysTryReturn(NID_GRP, pPointArray, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
112
113         {
114                 for (int i = 0; i < count; i++)
115                 {
116                         const Tizen::Graphics::Point* pPoint = dynamic_cast <const Tizen::Graphics::Point*>(points.GetAt(i));
117
118                         if (pPoint)
119                         {
120                                 pPointArray[i].x = double(pPoint->x);
121                                 pPointArray[i].y = double(pPoint->y);
122                         }
123                         else
124                         {
125                                 const Tizen::Graphics::FloatPoint* pFloatPoint = dynamic_cast <const Tizen::Graphics::FloatPoint*>(points.GetAt(i));
126
127                                 if (pFloatPoint)
128                                 {
129                                         pPointArray[i].x = double(pFloatPoint->x);
130                                         pPointArray[i].y = double(pFloatPoint->y);
131                                 }
132                                 else
133                                 {
134                                         return null;
135                                 }
136                         }
137                 }
138         }
139
140         return pPointArray.release();
141 }
142
143 } // Tizen::Graphics::_Util
144
145 }} // Tizen::Graphics
146
147 ////////////////////////////////////////////////////////////////////////////////
148 //
149
150 namespace Tizen { namespace Graphics
151 {
152
153 _CanvasImpl::_CanvasImpl(void)
154         : _pNativeCanvas(0)
155         , _pCoordHolder(0)
156         , _pFont(0)
157         , _pPriorityFont(0)
158         , _dashOffset(0)
159 {
160         _pNativeCanvas = new (std::nothrow) _Canvas;
161         _pCoordHolder = new (std::nothrow) _CanvasCoordHolder;
162
163         if (_pNativeCanvas == null || _pCoordHolder == null)
164         {
165                 delete _pCoordHolder;
166                 delete _pNativeCanvas;
167
168                 _pCoordHolder = null;
169                 _pNativeCanvas = null;
170         }
171 }
172
173 _CanvasImpl::~_CanvasImpl(void)
174 {
175         if (_pFont)
176         {
177                 delete _pFont;
178                 _pFont = 0;
179         }
180
181         delete _pCoordHolder;
182         delete _pNativeCanvas;
183 }
184
185 result
186 _CanvasImpl::Construct(void)
187 {
188         SysTryReturnResult(NID_GRP, this, E_OUT_OF_MEMORY, "This instance is not allocated yet.");
189
190         SysTryReturnResult(NID_GRP, this->_pNativeCanvas, E_OUT_OF_MEMORY, "Fails to allocate memory.");
191
192         if (_ResUtil::NeedToConvertCoord())
193         {
194                 result r = this->_pNativeCanvas->Construct();
195
196                 if (IsSucceeded(r))
197                 {
198                         Rectangle pcRect = this->_pNativeCanvas->GetBounds();
199                         Rectangle vcRect = _ResUtil::ConvertToVirCoord(pcRect);
200                         this->_pCoordHolder->Init(vcRect);
201                 }
202
203                 return r;
204         }
205         else
206         {
207                 return this->_pNativeCanvas->Construct();
208         }
209 }
210
211 result
212 _CanvasImpl::Construct(const Rectangle& vcRect)
213 {
214         SysTryReturnResult(NID_GRP, this, E_OUT_OF_MEMORY, "This instance is not allocated yet.");
215
216         SysTryReturnResult(NID_GRP, this->_pNativeCanvas, E_OUT_OF_MEMORY, "Fails to allocate memory.");
217
218         SysTryReturnResult(NID_GRP, vcRect.width > 0 && vcRect.height > 0, E_OUT_OF_RANGE,
219                                           "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width,
220                                           vcRect.height);
221
222         if (_ResUtil::NeedToConvertCoord())
223         {
224                 Rectangle pcRect = _ResUtil::ConvertToPhyCoord(vcRect);
225
226                 pcRect.width = (pcRect.width > 0) ? pcRect.width : 1;
227                 pcRect.height = (pcRect.height > 0) ? pcRect.height : 1;
228
229                 result r = this->_pNativeCanvas->Construct(pcRect);
230
231                 if (IsSucceeded(r))
232                 {
233                         this->_pCoordHolder->Init(vcRect);
234                         this->_pCoordHolder->canvasSize.phyCoord.w = pcRect.width;
235                         this->_pCoordHolder->canvasSize.phyCoord.h = pcRect.height;
236                 }
237
238                 return r;
239         }
240         else
241         {
242                 return this->_pNativeCanvas->Construct(vcRect);
243         }
244 }
245
246 result
247 _CanvasImpl::Construct(Handle windowHandle, const Rectangle& vcRect)
248 {
249         SysTryReturnResult(NID_GRP, this, E_OUT_OF_MEMORY, "This instance is not allocated yet.");
250
251         SysTryReturnResult(NID_GRP, this->_pNativeCanvas, E_OUT_OF_MEMORY, "Fails to allocate memory.");
252
253         SysTryReturnResult(NID_GRP, vcRect.width > 0 && vcRect.height > 0, E_OUT_OF_RANGE,
254                                           "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width,
255                                           vcRect.height);
256
257         if (_ResUtil::NeedToConvertCoord())
258         {
259                 Rectangle pcRect = _ResUtil::ConvertToPhyCoord(vcRect);
260
261                 pcRect.width = (pcRect.width > 0) ? pcRect.width : 1;
262                 pcRect.height = (pcRect.height > 0) ? pcRect.height : 1;
263
264                 result r = this->_pNativeCanvas->Construct(windowHandle, pcRect);
265
266                 if (IsSucceeded(r))
267                 {
268                         this->_pCoordHolder->Init(vcRect);
269                         this->_pCoordHolder->canvasSize.phyCoord.w = pcRect.width;
270                         this->_pCoordHolder->canvasSize.phyCoord.h = pcRect.height;
271                 }
272
273                 return r;
274         }
275         else
276         {
277                 return this->_pNativeCanvas->Construct(windowHandle, vcRect);
278         }
279 }
280
281 result
282 _CanvasImpl::Construct(const BufferInfo& bufferInfo)
283 {
284         SysTryReturnResult(NID_GRP, this, E_OUT_OF_MEMORY, "This instance is not allocated yet.");
285
286         SysTryReturnResult(NID_GRP, this->_pNativeCanvas, E_OUT_OF_MEMORY, "Fails to allocate memory.");
287
288         SysTryReturnResult(NID_GRP, (bufferInfo.width > 0) && (bufferInfo.height > 0) && (bufferInfo.pitch > 0)
289                 , E_INVALID_ARG
290                 , "Invalid argument (BufferInfo::width = %d, BufferInfo::height = %d, BufferInfo::pitch = %d)"
291                 , bufferInfo.width, bufferInfo.height, bufferInfo.pitch);
292
293         SysTryReturnResult(NID_GRP, bufferInfo.bitsPerPixel > 0
294                 , E_INVALID_ARG
295                 , "Invalid argument (BufferInfo::bitsPerPixel = %d)"
296                 , bufferInfo.bitsPerPixel);
297
298         SysTryReturnResult(NID_GRP, (bufferInfo.pixelFormat > PIXEL_FORMAT_MIN) && (bufferInfo.pixelFormat < PIXEL_FORMAT_MAX)
299                 , E_INVALID_ARG
300                 , "Invalid argument (BufferInfo::pixelFormat = %d)"
301                 , bufferInfo.pixelFormat);
302
303         SysTryReturnResult(NID_GRP, bufferInfo.bitsPerPixel == 32
304                 , E_UNSUPPORTED_FORMAT
305                 , "Unsupported format (BufferInfo::bitsPerPixel = %d)"
306                 , bufferInfo.bitsPerPixel);
307
308         SysTryReturnResult(NID_GRP, bufferInfo.pixelFormat == PIXEL_FORMAT_ARGB8888
309                 , E_UNSUPPORTED_FORMAT
310                 , "Unsupported format (BufferInfo::pixelFormat = %d)"
311                 , bufferInfo.pixelFormat);
312
313         if (bufferInfo.pPixels == null)
314         {
315                 const _BufferInfoImpl* pBufferInfoImpl = _BufferInfoImpl::GetInstance(bufferInfo);
316
317                 if (pBufferInfoImpl)
318                 {
319                         Handle handle = pBufferInfoImpl->GetHandle(_BufferInfoImpl::HANDLE_TYPE_VE_SURFACE);
320
321                         if (handle != 0) // not INVALID_HANDLE
322                         {
323                                 result r = this->Construct(handle, Rectangle(0, 0, bufferInfo.width, bufferInfo.height));
324
325                                 // OUT_OF_RANGE does not occur
326
327                                 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
328
329                                 return E_SUCCESS;
330                         }
331                 }
332
333                 SysTryReturnResult(NID_GRP, false
334                         , E_INVALID_ARG
335                         , "Invalid argument (BufferInfo::pPixels = null)");
336         }
337         else
338         {
339                 result r = this->_pNativeCanvas->Construct(bufferInfo);
340
341                 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
342
343                 if (_ResUtil::NeedToConvertCoord())
344                 {
345                         Rectangle pcRect(0, 0, bufferInfo.width, bufferInfo.height);
346                         Rectangle vcRect = _ResUtil::ConvertToVirCoord(pcRect);
347
348                         vcRect.width = (vcRect.width > 0) ? vcRect.width : 1;
349                         vcRect.height = (vcRect.height > 0) ? vcRect.height : 1;
350
351                         this->_pCoordHolder->Init(vcRect);
352                         this->_pCoordHolder->canvasSize.phyCoord.w = pcRect.width;
353                         this->_pCoordHolder->canvasSize.phyCoord.h = pcRect.height;
354                 }
355
356                 return E_SUCCESS;
357         }
358
359         return E_SYSTEM;
360 }
361
362 bool
363 _CanvasImpl::IsConstructed(void) const
364 {
365         return (this->_pNativeCanvas != null) && this->_pNativeCanvas->IsValid();
366 }
367
368 result
369 _CanvasImpl::Clear(void)
370 {
371         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
372
373         return this->_pNativeCanvas->Clear();
374 }
375
376 result
377 _CanvasImpl::Clear(const Rectangle& vcRect)
378 {
379         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
380
381         SysTryReturnResult(NID_GRP, &vcRect, E_OUT_OF_RANGE, "The given rectangle is invalid.");
382         SysTryReturnResult(NID_GRP, (vcRect.width >= 0) && (vcRect.height >= 0), E_OUT_OF_RANGE,
383                                           "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width,
384                                           vcRect.height);
385
386         if ((vcRect.width == 0) || (vcRect.height == 0))
387         {
388                 return E_SUCCESS;
389         }
390
391         Rectangle rtCanvas = _GetBoundsRel(*this);
392
393         if (rtCanvas.IsEmpty())
394         {
395                 return E_SUCCESS;
396         }
397
398         result r = _Util::Validate(vcRect, rtCanvas);
399
400         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
401
402         if (_ResUtil::NeedToConvertCoord())
403         {
404                 Rectangle pcRect = _ResUtil::ConvertToPhyCoord(vcRect);
405
406                 return this->_pNativeCanvas->Clear(pcRect);
407         }
408         else
409         {
410                 return this->_pNativeCanvas->Clear(vcRect);
411         }
412 }
413
414 result
415 _CanvasImpl::Copy(const Point& vcDestPoint, const _CanvasImpl& canvas, const Rectangle& vcSrcRect)
416 {
417         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
418
419         SysTryReturnResult(NID_GRP, CANVAS_IS_VALID(canvas), E_INVALID_ARG, "The specified source canvas is invalid.");
420
421         Rectangle srcRectCanvas = _GetBoundsRel(canvas);
422
423         if (srcRectCanvas.IsEmpty())
424         {
425                 return E_SUCCESS;
426         }
427
428         result r = _Util::Validate(vcSrcRect, srcRectCanvas);
429
430         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
431
432         // check if destRect is in this canvas.
433         Rectangle destRect(vcDestPoint.x, vcDestPoint.y, vcSrcRect.width, vcSrcRect.height);
434         Rectangle destRectCanvas = _GetBoundsRel(*this);
435
436         if (destRectCanvas.IsEmpty())
437         {
438                 return E_SUCCESS;
439         }
440
441         r = _Util::Validate(destRect, destRectCanvas);
442
443         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
444
445         EXTRACT_CANVASEX(_pNativeCanvas, canvas);
446
447
448         if (_ResUtil::NeedToConvertCoord())
449         {
450                 Point pcDestPoint = _ResUtil::ConvertToPhyCoord(vcDestPoint);
451                 Rectangle pcSrcRect = _ResUtil::ConvertToPhyCoord(vcSrcRect);
452
453                 return this->_pNativeCanvas->Copy(pcDestPoint, *_pNativeCanvas, pcSrcRect);
454         }
455         else
456         {
457                 return this->_pNativeCanvas->Copy(vcDestPoint, *_pNativeCanvas, vcSrcRect);
458         }
459 }
460
461 result
462 _CanvasImpl::Copy(const Rectangle& vcDestRect, const _CanvasImpl& canvas, const Rectangle& vcSrcRect)
463 {
464         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
465
466         SysTryReturnResult(NID_GRP, CANVAS_IS_VALID(canvas), E_INVALID_ARG, "The specified source canvas is invalid.");
467
468         // check if srcRect is in source canvas.
469         Rectangle srcRectCanvas = _GetBoundsRel(canvas);
470
471         if (srcRectCanvas.IsEmpty())
472         {
473                 return E_SUCCESS;
474         }
475
476         result r = _Util::Validate(vcSrcRect, srcRectCanvas);
477
478         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
479
480         // check if destRect is in this canvas.
481         Rectangle destRectCanvas = _GetBoundsRel(*this);
482
483         if (destRectCanvas.IsEmpty())
484         {
485                 return E_SUCCESS;
486         }
487
488         r = _Util::Validate(vcDestRect, destRectCanvas);
489
490         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
491
492         EXTRACT_CANVASEX(_pNativeCanvas, canvas);
493
494         if (_ResUtil::NeedToConvertCoord())
495         {
496                 Rectangle pcDestRect = _ResUtil::ConvertToPhyCoord(vcDestRect);
497                 Rectangle pcSrcRect = _ResUtil::ConvertToPhyCoord(vcSrcRect);
498
499                 return this->_pNativeCanvas->Copy(pcDestRect, *_pNativeCanvas, pcSrcRect);
500         }
501         else
502         {
503                 return this->_pNativeCanvas->Copy(vcDestRect, *_pNativeCanvas, vcSrcRect);
504         }
505 }
506
507 result
508 _CanvasImpl::Copy(const Point& vcDestPoint, const _CanvasImpl& canvas, const Rectangle& vcSrcRect, BlendingMode blendingMode)
509 {
510         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
511
512         SysTryReturnResult(NID_GRP, CANVAS_IS_VALID(canvas), E_INVALID_ARG, "The specified source canvas is invalid.");
513
514         switch (blendingMode)
515         {
516         case BLENDING_MODE_CLEAR:
517         case BLENDING_MODE_SRC:
518         case BLENDING_MODE_DST:
519         case BLENDING_MODE_SRC_OVER:
520         case BLENDING_MODE_DST_OVER:
521         case BLENDING_MODE_SRC_IN:
522         case BLENDING_MODE_DST_IN:
523         case BLENDING_MODE_SRC_OUT:
524         case BLENDING_MODE_DST_OUT:
525         case BLENDING_MODE_SRC_ATOP:
526         case BLENDING_MODE_DST_ATOP:
527         case BLENDING_MODE_DST_XOR:
528         case BLENDING_MODE_ADD:
529         case BLENDING_MODE_SATURATE:
530         case BLENDING_MODE_MULTIPLY:
531         case BLENDING_MODE_SCREEN:
532         case BLENDING_MODE_OVERLAY:
533         case BLENDING_MODE_DARKEN:
534         case BLENDING_MODE_LIGHTEN:
535         case BLENDING_MODE_COLOR_DODGE:
536         case BLENDING_MODE_COLOR_BURN:
537         case BLENDING_MODE_HARD_LIGHT:
538         case BLENDING_MODE_SOFT_LIGHT:
539         case BLENDING_MODE_DIFFERENCE:
540         case BLENDING_MODE_EXCLUSION:
541                 break;
542         default:
543                 SysTryReturnResult(NID_GRP, false, E_INVALID_ARG, "The specified blending mode is invalid.");
544         }
545
546         Rectangle srcRectCanvas = _GetBoundsRel(canvas);
547
548         if (srcRectCanvas.IsEmpty())
549         {
550                 return E_SUCCESS;
551         }
552
553         result r = _Util::Validate(vcSrcRect, srcRectCanvas);
554
555         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
556
557         // check if destRect is in this canvas.
558         Rectangle destRect(vcDestPoint.x, vcDestPoint.y, vcSrcRect.width, vcSrcRect.height);
559         Rectangle destRectCanvas = _GetBoundsRel(*this);
560
561         if (destRectCanvas.IsEmpty())
562         {
563                 return E_SUCCESS;
564         }
565
566         r = _Util::Validate(destRect, destRectCanvas);
567
568         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
569
570         EXTRACT_CANVASEX(_pNativeCanvas, canvas);
571
572
573         if (_ResUtil::NeedToConvertCoord())
574         {
575                 Point pcDestPoint = _ResUtil::ConvertToPhyCoord(vcDestPoint);
576                 Rectangle pcSrcRect = _ResUtil::ConvertToPhyCoord(vcSrcRect);
577
578                 return this->_pNativeCanvas->Copy(pcDestPoint, *_pNativeCanvas, pcSrcRect, blendingMode);
579         }
580         else
581         {
582                 return this->_pNativeCanvas->Copy(vcDestPoint, *_pNativeCanvas, vcSrcRect, blendingMode);
583         }
584 }
585
586 result
587 _CanvasImpl::CopyEx(const Point& vcDestPoint, const _CanvasImpl& srcCanvas, const Rectangle& vcSrcRect)
588 {
589         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
590
591         if (this != &srcCanvas)
592         {
593                 return this->Copy(vcDestPoint, srcCanvas, vcSrcRect);
594         }
595
596         // validity check as _CanvasImpl::Copy()
597         SysTryReturnResult(NID_GRP, CANVAS_IS_VALID(srcCanvas), E_INVALID_ARG, "The specified source canvas is invalid.");
598
599         Rectangle srcRectCanvas = _GetBoundsRel(srcCanvas);
600
601         if (srcRectCanvas.IsEmpty())
602         {
603                 return E_SUCCESS;
604         }
605
606         result r = _Util::Validate(vcSrcRect, srcRectCanvas);
607
608         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
609
610         // check if destRect is in this canvas.
611         Rectangle destRect(vcDestPoint.x, vcDestPoint.y, vcSrcRect.width, vcSrcRect.height);
612         Rectangle destRectCanvas = _GetBoundsRel(*this);
613
614         if (destRectCanvas.IsEmpty())
615         {
616                 return E_SUCCESS;
617         }
618
619         r = _Util::Validate(destRect, destRectCanvas);
620
621         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
622
623         int pixelPerLine = 0;
624
625         {
626                 BufferInfo bufferInfo;
627
628                 result r = this->_pNativeCanvas->Lock(bufferInfo);
629
630                 //?? log
631                 SysTryReturn(NID_GRP, r == E_SUCCESS, r, E_SYSTEM, "[] ");
632
633                 this->_pNativeCanvas->Unlock();
634
635                 pixelPerLine = bufferInfo.pitch / (bufferInfo.bitsPerPixel / 8);
636         }
637
638         //?? Auto-scaling should be applied to vc**** parameters later
639         int sourDistance = vcSrcRect.y * pixelPerLine + vcSrcRect.x;
640         int destDistance = vcDestPoint.y * pixelPerLine + vcDestPoint.x;
641
642         typedef result (_Canvas::* FnCopy)(const Point&, const _Canvas&, const Rectangle&);
643         FnCopy fnCopy = (destDistance < sourDistance) ? FnCopy(&_Canvas::Copy) : FnCopy(&_Canvas::CopyReverse);
644
645         if (fnCopy)
646         {
647                 EXTRACT_CANVASEX(_pNativeCanvas, srcCanvas);
648
649                 if (_ResUtil::NeedToConvertCoord())
650                 {
651                         Point pcDestPoint = _ResUtil::ConvertToPhyCoord(vcDestPoint);
652                         Rectangle pcSrcRect = _ResUtil::ConvertToPhyCoord(vcSrcRect);
653
654                         return (this->_pNativeCanvas->*fnCopy)(pcDestPoint, *_pNativeCanvas, pcSrcRect);
655                 }
656                 else
657                 {
658                         return (this->_pNativeCanvas->*fnCopy)(vcDestPoint, *_pNativeCanvas, vcSrcRect);
659                 }
660         }
661
662         // never!!
663         return E_SYSTEM;
664 }
665
666 result
667 _CanvasImpl::DrawArc(const FloatRectangle& vcBounds, float startAngle, float endAngle, ArcStyle arcStyle)
668 {
669         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
670         SysTryReturnResult(NID_GRP, ARC_STYLE_MIN < arcStyle && arcStyle < ARC_STYLE_MAX, E_INVALID_ARG, "The invalid arc type(%d) is given.", arcStyle);
671         SysTryReturnResult(NID_GRP, &vcBounds, E_INVALID_ARG, "The given rectangle is invalid.");
672         SysTryReturnResult(NID_GRP, (vcBounds.width >= 0) && (vcBounds.height >= 0), E_OUT_OF_RANGE,
673                                           "The given rectangle(width:%d,height:%d) is out of range.", vcBounds.width, vcBounds.height);
674
675         return _CanvasImplPrivate::DrawArc(this, _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcBounds), double(startAngle), double(endAngle), arcStyle);
676 }
677
678 result
679 _CanvasImpl::DrawArc(const Rectangle& vcBounds, int startAngle, int endAngle, ArcStyle arcStyle)
680 {
681         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
682         SysTryReturnResult(NID_GRP, ARC_STYLE_MIN < arcStyle && arcStyle < ARC_STYLE_MAX, E_INVALID_ARG, "The invalid arc type(%d) is given.", arcStyle);
683         SysTryReturnResult(NID_GRP, &vcBounds, E_INVALID_ARG, "The given rectangle is invalid.");
684         SysTryReturnResult(NID_GRP, (vcBounds.width >= 0) && (vcBounds.height >= 0), E_OUT_OF_RANGE,
685                                           "The given rectangle(width:%d,height:%d) is out of range.", vcBounds.width, vcBounds.height);
686
687         return _CanvasImplPrivate::DrawArc(this, _Util::Convert<Rectangle, _Util::Rectangle<double> >(vcBounds), double(startAngle), double(endAngle), arcStyle);
688 }
689
690 result
691 _CanvasImpl::DrawBitmap(const Rectangle& vcRect, const _BitmapImpl& bitmap)
692 {
693         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
694
695         SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(bitmap), E_INVALID_ARG, "The source bitmap is invalid.");
696         SysTryReturnResult(NID_GRP, &vcRect, E_INVALID_ARG, "The source rectangle is invalid.");
697
698         if (vcRect.width == bitmap.GetWidth() && vcRect.height == bitmap.GetHeight())
699         {
700                 return this->DrawBitmap(Point(vcRect.x, vcRect.y), bitmap);
701         }
702
703         // check if bimap can be drew in canvas area.
704         Rectangle rtCanvas = _GetBoundsRel(*this);
705
706         if (rtCanvas.IsEmpty())
707         {
708                 return E_SUCCESS;
709         }
710
711         result r = _Util::Validate(vcRect, rtCanvas);
712
713         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
714
715         EXTRACT_BITMAPEX(pBitmapEx, bitmap);
716
717         if (_ResUtil::NeedToConvertCoord())
718         {
719                 Rectangle pcRect = _ResUtil::ConvertToPhyCoord(vcRect);
720
721                 return this->_pNativeCanvas->DrawBitmap(pcRect, *pBitmapEx);
722         }
723         else
724         {
725                 return this->_pNativeCanvas->DrawBitmap(vcRect, *pBitmapEx);
726         }
727 }
728
729 result
730 _CanvasImpl::DrawBitmap(const FloatRectangle& vcRect, const _BitmapImpl& bitmap)
731 {
732         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
733
734         return this->DrawBitmap(_Util::Convert<FloatRectangle, Rectangle>(vcRect), bitmap);
735 }
736
737 result
738 _CanvasImpl::DrawBitmap(const Point& vcPoint, const _BitmapImpl& bitmap)
739 {
740         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
741
742         SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(bitmap), E_INVALID_ARG, "The source bitmap is invalid.");
743
744         Rectangle rtCanvas = _GetBoundsRel(*this);
745
746         if (rtCanvas.IsEmpty())
747         {
748                 return E_SUCCESS;
749         }
750
751         result r = _Util::Validate(Rectangle(vcPoint.x, vcPoint.y, bitmap.GetWidth(), bitmap.GetHeight()), rtCanvas);
752
753         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
754
755         EXTRACT_BITMAPEX(pBitmapEx, bitmap);
756
757         if (_ResUtil::NeedToConvertCoord())
758         {
759                 Tizen::Graphics::Dimension virSize;
760                 Tizen::Graphics::Dimension phySize;
761                 bool lazyScaling = Tizen::Graphics::IsLazyScalingBitmap(bitmap, virSize, phySize);
762
763                 Point pcPoint = _ResUtil::ConvertToPhyCoord(vcPoint);
764
765                 Rectangle vcRect(vcPoint.x, vcPoint.y, bitmap.GetWidth(), bitmap.GetHeight());
766
767 #if 1 // Bitmap scaling is always uniform
768                 if (lazyScaling)
769                 {
770                         EXTRACT_SCALED_BITMAPEX(pScaledBitmapEx, bitmap);
771
772                         return this->_pNativeCanvas->DrawBitmap(pcPoint, *pScaledBitmapEx);
773                 }
774                 else
775                 {
776                         return this->_pNativeCanvas->DrawBitmap(pcPoint, *pBitmapEx);
777                 }
778 #else
779                 int testSize = 2 * 3 * 5 * 7;
780                 bool isUniform = _ResUtil::ConvertToPhyCoordWidth(testSize) == ConvertToPhyCoordHeight(testSize);
781
782                 Rectangle pcRect = _ResUtil::ConvertToPhyCoord(vcRect);
783
784                 isUniform = true;
785
786                 if (lazyScaling)
787                 {
788                         EXTRACT_SCALED_BITMAPEX(pScaledBitmapEx, bitmap);
789
790                         if (isUniform)
791                         {
792                                 return this->_pNativeCanvas->DrawBitmap(pcPoint, *pScaledBitmapEx);
793                         }
794                         else
795                         {
796                                 return this->_pNativeCanvas->DrawBitmap(pcRect, *pScaledBitmapEx);
797                         }
798                 }
799                 else
800                 {
801                         if (isUniform)
802                         {
803                                 return this->_pNativeCanvas->DrawBitmap(pcPoint, *pBitmapEx);
804                         }
805                         else
806                         {
807                                 return this->_pNativeCanvas->DrawBitmap(pcRect, *pBitmapEx);
808                         }
809                 }
810 #endif
811         }
812         else
813         {
814                 return this->_pNativeCanvas->DrawBitmap(vcPoint, *pBitmapEx);
815         }
816 }
817
818 result
819 _CanvasImpl::DrawBitmap(const FloatPoint& vcPoint, const _BitmapImpl& bitmap)
820 {
821         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
822
823         return this->DrawBitmap(_Util::Convert<FloatPoint, Point>(vcPoint), bitmap);
824 }
825
826 result
827 _CanvasImpl::DrawBitmap(const Rectangle& vcDestRect, const _BitmapImpl& srcBitmap, const Rectangle& vcSrcRect)
828 {
829         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
830
831         SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(srcBitmap), E_INVALID_ARG, "The source bitmap is invalid.");
832
833         SysTryReturnResult(NID_GRP, (&vcSrcRect) && (&vcDestRect), E_INVALID_ARG, "The given rectangle is invalid.");
834
835         SysTryReturnResult(NID_GRP, (vcSrcRect.width >= 0) && (vcSrcRect.height >= 0), E_OUT_OF_RANGE, "The given source rectangle(width:%d,height:%d) is out of range.", vcSrcRect.width,  vcSrcRect.height);
836         SysTryReturnResult(NID_GRP, (vcDestRect.width >= 0) && (vcDestRect.height >= 0), E_OUT_OF_RANGE, "The given destination rectangle(width:%d,height:%d) is out of range.", vcDestRect.width, vcDestRect.height);
837
838         if (vcSrcRect.width == 0 || vcSrcRect.height == 0)
839         {
840                 return E_SUCCESS;
841         }
842
843         if (vcDestRect.width == 0 || vcDestRect.height == 0)
844         {
845                 return E_SUCCESS;
846         }
847
848         if ((vcSrcRect.x < 0) || (vcSrcRect.y < 0) || (vcSrcRect.x + vcSrcRect.width > srcBitmap.GetWidth()) || (vcSrcRect.y + vcSrcRect.height > srcBitmap.GetHeight()))
849         {
850                 SysTryReturnResult(NID_GRP, 0, E_OUT_OF_RANGE, "The specified region of source bitmap is out of range.");
851         }
852
853         // check if srcRect is in bitmap's area.
854         result r = _Util::Validate(vcSrcRect, Rectangle(0, 0, srcBitmap.GetWidth(), srcBitmap.GetHeight()));
855
856         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
857
858         // check if destRect is in this canvas.
859         Rectangle rtCanvas = _GetBoundsRel(*this);
860
861         if (rtCanvas.IsEmpty())
862         {
863                 return E_SUCCESS;
864         }
865
866         r = _Util::Validate(vcDestRect, rtCanvas);
867
868         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
869
870         EXTRACT_BITMAPEX(pBitmapEx, srcBitmap);
871
872         if (_ResUtil::NeedToConvertCoord())
873         {
874                 Tizen::Graphics::Dimension virSize;
875                 Tizen::Graphics::Dimension phySize;
876                 bool lazyScaling = Tizen::Graphics::IsLazyScalingBitmap(srcBitmap, virSize, phySize);
877
878                 Rectangle pcDestRect = _ResUtil::ConvertToPhyCoord(vcDestRect);
879
880                 if (lazyScaling)
881                 {
882                         return this->_pNativeCanvas->DrawBitmap(pcDestRect, *pBitmapEx, vcSrcRect);
883                 }
884                 else
885                 {
886                         Rectangle pcSrcRect = _ResUtil::ConvertToPhyCoord(vcSrcRect);
887
888                         return this->_pNativeCanvas->DrawBitmap(pcDestRect, *pBitmapEx, pcSrcRect);
889                 }
890         }
891         else
892         {
893                 return this->_pNativeCanvas->DrawBitmap(vcDestRect, *pBitmapEx, vcSrcRect);
894         }
895 }
896
897 result
898 _CanvasImpl::DrawBitmap(const FloatRectangle& vcDestRect, const _BitmapImpl& srcBitmap, const FloatRectangle& vcSrcRect)
899 {
900         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
901
902         return this->DrawBitmap(_Util::Convert<FloatRectangle, Rectangle>(vcDestRect), srcBitmap, _Util::Convert<FloatRectangle, Rectangle>(vcSrcRect));
903 }
904
905 result
906 _CanvasImpl::DrawBitmap(const Point& vcPoint, const _BitmapImpl& bitmap, FlipDirection dir)
907 {
908         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
909
910         SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(bitmap), E_INVALID_ARG, "The source bitmap is invalid.");
911
912         switch (dir)
913         {
914         case FLIP_DIRECTION_HORIZONTAL:
915         case FLIP_DIRECTION_VERTICAL:
916                 break;
917         default:
918                 SysTryReturnResult(NID_GRP, 0, E_INVALID_ARG, "FlipStyle(%d) is invalid.", dir);
919                 break;
920         }
921
922         EXTRACT_BITMAPEX(pBitmapEx, bitmap);
923
924         if (_ResUtil::NeedToConvertCoord())
925         {
926                 Tizen::Graphics::Dimension virSize;
927                 Tizen::Graphics::Dimension phySize;
928                 bool lazyScaling = Tizen::Graphics::IsLazyScalingBitmap(bitmap, virSize, phySize);
929
930                 Point pcPoint = _ResUtil::ConvertToPhyCoord(vcPoint);
931
932                 if (lazyScaling)
933                 {
934                         EXTRACT_SCALED_BITMAPEX(pScaledBitmapEx, bitmap);
935
936                         return this->_pNativeCanvas->DrawBitmap(pcPoint, *pScaledBitmapEx, dir);
937                 }
938                 else
939                 {
940                         return this->_pNativeCanvas->DrawBitmap(pcPoint, *pBitmapEx, dir);
941                 }
942         }
943         else
944         {
945                 return this->_pNativeCanvas->DrawBitmap(vcPoint, *pBitmapEx, dir);
946         }
947 }
948
949 result
950 _CanvasImpl::DrawBitmap(const FloatPoint& vcPoint, const _BitmapImpl& bitmap, FlipDirection dir)
951 {
952         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
953
954         return this->DrawBitmap(_Util::Convert<FloatPoint, Point>(vcPoint), bitmap, dir);
955 }
956
957 result
958 _CanvasImpl::DrawBitmap(const Point& vcPoint, const _BitmapImpl& bitmap, const Point& vcPivot, int degree)
959 {
960         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
961
962         SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(bitmap), E_INVALID_ARG, "The source bitmap is invalid.");
963
964         EXTRACT_BITMAPEX(pBitmapEx, bitmap);
965
966         if (_ResUtil::NeedToConvertCoord())
967         {
968                 Tizen::Graphics::Dimension virSize;
969                 Tizen::Graphics::Dimension phySize;
970                 bool lazyScaling = Tizen::Graphics::IsLazyScalingBitmap(bitmap, virSize, phySize);
971
972                 Point pcPoint = _ResUtil::ConvertToPhyCoord(vcPoint);
973                 Point pcPivot = _ResUtil::ConvertToPhyCoord(vcPivot);
974
975                 if (lazyScaling)
976                 {
977                         EXTRACT_SCALED_BITMAPEX(pScaledBitmapEx, bitmap);
978
979                         return this->_pNativeCanvas->DrawBitmap(pcPoint, *pScaledBitmapEx, pcPivot, degree);
980                 }
981                 else
982                 {
983                         return this->_pNativeCanvas->DrawBitmap(pcPoint, *pBitmapEx, pcPivot, degree);
984                 }
985         }
986         else
987         {
988                 return this->_pNativeCanvas->DrawBitmap(vcPoint, *pBitmapEx, vcPivot, degree);
989         }
990 }
991
992 result
993 _CanvasImpl::DrawBitmap(const FloatPoint& vcPoint, const _BitmapImpl& bitmap, const FloatPoint& vcPivot, float degree)
994 {
995         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
996
997         return this->DrawBitmap(_Util::Convert<FloatPoint, Point>(vcPoint), bitmap, _Util::Convert<FloatPoint, Point>(vcPivot), int(degree));
998 }
999
1000 result
1001 _CanvasImpl::DrawNinePatchedBitmap(const Rectangle& vcRect, const _BitmapImpl& bitmap)
1002 {
1003         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1004
1005         SysTryReturnResult(NID_GRP, BITMAP_IS_VALID(bitmap), E_INVALID_ARG, "The source bitmap is invalid.");
1006
1007         SysTryReturnResult(NID_GRP, bitmap.IsNinePatchedBitmap(), E_INVALID_ARG, "The source bitmap is not a nine patched bitmap.");
1008
1009         // check if bimap can be drew in canvas area.
1010         Rectangle rtCanvas = _GetBoundsRel(*this);
1011
1012         if (rtCanvas.IsEmpty())
1013         {
1014                 SysTryReturnResult(NID_GRP, 0, E_OPERATION_FAILED, "Cannot get the bounds of the canvas.");
1015         }
1016
1017         result r = _Util::Validate(vcRect, rtCanvas);
1018
1019         if (IsFailed(r))
1020         {
1021                 return E_SUCCESS;
1022         }
1023
1024         EXTRACT_BITMAPEX(pBitmapEx, bitmap);
1025
1026         if (_ResUtil::NeedToConvertCoord())
1027         {
1028                 Tizen::Graphics::Dimension virSize;
1029                 Tizen::Graphics::Dimension phySize;
1030                 bool lazyScaling = Tizen::Graphics::IsLazyScalingBitmap(bitmap, virSize, phySize);
1031
1032                 Rectangle pcRect = _ResUtil::ConvertToPhyCoord(vcRect);
1033
1034                 if (lazyScaling)
1035                 {
1036                         EXTRACT_SCALED_BITMAPEX(pScaledBitmapEx, bitmap);
1037
1038                         return this->_pNativeCanvas->DrawNinePatchedBitmap(pcRect, *pScaledBitmapEx);
1039                 }
1040                 else
1041                 {
1042                         return this->_pNativeCanvas->DrawNinePatchedBitmap(pcRect, *pBitmapEx);
1043                 }
1044         }
1045         else
1046         {
1047                 return this->_pNativeCanvas->DrawNinePatchedBitmap(vcRect, *pBitmapEx);
1048         }
1049 }
1050
1051 result
1052 _CanvasImpl::DrawNinePatchedBitmap(const FloatRectangle& vcRect, const _BitmapImpl& bitmap)
1053 {
1054         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1055
1056         return this->DrawNinePatchedBitmap(_Util::Convert<FloatRectangle, Rectangle>(vcRect), bitmap);
1057 }
1058
1059 result
1060 _CanvasImpl::DrawEllipse(const Rectangle& vcBounds)
1061 {
1062         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1063         SysTryReturnResult(NID_GRP, &vcBounds, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1064         SysTryReturnResult(NID_GRP, (vcBounds.width >= 0) && (vcBounds.height >= 0), E_OUT_OF_RANGE,
1065                                           "The given rectangle(width:%d,height:%d) is out of range.", vcBounds.width, vcBounds.height);
1066
1067         return _CanvasImplPrivate::DrawEllipse(this, _Util::Convert<Rectangle, _Util::Rectangle<double> >(vcBounds));
1068 }
1069
1070 result
1071 _CanvasImpl::DrawEllipse(const FloatRectangle& vcBounds)
1072 {
1073         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1074         SysTryReturnResult(NID_GRP, &vcBounds, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1075         SysTryReturnResult(NID_GRP, (vcBounds.width >= 0) && (vcBounds.height >= 0), E_OUT_OF_RANGE,
1076                                           "The given rectangle(width:%d,height:%d) is out of range.", vcBounds.width, vcBounds.height);
1077
1078         return _CanvasImplPrivate::DrawEllipse(this, _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcBounds));
1079 }
1080
1081 result
1082 _CanvasImpl::DrawLine(const Point& vcPoint1, const Point& vcPoint2)
1083 {
1084         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1085
1086         return _CanvasImplPrivate::DrawLine(this,
1087                 _Util::Convert<Point, _Util::Point<double> >(vcPoint1),
1088                 _Util::Convert<Point, _Util::Point<double> >(vcPoint2));
1089 }
1090
1091 result
1092 _CanvasImpl::DrawLine(const FloatPoint& vcPoint1, const FloatPoint& vcPoint2)
1093 {
1094         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1095
1096         return _CanvasImplPrivate::DrawLine(this,
1097                 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint1),
1098                 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint2));
1099 }
1100
1101 result
1102 _CanvasImpl::DrawPolygon(const Tizen::Base::Collection::IList& vcPoints)
1103 {
1104         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1105
1106         int numPoint = vcPoints.GetCount();
1107
1108         SysTryReturnResult(NID_GRP, numPoint >= 0, E_INVALID_ARG, "The number of points (%d) is not valid.", numPoint);
1109
1110         if (numPoint < 2) // TBD.
1111         {
1112                 return E_SUCCESS;
1113         }
1114
1115         std::unique_ptr<_Util::Point<double>[]> doublePoint;
1116
1117         {
1118                 _Util::Point<double>* pDoublePoint = _Util::Convert<Tizen::Base::Collection::IList, _Util::Point<double>*>(vcPoints);
1119
1120                 SysTryReturnResult(NID_GRP, pDoublePoint != null, E_INVALID_ARG, "The type of points is not valid.");
1121
1122                 doublePoint.reset(pDoublePoint);
1123         }
1124
1125         if (_ResUtil::NeedToConvertCoord())
1126         {
1127                 for (int i = 0; i < numPoint; i++)
1128                 {
1129                         doublePoint[i] = _ResUtil::ConvertToPhyCoord(doublePoint[i]);
1130                 }
1131
1132                 return this->_pNativeCanvas->DrawPolygon(doublePoint.get(), numPoint);
1133         }
1134         else
1135         {
1136                 return this->_pNativeCanvas->DrawPolygon(doublePoint.get(), numPoint);
1137         }
1138 }
1139
1140 result
1141 _CanvasImpl::DrawPolyline(const Tizen::Base::Collection::IList& vcPoints)
1142 {
1143         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1144
1145         int numPoint = vcPoints.GetCount();
1146
1147         SysTryReturnResult(NID_GRP, numPoint >= 0, E_INVALID_ARG, "The number of points (%d) is not valid.", numPoint);
1148
1149         if (numPoint < 2)
1150         {
1151                 return E_SUCCESS;
1152         }
1153
1154         std::unique_ptr<_Util::Point<double>[]> doublePoint;
1155
1156         {
1157                 _Util::Point<double>* pDoublePoint = _Util::Convert<Tizen::Base::Collection::IList, _Util::Point<double>*>(vcPoints);
1158
1159                 SysTryReturnResult(NID_GRP, pDoublePoint != null, E_INVALID_ARG, "The type of points is not valid.");
1160
1161                 doublePoint.reset(pDoublePoint);
1162         }
1163
1164         if (_ResUtil::NeedToConvertCoord())
1165         {
1166                 for (int i = 0; i < numPoint; i++)
1167                 {
1168                         doublePoint[i] = _ResUtil::ConvertToPhyCoord(doublePoint[i]);
1169                 }
1170
1171                 return this->_pNativeCanvas->DrawPolyline(doublePoint.get(), numPoint);
1172         }
1173         else
1174         {
1175                 return this->_pNativeCanvas->DrawPolyline(doublePoint.get(), numPoint);
1176         }
1177 }
1178
1179 result
1180 _CanvasImpl::DrawRectangle(const Rectangle& vcRect)
1181 {
1182         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1183         SysTryReturnResult(NID_GRP, &vcRect, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1184         SysTryReturnResult(NID_GRP, (vcRect.width >= 0) && (vcRect.height >= 0), E_OUT_OF_RANGE, "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width, vcRect.height);
1185
1186         return _CanvasImplPrivate::DrawRectangle(this, _Util::Convert<Rectangle, _Util::Rectangle<double> >(vcRect));
1187 }
1188
1189 result
1190 _CanvasImpl::DrawRectangle(const FloatRectangle& vcRect)
1191 {
1192         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1193         SysTryReturnResult(NID_GRP, &vcRect, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1194         SysTryReturnResult(NID_GRP, (vcRect.width >= 0.0f) && (vcRect.height >= 0.0f), E_OUT_OF_RANGE, "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width, vcRect.height);
1195
1196         return _CanvasImplPrivate::DrawRectangle(this, _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcRect));
1197 }
1198
1199 result
1200 _CanvasImpl::DrawRoundRectangle(const Rectangle& vcRect, const Dimension& vcArcDim)
1201 {
1202         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1203         SysTryReturnResult(NID_GRP, (&vcRect) && (&vcArcDim), E_OUT_OF_RANGE, "The given rectangle is invalid.");
1204         SysTryReturnResult(NID_GRP, (vcRect.width >= 0) && (vcRect.height >= 0), E_OUT_OF_RANGE, "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width, vcRect.height);
1205         SysTryReturnResult(NID_GRP, (vcArcDim.width >= 0) && (vcArcDim.height >= 0), E_OUT_OF_RANGE, "The given arc size(width:%d,height:%d) is out of range.", vcArcDim.width, vcArcDim.height);
1206
1207         return _CanvasImplPrivate::DrawRoundRectangle(this, _Util::Convert<Rectangle, _Util::Rectangle<double> >(vcRect), _Util::Convert<Dimension, _Util::Dimension<double> >(vcArcDim));
1208 }
1209
1210 result
1211 _CanvasImpl::DrawRoundRectangle(const FloatRectangle& vcRect, const FloatDimension& vcArcDim)
1212 {
1213         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1214         SysTryReturnResult(NID_GRP, (&vcRect) && (&vcArcDim), E_OUT_OF_RANGE, "The given rectangle is invalid.");
1215         SysTryReturnResult(NID_GRP, (vcRect.width >= 0.0f) && (vcRect.height >= 0.0f), E_OUT_OF_RANGE, "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width, vcRect.height);
1216         SysTryReturnResult(NID_GRP, (vcArcDim.width >= 0.0f) && (vcArcDim.height >= 0.0f), E_OUT_OF_RANGE, "The given arc size(width:%d,height:%d) is out of range.", vcArcDim.width, vcArcDim.height);
1217
1218         return _CanvasImplPrivate::DrawRoundRectangle(this, _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcRect), _Util::Convert<FloatDimension, _Util::Dimension<double> >(vcArcDim));
1219 }
1220
1221 result
1222 _CanvasImpl::DrawTriangle(const Point& vcPoint1, const Point& vcPoint2, const Point& vcPoint3)
1223 {
1224         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1225
1226         return _CanvasImplPrivate::DrawTriangle(this,
1227                 _Util::Convert<Point, _Util::Point<double> >(vcPoint1),
1228                 _Util::Convert<Point, _Util::Point<double> >(vcPoint2),
1229                 _Util::Convert<Point, _Util::Point<double> >(vcPoint3));
1230 }
1231
1232 result
1233 _CanvasImpl::DrawTriangle(const FloatPoint& vcPoint1, const FloatPoint& vcPoint2, const FloatPoint& vcPoint3)
1234 {
1235         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1236
1237         return _CanvasImplPrivate::DrawTriangle(this,
1238                 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint1),
1239                 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint2),
1240                 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint3));
1241 }
1242
1243 result
1244 _CanvasImpl::FillEllipse(const Color& color, const Rectangle& vcBounds)
1245 {
1246         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1247         SysTryReturnResult(NID_GRP, &vcBounds, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1248         SysTryReturnResult(NID_GRP, (vcBounds.width >= 0) && (vcBounds.height >= 0), E_OUT_OF_RANGE,
1249                                           "The given rectangle(width:%d,height:%d) is out of range.", vcBounds.width, vcBounds.height);
1250
1251         return _CanvasImplPrivate::FillEllipse(this, color, _Util::Convert<Rectangle, _Util::Rectangle<double> >(vcBounds));
1252 }
1253
1254 result
1255 _CanvasImpl::FillEllipse(const Color& color, const FloatRectangle& vcBounds)
1256 {
1257         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1258         SysTryReturnResult(NID_GRP, &vcBounds, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1259         SysTryReturnResult(NID_GRP, (vcBounds.width >= 0.0f) && (vcBounds.height >= 0.0f), E_OUT_OF_RANGE,
1260                                           "The given rectangle(width:%d,height:%d) is out of range.", vcBounds.width, vcBounds.height);
1261
1262         return _CanvasImplPrivate::FillEllipse(this, color, _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcBounds));
1263 }
1264
1265 result
1266 _CanvasImpl::FillPolygon(const Color& color, const Tizen::Base::Collection::IList& vcPoints)
1267 {
1268         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1269
1270         SysTryReturnResult(NID_GRP, &vcPoints, E_INVALID_ARG, "The given rectangle is invalid.");
1271
1272         int numPoint = vcPoints.GetCount();
1273
1274         SysTryReturnResult(NID_GRP, numPoint >= 0, E_INVALID_ARG, "The number of points (%d) is not valid.", numPoint);
1275
1276         if (numPoint < 3) // TBD.
1277         {
1278                 return E_SUCCESS;
1279         }
1280
1281         std::unique_ptr<_Util::Point<double>[]> doublePoint;
1282
1283         {
1284                 _Util::Point<double>* pDoublePoint = _Util::Convert<Tizen::Base::Collection::IList, _Util::Point<double>*>(vcPoints);
1285
1286                 SysTryReturnResult(NID_GRP, pDoublePoint != null, E_INVALID_ARG, "The type of points is not valid.");
1287
1288                 doublePoint.reset(pDoublePoint);
1289         }
1290
1291         if (_ResUtil::NeedToConvertCoord())
1292         {
1293                 for (int i = 0; i < numPoint; i++)
1294                 {
1295                         doublePoint[i] = _ResUtil::ConvertToPhyCoord(doublePoint[i]);
1296                 }
1297
1298                 return this->_pNativeCanvas->FillPolygon(color, doublePoint.get(), numPoint);
1299         }
1300         else
1301         {
1302                 return this->_pNativeCanvas->FillPolygon(color, doublePoint.get(), numPoint);
1303         }
1304 }
1305
1306 result
1307 _CanvasImpl::FillRectangle(const Color& color, const Rectangle& vcRect)
1308 {
1309         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1310         SysTryReturnResult(NID_GRP, &vcRect, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1311         SysTryReturnResult(NID_GRP, (vcRect.width >= 0) && (vcRect.height >= 0), E_OUT_OF_RANGE, "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width, vcRect.height);
1312
1313         return _CanvasImplPrivate::FillRectangle(this, color, _Util::Convert<Rectangle, _Util::Rectangle<double> >(vcRect));
1314 }
1315
1316 result
1317 _CanvasImpl::FillRectangle(const Color& color, const FloatRectangle& vcRect)
1318 {
1319         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1320         SysTryReturnResult(NID_GRP, &vcRect, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1321         SysTryReturnResult(NID_GRP, (vcRect.width >= 0.0f) && (vcRect.height >= 0.0f), E_OUT_OF_RANGE, "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width, vcRect.height);
1322
1323         return _CanvasImplPrivate::FillRectangle(this, color, _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcRect));
1324 }
1325
1326 result
1327 _CanvasImpl::FillRoundRectangle(const Color& color, const Rectangle& vcRect, const Dimension& vcArcDim)
1328 {
1329         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1330         SysTryReturnResult(NID_GRP, (&vcRect) && (&vcArcDim), E_OUT_OF_RANGE, "The given rectangle is invalid.");
1331         SysTryReturnResult(NID_GRP, (vcRect.width >= 0) && (vcRect.height >= 0), E_OUT_OF_RANGE, "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width, vcRect.height);
1332         SysTryReturnResult(NID_GRP, (vcArcDim.width >= 0) && (vcArcDim.height >= 0), E_OUT_OF_RANGE, "The given arc size(width:%d,height:%d) is out of range.", vcArcDim.width, vcArcDim.height);
1333
1334         return _CanvasImplPrivate::FillRoundRectangle(this, color, _Util::Convert<Rectangle, _Util::Rectangle<double> >(vcRect), _Util::Convert<Dimension, _Util::Dimension<double> >(vcArcDim));
1335 }
1336
1337 result
1338 _CanvasImpl::FillRoundRectangle(const Color& color, const FloatRectangle& vcRect, const FloatDimension& vcArcDim)
1339 {
1340         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1341         SysTryReturnResult(NID_GRP, (&vcRect) && (&vcArcDim), E_OUT_OF_RANGE, "The given rectangle is invalid.");
1342         SysTryReturnResult(NID_GRP, (vcRect.width >= 0.0f) && (vcRect.height >= 0.0f), E_OUT_OF_RANGE, "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width, vcRect.height);
1343         SysTryReturnResult(NID_GRP, (vcArcDim.width >= 0.0f) && (vcArcDim.height >= 0.0f), E_OUT_OF_RANGE, "The given arc size(width:%d,height:%d) is out of range.", vcArcDim.width, vcArcDim.height);
1344
1345         return _CanvasImplPrivate::FillRoundRectangle(this, color, _Util::Convert<FloatRectangle, _Util::Rectangle<double> >(vcRect), _Util::Convert<FloatDimension, _Util::Dimension<double> >(vcArcDim));
1346 }
1347
1348 result
1349 _CanvasImpl::FillTriangle(const Color& color, const FloatPoint& vcPoint1, const FloatPoint& vcPoint2, const FloatPoint& vcPoint3)
1350 {
1351         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1352
1353         return _CanvasImplPrivate::FillTriangle(this, color,
1354                 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint1),
1355                 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint2),
1356                 _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint3));
1357 }
1358
1359 result
1360 _CanvasImpl::FillTriangle(const Color& color, const Point& vcPoint1, const Point& vcPoint2, const Point& vcPoint3)
1361 {
1362         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1363
1364         return _CanvasImplPrivate::FillTriangle(this, color,
1365                 _Util::Convert<Point, _Util::Point<double> >(vcPoint1),
1366                 _Util::Convert<Point, _Util::Point<double> >(vcPoint2),
1367                 _Util::Convert<Point, _Util::Point<double> >(vcPoint3));
1368 }
1369
1370 result
1371 _CanvasImpl::DrawText(const Point& vcPoint, const Tizen::Base::String& text)
1372 {
1373         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1374
1375         SysTryReturnResult(NID_GRP, text.GetLength() >= 0, E_INVALID_ARG, "The text length (%d) is not valid.", text.GetLength());
1376
1377         if (_ResUtil::NeedToConvertCoord())
1378         {
1379                 Point pcPoint = _ResUtil::ConvertToPhyCoord(vcPoint);
1380
1381                 return this->_pNativeCanvas->DrawText(pcPoint, text);
1382         }
1383         else
1384         {
1385                 return this->_pNativeCanvas->DrawText(vcPoint, text);
1386         }
1387 }
1388
1389 result
1390 _CanvasImpl::DrawText(const Point& vcPoint, const Tizen::Base::String& text, int startIndex, int length)
1391 {
1392         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1393         SysTryReturnResult(NID_GRP, text.GetLength() >= 0, E_INVALID_ARG, "The text length (%d) is not valid.", text.GetLength());
1394         SysTryReturnResult(NID_GRP, length >= 0 && startIndex >= 0 && startIndex < text.GetLength(), E_OUT_OF_RANGE, "The value of the length (%d),  startIndex(%d) are outside the valid range defined by the method.", length, startIndex);
1395
1396         if (text.GetLength() == 0)
1397         {
1398                 return E_SUCCESS;
1399         }
1400
1401         if (_ResUtil::NeedToConvertCoord())
1402         {
1403                 Point pcPt = _ResUtil::ConvertToPhyCoord(vcPoint);
1404
1405                 return this->_pNativeCanvas->DrawText(pcPt, text, startIndex, length);
1406         }
1407         else
1408         {
1409                 return this->_pNativeCanvas->DrawText(vcPoint, text, startIndex, length);
1410         }
1411 }
1412
1413 result
1414 _CanvasImpl::DrawText(const Point& vcPoint, const Tizen::Base::String& text, int startIndex, const Color& outlineColor)
1415 {
1416         const char* pNotConstructedYet = "[E_OPERATION_FAILED] This instance is not constructed yet.";
1417
1418         SysTryReturn(NID_GRP, this, E_OPERATION_FAILED, E_OPERATION_FAILED, pNotConstructedYet);
1419         SysTryReturn(NID_GRP, this->_pNativeCanvas, E_OPERATION_FAILED, E_OPERATION_FAILED, pNotConstructedYet);
1420         SysTryReturn(NID_GRP, this->_pNativeCanvas->IsValid(), E_OPERATION_FAILED, E_OPERATION_FAILED, pNotConstructedYet);
1421
1422         SysTryReturnResult(NID_GRP, text.GetLength() >= 0, E_INVALID_ARG, "The text length (%d) is not valid.", text.GetLength());
1423
1424         return this->DrawText(vcPoint, text, startIndex, text.GetLength(), outlineColor);
1425 }
1426
1427 result
1428 _CanvasImpl::DrawText(const Point& vcPoint, const Tizen::Base::String& text, int startIndex, int length, const Color& outlineColor)
1429 {
1430         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1431
1432         SysTryReturnResult(NID_GRP, text.GetLength() >= 0, E_INVALID_ARG, "The text length (%d) is not valid.", text.GetLength());
1433
1434         SysTryReturnResult(NID_GRP, length >= 0, E_OUT_OF_RANGE,
1435                                           "The value of the length (%d) is outside the valid range defined by the method.",
1436                                           length);
1437
1438         if (text.GetLength() == 0)
1439         {
1440                 return E_SUCCESS;
1441         }
1442
1443         if (_ResUtil::NeedToConvertCoord())
1444         {
1445                 Point pcPoint = _ResUtil::ConvertToPhyCoord(vcPoint);
1446
1447                 return this->_pNativeCanvas->DrawText(pcPoint, text, startIndex, length, outlineColor);
1448         }
1449         else
1450         {
1451                 return this->_pNativeCanvas->DrawText(vcPoint, text, startIndex, length, outlineColor);
1452         }
1453 }
1454
1455 result
1456 _CanvasImpl::DrawText(const Point& vcPoint, const EnrichedText& etext)
1457 {
1458         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1459
1460         const _EnrichedTextImpl* pImpl = _EnrichedTextImpl::GetInstance(etext);
1461
1462         if (pImpl == null)
1463         {
1464                 return E_OPERATION_FAILED;
1465         }
1466
1467         Tizen::Graphics::_Text::TextObject* pTextObject = const_cast <_EnrichedTextImpl*>(pImpl)->GetTextObject();
1468
1469         if (pTextObject == null)
1470         {
1471                 return E_OPERATION_FAILED;
1472         }
1473
1474         Rectangle bounds = pImpl->GetBounds();
1475         Rectangle rect(vcPoint.x, vcPoint.y, bounds.width, bounds.height);
1476         pTextObject->SetBounds(rect);
1477         pTextObject->Draw(*this);
1478
1479         return E_SUCCESS;
1480 }
1481
1482 Rectangle
1483 _CanvasImpl::GetBounds(void) const
1484 {
1485         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, Rectangle(), E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
1486
1487         if (_ResUtil::NeedToConvertCoord())
1488         {
1489                 const _ResUtil::Pos& pos = this->_pCoordHolder->canvasPos.required;
1490                 const _ResUtil::Rect& bounds = this->_pCoordHolder->canvasSize.required;
1491                 const Rectangle boundsFromPi = this->_pNativeCanvas->GetBounds();
1492
1493                 if ((bounds.w == 0 && boundsFromPi.width > 0) || (bounds.h == 0 && boundsFromPi.height > 0))
1494                 {
1495                         _CanvasImpl* pThis = const_cast<_CanvasImpl*>(this);
1496
1497                         pThis->_pCoordHolder->canvasSize = _ResUtil::Rect(boundsFromPi.x, boundsFromPi.y, boundsFromPi.width, boundsFromPi.height);
1498
1499                         pThis->_pCoordHolder->canvasSize.phyCoord.x = boundsFromPi.x;
1500                         pThis->_pCoordHolder->canvasSize.phyCoord.y = boundsFromPi.y;
1501                         pThis->_pCoordHolder->canvasSize.phyCoord.w = boundsFromPi.width;
1502                         pThis->_pCoordHolder->canvasSize.phyCoord.h = boundsFromPi.height;
1503                 }
1504
1505                 // exception from the window canvas
1506                 if (boundsFromPi.x == 0 && boundsFromPi.y == 0)
1507                 {
1508                         return Rectangle(0, 0, bounds.w, bounds.h);
1509                 }
1510                 else
1511                 {
1512                         return Rectangle(pos.x, pos.y, bounds.w, bounds.h);
1513                 }
1514         }
1515         else
1516         {
1517                 return this->_pNativeCanvas->GetBounds();
1518         }
1519 }
1520
1521 LineStyle
1522 _CanvasImpl::GetLineStyle() const
1523 {
1524         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, LINE_STYLE_MAX, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
1525
1526         return this->_pNativeCanvas->GetLineStyle();
1527 }
1528
1529 int
1530 _CanvasImpl::GetLineWidth() const
1531 {
1532         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, -1, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
1533
1534         if (_ResUtil::NeedToConvertCoord())
1535         {
1536                 return this->_pCoordHolder->lineWidth.required;
1537         }
1538         else
1539         {
1540                 return this->_pNativeCanvas->GetLineWidth();
1541         }
1542 }
1543
1544 result
1545 _CanvasImpl::SetLineStyle(LineStyle style)
1546 {
1547         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1548
1549         SysTryReturnResult(NID_GRP, LINE_STYLE_MIN < style && style < LINE_STYLE_MAX, E_INVALID_ARG, "The given line style(%d) is out of range.", style);
1550
1551         return this->_pNativeCanvas->SetLineStyle(style);
1552 }
1553
1554 result
1555 _CanvasImpl::SetLineWidth(int vcWidth)
1556 {
1557         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1558
1559         SysTryReturnResult(NID_GRP, vcWidth > 0, E_OUT_OF_RANGE, "The given line width(%d) is out of range.", vcWidth);
1560
1561         if (_ResUtil::NeedToConvertCoord())
1562         {
1563                 int pcWidth = _ResUtil::ConvertToPhyCoordSize(vcWidth);
1564                 float pcWidthFloat = _ResUtil::ConvertToPhyCoordSize(float(vcWidth));
1565
1566                 result r = this->_pNativeCanvas->SetLineWidth(pcWidth, pcWidthFloat);
1567
1568                 if (IsSucceeded(r))
1569                 {
1570                         this->_pCoordHolder->lineWidth = vcWidth;
1571                 }
1572
1573                 return r;
1574         }
1575         else
1576         {
1577                 return this->_pNativeCanvas->SetLineWidth(vcWidth, float(vcWidth));
1578         }
1579 }
1580
1581 result
1582 _CanvasImpl::GetDashPattern(Tizen::Base::Collection::IListT<int>& pattern, int& offset)
1583 {
1584         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
1585
1586         pattern.RemoveAll();
1587
1588         result r = pattern.AddItems(this->_dashList);
1589
1590         if (IsFailed(r))
1591         {
1592                 switch (r)
1593                 {
1594                 case E_INVALID_ARG:
1595                 case E_OPERATION_FAILED:
1596                 case E_OUT_OF_MEMORY:
1597                         SysTryReturn(NID_GRP, false, r, r, "[%s] Propagating.", GetErrorMessage(r));
1598                         break;
1599                 default:
1600                         SysTryReturn(NID_GRP, false, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] Tizen::Base::Collection::ArrayListT<int>::AddItems() failed");
1601                         break;
1602                 }
1603         }
1604
1605         offset = this->_dashOffset;
1606
1607         return r;
1608 }
1609
1610 result
1611 _CanvasImpl::SetDashPattern(const Tizen::Base::Collection::IListT<int>& pattern, int offset)
1612 {
1613         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
1614
1615         result r = E_SUCCESS;
1616
1617         // It is NOT the strong guarantee for an exception
1618         this->_dashList.RemoveAll();
1619
1620         r = this->_dashList.AddItems(pattern);
1621
1622         if (IsFailed(r))
1623         {
1624                 switch (r)
1625                 {
1626                 case E_INVALID_ARG:
1627                 case E_OPERATION_FAILED:
1628                 case E_OUT_OF_MEMORY:
1629                         SysTryReturn(NID_GRP, false, r, r, "[%s] Propagating.", GetErrorMessage(r));
1630                         break;
1631                 default:
1632                         SysTryReturn(NID_GRP, false, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] Tizen::Base::Collection::ArrayListT<int>::AddItems() failed");
1633                         break;
1634                 }
1635         }
1636
1637         {
1638                 int dashIntValue = 0;
1639                 Tizen::Graphics::_Util::AccumList<double> dashValueList;
1640
1641                 for (int i = 0; i < pattern.GetCount(); i++)
1642                 {
1643                         pattern.GetAt(i, dashIntValue);
1644                         dashValueList.Push(double(dashIntValue));
1645                 }
1646
1647                 r = this->_pNativeCanvas->SetDashPattern(dashValueList, double(offset));
1648                 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1649
1650                 this->_dashOffset = offset;
1651         }
1652
1653         return r;
1654 }
1655
1656 result
1657 _CanvasImpl::SetDrawingQuality(BitmapDrawingQuality quality)
1658 {
1659         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1660
1661         switch (quality)
1662         {
1663         case BITMAP_DRAWING_QUALITY_LOW:
1664         case BITMAP_DRAWING_QUALITY_MID:
1665         case BITMAP_DRAWING_QUALITY_HIGH:
1666                 break;
1667         default:
1668                 SysLogException(NID_GRP, E_INVALID_ARG, "The specified drawing quality(%d) is invalid.", quality);
1669                 return E_INVALID_ARG;
1670         }
1671
1672         this->_pNativeCanvas->SetDrawingQuality(quality);
1673
1674         return E_SUCCESS;
1675 }
1676
1677 BitmapDrawingQuality
1678 _CanvasImpl::GetDrawingQuality(void) const
1679 {
1680         return (INSTANCE_IS_VALID) ? this->_pNativeCanvas->GetDrawingQuality() : BITMAP_DRAWING_QUALITY_LOW;
1681 }
1682
1683 result
1684 _CanvasImpl::SetBlendingMode(BlendingMode blendingMode)
1685 {
1686         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1687
1688         switch (blendingMode)
1689         {
1690         case BLENDING_MODE_CLEAR:
1691         case BLENDING_MODE_SRC:
1692         case BLENDING_MODE_DST:
1693         case BLENDING_MODE_SRC_OVER:
1694         case BLENDING_MODE_DST_OVER:
1695         case BLENDING_MODE_SRC_IN:
1696         case BLENDING_MODE_DST_IN:
1697         case BLENDING_MODE_SRC_OUT:
1698         case BLENDING_MODE_DST_OUT:
1699         case BLENDING_MODE_SRC_ATOP:
1700         case BLENDING_MODE_DST_ATOP:
1701         case BLENDING_MODE_DST_XOR:
1702         case BLENDING_MODE_ADD:
1703         case BLENDING_MODE_SATURATE:
1704         case BLENDING_MODE_MULTIPLY:
1705         case BLENDING_MODE_SCREEN:
1706         case BLENDING_MODE_OVERLAY:
1707         case BLENDING_MODE_DARKEN:
1708         case BLENDING_MODE_LIGHTEN:
1709         case BLENDING_MODE_COLOR_DODGE:
1710         case BLENDING_MODE_COLOR_BURN:
1711         case BLENDING_MODE_HARD_LIGHT:
1712         case BLENDING_MODE_SOFT_LIGHT:
1713         case BLENDING_MODE_DIFFERENCE:
1714         case BLENDING_MODE_EXCLUSION:
1715                 break;
1716         default:
1717                 SysLogException(NID_GRP, E_INVALID_ARG, "The specified blending mode(%d) is invalid.", blendingMode);
1718                 return E_INVALID_ARG;
1719         }
1720
1721         this->_pNativeCanvas->SetBlendingMode(blendingMode);
1722
1723         return E_SUCCESS;
1724 }
1725
1726 BlendingMode
1727 _CanvasImpl::GetBlendingMode(void) const
1728 {
1729         return (INSTANCE_IS_VALID) ? this->_pNativeCanvas->GetBlendingMode() : BLENDING_MODE_SRC_OVER;
1730 }
1731
1732 result
1733 _CanvasImpl::GetPixel(const Point& vcPoint, Color& color) const
1734 {
1735         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1736
1737         Rectangle rtCanvas = _GetBoundsRel(*this);
1738
1739         SysTryReturnResult(NID_GRP, !rtCanvas.IsEmpty(), E_OUT_OF_RANGE, "Cannot get the bounds of the canvas.");
1740
1741         result r = _Util::Validate(vcPoint, rtCanvas);
1742
1743         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
1744
1745         if (_ResUtil::NeedToConvertCoord())
1746         {
1747                 Point pcPoint = _ResUtil::ConvertToPhyCoord(vcPoint);
1748
1749                 return this->_pNativeCanvas->GetPixel(pcPoint, color);
1750         }
1751         else
1752         {
1753                 return this->_pNativeCanvas->GetPixel(vcPoint, color);
1754         }
1755 }
1756
1757 result
1758 _CanvasImpl::SetPixel(const FloatPoint& vcPoint)
1759 {
1760         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1761
1762         return _CanvasImplPrivate::SetPixel(this, _Util::Convert<FloatPoint, _Util::Point<double> >(vcPoint));
1763 }
1764
1765 result
1766 _CanvasImpl::SetPixel(const Point& vcPoint)
1767 {
1768         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1769
1770         return _CanvasImplPrivate::SetPixel(this, _Util::Convert<Point, _Util::Point<int> >(vcPoint));
1771 }
1772
1773 result
1774 _CanvasImpl::Show()
1775 {
1776         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1777
1778         result r = E_SUCCESS;
1779         Rectangle rect = this->GetBounds();
1780
1781         r = this->_pNativeCanvas->Show();
1782
1783         return r;
1784 }
1785
1786 result
1787 _CanvasImpl::Show(const Rectangle& vcRect)
1788 {
1789         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1790
1791         SysTryReturnResult(NID_GRP, &vcRect, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1792         SysTryReturnResult(NID_GRP, (vcRect.width >= 0) && (vcRect.height >= 0), E_OUT_OF_RANGE,
1793                                           "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width,
1794                                           vcRect.height);
1795
1796         result r = E_SUCCESS;
1797         Rectangle rect = this->GetBounds();
1798
1799         if (_ResUtil::NeedToConvertCoord())
1800         {
1801                 Rectangle pcRect = _ResUtil::ConvertToPhyCoord(vcRect);
1802
1803                 r = this->_pNativeCanvas->Show(pcRect);
1804         }
1805         else
1806         {
1807                 r = this->_pNativeCanvas->Show(vcRect);
1808         }
1809
1810         return r;
1811 }
1812
1813 result
1814 _CanvasImpl::SetFont(const Font& font)
1815 {
1816         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1817         SysTryReturnResult(NID_GRP, _FontImpl::GetInstance(font) && _FontImpl::GetInstance(font)->IsConstructed(), E_INVALID_ARG, "The given font is not constructed.");
1818         SysTryReturnResult(NID_GRP, font.GetMaxHeight() > 0 && font.GetMaxWidth() > 0, E_INVALID_ARG, "The infomation of the given font is not valid. (maxWidth=%d,maxHeight=%d).", font.GetMaxWidth(), font.GetMaxHeight());
1819
1820         // should keep clone font
1821         Font* pFont = _FontImpl::CloneN(font);
1822
1823         if (pFont == null)
1824         {
1825                 SysTryLog(NID_GRP, pFont, "[] Fails to allocate memory for font resource.");
1826
1827                 this->_pFont = null;
1828
1829                 // shkim, TODO.
1830                 // we failed to make cloned font. so, return what? E_SYSTEM which is not defined in header?? or use E_OPERATION_FAILED again for different meaning?
1831                 // or just setting defult font?!
1832                 return E_OPERATION_FAILED;
1833         }
1834
1835         EXTRACT_FONTEX(pFontEx, *pFont);
1836         result r = this->_pNativeCanvas->SetFont(*pFontEx);
1837         SysTryCatch(NID_GRP, E_SUCCESS == r, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] Fails to set font.");
1838
1839         // succeed making cloned font, then keep it and replace old one.
1840         if (this->_pFont)
1841         {
1842                 delete this->_pFont;
1843                 this->_pFont = null;
1844         }
1845
1846         this->_pFont = pFont;
1847
1848         return r;
1849
1850 CATCH:
1851         delete pFont;
1852         pFont = null;
1853
1854         return r;
1855 }
1856
1857 Font*
1858 _CanvasImpl::GetFontN(void)
1859 {
1860         result r = E_SUCCESS;
1861         Font* pFont = null;
1862
1863         // clear last error
1864         ClearLastResult();
1865
1866         SysTryCatch(NID_GRP, INSTANCE_IS_VALID, r = E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
1867
1868         // we have the font user set
1869         if (this->_pFont)
1870         {
1871                 pFont = _FontImpl::CloneN(*(this->_pFont));
1872                 SysTryCatch(NID_GRP, pFont, r = E_OUT_OF_MEMORY, E_OPERATION_FAILED, "[E_OUT_OF_MEMORY] Failed to create Font instance.");
1873         }
1874         else
1875         {
1876                 // make font instance with the attribute of system default font
1877                 // shkim, TODO
1878         }
1879
1880         SetLastResult(r);
1881         return pFont;
1882
1883 CATCH:
1884         if (pFont)
1885         {
1886                 delete pFont;
1887         }
1888
1889         SetLastResult(r);
1890
1891         return null;
1892 }
1893
1894 void
1895 _CanvasImpl::SetTextOrigin(TextOrigin origin)
1896 {
1897         if (INSTANCE_IS_VALID)
1898         {
1899                 switch (origin)
1900                 {
1901                 case TEXT_ORIGIN_LEFT_TOP:
1902                 case TEXT_ORIGIN_BASELINE:
1903                         this->_pNativeCanvas->__textOrigin = origin;
1904                         break;
1905                 }
1906         }
1907 }
1908
1909 result
1910 _CanvasImpl::SetClipBounds(const Rectangle& vcRect)
1911 {
1912         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1913
1914         SysTryReturnResult(NID_GRP, &vcRect, E_OUT_OF_RANGE, "The given rectangle is invalid.");
1915         SysTryReturnResult(NID_GRP, (vcRect.width >= 0) && (vcRect.height >= 0), E_OUT_OF_RANGE, "The given rectangle(width:%d,height:%d) is out of range.", vcRect.width, vcRect.height);
1916
1917         Rectangle rtCanvas = _GetBoundsRel(*this);
1918
1919         result r = _Util::Validate(vcRect, rtCanvas);
1920
1921         SysTryReturnResult(NID_GRP, !IsFailed(r), r, "Propagating.");
1922
1923         Rectangle revisedVcRect;
1924
1925         {
1926                 int x1 = vcRect.x;
1927                 int y1 = vcRect.y;
1928                 int x2 = vcRect.x + vcRect.width;
1929                 int y2 = vcRect.y + vcRect.height;
1930
1931                 x1 = (x1 > 0) ? x1 : 0;
1932                 y1 = (y1 > 0) ? y1 : 0;
1933                 x2 = (x2 < rtCanvas.width) ? x2 : rtCanvas.width;
1934                 y2 = (y2 < rtCanvas.height) ? y2 : rtCanvas.height;
1935
1936                 revisedVcRect.x = x1;
1937                 revisedVcRect.y = y1;
1938                 revisedVcRect.width = x2 - x1;
1939                 revisedVcRect.height = y2 - y1;
1940         }
1941
1942         if (_ResUtil::NeedToConvertCoord())
1943         {
1944                 Rectangle pcRect = _ResUtil::ConvertToPhyCoord(revisedVcRect);
1945
1946                 // special case
1947                 pcRect.width = (pcRect.width >= 0) ? pcRect.width : 1;
1948                 pcRect.height = (pcRect.height >= 0) ? pcRect.height : 1;
1949
1950                 result r = this->_pNativeCanvas->SetClipBounds(pcRect);
1951
1952                 if (IsSucceeded(r))
1953                 {
1954                         this->_pCoordHolder->clipBounds = _ResUtil::Rect(revisedVcRect.x, revisedVcRect.y, revisedVcRect.width,
1955                                                                                                                    revisedVcRect.height);
1956                 }
1957
1958                 return r;
1959         }
1960         else
1961         {
1962                 return this->_pNativeCanvas->SetClipBounds(revisedVcRect);
1963         }
1964 }
1965
1966 Rectangle
1967 _CanvasImpl::GetClipBounds(void) const
1968 {
1969         Rectangle rect;
1970         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, rect, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
1971
1972         if (_ResUtil::NeedToConvertCoord())
1973         {
1974                 const _ResUtil::Rect& bounds = this->_pCoordHolder->clipBounds.required;
1975
1976                 return Rectangle(bounds.x, bounds.y, bounds.w, bounds.h);
1977         }
1978         else
1979         {
1980                 return this->_pNativeCanvas->GetClipBounds();
1981         }
1982 }
1983
1984 result
1985 _CanvasImpl::Lock(BufferInfo& info, long timeout)
1986 {
1987         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
1988
1989         SysTryReturnResult(NID_GRP, (static_cast <unsigned long>(timeout) == INFINITE) || (timeout >= 0), E_INVALID_ARG,
1990                                           "'timeout(=%d)' is not valid.",
1991                                           timeout);
1992
1993         return this->_pNativeCanvas->Lock(info, timeout);
1994 }
1995
1996 result
1997 _CanvasImpl::Unlock()
1998 {
1999         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2000
2001         return this->_pNativeCanvas->Unlock();
2002 }
2003
2004 void
2005 _CanvasImpl::SetForegroundColor(const Color& fgColor)
2006 {
2007         SysTryReturnVoidResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2008
2009         return this->_pNativeCanvas->SetForegroundColor(fgColor);
2010 }
2011
2012 Color
2013 _CanvasImpl::GetForegroundColor(void) const
2014 {
2015         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, Color::GetColor(COLOR_ID_BLACK), E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2016
2017         return this->_pNativeCanvas->GetForegroundColor();
2018 }
2019
2020 void
2021 _CanvasImpl::SetBackgroundColor(const Color& bgColor)
2022 {
2023         SysTryReturnVoidResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2024
2025         return this->_pNativeCanvas->SetBackgroundColor(bgColor);
2026 }
2027
2028 Color
2029 _CanvasImpl::GetBackgroundColor(void) const
2030 {
2031         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, Color::GetColor(COLOR_ID_BLACK), E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2032
2033         return this->_pNativeCanvas->GetBackgroundColor();
2034 }
2035
2036 result
2037 _CanvasImpl::SetPosition(const Point& vcPoint)
2038 {
2039         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2040
2041         return this->SetPosition(vcPoint.x, vcPoint.y);
2042 }
2043
2044 result
2045 _CanvasImpl::SetPosition(int vcX, int vcY)
2046 {
2047         SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, "This instance is not constructed yet.");
2048
2049         if (_ResUtil::NeedToConvertCoord())
2050         {
2051                 Point pcPoint = _ResUtil::ConvertToPhyCoord(Point(vcX, vcY));
2052
2053                 result r = this->_pNativeCanvas->SetPosition(pcPoint.x, pcPoint.y);
2054
2055                 if (IsSucceeded(r))
2056                 {
2057                         this->_pCoordHolder->canvasPos = _ResUtil::Pos(vcX, vcY);
2058                 }
2059
2060                 return r;
2061         }
2062         else
2063         {
2064                 return this->_pNativeCanvas->SetPosition(vcX, vcY);
2065         }
2066 }
2067
2068 Canvas*
2069 _CanvasImpl::GetSubCanvasN(const Rectangle& subRegion) const
2070 {
2071         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, null, E_OPERATION_FAILED, "This instance is not constructed yet.");
2072
2073         _Canvas* pSourceNativeCanvas = this->_pNativeCanvas;
2074
2075         std::auto_ptr <Canvas> subCanvas(new (std::nothrow) Canvas);
2076
2077         Canvas* pSubCanvas = subCanvas.get();
2078
2079         SysTryReturn(NID_GRP, pSubCanvas, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
2080
2081         _CanvasImpl* pSubCanvasImpl = _CanvasImpl::GetInstance(*pSubCanvas);
2082
2083         SysTryReturn(NID_GRP, pSubCanvasImpl, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
2084
2085         if (_ResUtil::NeedToConvertCoord())
2086         {
2087                 Rectangle subRegionPC = _ResUtil::ConvertToPhyCoord(subRegion);
2088
2089                 subRegionPC.width = (subRegionPC.width > 0) ? subRegionPC.width : 1;
2090                 subRegionPC.height = (subRegionPC.height > 0) ? subRegionPC.height : 1;
2091
2092                 result r = pSubCanvasImpl->_pNativeCanvas->Construct(pSourceNativeCanvas, subRegionPC);
2093
2094                 SysTryReturn(NID_GRP, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
2095
2096                 pSubCanvasImpl->_pCoordHolder->Init(subRegion);
2097                 pSubCanvasImpl->_pCoordHolder->canvasSize.phyCoord.w = subRegionPC.width;
2098                 pSubCanvasImpl->_pCoordHolder->canvasSize.phyCoord.h = subRegionPC.height;
2099         }
2100         else
2101         {
2102                 result r = pSubCanvasImpl->_pNativeCanvas->Construct(pSourceNativeCanvas, subRegion);
2103
2104                 SysTryReturn(NID_GRP, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
2105         }
2106
2107         if (this->_pFont)
2108         {
2109                 pSubCanvasImpl->SetFont(*this->_pFont);
2110         }
2111
2112         if (this->_pPriorityFont)
2113         {
2114                 pSubCanvasImpl->SetPriorityFont(*this->_pPriorityFont);
2115         }
2116
2117         return subCanvas.release();
2118 }
2119
2120 result
2121 _CanvasImpl::SetPriorityFont(const Font& font)
2122 {
2123         ClearLastResult();
2124
2125         // check input param
2126         SysTryReturn(NID_GRP, INSTANCE_IS_VALID, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
2127         SysTryReturn(NID_GRP, font.GetMaxHeight() > 0 && font.GetMaxWidth() > 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The infomation of the given font is not valid. (maxWidth=%d, maxHeight=%d).", font.GetMaxWidth(), font.GetMaxHeight());
2128
2129         Font* pFont = &(const_cast <Font&>(font));
2130
2131         EXTRACT_FONTEX(pFontEx, *pFont);
2132         result r = this->_pNativeCanvas->SetPriorityFont(*pFontEx);
2133         SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2134         // overwrite existing priority font
2135         this->_pPriorityFont = pFont;
2136
2137         return E_SUCCESS;
2138 }
2139
2140 void
2141 _CanvasImpl::ResetPriorityFont(void)
2142 {
2143         if (INSTANCE_IS_VALID)
2144         {
2145                 this->_pPriorityFont = null;
2146                 this->_pNativeCanvas->ResetPriorityFont();
2147         }
2148 }
2149
2150 void
2151 _CanvasImpl::SetStableRenderer(bool isStable)
2152 {
2153         if (INSTANCE_IS_VALID)
2154         {
2155                 this->_pNativeCanvas->__useStableRenderer = isStable;
2156         }
2157 }
2158
2159 void
2160 _CanvasImpl::SetFrameInfoCallback(void* (*pGetDefaultFrameNativeHandle)(void), void* (*pGetDefaultFrameHandle)(void))
2161 {
2162         _GetDefaultFrameEcoreEvasHandle = (pGetDefaultFrameNativeHandle) ? pGetDefaultFrameNativeHandle : _GetNull;
2163         _GetDefaultFrameEvasHandle = (pGetDefaultFrameHandle) ? pGetDefaultFrameHandle : _GetNull;
2164 }
2165
2166 void
2167 _CanvasImpl::SetThemeInfoCallback(Color (*pGetDefaultForegroundColor)(void), Color (*pGetDefaultBackgroundColor)(void))
2168 {
2169         _GetDefaultForegroundColor = (pGetDefaultForegroundColor) ? pGetDefaultForegroundColor : _GetBlack;
2170         _GetDefaultBackgroundColor = (pGetDefaultBackgroundColor) ? pGetDefaultBackgroundColor : _GetWhite;
2171 }
2172
2173 _CanvasImpl*
2174 _CanvasImpl::GetInstance(Canvas& canvas)
2175 {
2176         return (&canvas != null) ? canvas.__pImpl : null;
2177 }
2178
2179 const _CanvasImpl*
2180 _CanvasImpl::GetInstance(const Canvas& canvas)
2181 {
2182         return (&canvas != null) ? canvas.__pImpl : null;
2183 }
2184
2185 }} // Tizen::Graphics