2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FGrp_Canvas.cpp
20 * @brief This is the implementation file for _Canvas class.
30 #include <unique_ptr.h>
34 #include <FGrpBufferInfo.h>
36 #include <FBaseInternalTypes.h>
37 #include <FApp_AppInfo.h>
39 #include <FBaseSysLog.h>
41 #include "FGrp_BufferInfoImpl.h"
42 #include "FGrp_Callback.h"
43 #include "FGrp_Canvas.h"
44 #include "FGrp_CanvasGpPrimitive.h"
45 #include "FGrp_CanvasRasterOp.h"
46 #include "FGrp_Bitmap.h"
47 #include "FGrp_Font.h"
48 #include "FGrp_Screen.h"
49 #include "FGrp_ResUtil.h"
50 #include "FGrp_CanvasCairo.h"
51 #include "FGrp_CanvasPixman.h"
52 #include "util/FGrp_Util.h"
53 #include "effect/FGrp_Effect.h"
55 ////////////////////////////////////////////////////////////////////////////////
58 #define M_PI 3.14159265358979323846
63 ////////////////////////////////////////////////////////////////////////////////
65 #define SET_CAIRO_ALL_PROPERTIES \
66 _Cairo::SetComposite(pCairo->pCairo, _ConvertParam<cairo_operator_t>(this->__compositeMode)); \
67 _Cairo::SetDash(pCairo->pCairo, this->__dashData.pattern.Begin(), int(this->__dashData.pattern.Size()), this->__dashData.offset); \
68 _Cairo::SetLineCap(pCairo->pCairo, _ConvertParam<cairo_line_cap_t>(this->__lineCapStyle)); \
69 _Cairo::SetLineJoin(pCairo->pCairo, _ConvertParam<cairo_line_join_t>(this->__lineJoinStyle)); \
70 if (this->__isClipBoundsSet) \
72 _Cairo::SetClip(pCairo->pCairo, this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height); \
75 #define RESET_CAIRO_ALL_PROPERTIES \
76 _Cairo::ResetComposite(pCairo->pCairo); \
77 _Cairo::ResetDash(pCairo->pCairo); \
78 _Cairo::ResetLineCap(pCairo->pCairo); \
79 _Cairo::ResetLineJoin(pCairo->pCairo); \
80 if (this->__isClipBoundsSet) \
82 _Cairo::ResetClip(pCairo->pCairo); \
85 #define SET_CAIRO_FILL_PROPERTIES \
86 _Cairo::SetComposite(pCairo->pCairo, _ConvertParam<cairo_operator_t>(this->__compositeMode)); \
87 if (this->__isClipBoundsSet) \
89 _Cairo::SetClip(pCairo->pCairo, this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height); \
92 #define RESET_CAIRO_FILL_PROPERTIES \
93 _Cairo::ResetComposite(pCairo->pCairo); \
94 if (this->__isClipBoundsSet) \
96 _Cairo::ResetClip(pCairo->pCairo); \
101 ////////////////////////////////////////////////////////////////////////////////
103 using namespace Tizen::Base;
104 using namespace Tizen::Base::Collection;
105 using namespace Tizen::Base::Utility;
107 ////////////////////////////////////////////////////////////////////////////////
113 template<typename Dest, typename Sour>
114 Dest _ConvertParam(Sour val);
117 Tizen::Graphics::_Effect::Rop
118 _ConvertParam(Tizen::Graphics::_Canvas::BlendOption blendOption)
122 case Tizen::Graphics::_Canvas::BLEND_COPY:
123 return Tizen::Graphics::_Effect::ROP_COPY;
124 case Tizen::Graphics::_Canvas::BLEND_ALPHABLEND:
125 return Tizen::Graphics::_Effect::ROP_ALPHABLEND;
127 return Tizen::Graphics::_Effect::ROP_ALPHABLEND;
133 _ConvertParam(Tizen::Graphics::CompositeMode compositeMode)
135 switch (compositeMode)
137 case Tizen::Graphics::COMPOSITE_MODE_CLEAR:
138 return CAIRO_OPERATOR_CLEAR;
139 case Tizen::Graphics::COMPOSITE_MODE_SRC:
140 return CAIRO_OPERATOR_SOURCE;
141 case Tizen::Graphics::COMPOSITE_MODE_DST:
142 return CAIRO_OPERATOR_DEST;
143 case Tizen::Graphics::COMPOSITE_MODE_SRC_OVER:
144 return CAIRO_OPERATOR_OVER;
145 case Tizen::Graphics::COMPOSITE_MODE_DST_OVER:
146 return CAIRO_OPERATOR_DEST_OVER;
147 case Tizen::Graphics::COMPOSITE_MODE_SRC_IN:
148 return CAIRO_OPERATOR_IN;
149 case Tizen::Graphics::COMPOSITE_MODE_DST_IN:
150 return CAIRO_OPERATOR_DEST_IN;
151 case Tizen::Graphics::COMPOSITE_MODE_SRC_OUT:
152 return CAIRO_OPERATOR_OUT;
153 case Tizen::Graphics::COMPOSITE_MODE_DST_OUT:
154 return CAIRO_OPERATOR_DEST_OUT;
155 case Tizen::Graphics::COMPOSITE_MODE_SRC_ATOP:
156 return CAIRO_OPERATOR_ATOP;
157 case Tizen::Graphics::COMPOSITE_MODE_DST_ATOP:
158 return CAIRO_OPERATOR_DEST_ATOP;
159 case Tizen::Graphics::COMPOSITE_MODE_DST_XOR:
160 return CAIRO_OPERATOR_XOR;
161 case Tizen::Graphics::COMPOSITE_MODE_ADD:
162 return CAIRO_OPERATOR_ADD;
163 case Tizen::Graphics::COMPOSITE_MODE_SATURATE:
164 return CAIRO_OPERATOR_SATURATE;
165 case Tizen::Graphics::COMPOSITE_MODE_MULTIPLY:
166 return CAIRO_OPERATOR_MULTIPLY;
167 case Tizen::Graphics::COMPOSITE_MODE_SCREEN:
168 return CAIRO_OPERATOR_SCREEN;
169 case Tizen::Graphics::COMPOSITE_MODE_OVERLAY:
170 return CAIRO_OPERATOR_OVERLAY;
171 case Tizen::Graphics::COMPOSITE_MODE_DARKEN:
172 return CAIRO_OPERATOR_DARKEN;
173 case Tizen::Graphics::COMPOSITE_MODE_LIGHTEN:
174 return CAIRO_OPERATOR_LIGHTEN;
176 return CAIRO_OPERATOR_OVER;
182 _ConvertParam(Tizen::Graphics::LineCapStyle lineCapStyle)
184 switch (lineCapStyle)
186 case Tizen::Graphics::LINE_CAP_STYLE_BUTT:
187 return CAIRO_LINE_CAP_BUTT;
188 case Tizen::Graphics::LINE_CAP_STYLE_ROUND:
189 return CAIRO_LINE_CAP_ROUND;
190 case Tizen::Graphics::LINE_CAP_STYLE_SQUARE:
191 return CAIRO_LINE_CAP_SQUARE;
193 return CAIRO_LINE_CAP_ROUND;
199 _ConvertParam(Tizen::Graphics::LineJoinStyle lineJoinStyle)
201 switch (lineJoinStyle)
203 case Tizen::Graphics::LINE_JOIN_STYLE_BEVEL:
204 return CAIRO_LINE_JOIN_BEVEL;
205 case Tizen::Graphics::LINE_JOIN_STYLE_ROUND:
206 return CAIRO_LINE_JOIN_ROUND;
207 case Tizen::Graphics::LINE_JOIN_STYLE_MITER:
208 return CAIRO_LINE_JOIN_MITER;
210 return CAIRO_LINE_JOIN_ROUND;
214 inline unsigned short
215 _ConvertRGB888ToRGB565(unsigned char red, unsigned char green, unsigned char blue)
217 typedef unsigned short ColorType;
219 return (ColorType(red >> 3) << 11) | (ColorType(green >> 2) << 5) | ColorType(blue >> 3);
223 _GetWindowSourceObject(Handle handle)
225 Evas_Object* pSourceObject = evas_object_image_source_get((Evas_Object*) handle);
227 return (pSourceObject) ? pSourceObject : (Evas_Object*) handle;
231 _GetWindowWidth(Handle handle)
236 evas_object_image_size_get(_GetWindowSourceObject(handle), &width, &height);
242 _GetWindowHeight(Handle handle)
247 evas_object_image_size_get(_GetWindowSourceObject(handle), &width, &height);
252 ///////////////////////////////////////////////
253 // class _GenericBufferFrameBuffer
255 template<typename Pixel>
256 class _GenericBufferFrameBuffer
257 : public Tizen::Graphics::_Util::GenericBufferBase<Pixel>
260 _GenericBufferFrameBuffer(Handle handle, int _width, int _height)
262 this->__pAssociatedBuffer = this->_pBuffer = (Pixel*) evas_object_image_data_get(_GetWindowSourceObject(handle), EINA_TRUE);
264 int pitch = evas_object_image_stride_get(_GetWindowSourceObject(handle)) / int(sizeof(Pixel));
265 pitch = (pitch) ? pitch : _width;
267 if (this->_pBuffer == null)
269 SysLog(NID_GRP, "[] evas_object_image_data_get(%d) failed!", handle);
272 this->_pitch = pitch;
273 this->_padding = this->_pitch - _width;
276 this->_rect.w = _width;
277 this->_rect.h = _height;
278 this->_pHandle = reinterpret_cast<void*>(handle);
280 this->__associatedHandle = handle;
281 this->__hasOwnership = false;
284 _GenericBufferFrameBuffer(Handle handle, int _x, int _y, int _width, int _height, int pitch)
286 this->__pAssociatedBuffer = this->_pBuffer = (Pixel*) evas_object_image_data_get(_GetWindowSourceObject(handle), EINA_TRUE);
290 pitch = evas_object_image_stride_get(_GetWindowSourceObject(handle)) / int(sizeof(Pixel));
291 pitch = (pitch) ? pitch : _GetWindowWidth(handle);
294 if (this->_pBuffer == null)
296 SysLog(NID_GRP, "[] evas_object_image_data_get(%d) failed!", handle);
299 this->_pBuffer += (_y * pitch + _x);
301 this->_pitch = pitch;
302 this->_padding = this->_pitch - _width;
305 this->_rect.w = _width;
306 this->_rect.h = _height;
307 this->_pHandle = reinterpret_cast<void*>(handle);
309 this->__associatedHandle = handle;
310 this->__hasOwnership = false;
313 _GenericBufferFrameBuffer(int width, int height)
314 : __pAssociatedBuffer(0)
316 this->_pBuffer = new (std::nothrow) Pixel[width * height];
318 if (this->_pBuffer == null)
324 this->_pitch = width;
325 this->_padding = this->_pitch - width;
328 this->_rect.w = width;
329 this->_rect.h = height;
332 this->__associatedHandle = 0;
333 this->__hasOwnership = (this->_pBuffer != null);
336 _GenericBufferFrameBuffer(Pixel* pBuffer, int width, int height, int pitch)
337 : __pAssociatedBuffer(0)
339 this->_pBuffer = pBuffer;
341 this->_pitch = pitch;
342 this->_padding = this->_pitch - width;
345 this->_rect.w = width;
346 this->_rect.h = height;
349 this->__associatedHandle = 0;
350 this->__hasOwnership = false;
353 virtual ~_GenericBufferFrameBuffer(void)
355 if (this->__associatedHandle != 0 && this->__pAssociatedBuffer != null)
357 evas_object_image_data_set(_GetWindowSourceObject(this->__associatedHandle), this->__pAssociatedBuffer);
360 if (this->__hasOwnership)
362 delete[] this->_pBuffer;
368 _GenericBufferFrameBuffer(const _GenericBufferFrameBuffer&);
369 _GenericBufferFrameBuffer& operator =(const _GenericBufferFrameBuffer&);
371 void* __pAssociatedBuffer;
372 Handle __associatedHandle;
385 CLIP_REJECT, // Clipped rejected
386 CLIP_CLIPPED, // Clipped accepted
387 CLIP_ACCEPT // Accepted
391 _ClipRectangle(int& srcX, int& srcY, int& srcW, int& srcH, int clipX, int clipY, int clipW, int clipH)
393 if (clipW <= 0 || clipH <= 0)
398 _ClipResult returnValue = CLIP_ACCEPT;
400 int srcEndX = srcX + srcW - 1;
401 int srcEndY = srcY + srcH - 1;
402 int clipEndX = clipX + clipW - 1;
403 int clipEndY = clipY + clipH - 1;
405 if (srcX > clipEndX || srcEndX < clipX)
410 if (srcY > clipEndY || srcEndY < clipY)
419 returnValue = CLIP_CLIPPED;
422 if (srcEndX > clipEndX)
426 returnValue = CLIP_CLIPPED;
433 returnValue = CLIP_CLIPPED;
436 if (srcEndY > clipEndY)
440 returnValue = CLIP_CLIPPED;
443 srcW = srcEndX - srcX + 1;
444 srcH = srcEndY - srcY + 1;
450 _ComposeColor(unsigned long color32, int opacity)
452 unsigned char alpha = (unsigned char) (((color32) >> 24));
453 unsigned char red = (unsigned char) (((color32) >> 16));
454 unsigned char green = (unsigned char) (((color32) >> 8));
455 unsigned char blue = (unsigned char) ((color32));
457 alpha = (unsigned char) ((alpha * opacity + 255) >> 8);
458 red = (unsigned char) ((red * opacity + 255) >> 8);
459 green = (unsigned char) ((green * opacity + 255) >> 8);
460 blue = (unsigned char) ((blue * opacity + 255) >> 8);
462 return (unsigned long) (((unsigned long) (alpha) << 24) | ((unsigned long) (red) << 16) | ((unsigned long) (green) << 8) | (unsigned long) (blue));
465 template<typename Pixel>
467 _ClearRectangleWithClip(Tizen::Graphics::_Util::ScratchPad<Pixel>* pScratchPad, Pixel color, const Tizen::Graphics::_Util::Rectangle<int>& rect, const Tizen::Graphics::_Util::Rectangle<int>& clip)
469 if (pScratchPad == null)
477 int x2 = x1 + rect.w;
478 int y2 = y1 + rect.h;
480 x1 = (x1 >= clip.x) ? x1 : clip.x;
481 y1 = (y1 >= clip.y) ? y1 : clip.y;
483 x2 = (x2 <= clip.x + clip.w) ? x2 : clip.x + clip.w;
484 y2 = (y2 <= clip.y + clip.h) ? y2 : clip.y + clip.h;
486 if ((x2 - x1) > 0 && (y2 - y1) > 0)
488 pScratchPad->FillRect(x1, y1, x2 - x1, y2 - y1, color);
492 template<typename Pixel>
494 _FillRectangleWithClip(Tizen::Graphics::_Util::ScratchPad<Pixel>* pScratchPad, Pixel color, const Tizen::Graphics::_Util::Rectangle<int>& rect, const Tizen::Graphics::_Util::Rectangle<int>& clip)
496 if (pScratchPad == null)
501 // alpha-fill-rect() applied
502 pScratchPad->RegisterFillRect(Tizen::Graphics::_RasterOp::FnFillRectAlpha32Bit);
503 _ClearRectangleWithClip(pScratchPad, color, rect, clip);
504 pScratchPad->RegisterFillRect(null);
512 typedef Tizen::Graphics::_Canvas::SystemPixel _SystemPixel;
513 typedef Tizen::Graphics::_Util::ScratchPad<_SystemPixel> _ScratchPad32;
515 static std::unique_ptr<_SystemPixel[]> _systemFontBuffer;
516 static std::auto_ptr<_ScratchPad32> _systemFont;
520 ////////////////////////////////////////////////////////////////////////////////
521 // Tizen::Graphics::_Canvas
523 namespace Tizen { namespace Graphics
526 bool _CanvasShowFromMemory(int xDest, int yDest, int xSour, int ySour, int wSour, int hSour, void* pMemory, int width, int height, int depth, int bytesPerLine);
527 void _FlushCanvas(void);
533 _ApplySrcBitmapAttrib(_Util::Pixmap& srcImage, const _Bitmap& bitmap, long isOpaque)
537 if (bitmap.GetBitsPerPixel() == 16)
539 if (bitmap.GetMaskingColor(maskingColor) == E_SUCCESS)
541 srcImage.enableColorKey = 1;
542 srcImage.colorKey = _ConvertRGB888ToRGB565(maskingColor.GetRed(), maskingColor.GetGreen(), maskingColor.GetBlue());
546 srcImage.isOpaque = isOpaque;
547 srcImage.isPremultiplied = bitmap.IsPremultiplied();
550 // retrieving bounds rectangle which has (0,0,w,h).
552 _GetBoundsRel(const _Canvas& canvas)
554 Rectangle rect = canvas.GetBounds();
563 _FillRectangleWithClip32(_Util::ScratchPad<unsigned long>* pScratchPad, unsigned long color, const _Util::Rectangle<int>& rect, const _Util::Rectangle<int>& clip)
565 _FillRectangleWithClip(pScratchPad, color, rect, clip);
568 struct _NativeGfxEngine
571 cairo_surface_t* pCairoSurface;
582 cairo_destroy(pCairo);
587 cairo_surface_destroy(pCairoSurface);
593 _Canvas::_Canvas(void)
594 : _pNativeGfxEngine(static_cast<void*>(new (std::nothrow)_NativeGfxEngine))
598 , __windowHandle(INVALID_HANDLE)
599 , __blendOption(Tizen::Graphics::_Canvas::BLEND_ALPHABLEND)
605 , __fgColor(0xFFFFFFFF)
606 , __bgColor(0x00000000)
610 , __lineStyle(LINE_STYLE_SOLID)
611 , __lineCapStyle(LINE_CAP_STYLE_ROUND)
612 , __lineJoinStyle(LINE_JOIN_STYLE_ROUND)
613 , __isClipBoundsSet(false)
614 , __textOrigin(TEXT_ORIGIN_LEFT_TOP)
616 , __bitmapDrawingQuality(BITMAP_DRAWING_QUALITY_LOW)
617 , __compositeMode(COMPOSITE_MODE_SRC_OVER)
618 , __useStableRenderer(false)
620 __fgColorNative = Color(__fgColor);
621 __bgColorNative = Color(__bgColor);
623 __dashData.offset = 0;
629 _Canvas::~_Canvas(void)
631 delete __pScratchPad;
634 if (_pNativeGfxEngine)
636 delete static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
641 _Canvas::Construct(void)
643 return this->Construct(Rectangle(0, 0, _Screen::GetWidth(), _Screen::GetHeight()));
647 _Canvas::Construct(const Rectangle& rect)
649 result r = E_SUCCESS;
651 _GenericBufferFrameBuffer<SystemPixel>* pTemp = new (std::nothrow) _GenericBufferFrameBuffer<SystemPixel>(rect.width, rect.height);
653 SysTryReturnResult(NID_GRP, pTemp, E_OUT_OF_MEMORY, " _GenericBufferFrameBuffer<> cannot be allocated.");
655 this->__pSurface = new (std::nothrow) _Util::GenericBuffer<SystemPixel>(pTemp);
657 SysTryCatch(NID_GRP, this->__pSurface, delete pTemp;
658 r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] _Util::GenericBuffer<> cannot be allocated.");
660 this->__pBuffer = (unsigned long*) __pSurface->GetBufferAddr();
661 this->__pScratchPad = new (std::nothrow) _Util::ScratchPad<SystemPixel>(__pBuffer, rect.width, rect.height, rect.width);
663 SysTryCatch(NID_GRP, this->__pScratchPad, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] _Util::ScratchPad<> cannot be allocated.");
665 this->__pScratchPad->FillRect(0, 0, this->__pScratchPad->GetWidth(), this->__pScratchPad->GetHeight(), 0x00000000);
667 this->__xBufferPos = rect.x;
668 this->__yBufferPos = rect.y;
670 #if defined(USE_CAIRO)
672 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
676 pCairo->pCairoSurface = cairo_image_surface_create_for_data((unsigned char*) this->__pBuffer, CAIRO_FORMAT_ARGB32, rect.width, rect.height, rect.width * 4);
677 pCairo->pCairo = cairo_create(pCairo->pCairoSurface);
682 __InitFgBgColorFromTheme();
687 delete this->__pScratchPad;
688 this->__pScratchPad = null;
690 delete this->__pSurface;
691 this->__pSurface = null;
697 _Canvas::Construct(Handle windowHandle)
699 return this->Construct(windowHandle, Rectangle(0, 0, _GetWindowWidth(windowHandle), _GetWindowHeight(windowHandle)));
703 _Canvas::Construct(Handle windowHandle, const Rectangle& rect)
705 SysTryReturnResult(NID_GRP, rect.width >= 0 && rect.height >= 0, E_OUT_OF_RANGE, "The given rectangle(width:%d,height:%d) is out of range.\n", rect.width, rect.height);
707 result r = E_SUCCESS;
711 int x2 = x1 + rect.width;
712 int y2 = y1 + rect.height;
724 if (x2 > _GetWindowWidth(windowHandle))
726 x2 = _GetWindowWidth(windowHandle);
729 if (y2 > _GetWindowHeight(windowHandle))
731 y2 = _GetWindowHeight(windowHandle);
734 SysTryReturnResult(NID_GRP, (x2 - x1 >= 0) && (y2 - y1 >= 0), E_OUT_OF_RANGE, "The given rectangle(x1:%d,y1:%d,x2:%d,y2:%d) is out of range.", x1, y1, x2, y2);
736 int bufferWidth = x2 - x1;
737 int bufferHeight = y2 - y1;
740 _GenericBufferFrameBuffer<SystemPixel>* pTemp = new (std::nothrow) _GenericBufferFrameBuffer<SystemPixel>(windowHandle, x1, y1, bufferWidth, bufferHeight, 0);
742 SysTryReturnResult(NID_GRP, pTemp, E_OUT_OF_MEMORY, "_GenericBufferFrameBuffer<> cannot be allocated.");
744 SysTryCatch(NID_GRP, !(pTemp->GetBufferAddr() == null && bufferWidth > 0 && bufferHeight > 0), delete pTemp; r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] The associated Evas buffer is NULL.");
746 this->__pSurface = new (std::nothrow) _Util::GenericBuffer<SystemPixel>(pTemp);
748 SysTryCatch(NID_GRP, this->__pSurface, delete pTemp; r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] _Util::GenericBuffer<> cannot be allocated.");
750 this->__pBuffer = (unsigned long*) __pSurface->GetBufferAddr();
751 sourcePitch = __pSurface->GetPitch();
753 this->__pScratchPad = new (std::nothrow) _Util::ScratchPad<SystemPixel>(__pBuffer, bufferWidth, bufferHeight, sourcePitch);
755 SysTryCatch(NID_GRP, this->__pScratchPad, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] _Util::ScratchPad<> cannot be allocated.");
757 this->__windowHandle = windowHandle;
759 this->__xBufferPos = x1;
760 this->__yBufferPos = y1;
762 #if defined(USE_CAIRO)
764 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
768 pCairo->pCairoSurface = cairo_image_surface_create_for_data((unsigned char*) this->__pBuffer, CAIRO_FORMAT_ARGB32, bufferWidth, bufferHeight, sourcePitch * 4);
769 pCairo->pCairo = cairo_create(pCairo->pCairoSurface);
774 __InitFgBgColorFromTheme();
779 delete this->__pScratchPad;
780 this->__pScratchPad = null;
782 delete this->__pSurface;
783 this->__pSurface = null;
789 _Canvas::Construct(_Canvas* pSourceCanvas, const Rectangle& subRegion)
791 SysTryReturnResult(NID_GRP, pSourceCanvas, E_INVALID_ARG, "The source canvas is invalid");
793 SysTryReturnResult(NID_GRP, pSourceCanvas->IsValid(), E_INVALID_ARG, "The source canvas is invalid");
795 result r = E_SUCCESS;
797 int x1 = subRegion.x;
798 int y1 = subRegion.y;
799 int x2 = x1 + subRegion.width;
800 int y2 = y1 + subRegion.height;
812 if (x2 > pSourceCanvas->GetBounds().width)
814 x2 = pSourceCanvas->GetBounds().width;
817 if (y2 > pSourceCanvas->GetBounds().height)
819 y2 = pSourceCanvas->GetBounds().height;
822 SysTryReturnResult(NID_GRP, (x2 - x1 > 0) && (y2 - y1 > 0), E_OUT_OF_RANGE, "The given rectangle(x1:%d,y1:%d,x2:%d,y2:%d) is out of range.", subRegion.x, subRegion.y, subRegion.width, subRegion.height);
824 int bufferWidth = x2 - x1;
825 int bufferHeight = y2 - y1;
827 int sourcePitch = pSourceCanvas->__pSurface->GetPitch();
829 if (pSourceCanvas->__windowHandle != INVALID_HANDLE)
831 _GenericBufferFrameBuffer<SystemPixel>* pTemp = new (std::nothrow) _GenericBufferFrameBuffer<SystemPixel>(pSourceCanvas->__windowHandle, x1, y1, bufferWidth, bufferHeight, sourcePitch);
833 SysTryReturnResult(NID_GRP, pTemp, E_OUT_OF_MEMORY, "_GenericBufferFrameBuffer<> cannot be allocated.");
835 if (pTemp->GetBufferAddr() == null && bufferWidth > 0 && bufferHeight > 0)
838 SysTryReturnResult(NID_GRP, false, E_SYSTEM, "The associated Evas buffer is NULL.");
841 this->__pSurface = new (std::nothrow) _Util::GenericBuffer<SystemPixel>(pTemp);
843 if (this->__pSurface == null)
846 SysTryReturnResult(NID_GRP, false, E_OUT_OF_MEMORY, "_Util::GenericBuffer<> cannot be allocated.");
851 SystemPixel* pBuffer = pSourceCanvas->__pSurface->GetBufferAddr();
852 pBuffer += y1 * sourcePitch + x1;
854 _GenericBufferFrameBuffer<SystemPixel>* pTemp = new (std::nothrow) _GenericBufferFrameBuffer<SystemPixel>(pBuffer, bufferWidth, bufferHeight, sourcePitch);
856 SysTryReturnResult(NID_GRP, pTemp, E_OUT_OF_MEMORY, "_GenericBufferFrameBuffer<> cannot be allocated.");
858 this->__pSurface = new (std::nothrow) _Util::GenericBuffer<SystemPixel>(pTemp);
860 if (this->__pSurface == null)
863 SysTryReturnResult(NID_GRP, false, E_OUT_OF_MEMORY, "_Util::GenericBuffer<> cannot be allocated.");
867 this->__pBuffer = (unsigned long*) __pSurface->GetBufferAddr();
868 this->__pScratchPad = new (std::nothrow) _Util::ScratchPad<SystemPixel>(__pBuffer, bufferWidth, bufferHeight, sourcePitch);
870 SysTryCatch(NID_GRP, this->__pScratchPad, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] _Util::ScratchPad<> cannot be allocated.");
872 this->__pParent = pSourceCanvas;
873 this->__xBufferPos = x1;
874 this->__yBufferPos = y1;
877 // must re-assign by _CanvasImpl::GetSubCanvasN()
878 this->__pFont = pSourceCanvas->__pFont;
880 this->__pPriorityFont = pSourceCanvas->__pPriorityFont;
883 this->__windowHandle = pSourceCanvas->__windowHandle;
884 this->__blendOption = pSourceCanvas->__blendOption;
885 this->__fgColor = pSourceCanvas->__fgColor;
886 this->__bgColor = pSourceCanvas->__bgColor;
887 this->__fgColorNative = pSourceCanvas->__fgColorNative;
888 this->__bgColorNative = pSourceCanvas->__bgColorNative;
889 this->__fgOpacity = pSourceCanvas->__fgOpacity;
890 this->__bgOpacity = pSourceCanvas->__bgOpacity;
891 this->__lineWidth = pSourceCanvas->__lineWidth;
892 this->__lineStyle = pSourceCanvas->__lineStyle;
895 this->__isClipBoundsSet = false;
896 this->__clipBounds = Rectangle(0, 0, bufferWidth, bufferHeight);
898 #if defined(USE_CAIRO)
900 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
904 pCairo->pCairoSurface = cairo_image_surface_create_for_data((unsigned char*) this->__pBuffer, CAIRO_FORMAT_ARGB32, bufferWidth, bufferHeight, sourcePitch * 4);
905 pCairo->pCairo = cairo_create(pCairo->pCairoSurface);
913 delete this->__pScratchPad;
914 this->__pScratchPad = null;
916 delete this->__pSurface;
917 this->__pSurface = null;
923 _Canvas::Construct(const BufferInfo& bufferInfo)
925 // all parameters checked
927 result r = E_SUCCESS;
929 _GenericBufferFrameBuffer<SystemPixel>* pTemp = new (std::nothrow) _GenericBufferFrameBuffer<SystemPixel>(static_cast<SystemPixel*>(bufferInfo.pPixels), bufferInfo.width, bufferInfo.height, bufferInfo.pitch * 8 / bufferInfo.bitsPerPixel);
931 SysTryReturnResult(NID_GRP
934 , " _GenericBufferFrameBuffer<> cannot be allocated.");
936 this->__pSurface = new (std::nothrow) _Util::GenericBuffer<SystemPixel>(pTemp);
940 , delete pTemp; r = E_OUT_OF_MEMORY
942 , "[E_OUT_OF_MEMORY] _Util::GenericBuffer<> cannot be allocated.");
944 this->__pBuffer = (unsigned long*) __pSurface->GetBufferAddr();
945 this->__pScratchPad = new (std::nothrow) _Util::ScratchPad<SystemPixel>(__pBuffer, bufferInfo.width, bufferInfo.height, bufferInfo.pitch * 8 / bufferInfo.bitsPerPixel);
948 , this->__pScratchPad
949 , r = E_OUT_OF_MEMORY
951 , "[E_OUT_OF_MEMORY] _Util::ScratchPad<> cannot be allocated.");
953 this->__xBufferPos = 0;
954 this->__yBufferPos = 0;
956 #if defined(USE_CAIRO)
958 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
962 pCairo->pCairoSurface = cairo_image_surface_create_for_data((unsigned char*) this->__pBuffer, CAIRO_FORMAT_ARGB32, bufferInfo.width, bufferInfo.height, bufferInfo.pitch);
963 pCairo->pCairo = cairo_create(pCairo->pCairoSurface);
968 __InitFgBgColorFromTheme();
973 delete this->__pScratchPad;
974 this->__pScratchPad = null;
976 delete this->__pSurface;
977 this->__pSurface = null;
983 _Canvas::IsValid() const
985 return (this && this->__pSurface);
991 if (this->__isClipBoundsSet)
993 _Util::Rectangle<int> clip =
995 this->__clipBounds.x,
996 this->__clipBounds.y,
997 this->__clipBounds.width,
998 this->__clipBounds.height
1001 _Util::Rectangle<int> rect =
1005 __pScratchPad->GetWidth(),
1006 __pScratchPad->GetHeight()
1009 _ClearRectangleWithClip(__pScratchPad, __bgColor, rect, clip);
1013 __pScratchPad->FillRect(0, 0, __pScratchPad->GetWidth(), __pScratchPad->GetHeight(), __bgColor);
1020 _Canvas::Clear(const Rectangle& rect)
1022 if ((rect.width == 0) || (rect.height == 0))
1027 if (this->__isClipBoundsSet)
1029 _Util::Rectangle<int> clip =
1031 this->__clipBounds.x,
1032 this->__clipBounds.y,
1033 this->__clipBounds.width,
1034 this->__clipBounds.height
1037 _Util::Rectangle<int> rect1 =
1045 _ClearRectangleWithClip(__pScratchPad, __bgColor, rect1, clip);
1049 __pScratchPad->FillRect(rect.x, rect.y, rect.width, rect.height, __bgColor);
1056 _Canvas::Copy(const Point& destPoint, const _Canvas& canvas, const Rectangle& srcRect)
1059 if (srcRect.width == 0 || srcRect.height == 0)
1064 return this->__Copy(destPoint, canvas, srcRect);
1068 _Canvas::Copy(const Rectangle& destRect, const _Canvas& canvas, const Rectangle& srcRect)
1071 if (srcRect.width == 0 || srcRect.height == 0 || destRect.width == 0 || destRect.height == 0)
1076 return this->__Copy(destRect, canvas, srcRect);
1080 _Canvas::Copy(const Point& destPoint, const _Canvas& canvas, const Rectangle& srcRect, CompositeMode compositeMode)
1082 _Util::LockManager srcLock(canvas);
1083 _Util::LockManager dstLock(*this);
1085 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source canvas cannot be locked.");
1086 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked");
1088 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1089 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1092 _Util::Pixmap srcImageUnclipped(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1093 _Util::Pixmap srcImage = srcImageUnclipped.GetSubBitmap(srcRect.x, srcRect.y, srcRect.width, srcRect.height);
1095 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1096 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(destPoint.x, destPoint.y, srcRect.width, srcRect.height);
1098 _Pixman::CopyPixmap(dstImage, srcImage, GetDrawingQuality(), compositeMode);
1105 _Canvas::CopyReverse(const Point& destPoint, const _Canvas& srcCanvas, const Rectangle& srcRect)
1108 if (srcRect.width == 0 || srcRect.height == 0)
1113 if (__pScratchPad == null)
1118 const _Canvas* pSrcCanvas = &srcCanvas;
1120 if (pSrcCanvas == null)
1125 if (pSrcCanvas->__pScratchPad == null)
1130 Rectangle clippedSrcRect(srcRect);
1132 if (_ClipRectangle(clippedSrcRect.x, clippedSrcRect.y, clippedSrcRect.width, clippedSrcRect.height, 0, 0, pSrcCanvas->__pScratchPad->GetWidth(), pSrcCanvas->__pScratchPad->GetHeight()) == CLIP_REJECT)
1137 __pScratchPad->RegisterBitBlt(_RasterOp::FnBitBlt32BitCopyReverse);
1138 __pScratchPad->BitBlt(destPoint.x, destPoint.y, pSrcCanvas->__pScratchPad, clippedSrcRect.x, clippedSrcRect.y, clippedSrcRect.width, clippedSrcRect.height);
1139 __pScratchPad->RegisterBitBlt(null);
1147 // spec. from SDK 1.0
1149 template<typename T>
1151 _ReviseAngle(T& startAngle, T& endAngle)
1157 // startAngle = startAngle % twoPi;
1158 int mod = int(startAngle / twoPi);
1159 startAngle = startAngle - twoPi * mod;
1161 //endAngle = endAngle % twoPi;
1162 mod = int(endAngle / twoPi);
1163 endAngle = endAngle - twoPi * mod;
1166 if (startAngle < zeroPi || endAngle < zeroPi)
1168 startAngle += twoPi;
1172 if (startAngle > endAngle)
1181 _Canvas::DrawArc(const _Util::Rectangle<double>& bounds, double startAngle, double endAngle, ArcStyle arcStyle)
1183 if ((bounds.w <= 0.0) || (bounds.h <= 0.0))
1188 // this->__lineWidth is always greater than 0
1190 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
1192 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
1194 if (pCairo && pCairo->pCairo)
1196 SET_CAIRO_ALL_PROPERTIES;
1198 double startDstAngle = (180.0 / M_PI) * atan2(sin(startAngle*M_PI / 180.0) * bounds.w / bounds.h, cos(startAngle * M_PI / 180.0));
1199 double endDstAngle = (180.0 / M_PI) * atan2(sin(endAngle * M_PI / 180.0) * bounds.w / bounds.h, cos(endAngle * M_PI / 180.0));
1201 startDstAngle += (abs(startAngle - startDstAngle) <= 90.0) ? 0.0 : (startDstAngle < 0.0 && startAngle >= 0.0) ? 360.0 : (startDstAngle >= 0.0 && startAngle < 0.0) ? -360.0 : 0.0;
1202 endDstAngle += (abs(endAngle - endDstAngle) <= 90.0) ? 0.0 : (endDstAngle < 0.0 && endAngle >= 0.0) ? 360.0 : (endDstAngle >= 0.0 && endAngle < 0.0) ? -360.0 : 0.0;
1204 _ReviseAngle(startDstAngle, endDstAngle);
1208 case ARC_STYLE_ONLY:
1209 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
1211 _Cairo::DrawArc(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::DRAW_ARC_STYLE_ARC);
1215 _Cairo::DrawArc(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::DRAW_ARC_STYLE_ARC);
1220 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
1222 _Cairo::DrawArc(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::DRAW_ARC_STYLE_PIE);
1226 _Cairo::DrawArc(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::DRAW_ARC_STYLE_PIE);
1230 case ARC_STYLE_CHORD:
1231 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
1233 _Cairo::DrawArc(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::DRAW_ARC_STYLE_CHORD);
1237 _Cairo::DrawArc(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::DRAW_ARC_STYLE_CHORD);
1241 case ARC_STYLE_FILLED_PIE:
1242 _Cairo::FillArc(pCairo->pCairo, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::FILL_ARC_STYLE_PIE);
1245 case ARC_STYLE_FILLED_CHORD:
1246 _Cairo::FillArc(pCairo->pCairo, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::FILL_ARC_STYLE_CHORD);
1253 RESET_CAIRO_ALL_PROPERTIES;
1262 memset(&info, 0, sizeof(info));
1264 SystemPixel* pBufferAddr = null;
1265 int bufferPitch = 0;
1267 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
1269 info.width = __pScratchPad->GetWidth();
1270 info.height = __pScratchPad->GetHeight();
1271 info.bitsPerPixel = 32;
1272 info.pixelPerLine = bufferPitch;
1273 info.pPixels = (void*) pBufferAddr;
1274 info.color32 = composedColor;
1275 info.isClipBoundsSet = this->__isClipBoundsSet;
1276 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
1278 arc.SetLineWidth(this->__lineWidth.asInteger);
1280 _ReviseAngle(startAngle, endAngle);
1282 return arc.DrawArc(int(bounds.x), int(bounds.y), int(bounds.w), int(bounds.h), int(startAngle), int(endAngle), arcStyle, info);
1287 _Canvas::DrawBitmap(const _Util::Rectangle<double>& rectD, const _Bitmap& bitmap)
1289 SysTryReturnResult(NID_GRP, &bitmap && bitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
1291 if (rectD.w <= 0 || rectD.h <= 0)
1296 int alphaConstant = this->_GetAlphaAttenuation(bitmap);
1300 this->__GetClipBounds(clipRect);
1302 _Util::Rectangle<int> rect =
1304 _DoubleToIntForPos(rectD.x),
1305 _DoubleToIntForPos(rectD.y),
1306 _DoubleToIntForSize(rectD.w),
1307 _DoubleToIntForSize(rectD.h)
1310 if (alphaConstant >= 255)
1314 _Util::LockManager srcLock(bitmap);
1315 _Util::LockManager dstLock(*this);
1317 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1318 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1320 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1321 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1324 if (!this->__useStableRenderer && srcBufferInfo.bitsPerPixel == 32)
1326 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1327 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1329 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1330 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1332 pass = _Pixman::ScalePixmap(dstImage, srcImage, GetDrawingQuality(), GetCompositeMode(), rectD.x - clipRect.x, rectD.y - clipRect.y, rectD.w, rectD.h);
1338 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1339 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1341 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1342 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1344 pass = Tizen::Graphics::_Effect::ScaleImage(dstImage, rect.x - clipRect.x, rect.y - clipRect.y, rect.w, rect.h, srcImage, _ConvertParam<_Effect::Rop>(this->__blendOption));
1349 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1355 _Util::Pixmap tmpImage(rect.w, rect.h, bitmap.GetBitsPerPixel());
1357 // copies the source bitmap to the scaled bitmap
1359 // ykahn, 2011/10/11 patched
1361 _ApplySrcBitmapAttrib(tmpImage, bitmap, bitmap.__isOpaqueAllOver);
1363 if (tmpImage.depth == 16)
1365 if (tmpImage.enableColorKey)
1367 typedef unsigned short Pixel;
1369 Pixel colorKey = (Pixel) tmpImage.colorKey;
1370 Pixel* pDest = (Pixel*) tmpImage.pBitmap;
1371 Pixel* pDestEnd = pDest + (tmpImage.bytesPerLine * tmpImage.height / (tmpImage.depth / 8));
1373 while (pDest < pDestEnd)
1375 *pDest++ = colorKey;
1383 else if (tmpImage.depth == 32)
1385 typedef unsigned long Pixel;
1387 Pixel fillColor = 0;
1388 Pixel* pDest = (Pixel*) tmpImage.pBitmap;
1389 Pixel* pDestEnd = pDest + (tmpImage.bytesPerLine * tmpImage.height / (tmpImage.depth / 8));
1391 while (pDest < pDestEnd)
1393 *pDest++ = fillColor;
1401 _Util::LockManager srcLock(bitmap);
1402 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1404 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1407 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1408 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1410 pass = Tizen::Graphics::_Effect::ScaleImage(tmpImage, 0, 0, rect.w, rect.h, srcImage, Tizen::Graphics::_Effect::ROP_COPY);
1414 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1421 _Util::LockManager dstLock(*this);
1422 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1424 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1427 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1428 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1430 pass = Tizen::Graphics::_Effect::DrawImageWithAlpha(dstImage, rect.x - clipRect.x, rect.y - clipRect.y, tmpImage, alphaConstant);
1434 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1442 _Canvas::DrawBitmap(const _Util::Point<double>& pointD, const _Bitmap& bitmap)
1444 SysTryReturnResult(NID_GRP, &bitmap && bitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
1446 int alphaConstant = this->_GetAlphaAttenuation(bitmap);
1451 this->__GetClipBounds(clipRect);
1456 _Util::Point<int> point =
1458 _DoubleToIntForPos(pointD.x),
1459 _DoubleToIntForPos(pointD.y)
1462 _Util::LockManager srcLock(bitmap);
1463 _Util::LockManager dstLock(*this);
1465 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1466 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1468 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1469 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1472 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1473 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1475 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1476 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1478 if (srcBufferInfo.pixelFormat == PIXEL_FORMAT_RGB565 && srcImage.enableColorKey == 0 && dstBufferInfo.pixelFormat == PIXEL_FORMAT_ARGB8888 && !this->__isClipBoundsSet)
1480 pixman_image_t* pPixmanSrc = pixman_image_create_bits(PIXMAN_r5g6b5, srcBufferInfo.width, srcBufferInfo.height, (uint32_t*)srcBufferInfo.pPixels, srcBufferInfo.pitch);
1481 pixman_image_t* pPixmanDst = pixman_image_create_bits(PIXMAN_a8r8g8b8, dstBufferInfo.width, dstBufferInfo.height, (uint32_t*)dstBufferInfo.pPixels, dstBufferInfo.pitch);
1483 if (pPixmanSrc && pPixmanDst)
1485 pixman_image_composite32(PIXMAN_OP_SRC, pPixmanSrc, NULL, pPixmanDst, 0, 0, 0, 0, point.x, point.y, srcBufferInfo.width, srcBufferInfo.height);
1491 pixman_image_unref(pPixmanDst);
1496 pixman_image_unref(pPixmanSrc);
1501 bool isPixmanSupported = (!this->__useStableRenderer) && (alphaConstant >= 255);
1503 if (isPixmanSupported)
1507 isPixmanSupported = !((bitmap.GetBitsPerPixel() == 16) && (bitmap.GetMaskingColor(color) == E_SUCCESS));
1510 if (isPixmanSupported)
1512 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1513 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1515 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1516 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1518 pass = _Pixman::CopyPixmap(dstImage, srcImage, GetDrawingQuality(), GetCompositeMode(), pointD.x - clipRect.x, pointD.y - clipRect.y);
1523 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1524 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1526 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1527 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1529 pass = Tizen::Graphics::_Effect::DrawImageWithAlpha(dstImage, point.x - clipRect.x, point.y - clipRect.y, srcImage, alphaConstant);
1534 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1541 _Canvas::DrawBitmap(const Rectangle& destRect, const _Bitmap& srcBitmap, const Rectangle& srcRect)
1543 SysTryReturnResult(NID_GRP, &srcBitmap && srcBitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
1545 if (srcRect.width == 0 || srcRect.height == 0)
1550 if (destRect.width == 0 || destRect.height == 0)
1555 int alphaConstant = this->_GetAlphaAttenuation(srcBitmap);
1559 this->__GetClipBounds(clipRect);
1561 if (alphaConstant >= 255)
1565 _Util::LockManager srcLock(srcBitmap);
1566 _Util::LockManager dstLock(*this);
1568 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1569 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1571 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1572 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1575 if (!this->__useStableRenderer && srcBufferInfo.bitsPerPixel == 32)
1577 _Util::Rectangle<int> outRect = { 0, 0, -1, -1 };
1578 _Util::Rectangle<int> dstRect = { destRect.x, destRect.y, destRect.width, destRect.height };
1579 _Util::Rectangle<int> tgtRect = { clipRect.x, clipRect.y, clipRect.width, clipRect.height };
1581 _Util::IntersectRect(outRect, tgtRect, dstRect);
1583 // assert(destRect.width > 0 && destRect.height > 0);
1585 _Util::Bounds<int> outBounds = { outRect.x, outRect.y, outRect.x + outRect.w, outRect.y + outRect.h };
1586 _Util::Bounds<int> dstBounds = { dstRect.x, dstRect.y, dstRect.x + dstRect.w, dstRect.y + dstRect.h };
1587 _Util::Bounds<int> srcBounds =
1589 srcRect.x + (outBounds.x1 - dstBounds.x1) * srcRect.width / (dstBounds.x2 - dstBounds.x1),
1590 srcRect.y + (outBounds.y1 - dstBounds.y1) * srcRect.height / (dstBounds.y2 - dstBounds.y1),
1591 (srcRect.x + srcRect.width) + (outBounds.x2 - dstBounds.x2) * srcRect.width / (dstBounds.x2 - dstBounds.x1),
1592 (srcRect.y + srcRect.height) + (outBounds.y2 - dstBounds.y2) * srcRect.height / (dstBounds.y2 - dstBounds.y1),
1595 srcBounds.x1 = (srcBounds.x1 >= srcRect.x) ? srcBounds.x1 : srcRect.x;
1596 srcBounds.y1 = (srcBounds.y1 >= srcRect.y) ? srcBounds.y1 : srcRect.y;
1597 srcBounds.x2 = (srcBounds.x2 <= (srcRect.x + srcRect.width)) ? srcBounds.x2 : (srcRect.x + srcRect.width);
1598 srcBounds.y2 = (srcBounds.y2 <= (srcRect.y + srcRect.height)) ? srcBounds.y2 : (srcRect.y + srcRect.height);
1600 _Util::Pixmap srcImageUnclipped(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1601 _Util::Pixmap srcImage = srcImageUnclipped.GetSubBitmap(srcBounds.x1, srcBounds.y1, srcBounds.x2 - srcBounds.x1, srcBounds.y2 - srcBounds.y1);
1602 _ApplySrcBitmapAttrib(srcImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
1604 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1605 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(outRect.x, outRect.y, outRect.w, outRect.h);
1607 pass = _Pixman::ScalePixmap(dstImage, srcImage, GetDrawingQuality(), GetCompositeMode());
1612 unsigned char* pPixels = (unsigned char*) srcBufferInfo.pPixels + srcRect.y * srcBufferInfo.pitch + srcRect.x * (srcBufferInfo.bitsPerPixel / 8);
1614 _Util::Pixmap srcImage(srcRect.width, srcRect.height, srcBufferInfo.bitsPerPixel, (void*) pPixels, srcBufferInfo.pitch);
1615 _ApplySrcBitmapAttrib(srcImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
1617 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1618 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1620 pass = Tizen::Graphics::_Effect::ScaleImage(dstImage, destRect.x - clipRect.x, destRect.y - clipRect.y, destRect.width, destRect.height, srcImage, _ConvertParam<_Effect::Rop>(this->__blendOption));
1625 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1631 _Util::Pixmap tmpImage(destRect.width, destRect.height, srcBitmap.GetBitsPerPixel());
1633 // copies the source bitmap to the scaled bitmap
1635 // ykahn, 2011/10/11 patched
1637 _ApplySrcBitmapAttrib(tmpImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
1639 if (tmpImage.depth == 16)
1641 if (tmpImage.enableColorKey)
1643 typedef unsigned short Pixel;
1645 Pixel colorKey = (Pixel) tmpImage.colorKey;
1646 Pixel* pDest = (Pixel*) tmpImage.pBitmap;
1647 Pixel* pDestEnd = pDest + (tmpImage.bytesPerLine * tmpImage.height / (tmpImage.depth / 8));
1649 while (pDest < pDestEnd)
1651 *pDest++ = colorKey;
1658 else if (tmpImage.depth == 32)
1660 typedef unsigned long Pixel;
1662 Pixel fillColor = 0;
1663 Pixel* pDest = (Pixel*) tmpImage.pBitmap;
1664 Pixel* pDestEnd = pDest + (tmpImage.bytesPerLine * tmpImage.height / (tmpImage.depth / 8));
1666 while (pDest < pDestEnd)
1668 *pDest++ = fillColor;
1676 _Util::LockManager srcLock(srcBitmap);
1677 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1679 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1682 unsigned char* pPixels = (unsigned char*) srcBufferInfo.pPixels + srcRect.y * srcBufferInfo.pitch + srcRect.x * (srcBufferInfo.bitsPerPixel / 8);
1684 _Util::Pixmap srcImage(srcRect.width, srcRect.height, srcBufferInfo.bitsPerPixel, (void*) pPixels, srcBufferInfo.pitch);
1685 _ApplySrcBitmapAttrib(srcImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
1687 pass = Tizen::Graphics::_Effect::ScaleImage(tmpImage, 0, 0, destRect.width, destRect.height, srcImage, Tizen::Graphics::_Effect::ROP_COPY);
1691 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1698 _Util::LockManager dstLock(*this);
1699 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1701 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1704 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1705 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1707 pass = Tizen::Graphics::_Effect::DrawImageWithAlpha(dstImage, destRect.x - clipRect.x, destRect.y - clipRect.y, tmpImage, alphaConstant);
1711 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1719 _Canvas::DrawBitmapForNinePatchedBitmap(const Rectangle& destRect, const _Bitmap& srcBitmap, const Rectangle& srcRect)
1721 SysTryReturnResult(NID_GRP, &srcBitmap && srcBitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
1723 if (srcRect.width == 0 || srcRect.height == 0)
1728 if (destRect.width == 0 || destRect.height == 0)
1733 int alphaConstant = this->_GetAlphaAttenuation(srcBitmap);
1737 this->__GetClipBounds(clipRect);
1739 if (alphaConstant >= 255)
1743 _Util::LockManager srcLock(srcBitmap);
1744 _Util::LockManager dstLock(*this);
1746 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1747 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1749 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1750 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1753 if (srcBufferInfo.bitsPerPixel == 32)
1755 _Util::Rectangle<int> outRect = { 0, 0, -1, -1 };
1756 _Util::Rectangle<int> dstRect = { destRect.x, destRect.y, destRect.width, destRect.height };
1757 _Util::Rectangle<int> tgtRect = { clipRect.x, clipRect.y, clipRect.width, clipRect.height };
1759 _Util::IntersectRect(outRect, tgtRect, dstRect);
1761 // assert(destRect.width > 0 && destRect.height > 0);
1763 _Util::Bounds<int> outBounds = { outRect.x, outRect.y, outRect.x + outRect.w, outRect.y + outRect.h };
1764 _Util::Bounds<int> dstBounds = { dstRect.x, dstRect.y, dstRect.x + dstRect.w, dstRect.y + dstRect.h };
1765 _Util::Bounds<int> srcBounds =
1767 srcRect.x + (outBounds.x1 - dstBounds.x1) * srcRect.width / (dstBounds.x2 - dstBounds.x1),
1768 srcRect.y + (outBounds.y1 - dstBounds.y1) * srcRect.height / (dstBounds.y2 - dstBounds.y1),
1769 (srcRect.x + srcRect.width) + (outBounds.x2 - dstBounds.x2) * srcRect.width / (dstBounds.x2 - dstBounds.x1),
1770 (srcRect.y + srcRect.height) + (outBounds.y2 - dstBounds.y2) * srcRect.height / (dstBounds.y2 - dstBounds.y1),
1773 srcBounds.x1 = (srcBounds.x1 >= srcRect.x) ? srcBounds.x1 : srcRect.x;
1774 srcBounds.y1 = (srcBounds.y1 >= srcRect.y) ? srcBounds.y1 : srcRect.y;
1775 srcBounds.x2 = (srcBounds.x2 <= (srcRect.x + srcRect.width)) ? srcBounds.x2 : (srcRect.x + srcRect.width);
1776 srcBounds.y2 = (srcBounds.y2 <= (srcRect.y + srcRect.height)) ? srcBounds.y2 : (srcRect.y + srcRect.height);
1778 _Util::Pixmap srcImageUnclipped(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1779 _Util::Pixmap srcImage = srcImageUnclipped.GetSubBitmap(srcBounds.x1, srcBounds.y1, srcBounds.x2 - srcBounds.x1, srcBounds.y2 - srcBounds.y1);
1780 _ApplySrcBitmapAttrib(srcImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
1782 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1783 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(outRect.x, outRect.y, outRect.w, outRect.h);
1785 pass = _Pixman::ScalePixmap(dstImage, srcImage, GetDrawingQuality(), GetCompositeMode());
1790 unsigned char* pPixels = (unsigned char*) srcBufferInfo.pPixels + srcRect.y * srcBufferInfo.pitch + srcRect.x * (srcBufferInfo.bitsPerPixel / 8);
1792 _Util::Pixmap srcImage(srcRect.width, srcRect.height, srcBufferInfo.bitsPerPixel, (void*) pPixels, srcBufferInfo.pitch);
1793 _ApplySrcBitmapAttrib(srcImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
1795 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1796 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1798 pass = Tizen::Graphics::_Effect::ScaleImage(dstImage, destRect.x - clipRect.x, destRect.y - clipRect.y, destRect.width, destRect.height, srcImage, _ConvertParam<_Effect::Rop>(this->__blendOption));
1803 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1809 _Util::Pixmap tmpImage(destRect.width, destRect.height, srcBitmap.GetBitsPerPixel());
1811 // copies the source bitmap to the scaled bitmap
1813 // ykahn, 2011/10/11 patched
1815 _ApplySrcBitmapAttrib(tmpImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
1817 if (tmpImage.depth == 16)
1819 if (tmpImage.enableColorKey)
1821 typedef unsigned short Pixel;
1823 Pixel colorKey = (Pixel) tmpImage.colorKey;
1824 Pixel* pDest = (Pixel*) tmpImage.pBitmap;
1825 Pixel* pDestEnd = pDest + (tmpImage.bytesPerLine * tmpImage.height / (tmpImage.depth / 8));
1827 while (pDest < pDestEnd)
1829 *pDest++ = colorKey;
1836 else if (tmpImage.depth == 32)
1838 typedef unsigned long Pixel;
1840 Pixel fillColor = 0;
1841 Pixel* pDest = (Pixel*) tmpImage.pBitmap;
1842 Pixel* pDestEnd = pDest + (tmpImage.bytesPerLine * tmpImage.height / (tmpImage.depth / 8));
1844 while (pDest < pDestEnd)
1846 *pDest++ = fillColor;
1854 _Util::LockManager srcLock(srcBitmap);
1855 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1857 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1860 unsigned char* pPixels = (unsigned char*) srcBufferInfo.pPixels + srcRect.y * srcBufferInfo.pitch + srcRect.x * (srcBufferInfo.bitsPerPixel / 8);
1862 _Util::Pixmap srcImage(srcRect.width, srcRect.height, srcBufferInfo.bitsPerPixel, (void*) pPixels, srcBufferInfo.pitch);
1863 _ApplySrcBitmapAttrib(srcImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
1865 pass = Tizen::Graphics::_Effect::ScaleImage(tmpImage, 0, 0, destRect.width, destRect.height, srcImage, Tizen::Graphics::_Effect::ROP_COPY);
1869 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1876 _Util::LockManager dstLock(*this);
1877 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1879 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1882 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1883 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1885 pass = Tizen::Graphics::_Effect::DrawImageWithAlpha(dstImage, destRect.x - clipRect.x, destRect.y - clipRect.y, tmpImage, alphaConstant);
1889 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1897 _Canvas::DrawBitmap(const Point& point, const _Bitmap& bitmap, FlipDirection dir)
1899 SysTryReturnResult(NID_GRP, &bitmap && bitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
1901 int alphaConstant = this->_GetAlphaAttenuation(bitmap);
1905 this->__GetClipBounds(clipRect);
1908 _Util::Pixmap* pFlippedImage = 0;
1911 _Util::LockManager srcLock(bitmap);
1912 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1914 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1916 Tizen::Graphics::_Effect::Flip flip = (dir == FLIP_DIRECTION_HORIZONTAL) ? Tizen::Graphics::_Effect::FLIP_HORIZONTAL : Tizen::Graphics::_Effect::FLIP_VERTICAL;
1919 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1921 pFlippedImage = Tizen::Graphics::_Effect::GetFlippedImage(srcImage, flip);
1925 SysTryReturnResult(NID_GRP, pFlippedImage, E_INVALID_ARG, "The source bitmap is invalid.\n");
1927 _ApplySrcBitmapAttrib(*pFlippedImage, bitmap, bitmap.__isOpaqueAllOver);
1929 std::auto_ptr<_Util::Pixmap> autoReleasingImage(pFlippedImage);
1934 if (!this->__useStableRenderer && alphaConstant >= 255 && !bitmap.__hasMaskingColor)
1936 _Util::LockManager dstLock(*this);
1937 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.");
1939 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1942 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1943 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1945 pass = _Pixman::FlipPixmap(dstImage, *pFlippedImage, GetDrawingQuality(), GetCompositeMode(), point.x - clipRect.x, point.y - clipRect.y);
1951 _Util::LockManager dstLock(*this);
1952 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1954 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1957 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1958 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1960 pass = Tizen::Graphics::_Effect::DrawImageWithAlpha(dstImage, point.x - clipRect.x, point.y - clipRect.y, *pFlippedImage, alphaConstant);
1964 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1972 _Canvas::DrawBitmap(const _Util::Point<double>& pointD, const _Bitmap& bitmap, const _Util::Point<double>& pivotD, double degreeD)
1974 SysTryReturnResult(NID_GRP, &bitmap && bitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
1978 this->__GetClipBounds(clipRect);
1980 int alphaConstant = this->_GetAlphaAttenuation(bitmap);
1982 if (alphaConstant >= 255 && !bitmap.__hasMaskingColor)
1986 _Util::LockManager srcLock(bitmap);
1987 _Util::LockManager dstLock(*this);
1989 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.");
1990 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.");
1992 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1993 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1995 if (!this->__useStableRenderer)
1997 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1998 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
2000 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
2001 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
2003 pass = _Pixman::RotatePixmap(dstImage, srcImage, GetDrawingQuality(), GetCompositeMode(), pointD.x - clipRect.x, pointD.y - clipRect.y, degreeD, pivotD.x, pivotD.y);
2013 if (alphaConstant >= 255)
2015 return pCanvasInterface->DrawBitmap(point.x, point.y, *((IBitmapPi*)*(IBitmapPi**)bitmap.__pImpl), pivot.x, pivot.y, degree);
2020 _Util::LockManager srcLock(bitmap);
2021 _Util::LockManager dstLock(*this);
2023 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
2024 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
2026 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
2027 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
2029 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
2030 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
2031 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
2033 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
2035 _Util::Point<int> point =
2037 _DoubleToIntForPos(pointD.x),
2038 _DoubleToIntForPos(pointD.y)
2041 Tizen::Graphics::_Effect::RotateDesc rotateDesc = { _DoubleToIntForRound(degreeD), _DoubleToIntForPos(pivotD.x), _DoubleToIntForPos(pivotD.y) };
2043 bool pass = Tizen::Graphics::_Effect::RotateImage(dstImage, point.x - clipRect.x, point.y - clipRect.y, srcImage, rotateDesc, alphaConstant);
2045 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
2052 _Canvas::DrawNinePatchedBitmap(const Rectangle& rect, const _Bitmap& bitmap)
2054 SysTryReturnResult(NID_GRP, &bitmap && bitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
2056 // down-scales the source bitmap
2057 if (rect.width < bitmap.GetWidth() - 2 || rect.height < bitmap.GetHeight() - 2)
2060 int dstW = rect.width;
2061 int dstH = rect.height;
2062 int srcW = bitmap.GetWidth() - 2;
2063 int srcH = bitmap.GetHeight() - 2;
2065 if (dstW <= 0 || dstH <= 0)
2070 if (dstW * srcH < dstH * srcW)
2074 dstH = dstH * srcW / dstW;
2079 dstW = dstW * srcH / dstH;
2086 const int PADDING = 1;
2088 _Bitmap expandedBitmap;
2090 r = expandedBitmap.Construct(Dimension(dstW + PADDING * 2, dstH + PADDING * 2), BITMAP_PIXEL_FORMAT_ARGB8888);
2092 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2094 _Util::LockManager dstBitmap(expandedBitmap);
2097 const BufferInfo& dstBufferInfo = dstBitmap.GetBufferInfo();
2099 memset(dstBufferInfo.pPixels, 0, dstBufferInfo.pitch * dstBufferInfo.height);
2101 _Canvas expandedCanvas;
2103 r = expandedCanvas.Construct(dstBufferInfo);
2105 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2107 expandedCanvas.SetDrawingQuality(BITMAP_DRAWING_QUALITY_HIGH);
2108 expandedCanvas.SetCompositeMode(COMPOSITE_MODE_SRC);
2110 _Util::Pixmap dstImage(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, (void*) dstBufferInfo.pPixels, dstBufferInfo.pitch);
2112 _Util::AccumList<_Util::Pair<_Util::Rectangle<int>, _Util::Rectangle<int> > > boundsList;
2114 r = _Util::GetPatchList(boundsList, Rectangle(PADDING, PADDING, dstBufferInfo.width - PADDING * 2, dstBufferInfo.height - PADDING * 2), bitmap);
2116 SysTryReturn(NID_GRP, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] _Util::GetPatchList() failed (error = %#x)", r);
2118 _Util::AccumList<_Util::Pair<_Util::Rectangle<int>, _Util::Rectangle<int> > >::Iterator iter = boundsList.Begin();
2120 int alphaConstant = bitmap.GetAlphaConstant();
2121 const_cast<_Bitmap*>(&bitmap)->SetAlphaConstant(255);
2123 while (iter != boundsList.End())
2125 Rectangle destRect(iter->first.x, iter->first.y, iter->first.w, iter->first.h);
2126 Rectangle sourRect(iter->second.x, iter->second.y, iter->second.w, iter->second.h);
2128 expandedCanvas.DrawBitmapForNinePatchedBitmap(destRect, bitmap, sourRect);
2133 const_cast<_Bitmap*>(&bitmap)->SetAlphaConstant(alphaConstant);
2134 expandedBitmap.SetAlphaConstant(alphaConstant);
2137 // not <- PADDING * 2>
2138 Tizen::Graphics::Rectangle srcRect(PADDING, PADDING, expandedBitmap.GetWidth() - PADDING, expandedBitmap.GetHeight() - PADDING);
2140 return this->DrawBitmap(rect, expandedBitmap, srcRect);
2144 Tizen::Graphics::Rectangle srcRect(1, 1, bitmap.GetWidth() - 2, bitmap.GetHeight() - 2);
2146 return this->DrawBitmap(rect, bitmap, srcRect);
2150 _Util::AccumList<_Util::Pair<_Util::Rectangle<int>, _Util::Rectangle<int> > > boundsList;
2152 result r = _Util::GetPatchList(boundsList, rect, bitmap);
2156 _Util::AccumList<_Util::Pair<_Util::Rectangle<int>, _Util::Rectangle<int> > >::Iterator iter = boundsList.Begin();
2158 while (iter != boundsList.End())
2160 Rectangle destRect(iter->first.x, iter->first.y, iter->first.w, iter->first.h);
2161 Rectangle sourRect(iter->second.x, iter->second.y, iter->second.w, iter->second.h);
2163 DrawBitmapForNinePatchedBitmap(destRect, bitmap, sourRect);
2173 _Canvas::DrawNineTiledBitmap(const Rectangle& rect, const _Bitmap& bitmap)
2175 SysTryReturnResult(NID_GRP, &bitmap && bitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
2177 // down-scales the source bitmap
2178 if (rect.width < bitmap.GetWidth() - 2 || rect.height < bitmap.GetHeight() - 2)
2180 return this->DrawNinePatchedBitmap(rect, bitmap);
2183 _Util::AccumList<_Util::Pair<_Util::Rectangle<int>, _Util::Rectangle<int> > > boundsList;
2185 result r = _Util::GetPatchList(boundsList, rect, bitmap);
2189 // This block is slow and not optimized.
2190 _Util::AccumList<_Util::Pair<_Util::Rectangle<int>, _Util::Rectangle<int> > >::Iterator iter = boundsList.Begin();
2192 while (iter != boundsList.End())
2194 Rectangle destRect(iter->first.x, iter->first.y, iter->first.w, iter->first.h);
2195 Rectangle sourRect(iter->second.x, iter->second.y, iter->second.w, iter->second.h);
2197 if (iter->first.w == iter->second.w && iter->first.h == iter->second.h)
2199 DrawBitmapForNinePatchedBitmap(destRect, bitmap, sourRect);
2203 for (int y = iter->first.y; y < iter->first.y + iter->first.h; y += iter->second.h)
2205 if (y + iter->second.h <= iter->first.y + iter->first.h)
2207 for (int x = iter->first.x; x < iter->first.x + iter->first.w; x += iter->second.w)
2209 if (x + iter->second.w <= iter->first.x + iter->first.w)
2211 Rectangle destRect(x, y, iter->second.w, iter->second.h);
2212 DrawBitmapForNinePatchedBitmap(destRect, bitmap, sourRect);
2216 // right side clipping
2217 int w = iter->first.x + iter->first.w - x;
2219 Rectangle destRect(x, y, w, iter->second.h);
2220 Rectangle sourRect(iter->second.x, iter->second.y, w, iter->second.h);
2222 DrawBitmapForNinePatchedBitmap(destRect, bitmap, sourRect);
2228 // bottom side clipping
2229 int h = iter->first.y + iter->first.h - y;
2231 for (int x = iter->first.x; x < iter->first.x + iter->first.w; x += iter->second.w)
2233 if (x + iter->second.w <= iter->first.x + iter->first.w)
2235 Rectangle destRect(x, y, iter->second.w, h);
2236 Rectangle sourRect(iter->second.x, iter->second.y, iter->second.w, h);
2237 DrawBitmapForNinePatchedBitmap(destRect, bitmap, sourRect);
2241 // right-bottom side clipping
2242 int w = iter->first.x + iter->first.w - x;
2244 Rectangle destRect(x, y, w, h);
2245 Rectangle sourRect(iter->second.x, iter->second.y, w, h);
2247 DrawBitmapForNinePatchedBitmap(destRect, bitmap, sourRect);
2262 _Canvas::DrawEllipse(const _Util::Rectangle<int>& bounds)
2264 _Util::Rectangle<double> doubleBounds =
2272 return this->DrawEllipse(doubleBounds);
2276 _Canvas::DrawEllipse(const _Util::Rectangle<double>& bounds)
2278 if ((bounds.w <= 0.0) || (bounds.h <= 0.0))
2283 // this->__lineWidth is always greater than 0
2285 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
2287 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2289 bool shouldWorkAround = !__IsInClipBounds(bounds) && (this->__dashData.pattern.Size() == 0);
2291 if (!shouldWorkAround && pCairo && pCairo->pCairo)
2293 SET_CAIRO_ALL_PROPERTIES;
2295 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
2297 _Cairo::DrawEllipse(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, bounds);
2301 _Cairo::DrawEllipse(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, bounds);
2304 RESET_CAIRO_ALL_PROPERTIES;
2308 else if (shouldWorkAround && pCairo && pCairo->pCairo)
2310 SET_CAIRO_ALL_PROPERTIES;
2312 double pattern = (bounds.w + bounds.h) * 2.0;
2313 _Cairo::SetDash(pCairo->pCairo, &pattern, 1, 0);
2315 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
2317 _Cairo::DrawEllipse(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, bounds);
2321 _Cairo::DrawEllipse(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, bounds);
2324 RESET_CAIRO_ALL_PROPERTIES;
2330 _CanvasEllipse ellipse;
2333 memset(&info, 0, sizeof(info));
2335 SystemPixel* pBufferAddr = null;
2336 int bufferPitch = 0;
2338 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2340 info.width = __pScratchPad->GetWidth();
2341 info.height = __pScratchPad->GetHeight();
2342 info.bitsPerPixel = 32;
2343 info.pixelPerLine = bufferPitch;
2344 info.pPixels = (void*) pBufferAddr;
2345 info.color32 = composedColor;
2346 info.isClipBoundsSet = this->__isClipBoundsSet;
2347 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2349 ellipse.SetLineWidth(this->__lineWidth.asInteger);
2351 return ellipse.DrawEllipse(int(bounds.x), int(bounds.y), int(bounds.w), int(bounds.h), info);
2356 _Canvas::DrawLine(const _Util::Point<int>& point1, const _Util::Point<int>& point2)
2358 _Util::Point<double> doublePoint1 =
2364 _Util::Point<double> doublePoint2 =
2370 return this->DrawLine(doublePoint1, doublePoint2);
2374 _Canvas::DrawLine(const _Util::Point<double>& point1, const _Util::Point<double>& point2)
2376 // this->__lineWidth is always greater than 0
2378 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
2380 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2382 if (pCairo && pCairo->pCairo)
2384 _Util::Point<double> point[] =
2386 { point1.x, point1.y },
2387 { point2.x, point2.y }
2390 SET_CAIRO_ALL_PROPERTIES;
2392 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
2394 _Cairo::Drawline(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, point, 2);
2398 _Cairo::Drawline(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, point, 2);
2401 RESET_CAIRO_ALL_PROPERTIES;
2422 memset(&info, 0, sizeof(info));
2424 SystemPixel* pBufferAddr = null;
2425 int bufferPitch = 0;
2427 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2429 info.width = __pScratchPad->GetWidth();
2430 info.height = __pScratchPad->GetHeight();
2431 info.bitsPerPixel = 32;
2432 info.pixelPerLine = bufferPitch;
2433 info.pPixels = (void*) pBufferAddr;
2434 info.color32 = composedColor;
2435 info.isClipBoundsSet = this->__isClipBoundsSet;
2436 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2438 line.SetLineWidth(this->__lineWidth.asInteger);
2440 if (this->__lineWidth.asInteger == 1)
2442 if ((startPt.x == endPt.x) && (startPt.y == endPt.y))
2444 this->SetPixel(point1);
2449 return line.DrawLine(startPt, endPt, info);
2454 _Canvas::DrawPolygon(const _Util::Point<double>* pPoints, unsigned int pointCount)
2456 // this->__lineWidth is always greater than 0
2458 if (pointCount == 1)
2460 return this->SetPixel(pPoints[0]);
2463 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
2465 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2467 if (pCairo && pCairo->pCairo)
2469 SET_CAIRO_ALL_PROPERTIES;
2471 _Cairo::DrawPolygon(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, pPoints, pointCount);
2473 RESET_CAIRO_ALL_PROPERTIES;
2479 std::unique_ptr<_GpPoint[]> tempPoints(new (std::nothrow) _GpPoint[pointCount]);
2481 _GpPoint* pTempPoints = tempPoints.get();
2483 if (pTempPoints == null)
2488 for (unsigned int i = 0; i < pointCount; i++)
2490 pTempPoints[i].x = int(pPoints[i].x);
2491 pTempPoints[i].y = int(pPoints[i].y);
2497 memset(&info, 0, sizeof(info));
2499 SystemPixel* pBufferAddr = null;
2500 int bufferPitch = 0;
2502 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2504 info.width = __pScratchPad->GetWidth();
2505 info.height = __pScratchPad->GetHeight();
2506 info.bitsPerPixel = 32;
2507 info.pixelPerLine = bufferPitch;
2508 info.pPixels = (void*) pBufferAddr;
2509 info.color32 = composedColor;
2510 info.isClipBoundsSet = this->__isClipBoundsSet;
2511 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2513 line.SetLineWidth(this->__lineWidth.asInteger);
2515 result r = line.DrawPolygon(int(pointCount), pTempPoints, info);
2522 _Canvas::DrawPolyline(const _Util::Point<double>* pPoints, unsigned int pointCount)
2524 // this->__lineWidth is always greater than 0
2526 if (pointCount == 1)
2528 return this->SetPixel(pPoints[0]);
2531 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
2533 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2535 if (pCairo && pCairo->pCairo)
2537 SET_CAIRO_ALL_PROPERTIES;
2539 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
2541 _Cairo::DrawPolyline(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, pPoints, pointCount);
2545 _Cairo::DrawPolyline(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, pPoints, pointCount);
2548 RESET_CAIRO_ALL_PROPERTIES;
2554 std::unique_ptr<_GpPoint[]> tempPoints(new (std::nothrow) _GpPoint[pointCount]);
2556 _GpPoint* pTempPoints = tempPoints.get();
2558 if (pTempPoints == null)
2563 for (unsigned int i = 0; i < pointCount; i++)
2565 pTempPoints[i].x = int(pPoints[i].x);
2566 pTempPoints[i].y = int(pPoints[i].y);
2572 memset(&info, 0, sizeof(info));
2574 SystemPixel* pBufferAddr = null;
2575 int bufferPitch = 0;
2577 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2579 info.width = __pScratchPad->GetWidth();
2580 info.height = __pScratchPad->GetHeight();
2581 info.bitsPerPixel = 32;
2582 info.pixelPerLine = bufferPitch;
2583 info.pPixels = (void*) pBufferAddr;
2584 info.color32 = composedColor;
2585 info.isClipBoundsSet = this->__isClipBoundsSet;
2586 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2588 line.SetLineWidth(this->__lineWidth.asInteger);
2590 result r = line.DrawPolyLine(int(pointCount), pTempPoints, info);
2597 _Canvas::DrawRectangle(const _Util::Rectangle<int>& rect)
2599 _Util::Rectangle<double> doubleRect =
2607 return this->DrawRectangle(doubleRect);
2611 _Canvas::DrawRectangle(const _Util::Rectangle<double>& rectangle)
2613 if ((rectangle.w <= 0.0) || (rectangle.h <= 0.0))
2618 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
2620 bool tryToDrawWithCairo = (__lineWidth.applied == _Util::ScalarHolder::AS_DOUBLE || __lineWidth.asInteger > 1 || __dashData.pattern.Size() > 0);
2622 if (tryToDrawWithCairo)
2624 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2626 if (pCairo && pCairo->pCairo)
2628 SET_CAIRO_ALL_PROPERTIES;
2630 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
2632 _Cairo::DrawRectangle(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, rectangle);
2636 _Cairo::DrawRectangle(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, rectangle);
2639 RESET_CAIRO_ALL_PROPERTIES;
2645 // falls through legacy drawing solution
2647 int x1 = static_cast<int>(rectangle.x);
2648 int y1 = static_cast<int>(rectangle.y);
2649 int x2 = x1 + static_cast<int>(rectangle.w) - 1;
2650 int y2 = y1 + static_cast<int>(rectangle.h) - 1;
2652 if (this->__lineWidth.asInteger == 1)
2654 if (!this->__isClipBoundsSet)
2656 __pScratchPad->RegisterFillRect(_RasterOp::FnFillRectAlpha32Bit);
2658 if (x2 > x1 && y2 > y1)
2660 __pScratchPad->FillRect(x1, y1, x2 - x1, 1, composedColor);
2661 __pScratchPad->FillRect(x2, y1, 1, y2 - y1, composedColor);
2663 __pScratchPad->FillRect(x1 + 1, y2, x2 - x1, 1, composedColor);
2664 __pScratchPad->FillRect(x1, y1 + 1, 1, y2 - y1, composedColor);
2668 __pScratchPad->FillRect(x1, y1, static_cast<int>(rectangle.w), static_cast<int>(rectangle.h), composedColor);
2671 __pScratchPad->RegisterFillRect(null);
2675 _Util::Rectangle<int> clip = { this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height };
2677 if (x2 > x1 && y2 > y1)
2679 _Util::Rectangle<int> rect1 = { x1, y1, x2 - x1, 1 };
2680 _Util::Rectangle<int> rect2 = { x2, y1, 1, y2 - y1 };
2681 _Util::Rectangle<int> rect3 = { x1 + 1, y2, x2 - x1, 1 };
2682 _Util::Rectangle<int> rect4 = { x1, y1 + 1, 1, y2 - y1 };
2684 _FillRectangleWithClip(__pScratchPad, composedColor, rect1, clip);
2685 _FillRectangleWithClip(__pScratchPad, composedColor, rect2, clip);
2686 _FillRectangleWithClip(__pScratchPad, composedColor, rect3, clip);
2687 _FillRectangleWithClip(__pScratchPad, composedColor, rect4, clip);
2691 _Util::Rectangle<int> rect1 = { x1, y1, static_cast<int>(rectangle.w), static_cast<int>(rectangle.h) };
2693 _FillRectangleWithClip(__pScratchPad, composedColor, rect1, clip);
2699 else if (this->__lineWidth.asInteger > 1)
2701 _GpPoint tempPoints[4] =
2712 memset(&info, 0, sizeof(info));
2714 SystemPixel* pBufferAddr = null;
2715 int bufferPitch = 0;
2717 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2719 info.width = __pScratchPad->GetWidth();
2720 info.height = __pScratchPad->GetHeight();
2721 info.bitsPerPixel = 32;
2722 info.pixelPerLine = bufferPitch;
2723 info.pPixels = (void*) pBufferAddr;
2724 info.color32 = composedColor;
2725 info.isClipBoundsSet = this->__isClipBoundsSet;
2726 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2728 line.SetLineWidth(this->__lineWidth.asInteger);
2730 result r = line.DrawPolygon(4, tempPoints, info);
2735 // this->__lineWidth is always greater than 0
2740 _Canvas::DrawRoundRectangle(const _Util::Rectangle<int>& rect, const _Util::Dimension<int>& arcDim)
2742 _Util::Rectangle<double> doubleRect =
2750 _Util::Dimension<double> doubleArcDim =
2756 return this->DrawRoundRectangle(doubleRect, doubleArcDim);
2760 _Canvas::DrawRoundRectangle(const _Util::Rectangle<double>& rect, const _Util::Dimension<double>& arcDim)
2762 if ((rect.w <= 0.0) || (rect.h <= 0))
2767 if ((int(arcDim.w) == 0) || (int(arcDim.h) == 0))
2769 return this->DrawRectangle(rect);
2772 _Util::Dimension<double> revisedArcDim =
2774 (arcDim.w <= rect.w / 2.0) ? arcDim.w : rect.w / 2.0,
2775 (arcDim.h <= rect.h / 2.0) ? arcDim.h : rect.h / 2.0
2778 // this->__lineWidth is always greater than 0
2780 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
2782 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2784 if (pCairo && pCairo->pCairo)
2786 SET_CAIRO_ALL_PROPERTIES;
2788 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
2790 _Cairo::DrawRoundRectangle(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, rect, revisedArcDim);
2794 _Cairo::DrawRoundRectangle(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, rect, revisedArcDim);
2797 RESET_CAIRO_ALL_PROPERTIES;
2803 _CanvasRoundRect roundRect;
2806 memset(&info, 0, sizeof(info));
2808 SystemPixel* pBufferAddr = null;
2809 int bufferPitch = 0;
2811 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2813 info.width = __pScratchPad->GetWidth();
2814 info.height = __pScratchPad->GetHeight();
2815 info.bitsPerPixel = 32;
2816 info.pixelPerLine = bufferPitch;
2817 info.pPixels = (void*) pBufferAddr;
2818 info.color32 = composedColor;
2819 info.isClipBoundsSet = this->__isClipBoundsSet;
2820 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2822 roundRect.SetLineWidth(this->__lineWidth.asInteger);
2824 return roundRect.DrawRoundRect(int(rect.x), int(rect.y), int(rect.w), int(rect.h), int(revisedArcDim.w), int(revisedArcDim.h), info);
2829 _Canvas::DrawTriangle(const _Util::Point<double>& point1, const _Util::Point<double>& point2, const _Util::Point<double>& point3)
2831 // this->__lineWidth is always greater than 0
2833 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
2835 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2837 if (pCairo && pCairo->pCairo)
2839 _Util::Point<double> point[] =
2841 { point1.x, point1.y },
2842 { point2.x, point2.y },
2843 { point3.x, point3.y }
2846 SET_CAIRO_ALL_PROPERTIES;
2848 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
2850 _Cairo::DrawPolygon(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, point, 3);
2854 _Cairo::DrawPolygon(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, point, 3);
2857 RESET_CAIRO_ALL_PROPERTIES;
2863 _CanvasTriangle triangle;
2866 memset(&info, 0, sizeof(info));
2868 SystemPixel* pBufferAddr = null;
2869 int bufferPitch = 0;
2871 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2873 info.width = __pScratchPad->GetWidth();
2874 info.height = __pScratchPad->GetHeight();
2875 info.bitsPerPixel = 32;
2876 info.pixelPerLine = bufferPitch;
2877 info.pPixels = (void*) pBufferAddr;
2878 info.color32 = composedColor;
2879 info.isClipBoundsSet = this->__isClipBoundsSet;
2880 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2882 triangle.SetLineWidth(this->__lineWidth.asInteger);
2884 _GpPoint p1 = { int(point1.x), int(point1.y) };
2885 _GpPoint p2 = { int(point2.x), int(point2.y) };
2886 _GpPoint p3 = { int(point3.x), int(point3.y) };
2888 return triangle.DrawTriangle(p1, p2, p3, info);
2893 _Canvas::FillTriangle(const Color& color, const _Util::Point<int>& point1, const _Util::Point<int>& point2, const _Util::Point<int>& point3)
2895 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
2897 _Util::Point<double> doublePoint1 =
2903 _Util::Point<double> doublePoint2 =
2909 _Util::Point<double> doublePoint3 =
2915 return this->__FillTriangle(composedColor, doublePoint1, doublePoint2, doublePoint3);
2919 _Canvas::FillTriangle(const Color& color, const _Util::Point<double>& point1, const _Util::Point<double>& point2, const _Util::Point<double>& point3)
2921 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
2923 return this->__FillTriangle(composedColor, point1, point2, point3);
2927 _Canvas::__FillTriangle(unsigned long composedColor, const _Util::Point<double>& point1, const _Util::Point<double>& point2, const _Util::Point<double>& point3)
2929 // this->__lineWidth is always greater than 0
2931 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2933 if (pCairo && pCairo->pCairo)
2935 _Util::Point<double> point[] =
2937 { point1.x, point1.y },
2938 { point2.x, point2.y },
2939 { point3.x, point3.y }
2942 SET_CAIRO_FILL_PROPERTIES;
2944 _Cairo::FillPolygon(pCairo->pCairo, composedColor, point, 3);
2946 RESET_CAIRO_FILL_PROPERTIES;
2952 _CanvasTriangle triangle;
2955 memset(&info, 0, sizeof(info));
2957 SystemPixel* pBufferAddr = null;
2958 int bufferPitch = 0;
2960 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2962 info.width = __pScratchPad->GetWidth();
2963 info.height = __pScratchPad->GetHeight();
2964 info.bitsPerPixel = 32;
2965 info.pixelPerLine = bufferPitch;
2966 info.pPixels = (void*) pBufferAddr;
2967 info.color32 = composedColor;
2968 info.isClipBoundsSet = this->__isClipBoundsSet;
2969 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2971 triangle.SetLineWidth(this->__lineWidth.asInteger);
2973 return triangle.FillTriangle(int(point1.x), int(point1.y), int(point2.x), int(point2.y), int(point3.x), int(point3.y), info);
2978 _Canvas::__FillEllipse(unsigned long composedColor, const _Util::Rectangle<double>& bounds)
2980 if ((bounds.w <= 0.0) || (bounds.h <= 0.0))
2985 // this->__lineWidth is always greater than 0
2987 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2989 if (pCairo && pCairo->pCairo)
2991 SET_CAIRO_FILL_PROPERTIES;
2993 _Cairo::FillEllipse(pCairo->pCairo, composedColor, bounds);
2995 RESET_CAIRO_FILL_PROPERTIES;
3001 _CanvasEllipse ellipse;
3004 memset(&info, 0, sizeof(info));
3006 SystemPixel* pBufferAddr = null;
3007 int bufferPitch = 0;
3009 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
3011 info.width = __pScratchPad->GetWidth();
3012 info.height = __pScratchPad->GetHeight();
3013 info.bitsPerPixel = 32;
3014 info.pixelPerLine = bufferPitch;
3015 info.pPixels = (void*) pBufferAddr;
3016 info.color32 = composedColor;
3017 info.isClipBoundsSet = this->__isClipBoundsSet;
3018 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
3020 ellipse.SetLineWidth(this->__lineWidth.asInteger);
3022 return ellipse.FillElliepse(int(bounds.x), int(bounds.y), int(bounds.w), int(bounds.h), info);
3027 _Canvas::FillEllipse(const Color& color, const _Util::Rectangle<int>& bounds)
3029 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3031 _Util::Rectangle<double> doubleBounds =
3039 return this->__FillEllipse(composedColor, doubleBounds);
3043 _Canvas::FillEllipse(const Color& color, const _Util::Rectangle<double>& bounds)
3045 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3047 return this->__FillEllipse(composedColor, bounds);
3051 _Canvas::FillPolygon(const Color& color, const _Util::Point<double>* pPoints, unsigned int pointCount)
3054 // Implementation of this method in API versions prior to 2.0 has the following issue:
3056 // -# If there are 4 input points and conditions below is satisfied, the drawing result does not match the expected behavior. @n
3058 // "point[0].x == point[3].x && point[1].x == point[2].x && point[0].y == point[1].y && point[2].y == point[3].y"
3060 // there are 4 cases can be occurred.
3062 // [case1] (p[0]->x > p[1]->x && p[0]->y > p[3]->y)
3067 // | | <--- expected result
3069 // p1--------p0_________
3072 // | | <--- wrong result
3076 // [case2] (p[0]->x < p[1]->x && p[0]->y > p[3]->y)
3081 // | | <--- expected result
3086 // | | <--- wrong result
3090 // [case3] (p[0]->x < p[1]->x && p[0]->y < p[3]->y)
3095 // | | <--- no problem.
3100 // [case4] (p[0]->x > p[1]->x && p[0]->y < p[3]->y)
3102 // p1________p0________
3105 // | | | <--- wrong result
3107 // p2--------p3--------
3110 // -- expected result
3112 // The issue mentioned above is resolved in API version 2.0, So, check the SDK version and emulate problem before step forward furthermore.
3114 // CR approved, no. EP-47D6817268074396919211307C39CA55
3117 // this->__lineWidth is always greater than 0
3119 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3121 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
3123 if (pCairo && pCairo->pCairo)
3125 SET_CAIRO_FILL_PROPERTIES;
3127 _Cairo::FillPolygon(pCairo->pCairo, composedColor, pPoints, pointCount);
3129 RESET_CAIRO_FILL_PROPERTIES;
3135 _CanvasFillPolygon polygon;
3138 memset(&info, 0, sizeof(info));
3140 SystemPixel* pBufferAddr = null;
3141 int bufferPitch = 0;
3143 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
3145 info.width = __pScratchPad->GetWidth();
3146 info.height = __pScratchPad->GetHeight();
3147 info.bitsPerPixel = 32;
3148 info.pixelPerLine = bufferPitch;
3149 info.pPixels = (void*) pBufferAddr;
3150 info.color32 = composedColor;
3151 info.isClipBoundsSet = this->__isClipBoundsSet;
3152 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
3154 polygon.SetLineWidth(this->__lineWidth.asInteger);
3156 std::unique_ptr<_GpPoint[]> tempPoints(new (std::nothrow) _GpPoint[pointCount]);
3158 _GpPoint* pTempPoints = tempPoints.get();
3160 if (pTempPoints == null)
3165 for (unsigned int i = 0; i < pointCount; i++)
3167 pTempPoints[i].x = int(pPoints[i].x);
3168 pTempPoints[i].y = int(pPoints[i].y);
3171 result r = polygon.FillPolygon(int(pointCount), pTempPoints, info);
3178 _Canvas::__FillRectangle(unsigned long composedColor, const _Util::Rectangle<double>& rectangle)
3180 if ((rectangle.w <= 0.0) || (rectangle.h <= 0.0))
3185 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
3187 if (pCairo && pCairo->pCairo)
3189 SET_CAIRO_FILL_PROPERTIES;
3191 _Cairo::FillRectangle(pCairo->pCairo, composedColor, rectangle);
3193 RESET_CAIRO_FILL_PROPERTIES;
3199 _Util::Rectangle<int> rect =
3201 static_cast<int>(rectangle.x),
3202 static_cast<int>(rectangle.y),
3203 static_cast<int>(rectangle.w),
3204 static_cast<int>(rectangle.h)
3207 if (this->__isClipBoundsSet)
3211 int x2 = x1 + rect.w;
3212 int y2 = y1 + rect.h;
3214 x1 = (x1 >= this->__clipBounds.x) ? x1 : this->__clipBounds.x;
3215 y1 = (y1 >= this->__clipBounds.y) ? y1 : this->__clipBounds.y;
3217 x2 = (x2 <= this->__clipBounds.x + this->__clipBounds.width) ? x2 : this->__clipBounds.x + this->__clipBounds.width;
3218 y2 = (y2 <= this->__clipBounds.y + this->__clipBounds.height) ? y2 : this->__clipBounds.y + this->__clipBounds.height;
3226 if (rect.w > 0 && rect.h > 0)
3228 // alpha-fill-rect() applied
3229 __pScratchPad->RegisterFillRect(_RasterOp::FnFillRectAlpha32Bit);
3230 __pScratchPad->FillRect(rect.x, rect.y, rect.w, rect.h, composedColor);
3231 __pScratchPad->RegisterFillRect(null);
3239 _Canvas::FillRectangle(const Color& color, const Rectangle& rect)
3241 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3243 return this->__FillRectangle(composedColor, _Util::Convert<Rectangle, _Util::Rectangle<double> >(rect));
3247 _Canvas::FillRectangle(const Color& color, const _Util::Rectangle<int>& rect)
3249 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3251 _Util::Rectangle<double> doubleRect =
3259 return this->__FillRectangle(composedColor, doubleRect);
3263 _Canvas::FillRectangle(const Color& color, const _Util::Rectangle<double>& rect)
3265 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3267 return this->__FillRectangle(composedColor, rect);
3271 _Canvas::FillRoundRectangle(const Color& color, const _Util::Rectangle<int>& rect, const _Util::Dimension<int>& arcDim)
3273 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3275 _Util::Rectangle<double> doubleRect =
3283 _Util::Dimension<double> doubleArcDim =
3289 return this->__FillRoundRectangle(composedColor, doubleRect, doubleArcDim);
3293 _Canvas::FillRoundRectangle(const Color& color, const _Util::Rectangle<double>& rect, const _Util::Dimension<double>& arcDim)
3295 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3297 return this->__FillRoundRectangle(composedColor, rect, arcDim);
3301 _Canvas::__FillRoundRectangle(unsigned long composedColor, const _Util::Rectangle<double>& rect, const _Util::Dimension<double>& arcDim)
3303 if ((rect.w <= 0.0) || (rect.h <= 0.0))
3308 if ((int(arcDim.w) <= 0) || (int(arcDim.h) <= 0))
3310 return this->__FillRectangle(composedColor, rect);
3313 _Util::Dimension<double> revisedArcDim =
3315 (arcDim.w <= rect.w / 2.0) ? arcDim.w : rect.w / 2.0,
3316 (arcDim.h <= rect.h / 2.0) ? arcDim.h : rect.h / 2.0
3319 // this->__lineWidth is always greater than 0
3321 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
3323 if (pCairo && pCairo->pCairo)
3325 SET_CAIRO_FILL_PROPERTIES;
3327 _Cairo::FillRoundRectangle(pCairo->pCairo, composedColor, rect, revisedArcDim);
3329 RESET_CAIRO_FILL_PROPERTIES;
3335 _CanvasRoundRect roundRect;
3338 memset(&info, 0, sizeof(info));
3340 SystemPixel* pBufferAddr = null;
3341 int bufferPitch = 0;
3343 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
3345 info.width = __pScratchPad->GetWidth();
3346 info.height = __pScratchPad->GetHeight();
3347 info.bitsPerPixel = 32;
3348 info.pixelPerLine = bufferPitch;
3349 info.pPixels = (void*) pBufferAddr;
3350 info.color32 = composedColor;
3351 info.isClipBoundsSet = this->__isClipBoundsSet;
3352 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
3354 roundRect.SetLineWidth(this->__lineWidth.asInteger);
3356 return roundRect.FillRoundRectangle(int(rect.x), int(rect.y), int(rect.w), int(rect.h), int(revisedArcDim.w), int(revisedArcDim.h), info);
3361 _Canvas::DrawText(const Point& point, const Tizen::Base::String& text)
3363 return _Font::DrawText(*this, point, text, 0, text.GetLength());
3367 _Canvas::DrawText(const Point& point, const Tizen::Base::String& text, int startIndex, int length)
3369 return _Font::DrawText(*this, point, text, startIndex, length);
3373 _Canvas::DrawText(const Point& point, const Tizen::Base::String& text, int startIndex, int length, const Color& outlineColor)
3375 return _Font::DrawText(*this, point, text, startIndex, length, outlineColor);
3379 _Canvas::GetBounds(void) const
3381 Rectangle rect(this->__xBufferPos, this->__yBufferPos, __pScratchPad->GetWidth(), __pScratchPad->GetHeight());
3383 if (this->__windowHandle != INVALID_HANDLE)
3393 _Canvas::GetLineStyle() const
3395 SysTryReturn(NID_GRP, this && this->__pSurface, LINE_STYLE_MAX, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3397 return this->__lineStyle;
3401 _Canvas::GetLineWidth() const
3403 SysTryReturn(NID_GRP, this && this->__pSurface, -1, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3405 return this->__lineWidth.asInteger;
3409 _Canvas::GetLineCapStyle() const
3411 SysTryReturn(NID_GRP, this && this->__pSurface, LINE_CAP_STYLE_ROUND, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3413 return this->__lineCapStyle;
3417 _Canvas::GetLineJoinStyle() const
3419 SysTryReturn(NID_GRP, this && this->__pSurface, LINE_JOIN_STYLE_ROUND, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3421 return this->__lineJoinStyle;
3425 _Canvas::SetLineStyle(LineStyle style)
3427 this->__lineStyle = style;
3433 _Canvas::SetLineWidth(int width, float widthAsFloat)
3435 SysTryReturnResult(NID_GRP, width > 0 || widthAsFloat >= 0.0f, E_OUT_OF_RANGE, "The given line width(%d) is out of range.\n", width);
3437 this->__lineWidth = width;
3438 this->__lineWidth.asDouble = double(widthAsFloat);
3444 _Canvas::SetLineWidth(float width)
3446 SysTryReturnResult(NID_GRP, width > 0.0f, E_OUT_OF_RANGE, "The given line width(%f) is out of range.\n", width);
3448 this->__lineWidth = width;
3454 _Canvas::SetLineCapStyle(LineCapStyle lineCapStyle)
3456 this->__lineCapStyle = lineCapStyle;
3462 _Canvas::SetLineJoinStyle(LineJoinStyle lineJoinStyle)
3464 this->__lineJoinStyle = lineJoinStyle;
3470 _Canvas::SetDashPattern(const Tizen::Graphics::_Util::AccumList<double>& dashValueList, double offset)
3472 SysTryReturn(NID_GRP, this && this->__pSurface, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3475 Tizen::Graphics::_Util::AccumList<double> listSwap;
3476 this->__dashData.pattern.Swap(listSwap);
3478 this->__dashData.offset = 0.0;
3482 Tizen::Graphics::_Util::AccumList<double>::ConstIterator dashIterator = dashValueList.Begin();
3484 for (; dashIterator != dashValueList.End(); dashIterator++)
3486 this->__dashData.pattern.Push(*dashIterator);
3489 this->__dashData.offset = offset;
3496 _Canvas::SetDrawingQuality(BitmapDrawingQuality quality)
3498 // 'quality' is verified in _CanvasImpl::SetDrawingQuality()
3499 this->__bitmapDrawingQuality = quality;
3502 BitmapDrawingQuality
3503 _Canvas::GetDrawingQuality(void) const
3505 return this->__bitmapDrawingQuality;
3509 _Canvas::SetCompositeMode(CompositeMode compositeMode)
3511 // 'blendingMode' is verified in _CanvasImpl::SetBlendingMode()
3512 this->__compositeMode = compositeMode;
3516 _Canvas::GetCompositeMode(void) const
3518 return this->__compositeMode;
3522 _Canvas::GetPixel(const Point& point, Color& color) const
3524 Point pos(point.x, point.y);
3526 // [ykahn 2011.06.27] revise the value of 'point' if it goes out-of-range
3528 Rectangle rtCanvas = _GetBoundsRel(*this);
3530 SysTryReturnResult(NID_GRP, !rtCanvas.IsEmpty(), E_OUT_OF_RANGE, "Cannot get the bounds of the canvas.\n");
3532 if (pos.x >= rtCanvas.width && rtCanvas.width >= 1)
3534 pos.x = rtCanvas.width - 1;
3537 if (pos.y >= rtCanvas.height && rtCanvas.height >= 1)
3539 pos.y = rtCanvas.height - 1;
3544 result r = E_OUT_OF_RANGE;
3546 Rectangle rect = this->GetBounds();
3551 if ((point.x >= rect.x && point.x < rect.x + rect.width) && (point.y >= rect.y && point.y < rect.y + rect.height))
3555 (const_cast<_Canvas*>(this))->Lock(info);
3557 if (info.bitsPerPixel == 32)
3559 unsigned long* pDest32 = (unsigned long*) info.pPixels;
3560 long pitch = info.pitch / 4;
3562 color.SetRGB32(pDest32[pitch * point.y + point.x], true);
3566 else if (info.bitsPerPixel == 16)
3568 unsigned short* pDest16 = (unsigned short*) info.pPixels;
3569 long pitch = info.pitch / 2;
3571 unsigned short color16 = pDest16[pitch * point.y + point.x];
3573 unsigned long r = (color16 & 0xF800) >> 8;
3574 unsigned long g = (color16 & 0x07E0) >> 3;
3575 unsigned long b = (color16 & 0x001F) << 3;
3581 unsigned long color32 = 0xFF000000 | (r << 16) | (g << 8) | (b);
3583 color.SetRGB32(color32, true);
3588 (const_cast<_Canvas*>(this))->Unlock();
3596 _Canvas::SetPixel(const _Util::Point<int>& point)
3598 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
3600 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
3602 if (pCairo && pCairo->pCairo)
3604 _Util::Rectangle<double> rectangle = {double(point.x), double(point.y), 1.0, 1.0};
3606 SET_CAIRO_FILL_PROPERTIES;
3608 _Cairo::FillRectangle(pCairo->pCairo, composedColor, rectangle);
3610 RESET_CAIRO_FILL_PROPERTIES;
3615 if (!this->__isClipBoundsSet)
3617 __pScratchPad->FillRect(point.x, point.y, 1, 1, composedColor);
3621 _Util::Rectangle<int> rect = { point.x, point.y, 1, 1 };
3622 _Util::Rectangle<int> clip = { this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height };
3624 _FillRectangleWithClip(__pScratchPad, composedColor, rect, clip);
3631 _Canvas::SetPixel(const _Util::Point<double>& point)
3633 _Util::Rectangle<double> doubleRect =
3641 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
3643 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
3645 if (pCairo && pCairo->pCairo)
3647 SET_CAIRO_FILL_PROPERTIES;
3649 _Cairo::FillRectangle(pCairo->pCairo, composedColor, doubleRect);
3651 RESET_CAIRO_FILL_PROPERTIES;
3656 this->__FillRectangle(composedColor, doubleRect);
3664 int bufferWidth = __pSurface->GetWidth();
3665 int bufferHeight = __pSurface->GetHeight();
3666 int bufferPpl = __pSurface->GetPitch();
3668 // cannot use 'if (__pSurface->GetHandle())'
3669 if (this->__windowHandle != INVALID_HANDLE)
3672 evas_object_image_pixels_dirty_set((Evas_Object*) this->__windowHandle, true);
3674 Evas_Object* pSourceObject = _GetWindowSourceObject(this->__windowHandle);
3675 evas_object_image_data_set(pSourceObject, evas_object_image_data_get(pSourceObject, EINA_TRUE));
3676 evas_object_image_data_update_add(pSourceObject, 0, 0, bufferWidth, bufferHeight);
3679 evas_object_show((Evas_Object*) this->__windowHandle);
3685 SysTryReturnResult(NID_GRP, Tizen::App::_AppInfo::IsOspCompat(), E_UNSUPPORTED_OPERATION, "This method is unsupported in Tizen.");
3687 _CanvasShowFromMemory(this->__xBufferPos, this->__yBufferPos, 0, 0, bufferWidth, bufferHeight, __pBuffer, bufferWidth, bufferHeight, 32, bufferPpl * 4);
3694 _Canvas::Show(const Rectangle& rect)
3696 if ((rect.width == 0) || (rect.height == 0))
3701 if (this->__windowHandle != INVALID_HANDLE)
3704 int x2 = rect.x + rect.width;
3706 int y2 = rect.y + rect.height;
3729 evas_object_image_pixels_dirty_set((Evas_Object*) this->__windowHandle, true);
3730 // same as evas_object_image_data_update_add((Evas_Object*)this->__windowHandle, rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2), if (width >= 3) and (height >= 3)
3731 evas_object_image_data_update_add((Evas_Object*) this->__windowHandle, x1, y1, x2 - x1, y2 - y1);
3733 Evas_Object* pSourceObject = _GetWindowSourceObject(this->__windowHandle);
3734 evas_object_image_data_set(pSourceObject, evas_object_image_data_get(pSourceObject, EINA_TRUE));
3735 evas_object_image_data_update_add(pSourceObject, x1, y1, x2 - x1, y2 - y1);
3738 evas_object_show((Evas_Object*) this->__windowHandle);
3744 SysTryReturnResult(NID_GRP, Tizen::App::_AppInfo::IsOspCompat(), E_UNSUPPORTED_OPERATION, "This method is unsupported in Tizen.");
3746 int bufferWidth = __pSurface->GetWidth();
3747 int bufferHeight = __pSurface->GetHeight();
3748 int bufferPpl = __pSurface->GetPitch();
3750 _CanvasShowFromMemory(this->__xBufferPos + rect.x, this->__yBufferPos + rect.y, rect.x, rect.y, rect.width, rect.height, __pBuffer, bufferWidth, bufferHeight, 32, bufferPpl * 4);
3757 _Canvas::SetFont(const _Font& font)
3759 SysTryReturn(NID_GRP, this && this->__pSurface, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
3762 this->__pFont = const_cast<_Font*>(&font);
3768 _Canvas::SetPriorityFont(const _Font& font)
3770 SysTryReturn(NID_GRP, this && this->__pSurface, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
3773 this->__pPriorityFont = const_cast<_Font*>(&font);
3779 _Canvas::ResetPriorityFont(void)
3781 // nullify weak reference
3782 this->__pPriorityFont = null;
3786 _Canvas::SetClipBounds(const Rectangle& rect)
3788 if (__pScratchPad == null)
3795 int x2 = x1 + rect.width;
3796 int y2 = y1 + rect.height;
3798 x1 = (x1 > 0) ? x1 : 0;
3799 y1 = (y1 > 0) ? y1 : 0;
3800 x2 = (x2 < __pScratchPad->GetWidth()) ? x2 : __pScratchPad->GetWidth();
3801 y2 = (y2 < __pScratchPad->GetHeight()) ? y2 : __pScratchPad->GetHeight();
3803 x2 = (x1 > x2) ? x1 : x2;
3804 y2 = (y1 > y2) ? y1 : y2;
3806 if (x1 == 0 && y1 == 0 && x2 == __pScratchPad->GetWidth() && y2 == __pScratchPad->GetHeight())
3808 this->__isClipBoundsSet = false;
3812 this->__isClipBoundsSet = true;
3815 this->__clipBounds.SetBounds(x1, y1, x2 - x1, y2 - y1);
3821 _Canvas::GetClipBounds(void) const
3825 SysTryReturn(NID_GRP, this && this->__pSurface, rect, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3827 this->__GetClipBounds(rect);
3833 _Canvas::Lock(BufferInfo& info, long timeout)
3835 if (__pScratchPad == null)
3840 if (_BufferInfoImpl::GetInstance(info) != null)
3842 _BufferInfoImpl::GetInstance(info)->SetHandle(_BufferInfoImpl::HANDLE_TYPE_NONE, 0);
3845 SystemPixel* pBufferAddr = null;
3846 int bufferPitch = 0;
3848 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
3850 info.width = __pScratchPad->GetWidth();
3851 info.height = __pScratchPad->GetHeight();
3852 info.pitch = bufferPitch * sizeof(_SystemPixel);
3853 info.bitsPerPixel = sizeof(_SystemPixel) * 8;
3854 info.pixelFormat = PIXEL_FORMAT_ARGB8888;
3855 info.pPixels = (void*) pBufferAddr;
3856 //info.__handle = INVALID_HANDLE;
3868 _Canvas::SetForegroundColor(const Color& fgColor)
3870 this->__fgColorNative = fgColor;
3871 this->__ComposeFgColor();
3875 _Canvas::GetForegroundColor(void)
3877 return Color(this->__fgColor);
3881 _Canvas::SetBackgroundColor(const Color& bgColor)
3883 this->__bgColorNative = bgColor;
3884 this->__ComposeBgColor();
3888 _Canvas::GetBackgroundColor(void)
3890 return Color(this->__bgColor);
3894 _Canvas::SetForegroundOpacity(int level)
3896 SysTryReturnVoidResult(NID_GRP, this && this->__pSurface, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3908 this->__fgOpacity = level;
3909 this->__ComposeFgColor();
3913 _Canvas::GetForegroundOpacity(void)
3915 SysTryReturn(NID_GRP, this && this->__pSurface, 255, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3917 return this->__fgOpacity;
3921 _Canvas::SetBackgroundOpacity(int level)
3923 SysTryReturnVoidResult(NID_GRP, this && this->__pSurface, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3935 this->__bgOpacity = level;
3936 this->__ComposeBgColor();
3940 _Canvas::GetBackgroundOpacity(void)
3942 SysTryReturn(NID_GRP, this && this->__pSurface, 255, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3944 return this->__bgOpacity;
3948 _Canvas::SetPosition(int x, int y)
3950 SysTryReturnResult(NID_GRP, this->__windowHandle == INVALID_HANDLE, E_UNSUPPORTED_OPERATION, "Window canvas does not support moving the position.\n");
3959 _Canvas::SetAntialiasingEnabled(bool enable)
3961 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
3963 if (pCairo && pCairo->pCairo)
3967 cairo_set_antialias(pCairo->pCairo, CAIRO_ANTIALIAS_DEFAULT);
3971 cairo_set_antialias(pCairo->pCairo, CAIRO_ANTIALIAS_NONE);
3977 _Canvas::IsAntialiasingEnabled(void) const
3979 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
3981 if (pCairo && pCairo->pCairo)
3983 return (cairo_get_antialias(pCairo->pCairo) == CAIRO_ANTIALIAS_DEFAULT);
3990 _Canvas::GetInstance(_CanvasImpl& canvas)
3992 return (&canvas != null) ? canvas._pNativeCanvas : null;
3996 _Canvas::GetInstance(const _CanvasImpl& canvas)
3998 return (&canvas != null) ? canvas._pNativeCanvas : null;
4002 _Canvas::_IsWindowCanvas(void) const
4004 if (!(this && this->__pSurface))
4009 return (this->__windowHandle != INVALID_HANDLE);
4013 _Canvas::_SetPosition(int x, int y)
4015 if (!(this && this->__pSurface))
4017 return E_OPERATION_FAILED;
4020 if (this->__windowHandle != INVALID_HANDLE)
4022 return E_UNSUPPORTED_OPERATION;
4025 //?? what is this function ?
4033 _Canvas::_GetAlphaAttenuation(const _Bitmap& bitmap) const
4035 // 'bitmap' and 'this' are always valid.
4037 int alphaConstant = bitmap.GetAlphaConstant();
4039 alphaConstant = (alphaConstant > 255) ? 255 : alphaConstant;
4040 alphaConstant = (alphaConstant < 0) ? 0 : alphaConstant;
4042 int fgOpacity = this->__fgOpacity;
4044 if (fgOpacity > 0 && fgOpacity < 255)
4046 fgOpacity += (fgOpacity >> 7);
4047 alphaConstant = (alphaConstant * fgOpacity) >> 8;
4050 return alphaConstant;
4054 _Canvas::_SetBlendOption(_Canvas::BlendOption blendOption)
4056 if (!(this && this->__pSurface))
4061 if (blendOption < BLEND_MIN || blendOption >= BLEND_MAX)
4066 this->__blendOption = blendOption;
4069 _Canvas::BlendOption
4070 _Canvas::_GetBlendOption(void) const
4072 if (!(this && this->__pSurface))
4075 return BLEND_ALPHABLEND;
4078 return this->__blendOption;
4082 _Canvas::__InitFgBgColorFromTheme(void)
4084 __fgColorNative = (_GetDefaultForegroundColor) ? _GetDefaultForegroundColor() : Color(0xFF000000);
4085 __bgColorNative = (_GetDefaultBackgroundColor) ? _GetDefaultBackgroundColor() : Color(0xFFFFFFFF);
4087 this->__ComposeFgColor();
4088 this->__ComposeBgColor();
4092 _Canvas::__ComposeFgColor(void)
4094 this->__fgColor = _ComposeColor(this->__fgColorNative.GetRGB32(), this->__fgOpacity);
4098 _Canvas::__ComposeBgColor(void)
4100 this->__bgColor = _ComposeColor(this->__bgColorNative.GetRGB32(), this->__bgOpacity);
4104 _Canvas::__GetClipBounds(Rectangle& rect) const
4106 if (this->__isClipBoundsSet)
4108 rect = this->__clipBounds;
4112 rect = Rectangle(0, 0, __pScratchPad->GetWidth(), __pScratchPad->GetHeight());
4117 _Canvas::__Copy(const Point& destPoint, const _Canvas& srcCanvas, const Rectangle& srcRect)
4119 const _Canvas* pSrcCanvas = &srcCanvas;
4121 Rectangle clippedSrcRect(srcRect);
4123 if (_ClipRectangle(clippedSrcRect.x, clippedSrcRect.y, clippedSrcRect.width, clippedSrcRect.height, 0, 0, pSrcCanvas->__pScratchPad->GetWidth(), pSrcCanvas->__pScratchPad->GetHeight()) == CLIP_REJECT)
4128 __pScratchPad->BitBlt(destPoint.x, destPoint.y, pSrcCanvas->__pScratchPad, clippedSrcRect.x, clippedSrcRect.y, clippedSrcRect.width, clippedSrcRect.height);
4134 _Canvas::__Copy(const Rectangle& destRect, const _Canvas& srcCanvas, const Rectangle& srcRect)
4136 const _Canvas* pSrcCanvas = &srcCanvas;
4138 Rectangle clippedSrcRect(srcRect);
4140 if (_ClipRectangle(clippedSrcRect.x, clippedSrcRect.y, clippedSrcRect.width, clippedSrcRect.height, 0, 0, pSrcCanvas->__pScratchPad->GetWidth(), pSrcCanvas->__pScratchPad->GetHeight()) == CLIP_REJECT)
4146 SystemPixel* pSrcAddr = null;
4149 pSrcCanvas->__pScratchPad->GetBuffer(pSrcAddr, srcPitch);
4150 pSrcAddr += srcPitch * clippedSrcRect.y + clippedSrcRect.x;
4152 SystemPixel* pDstAddr = null;
4155 __pScratchPad->GetBuffer(pDstAddr, dstPitch);
4157 _Util::Pixmap srcImageEx(clippedSrcRect.width, clippedSrcRect.height, sizeof(SystemPixel) * 8, pSrcAddr, srcPitch * sizeof(SystemPixel));
4158 _Util::Pixmap dstImageEx(__pScratchPad->GetWidth(), __pScratchPad->GetHeight(), sizeof(SystemPixel) * 8, pDstAddr, dstPitch * sizeof(SystemPixel));
4160 Tizen::Graphics::_Effect::ScaleImage(dstImageEx, destRect.x, destRect.y, destRect.width, destRect.height, srcImageEx);
4167 _Canvas::__IsInClipBounds(const _Util::Rectangle<double>& bounds)
4171 int x2 = x1 + this->GetBounds().width;
4172 int y2 = y1 + this->GetBounds().height;
4174 if (this->__isClipBoundsSet)
4176 x1 = (this->__clipBounds.x > x1) ? this->__clipBounds.x : x1;
4177 y1 = (this->__clipBounds.y > y1) ? this->__clipBounds.y : y1;
4178 x2 = (this->__clipBounds.x + this->__clipBounds.width < x2) ? this->__clipBounds.x + this->__clipBounds.width : x2;
4179 y2 = (this->__clipBounds.y + this->__clipBounds.height < y2) ? this->__clipBounds.y + this->__clipBounds.height : y2;
4182 return ((bounds.x >= x1) && (bounds.y >= y1) && (bounds.x + bounds.w <= x2) && (bounds.y + bounds.h <= y2));
4185 }} // Tizen::Graphics