2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file 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)
595 , _pNativeGfxEngine(static_cast<void*>(new (std::nothrow)_NativeGfxEngine))
599 , __windowHandle(INVALID_HANDLE)
600 , __blendOption(Tizen::Graphics::_Canvas::BLEND_ALPHABLEND)
606 , __fgColor(0xFFFFFFFF)
607 , __bgColor(0x00000000)
611 , __lineStyle(LINE_STYLE_SOLID)
612 , __lineCapStyle(LINE_CAP_STYLE_ROUND)
613 , __lineJoinStyle(LINE_JOIN_STYLE_ROUND)
614 , __isClipBoundsSet(false)
615 , __textOrigin(TEXT_ORIGIN_LEFT_TOP)
617 , __bitmapDrawingQuality(BITMAP_DRAWING_QUALITY_LOW)
618 , __compositeMode(COMPOSITE_MODE_SRC_OVER)
619 , __useStableRenderer(false)
621 __fgColorNative = Color(__fgColor);
622 __bgColorNative = Color(__bgColor);
624 __dashData.offset = 0;
629 _Util::CarveMagicKey(*this, _magicKey);
632 _Canvas::~_Canvas(void)
634 delete __pScratchPad;
637 if (_pNativeGfxEngine)
639 delete static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
642 _Util::EraseMagicKey(*this, _magicKey);
646 _Canvas::Construct(void)
648 return this->Construct(Rectangle(0, 0, _Screen::GetWidth(), _Screen::GetHeight()));
652 _Canvas::Construct(const Rectangle& rect)
654 result r = E_SUCCESS;
656 _GenericBufferFrameBuffer<SystemPixel>* pTemp = new (std::nothrow) _GenericBufferFrameBuffer<SystemPixel>(rect.width, rect.height);
658 SysTryReturnResult(NID_GRP, pTemp, E_OUT_OF_MEMORY, " _GenericBufferFrameBuffer<> cannot be allocated.");
660 this->__pSurface = new (std::nothrow) _Util::GenericBuffer<SystemPixel>(pTemp);
662 SysTryCatch(NID_GRP, this->__pSurface, delete pTemp;
663 r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] _Util::GenericBuffer<> cannot be allocated.");
665 this->__pBuffer = (unsigned long*) __pSurface->GetBufferAddr();
666 this->__pScratchPad = new (std::nothrow) _Util::ScratchPad<SystemPixel>(__pBuffer, rect.width, rect.height, rect.width);
668 SysTryCatch(NID_GRP, this->__pScratchPad, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] _Util::ScratchPad<> cannot be allocated.");
670 this->__pScratchPad->FillRect(0, 0, this->__pScratchPad->GetWidth(), this->__pScratchPad->GetHeight(), 0x00000000);
672 this->__xBufferPos = rect.x;
673 this->__yBufferPos = rect.y;
675 #if defined(USE_CAIRO)
677 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
681 pCairo->pCairoSurface = cairo_image_surface_create_for_data((unsigned char*) this->__pBuffer, CAIRO_FORMAT_ARGB32, rect.width, rect.height, rect.width * 4);
682 pCairo->pCairo = cairo_create(pCairo->pCairoSurface);
687 __InitFgBgColorFromTheme();
692 delete this->__pScratchPad;
693 this->__pScratchPad = null;
695 delete this->__pSurface;
696 this->__pSurface = null;
702 _Canvas::Construct(Handle windowHandle)
704 return this->Construct(windowHandle, Rectangle(0, 0, _GetWindowWidth(windowHandle), _GetWindowHeight(windowHandle)));
708 _Canvas::Construct(Handle windowHandle, const Rectangle& rect)
710 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);
712 result r = E_SUCCESS;
716 int x2 = x1 + rect.width;
717 int y2 = y1 + rect.height;
729 if (x2 > _GetWindowWidth(windowHandle))
731 x2 = _GetWindowWidth(windowHandle);
734 if (y2 > _GetWindowHeight(windowHandle))
736 y2 = _GetWindowHeight(windowHandle);
739 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);
741 int bufferWidth = x2 - x1;
742 int bufferHeight = y2 - y1;
745 _GenericBufferFrameBuffer<SystemPixel>* pTemp = new (std::nothrow) _GenericBufferFrameBuffer<SystemPixel>(windowHandle, x1, y1, bufferWidth, bufferHeight, 0);
747 SysTryReturnResult(NID_GRP, pTemp, E_OUT_OF_MEMORY, "_GenericBufferFrameBuffer<> cannot be allocated.");
749 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.");
751 this->__pSurface = new (std::nothrow) _Util::GenericBuffer<SystemPixel>(pTemp);
753 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.");
755 this->__pBuffer = (unsigned long*) __pSurface->GetBufferAddr();
756 sourcePitch = __pSurface->GetPitch();
758 this->__pScratchPad = new (std::nothrow) _Util::ScratchPad<SystemPixel>(__pBuffer, bufferWidth, bufferHeight, sourcePitch);
760 SysTryCatch(NID_GRP, this->__pScratchPad, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] _Util::ScratchPad<> cannot be allocated.");
762 this->__windowHandle = windowHandle;
764 this->__xBufferPos = x1;
765 this->__yBufferPos = y1;
767 #if defined(USE_CAIRO)
769 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
773 pCairo->pCairoSurface = cairo_image_surface_create_for_data((unsigned char*) this->__pBuffer, CAIRO_FORMAT_ARGB32, bufferWidth, bufferHeight, sourcePitch * 4);
774 pCairo->pCairo = cairo_create(pCairo->pCairoSurface);
779 __InitFgBgColorFromTheme();
784 delete this->__pScratchPad;
785 this->__pScratchPad = null;
787 delete this->__pSurface;
788 this->__pSurface = null;
794 _Canvas::Construct(_Canvas* pSourceCanvas, const Rectangle& subRegion)
796 SysTryReturnResult(NID_GRP, pSourceCanvas, E_INVALID_ARG, "The source canvas is invalid");
798 SysTryReturnResult(NID_GRP, pSourceCanvas->IsValid(), E_INVALID_ARG, "The source canvas is invalid");
800 result r = E_SUCCESS;
802 int x1 = subRegion.x;
803 int y1 = subRegion.y;
804 int x2 = x1 + subRegion.width;
805 int y2 = y1 + subRegion.height;
817 if (x2 > pSourceCanvas->GetBounds().width)
819 x2 = pSourceCanvas->GetBounds().width;
822 if (y2 > pSourceCanvas->GetBounds().height)
824 y2 = pSourceCanvas->GetBounds().height;
827 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);
829 int bufferWidth = x2 - x1;
830 int bufferHeight = y2 - y1;
832 int sourcePitch = pSourceCanvas->__pSurface->GetPitch();
834 if (pSourceCanvas->__windowHandle != INVALID_HANDLE)
836 _GenericBufferFrameBuffer<SystemPixel>* pTemp = new (std::nothrow) _GenericBufferFrameBuffer<SystemPixel>(pSourceCanvas->__windowHandle, x1, y1, bufferWidth, bufferHeight, sourcePitch);
838 SysTryReturnResult(NID_GRP, pTemp, E_OUT_OF_MEMORY, "_GenericBufferFrameBuffer<> cannot be allocated.");
840 if (pTemp->GetBufferAddr() == null && bufferWidth > 0 && bufferHeight > 0)
843 SysTryReturnResult(NID_GRP, false, E_SYSTEM, "The associated Evas buffer is NULL.");
846 this->__pSurface = new (std::nothrow) _Util::GenericBuffer<SystemPixel>(pTemp);
848 if (this->__pSurface == null)
851 SysTryReturnResult(NID_GRP, false, E_OUT_OF_MEMORY, "_Util::GenericBuffer<> cannot be allocated.");
856 SystemPixel* pBuffer = pSourceCanvas->__pSurface->GetBufferAddr();
857 pBuffer += y1 * sourcePitch + x1;
859 _GenericBufferFrameBuffer<SystemPixel>* pTemp = new (std::nothrow) _GenericBufferFrameBuffer<SystemPixel>(pBuffer, bufferWidth, bufferHeight, sourcePitch);
861 SysTryReturnResult(NID_GRP, pTemp, E_OUT_OF_MEMORY, "_GenericBufferFrameBuffer<> cannot be allocated.");
863 this->__pSurface = new (std::nothrow) _Util::GenericBuffer<SystemPixel>(pTemp);
865 if (this->__pSurface == null)
868 SysTryReturnResult(NID_GRP, false, E_OUT_OF_MEMORY, "_Util::GenericBuffer<> cannot be allocated.");
872 this->__pBuffer = (unsigned long*) __pSurface->GetBufferAddr();
873 this->__pScratchPad = new (std::nothrow) _Util::ScratchPad<SystemPixel>(__pBuffer, bufferWidth, bufferHeight, sourcePitch);
875 SysTryCatch(NID_GRP, this->__pScratchPad, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] _Util::ScratchPad<> cannot be allocated.");
877 this->__pParent = pSourceCanvas;
878 this->__xBufferPos = x1;
879 this->__yBufferPos = y1;
882 // must re-assign by _CanvasImpl::GetSubCanvasN()
883 this->__pFont = pSourceCanvas->__pFont;
885 this->__pPriorityFont = pSourceCanvas->__pPriorityFont;
888 this->__windowHandle = pSourceCanvas->__windowHandle;
889 this->__blendOption = pSourceCanvas->__blendOption;
890 this->__fgColor = pSourceCanvas->__fgColor;
891 this->__bgColor = pSourceCanvas->__bgColor;
892 this->__fgColorNative = pSourceCanvas->__fgColorNative;
893 this->__bgColorNative = pSourceCanvas->__bgColorNative;
894 this->__fgOpacity = pSourceCanvas->__fgOpacity;
895 this->__bgOpacity = pSourceCanvas->__bgOpacity;
896 this->__lineWidth = pSourceCanvas->__lineWidth;
897 this->__lineStyle = pSourceCanvas->__lineStyle;
900 this->__isClipBoundsSet = false;
901 this->__clipBounds = Rectangle(0, 0, bufferWidth, bufferHeight);
903 #if defined(USE_CAIRO)
905 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
909 pCairo->pCairoSurface = cairo_image_surface_create_for_data((unsigned char*) this->__pBuffer, CAIRO_FORMAT_ARGB32, bufferWidth, bufferHeight, sourcePitch * 4);
910 pCairo->pCairo = cairo_create(pCairo->pCairoSurface);
918 delete this->__pScratchPad;
919 this->__pScratchPad = null;
921 delete this->__pSurface;
922 this->__pSurface = null;
928 _Canvas::Construct(const BufferInfo& bufferInfo)
930 // all parameters checked
932 result r = E_SUCCESS;
934 _GenericBufferFrameBuffer<SystemPixel>* pTemp = new (std::nothrow) _GenericBufferFrameBuffer<SystemPixel>(static_cast<SystemPixel*>(bufferInfo.pPixels), bufferInfo.width, bufferInfo.height, bufferInfo.pitch * 8 / bufferInfo.bitsPerPixel);
936 SysTryReturnResult(NID_GRP
939 , " _GenericBufferFrameBuffer<> cannot be allocated.");
941 this->__pSurface = new (std::nothrow) _Util::GenericBuffer<SystemPixel>(pTemp);
945 , delete pTemp; r = E_OUT_OF_MEMORY
947 , "[E_OUT_OF_MEMORY] _Util::GenericBuffer<> cannot be allocated.");
949 this->__pBuffer = (unsigned long*) __pSurface->GetBufferAddr();
950 this->__pScratchPad = new (std::nothrow) _Util::ScratchPad<SystemPixel>(__pBuffer, bufferInfo.width, bufferInfo.height, bufferInfo.pitch * 8 / bufferInfo.bitsPerPixel);
953 , this->__pScratchPad
954 , r = E_OUT_OF_MEMORY
956 , "[E_OUT_OF_MEMORY] _Util::ScratchPad<> cannot be allocated.");
958 this->__xBufferPos = 0;
959 this->__yBufferPos = 0;
961 #if defined(USE_CAIRO)
963 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
967 pCairo->pCairoSurface = cairo_image_surface_create_for_data((unsigned char*) this->__pBuffer, CAIRO_FORMAT_ARGB32, bufferInfo.width, bufferInfo.height, bufferInfo.pitch);
968 pCairo->pCairo = cairo_create(pCairo->pCairoSurface);
973 __InitFgBgColorFromTheme();
978 delete this->__pScratchPad;
979 this->__pScratchPad = null;
981 delete this->__pSurface;
982 this->__pSurface = null;
988 _Canvas::IsValid() const
990 return (this && this->__pSurface);
996 if (this->__isClipBoundsSet)
998 _Util::Rectangle<int> clip =
1000 this->__clipBounds.x,
1001 this->__clipBounds.y,
1002 this->__clipBounds.width,
1003 this->__clipBounds.height
1006 _Util::Rectangle<int> rect =
1010 __pScratchPad->GetWidth(),
1011 __pScratchPad->GetHeight()
1014 _ClearRectangleWithClip(__pScratchPad, __bgColor, rect, clip);
1018 __pScratchPad->FillRect(0, 0, __pScratchPad->GetWidth(), __pScratchPad->GetHeight(), __bgColor);
1025 _Canvas::Clear(const Rectangle& rect)
1027 if ((rect.width == 0) || (rect.height == 0))
1032 if (this->__isClipBoundsSet)
1034 _Util::Rectangle<int> clip =
1036 this->__clipBounds.x,
1037 this->__clipBounds.y,
1038 this->__clipBounds.width,
1039 this->__clipBounds.height
1042 _Util::Rectangle<int> rect1 =
1050 _ClearRectangleWithClip(__pScratchPad, __bgColor, rect1, clip);
1054 __pScratchPad->FillRect(rect.x, rect.y, rect.width, rect.height, __bgColor);
1061 _Canvas::Copy(const Point& destPoint, const _Canvas& canvas, const Rectangle& srcRect)
1064 if (srcRect.width == 0 || srcRect.height == 0)
1069 return this->__Copy(destPoint, canvas, srcRect);
1073 _Canvas::Copy(const Rectangle& destRect, const _Canvas& canvas, const Rectangle& srcRect)
1076 if (srcRect.width == 0 || srcRect.height == 0 || destRect.width == 0 || destRect.height == 0)
1081 return this->__Copy(destRect, canvas, srcRect);
1085 _Canvas::Copy(const Point& destPoint, const _Canvas& canvas, const Rectangle& srcRect, CompositeMode compositeMode)
1087 _Util::LockManager srcLock(canvas);
1088 _Util::LockManager dstLock(*this);
1090 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source canvas cannot be locked.");
1091 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked");
1093 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1094 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1097 _Util::Pixmap srcImageUnclipped(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1098 _Util::Pixmap srcImage = srcImageUnclipped.GetSubBitmap(srcRect.x, srcRect.y, srcRect.width, srcRect.height);
1100 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1101 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(destPoint.x, destPoint.y, srcRect.width, srcRect.height);
1103 _Pixman::CopyPixmap(dstImage, srcImage, GetDrawingQuality(), compositeMode);
1110 _Canvas::CopyReverse(const Point& destPoint, const _Canvas& srcCanvas, const Rectangle& srcRect)
1113 if (srcRect.width == 0 || srcRect.height == 0)
1118 if (__pScratchPad == null)
1123 const _Canvas* pSrcCanvas = &srcCanvas;
1125 if (pSrcCanvas == null)
1130 if (pSrcCanvas->__pScratchPad == null)
1135 Rectangle clippedSrcRect(srcRect);
1137 if (_ClipRectangle(clippedSrcRect.x, clippedSrcRect.y, clippedSrcRect.width, clippedSrcRect.height, 0, 0, pSrcCanvas->__pScratchPad->GetWidth(), pSrcCanvas->__pScratchPad->GetHeight()) == CLIP_REJECT)
1142 __pScratchPad->RegisterBitBlt(_RasterOp::FnBitBlt32BitCopyReverse);
1143 __pScratchPad->BitBlt(destPoint.x, destPoint.y, pSrcCanvas->__pScratchPad, clippedSrcRect.x, clippedSrcRect.y, clippedSrcRect.width, clippedSrcRect.height);
1144 __pScratchPad->RegisterBitBlt(null);
1152 // spec. from SDK 1.0
1154 template<typename T>
1156 _ReviseAngle(T& startAngle, T& endAngle)
1162 // startAngle = startAngle % twoPi;
1163 int mod = int(startAngle / twoPi);
1164 startAngle = startAngle - twoPi * mod;
1166 //endAngle = endAngle % twoPi;
1167 mod = int(endAngle / twoPi);
1168 endAngle = endAngle - twoPi * mod;
1171 if (startAngle < zeroPi || endAngle < zeroPi)
1173 startAngle += twoPi;
1177 if (startAngle > endAngle)
1186 _Canvas::DrawArc(const _Util::Rectangle<double>& bounds, double startAngle, double endAngle, ArcStyle arcStyle)
1188 if ((bounds.w <= 0.0) || (bounds.h <= 0.0))
1193 // this->__lineWidth is always greater than 0
1195 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
1197 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
1199 if (pCairo && pCairo->pCairo)
1201 SET_CAIRO_ALL_PROPERTIES;
1203 double startDstAngle = (180.0 / M_PI) * atan2(sin(startAngle*M_PI / 180.0) * bounds.w / bounds.h, cos(startAngle * M_PI / 180.0));
1204 double endDstAngle = (180.0 / M_PI) * atan2(sin(endAngle * M_PI / 180.0) * bounds.w / bounds.h, cos(endAngle * M_PI / 180.0));
1206 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;
1207 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;
1209 _ReviseAngle(startDstAngle, endDstAngle);
1213 case ARC_STYLE_ONLY:
1214 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
1216 _Cairo::DrawArc(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::DRAW_ARC_STYLE_ARC);
1220 _Cairo::DrawArc(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::DRAW_ARC_STYLE_ARC);
1225 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
1227 _Cairo::DrawArc(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::DRAW_ARC_STYLE_PIE);
1231 _Cairo::DrawArc(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::DRAW_ARC_STYLE_PIE);
1235 case ARC_STYLE_CHORD:
1236 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
1238 _Cairo::DrawArc(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::DRAW_ARC_STYLE_CHORD);
1242 _Cairo::DrawArc(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::DRAW_ARC_STYLE_CHORD);
1246 case ARC_STYLE_FILLED_PIE:
1247 _Cairo::FillArc(pCairo->pCairo, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::FILL_ARC_STYLE_PIE);
1250 case ARC_STYLE_FILLED_CHORD:
1251 _Cairo::FillArc(pCairo->pCairo, composedColor, bounds, startDstAngle, endDstAngle, _Cairo::FILL_ARC_STYLE_CHORD);
1258 RESET_CAIRO_ALL_PROPERTIES;
1267 memset(&info, 0, sizeof(info));
1269 SystemPixel* pBufferAddr = null;
1270 int bufferPitch = 0;
1272 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
1274 info.width = __pScratchPad->GetWidth();
1275 info.height = __pScratchPad->GetHeight();
1276 info.bitsPerPixel = 32;
1277 info.pixelPerLine = bufferPitch;
1278 info.pPixels = (void*) pBufferAddr;
1279 info.color32 = composedColor;
1280 info.isClipBoundsSet = this->__isClipBoundsSet;
1281 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
1283 arc.SetLineWidth(this->__lineWidth.asInteger);
1285 _ReviseAngle(startAngle, endAngle);
1287 return arc.DrawArc(int(bounds.x), int(bounds.y), int(bounds.w), int(bounds.h), int(startAngle), int(endAngle), arcStyle, info);
1292 _Canvas::DrawBitmap(const _Util::Rectangle<double>& rectD, const _Bitmap& bitmap)
1294 SysTryReturnResult(NID_GRP, &bitmap && bitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
1296 if (rectD.w <= 0 || rectD.h <= 0)
1301 int alphaConstant = this->_GetAlphaAttenuation(bitmap);
1305 this->__GetClipBounds(clipRect);
1307 _Util::Rectangle<int> rect =
1309 _DoubleToIntForPos(rectD.x),
1310 _DoubleToIntForPos(rectD.y),
1311 _DoubleToIntForSize(rectD.w),
1312 _DoubleToIntForSize(rectD.h)
1318 _Util::LockManagerFast srcLock(bitmap);
1319 _Util::LockManagerFast dstLock(*this);
1321 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1322 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1324 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1325 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1328 if (!this->__useStableRenderer && srcBufferInfo.bitsPerPixel == 32 && (GetCompositeMode() != COMPOSITE_MODE_SRC_OVER || bitmap.__isPremultiplied))
1330 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1331 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1333 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1334 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1336 if (alphaConstant < 255)
1338 std::unique_ptr<_Util::Pixmap> modifiedSrcImage(srcImage.GetAlphaAttenuatedPixmap(alphaConstant));
1340 if (modifiedSrcImage != null)
1342 pass = _Pixman::ScalePixmap(dstImage, *modifiedSrcImage.get(), GetDrawingQuality(), GetCompositeMode(), rectD.x - clipRect.x, rectD.y - clipRect.y, rectD.w, rectD.h);
1348 pass = _Pixman::ScalePixmap(dstImage, srcImage, GetDrawingQuality(), GetCompositeMode(), rectD.x - clipRect.x, rectD.y - clipRect.y, rectD.w, rectD.h);
1353 if (!pass && alphaConstant >= 255)
1355 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1356 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1358 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1359 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1361 pass = Tizen::Graphics::_Effect::ScaleImage(dstImage, rect.x - clipRect.x, rect.y - clipRect.y, rect.w, rect.h, srcImage, _ConvertParam<_Effect::Rop>(this->__blendOption));
1373 _Util::Pixmap tmpImage(rect.w, rect.h, bitmap.GetBitsPerPixel());
1375 // copies the source bitmap to the scaled bitmap
1377 // ykahn, 2011/10/11 patched
1379 _ApplySrcBitmapAttrib(tmpImage, bitmap, bitmap.__isOpaqueAllOver);
1381 if (tmpImage.depth == 16)
1383 if (tmpImage.enableColorKey)
1385 typedef unsigned short Pixel;
1387 Pixel colorKey = (Pixel) tmpImage.colorKey;
1388 Pixel* pDest = (Pixel*) tmpImage.pBitmap;
1389 Pixel* pDestEnd = pDest + (tmpImage.bytesPerLine * tmpImage.height / (tmpImage.depth / 8));
1391 while (pDest < pDestEnd)
1393 *pDest++ = colorKey;
1401 else if (tmpImage.depth == 32)
1403 typedef unsigned long Pixel;
1405 Pixel fillColor = 0;
1406 Pixel* pDest = (Pixel*) tmpImage.pBitmap;
1407 Pixel* pDestEnd = pDest + (tmpImage.bytesPerLine * tmpImage.height / (tmpImage.depth / 8));
1409 while (pDest < pDestEnd)
1411 *pDest++ = fillColor;
1419 _Util::LockManagerFast srcLock(bitmap);
1420 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1422 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1425 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1426 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1428 pass = Tizen::Graphics::_Effect::ScaleImage(tmpImage, 0, 0, rect.w, rect.h, srcImage, Tizen::Graphics::_Effect::ROP_COPY);
1432 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1439 _Util::LockManagerFast dstLock(*this);
1440 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1442 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1445 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1446 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1448 pass = Tizen::Graphics::_Effect::DrawImageWithAlpha(dstImage, rect.x - clipRect.x, rect.y - clipRect.y, tmpImage, alphaConstant);
1452 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1460 _Canvas::DrawBitmap(const _Util::Point<double>& pointD, const _Bitmap& bitmap)
1462 SysTryReturnResult(NID_GRP, &bitmap && bitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
1464 int alphaConstant = this->_GetAlphaAttenuation(bitmap);
1469 this->__GetClipBounds(clipRect);
1474 _Util::Point<int> point =
1476 _DoubleToIntForPos(pointD.x),
1477 _DoubleToIntForPos(pointD.y)
1480 _Util::LockManagerFast srcLock(bitmap);
1481 _Util::LockManagerFast dstLock(*this);
1483 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1484 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1486 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1487 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1490 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1491 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1493 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1494 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1496 if (srcBufferInfo.pixelFormat == PIXEL_FORMAT_RGB565 && srcImage.enableColorKey == 0 && dstBufferInfo.pixelFormat == PIXEL_FORMAT_ARGB8888 && !this->__isClipBoundsSet && alphaConstant >= 255)
1498 pixman_image_t* pPixmanSrc = pixman_image_create_bits(PIXMAN_r5g6b5, srcBufferInfo.width, srcBufferInfo.height, (uint32_t*)srcBufferInfo.pPixels, srcBufferInfo.pitch);
1499 pixman_image_t* pPixmanDst = pixman_image_create_bits(PIXMAN_a8r8g8b8, dstBufferInfo.width, dstBufferInfo.height, (uint32_t*)dstBufferInfo.pPixels, dstBufferInfo.pitch);
1501 if (pPixmanSrc && pPixmanDst)
1503 pixman_image_composite32(PIXMAN_OP_SRC, pPixmanSrc, NULL, pPixmanDst, 0, 0, 0, 0, point.x, point.y, srcBufferInfo.width, srcBufferInfo.height);
1509 pixman_image_unref(pPixmanDst);
1514 pixman_image_unref(pPixmanSrc);
1519 bool isPixmanSupported = (!this->__useStableRenderer && (GetCompositeMode() != COMPOSITE_MODE_SRC_OVER || bitmap.__isPremultiplied));
1521 if (isPixmanSupported)
1525 isPixmanSupported = !((bitmap.GetBitsPerPixel() == 16) && (bitmap.GetMaskingColor(color) == E_SUCCESS));
1528 if (isPixmanSupported)
1530 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1531 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1533 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1534 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1536 if (alphaConstant < 255)
1538 std::unique_ptr<_Util::Pixmap> modifiedSrcImage(srcImage.GetAlphaAttenuatedPixmap(alphaConstant));
1540 if (modifiedSrcImage != null)
1542 pass = _Pixman::CopyPixmap(dstImage, *modifiedSrcImage.get(), GetDrawingQuality(), GetCompositeMode(), pointD.x - clipRect.x, pointD.y - clipRect.y);
1548 pass = _Pixman::CopyPixmap(dstImage, srcImage, GetDrawingQuality(), GetCompositeMode(), pointD.x - clipRect.x, pointD.y - clipRect.y);
1554 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1555 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1557 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1558 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1560 pass = Tizen::Graphics::_Effect::DrawImageWithAlpha(dstImage, point.x - clipRect.x, point.y - clipRect.y, srcImage, alphaConstant);
1565 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1572 _Canvas::DrawBitmap(const _Util::Point<int>& point, const _Bitmap& bitmap)
1574 SysTryReturnResult(NID_GRP, &bitmap && bitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
1576 int alphaConstant = this->_GetAlphaAttenuation(bitmap);
1580 this->__GetClipBounds(clipRect);
1585 _Util::LockManagerFast srcLock(bitmap);
1586 _Util::LockManagerFast dstLock(*this);
1588 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1589 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1591 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1592 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1595 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1596 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1598 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1599 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x,clipRect.y, clipRect.width, clipRect.height);
1601 if (srcBufferInfo.pixelFormat == PIXEL_FORMAT_RGB565 && srcImage.enableColorKey == 0 && dstBufferInfo.pixelFormat == PIXEL_FORMAT_ARGB8888 && !this->__isClipBoundsSet)
1603 pixman_image_t* pPixmanSrc = pixman_image_create_bits(PIXMAN_r5g6b5, srcBufferInfo.width, srcBufferInfo.height, (uint32_t*)srcBufferInfo.pPixels, srcBufferInfo.pitch);
1604 pixman_image_t* pPixmanDst = pixman_image_create_bits(PIXMAN_a8r8g8b8, dstBufferInfo.width, dstBufferInfo.height, (uint32_t*)dstBufferInfo.pPixels, dstBufferInfo.pitch);
1606 if (pPixmanSrc && pPixmanDst)
1608 pixman_image_composite32(PIXMAN_OP_SRC, pPixmanSrc,NULL, pPixmanDst, 0, 0, 0, 0, point.x, point.y, srcBufferInfo.width, srcBufferInfo.height);
1614 pixman_image_unref(pPixmanDst);
1619 pixman_image_unref(pPixmanSrc);
1627 bool isPixmanSupported = !(bitmap.__isOpaqueAllOver && GetCompositeMode() == COMPOSITE_MODE_SRC_OVER) && (!this->__useStableRenderer || bitmap.__isPremultiplied);
1629 if (isPixmanSupported)
1633 isPixmanSupported = !((bitmap.GetBitsPerPixel() == 16) && (bitmap.GetMaskingColor(color) == E_SUCCESS));
1636 if (isPixmanSupported)
1638 _Util::Rectangle<int> outRect = { 0, 0, -1, -1 };
1639 _Util::Rectangle<int> dstRect = { point.x, point.y, srcBufferInfo.width, srcBufferInfo.height };
1640 _Util::Rectangle<int> tgtRect = { clipRect.x, clipRect.y, clipRect.width, clipRect.height };
1642 if (_Util::IntersectRect(outRect, tgtRect, dstRect))
1644 _Util::Bounds<int> outBounds = { outRect.x, outRect.y, outRect.x + outRect.w, outRect.y + outRect.h };
1645 _Util::Bounds<int> dstBounds = { dstRect.x, dstRect.y, dstRect.x + dstRect.w, dstRect.y + dstRect.h };
1646 _Util::Bounds<int> srcBounds =
1649 (outBounds.x1 - dstBounds.x1),
1650 (outBounds.y1 - dstBounds.y1),
1651 srcBufferInfo.width + (outBounds.x2 - dstBounds.x2),
1652 srcBufferInfo.height + (outBounds.y2 - dstBounds.y2),
1655 srcBounds.x1 = (srcBounds.x1 >= 0) ? srcBounds.x1 :0;
1656 srcBounds.y1 = (srcBounds.y1 >= 0) ? srcBounds.y1 :0;
1657 srcBounds.x2 = (srcBounds.x2 <= srcBufferInfo.width) ? srcBounds.x2 : srcBufferInfo.width;
1658 srcBounds.y2 = (srcBounds.y2 <= srcBufferInfo.height) ? srcBounds.y2 : srcBufferInfo.height;
1660 _Util::Pixmap srcImageUnclipped(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1661 _Util::Pixmap srcImage = srcImageUnclipped.GetSubBitmap(srcBounds.x1, srcBounds.y1, srcBounds.x2 - srcBounds.x1, srcBounds.y2 - srcBounds.y1);
1662 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1664 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1665 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(outRect.x, outRect.y, outRect.w, outRect.h);
1667 pixman_transform_t transform;
1668 pixman_transform_init_identity(&transform);
1670 if (alphaConstant < 255)
1672 std::unique_ptr<_Util::Pixmap> modifiedSrcImage(srcImage.GetAlphaAttenuatedPixmap(alphaConstant));
1674 if (modifiedSrcImage != null)
1676 pass = _Pixman::CopyPixmap(dstImage, *modifiedSrcImage.get(), GetDrawingQuality(), GetCompositeMode());
1682 pass = _Pixman::CopyPixmap(dstImage, srcImage, GetDrawingQuality(), GetCompositeMode());
1689 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1690 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
1692 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1693 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1694 pass = Tizen::Graphics::_Effect::DrawImageWithAlpha(dstImage, point.x - clipRect.x, point.y - clipRect.y, srcImage, alphaConstant);
1699 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1706 _Canvas::DrawBitmap(const _Util::Rectangle<double>& destRectD, const _Bitmap& srcBitmap, const _Util::Rectangle<double>& srcRectD)
1708 SysTryReturnResult(NID_GRP, &srcBitmap && srcBitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
1710 if (srcRectD.w == 0 || srcRectD.h == 0)
1715 if (destRectD.w == 0 || destRectD.h == 0)
1720 int alphaConstant = this->_GetAlphaAttenuation(srcBitmap);
1724 this->__GetClipBounds(clipRect);
1726 _Util::Rectangle<int> destRect =
1728 _DoubleToIntForPos(destRectD.x),
1729 _DoubleToIntForPos(destRectD.y),
1730 _DoubleToIntForSize(destRectD.w),
1731 _DoubleToIntForSize(destRectD.h)
1734 _Util::Rectangle<int> srcRect =
1736 _DoubleToIntForPos(srcRectD.x),
1737 _DoubleToIntForPos(srcRectD.y),
1738 _DoubleToIntForSize(srcRectD.w),
1739 _DoubleToIntForSize(srcRectD.h)
1745 _Util::LockManagerFast srcLock(srcBitmap);
1746 _Util::LockManagerFast dstLock(*this);
1748 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1749 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1751 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1752 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1755 if (!this->__useStableRenderer && srcBufferInfo.bitsPerPixel == 32 && (GetCompositeMode() != COMPOSITE_MODE_SRC_OVER || srcBitmap.__isPremultiplied))
1757 _Util::Pixmap srcImageUnclipped(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1758 _Util::Pixmap srcImage = srcImageUnclipped.GetSubBitmap(srcRect.x, srcRect.y, srcRect.w, srcRect.h);
1759 _ApplySrcBitmapAttrib(srcImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
1761 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1762 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1764 if (alphaConstant < 255)
1766 std::unique_ptr<_Util::Pixmap> modifiedSrcImage(srcImage.GetAlphaAttenuatedPixmap(alphaConstant));
1768 if (modifiedSrcImage != null)
1770 pass = _Pixman::ScalePixmap(dstImage, *modifiedSrcImage.get(), GetDrawingQuality(), GetCompositeMode(), destRectD.x - clipRect.x, destRectD.y - clipRect.y, destRectD.w, destRectD.h);
1776 pass = _Pixman::ScalePixmap(dstImage, srcImage, GetDrawingQuality(), GetCompositeMode(), destRectD.x - clipRect.x, destRectD.y - clipRect.y, destRectD.w, destRectD.h);
1780 if (!pass && alphaConstant >= 255)
1782 unsigned char* pPixels = (unsigned char*) srcBufferInfo.pPixels + srcRect.y * srcBufferInfo.pitch + srcRect.x * (srcBufferInfo.bitsPerPixel / 8);
1784 _Util::Pixmap srcImage(srcRect.w, srcRect.h, srcBufferInfo.bitsPerPixel, (void*) pPixels, srcBufferInfo.pitch);
1785 _ApplySrcBitmapAttrib(srcImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
1787 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1788 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1790 pass = Tizen::Graphics::_Effect::ScaleImage(dstImage, destRect.x - clipRect.x, destRect.y - clipRect.y, destRect.w, destRect.h, srcImage, _ConvertParam<_Effect::Rop>(this->__blendOption));
1802 _Util::Pixmap tmpImage(destRect.w, destRect.h, srcBitmap.GetBitsPerPixel());
1804 // copies the source bitmap to the scaled bitmap
1806 // ykahn, 2011/10/11 patched
1808 _ApplySrcBitmapAttrib(tmpImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
1810 if (tmpImage.depth == 16)
1812 if (tmpImage.enableColorKey)
1814 typedef unsigned short Pixel;
1816 Pixel colorKey = (Pixel) tmpImage.colorKey;
1817 Pixel* pDest = (Pixel*) tmpImage.pBitmap;
1818 Pixel* pDestEnd = pDest + (tmpImage.bytesPerLine * tmpImage.height / (tmpImage.depth / 8));
1820 while (pDest < pDestEnd)
1822 *pDest++ = colorKey;
1829 else if (tmpImage.depth == 32)
1831 typedef unsigned long Pixel;
1833 Pixel fillColor = 0;
1834 Pixel* pDest = (Pixel*) tmpImage.pBitmap;
1835 Pixel* pDestEnd = pDest + (tmpImage.bytesPerLine * tmpImage.height / (tmpImage.depth / 8));
1837 while (pDest < pDestEnd)
1839 *pDest++ = fillColor;
1847 _Util::LockManagerFast srcLock(srcBitmap);
1848 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1850 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1853 unsigned char* pPixels = (unsigned char*) srcBufferInfo.pPixels + srcRect.y * srcBufferInfo.pitch + srcRect.x * (srcBufferInfo.bitsPerPixel / 8);
1855 _Util::Pixmap srcImage(srcRect.w, srcRect.h, srcBufferInfo.bitsPerPixel, (void*) pPixels, srcBufferInfo.pitch);
1856 _ApplySrcBitmapAttrib(srcImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
1858 pass = Tizen::Graphics::_Effect::ScaleImage(tmpImage, 0, 0, destRect.w, destRect.h, srcImage, Tizen::Graphics::_Effect::ROP_COPY);
1862 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1869 _Util::LockManagerFast dstLock(*this);
1870 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1872 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1875 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1876 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1878 pass = Tizen::Graphics::_Effect::DrawImageWithAlpha(dstImage, destRect.x - clipRect.x, destRect.y - clipRect.y, tmpImage, alphaConstant);
1882 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
1890 _Canvas::DrawBitmapForNinePatchedBitmap(const Rectangle& destRect, const _Bitmap& srcBitmap, const Rectangle& srcRect, bool copyOnly)
1892 SysTryReturnResult(NID_GRP, &srcBitmap && srcBitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
1894 if (srcRect.width == 0 || srcRect.height == 0)
1899 if (destRect.width == 0 || destRect.height == 0)
1904 int alphaConstant = this->_GetAlphaAttenuation(srcBitmap);
1908 this->__GetClipBounds(clipRect);
1913 _Util::LockManagerFast srcLock(srcBitmap);
1914 _Util::LockManagerFast dstLock(*this);
1916 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
1917 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
1919 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
1920 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
1923 if (srcBufferInfo.bitsPerPixel == 32 && (GetCompositeMode() != COMPOSITE_MODE_SRC_OVER || srcBitmap.__isPremultiplied))
1925 _Util::Rectangle<int> outRect = { 0, 0, -1, -1 };
1926 _Util::Rectangle<int> dstRect = { destRect.x, destRect.y, destRect.width, destRect.height };
1927 _Util::Rectangle<int> tgtRect = { clipRect.x, clipRect.y, clipRect.width, clipRect.height };
1929 _Util::IntersectRect(outRect, tgtRect, dstRect);
1931 // assert(destRect.width > 0 && destRect.height > 0);
1933 _Util::Bounds<int> outBounds = { outRect.x, outRect.y, outRect.x + outRect.w, outRect.y + outRect.h };
1934 _Util::Bounds<int> dstBounds = { dstRect.x, dstRect.y, dstRect.x + dstRect.w, dstRect.y + dstRect.h };
1935 _Util::Bounds<int> srcBounds =
1937 srcRect.x + (outBounds.x1 - dstBounds.x1) * srcRect.width / (dstBounds.x2 - dstBounds.x1),
1938 srcRect.y + (outBounds.y1 - dstBounds.y1) * srcRect.height / (dstBounds.y2 - dstBounds.y1),
1939 (srcRect.x + srcRect.width) + (outBounds.x2 - dstBounds.x2) * srcRect.width / (dstBounds.x2 - dstBounds.x1),
1940 (srcRect.y + srcRect.height) + (outBounds.y2 - dstBounds.y2) * srcRect.height / (dstBounds.y2 - dstBounds.y1),
1943 srcBounds.x1 = (srcBounds.x1 >= srcRect.x) ? srcBounds.x1 : srcRect.x;
1944 srcBounds.y1 = (srcBounds.y1 >= srcRect.y) ? srcBounds.y1 : srcRect.y;
1945 srcBounds.x2 = (srcBounds.x2 <= (srcRect.x + srcRect.width)) ? srcBounds.x2 : (srcRect.x + srcRect.width);
1946 srcBounds.y2 = (srcBounds.y2 <= (srcRect.y + srcRect.height)) ? srcBounds.y2 : (srcRect.y + srcRect.height);
1948 _Util::Pixmap srcImageUnclipped(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
1949 _Util::Pixmap srcImage = srcImageUnclipped.GetSubBitmap(srcBounds.x1, srcBounds.y1, srcBounds.x2 - srcBounds.x1, srcBounds.y2 - srcBounds.y1);
1950 _ApplySrcBitmapAttrib(srcImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
1953 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1954 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(outRect.x, outRect.y, outRect.w, outRect.h);
1958 pass = _Pixman::ScalePixmapOpCopy(dstImage, srcImage, GetDrawingQuality());
1962 if (alphaConstant < 255)
1964 std::unique_ptr<_Util::Pixmap> modifiedSrcImage(srcImage.GetAlphaAttenuatedPixmap(alphaConstant));
1966 if (modifiedSrcImage != null)
1968 pass = _Pixman::ScalePixmap(dstImage, *modifiedSrcImage.get(), GetDrawingQuality(), GetCompositeMode());
1974 pass = _Pixman::ScalePixmap(dstImage, srcImage, GetDrawingQuality(), GetCompositeMode());
1978 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
1982 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(outRect.x, outRect.y, outRect.w, outRect.h);
1984 pass = _Pixman::ScalePixmapOpCopy(dstImage, srcImage, GetDrawingQuality());
1988 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
1990 if (alphaConstant < 255)
1992 std::unique_ptr<_Util::Pixmap> modifiedSrcImage(srcImage.GetAlphaAttenuatedPixmap(alphaConstant));
1994 if (modifiedSrcImage != null)
1996 pass = _Pixman::ScalePixmap(dstImage, *modifiedSrcImage.get(), GetDrawingQuality(), GetCompositeMode(), destRect.x - clipRect.x, destRect.y - clipRect.y, destRect.width, destRect.height);
2002 pass = _Pixman::ScalePixmap(dstImage, srcImage, GetDrawingQuality(), GetCompositeMode(), destRect.x - clipRect.x, destRect.y - clipRect.y, destRect.width, destRect.height);
2008 if (!pass && alphaConstant >= 255)
2010 unsigned char* pPixels = (unsigned char*) srcBufferInfo.pPixels + srcRect.y * srcBufferInfo.pitch + srcRect.x * (srcBufferInfo.bitsPerPixel / 8);
2012 _Util::Pixmap srcImage(srcRect.width, srcRect.height, srcBufferInfo.bitsPerPixel, (void*) pPixels, srcBufferInfo.pitch);
2013 _ApplySrcBitmapAttrib(srcImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
2015 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
2016 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
2020 pass = Tizen::Graphics::_Effect::ScaleImage(dstImage, destRect.x - clipRect.x, destRect.y - clipRect.y, destRect.width, destRect.height, srcImage, Tizen::Graphics::_Effect::ROP_COPY);
2024 pass = Tizen::Graphics::_Effect::ScaleImage(dstImage, destRect.x - clipRect.x, destRect.y - clipRect.y, destRect.width, destRect.height, srcImage, _ConvertParam<_Effect::Rop>(this->__blendOption));
2034 _Util::Pixmap tmpImage(destRect.width, destRect.height, srcBitmap.GetBitsPerPixel());
2036 // copies the source bitmap to the scaled bitmap
2038 // ykahn, 2011/10/11 patched
2040 _ApplySrcBitmapAttrib(tmpImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
2042 if (tmpImage.depth == 16)
2044 if (tmpImage.enableColorKey)
2046 typedef unsigned short Pixel;
2048 Pixel colorKey = (Pixel) tmpImage.colorKey;
2049 Pixel* pDest = (Pixel*) tmpImage.pBitmap;
2050 Pixel* pDestEnd = pDest + (tmpImage.bytesPerLine * tmpImage.height / (tmpImage.depth / 8));
2052 while (pDest < pDestEnd)
2054 *pDest++ = colorKey;
2061 else if (tmpImage.depth == 32)
2063 typedef unsigned long Pixel;
2065 Pixel fillColor = 0;
2066 Pixel* pDest = (Pixel*) tmpImage.pBitmap;
2067 Pixel* pDestEnd = pDest + (tmpImage.bytesPerLine * tmpImage.height / (tmpImage.depth / 8));
2069 while (pDest < pDestEnd)
2071 *pDest++ = fillColor;
2076 bool scaled = false;
2079 _Util::LockManagerFast srcLock(srcBitmap);
2080 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
2082 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
2085 unsigned char* pPixels = (unsigned char*) srcBufferInfo.pPixels + srcRect.y * srcBufferInfo.pitch + srcRect.x * (srcBufferInfo.bitsPerPixel / 8);
2087 _Util::Pixmap srcImage(srcRect.width, srcRect.height, srcBufferInfo.bitsPerPixel, (void*) pPixels, srcBufferInfo.pitch);
2088 _ApplySrcBitmapAttrib(srcImage, srcBitmap, srcBitmap.__isOpaqueAllOver);
2090 scaled = Tizen::Graphics::_Effect::ScaleImage(tmpImage, 0, 0, destRect.width, destRect.height, srcImage, Tizen::Graphics::_Effect::ROP_COPY);
2094 SysTryReturnResult(NID_GRP, scaled, E_INVALID_ARG, "The source bitmap is invalid.\n");
2098 _Util::LockManagerFast dstLock(*this);
2099 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
2101 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
2104 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
2105 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
2107 pass = Tizen::Graphics::_Effect::DrawImageWithAlpha(dstImage, destRect.x - clipRect.x, destRect.y - clipRect.y, tmpImage, alphaConstant);
2112 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
2118 _Canvas::DrawBitmap(const _Util::Point<double>& pointD, const _Bitmap& bitmap, FlipDirection dir)
2120 SysTryReturnResult(NID_GRP, &bitmap && bitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
2122 int alphaConstant = this->_GetAlphaAttenuation(bitmap);
2126 this->__GetClipBounds(clipRect);
2129 _Util::Point<int> point =
2131 _DoubleToIntForPos(pointD.x),
2132 _DoubleToIntForPos(pointD.y)
2135 _Util::Pixmap* pFlippedImage = 0;
2138 _Util::LockManagerFast srcLock(bitmap);
2139 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
2141 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
2143 Tizen::Graphics::_Effect::Flip flip = (dir == FLIP_DIRECTION_HORIZONTAL) ? Tizen::Graphics::_Effect::FLIP_HORIZONTAL : Tizen::Graphics::_Effect::FLIP_VERTICAL;
2146 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
2148 pFlippedImage = Tizen::Graphics::_Effect::GetFlippedImage(srcImage, flip);
2152 SysTryReturnResult(NID_GRP, pFlippedImage, E_INVALID_ARG, "The source bitmap is invalid.\n");
2154 _ApplySrcBitmapAttrib(*pFlippedImage, bitmap, bitmap.__isOpaqueAllOver);
2156 std::auto_ptr<_Util::Pixmap> autoReleasingImage(pFlippedImage);
2161 if (!this->__useStableRenderer && pFlippedImage->depth == 32)
2163 _Util::LockManagerFast dstLock(*this);
2164 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.");
2166 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
2169 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
2170 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
2172 if (alphaConstant < 255)
2174 std::unique_ptr<_Util::Pixmap> modifiedSrcImage(pFlippedImage->GetAlphaAttenuatedPixmap(alphaConstant));
2176 if (modifiedSrcImage != null)
2178 pass = _Pixman::CopyPixmap(dstImage, *modifiedSrcImage, GetDrawingQuality(), GetCompositeMode(), pointD.x - clipRect.x, pointD.y - clipRect.y);
2184 pass = _Pixman::CopyPixmap(dstImage, *pFlippedImage, GetDrawingQuality(), GetCompositeMode(), pointD.x - clipRect.x, pointD.y - clipRect.y);
2191 _Util::LockManagerFast dstLock(*this);
2192 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
2194 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
2197 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
2198 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
2200 pass = Tizen::Graphics::_Effect::DrawImageWithAlpha(dstImage, point.x - clipRect.x, point.y - clipRect.y, *pFlippedImage, alphaConstant);
2204 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
2212 _Canvas::DrawBitmap(const _Util::Point<double>& pointD, const _Bitmap& bitmap, const _Util::Point<double>& pivotD, double degreeD)
2214 SysTryReturnResult(NID_GRP, &bitmap && bitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
2218 this->__GetClipBounds(clipRect);
2220 int alphaConstant = this->_GetAlphaAttenuation(bitmap);
2222 if (!this->__useStableRenderer && bitmap.GetBitsPerPixel() == 32)
2226 _Util::LockManagerFast srcLock(bitmap);
2227 _Util::LockManagerFast dstLock(*this);
2229 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.");
2230 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.");
2232 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
2233 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
2236 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
2237 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
2239 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
2240 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
2242 if (alphaConstant < 255)
2244 std::unique_ptr<_Util::Pixmap> modifiedSrcImage(srcImage.GetAlphaAttenuatedPixmap(alphaConstant));
2246 if (modifiedSrcImage != null)
2248 pass = _Pixman::RotatePixmap(dstImage, *modifiedSrcImage.get(), GetDrawingQuality(), GetCompositeMode(), pointD.x - clipRect.x, pointD.y - clipRect.y, degreeD, pivotD.x, pivotD.y);
2254 pass = _Pixman::RotatePixmap(dstImage, srcImage, GetDrawingQuality(), GetCompositeMode(), pointD.x - clipRect.x, pointD.y - clipRect.y, degreeD, pivotD.x, pivotD.y);
2266 if (alphaConstant >= 255)
2268 return pCanvasInterface->DrawBitmap(point.x, point.y, *((IBitmapPi*)*(IBitmapPi**)bitmap.__pImpl), pivot.x, pivot.y, degree);
2273 _Util::LockManagerFast srcLock(bitmap);
2274 _Util::LockManagerFast dstLock(*this);
2276 SysTryReturnResult(NID_GRP, srcLock.IsValid(), E_OPERATION_FAILED, "The source bitmap cannot be locked.\n");
2277 SysTryReturnResult(NID_GRP, dstLock.IsValid(), E_OPERATION_FAILED, "The canvas cannot be locked.\n");
2279 const BufferInfo& srcBufferInfo = srcLock.GetBufferInfo();
2280 const BufferInfo& dstBufferInfo = dstLock.GetBufferInfo();
2282 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
2283 _Util::Pixmap dstImageUnclipped(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
2284 _Util::Pixmap dstImage = dstImageUnclipped.GetSubBitmap(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
2286 _ApplySrcBitmapAttrib(srcImage, bitmap, bitmap.__isOpaqueAllOver);
2288 _Util::Point<int> point =
2290 _DoubleToIntForPos(pointD.x),
2291 _DoubleToIntForPos(pointD.y)
2294 Tizen::Graphics::_Effect::RotateDesc rotateDesc = { _DoubleToIntForRound(degreeD), _DoubleToIntForPos(pivotD.x), _DoubleToIntForPos(pivotD.y) };
2296 bool pass = Tizen::Graphics::_Effect::RotateImage(dstImage, point.x - clipRect.x, point.y - clipRect.y, srcImage, rotateDesc, alphaConstant);
2298 SysTryReturnResult(NID_GRP, pass, E_INVALID_ARG, "The source bitmap is invalid.\n");
2305 _Canvas::DrawNinePatchedBitmap(const Rectangle& rect, const _Bitmap& bitmap)
2307 SysTryReturnResult(NID_GRP, &bitmap && bitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
2309 // down-scales the source bitmap
2310 if (rect.width < bitmap.GetWidth() - 2 || rect.height < bitmap.GetHeight() - 2)
2313 int dstW = rect.width;
2314 int dstH = rect.height;
2315 int srcW = bitmap.GetWidth() - 2;
2316 int srcH = bitmap.GetHeight() - 2;
2318 if (dstW <= 0 || dstH <= 0)
2323 if (dstW * srcH < dstH * srcW)
2327 dstH = dstH * srcW / dstW;
2332 dstW = dstW * srcH / dstH;
2339 const int PADDING = 1;
2341 _Bitmap expandedBitmap;
2343 r = expandedBitmap.Construct(Dimension(dstW + PADDING * 2, dstH + PADDING * 2), BITMAP_PIXEL_FORMAT_ARGB8888);
2345 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2347 _Util::LockManagerFast dstBitmap(expandedBitmap);
2350 const BufferInfo& dstBufferInfo = dstBitmap.GetBufferInfo();
2352 memset(dstBufferInfo.pPixels, 0, dstBufferInfo.pitch * dstBufferInfo.height);
2354 _Canvas expandedCanvas;
2356 r = expandedCanvas.Construct(dstBufferInfo);
2358 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2360 expandedCanvas.SetDrawingQuality(BITMAP_DRAWING_QUALITY_HIGH);
2361 expandedCanvas.SetCompositeMode(COMPOSITE_MODE_SRC);
2363 _Util::Pixmap dstImage(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, (void*) dstBufferInfo.pPixels, dstBufferInfo.pitch);
2365 _Util::AccumList<_Util::Pair<_Util::Rectangle<int>, _Util::Rectangle<int> > > boundsList;
2367 r = _Util::GetPatchList(boundsList, Rectangle(PADDING, PADDING, dstBufferInfo.width - PADDING * 2, dstBufferInfo.height - PADDING * 2), bitmap);
2369 SysTryReturn(NID_GRP, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] _Util::GetPatchList() failed (error = %#x)", r);
2371 _Util::AccumList<_Util::Pair<_Util::Rectangle<int>, _Util::Rectangle<int> > >::Iterator iter = boundsList.Begin();
2373 int alphaConstant = bitmap.GetAlphaConstant();
2374 const_cast<_Bitmap*>(&bitmap)->SetAlphaConstant(255);
2376 while (iter != boundsList.End())
2378 Rectangle destRect(iter->first.x, iter->first.y, iter->first.w, iter->first.h);
2379 Rectangle sourRect(iter->second.x, iter->second.y, iter->second.w, iter->second.h);
2381 expandedCanvas.DrawBitmapForNinePatchedBitmap(destRect, bitmap, sourRect, true);
2386 const_cast<_Bitmap*>(&bitmap)->SetAlphaConstant(alphaConstant);
2387 expandedBitmap.SetAlphaConstant(alphaConstant);
2390 // not <- PADDING * 2>
2391 Tizen::Graphics::Rectangle srcRect(PADDING, PADDING, expandedBitmap.GetWidth() - PADDING, expandedBitmap.GetHeight() - PADDING);
2393 return this->DrawBitmap(_Util::Convert<Rectangle, _Util::Rectangle<double> >(rect), expandedBitmap, _Util::Convert<Rectangle, _Util::Rectangle<double> >(srcRect));
2397 Tizen::Graphics::Rectangle srcRect(1, 1, bitmap.GetWidth() - 2, bitmap.GetHeight() - 2);
2399 return this->DrawBitmap(rect, bitmap, srcRect);
2403 _Util::AccumList<_Util::Pair<_Util::Rectangle<int>, _Util::Rectangle<int> > > boundsList;
2405 result r = _Util::GetPatchList(boundsList, rect, bitmap);
2409 _Util::AccumList<_Util::Pair<_Util::Rectangle<int>, _Util::Rectangle<int> > >::Iterator iter = boundsList.Begin();
2411 while (iter != boundsList.End())
2413 Rectangle destRect(iter->first.x, iter->first.y, iter->first.w, iter->first.h);
2414 Rectangle sourRect(iter->second.x, iter->second.y, iter->second.w, iter->second.h);
2416 DrawBitmapForNinePatchedBitmap(destRect, bitmap, sourRect);
2426 _Canvas::DrawNineTiledBitmap(const Rectangle& rect, const _Bitmap& bitmap)
2428 SysTryReturnResult(NID_GRP, &bitmap && bitmap.IsValid(), E_INVALID_ARG, "The source bitmap is invalid.\n");
2430 // down-scales the source bitmap
2431 if (rect.width < bitmap.GetWidth() - 2 || rect.height < bitmap.GetHeight() - 2)
2433 return this->DrawNinePatchedBitmap(rect, bitmap);
2436 _Util::AccumList<_Util::Pair<_Util::Rectangle<int>, _Util::Rectangle<int> > > boundsList;
2438 result r = _Util::GetPatchList(boundsList, rect, bitmap);
2442 // This block is slow and not optimized.
2443 _Util::AccumList<_Util::Pair<_Util::Rectangle<int>, _Util::Rectangle<int> > >::Iterator iter = boundsList.Begin();
2445 while (iter != boundsList.End())
2447 Rectangle destRect(iter->first.x, iter->first.y, iter->first.w, iter->first.h);
2448 Rectangle sourRect(iter->second.x, iter->second.y, iter->second.w, iter->second.h);
2450 if (iter->first.w == iter->second.w && iter->first.h == iter->second.h)
2452 DrawBitmapForNinePatchedBitmap(destRect, bitmap, sourRect);
2456 for (int y = iter->first.y; y < iter->first.y + iter->first.h; y += iter->second.h)
2458 if (y + iter->second.h <= iter->first.y + iter->first.h)
2460 for (int x = iter->first.x; x < iter->first.x + iter->first.w; x += iter->second.w)
2462 if (x + iter->second.w <= iter->first.x + iter->first.w)
2464 Rectangle destRect(x, y, iter->second.w, iter->second.h);
2465 DrawBitmapForNinePatchedBitmap(destRect, bitmap, sourRect);
2469 // right side clipping
2470 int w = iter->first.x + iter->first.w - x;
2472 Rectangle destRect(x, y, w, iter->second.h);
2473 Rectangle sourRect(iter->second.x, iter->second.y, w, iter->second.h);
2475 DrawBitmapForNinePatchedBitmap(destRect, bitmap, sourRect);
2481 // bottom side clipping
2482 int h = iter->first.y + iter->first.h - y;
2484 for (int x = iter->first.x; x < iter->first.x + iter->first.w; x += iter->second.w)
2486 if (x + iter->second.w <= iter->first.x + iter->first.w)
2488 Rectangle destRect(x, y, iter->second.w, h);
2489 Rectangle sourRect(iter->second.x, iter->second.y, iter->second.w, h);
2490 DrawBitmapForNinePatchedBitmap(destRect, bitmap, sourRect);
2494 // right-bottom side clipping
2495 int w = iter->first.x + iter->first.w - x;
2497 Rectangle destRect(x, y, w, h);
2498 Rectangle sourRect(iter->second.x, iter->second.y, w, h);
2500 DrawBitmapForNinePatchedBitmap(destRect, bitmap, sourRect);
2515 _Canvas::DrawEllipse(const _Util::Rectangle<int>& bounds)
2517 _Util::Rectangle<double> doubleBounds =
2525 return this->DrawEllipse(doubleBounds);
2529 _Canvas::DrawEllipse(const _Util::Rectangle<double>& bounds)
2531 if ((bounds.w <= 0.0) || (bounds.h <= 0.0))
2536 // this->__lineWidth is always greater than 0
2538 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
2540 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2542 bool shouldWorkAround = !__IsInClipBounds(bounds) && (this->__dashData.pattern.Size() == 0);
2544 if (!shouldWorkAround && pCairo && pCairo->pCairo)
2546 SET_CAIRO_ALL_PROPERTIES;
2548 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
2550 _Cairo::DrawEllipse(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, bounds);
2554 _Cairo::DrawEllipse(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, bounds);
2557 RESET_CAIRO_ALL_PROPERTIES;
2561 else if (shouldWorkAround && pCairo && pCairo->pCairo)
2563 SET_CAIRO_ALL_PROPERTIES;
2565 double pattern = (bounds.w + bounds.h) * 2.0;
2566 _Cairo::SetDash(pCairo->pCairo, &pattern, 1, 0);
2568 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
2570 _Cairo::DrawEllipse(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, bounds);
2574 _Cairo::DrawEllipse(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, bounds);
2577 RESET_CAIRO_ALL_PROPERTIES;
2583 _CanvasEllipse ellipse;
2586 memset(&info, 0, sizeof(info));
2588 SystemPixel* pBufferAddr = null;
2589 int bufferPitch = 0;
2591 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2593 info.width = __pScratchPad->GetWidth();
2594 info.height = __pScratchPad->GetHeight();
2595 info.bitsPerPixel = 32;
2596 info.pixelPerLine = bufferPitch;
2597 info.pPixels = (void*) pBufferAddr;
2598 info.color32 = composedColor;
2599 info.isClipBoundsSet = this->__isClipBoundsSet;
2600 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2602 ellipse.SetLineWidth(this->__lineWidth.asInteger);
2604 return ellipse.DrawEllipse(int(bounds.x), int(bounds.y), int(bounds.w), int(bounds.h), info);
2609 _Canvas::DrawLine(const _Util::Point<int>& point1, const _Util::Point<int>& point2)
2611 _Util::Point<double> doublePoint1 =
2617 _Util::Point<double> doublePoint2 =
2623 return this->DrawLine(doublePoint1, doublePoint2);
2627 _Canvas::DrawLine(const _Util::Point<double>& point1, const _Util::Point<double>& point2)
2629 // this->__lineWidth is always greater than 0
2631 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
2633 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2635 if (pCairo && pCairo->pCairo)
2637 _Util::Point<double> point[] =
2639 { point1.x, point1.y },
2640 { point2.x, point2.y }
2643 SET_CAIRO_ALL_PROPERTIES;
2645 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
2647 _Cairo::Drawline(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, point, 2);
2651 _Cairo::Drawline(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, point, 2);
2654 RESET_CAIRO_ALL_PROPERTIES;
2675 memset(&info, 0, sizeof(info));
2677 SystemPixel* pBufferAddr = null;
2678 int bufferPitch = 0;
2680 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2682 info.width = __pScratchPad->GetWidth();
2683 info.height = __pScratchPad->GetHeight();
2684 info.bitsPerPixel = 32;
2685 info.pixelPerLine = bufferPitch;
2686 info.pPixels = (void*) pBufferAddr;
2687 info.color32 = composedColor;
2688 info.isClipBoundsSet = this->__isClipBoundsSet;
2689 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2691 line.SetLineWidth(this->__lineWidth.asInteger);
2693 if (this->__lineWidth.asInteger == 1)
2695 if ((startPt.x == endPt.x) && (startPt.y == endPt.y))
2697 this->SetPixel(point1);
2702 return line.DrawLine(startPt, endPt, info);
2707 _Canvas::DrawPolygon(const _Util::Point<double>* pPoints, unsigned int pointCount)
2709 // this->__lineWidth is always greater than 0
2711 if (pointCount == 1)
2713 return this->SetPixel(pPoints[0]);
2716 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
2718 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2720 if (pCairo && pCairo->pCairo)
2722 SET_CAIRO_ALL_PROPERTIES;
2724 _Cairo::DrawPolygon(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, pPoints, pointCount);
2726 RESET_CAIRO_ALL_PROPERTIES;
2732 std::unique_ptr<_GpPoint[]> tempPoints(new (std::nothrow) _GpPoint[pointCount]);
2734 _GpPoint* pTempPoints = tempPoints.get();
2736 if (pTempPoints == null)
2741 for (unsigned int i = 0; i < pointCount; i++)
2743 pTempPoints[i].x = int(pPoints[i].x);
2744 pTempPoints[i].y = int(pPoints[i].y);
2750 memset(&info, 0, sizeof(info));
2752 SystemPixel* pBufferAddr = null;
2753 int bufferPitch = 0;
2755 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2757 info.width = __pScratchPad->GetWidth();
2758 info.height = __pScratchPad->GetHeight();
2759 info.bitsPerPixel = 32;
2760 info.pixelPerLine = bufferPitch;
2761 info.pPixels = (void*) pBufferAddr;
2762 info.color32 = composedColor;
2763 info.isClipBoundsSet = this->__isClipBoundsSet;
2764 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2766 line.SetLineWidth(this->__lineWidth.asInteger);
2768 result r = line.DrawPolygon(int(pointCount), pTempPoints, info);
2775 _Canvas::DrawPolyline(const _Util::Point<double>* pPoints, unsigned int pointCount)
2777 // this->__lineWidth is always greater than 0
2779 if (pointCount == 1)
2781 return this->SetPixel(pPoints[0]);
2784 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
2786 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2788 if (pCairo && pCairo->pCairo)
2790 SET_CAIRO_ALL_PROPERTIES;
2792 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
2794 _Cairo::DrawPolyline(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, pPoints, pointCount);
2798 _Cairo::DrawPolyline(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, pPoints, pointCount);
2801 RESET_CAIRO_ALL_PROPERTIES;
2807 std::unique_ptr<_GpPoint[]> tempPoints(new (std::nothrow) _GpPoint[pointCount]);
2809 _GpPoint* pTempPoints = tempPoints.get();
2811 if (pTempPoints == null)
2816 for (unsigned int i = 0; i < pointCount; i++)
2818 pTempPoints[i].x = int(pPoints[i].x);
2819 pTempPoints[i].y = int(pPoints[i].y);
2825 memset(&info, 0, sizeof(info));
2827 SystemPixel* pBufferAddr = null;
2828 int bufferPitch = 0;
2830 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2832 info.width = __pScratchPad->GetWidth();
2833 info.height = __pScratchPad->GetHeight();
2834 info.bitsPerPixel = 32;
2835 info.pixelPerLine = bufferPitch;
2836 info.pPixels = (void*) pBufferAddr;
2837 info.color32 = composedColor;
2838 info.isClipBoundsSet = this->__isClipBoundsSet;
2839 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2841 line.SetLineWidth(this->__lineWidth.asInteger);
2843 result r = line.DrawPolyLine(int(pointCount), pTempPoints, info);
2850 _Canvas::DrawRectangle(const _Util::Rectangle<int>& rect)
2852 _Util::Rectangle<double> doubleRect =
2860 return this->DrawRectangle(doubleRect);
2864 _Canvas::DrawRectangle(const _Util::Rectangle<double>& rectangle)
2866 if ((rectangle.w <= 0.0) || (rectangle.h <= 0.0))
2871 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
2873 bool tryToDrawWithCairo = (__lineWidth.applied == _Util::ScalarHolder::AS_DOUBLE || __lineWidth.asInteger > 1 || __dashData.pattern.Size() > 0);
2875 if (tryToDrawWithCairo)
2877 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
2879 if (pCairo && pCairo->pCairo)
2881 SET_CAIRO_ALL_PROPERTIES;
2883 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
2885 _Cairo::DrawRectangle(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, rectangle);
2889 _Cairo::DrawRectangle(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, rectangle);
2892 RESET_CAIRO_ALL_PROPERTIES;
2898 // falls through legacy drawing solution
2900 int x1 = static_cast<int>(rectangle.x);
2901 int y1 = static_cast<int>(rectangle.y);
2902 int x2 = x1 + static_cast<int>(rectangle.w) - 1;
2903 int y2 = y1 + static_cast<int>(rectangle.h) - 1;
2905 if (this->__lineWidth.asInteger == 1)
2907 if (!this->__isClipBoundsSet)
2909 __pScratchPad->RegisterFillRect(_RasterOp::FnFillRectAlpha32Bit);
2911 if (x2 > x1 && y2 > y1)
2913 __pScratchPad->FillRect(x1, y1, x2 - x1, 1, composedColor);
2914 __pScratchPad->FillRect(x2, y1, 1, y2 - y1, composedColor);
2916 __pScratchPad->FillRect(x1 + 1, y2, x2 - x1, 1, composedColor);
2917 __pScratchPad->FillRect(x1, y1 + 1, 1, y2 - y1, composedColor);
2921 __pScratchPad->FillRect(x1, y1, static_cast<int>(rectangle.w), static_cast<int>(rectangle.h), composedColor);
2924 __pScratchPad->RegisterFillRect(null);
2928 _Util::Rectangle<int> clip = { this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height };
2930 if (x2 > x1 && y2 > y1)
2932 _Util::Rectangle<int> rect1 = { x1, y1, x2 - x1, 1 };
2933 _Util::Rectangle<int> rect2 = { x2, y1, 1, y2 - y1 };
2934 _Util::Rectangle<int> rect3 = { x1 + 1, y2, x2 - x1, 1 };
2935 _Util::Rectangle<int> rect4 = { x1, y1 + 1, 1, y2 - y1 };
2937 _FillRectangleWithClip(__pScratchPad, composedColor, rect1, clip);
2938 _FillRectangleWithClip(__pScratchPad, composedColor, rect2, clip);
2939 _FillRectangleWithClip(__pScratchPad, composedColor, rect3, clip);
2940 _FillRectangleWithClip(__pScratchPad, composedColor, rect4, clip);
2944 _Util::Rectangle<int> rect1 = { x1, y1, static_cast<int>(rectangle.w), static_cast<int>(rectangle.h) };
2946 _FillRectangleWithClip(__pScratchPad, composedColor, rect1, clip);
2952 else if (this->__lineWidth.asInteger > 1)
2954 _GpPoint tempPoints[4] =
2965 memset(&info, 0, sizeof(info));
2967 SystemPixel* pBufferAddr = null;
2968 int bufferPitch = 0;
2970 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
2972 info.width = __pScratchPad->GetWidth();
2973 info.height = __pScratchPad->GetHeight();
2974 info.bitsPerPixel = 32;
2975 info.pixelPerLine = bufferPitch;
2976 info.pPixels = (void*) pBufferAddr;
2977 info.color32 = composedColor;
2978 info.isClipBoundsSet = this->__isClipBoundsSet;
2979 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
2981 line.SetLineWidth(this->__lineWidth.asInteger);
2983 result r = line.DrawPolygon(4, tempPoints, info);
2988 // this->__lineWidth is always greater than 0
2993 _Canvas::DrawRoundRectangle(const _Util::Rectangle<int>& rect, const _Util::Dimension<int>& arcDim)
2995 _Util::Rectangle<double> doubleRect =
3003 _Util::Dimension<double> doubleArcDim =
3009 return this->DrawRoundRectangle(doubleRect, doubleArcDim);
3013 _Canvas::DrawRoundRectangle(const _Util::Rectangle<double>& rect, const _Util::Dimension<double>& arcDim)
3015 if ((rect.w <= 0.0) || (rect.h <= 0))
3020 if ((int(arcDim.w) == 0) || (int(arcDim.h) == 0))
3022 return this->DrawRectangle(rect);
3025 _Util::Dimension<double> revisedArcDim =
3027 (arcDim.w <= rect.w / 2.0) ? arcDim.w : rect.w / 2.0,
3028 (arcDim.h <= rect.h / 2.0) ? arcDim.h : rect.h / 2.0
3031 // this->__lineWidth is always greater than 0
3033 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
3035 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
3037 if (pCairo && pCairo->pCairo)
3039 SET_CAIRO_ALL_PROPERTIES;
3041 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
3043 _Cairo::DrawRoundRectangle(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, rect, revisedArcDim);
3047 _Cairo::DrawRoundRectangle(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, rect, revisedArcDim);
3050 RESET_CAIRO_ALL_PROPERTIES;
3056 _CanvasRoundRect roundRect;
3059 memset(&info, 0, sizeof(info));
3061 SystemPixel* pBufferAddr = null;
3062 int bufferPitch = 0;
3064 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
3066 info.width = __pScratchPad->GetWidth();
3067 info.height = __pScratchPad->GetHeight();
3068 info.bitsPerPixel = 32;
3069 info.pixelPerLine = bufferPitch;
3070 info.pPixels = (void*) pBufferAddr;
3071 info.color32 = composedColor;
3072 info.isClipBoundsSet = this->__isClipBoundsSet;
3073 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
3075 roundRect.SetLineWidth(this->__lineWidth.asInteger);
3077 return roundRect.DrawRoundRect(int(rect.x), int(rect.y), int(rect.w), int(rect.h), int(revisedArcDim.w), int(revisedArcDim.h), info);
3082 _Canvas::DrawTriangle(const _Util::Point<double>& point1, const _Util::Point<double>& point2, const _Util::Point<double>& point3)
3084 // this->__lineWidth is always greater than 0
3086 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
3088 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
3090 if (pCairo && pCairo->pCairo)
3092 _Util::Point<double> point[] =
3094 { point1.x, point1.y },
3095 { point2.x, point2.y },
3096 { point3.x, point3.y }
3099 SET_CAIRO_ALL_PROPERTIES;
3101 if (__lineWidth.applied != _Util::ScalarHolder::AS_INTEGER)
3103 _Cairo::DrawPolygon(pCairo->pCairo, this->__lineWidth.asDouble, composedColor, point, 3);
3107 _Cairo::DrawPolygon(pCairo->pCairo, this->__lineWidth.asInteger, composedColor, point, 3);
3110 RESET_CAIRO_ALL_PROPERTIES;
3116 _CanvasTriangle triangle;
3119 memset(&info, 0, sizeof(info));
3121 SystemPixel* pBufferAddr = null;
3122 int bufferPitch = 0;
3124 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
3126 info.width = __pScratchPad->GetWidth();
3127 info.height = __pScratchPad->GetHeight();
3128 info.bitsPerPixel = 32;
3129 info.pixelPerLine = bufferPitch;
3130 info.pPixels = (void*) pBufferAddr;
3131 info.color32 = composedColor;
3132 info.isClipBoundsSet = this->__isClipBoundsSet;
3133 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
3135 triangle.SetLineWidth(this->__lineWidth.asInteger);
3137 _GpPoint p1 = { int(point1.x), int(point1.y) };
3138 _GpPoint p2 = { int(point2.x), int(point2.y) };
3139 _GpPoint p3 = { int(point3.x), int(point3.y) };
3141 return triangle.DrawTriangle(p1, p2, p3, info);
3146 _Canvas::FillTriangle(const Color& color, const _Util::Point<int>& point1, const _Util::Point<int>& point2, const _Util::Point<int>& point3)
3148 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3150 _Util::Point<double> doublePoint1 =
3156 _Util::Point<double> doublePoint2 =
3162 _Util::Point<double> doublePoint3 =
3168 return this->__FillTriangle(composedColor, doublePoint1, doublePoint2, doublePoint3);
3172 _Canvas::FillTriangle(const Color& color, const _Util::Point<double>& point1, const _Util::Point<double>& point2, const _Util::Point<double>& point3)
3174 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3176 return this->__FillTriangle(composedColor, point1, point2, point3);
3180 _Canvas::__FillTriangle(unsigned long composedColor, const _Util::Point<double>& point1, const _Util::Point<double>& point2, const _Util::Point<double>& point3)
3182 // this->__lineWidth is always greater than 0
3184 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
3186 if (pCairo && pCairo->pCairo)
3188 _Util::Point<double> point[] =
3190 { point1.x, point1.y },
3191 { point2.x, point2.y },
3192 { point3.x, point3.y }
3195 SET_CAIRO_FILL_PROPERTIES;
3197 _Cairo::FillPolygon(pCairo->pCairo, composedColor, point, 3);
3199 RESET_CAIRO_FILL_PROPERTIES;
3205 _CanvasTriangle triangle;
3208 memset(&info, 0, sizeof(info));
3210 SystemPixel* pBufferAddr = null;
3211 int bufferPitch = 0;
3213 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
3215 info.width = __pScratchPad->GetWidth();
3216 info.height = __pScratchPad->GetHeight();
3217 info.bitsPerPixel = 32;
3218 info.pixelPerLine = bufferPitch;
3219 info.pPixels = (void*) pBufferAddr;
3220 info.color32 = composedColor;
3221 info.isClipBoundsSet = this->__isClipBoundsSet;
3222 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
3224 triangle.SetLineWidth(this->__lineWidth.asInteger);
3226 return triangle.FillTriangle(int(point1.x), int(point1.y), int(point2.x), int(point2.y), int(point3.x), int(point3.y), info);
3231 _Canvas::__FillEllipse(unsigned long composedColor, const _Util::Rectangle<double>& bounds)
3233 if ((bounds.w <= 0.0) || (bounds.h <= 0.0))
3238 // this->__lineWidth is always greater than 0
3240 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
3242 if (pCairo && pCairo->pCairo)
3244 SET_CAIRO_FILL_PROPERTIES;
3246 _Cairo::FillEllipse(pCairo->pCairo, composedColor, bounds);
3248 RESET_CAIRO_FILL_PROPERTIES;
3254 _CanvasEllipse ellipse;
3257 memset(&info, 0, sizeof(info));
3259 SystemPixel* pBufferAddr = null;
3260 int bufferPitch = 0;
3262 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
3264 info.width = __pScratchPad->GetWidth();
3265 info.height = __pScratchPad->GetHeight();
3266 info.bitsPerPixel = 32;
3267 info.pixelPerLine = bufferPitch;
3268 info.pPixels = (void*) pBufferAddr;
3269 info.color32 = composedColor;
3270 info.isClipBoundsSet = this->__isClipBoundsSet;
3271 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
3273 ellipse.SetLineWidth(this->__lineWidth.asInteger);
3275 return ellipse.FillElliepse(int(bounds.x), int(bounds.y), int(bounds.w), int(bounds.h), info);
3280 _Canvas::FillEllipse(const Color& color, const _Util::Rectangle<int>& bounds)
3282 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3284 _Util::Rectangle<double> doubleBounds =
3292 return this->__FillEllipse(composedColor, doubleBounds);
3296 _Canvas::FillEllipse(const Color& color, const _Util::Rectangle<double>& bounds)
3298 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3300 return this->__FillEllipse(composedColor, bounds);
3304 _Canvas::FillPolygon(const Color& color, const _Util::Point<double>* pPoints, unsigned int pointCount)
3307 // Implementation of this method in API versions prior to 2.0 has the following issue:
3309 // -# If there are 4 input points and conditions below is satisfied, the drawing result does not match the expected behavior. @n
3311 // "point[0].x == point[3].x && point[1].x == point[2].x && point[0].y == point[1].y && point[2].y == point[3].y"
3313 // there are 4 cases can be occurred.
3315 // [case1] (p[0]->x > p[1]->x && p[0]->y > p[3]->y)
3320 // | | <--- expected result
3322 // p1--------p0_________
3325 // | | <--- wrong result
3329 // [case2] (p[0]->x < p[1]->x && p[0]->y > p[3]->y)
3334 // | | <--- expected result
3339 // | | <--- wrong result
3343 // [case3] (p[0]->x < p[1]->x && p[0]->y < p[3]->y)
3348 // | | <--- no problem.
3353 // [case4] (p[0]->x > p[1]->x && p[0]->y < p[3]->y)
3355 // p1________p0________
3358 // | | | <--- wrong result
3360 // p2--------p3--------
3363 // -- expected result
3365 // The issue mentioned above is resolved in API version 2.0, So, check the SDK version and emulate problem before step forward furthermore.
3367 // CR approved, no. EP-47D6817268074396919211307C39CA55
3370 // this->__lineWidth is always greater than 0
3372 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3374 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
3376 if (pCairo && pCairo->pCairo)
3378 SET_CAIRO_FILL_PROPERTIES;
3380 _Cairo::FillPolygon(pCairo->pCairo, composedColor, pPoints, pointCount);
3382 RESET_CAIRO_FILL_PROPERTIES;
3388 _CanvasFillPolygon polygon;
3391 memset(&info, 0, sizeof(info));
3393 SystemPixel* pBufferAddr = null;
3394 int bufferPitch = 0;
3396 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
3398 info.width = __pScratchPad->GetWidth();
3399 info.height = __pScratchPad->GetHeight();
3400 info.bitsPerPixel = 32;
3401 info.pixelPerLine = bufferPitch;
3402 info.pPixels = (void*) pBufferAddr;
3403 info.color32 = composedColor;
3404 info.isClipBoundsSet = this->__isClipBoundsSet;
3405 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
3407 polygon.SetLineWidth(this->__lineWidth.asInteger);
3409 std::unique_ptr<_GpPoint[]> tempPoints(new (std::nothrow) _GpPoint[pointCount]);
3411 _GpPoint* pTempPoints = tempPoints.get();
3413 if (pTempPoints == null)
3418 for (unsigned int i = 0; i < pointCount; i++)
3420 pTempPoints[i].x = int(pPoints[i].x);
3421 pTempPoints[i].y = int(pPoints[i].y);
3424 result r = polygon.FillPolygon(int(pointCount), pTempPoints, info);
3431 _Canvas::__FillRectangle(unsigned long composedColor, const _Util::Rectangle<double>& rectangle)
3433 if ((rectangle.w <= 0.0) || (rectangle.h <= 0.0))
3438 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
3440 if (pCairo && pCairo->pCairo)
3442 SET_CAIRO_FILL_PROPERTIES;
3444 _Cairo::FillRectangle(pCairo->pCairo, composedColor, rectangle);
3446 RESET_CAIRO_FILL_PROPERTIES;
3452 _Util::Rectangle<int> rect =
3454 static_cast<int>(rectangle.x),
3455 static_cast<int>(rectangle.y),
3456 static_cast<int>(rectangle.w),
3457 static_cast<int>(rectangle.h)
3460 if (this->__isClipBoundsSet)
3464 int x2 = x1 + rect.w;
3465 int y2 = y1 + rect.h;
3467 x1 = (x1 >= this->__clipBounds.x) ? x1 : this->__clipBounds.x;
3468 y1 = (y1 >= this->__clipBounds.y) ? y1 : this->__clipBounds.y;
3470 x2 = (x2 <= this->__clipBounds.x + this->__clipBounds.width) ? x2 : this->__clipBounds.x + this->__clipBounds.width;
3471 y2 = (y2 <= this->__clipBounds.y + this->__clipBounds.height) ? y2 : this->__clipBounds.y + this->__clipBounds.height;
3479 if (rect.w > 0 && rect.h > 0)
3481 // alpha-fill-rect() applied
3482 __pScratchPad->RegisterFillRect(_RasterOp::FnFillRectAlpha32Bit);
3483 __pScratchPad->FillRect(rect.x, rect.y, rect.w, rect.h, composedColor);
3484 __pScratchPad->RegisterFillRect(null);
3492 _Canvas::FillRectangle(const Color& color, const Rectangle& rect)
3494 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3496 return this->__FillRectangle(composedColor, _Util::Convert<Rectangle, _Util::Rectangle<double> >(rect));
3500 _Canvas::FillRectangle(const Color& color, const _Util::Rectangle<int>& rect)
3502 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3504 _Util::Rectangle<double> doubleRect =
3512 return this->__FillRectangle(composedColor, doubleRect);
3516 _Canvas::FillRectangle(const Color& color, const _Util::Rectangle<double>& rect)
3518 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3520 return this->__FillRectangle(composedColor, rect);
3524 _Canvas::FillRoundRectangle(const Color& color, const _Util::Rectangle<int>& rect, const _Util::Dimension<int>& arcDim)
3526 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3528 _Util::Rectangle<double> doubleRect =
3536 _Util::Dimension<double> doubleArcDim =
3542 return this->__FillRoundRectangle(composedColor, doubleRect, doubleArcDim);
3546 _Canvas::FillRoundRectangle(const Color& color, const _Util::Rectangle<double>& rect, const _Util::Dimension<double>& arcDim)
3548 unsigned long composedColor = _ComposeColor(color.GetRGB32(), this->__fgOpacity);
3550 return this->__FillRoundRectangle(composedColor, rect, arcDim);
3554 _Canvas::__FillRoundRectangle(unsigned long composedColor, const _Util::Rectangle<double>& rect, const _Util::Dimension<double>& arcDim)
3556 if ((rect.w <= 0.0) || (rect.h <= 0.0))
3561 if ((int(arcDim.w) <= 0) || (int(arcDim.h) <= 0))
3563 return this->__FillRectangle(composedColor, rect);
3566 _Util::Dimension<double> revisedArcDim =
3568 (arcDim.w <= rect.w / 2.0) ? arcDim.w : rect.w / 2.0,
3569 (arcDim.h <= rect.h / 2.0) ? arcDim.h : rect.h / 2.0
3572 // this->__lineWidth is always greater than 0
3574 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
3576 if (pCairo && pCairo->pCairo)
3578 SET_CAIRO_FILL_PROPERTIES;
3580 _Cairo::FillRoundRectangle(pCairo->pCairo, composedColor, rect, revisedArcDim);
3582 RESET_CAIRO_FILL_PROPERTIES;
3588 _CanvasRoundRect roundRect;
3591 memset(&info, 0, sizeof(info));
3593 SystemPixel* pBufferAddr = null;
3594 int bufferPitch = 0;
3596 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
3598 info.width = __pScratchPad->GetWidth();
3599 info.height = __pScratchPad->GetHeight();
3600 info.bitsPerPixel = 32;
3601 info.pixelPerLine = bufferPitch;
3602 info.pPixels = (void*) pBufferAddr;
3603 info.color32 = composedColor;
3604 info.isClipBoundsSet = this->__isClipBoundsSet;
3605 info.clipBounds.SetBounds(this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height);
3607 roundRect.SetLineWidth(this->__lineWidth.asInteger);
3609 return roundRect.FillRoundRectangle(int(rect.x), int(rect.y), int(rect.w), int(rect.h), int(revisedArcDim.w), int(revisedArcDim.h), info);
3614 _Canvas::DrawText(const Point& point, const Tizen::Base::String& text)
3616 return _Font::DrawText(*this, point, text, 0, text.GetLength());
3620 _Canvas::DrawText(const Point& point, const Tizen::Base::String& text, int startIndex, int length)
3622 return _Font::DrawText(*this, point, text, startIndex, length);
3626 _Canvas::DrawText(const Point& point, const Tizen::Base::String& text, int startIndex, int length, const Color& outlineColor)
3628 return _Font::DrawText(*this, point, text, startIndex, length, outlineColor);
3632 _Canvas::GetBounds(void) const
3634 Rectangle rect(this->__xBufferPos, this->__yBufferPos, __pScratchPad->GetWidth(), __pScratchPad->GetHeight());
3636 if (this->__windowHandle != INVALID_HANDLE)
3646 _Canvas::GetLineStyle() const
3648 SysTryReturn(NID_GRP, this && this->__pSurface, LINE_STYLE_MAX, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3650 return this->__lineStyle;
3654 _Canvas::GetLineWidth() const
3656 SysTryReturn(NID_GRP, this && this->__pSurface, -1, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3658 return this->__lineWidth.asInteger;
3662 _Canvas::GetLineCapStyle() const
3664 SysTryReturn(NID_GRP, this && this->__pSurface, LINE_CAP_STYLE_ROUND, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3666 return this->__lineCapStyle;
3670 _Canvas::GetLineJoinStyle() const
3672 SysTryReturn(NID_GRP, this && this->__pSurface, LINE_JOIN_STYLE_ROUND, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3674 return this->__lineJoinStyle;
3678 _Canvas::SetLineStyle(LineStyle style)
3680 this->__lineStyle = style;
3686 _Canvas::SetLineWidth(int width, float widthAsFloat)
3688 SysTryReturnResult(NID_GRP, width > 0 || widthAsFloat >= 0.0f, E_OUT_OF_RANGE, "The given line width(%d) is out of range.\n", width);
3690 this->__lineWidth = width;
3691 this->__lineWidth.asDouble = double(widthAsFloat);
3697 _Canvas::SetLineWidth(float width)
3699 SysTryReturnResult(NID_GRP, width > 0.0f, E_OUT_OF_RANGE, "The given line width(%f) is out of range.\n", width);
3701 this->__lineWidth = width;
3707 _Canvas::SetLineCapStyle(LineCapStyle lineCapStyle)
3709 this->__lineCapStyle = lineCapStyle;
3715 _Canvas::SetLineJoinStyle(LineJoinStyle lineJoinStyle)
3717 this->__lineJoinStyle = lineJoinStyle;
3723 _Canvas::SetDashPattern(const Tizen::Graphics::_Util::AccumList<double>& dashValueList, double offset)
3725 SysTryReturn(NID_GRP, this && this->__pSurface, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
3728 Tizen::Graphics::_Util::AccumList<double> listSwap;
3729 this->__dashData.pattern.Swap(listSwap);
3731 this->__dashData.offset = 0.0;
3735 Tizen::Graphics::_Util::AccumList<double>::ConstIterator dashIterator = dashValueList.Begin();
3737 for (; dashIterator != dashValueList.End(); dashIterator++)
3739 this->__dashData.pattern.Push(*dashIterator);
3742 this->__dashData.offset = offset;
3749 _Canvas::SetDrawingQuality(BitmapDrawingQuality quality)
3751 // 'quality' is verified in _CanvasImpl::SetDrawingQuality()
3752 this->__bitmapDrawingQuality = quality;
3755 BitmapDrawingQuality
3756 _Canvas::GetDrawingQuality(void) const
3758 return this->__bitmapDrawingQuality;
3762 _Canvas::SetCompositeMode(CompositeMode compositeMode)
3764 // 'blendingMode' is verified in _CanvasImpl::SetBlendingMode()
3765 this->__compositeMode = compositeMode;
3769 _Canvas::GetCompositeMode(void) const
3771 return this->__compositeMode;
3775 _Canvas::GetPixel(const Point& point, Color& color) const
3777 Point pos(point.x, point.y);
3779 // [ykahn 2011.06.27] revise the value of 'point' if it goes out-of-range
3781 Rectangle rtCanvas = _GetBoundsRel(*this);
3783 SysTryReturnResult(NID_GRP, !rtCanvas.IsEmpty(), E_OUT_OF_RANGE, "Cannot get the bounds of the canvas.\n");
3785 if (pos.x >= rtCanvas.width && rtCanvas.width >= 1)
3787 pos.x = rtCanvas.width - 1;
3790 if (pos.y >= rtCanvas.height && rtCanvas.height >= 1)
3792 pos.y = rtCanvas.height - 1;
3797 result r = E_OUT_OF_RANGE;
3799 Rectangle rect = this->GetBounds();
3804 if ((point.x >= rect.x && point.x < rect.x + rect.width) && (point.y >= rect.y && point.y < rect.y + rect.height))
3808 (const_cast<_Canvas*>(this))->Lock(info);
3810 if (info.bitsPerPixel == 32)
3812 unsigned long* pDest32 = (unsigned long*) info.pPixels;
3813 long pitch = info.pitch / 4;
3815 color.SetRGB32(pDest32[pitch * point.y + point.x], true);
3819 else if (info.bitsPerPixel == 16)
3821 unsigned short* pDest16 = (unsigned short*) info.pPixels;
3822 long pitch = info.pitch / 2;
3824 unsigned short color16 = pDest16[pitch * point.y + point.x];
3826 unsigned long r = (color16 & 0xF800) >> 8;
3827 unsigned long g = (color16 & 0x07E0) >> 3;
3828 unsigned long b = (color16 & 0x001F) << 3;
3834 unsigned long color32 = 0xFF000000 | (r << 16) | (g << 8) | (b);
3836 color.SetRGB32(color32, true);
3841 (const_cast<_Canvas*>(this))->Unlock();
3849 _Canvas::SetPixel(const _Util::Point<int>& point)
3851 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
3853 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
3855 if (pCairo && pCairo->pCairo)
3857 _Util::Rectangle<double> rectangle = {double(point.x), double(point.y), 1.0, 1.0};
3859 SET_CAIRO_FILL_PROPERTIES;
3861 _Cairo::FillRectangle(pCairo->pCairo, composedColor, rectangle);
3863 RESET_CAIRO_FILL_PROPERTIES;
3868 if (!this->__isClipBoundsSet)
3870 __pScratchPad->FillRect(point.x, point.y, 1, 1, composedColor);
3874 _Util::Rectangle<int> rect = { point.x, point.y, 1, 1 };
3875 _Util::Rectangle<int> clip = { this->__clipBounds.x, this->__clipBounds.y, this->__clipBounds.width, this->__clipBounds.height };
3877 _FillRectangleWithClip(__pScratchPad, composedColor, rect, clip);
3884 _Canvas::SetPixel(const _Util::Point<double>& point)
3886 _Util::Rectangle<double> doubleRect =
3894 unsigned long composedColor = _ComposeColor(this->__fgColor, this->__fgOpacity);
3896 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
3898 if (pCairo && pCairo->pCairo)
3900 SET_CAIRO_FILL_PROPERTIES;
3902 _Cairo::FillRectangle(pCairo->pCairo, composedColor, doubleRect);
3904 RESET_CAIRO_FILL_PROPERTIES;
3909 this->__FillRectangle(composedColor, doubleRect);
3917 int bufferWidth = __pSurface->GetWidth();
3918 int bufferHeight = __pSurface->GetHeight();
3919 int bufferPpl = __pSurface->GetPitch();
3921 // cannot use 'if (__pSurface->GetHandle())'
3922 if (this->__windowHandle != INVALID_HANDLE)
3925 evas_object_image_pixels_dirty_set((Evas_Object*) this->__windowHandle, true);
3927 Evas_Object* pSourceObject = _GetWindowSourceObject(this->__windowHandle);
3928 evas_object_image_data_update_add(pSourceObject, 0, 0, bufferWidth, bufferHeight);
3931 evas_object_show((Evas_Object*) this->__windowHandle);
3937 SysTryReturnResult(NID_GRP, Tizen::App::_AppInfo::IsOspCompat(), E_UNSUPPORTED_OPERATION, "This method is unsupported in Tizen.");
3939 _CanvasShowFromMemory(this->__xBufferPos, this->__yBufferPos, 0, 0, bufferWidth, bufferHeight, __pBuffer, bufferWidth, bufferHeight, 32, bufferPpl * 4);
3946 _Canvas::Show(const Rectangle& rect)
3948 if ((rect.width == 0) || (rect.height == 0))
3953 if (this->__windowHandle != INVALID_HANDLE)
3956 int x2 = rect.x + rect.width;
3958 int y2 = rect.y + rect.height;
3981 evas_object_image_pixels_dirty_set((Evas_Object*) this->__windowHandle, true);
3982 // 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)
3983 evas_object_image_data_update_add((Evas_Object*) this->__windowHandle, x1, y1, x2 - x1, y2 - y1);
3985 Evas_Object* pSourceObject = _GetWindowSourceObject(this->__windowHandle);
3986 evas_object_image_data_update_add(pSourceObject, x1, y1, x2 - x1, y2 - y1);
3989 evas_object_show((Evas_Object*) this->__windowHandle);
3995 SysTryReturnResult(NID_GRP, Tizen::App::_AppInfo::IsOspCompat(), E_UNSUPPORTED_OPERATION, "This method is unsupported in Tizen.");
3997 int bufferWidth = __pSurface->GetWidth();
3998 int bufferHeight = __pSurface->GetHeight();
3999 int bufferPpl = __pSurface->GetPitch();
4001 _CanvasShowFromMemory(this->__xBufferPos + rect.x, this->__yBufferPos + rect.y, rect.x, rect.y, rect.width, rect.height, __pBuffer, bufferWidth, bufferHeight, 32, bufferPpl * 4);
4008 _Canvas::SetFont(const _Font& font)
4010 SysTryReturn(NID_GRP, this && this->__pSurface, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
4013 this->__pFont = const_cast<_Font*>(&font);
4019 _Canvas::SetPriorityFont(const _Font& font)
4021 SysTryReturn(NID_GRP, this && this->__pSurface, E_OPERATION_FAILED, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.");
4024 this->__pPriorityFont = const_cast<_Font*>(&font);
4030 _Canvas::ResetPriorityFont(void)
4032 // nullify weak reference
4033 this->__pPriorityFont = null;
4037 _Canvas::SetClipBounds(const Rectangle& rect)
4039 if (__pScratchPad == null)
4046 int x2 = x1 + rect.width;
4047 int y2 = y1 + rect.height;
4049 x1 = (x1 > 0) ? x1 : 0;
4050 y1 = (y1 > 0) ? y1 : 0;
4051 x2 = (x2 < __pScratchPad->GetWidth()) ? x2 : __pScratchPad->GetWidth();
4052 y2 = (y2 < __pScratchPad->GetHeight()) ? y2 : __pScratchPad->GetHeight();
4054 x2 = (x1 > x2) ? x1 : x2;
4055 y2 = (y1 > y2) ? y1 : y2;
4057 if (x1 == 0 && y1 == 0 && x2 == __pScratchPad->GetWidth() && y2 == __pScratchPad->GetHeight())
4059 this->__isClipBoundsSet = false;
4063 this->__isClipBoundsSet = true;
4066 this->__clipBounds.SetBounds(x1, y1, x2 - x1, y2 - y1);
4072 _Canvas::GetClipBounds(void) const
4076 SysTryReturn(NID_GRP, this && this->__pSurface, rect, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
4078 this->__GetClipBounds(rect);
4084 _Canvas::Lock(BufferInfo& info, long timeout)
4086 if (__pScratchPad == null)
4091 if (_BufferInfoImpl::GetInstance(info) != null)
4093 _BufferInfoImpl::GetInstance(info)->SetHandle(_BufferInfoImpl::HANDLE_TYPE_NONE, 0);
4096 SystemPixel* pBufferAddr = null;
4097 int bufferPitch = 0;
4099 __pScratchPad->GetBuffer(pBufferAddr, bufferPitch);
4101 info.width = __pScratchPad->GetWidth();
4102 info.height = __pScratchPad->GetHeight();
4103 info.pitch = bufferPitch * sizeof(_SystemPixel);
4104 info.bitsPerPixel = sizeof(_SystemPixel) * 8;
4105 info.pixelFormat = PIXEL_FORMAT_ARGB8888;
4106 info.pPixels = (void*) pBufferAddr;
4107 //info.__handle = INVALID_HANDLE;
4119 _Canvas::SetForegroundColor(const Color& fgColor)
4121 this->__fgColorNative = fgColor;
4122 this->__ComposeFgColor();
4126 _Canvas::GetForegroundColor(void)
4128 return Color(this->__fgColor);
4132 _Canvas::SetBackgroundColor(const Color& bgColor)
4134 this->__bgColorNative = bgColor;
4135 this->__ComposeBgColor();
4139 _Canvas::GetBackgroundColor(void)
4141 return Color(this->__bgColor);
4145 _Canvas::SetForegroundOpacity(int level)
4147 SysTryReturnVoidResult(NID_GRP, this && this->__pSurface, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
4159 this->__fgOpacity = level;
4160 this->__ComposeFgColor();
4164 _Canvas::GetForegroundOpacity(void)
4166 SysTryReturn(NID_GRP, this && this->__pSurface, 255, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
4168 return this->__fgOpacity;
4172 _Canvas::SetBackgroundOpacity(int level)
4174 SysTryReturnVoidResult(NID_GRP, this && this->__pSurface, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
4186 this->__bgOpacity = level;
4187 this->__ComposeBgColor();
4191 _Canvas::GetBackgroundOpacity(void)
4193 SysTryReturn(NID_GRP, this && this->__pSurface, 255, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
4195 return this->__bgOpacity;
4199 _Canvas::SetPosition(int x, int y)
4201 SysTryReturnResult(NID_GRP, this->__windowHandle == INVALID_HANDLE, E_UNSUPPORTED_OPERATION, "Window canvas does not support moving the position.\n");
4210 _Canvas::SetAntialiasingEnabled(bool enable)
4212 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
4214 if (pCairo && pCairo->pCairo)
4218 cairo_set_antialias(pCairo->pCairo, CAIRO_ANTIALIAS_DEFAULT);
4222 cairo_set_antialias(pCairo->pCairo, CAIRO_ANTIALIAS_NONE);
4228 _Canvas::IsAntialiasingEnabled(void) const
4230 _NativeGfxEngine* pCairo = static_cast<_NativeGfxEngine*>(_pNativeGfxEngine);
4232 if (pCairo && pCairo->pCairo)
4234 return (cairo_get_antialias(pCairo->pCairo) == CAIRO_ANTIALIAS_DEFAULT);
4241 _Canvas::GetInstance(_CanvasImpl& canvas)
4243 return (&canvas != null) ? canvas._pNativeCanvas : null;
4247 _Canvas::GetInstance(const _CanvasImpl& canvas)
4249 return (&canvas != null) ? canvas._pNativeCanvas : null;
4253 _Canvas::_IsWindowCanvas(void) const
4255 if (!(this && this->__pSurface))
4260 return (this->__windowHandle != INVALID_HANDLE);
4264 _Canvas::_SetPosition(int x, int y)
4266 if (!(this && this->__pSurface))
4268 return E_OPERATION_FAILED;
4271 if (this->__windowHandle != INVALID_HANDLE)
4273 return E_UNSUPPORTED_OPERATION;
4276 //?? what is this function ?
4284 _Canvas::_GetAlphaAttenuation(const _Bitmap& bitmap) const
4286 // 'bitmap' and 'this' are always valid.
4288 int alphaConstant = bitmap.GetAlphaConstant();
4290 alphaConstant = (alphaConstant > 255) ? 255 : alphaConstant;
4291 alphaConstant = (alphaConstant < 0) ? 0 : alphaConstant;
4293 int fgOpacity = this->__fgOpacity;
4295 if (fgOpacity > 0 && fgOpacity < 255)
4297 fgOpacity += (fgOpacity >> 7);
4298 alphaConstant = (alphaConstant * fgOpacity) >> 8;
4301 return alphaConstant;
4305 _Canvas::_SetBlendOption(_Canvas::BlendOption blendOption)
4307 if (!(this && this->__pSurface))
4312 if (blendOption < BLEND_MIN || blendOption >= BLEND_MAX)
4317 this->__blendOption = blendOption;
4320 _Canvas::BlendOption
4321 _Canvas::_GetBlendOption(void) const
4323 if (!(this && this->__pSurface))
4326 return BLEND_ALPHABLEND;
4329 return this->__blendOption;
4333 _Canvas::__InitFgBgColorFromTheme(void)
4335 __fgColorNative = (_GetDefaultForegroundColor) ? _GetDefaultForegroundColor() : Color(0xFF000000);
4336 __bgColorNative = (_GetDefaultBackgroundColor) ? _GetDefaultBackgroundColor() : Color(0xFFFFFFFF);
4338 this->__ComposeFgColor();
4339 this->__ComposeBgColor();
4343 _Canvas::__ComposeFgColor(void)
4345 this->__fgColor = _ComposeColor(this->__fgColorNative.GetRGB32(), this->__fgOpacity);
4349 _Canvas::__ComposeBgColor(void)
4351 this->__bgColor = _ComposeColor(this->__bgColorNative.GetRGB32(), this->__bgOpacity);
4355 _Canvas::__GetClipBounds(Rectangle& rect) const
4357 if (this->__isClipBoundsSet)
4359 rect = this->__clipBounds;
4363 rect = Rectangle(0, 0, __pScratchPad->GetWidth(), __pScratchPad->GetHeight());
4368 _Canvas::__Copy(const Point& destPoint, const _Canvas& srcCanvas, const Rectangle& srcRect)
4370 const _Canvas* pSrcCanvas = &srcCanvas;
4372 Rectangle clippedSrcRect(srcRect);
4374 if (_ClipRectangle(clippedSrcRect.x, clippedSrcRect.y, clippedSrcRect.width, clippedSrcRect.height, 0, 0, pSrcCanvas->__pScratchPad->GetWidth(), pSrcCanvas->__pScratchPad->GetHeight()) == CLIP_REJECT)
4379 __pScratchPad->BitBlt(destPoint.x, destPoint.y, pSrcCanvas->__pScratchPad, clippedSrcRect.x, clippedSrcRect.y, clippedSrcRect.width, clippedSrcRect.height);
4385 _Canvas::__Copy(const Rectangle& destRect, const _Canvas& srcCanvas, const Rectangle& srcRect)
4387 const _Canvas* pSrcCanvas = &srcCanvas;
4389 Rectangle clippedSrcRect(srcRect);
4391 if (_ClipRectangle(clippedSrcRect.x, clippedSrcRect.y, clippedSrcRect.width, clippedSrcRect.height, 0, 0, pSrcCanvas->__pScratchPad->GetWidth(), pSrcCanvas->__pScratchPad->GetHeight()) == CLIP_REJECT)
4397 SystemPixel* pSrcAddr = null;
4400 pSrcCanvas->__pScratchPad->GetBuffer(pSrcAddr, srcPitch);
4401 pSrcAddr += srcPitch * clippedSrcRect.y + clippedSrcRect.x;
4403 SystemPixel* pDstAddr = null;
4406 __pScratchPad->GetBuffer(pDstAddr, dstPitch);
4408 _Util::Pixmap srcImageEx(clippedSrcRect.width, clippedSrcRect.height, sizeof(SystemPixel) * 8, pSrcAddr, srcPitch * sizeof(SystemPixel));
4409 _Util::Pixmap dstImageEx(__pScratchPad->GetWidth(), __pScratchPad->GetHeight(), sizeof(SystemPixel) * 8, pDstAddr, dstPitch * sizeof(SystemPixel));
4411 Tizen::Graphics::_Effect::ScaleImage(dstImageEx, destRect.x, destRect.y, destRect.width, destRect.height, srcImageEx, _Effect::ROP_COPY);
4418 _Canvas::__IsInClipBounds(const _Util::Rectangle<double>& bounds)
4422 int x2 = x1 + this->GetBounds().width;
4423 int y2 = y1 + this->GetBounds().height;
4425 if (this->__isClipBoundsSet)
4427 x1 = (this->__clipBounds.x > x1) ? this->__clipBounds.x : x1;
4428 y1 = (this->__clipBounds.y > y1) ? this->__clipBounds.y : y1;
4429 x2 = (this->__clipBounds.x + this->__clipBounds.width < x2) ? this->__clipBounds.x + this->__clipBounds.width : x2;
4430 y2 = (this->__clipBounds.y + this->__clipBounds.height < y2) ? this->__clipBounds.y + this->__clipBounds.height : y2;
4433 return ((bounds.x >= x1) && (bounds.y >= y1) && (bounds.x + bounds.w <= x2) && (bounds.y + bounds.h <= y2));
4436 }} // Tizen::Graphics